Use GameRenderer.renderHand boolean field instead of mixin

Should be more compatible with mods which replace the entire renderHand
method (thereby making our mixin non-applicable), at least as long as these mods
check `renderHand` as well (Iris explicitly does).

This will become important once #638 is fixed.
This commit is contained in:
Jonas Herzig
2022-03-06 13:36:30 +01:00
parent 6cc370a117
commit 4a5df2ad6d
4 changed files with 21 additions and 35 deletions

View File

@@ -8,6 +8,7 @@ import com.replaymod.render.Setting;
import com.replaymod.render.capturer.CaptureData; import com.replaymod.render.capturer.CaptureData;
import com.replaymod.render.capturer.RenderInfo; import com.replaymod.render.capturer.RenderInfo;
import com.replaymod.render.capturer.WorldRenderer; import com.replaymod.render.capturer.WorldRenderer;
import com.replaymod.render.mixin.GameRendererAccessor;
import com.replaymod.replay.ReplayModReplay; import com.replaymod.replay.ReplayModReplay;
import de.johni0702.minecraft.gui.utils.EventRegistrations; import de.johni0702.minecraft.gui.utils.EventRegistrations;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@@ -81,11 +82,16 @@ public class EntityRendererHandler extends EventRegistrations implements WorldRe
//#endif //#endif
if (mc.world != null && mc.player != null) { if (mc.world != null && mc.player != null) {
GameRendererAccessor gameRenderer = (GameRendererAccessor) mc.gameRenderer;
Screen orgScreen = mc.currentScreen; Screen orgScreen = mc.currentScreen;
boolean orgPauseOnLostFocus = mc.options.pauseOnLostFocus; boolean orgPauseOnLostFocus = mc.options.pauseOnLostFocus;
boolean orgRenderHand = gameRenderer.getRenderHand();
try { try {
mc.currentScreen = null; // do not want to render the current screen (that'd just be the progress gui) mc.currentScreen = null; // do not want to render the current screen (that'd just be the progress gui)
mc.options.pauseOnLostFocus = false; // do not want the pause menu to open if the window is unfocused mc.options.pauseOnLostFocus = false; // do not want the pause menu to open if the window is unfocused
if (omnidirectional) {
gameRenderer.setRenderHand(false); // makes no sense, we wouldn't even know where to put it
}
//#if MC>=11400 //#if MC>=11400
mc.gameRenderer.render(partialTicks, finishTimeNano, true); mc.gameRenderer.render(partialTicks, finishTimeNano, true);
@@ -100,6 +106,7 @@ public class EntityRendererHandler extends EventRegistrations implements WorldRe
} finally { } finally {
mc.currentScreen = orgScreen; mc.currentScreen = orgScreen;
mc.options.pauseOnLostFocus = orgPauseOnLostFocus; mc.options.pauseOnLostFocus = orgPauseOnLostFocus;
gameRenderer.setRenderHand(orgRenderHand);
} }
} }

View File

@@ -0,0 +1,13 @@
package com.replaymod.render.mixin;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(GameRenderer.class)
public interface GameRendererAccessor {
@Accessor
boolean getRenderHand();
@Accessor
void setRenderHand(boolean value);
}

View File

@@ -1,34 +0,0 @@
package com.replaymod.render.mixin;
import com.replaymod.render.hooks.EntityRendererHandler;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class)
public abstract class Mixin_Omnidirectional_SkipHand implements EntityRendererHandler.IEntityRenderer {
@Inject(method = "renderHand", at = @At("HEAD"), cancellable = true)
private void replayModRender_renderSpectatorHand(
//#if MC>=11500
MatrixStack matrixStack,
//#endif
//#if MC>=11400
Camera camera,
//#endif
float partialTicks,
//#if MC<11400
//$$ int renderPass,
//#endif
CallbackInfo ci
) {
EntityRendererHandler handler = replayModRender_getHandler();
if (handler != null && handler.omnidirectional) {
// No spectator hands during 360° view, we wouldn't even know where to put it
ci.cancel();
}
}
}

View File

@@ -16,7 +16,6 @@
"Mixin_Omnidirectional_Camera", "Mixin_Omnidirectional_Camera",
"Mixin_Omnidirectional_DisableFrustumCulling", "Mixin_Omnidirectional_DisableFrustumCulling",
"Mixin_Omnidirectional_Rotation", "Mixin_Omnidirectional_Rotation",
"Mixin_Omnidirectional_SkipHand",
"Mixin_PreserveDepthDuringGuiRendering", "Mixin_PreserveDepthDuringGuiRendering",
"Mixin_SkipBlockOutlinesDuringRender", "Mixin_SkipBlockOutlinesDuringRender",
"Mixin_SkipHudDuringRender", "Mixin_SkipHudDuringRender",
@@ -39,6 +38,7 @@
"Mixin_PreserveDepthDuringHandRendering", "Mixin_PreserveDepthDuringHandRendering",
"Mixin_WindowsWorkaroundForTinyEXRNatives", "Mixin_WindowsWorkaroundForTinyEXRNatives",
//#endif //#endif
"GameRendererAccessor",
"MainWindowAccessor", "MainWindowAccessor",
"WorldRendererAccessor", "WorldRendererAccessor",
//#if MC>=10904 //#if MC>=10904