Skip to content

Commit

Permalink
Zoom (#724)
Browse files Browse the repository at this point in the history
Co-authored-by: kurrycat <44340227+kurrycat2004@users.noreply.github.com>
  • Loading branch information
Alexdoru and kurrycat2004 authored Nov 8, 2024
1 parent 0e4421f commit 7fb8cde
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@

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;
import net.minecraft.client.gui.ScaledResolution;
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;
Expand Down Expand Up @@ -70,31 +66,6 @@ public class HUDCaching {

private HUDCaching() {}

/* TODO START REMOVE DEBUG STUFF */

private final List<Long> 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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -130,14 +130,17 @@ 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();

if (ModStatus.isBetterCrashesLoaded) {
BetterCrashesCompat.init();
}
if (AngelicaConfig.enableZoom) {
Zoom.init();
}
}

private boolean wasGLSMKeyPressed;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.gtnewhorizons.angelica.zoom;

public interface IMouseFilterExt {
void angelica$reset();
}
53 changes: 53 additions & 0 deletions src/main/java/com/gtnewhorizons/angelica/zoom/Zoom.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/angelica_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7fb8cde

Please sign in to comment.