forked from Sk1erLLC/Patcher
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "removed all zoom features and added rawinput"
This reverts commit c4567ac.
- Loading branch information
Showing
6 changed files
with
220 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...main/java/club/sk1er/patcher/mixins/features/optifine/EntityRendererMixin_ZoomTweaks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
src/main/java/club/sk1er/patcher/mixins/features/rawinput/MouseHelperMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.