From 7fb8cde66dd2ceea5f7a73485f8f04d9a82536cf Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:00:05 +0100 Subject: [PATCH] Zoom (#724) Co-authored-by: kurrycat <44340227+kurrycat2004@users.noreply.github.com> --- .../angelica/config/AngelicaConfig.java | 5 ++ .../angelica/hudcaching/HUDCaching.java | 38 ++----------- .../gtnewhorizons/angelica/mixins/Mixins.java | 8 +++ .../angelica/proxy/ClientProxy.java | 9 ++-- .../angelica/zoom/IMouseFilterExt.java | 5 ++ .../com/gtnewhorizons/angelica/zoom/Zoom.java | 53 +++++++++++++++++++ src/main/resources/META-INF/angelica_at.cfg | 2 + .../zoom/MixinEntityRenderer_Zoom.java | 30 +++++++++++ .../angelica/zoom/MixinMinecraft_Zoom.java | 21 ++++++++ .../early/angelica/zoom/MixinMouseFilter.java | 26 +++++++++ 10 files changed, 161 insertions(+), 36 deletions(-) create mode 100644 src/main/java/com/gtnewhorizons/angelica/zoom/IMouseFilterExt.java create mode 100644 src/main/java/com/gtnewhorizons/angelica/zoom/Zoom.java create mode 100644 src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinEntityRenderer_Zoom.java create mode 100644 src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMinecraft_Zoom.java create mode 100644 src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMouseFilter.java diff --git a/src/main/java/com/gtnewhorizons/angelica/config/AngelicaConfig.java b/src/main/java/com/gtnewhorizons/angelica/config/AngelicaConfig.java index 356249f1e..dc40760b7 100644 --- a/src/main/java/com/gtnewhorizons/angelica/config/AngelicaConfig.java +++ b/src/main/java/com/gtnewhorizons/angelica/config/AngelicaConfig.java @@ -132,4 +132,9 @@ public class AngelicaConfig { @Config.DefaultBoolean(false) @Config.RequiresMcRestart public static boolean enableDebugLogging; + + @Config.Comment("Enable Zoom") + @Config.DefaultBoolean(true) + @Config.RequiresMcRestart + public static boolean enableZoom; } diff --git a/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java b/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java index c675dfaaf..f538a6c83 100644 --- a/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java +++ b/src/main/java/com/gtnewhorizons/angelica/hudcaching/HUDCaching.java @@ -19,9 +19,7 @@ import com.gtnewhorizons.angelica.glsm.GLStateManager; -import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.InputEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiIngame; @@ -29,9 +27,7 @@ import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.shader.Framebuffer; -import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.GuiIngameForge; import thaumcraft.common.Thaumcraft; import xaero.common.core.XaeroMinimapCore; @@ -70,31 +66,6 @@ public class HUDCaching { private HUDCaching() {} - /* TODO START REMOVE DEBUG STUFF */ - - private final List updateTimeList = new ArrayList<>(21); - private static boolean isEnabled = true; - - // moved initialization to when its registered to avoid an empty Debug category, which can cause crashes when - // opening the controls menu and hudcaching is disabled in the config - private static KeyBinding toggle; - - public static void registerKeyBindings() { - toggle = new KeyBinding("Toggle HUDCaching", 0, "Debug"); - ClientRegistry.registerKeyBinding(toggle); - } - - @SubscribeEvent - public void onKeypress(InputEvent.KeyInputEvent event) { - if (toggle != null && toggle.isPressed()) { - isEnabled = !isEnabled; - final String msg = isEnabled ? "Enabled HUDCaching" : "Disabled HUDCaching"; - if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText(msg)); - } - } - - /* TODO END REMOVE DEBUG STUFF */ - // highest so it runs before the GLSM load event @SubscribeEvent(priority = EventPriority.HIGH) public void onJoinWorld(WorldEvent.Load event) { @@ -112,7 +83,7 @@ public static void renderCachedHud(EntityRenderer renderer, GuiIngame ingame, fl XaeroMinimapCore.beforeIngameGuiRender(partialTicks); } - if (!OpenGlHelper.isFramebufferEnabled() || !isEnabled || framebuffer == null) { + if (!OpenGlHelper.isFramebufferEnabled() || framebuffer == null) { ingame.renderGameOverlay(partialTicks, hasScreen, mouseX, mouseY); return; } @@ -244,13 +215,14 @@ private static void drawTexturedRect(Tessellator tessellator, float width, float // moved to here due to the method being called from a mixin public static void disableHoloInventory() { - if (ModStatus.isHoloInventoryLoaded){ - Renderer.INSTANCE.angelicaOverride = isEnabled; + if (ModStatus.isHoloInventoryLoaded) { + Renderer.INSTANCE.angelicaOverride = true; } } + @SuppressWarnings("unused") // called via ASM public static class HUDCachingHooks { - public static boolean shouldReturnEarly(){ + public static boolean shouldReturnEarly() { return renderingCacheOverride; } } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java index 39c2d7a5d..0e31789d8 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java @@ -171,6 +171,14 @@ public enum Mixins { ,"angelica.textures.MixinTextureUtil" )), + ANGELICA_ZOOM(new Builder("Zoom").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) + .setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableZoom) + .addMixinClasses( + "angelica.zoom.MixinEntityRenderer_Zoom", + "angelica.zoom.MixinMinecraft_Zoom", + "angelica.zoom.MixinMouseFilter" + )), + HUD_CACHING(new Builder("Renders the HUD elements 20 times per second maximum to improve performance") .addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT).setPhase(Phase.EARLY) .setApplyIf(() -> AngelicaConfig.enableHudCaching).addMixinClasses( diff --git a/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java b/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java index d790a8a8a..182350711 100644 --- a/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java +++ b/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java @@ -15,6 +15,7 @@ import com.gtnewhorizons.angelica.render.CloudRenderer; import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry; import com.gtnewhorizons.angelica.utils.AssetLoader; +import com.gtnewhorizons.angelica.zoom.Zoom; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -96,8 +97,7 @@ public void init(FMLInitializationEvent event) { if (AngelicaConfig.enableHudCaching) { FMLCommonHandler.instance().bus().register(HUDCaching.INSTANCE); - MinecraftForge.EVENT_BUS.register(HUDCaching.INSTANCE); // TODO remove debug stuff, unused registration} - HUDCaching.registerKeyBindings(); + MinecraftForge.EVENT_BUS.register(HUDCaching.INSTANCE); } if (AngelicaConfig.enableSodium) { MinecraftForge.EVENT_BUS.register(SodiumDebugScreenHandler.INSTANCE); @@ -130,7 +130,7 @@ public void init(FMLInitializationEvent event) { FMLCommonHandler.instance().bus().register(this); MinecraftForge.EVENT_BUS.register(this); - glsmKeyBinding = new KeyBinding("Print GLSM Debug", Keyboard.KEY_NONE, "Angelica Keybinds"); + glsmKeyBinding = new KeyBinding("Print GLSM Debug", Keyboard.KEY_NONE, "Angelica"); ClientRegistry.registerKeyBinding(glsmKeyBinding); VanillaModels.init(); @@ -138,6 +138,9 @@ public void init(FMLInitializationEvent event) { if (ModStatus.isBetterCrashesLoaded) { BetterCrashesCompat.init(); } + if (AngelicaConfig.enableZoom) { + Zoom.init(); + } } private boolean wasGLSMKeyPressed; diff --git a/src/main/java/com/gtnewhorizons/angelica/zoom/IMouseFilterExt.java b/src/main/java/com/gtnewhorizons/angelica/zoom/IMouseFilterExt.java new file mode 100644 index 000000000..9108c23cf --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/zoom/IMouseFilterExt.java @@ -0,0 +1,5 @@ +package com.gtnewhorizons.angelica.zoom; + +public interface IMouseFilterExt { + void angelica$reset(); +} diff --git a/src/main/java/com/gtnewhorizons/angelica/zoom/Zoom.java b/src/main/java/com/gtnewhorizons/angelica/zoom/Zoom.java new file mode 100644 index 000000000..6a5badbd9 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/zoom/Zoom.java @@ -0,0 +1,53 @@ +package com.gtnewhorizons.angelica.zoom; + +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.MathHelper; +import org.lwjgl.input.Keyboard; + +public class Zoom { + + @Getter + private static float zoom = 4.0F; + @Getter + private static final KeyBinding zoomKey = new KeyBinding("Zoom", 0, "key.categories.misc"); + + public static final float ZOOM_MIN = 1.0F; + public static final float ZOOM_MAX = 64.0F; + public static final float ZOOM_STEP = 1.2F; + + private static boolean lastSmoothCameraState = false; + + public static void init() { + ClientRegistry.registerKeyBinding(zoomKey); + FMLCommonHandler.instance().bus().register(new Zoom()); + } + + public static void modifyZoom(int eventDWheel) { + if (eventDWheel == 0) return; + zoom = MathHelper.clamp_float((float) (zoom * Math.pow(ZOOM_STEP, Integer.signum(eventDWheel))), ZOOM_MIN, ZOOM_MAX); + } + + @SubscribeEvent + public void onKeyPress(InputEvent.KeyInputEvent e) { + final int keyCode = zoomKey.getKeyCode(); + if (keyCode == 0 || Keyboard.getEventKey() != keyCode || Keyboard.isRepeatEvent()) return; + final Minecraft mc = Minecraft.getMinecraft(); + if (Keyboard.getEventKeyState()) { + lastSmoothCameraState = mc.gameSettings.smoothCamera; + mc.gameSettings.smoothCamera = true; + } else { + zoom = 4.0F; + if (mc.gameSettings.smoothCamera != lastSmoothCameraState) { + ((IMouseFilterExt) mc.entityRenderer.mouseFilterXAxis).angelica$reset(); + ((IMouseFilterExt) mc.entityRenderer.mouseFilterYAxis).angelica$reset(); + } + mc.gameSettings.smoothCamera = lastSmoothCameraState; + } + } +} diff --git a/src/main/resources/META-INF/angelica_at.cfg b/src/main/resources/META-INF/angelica_at.cfg index 792c4f41c..6394fdbeb 100644 --- a/src/main/resources/META-INF/angelica_at.cfg +++ b/src/main/resources/META-INF/angelica_at.cfg @@ -8,6 +8,8 @@ public net.minecraft.client.renderer.EntityRenderer field_78503_V # cameraZoom public net.minecraft.client.renderer.EntityRenderer field_78502_W # cameraYaw public net.minecraft.client.renderer.EntityRenderer field_78509_X # cameraPitch public net.minecraft.client.renderer.EntityRenderer field_78530_s # farPlaneDistance +public net.minecraft.client.renderer.EntityRenderer field_78527_v # mouseFilterXAxis +public net.minecraft.client.renderer.EntityRenderer field_78526_w # mouseFilterYAxis public net.minecraft.client.renderer.RenderGlobal field_72765_l # worldRenderers diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinEntityRenderer_Zoom.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinEntityRenderer_Zoom.java new file mode 100644 index 000000000..4cdc5e5cb --- /dev/null +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinEntityRenderer_Zoom.java @@ -0,0 +1,30 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.zoom; + +import com.gtnewhorizons.angelica.zoom.Zoom; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.client.renderer.EntityRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Mixin(EntityRenderer.class) +public class MixinEntityRenderer_Zoom { + + @ModifyReturnValue(method = "getFOVModifier", at = @At("RETURN")) + private float angelica$modifyFOV(float original) { + if (Zoom.getZoomKey().getIsKeyPressed()) { + return original / Zoom.getZoom(); + } + return original; + } + + @ModifyConstant(method = "updateCameraAndRender", constant = @Constant(floatValue = 8.0F)) + private float angelica$modifyMouseSensitivity(float original) { + if (Zoom.getZoomKey().getIsKeyPressed()) { + return original / (1.0F + 0.2F * (Zoom.getZoom() - Zoom.ZOOM_MIN)); + } + return original; + } + +} diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMinecraft_Zoom.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMinecraft_Zoom.java new file mode 100644 index 000000000..799d0e750 --- /dev/null +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMinecraft_Zoom.java @@ -0,0 +1,21 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.zoom; + +import com.gtnewhorizons.angelica.zoom.Zoom; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(Minecraft.class) +public class MixinMinecraft_Zoom { + + @ModifyExpressionValue(method = "runTick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I", remap = false)) + private int angelica$captureMouseWheel(int original) { + if (Zoom.getZoomKey().getIsKeyPressed()) { + Zoom.modifyZoom(original); + return 0; + } + return original; + } + +} diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMouseFilter.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMouseFilter.java new file mode 100644 index 000000000..7e03fe2b9 --- /dev/null +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/zoom/MixinMouseFilter.java @@ -0,0 +1,26 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.zoom; + +import com.gtnewhorizons.angelica.zoom.IMouseFilterExt; +import net.minecraft.util.MouseFilter; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(MouseFilter.class) +public class MixinMouseFilter implements IMouseFilterExt { + + @Shadow + private float field_76336_a; + + @Shadow + private float field_76334_b; + + @Shadow + private float field_76335_c; + + @Override + public void angelica$reset() { + this.field_76336_a = 0.0F; + this.field_76334_b = 0.0F; + this.field_76335_c = 0.0F; + } +}