Skip to content

Commit

Permalink
Revert "removed all zoom features and added rawinput"
Browse files Browse the repository at this point in the history
This reverts commit c4567ac.
  • Loading branch information
ImToggle committed Feb 5, 2024
1 parent 699a399 commit a43c8c4
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 168 deletions.
49 changes: 49 additions & 0 deletions src/main/java/club/sk1er/patcher/hooks/EntityRendererHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@
@SuppressWarnings("unused")
public class EntityRendererHook {
private static final Minecraft mc = Minecraft.getMinecraft();
private static boolean zoomToggled = false;
private static boolean isBeingHeld = false;
private static float oldSensitivity;
private static float partialTicks;
public static float lastZoomModifier;

public static void fixMissingChunks() {
mc.renderGlobal.setDisplayListEntitiesDirty();
}

public static boolean getZoomState(boolean zoomKeyDown) {
if (zoomKeyDown) {
if (isBeingHeld) return zoomToggled;
isBeingHeld = true;
zoomToggled = !zoomToggled;
} else {
isBeingHeld = false;
}
return zoomToggled;
}

public static boolean hasMap() {
if (!PatcherConfig.mapBobbing || mc.thePlayer == null) return false;
//#if MC==10809
Expand All @@ -34,6 +50,39 @@ public static boolean hasMap() {
//#endif
}

public static void reduceSensitivityWhenZoomStarts() {
oldSensitivity = mc.gameSettings.mouseSensitivity;
mc.gameSettings.mouseSensitivity = oldSensitivity * PatcherConfig.customZoomSensitivity;
}

public static void reduceSensitivityDynamically(float modifier) {
if (!PatcherConfig.dynamicZoomSensitivity || !ZoomHook.zoomed) return;
float sensitivity = oldSensitivity * PatcherConfig.customZoomSensitivity;
sensitivity *= modifier / lastZoomModifier;
mc.gameSettings.mouseSensitivity = sensitivity;
}

public static void resetSensitivity() {
mc.gameSettings.mouseSensitivity = oldSensitivity;
}

public static float getHandFOVModifier(float original) {
if (PatcherConfig.renderHandWhenZoomed && (ZoomHook.zoomed || (PatcherConfig.smoothZoomAnimation && ZoomHook.smoothZoomProgress > 0))) {
float f = 70f;
//#if MC==10809
Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(mc.theWorld, mc.thePlayer, partialTicks);
//#else
//$$ IBlockState block = ActiveRenderInfo.getBlockStateAtEntityViewpoint(mc.world, mc.player, partialTicks);
//#endif

if (block.getMaterial() == Material.water) {
f = f * 60.0F / 70.0F;
}
return f;
}
return original;
}

@SubscribeEvent
public void worldRender(RenderWorldLastEvent event) {
//#if MC==10809
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/club/sk1er/patcher/hooks/MouseHelperHook.java

This file was deleted.

115 changes: 115 additions & 0 deletions src/main/java/club/sk1er/patcher/hooks/ZoomHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package club.sk1er.patcher.hooks;

import cc.polyfrost.oneconfig.libs.elementa.constraints.animation.Animations;
import club.sk1er.patcher.config.PatcherConfig;
import org.lwjgl.input.Mouse;

public class ZoomHook {
private static final float normalModifier = 4f;
private static float currentModifier = normalModifier;
private static boolean hasScrolledYet = false;
private static long lastMillis = System.currentTimeMillis();
private static float desiredModifier = currentModifier;

public static boolean zoomed = false;
public static float smoothZoomProgress = 0f;

public static float getScrollZoomModifier() {
if (!PatcherConfig.scrollToZoom) {
return normalModifier;
}
long time = System.currentTimeMillis();
long timeSinceLastChange = time - lastMillis;
if (!zoomed) lastMillis = time;

int moved = Mouse.getDWheel();

if (moved > 0) {
smoothZoomProgress = 0f;
hasScrolledYet = true;
desiredModifier += 0.25f * desiredModifier;
} else if (moved < 0) {
smoothZoomProgress = 0f;
hasScrolledYet = true;
desiredModifier -= 0.25f * desiredModifier;
EntityRendererHook.fixMissingChunks();
}

if (desiredModifier < 1f) {
desiredModifier = 1f;
}

if (desiredModifier > 600) {
desiredModifier = 600f;
}
if (PatcherConfig.smoothZoomAnimationWhenScrolling) {
if (hasScrolledYet && smoothZoomProgress < 1) {
EntityRendererHook.fixMissingChunks();
smoothZoomProgress += 0.004F * timeSinceLastChange;
smoothZoomProgress = smoothZoomProgress > 1 ? 1 : smoothZoomProgress;
return currentModifier += (desiredModifier - currentModifier) * calculateZoomEasing(smoothZoomProgress);
}
} else currentModifier = desiredModifier;
return desiredModifier;
}

public static float getSmoothZoomModifier() {
long time = System.currentTimeMillis();
long timeSinceLastChange = time - lastMillis;
lastMillis = time;
if (zoomed) {
if (hasScrolledYet) return 1f;
if (smoothZoomProgress < 1) {
smoothZoomProgress += 0.005F * timeSinceLastChange;
smoothZoomProgress = smoothZoomProgress > 1 ? 1 : smoothZoomProgress;
return 4f - 3f * calculateZoomEasing(smoothZoomProgress);
}
} else {
if (hasScrolledYet) {
hasScrolledYet = false;
smoothZoomProgress = 1f;
}
if (smoothZoomProgress > 0) {
smoothZoomProgress -= 0.005F * timeSinceLastChange;
smoothZoomProgress = smoothZoomProgress < 0 ? 0 : smoothZoomProgress;
EntityRendererHook.fixMissingChunks();
float progress = 1 - smoothZoomProgress;
float diff = PatcherConfig.scrollToZoom ? 1f / currentModifier : 0.25f;
return diff + (1 - diff) * calculateZoomEasing(progress);
}
}
return 1f;
}

private static float calculateZoomEasing(float x) { // todo we should add static methods for our animations too
switch (PatcherConfig.smoothZoomAlgorithm) {
case 0:
return Animations.IN_OUT_QUAD.getValue(x);

case 1:
return Animations.IN_OUT_CIRCULAR.getValue(x);

case 2:
return Animations.OUT_QUINT.getValue(x);
}

// fallback
return Animations.IN_OUT_QUAD.getValue(x);
}

public static void resetZoomState() {
hasScrolledYet = false;
currentModifier = normalModifier;
desiredModifier = normalModifier;
smoothZoomProgress = 0f;
}

public static void handleZoomStateChange(boolean newZoomed) {
if (newZoomed && !zoomed) {
Mouse.getDWheel();
} else if (!newZoomed && zoomed) {
EntityRendererHook.resetSensitivity();
}
zoomed = newZoomed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package club.sk1er.patcher.mixins.features.optifine;

import club.sk1er.patcher.config.PatcherConfig;
import club.sk1er.patcher.hooks.EntityRendererHook;
import club.sk1er.patcher.hooks.ZoomHook;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin_ZoomTweaks {
@Dynamic("OptiFine")
@Redirect(method = "getFOVModifier", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;smoothCamera:Z", opcode = Opcodes.PUTFIELD, ordinal = 0))
private void patcher$cancelSmoothCameraAndHandleZoom(GameSettings instance, boolean value) {
if (!PatcherConfig.normalZoomSensitivity) {
instance.smoothCamera = value;
}
ZoomHook.resetZoomState();
EntityRendererHook.reduceSensitivityWhenZoomStarts();
}

@Dynamic("OptiFine")
@ModifyConstant(method = "getFOVModifier", constant = @Constant(floatValue = 4f))
private float patcher$handleScrollZoom(float originalDivisor) {
return EntityRendererHook.lastZoomModifier = ZoomHook.getScrollZoomModifier();
}

@Dynamic("OptiFine")
@ModifyVariable(method = "getFOVModifier", name = "zoomActive", at = @At(value = "LOAD", ordinal = 0))
private boolean patcher$handleZoomStateChanged(boolean zoomActive) {
ZoomHook.handleZoomStateChange(zoomActive);
return zoomActive;
}

@Dynamic("OptiFine")
@Redirect(method = "getFOVModifier", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/settings/GameSettings;isKeyDown(Lnet/minecraft/client/settings/KeyBinding;)Z"))
private boolean patcher$handleToggleToZoom(KeyBinding zoomKey) {
boolean keyDown = GameSettings.isKeyDown(zoomKey);
if (PatcherConfig.toggleToZoom) {
return EntityRendererHook.getZoomState(keyDown);
}
return keyDown;
}

@Dynamic("OptiFine")
@ModifyVariable(method = "getFOVModifier", name = "f", at = @At(value = "FIELD", target = "Lnet/optifine/reflect/Reflector;ForgeHooksClient_getFOVModifier:Lnet/optifine/reflect/ReflectorMethod;", opcode = Opcodes.GETSTATIC, ordinal = 0, remap = false))
private float patcher$handleSmoothZoom(float f) {
float modifier = PatcherConfig.smoothZoomAnimation ? ZoomHook.getSmoothZoomModifier() : 1f;
EntityRendererHook.reduceSensitivityDynamically(modifier);
return f * modifier;
}
}

This file was deleted.

Loading

0 comments on commit a43c8c4

Please sign in to comment.