Skip to content

Commit

Permalink
Begin work on The Rebirth Update
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Dec 8, 2024
1 parent 3a70b0d commit 8de2c0b
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ public enum ZoomModes implements ConfigEnum {
PERSISTENT
}

public enum ScrollingModes implements ConfigEnum {
EXPONENTIAL,
LEGACY
}

public enum ZoomOverlays implements ConfigEnum {
OFF,
VIGNETTE,
SPYGLASS
}

public enum SpyglassMode implements ConfigEnum {
public enum SpyglassModes implements ConfigEnum {
OFF,
REQUIRE_ITEM,
REPLACE_ZOOM,
BOTH
}

public enum SeeDistantEntitiesModes implements ConfigEnum {
OFF,
SAFE,
ON
}

public enum ZoomPresets implements ConfigEnum {
CAMERA,
COMPETITIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public class OkZoomerConfig extends ReflectiveConfig {
@Comment("Allows for configuring the main zoom features.")
public final FeaturesConfig features = new FeaturesConfig();

@Alias("values")
@Comment("Allows for precise tweaking of the zoom.")
public final ZoomValuesConfig zoomValues = new ZoomValuesConfig();

@Alias("values")
@Comment("Allows to configure the \"Legacy\" scrolling mode.")
public final LegacyScrollValuesConfig legacyScrollValues = new LegacyScrollValuesConfig();

@Comment("Allows for precise tweaking of zoom transitions.")
public final TransitionValuesConfig transitionValues = new TransitionValuesConfig();

Expand Down Expand Up @@ -61,6 +62,13 @@ public static class FeaturesConfig extends Section {
@Comment("Allows to increase or decrease the zoom by scrolling with the mouse wheel.")
public final TrackedValue<Boolean> zoomScrolling = this.value(true);

@WidgetSize(Size.HALF)
@Comment("""
"EXPONENTIAL": The zoom will scroll in an exponential way, making zoom steps consistent. This may be harder to configure currently.
"LEGACY": The zoom will scroll in an arbitrary way. This may be easier to configure currently, but scrolling may feel harder on higher zoom levels.
""")
public final TrackedValue<ScrollingModes> scrollingMode = this.value(ScrollingModes.EXPONENTIAL);

@WidgetSize(Size.HALF)
@Comment("Retains the interface when zooming.")
public final TrackedValue<Boolean> persistentInterface = this.value(false);
Expand All @@ -85,10 +93,37 @@ public static class FeaturesConfig extends Section {
"REPLACE_ZOOM": Zooming will replace the spyglass zoom but it won't require one in order to work.
"BOTH": Zooming will act as a complete replacement of the spyglass zoom, requiring one to work and replacing its zoom as well.
""")
public final TrackedValue<SpyglassMode> spyglassMode = this.value(SpyglassMode.OFF);
public final TrackedValue<SpyglassModes> spyglassMode = this.value(SpyglassModes.OFF);
}

public static class ZoomValuesConfig extends Section {
@WidgetSize(Size.HALF)
@Comment("Determines the number to be used on the exponential curve. If unsure, keep this value at 2.")
@IntegerRange(min = 2, max = Integer.MAX_VALUE)
public final TrackedValue<Integer> scrollBase = this.value(2);

@WidgetSize(Size.HALF)
@Comment("Determines the resolution of zoom scrolling. This will effectively multiply the amount of scroll steps.")
@IntegerRange(min = 1, max = Integer.MAX_VALUE)
public final TrackedValue<Integer> scrollResolution = this.value(5);

@WidgetSize(Size.HALF)
@Comment("The default scroll step to use on zooming in.")
@IntegerRange(min = 0, max = Integer.MAX_VALUE)
public final TrackedValue<Integer> defaultScrollStep = this.value(10);

@WidgetSize(Size.HALF)
@Comment("The maximum amount of scroll steps that the zoom may reach.")
@IntegerRange(min = 0, max = Integer.MAX_VALUE)
public final TrackedValue<Integer> scrollStepLimit = this.value(30);

@WidgetSize(Size.HALF)
@Comment("The multiplier used by the multiplied cinematic camera.")
@FloatRange(min = Double.MIN_NORMAL, max = 32.0)
public final TrackedValue<Double> cinematicMultiplier = this.value(4.0);
}

public static class LegacyScrollValuesConfig extends Section {
@WidgetSize(Size.HALF)
@Comment("The divisor used to apply zoom to the FOV. A higher value means more zoom.")
@FloatRange(min = Double.MIN_NORMAL, max = Double.MAX_VALUE)
Expand All @@ -113,11 +148,6 @@ public static class ZoomValuesConfig extends Section {
@Comment("The number of steps between the zoom divisor and the maximum zoom divisor. Used by zoom scrolling.")
@IntegerRange(min = 0, max = Integer.MAX_VALUE)
public final TrackedValue<Integer> upperScrollSteps = this.value(10);

@WidgetSize(Size.HALF)
@Comment("The multiplier used for the multiplied cinematic camera.")
@FloatRange(min = Double.MIN_NORMAL, max = 32.0)
public final TrackedValue<Double> cinematicMultiplier = this.value(4.0);
}

public static class TransitionValuesConfig extends Section {
Expand All @@ -128,14 +158,9 @@ public static class TransitionValuesConfig extends Section {
public final TrackedValue<Double> smoothTransitionFactor = this.value(0.6);

@WidgetSize(Size.HALF)
@Comment("The minimum value which the linear zoom transition step can reach.")
@Comment("The value which the linear zoom transition step can reach.")
@FloatRange(min = 0.0, max = Double.MAX_VALUE)
public final TrackedValue<Double> minimumLinearStep = this.value(0.16);

@WidgetSize(Size.HALF)
@Comment("The maximum value which the linear zoom transition step can reach.")
@FloatRange(min = 0.0, max = Double.MAX_VALUE)
public final TrackedValue<Double> maximumLinearStep = this.value(0.22);
public final TrackedValue<Double> linearStep = this.value(0.2);
}

public static class TweaksConfig extends Section {
Expand All @@ -152,9 +177,13 @@ public static class TweaksConfig extends Section {
public final TrackedValue<Boolean> resetZoomWithMouse = this.value(true);

@WidgetSize(Size.HALF)
@Comment("Improves performance by making the game render less of the world while zoomed in. This feature requires the Sodium mod in order to work.")
@Comment("Improves performance by making the game render less of the world while zoomed in. This feature depends on the Sodium mod in order to work.")
public final TrackedValue<Boolean> smartOcclusion = this.value(true);

@WidgetSize(Size.HALF)
@Comment("Expands the entity distance while zooming in, allowing creatures and certain blocks to be seen from afar. This may have a performance impact during zoom.")
public final TrackedValue<SeeDistantEntitiesModes> seeDistantEntities = this.value(SeeDistantEntitiesModes.SAFE);

@WidgetSize(Size.HALF)
@Comment("If enabled, the current zoom divisor is forgotten once zooming is finished.")
public final TrackedValue<Boolean> forgetZoomDivisor = this.value(true);
Expand All @@ -163,6 +192,10 @@ public static class TweaksConfig extends Section {
@Comment("If enabled, the zoom will use spyglass sounds on zooming in and out.")
public final TrackedValue<Boolean> useSpyglassSounds = this.value(false);

@WidgetSize(Size.HALF)
@Comment("Displays debug information for exponential zoom scrolling. Currently it may help with configuring the zoom scrolling.")
public final TrackedValue<Boolean> debugScrolling = this.value(false);

// TODO - Disable it upon stable release!
@WidgetSize(Size.HALF)
@Comment("Prints a random owo in the console when the game starts.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package io.github.ennuil.ok_zoomer.config;

import io.github.ennuil.ok_zoomer.config.ConfigEnums.CinematicCameraOptions;
import io.github.ennuil.ok_zoomer.utils.ModUtils;
import io.github.ennuil.ok_zoomer.wrench_wrapper.WrenchWrapper;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import io.github.ennuil.ok_zoomer.zoom.modifiers.CinematicCameraMouseModifier;
import io.github.ennuil.ok_zoomer.zoom.modifiers.ContainingMouseModifier;
import io.github.ennuil.ok_zoomer.zoom.modifiers.MultipliedCinematicCameraMouseModifier;
import io.github.ennuil.ok_zoomer.zoom.modifiers.ZoomDivisorMouseModifier;
import io.github.ennuil.ok_zoomer.zoom.overlays.SpyglassZoomOverlay;
import io.github.ennuil.ok_zoomer.zoom.overlays.ZoomerZoomOverlay;
import io.github.ennuil.ok_zoomer.zoom.transitions.InstantTransitionMode;
import io.github.ennuil.ok_zoomer.zoom.transitions.SmoothTransitionMode;
import io.github.ennuil.ok_zoomer.config.ConfigEnums.CinematicCameraOptions;
import io.github.ennuil.ok_zoomer.utils.ModUtils;
import io.github.ennuil.ok_zoomer.wrench_wrapper.WrenchWrapper;
import io.github.ennuil.ok_zoomer.zoom.transitions.LinearTransitionMode;
import io.github.ennuil.ok_zoomer.zoom.modifiers.MultipliedCinematicCameraMouseModifier;
import io.github.ennuil.ok_zoomer.zoom.overlays.ZoomerZoomOverlay;
import io.github.ennuil.ok_zoomer.zoom.transitions.SmoothTransitionMode;
import net.minecraft.resources.ResourceLocation;

public class OkZoomerConfigManager {
Expand All @@ -30,16 +30,13 @@ public static void configureZoomInstance() {
Zoom.setTransitionMode(
switch (CONFIG.features.zoomTransition.value()) {
case SMOOTH -> new SmoothTransitionMode(CONFIG.transitionValues.smoothTransitionFactor.value().floatValue());
case LINEAR -> new LinearTransitionMode(CONFIG.transitionValues.minimumLinearStep.value(), CONFIG.transitionValues.maximumLinearStep.value());
case LINEAR -> new LinearTransitionMode(CONFIG.transitionValues.linearStep.value());
default -> new InstantTransitionMode();
}
);

// Sets zoom divisor
Zoom.setDefaultZoomDivisor(CONFIG.zoomValues.zoomDivisor.value());

// Sets mouse modifier
configureZoomModifier();
OkZoomerConfigManager.configureZoomModifier();

// Sets zoom overlay
// TODO - Restore the "Use Spyglass Texture" option as a "Use Custom Texture" option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public class ZoomPresets {
public static final Map<TrackedValue<?>, Object> PERSISTENT = Map.of(
OkZoomerConfigManager.CONFIG.features.zoomMode, ConfigEnums.ZoomModes.PERSISTENT,
OkZoomerConfigManager.CONFIG.features.persistentInterface, true,
OkZoomerConfigManager.CONFIG.zoomValues.zoomDivisor, 1.0,
OkZoomerConfigManager.CONFIG.zoomValues.lowerScrollSteps, 0,
OkZoomerConfigManager.CONFIG.zoomValues.upperScrollSteps, 38,
OkZoomerConfigManager.CONFIG.zoomValues.defaultScrollStep, 0,
OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair, false
);

Expand All @@ -40,10 +38,14 @@ public class ZoomPresets {
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomScrolling, false),
Map.entry(OkZoomerConfigManager.CONFIG.features.persistentInterface, true),
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomOverlay, ConfigEnums.ZoomOverlays.SPYGLASS),
Map.entry(OkZoomerConfigManager.CONFIG.features.spyglassMode, ConfigEnums.SpyglassMode.BOTH),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.zoomDivisor, 10.0),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.lowerScrollSteps, 8),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.upperScrollSteps, 16),
Map.entry(OkZoomerConfigManager.CONFIG.features.spyglassMode, ConfigEnums.SpyglassModes.BOTH),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.scrollBase, 10),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.scrollResolution, 10),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.defaultScrollStep, 10),
Map.entry(OkZoomerConfigManager.CONFIG.zoomValues.scrollStepLimit, 20),
Map.entry(OkZoomerConfigManager.CONFIG.legacyScrollValues.zoomDivisor, 10.0),
Map.entry(OkZoomerConfigManager.CONFIG.legacyScrollValues.lowerScrollSteps, 8),
Map.entry(OkZoomerConfigManager.CONFIG.legacyScrollValues.upperScrollSteps, 16),
Map.entry(OkZoomerConfigManager.CONFIG.transitionValues.smoothTransitionFactor, 0.5),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair, false),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.useSpyglassSounds, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public static void startClientTick(Minecraft minecraft) {
if (!OkZoomerConfigManager.CONFIG.features.extraKeyBinds.value()) return;

if (ZoomKeyBinds.DECREASE_ZOOM_KEY.isDown() && !ZoomKeyBinds.INCREASE_ZOOM_KEY.isDown()) {
ZoomUtils.changeZoomDivisor(minecraft, false);
ZoomUtils.changeZoomDivisor(false);
}

if (ZoomKeyBinds.INCREASE_ZOOM_KEY.isDown() && !ZoomKeyBinds.DECREASE_ZOOM_KEY.isDown()) {
ZoomUtils.changeZoomDivisor(minecraft, true);
ZoomUtils.changeZoomDivisor(true);
}

if (ZoomKeyBinds.RESET_ZOOM_KEY.isDown()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import io.github.ennuil.ok_zoomer.utils.ZoomUtils;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.util.Mth;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(BlockEntityRenderer.class)
public interface BlockEntityRendererMixin {
@WrapMethod(method = "getViewDistance")
private int modifyBlockEntityViewDistance(Operation<Integer> original) {
if (!ZoomUtils.canSeeDistantEntities()) {
return original.call();
} else {
return original.call() * (Zoom.isZooming() ? Math.max(1, Mth.ceil(Zoom.getZoomDivisor())) : 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private int modifyCulling(int original) {
if (!Zoom.isZooming() || !ZoomUtils.hasSmartOcclusion()) {
return original;
} else {
return Mth.positiveCeilDiv(original, Mth.floor(Zoom.getZoomDivisor()));
return Mth.positiveCeilDiv(original, Math.max(1, Mth.floor(Zoom.getZoomDivisor())));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import io.github.ennuil.ok_zoomer.utils.ZoomUtils;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.util.Mth;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(IntegratedServer.class)
public abstract class IntegratedServerMixin {
@WrapMethod(method = "getScaledTrackingDistance")
private int modifyEntityViewDistance(int trackingDistance, Operation<Integer> original) {
if (!ZoomUtils.canSeeDistantEntities()) {
return original.call(trackingDistance);
} else {
return original.call(trackingDistance * (Zoom.isZooming() ? Math.max(1, Mth.ceil(Zoom.getZoomDivisor())) : 1));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.ennuil.ok_zoomer.mixin.common;

import io.github.ennuil.ok_zoomer.utils.ZoomUtils;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.renderer.LevelRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(LevelRenderer.class)
public abstract class LevelRendererMixin {
@ModifyArg(
method = "collectVisibleEntities",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/Entity;setViewScale(D)V"
)
)
private double modifyViewScale(double original) {
if (!ZoomUtils.canSeeDistantEntities()) {
return original;
} else {
return original * Math.max(1.0, Zoom.isZooming() ? Zoom.getZoomDivisor() : 1.0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
// This mixin is responsible for the mouse-behavior-changing part of the zoom
@Mixin(MouseHandler.class)
public abstract class MouseHandlerMixin {
@Shadow
@Final
private Minecraft minecraft;

// Handles zoom scrolling
@Inject(
method = "onScroll",
Expand All @@ -38,7 +34,7 @@ private void zoomerOnMouseScroll(CallbackInfo ci, @Local int k) {
}

if (Zoom.isZooming()) {
ZoomUtils.changeZoomDivisor(this.minecraft, k > 0);
ZoomUtils.changeZoomDivisor(k > 0);
ci.cancel();
}
}
Expand Down
Loading

0 comments on commit 8de2c0b

Please sign in to comment.