Skip to content

Commit

Permalink
fix hand fov and item lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed May 29, 2022
1 parent 0cac721 commit 89c6fe9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
42 changes: 32 additions & 10 deletions src/main/java/net/wyvest/redaction/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/net/wyvest/redaction/Redaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object Redaction {
false
}
}
var overrideHand = false

@Mod.EventHandler
private fun onFMLPreInitialization(event: FMLPreInitializationEvent) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.redaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"GuiScreenServerListMixin",
"ItemRendererMixin",
"OverflowGlintHandlerMixin",
"PatcherEntityRendererHookMixin",
"PatcherFontRendererMixin",
"RenderItemMixin",
"RenderManagerMixin",
Expand Down

0 comments on commit 89c6fe9

Please sign in to comment.