v1.5.1
This commit is contained in:
1 parent
9536081bab
commit
1403446416
9 files changed
+280
-2
No files matched your search
+1
-1
@@ -34,7 +34,7 @@ mod_name=Lzxnone Terraria
|
|||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=All Rights Reserved
|
mod_license=All Rights Reserved
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.5.0
|
mod_version=1.5.1
|
||||||
## The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
## The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ public class SwordBeam extends Entity {
|
|||||||
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.BOOLEAN);
|
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<Float> INFLATE =
|
public static final EntityDataAccessor<Float> INFLATE =
|
||||||
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.FLOAT);
|
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.FLOAT);
|
||||||
|
public static final EntityDataAccessor<Boolean> OUTLINE =
|
||||||
|
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<Integer> AGE =
|
public static final EntityDataAccessor<Integer> AGE =
|
||||||
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT);
|
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> LIFETIME =
|
public static final EntityDataAccessor<Integer> LIFETIME =
|
||||||
@@ -194,6 +196,7 @@ public class SwordBeam extends Entity {
|
|||||||
builder.define(ROTATE, 0);
|
builder.define(ROTATE, 0);
|
||||||
builder.define(RIGHT, false);
|
builder.define(RIGHT, false);
|
||||||
builder.define(INFLATE, 0.0f);
|
builder.define(INFLATE, 0.0f);
|
||||||
|
builder.define(OUTLINE, false);
|
||||||
builder.define(COLOR0, new Vector3f(1.0f, 1.0f, 1.0f));
|
builder.define(COLOR0, new Vector3f(1.0f, 1.0f, 1.0f));
|
||||||
builder.define(COLOR1, new Vector3f(1.0f, 1.0f, 1.0f));
|
builder.define(COLOR1, new Vector3f(1.0f, 1.0f, 1.0f));
|
||||||
builder.define(COLOR2, new Vector3f(1.0f, 1.0f, 1.0f));
|
builder.define(COLOR2, new Vector3f(1.0f, 1.0f, 1.0f));
|
||||||
@@ -210,6 +213,7 @@ public class SwordBeam extends Entity {
|
|||||||
tag.putInt("rotate", this.entityData.get(ROTATE));
|
tag.putInt("rotate", this.entityData.get(ROTATE));
|
||||||
tag.putBoolean("right", this.entityData.get(RIGHT));
|
tag.putBoolean("right", this.entityData.get(RIGHT));
|
||||||
tag.putFloat("inflate", this.entityData.get(INFLATE));
|
tag.putFloat("inflate", this.entityData.get(INFLATE));
|
||||||
|
tag.putBoolean("outline", this.entityData.get(OUTLINE));
|
||||||
Vector3f c0 = this.entityData.get(COLOR0);
|
Vector3f c0 = this.entityData.get(COLOR0);
|
||||||
tag.putFloat("color0R", c0.x);
|
tag.putFloat("color0R", c0.x);
|
||||||
tag.putFloat("color0G", c0.y);
|
tag.putFloat("color0G", c0.y);
|
||||||
@@ -238,6 +242,7 @@ public class SwordBeam extends Entity {
|
|||||||
if(tag.contains("rotate")) this.entityData.set(ROTATE, tag.getInt("rotate"));
|
if(tag.contains("rotate")) this.entityData.set(ROTATE, tag.getInt("rotate"));
|
||||||
if(tag.contains("right")) this.entityData.set(RIGHT, tag.getBoolean("right"));
|
if(tag.contains("right")) this.entityData.set(RIGHT, tag.getBoolean("right"));
|
||||||
if(tag.contains("inflate")) this.entityData.set(INFLATE, tag.getFloat("inflate"));
|
if(tag.contains("inflate")) this.entityData.set(INFLATE, tag.getFloat("inflate"));
|
||||||
|
if(tag.contains("outline")) this.entityData.set(OUTLINE, tag.getBoolean("outline"));
|
||||||
if(tag.contains("color0R")) {
|
if(tag.contains("color0R")) {
|
||||||
this.entityData.set(COLOR0, new Vector3f(
|
this.entityData.set(COLOR0, new Vector3f(
|
||||||
tag.getFloat("color0R"), tag.getFloat("color0G"), tag.getFloat("color0B")
|
tag.getFloat("color0R"), tag.getFloat("color0G"), tag.getFloat("color0B")
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ public class StaticProjectile extends Projectile {
|
|||||||
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT);
|
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Boolean> GLOW =
|
public static final EntityDataAccessor<Boolean> GLOW =
|
||||||
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BOOLEAN);
|
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BOOLEAN);
|
||||||
|
public static final EntityDataAccessor<Boolean> OUTLINE =
|
||||||
|
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<Integer> AGE =
|
public static final EntityDataAccessor<Integer> AGE =
|
||||||
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT);
|
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> LIFETIME =
|
public static final EntityDataAccessor<Integer> LIFETIME =
|
||||||
@@ -126,6 +128,7 @@ public class StaticProjectile extends Projectile {
|
|||||||
builder.define(COLOR_B, 1.0f);
|
builder.define(COLOR_B, 1.0f);
|
||||||
builder.define(COLOR_A, 1.0f);
|
builder.define(COLOR_A, 1.0f);
|
||||||
builder.define(GLOW, false);
|
builder.define(GLOW, false);
|
||||||
|
builder.define(OUTLINE, false);
|
||||||
builder.define(AGE, 0);
|
builder.define(AGE, 0);
|
||||||
builder.define(LIFETIME, 60);
|
builder.define(LIFETIME, 60);
|
||||||
builder.define(EXPRESSION_X, "0");
|
builder.define(EXPRESSION_X, "0");
|
||||||
@@ -224,6 +227,7 @@ public class StaticProjectile extends Projectile {
|
|||||||
tag.putFloat("colorB", this.entityData.get(COLOR_B));
|
tag.putFloat("colorB", this.entityData.get(COLOR_B));
|
||||||
tag.putFloat("colorA", this.entityData.get(COLOR_A));
|
tag.putFloat("colorA", this.entityData.get(COLOR_A));
|
||||||
tag.putBoolean("glow", this.entityData.get(GLOW));
|
tag.putBoolean("glow", this.entityData.get(GLOW));
|
||||||
|
tag.putBoolean("outline", this.entityData.get(OUTLINE));
|
||||||
tag.putInt("age", this.entityData.get(AGE));
|
tag.putInt("age", this.entityData.get(AGE));
|
||||||
tag.putInt("lifetime", this.entityData.get(LIFETIME));
|
tag.putInt("lifetime", this.entityData.get(LIFETIME));
|
||||||
tag.putString("expressionX", this.entityData.get(EXPRESSION_X));
|
tag.putString("expressionX", this.entityData.get(EXPRESSION_X));
|
||||||
@@ -281,6 +285,7 @@ public class StaticProjectile extends Projectile {
|
|||||||
if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB"));
|
if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB"));
|
||||||
if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA"));
|
if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA"));
|
||||||
if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow"));
|
if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow"));
|
||||||
|
if(tag.contains("outline")) this.entityData.set(OUTLINE, tag.getBoolean("outline"));
|
||||||
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age"));
|
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age"));
|
||||||
if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
|
if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
|
||||||
if(tag.contains("expressionX")) this.entityData.set(EXPRESSION_X, tag.getString("expressionX"));
|
if(tag.contains("expressionX")) this.entityData.set(EXPRESSION_X, tag.getString("expressionX"));
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class StaticSummon extends Entity {
|
|||||||
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT);
|
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Boolean> GLOW =
|
public static final EntityDataAccessor<Boolean> GLOW =
|
||||||
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BOOLEAN);
|
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BOOLEAN);
|
||||||
|
public static final EntityDataAccessor<Boolean> OUTLINE =
|
||||||
|
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<Integer> AGE =
|
public static final EntityDataAccessor<Integer> AGE =
|
||||||
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT);
|
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> LIFETIME =
|
public static final EntityDataAccessor<Integer> LIFETIME =
|
||||||
@@ -121,6 +123,7 @@ public class StaticSummon extends Entity {
|
|||||||
builder.define(COLOR_B, 1.0f);
|
builder.define(COLOR_B, 1.0f);
|
||||||
builder.define(COLOR_A, 1.0f);
|
builder.define(COLOR_A, 1.0f);
|
||||||
builder.define(GLOW, false);
|
builder.define(GLOW, false);
|
||||||
|
builder.define(OUTLINE, false);
|
||||||
builder.define(AGE, 0);
|
builder.define(AGE, 0);
|
||||||
builder.define(LIFETIME, 100);
|
builder.define(LIFETIME, 100);
|
||||||
builder.define(OWNER, Optional.empty());
|
builder.define(OWNER, Optional.empty());
|
||||||
@@ -156,6 +159,7 @@ public class StaticSummon extends Entity {
|
|||||||
tag.putFloat("colorB", this.entityData.get(COLOR_B));
|
tag.putFloat("colorB", this.entityData.get(COLOR_B));
|
||||||
tag.putFloat("colorA", this.entityData.get(COLOR_A));
|
tag.putFloat("colorA", this.entityData.get(COLOR_A));
|
||||||
tag.putBoolean("glow", this.entityData.get(GLOW));
|
tag.putBoolean("glow", this.entityData.get(GLOW));
|
||||||
|
tag.putBoolean("outline", this.entityData.get(OUTLINE));
|
||||||
tag.putInt("age", this.entityData.get(AGE));
|
tag.putInt("age", this.entityData.get(AGE));
|
||||||
tag.putInt("lifetime", this.entityData.get(LIFETIME));
|
tag.putInt("lifetime", this.entityData.get(LIFETIME));
|
||||||
if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID());
|
if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID());
|
||||||
@@ -191,6 +195,7 @@ public class StaticSummon extends Entity {
|
|||||||
if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB"));
|
if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB"));
|
||||||
if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA"));
|
if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA"));
|
||||||
if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow"));
|
if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow"));
|
||||||
|
if(tag.contains("outline")) this.entityData.set(OUTLINE, tag.getBoolean("outline"));
|
||||||
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age"));
|
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age"));
|
||||||
if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
|
if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
|
||||||
if(tag.contains("owner")) {
|
if(tag.contains("owner")) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.io.IOException;
|
|||||||
public class ShaderRegistry {
|
public class ShaderRegistry {
|
||||||
private static ShaderInstance blur;
|
private static ShaderInstance blur;
|
||||||
private static ShaderInstance composite;
|
private static ShaderInstance composite;
|
||||||
|
private static ShaderInstance outline;
|
||||||
|
|
||||||
public static ShaderInstance getBlur() {
|
public static ShaderInstance getBlur() {
|
||||||
return blur;
|
return blur;
|
||||||
@@ -24,6 +25,10 @@ public class ShaderRegistry {
|
|||||||
return composite;
|
return composite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ShaderInstance getOutline() {
|
||||||
|
return outline;
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerShaders(RegisterShadersEvent event) {
|
public static void registerShaders(RegisterShadersEvent event) {
|
||||||
try {
|
try {
|
||||||
@@ -43,8 +48,16 @@ public class ShaderRegistry {
|
|||||||
),
|
),
|
||||||
shader -> composite = shader
|
shader -> composite = shader
|
||||||
);
|
);
|
||||||
|
event.registerShader(
|
||||||
|
new ShaderInstance(
|
||||||
|
event.getResourceProvider(),
|
||||||
|
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "outline"),
|
||||||
|
DefaultVertexFormat.POSITION_TEX
|
||||||
|
),
|
||||||
|
shader -> outline = shader
|
||||||
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Shader load error", e);
|
throw new RuntimeException("Shader load error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
package com.lzxnone.terraria.renderer;
|
||||||
|
|
||||||
|
import com.lzxnone.terraria.LzxnoneTerraria;
|
||||||
|
import com.lzxnone.terraria.entity.IrisCompat;
|
||||||
|
import com.lzxnone.terraria.entity.beam.SwordBeam;
|
||||||
|
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
|
||||||
|
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
|
||||||
|
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
|
||||||
|
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||||
|
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
|
||||||
|
import com.lzxnone.terraria.event.ShaderRegistry;
|
||||||
|
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||||
|
import com.mojang.blaze3d.pipeline.TextureTarget;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import com.mojang.blaze3d.shaders.Uniform;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.*;
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.ShaderInstance;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.client.GlStateBackup;
|
||||||
|
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = LzxnoneTerraria.MODID, value = Dist.CLIENT)
|
||||||
|
public class OutlineRenderer {
|
||||||
|
private static final int GL_LINEAR = 9729;
|
||||||
|
|
||||||
|
private static RenderTarget outlineTarget;
|
||||||
|
private static int lastW = -1;
|
||||||
|
private static int lastH = -1;
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRenderStage(RenderLevelStageEvent event) {
|
||||||
|
if(IrisCompat.isShaderPackInUse()) return;
|
||||||
|
if(ShaderRegistry.getOutline() == null) return;
|
||||||
|
|
||||||
|
ensureTarget();
|
||||||
|
if(outlineTarget == null) return;
|
||||||
|
|
||||||
|
if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) {
|
||||||
|
onAfterEntities(event);
|
||||||
|
}else if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_LEVEL) {
|
||||||
|
onAfterLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ensureTarget() {
|
||||||
|
RenderTarget main = Minecraft.getInstance().getMainRenderTarget();
|
||||||
|
int w = Math.max(1, main.viewWidth);
|
||||||
|
int h = Math.max(1, main.viewHeight);
|
||||||
|
|
||||||
|
if(w == lastW && h == lastH && outlineTarget != null) return;
|
||||||
|
|
||||||
|
if(outlineTarget != null) outlineTarget.destroyBuffers();
|
||||||
|
outlineTarget = new TextureTarget(w, h, true, false);
|
||||||
|
outlineTarget.setClearColor(0f, 0f, 0f, 0f);
|
||||||
|
outlineTarget.setFilterMode(GL_LINEAR);
|
||||||
|
lastW = w;
|
||||||
|
lastH = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onAfterEntities(RenderLevelStageEvent event) {
|
||||||
|
GlStateBackup backup = new GlStateBackup();
|
||||||
|
RenderSystem.backupGlState(backup);
|
||||||
|
ShaderInstance prevShader = RenderSystem.getShader();
|
||||||
|
int prevTex0 = RenderSystem.getShaderTexture(0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
RenderTarget main = Minecraft.getInstance().getMainRenderTarget();
|
||||||
|
outlineTarget.clear(false);
|
||||||
|
outlineTarget.bindWrite(true);
|
||||||
|
outlineTarget.copyDepthFrom(main);
|
||||||
|
outlineTarget.bindWrite(true);
|
||||||
|
|
||||||
|
renderOutlineEntities(
|
||||||
|
event.getPoseStack(),
|
||||||
|
event.getCamera(),
|
||||||
|
event.getPartialTick().getGameTimeDeltaPartialTick(true)
|
||||||
|
);
|
||||||
|
}finally {
|
||||||
|
Minecraft.getInstance().getMainRenderTarget().bindWrite(true);
|
||||||
|
RenderSystem.setShaderTexture(0, prevTex0);
|
||||||
|
if(prevShader != null) {
|
||||||
|
RenderSystem.setShader(() -> prevShader);
|
||||||
|
}
|
||||||
|
RenderSystem.restoreGlState(backup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onAfterLevel() {
|
||||||
|
GlStateBackup backup = new GlStateBackup();
|
||||||
|
RenderSystem.backupGlState(backup);
|
||||||
|
ShaderInstance prevShader = RenderSystem.getShader();
|
||||||
|
int prevTex0 = RenderSystem.getShaderTexture(0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
RenderTarget main = Minecraft.getInstance().getMainRenderTarget();
|
||||||
|
main.bindWrite(true);
|
||||||
|
|
||||||
|
ShaderInstance shader = ShaderRegistry.getOutline();
|
||||||
|
RenderSystem.setShader(() -> shader);
|
||||||
|
RenderSystem.setShaderTexture(0, outlineTarget.getColorTextureId());
|
||||||
|
|
||||||
|
Uniform texelSize = shader.getUniform("TexelSize");
|
||||||
|
if(texelSize != null) {
|
||||||
|
texelSize.set(1.0f / outlineTarget.viewWidth, 1.0f / outlineTarget.viewHeight);
|
||||||
|
}
|
||||||
|
Uniform outlineColor = shader.getUniform("OutlineColor");
|
||||||
|
if(outlineColor != null) {
|
||||||
|
outlineColor.set(0.8f, 0.176f, 0.78f, 1.0f);
|
||||||
|
}
|
||||||
|
Uniform radius = shader.getUniform("Radius");
|
||||||
|
if(radius != null) {
|
||||||
|
radius.set(2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFunc(
|
||||||
|
GlStateManager.SourceFactor.SRC_ALPHA,
|
||||||
|
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA
|
||||||
|
);
|
||||||
|
RenderSystem.disableDepthTest();
|
||||||
|
RenderSystem.depthMask(false);
|
||||||
|
drawFullscreen();
|
||||||
|
}finally {
|
||||||
|
RenderSystem.setShaderTexture(0, prevTex0);
|
||||||
|
if(prevShader != null) {
|
||||||
|
RenderSystem.setShader(() -> prevShader);
|
||||||
|
}
|
||||||
|
RenderSystem.restoreGlState(backup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderOutlineEntities(PoseStack poseStack, Camera camera, float partialTick) {
|
||||||
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
if(mc.level == null) return;
|
||||||
|
|
||||||
|
try(ByteBufferBuilder byteBuf = new ByteBufferBuilder(65536)) {
|
||||||
|
MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(byteBuf);
|
||||||
|
for(Entity entity : mc.level.entitiesForRendering()) {
|
||||||
|
double x = Mth.lerp(partialTick, entity.xo, entity.getX());
|
||||||
|
double y = Mth.lerp(partialTick, entity.yo, entity.getY());
|
||||||
|
double z = Mth.lerp(partialTick, entity.zo, entity.getZ());
|
||||||
|
float entityYaw = Mth.lerp(partialTick, entity.yRotO, entity.getYRot());
|
||||||
|
|
||||||
|
double camX = x - camera.getPosition().x();
|
||||||
|
double camY = y - camera.getPosition().y();
|
||||||
|
double camZ = z - camera.getPosition().z();
|
||||||
|
|
||||||
|
if(entity instanceof StaticProjectile projectile
|
||||||
|
&& projectile.getEntityData().get(StaticProjectile.OUTLINE)) {
|
||||||
|
poseStack.pushPose();
|
||||||
|
poseStack.translate(camX, camY, camZ);
|
||||||
|
StaticProjectileBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR))
|
||||||
|
.render(projectile, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
|
||||||
|
poseStack.popPose();
|
||||||
|
}else if(entity instanceof StaticSummon summon
|
||||||
|
&& summon.getEntityData().get(StaticSummon.OUTLINE)) {
|
||||||
|
poseStack.pushPose();
|
||||||
|
poseStack.translate(camX, camY, camZ);
|
||||||
|
StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR))
|
||||||
|
.render(summon, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
|
||||||
|
poseStack.popPose();
|
||||||
|
}else if(entity instanceof SwordBeam beam
|
||||||
|
&& beam.getEntityData().get(SwordBeam.OUTLINE)) {
|
||||||
|
poseStack.pushPose();
|
||||||
|
poseStack.translate(camX, camY, camZ);
|
||||||
|
SwordBeamBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR))
|
||||||
|
.render(beam, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
|
||||||
|
poseStack.popPose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bufferSource.endBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawFullscreen() {
|
||||||
|
BufferBuilder bb = RenderSystem.renderThreadTesselator().begin(
|
||||||
|
VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
|
||||||
|
bb.addVertex(-1f, -1f, 0f).setUv(0f, 0f);
|
||||||
|
bb.addVertex(1f, -1f, 0f).setUv(1f, 0f);
|
||||||
|
bb.addVertex(1f, 1f, 0f).setUv(1f, 1f);
|
||||||
|
bb.addVertex(-1f, 1f, 0f).setUv(0f, 1f);
|
||||||
|
BufferUploader.drawWithShader(Objects.requireNonNull(bb.build()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#version 150
|
||||||
|
|
||||||
|
in vec2 texCoord0;
|
||||||
|
|
||||||
|
uniform sampler2D Sampler0;
|
||||||
|
uniform vec2 TexelSize;
|
||||||
|
uniform vec4 OutlineColor;
|
||||||
|
uniform float Radius;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float center = texture(Sampler0, texCoord0).a;
|
||||||
|
float around = 0.0;
|
||||||
|
vec2 px = TexelSize * Radius;
|
||||||
|
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 + vec2(px.x, 0.0)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 - vec2(px.x, 0.0)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 + vec2(0.0, px.y)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 - vec2(0.0, px.y)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 + vec2(px.x, px.y)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 + vec2(px.x, -px.y)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 + vec2(-px.x, px.y)).a);
|
||||||
|
around = max(around, texture(Sampler0, texCoord0 - vec2(px.x, px.y)).a);
|
||||||
|
|
||||||
|
float outline = max(around - center, 0.0);
|
||||||
|
fragColor = vec4(OutlineColor.rgb, outline * OutlineColor.a);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"vertex": "lzxnoneterraria:outline",
|
||||||
|
"fragment": "lzxnoneterraria:outline",
|
||||||
|
"samplers": [
|
||||||
|
{ "name": "Sampler0" }
|
||||||
|
],
|
||||||
|
"attributes": [
|
||||||
|
"Position",
|
||||||
|
"UV0"
|
||||||
|
],
|
||||||
|
"uniforms": [
|
||||||
|
{ "name": "TexelSize", "type": "float", "count": 2, "values": [ 0.001, 0.001 ] },
|
||||||
|
{ "name": "OutlineColor", "type": "float", "count": 4, "values": [ 0.8, 0.176, 0.78, 1.0 ] },
|
||||||
|
{ "name": "Radius", "type": "float", "count": 1, "values": [ 2.0 ] }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#version 150
|
||||||
|
|
||||||
|
in vec3 Position;
|
||||||
|
in vec2 UV0;
|
||||||
|
|
||||||
|
out vec2 texCoord0;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(Position, 1.0);
|
||||||
|
texCoord0 = UV0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user