diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index e832a75396..db88b21918 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -104,6 +104,10 @@ public Iris() { } } + public static boolean isPackInUseQuick() { + return getPipelineManager().getPipelineNullable() instanceof NewWorldRenderingPipeline; + } + /** * Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do * some very basic setup, config loading, and environment checks. diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderFlame.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderFlame.java new file mode 100644 index 0000000000..9e1a6b0a13 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderFlame.java @@ -0,0 +1,37 @@ +package net.coderbot.iris.mixin.entity_render_context; + +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.LightningHandler; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.function.Function; + +@Pseudo +@Mixin(targets = "mekanism/client/render/entity/RenderFlame", remap = false) +public class MixinRenderFlame { + private static Object MEKANISM_FLAME; + + static { + try { + MEKANISM_FLAME = Class.forName("mekanism.client.render.MekanismRenderType").getField("FLAME").get(null); + } catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + Iris.logger.fatal("Failed to get Mekanism flame!"); + } + } + + @Redirect(method = { + "render(Lmekanism/common/entity/EntityFlame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V" + }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;FLAME:Ljava/util/function/Function;")) + private Function doNotSwitchShaders() { + if (Iris.isPackInUseQuick()) { + return LightningHandler.MEKANISM_FLAME; + } else { + return (Function) MEKANISM_FLAME; + } + } +} diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderMekasuit.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderMekasuit.java new file mode 100644 index 0000000000..c446d2acb2 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinRenderMekasuit.java @@ -0,0 +1,36 @@ +package net.coderbot.iris.mixin.entity_render_context; + +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.LightningHandler; +import net.coderbot.iris.vertices.ImmediateState; +import net.minecraft.client.renderer.RenderType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Pseudo +@Mixin(targets = "mekanism/client/render/armor/MekaSuitArmor", remap = false) +public class MixinRenderMekasuit { + private static Object MEKASUIT; + + static { + try { + MEKASUIT = Class.forName("mekanism.client.render.MekanismRenderType").getField("MEKASUIT").get(null); + } catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + Iris.logger.fatal("Failed to get Mekanism flame!"); + } + } + + @Redirect(method = { + "renderArm", + "Lmekanism/client/render/armor/MekaSuitArmor;render(Lnet/minecraft/client/model/HumanoidModel;Lnet/minecraft/client/renderer/MultiBufferSource;Lcom/mojang/blaze3d/vertex/PoseStack;IILmekanism/common/lib/Color;ZLnet/minecraft/world/entity/LivingEntity;Ljava/util/Map;Z)V" + }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;MEKASUIT:Lnet/minecraft/client/renderer/RenderType;")) + private RenderType doNotSwitchShaders() { + if (Iris.isPackInUseQuick() && ImmediateState.isRenderingLevel) { + return LightningHandler.MEKASUIT; + } else { + return (RenderType) MEKASUIT; + } + } +} diff --git a/src/main/java/net/coderbot/iris/pipeline/LightningHandler.java b/src/main/java/net/coderbot/iris/pipeline/LightningHandler.java index 82945958b9..a0b2b91ff3 100644 --- a/src/main/java/net/coderbot/iris/pipeline/LightningHandler.java +++ b/src/main/java/net/coderbot/iris/pipeline/LightningHandler.java @@ -4,8 +4,13 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.coderbot.iris.layer.InnerWrappedRenderType; import net.coderbot.iris.layer.LightningRenderStateShard; -import net.coderbot.iris.layer.OuterWrappedRenderType; +import net.minecraft.Util; +import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; + +import java.util.function.Function; + public class LightningHandler extends RenderType { public static final RenderType IRIS_LIGHTNING = new InnerWrappedRenderType("iris_lightning2", RenderType.create( @@ -23,6 +28,24 @@ public class LightningHandler extends RenderType { .createCompositeState(false) ), new LightningRenderStateShard()); + public static final Function MEKANISM_FLAME = Util.memoize(resourceLocation -> { + RenderType.CompositeState state = RenderType.CompositeState.builder() + .setShaderState(new ShaderStateShard(ShaderAccess::getMekanismFlameShader)) + .setTextureState(new RenderStateShard.TextureStateShard(resourceLocation, false, false)) + .setTransparencyState(TRANSLUCENT_TRANSPARENCY) + .createCompositeState(true); + return create("mek_flame", DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS, 256, true, false, state); + }); + + public static final RenderType MEKASUIT = create("mekasuit", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 131_072, true, false, + RenderType.CompositeState.builder() + .setShaderState(new ShaderStateShard(ShaderAccess::getMekasuitShader)) + .setTextureState(BLOCK_SHEET) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true) + ); + public LightningHandler(String pRenderType0, VertexFormat pVertexFormat1, VertexFormat.Mode pVertexFormat$Mode2, int pInt3, boolean pBoolean4, boolean pBoolean5, Runnable pRunnable6, Runnable pRunnable7) { super(pRenderType0, pVertexFormat1, pVertexFormat$Mode2, pInt3, pBoolean4, pBoolean5, pRunnable6, pRunnable7); } diff --git a/src/main/java/net/coderbot/iris/pipeline/ShaderAccess.java b/src/main/java/net/coderbot/iris/pipeline/ShaderAccess.java index eb9993ebe0..2ef2913162 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShaderAccess.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShaderAccess.java @@ -3,6 +3,7 @@ import net.coderbot.iris.Iris; import net.coderbot.iris.pipeline.newshader.CoreWorldRenderingPipeline; import net.coderbot.iris.pipeline.newshader.ShaderKey; +import net.coderbot.iris.shadows.ShadowRenderingState; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.ShaderInstance; @@ -20,4 +21,24 @@ public static ShaderInstance getParticleTranslucentShader() { return GameRenderer.getParticleShader(); } + public static ShaderInstance getMekanismFlameShader() { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + + if (pipeline instanceof CoreWorldRenderingPipeline) { + + return ((CoreWorldRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.MEKANISM_FLAME_SHADOW : ShaderKey.MEKANISM_FLAME); + } + + return GameRenderer.getPositionTexColorShader(); + } + + public static ShaderInstance getMekasuitShader() { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + + if (pipeline instanceof CoreWorldRenderingPipeline) { + return ((CoreWorldRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.SHADOW_ENTITIES_CUTOUT : ShaderKey.ENTITIES_TRANSLUCENT); + } + + return GameRenderer.getRendertypeEntityCutoutShader(); + } } diff --git a/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderKey.java b/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderKey.java index 358250e934..fef4774143 100644 --- a/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderKey.java +++ b/src/main/java/net/coderbot/iris/pipeline/newshader/ShaderKey.java @@ -58,6 +58,7 @@ public enum ShaderKey { BEACON (ProgramId.BeaconBeam, AlphaTests.OFF, DefaultVertexFormat.BLOCK, FogMode.PER_FRAGMENT, LightingModel.FULLBRIGHT), GLINT (ProgramId.ArmorGlint, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_TEX, FogMode.PER_VERTEX, LightingModel.LIGHTMAP ), LINES (ProgramId.Line, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_NORMAL, FogMode.PER_VERTEX, LightingModel.LIGHTMAP ), + MEKANISM_FLAME (ProgramId.SpiderEyes, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.PER_VERTEX, LightingModel.LIGHTMAP ), // Note: These must be at the very end (NewWorldRenderingPipeline implementation details) SHADOW_TERRAIN_CUTOUT (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, IrisVertexFormats.TERRAIN, FogMode.OFF, LightingModel.LIGHTMAP ), @@ -73,7 +74,9 @@ public enum ShaderKey { SHADOW_LIGHTNING (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.FULLBRIGHT), SHADOW_PARTICLES (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.PARTICLE, FogMode.OFF, LightingModel.LIGHTMAP ), SHADOW_TEXT (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , FogMode.OFF, LightingModel.LIGHTMAP ), - SHADOW_TEXT_INTENSITY (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , FogMode.OFF, LightingModel.LIGHTMAP ); + SHADOW_TEXT_INTENSITY (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , FogMode.OFF, LightingModel.LIGHTMAP ), + MEKANISM_FLAME_SHADOW (ProgramId.ShadowEntities,AlphaTests.ONE_TENTH_ALPHA,DefaultVertexFormat.POSITION_TEX_COLOR , FogMode.OFF, LightingModel.LIGHTMAP ); + private final ProgramId program; private final AlphaTest alphaTest; diff --git a/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java b/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java index c96d31ea4a..ba8dd4c84b 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java +++ b/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java @@ -11,6 +11,7 @@ public enum ProgramId { Shadow(ProgramGroup.Shadow, ""), ShadowSolid(ProgramGroup.Shadow, "solid", Shadow), ShadowCutout(ProgramGroup.Shadow, "cutout", Shadow), + ShadowEntities(ProgramGroup.Shadow, "entities", Shadow, BlendModeOverride.OFF), Basic(ProgramGroup.Gbuffers, "basic"), Line(ProgramGroup.Gbuffers, "line", Basic), diff --git a/src/main/resources/mixins.oculus.json b/src/main/resources/mixins.oculus.json index 384c2be602..9f4c59cc4a 100644 --- a/src/main/resources/mixins.oculus.json +++ b/src/main/resources/mixins.oculus.json @@ -51,6 +51,8 @@ "entity_render_context.MixinBlockEntityRenderDispatcher", "entity_render_context.MixinCapeLayer", "entity_render_context.MixinElytraLayer", + "entity_render_context.MixinRenderFlame", + "entity_render_context.MixinRenderMekasuit", "entity_render_context.MixinEntityRenderDispatcher", "entity_render_context.MixinHorseArmorLayer", "entity_render_context.MixinHumanoidArmorLayer",