Skip to content

Commit

Permalink
Mekasuit render fix backport. fixes #170
Browse files Browse the repository at this point in the history
  • Loading branch information
KostromDan committed Nov 11, 2024
1 parent da63951 commit 30e1eb5
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.irisshaders.iris.mixin.entity_render_context;

import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pathways.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<ResourceLocation, RenderType> doNotSwitchShaders() {
if (Iris.isPackInUseQuick()) {
return LightningHandler.MEKANISM_FLAME;
} else {
return (Function<ResourceLocation, RenderType>) MEKANISM_FLAME;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.irisshaders.iris.mixin.entity_render_context;

import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pathways.LightningHandler;
import net.irisshaders.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;
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/net/irisshaders/iris/pathways/LightningHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import net.irisshaders.iris.layer.InnerWrappedRenderType;
import net.irisshaders.iris.layer.LightningRenderStateShard;
import net.irisshaders.iris.pipeline.programs.ShaderAccess;
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(
Expand All @@ -22,6 +28,23 @@ public class LightningHandler extends RenderType {
.createCompositeState(false)
), new LightningRenderStateShard());

public static final Function<ResourceLocation, RenderType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pipeline.ShaderRenderingPipeline;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;

Expand All @@ -20,4 +21,20 @@ public static ShaderInstance getParticleTranslucentShader() {

return GameRenderer.getParticleShader();
}

public static ShaderInstance getMekanismFlameShader() {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
if (pipeline instanceof ShaderRenderingPipeline) {
return ((ShaderRenderingPipeline) 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 ShaderRenderingPipeline) {
return ((ShaderRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.SHADOW_ENTITIES_CUTOUT : ShaderKey.ENTITIES_TRANSLUCENT);
}
return GameRenderer.getRendertypeEntityCutoutShader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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),
Expand All @@ -78,7 +79,8 @@ public enum ShaderKey {
SHADOW_PARTICLES(ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.PARTICLE, FogMode.OFF, LightingModel.LIGHTMAP),
SHADOW_TEXT(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, FogMode.OFF, LightingModel.LIGHTMAP),
SHADOW_TEXT_BG(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, FogMode.OFF, LightingModel.LIGHTMAP),
SHADOW_TEXT_INTENSITY(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, FogMode.OFF, LightingModel.LIGHTMAP);
SHADOW_TEXT_INTENSITY(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mixins.oculus.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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",
Expand Down

0 comments on commit 30e1eb5

Please sign in to comment.