Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions forge.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@

**However, there is nothing stopping you from doing it yourself by forking the project,**
**but please do not call it an official port. Make it clear it is unsupported by us.**


## UNSUPPORTED

**It is possible to run FoxClient on Forge/NeoForge\* with [Sinytra Connector](https://modrinth.com/mod/connector) and [Forgified Fabric API](https://modrinth.com/mod/forgified-fabric-api)**

**For ModMenu support, you can also drop the corresponding ModMenu jar into your mods folder**

\* <sup>*This is not officially supported by us, so if anything breaks, please do not open an issue here*</sup>
28 changes: 18 additions & 10 deletions src/main/java/net/foxes4life/foxclient/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;


@Mixin(GameRenderer.class)
public class GameRendererMixin {
@Inject(at = @At("TAIL"), method = "getFov", cancellable = true)
private void getFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Double> cir) {
@Inject(method = "getFov", at = @At("TAIL"), cancellable = true)
private void onGetFov(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Double> cir) {
double baseFov = cir.getReturnValue();

// Handle key state and smooth camera toggle
ZoomUtils.smoothCam();

// Set the desired target zoom level based on key state
if (ZoomUtils.zoomin()) {
ZoomUtils.currentZoomLevel = cir.getReturnValue() * ZoomUtils.zoomModifier;
ZoomUtils.calculateZoom();
cir.setReturnValue(ZoomUtils.actualZoomLevel);
ZoomUtils.currentZoomLevel = baseFov * ZoomUtils.zoomedFov;
} else {
ZoomUtils.zoomModifier = 0.2F;
ZoomUtils.currentZoomLevel = cir.getReturnValue();
ZoomUtils.actualZoomLevel = cir.getReturnValue();
ZoomUtils.currentZoomLevel = baseFov;
}
ZoomUtils.smoothCam();

// Smoothly interpolate toward target
ZoomUtils.calculateZoom();

// Override FOV with interpolated zoom value
cir.setReturnValue(ZoomUtils.actualZoomLevel);
}
}
}
15 changes: 10 additions & 5 deletions src/main/java/net/foxes4life/foxclient/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

@Mixin(Mouse.class)
public class MouseMixin {
@Inject(at = @At("HEAD"), method = "onMouseScroll", cancellable = true)
@Inject(method = "onMouseScroll", at = @At("HEAD"), cancellable = true)
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) {
if (ZoomUtils.zoomin()) {
ci.cancel();
ci.cancel(); // Prevent default scroll behavior while zooming

// Adjust zoomed FOV modifier within safe bounds
if (vertical > 0) {
if (!(ZoomUtils.zoomModifier < 0.1)) ZoomUtils.zoomModifier -= 0.05;
ZoomUtils.zoomedFov = Math.max(0.05F, ZoomUtils.zoomedFov - 0.05F);
} else {
if (!(ZoomUtils.zoomModifier > 1)) ZoomUtils.zoomModifier += 0.05;
ZoomUtils.zoomedFov = Math.min(1.0F, ZoomUtils.zoomedFov + 0.05F);
}

// Update target zoom level to reflect scroll
ZoomUtils.currentZoomLevel = ZoomUtils.actualZoomLevel * ZoomUtils.zoomedFov;
}
}
}
}
39 changes: 24 additions & 15 deletions src/main/java/net/foxes4life/foxclient/util/ZoomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,46 @@

public class ZoomUtils {
private static final KeyBinding zoomKey = new KeyBinding("key.foxclient.zoom", GLFW.GLFW_KEY_C, "category.foxclient.main");
static boolean isZoomin = false;
public static float zoomModifier = 0.2F;
public static double currentZoomLevel = 0.2F;
public static double actualZoomLevel = 0.2F;
public static boolean isZoomin = false;

public static float zoomedFovDefault = 0.2F;
public static float zoomedFov = 0.2F; // Zoomed-in FOV scale
public static float defaultFov = 1.0F; // Normal FOV scale

public static double currentZoomLevel = 1.0F; // The target zoom level
public static double actualZoomLevel = 1.0F; // The lerped FOV value

public static void initZoom() {
KeyBindingHelper.registerKeyBinding(zoomKey);
isZoomin = false;
}

public static boolean zoomin() {
return zoomKey.isPressed();
}

public static void smoothCam() {
//start holdin
if (zoomin() && !isZoomin) {
isZoomin = true;
MinecraftClient.getInstance().options.smoothCameraEnabled = true;
}
if (zoomin()) {
if (!isZoomin) {
isZoomin = true;
MinecraftClient.getInstance().options.smoothCameraEnabled = true;
}

//stop holdin
if (!zoomin() && isZoomin) {
isZoomin = false;
MinecraftClient.getInstance().options.smoothCameraEnabled = false;
currentZoomLevel = zoomedFov;
} else {
if (isZoomin) {
isZoomin = false;
MinecraftClient.getInstance().options.smoothCameraEnabled = false;

zoomedFov = zoomedFovDefault;
}
currentZoomLevel = defaultFov;
}
}


public static void calculateZoom() {
ZoomUtils.actualZoomLevel = Main.config.get(FoxClientSetting.SmoothZoom, Boolean.class) ?
MathHelper.lerp(0.05f, ZoomUtils.actualZoomLevel, ZoomUtils.currentZoomLevel) :
MathHelper.lerp(0.1f, (float) actualZoomLevel, (float) currentZoomLevel) :
ZoomUtils.currentZoomLevel;
}
}
Loading