Skip to content

Commit

Permalink
Replace getZoomedFov with a lighter variant
Browse files Browse the repository at this point in the history
It turns out you can't really lose precision with floats!
(no this won't fix tweakeroo, tweakeroo needs fixing)
  • Loading branch information
EnnuiL committed Oct 24, 2024
1 parent fa0c421 commit 3e12565
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.util.Mth;
import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@ClientOnly
@Mixin(GameRenderer.class)
Expand Down Expand Up @@ -49,22 +47,13 @@ private int modifyCulling(int original) {
}
}

@Inject(
method = "getFov",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/Camera;getEntity()Lnet/minecraft/world/entity/Entity;",
ordinal = 0
)
)
private void getZoomedFov(Camera activeRenderInfo, float partialTicks, boolean useFOVSetting, CallbackInfoReturnable<Float> cir, @Local(ordinal = 1) LocalFloatRef internalFov) {
float zoomedFov = internalFov.get();

if (Zoom.isTransitionActive()) {
zoomedFov = Zoom.getTransitionMode().applyZoom(zoomedFov, partialTicks);
@ModifyReturnValue(method = "getFov", at = @At(value = "RETURN", ordinal = 1))
private float modifyFov(float original, @Local(argsOnly = true) float partialTicks) {
if (!Zoom.isTransitionActive()) {
return original;
} else {
return Zoom.getTransitionMode().applyZoom(original, partialTicks);
}

internalFov.set(zoomedFov);
}

@ModifyExpressionValue(method = "bobView", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;lerp(FFF)F"))
Expand Down

0 comments on commit 3e12565

Please sign in to comment.