From 89c6fe94173b439f4ca6fe03a835c707edda2344 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Sun, 29 May 2022 11:03:30 +0700 Subject: [PATCH] fix hand fov and item lighting --- build.gradle | 2 +- .../redaction/mixin/EntityRendererMixin.java | 42 ++++++++++++++----- .../mixin/OverflowGlintHandlerMixin.java | 2 +- .../mixin/PatcherEntityRendererHookMixin.java | 24 +++++++++++ .../kotlin/net/wyvest/redaction/Redaction.kt | 1 + src/main/resources/mixins.redaction.json | 1 + 6 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/wyvest/redaction/mixin/PatcherEntityRendererHookMixin.java diff --git a/build.gradle b/build.gradle index fda435f..dd6b159 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ import dev.architectury.pack200.java.Pack200Adapter plugins { id "dev.architectury.architectury-pack200" version "0.1.3" id "org.jetbrains.kotlin.jvm" version "1.6.10" - id "cc.woverflow.loom" version "0.10.6" + id "gg.essential.loom" version "0.10.0.3" id "java" } diff --git a/src/main/java/net/wyvest/redaction/mixin/EntityRendererMixin.java b/src/main/java/net/wyvest/redaction/mixin/EntityRendererMixin.java index 1e08888..dcd79ae 100644 --- a/src/main/java/net/wyvest/redaction/mixin/EntityRendererMixin.java +++ b/src/main/java/net/wyvest/redaction/mixin/EntityRendererMixin.java @@ -3,8 +3,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.GlStateManager; +import net.wyvest.redaction.Redaction; import net.wyvest.redaction.config.RedactionConfig; import org.lwjgl.util.glu.Project; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Dynamic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.*; @@ -15,32 +18,51 @@ public abstract class EntityRendererMixin { @Shadow protected abstract float getFOVModifier(float partialTicks, boolean useFOVSetting); @Shadow private Minecraft mc; - @Shadow private float farPlaneDistance; - private boolean override = false; - - @Inject(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;getFOVModifier(FZ)F")) + @Inject(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;loadIdentity()V", shift = At.Shift.AFTER, ordinal = 0)) private void modifyFov(float partialTicks, int xOffset, CallbackInfo ci) { - override = true; + setOverrideHand(); + } + + @Dynamic("I HATE OPTIFINE") + @Inject(method = {"renderHand*"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;loadIdentity()V", shift = At.Shift.AFTER, ordinal = 0, remap = true), remap = false) + private void modifyFov(float f, int n, boolean bl, boolean bl2, boolean bl3, CallbackInfo ci) { + setOverrideHand(); + } + + private void setOverrideHand() { + Redaction.INSTANCE.setOverrideHand(true); } - @Redirect(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;enableLightmap()V")) + @Dynamic("I HATE OPTIFINE") + @Redirect(method = {"renderHand*", "func_78476_b"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;enableLightmap()V", remap = true), remap = false) private void redirectLightmap(EntityRenderer instance) { if (!RedactionConfig.INSTANCE.getDisableHandLighting()) { instance.enableLightmap(); } } - @Redirect(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;disableLightmap()V")) + @Dynamic("I HATE OPTIFINE") + @Redirect(method = {"renderHand*", "func_78476_b"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;disableLightmap()V", remap = true), remap = false) private void redirectLightmap2(EntityRenderer instance) { if (!RedactionConfig.INSTANCE.getDisableHandLighting()) { instance.disableLightmap(); } } - @Inject(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V", shift = At.Shift.AFTER)) + @Inject(method = "renderHand", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;thirdPersonView:I", opcode = Opcodes.GETFIELD, ordinal = 1)) private void resetFOV(float partialTicks, int xOffset, CallbackInfo ci) { + resetFOV(partialTicks, xOffset); + } + + @Dynamic("I HATE OPTIFINE") + @Inject(method = "renderHand*", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;thirdPersonView:I", opcode = Opcodes.GETFIELD, ordinal = 1, remap = true), remap = false) + private void resetFOV(float f, int n, boolean bl, boolean bl2, boolean bl3, CallbackInfo ci) { + resetFOV(f, n); + } + + private void resetFOV(float partialTicks, int xOffset) { GlStateManager.matrixMode(5889); GlStateManager.loadIdentity(); if (this.mc.gameSettings.anaglyph) { @@ -56,8 +78,8 @@ private void resetFOV(float partialTicks, int xOffset, CallbackInfo ci) { @ModifyConstant(method = "getFOVModifier", constant = @Constant(floatValue = 70.0F, ordinal = 0)) private float modifyFOV(float constant) { - if (override && RedactionConfig.INSTANCE.getCustomHandFOV()) { - override = false; + if (Redaction.INSTANCE.getOverrideHand() && RedactionConfig.INSTANCE.getCustomHandFOV()) { + Redaction.INSTANCE.setOverrideHand(false); return RedactionConfig.INSTANCE.getHandFOV(); } else { return constant; diff --git a/src/main/java/net/wyvest/redaction/mixin/OverflowGlintHandlerMixin.java b/src/main/java/net/wyvest/redaction/mixin/OverflowGlintHandlerMixin.java index e7e3488..d13adea 100644 --- a/src/main/java/net/wyvest/redaction/mixin/OverflowGlintHandlerMixin.java +++ b/src/main/java/net/wyvest/redaction/mixin/OverflowGlintHandlerMixin.java @@ -13,7 +13,7 @@ @Mixin(targets = "cc.woverflow.overflowanimations.GlintHandler", remap = false) public class OverflowGlintHandlerMixin { @Inject(method = "renderGlint", at = @At("RETURN")) - private void afterRenderEffect(IBakedModel model, CallbackInfo ci) { + private static void afterRenderEffect(IBakedModel model, CallbackInfo ci) { if (RedactionConfig.INSTANCE.getDisableHandLighting()) { RenderHelper.disableStandardItemLighting(); } diff --git a/src/main/java/net/wyvest/redaction/mixin/PatcherEntityRendererHookMixin.java b/src/main/java/net/wyvest/redaction/mixin/PatcherEntityRendererHookMixin.java new file mode 100644 index 0000000..a2d1a55 --- /dev/null +++ b/src/main/java/net/wyvest/redaction/mixin/PatcherEntityRendererHookMixin.java @@ -0,0 +1,24 @@ +package net.wyvest.redaction.mixin; + +import net.wyvest.redaction.Redaction; +import net.wyvest.redaction.config.RedactionConfig; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Pseudo +@Mixin(targets = "club.sk1er.patcher.hooks.EntityRendererHook", remap = false) +public class PatcherEntityRendererHookMixin { + @Dynamic + @ModifyConstant(method = "getHandFOVModifier", constant = @Constant(floatValue = 70F, ordinal = 0)) + private static float modifyFOV(float constant) { + if (Redaction.INSTANCE.getOverrideHand() && RedactionConfig.INSTANCE.getCustomHandFOV()) { + Redaction.INSTANCE.setOverrideHand(false); + return RedactionConfig.INSTANCE.getHandFOV(); + } else { + return constant; + } + } +} diff --git a/src/main/kotlin/net/wyvest/redaction/Redaction.kt b/src/main/kotlin/net/wyvest/redaction/Redaction.kt index c207db3..d311ffa 100644 --- a/src/main/kotlin/net/wyvest/redaction/Redaction.kt +++ b/src/main/kotlin/net/wyvest/redaction/Redaction.kt @@ -38,6 +38,7 @@ object Redaction { false } } + var overrideHand = false @Mod.EventHandler private fun onFMLPreInitialization(event: FMLPreInitializationEvent) { diff --git a/src/main/resources/mixins.redaction.json b/src/main/resources/mixins.redaction.json index 6986fac..6d3f731 100644 --- a/src/main/resources/mixins.redaction.json +++ b/src/main/resources/mixins.redaction.json @@ -15,6 +15,7 @@ "GuiScreenServerListMixin", "ItemRendererMixin", "OverflowGlintHandlerMixin", + "PatcherEntityRendererHookMixin", "PatcherFontRendererMixin", "RenderItemMixin", "RenderManagerMixin",