Fix Zoom
This commit is contained in:
parent
5c3efb5506
commit
ae20d5c99d
@ -1,2 +1,58 @@
|
|||||||
package tech.nevets.vplus.init;public class ZoomInit {
|
package tech.nevets.vplus.init;
|
||||||
|
|
||||||
|
import static tech.nevets.vplus.misc.VPZoom.*;
|
||||||
|
|
||||||
|
public class ZoomInit {
|
||||||
|
public static Boolean isZooming() {
|
||||||
|
return keyBinding.isPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void manageSmoothCamera() {
|
||||||
|
if (zoomStarting()) {
|
||||||
|
zoomStarted();
|
||||||
|
enableSmoothCamera();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zoomStopping()) {
|
||||||
|
zoomStopped();
|
||||||
|
resetSmoothCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean isSmoothCamera() {
|
||||||
|
return mc.options.smoothCameraEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void enableSmoothCamera() {
|
||||||
|
mc.options.smoothCameraEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void disableSmoothCamera() {
|
||||||
|
mc.options.smoothCameraEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean zoomStarting() {
|
||||||
|
return isZooming() && !currentlyZoomed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean zoomStopping() {
|
||||||
|
return !isZooming() && currentlyZoomed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void zoomStarted() {
|
||||||
|
originalSmoothCameraEnabled = isSmoothCamera();
|
||||||
|
currentlyZoomed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void zoomStopped() {
|
||||||
|
currentlyZoomed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetSmoothCamera() {
|
||||||
|
if (originalSmoothCameraEnabled) {
|
||||||
|
enableSmoothCamera();
|
||||||
|
} else {
|
||||||
|
disableSmoothCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package tech.nevets.vplus.misc;
|
package tech.nevets.vplus.misc;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.option.KeyBinding;
|
||||||
@ -14,8 +12,8 @@ public class VPZoom {
|
|||||||
public static KeyBinding keyBinding;
|
public static KeyBinding keyBinding;
|
||||||
public static Boolean originalSmoothCameraEnabled;
|
public static Boolean originalSmoothCameraEnabled;
|
||||||
public static final MinecraftClient mc = MinecraftClient.getInstance();
|
public static final MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
public static final double zoomLevel = 19.0;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public static void vpZoom() {
|
public static void vpZoom() {
|
||||||
keyBinding = new KeyBinding("key.vplus.zoom", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, "category.vplus.zoom");
|
keyBinding = new KeyBinding("key.vplus.zoom", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, "category.vplus.zoom");
|
||||||
currentlyZoomed = false;
|
currentlyZoomed = false;
|
||||||
|
@ -1,2 +1,23 @@
|
|||||||
package tech.nevets.vplus.mixin;public class ZoomMixin {
|
package tech.nevets.vplus.mixin;
|
||||||
|
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.render.GameRenderer;
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
import tech.nevets.vplus.init.ZoomInit;
|
||||||
|
import tech.nevets.vplus.misc.VPZoom;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
@Mixin(GameRenderer.class)
|
||||||
|
public class ZoomMixin {
|
||||||
|
@Inject(method = "getFov(Lnet/minecraft/client/render/Camera;FZ)D", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void getZoomLevel(CallbackInfoReturnable<Double> callbackInfo) {
|
||||||
|
if(ZoomInit.isZooming()) {
|
||||||
|
callbackInfo.setReturnValue(VPZoom.zoomLevel);
|
||||||
|
}
|
||||||
|
ZoomInit.manageSmoothCamera();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"package": "tech.nevets.vplus.mixin",
|
"package": "tech.nevets.vplus.mixin",
|
||||||
"compatibilityLevel": "JAVA_16",
|
"compatibilityLevel": "JAVA_16",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"ZoomMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user