Skip to content

Commit

Permalink
Begin 10.0.0 cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Oct 15, 2024
1 parent ec71133 commit 3e156a7
Show file tree
Hide file tree
Showing 28 changed files with 343 additions and 275 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ loom {
}
}

// Mixin plugin needs this
mixin {
useLegacyMixinAp = false
useLegacyMixinAp = true
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ minecraft = "1.21.1"
parchment = "2024.07.28"

quilt_loom = "1.7.4"
quilt_loader = "0.26.4+local"
quilt_loader = "0.26.4"

fabric_api = "0.105.0+1.21.1"
wrench_wrapper = "0.4.0"
wrench_wrapper = "0.5.0"
modmenu = "11.0.3"

trinkets = "3.10.0"
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/io/github/ennuil/ok_zoomer/OkZoomerMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.ennuil.ok_zoomer;

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

// TODO - Demolish this mixin plugin by doing a real port!
public class OkZoomerMixinPlugin implements IMixinConfigPlugin {
private static final Logger LOGGER = LoggerFactory.getLogger("Ok Zoomer Mixins");
private static String mixinPackage;

@Override
public void onLoad(String mixinPackage) {
OkZoomerMixinPlugin.mixinPackage = mixinPackage;
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.startsWith(mixinPackage)) {
var id = mixinClassName.substring(mixinPackage.length());
id = id.substring(1, id.indexOf('.', 1));

boolean connectorLoaded = FabricLoader.getInstance().isModLoaded("connector");
if (id.equals("sintyra") && connectorLoaded) {
LOGGER.warn("Loaded Sintyra-specific mixins!");
return true;
} else if (id.equals("fabric")) {
return !connectorLoaded;
}

return id.equals("common");
}

return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ 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("Retains the interface when zooming.")
public final TrackedValue<Boolean> persistentInterface = this.value(false);

@WidgetSize(Size.HALF)
@Comment("Adds zoom manipulation keys along with the zoom key. A game reboot will be required in order to apply the changes.")
public final TrackedValue<Boolean> extraKeyBinds = this.value(true);
Expand Down Expand Up @@ -135,6 +139,10 @@ public static class TweaksConfig extends Section {
@Comment("If pressed, the \"Save Toolbar Activator\" keybind will be unbound if there's a conflict with the zoom key.")
public final TrackedValue<Boolean> unbindConflictingKey = this.value(true);

@WidgetSize(Size.HALF)
@Comment("Hides the crosshair while zooming.")
public final TrackedValue<Boolean> hideCrosshair = this.value(true);

@WidgetSize(Size.HALF)
@Comment("Allows for resetting the zoom with the middle mouse button.")
public final TrackedValue<Boolean> resetZoomWithMouse = this.value(true);
Expand All @@ -151,10 +159,10 @@ public static class TweaksConfig extends Section {
@Comment("Shows toasts when the server imposes a restriction.")
public final TrackedValue<Boolean> showRestrictionToasts = this.value(true);

// TODO - Enable it again during eternal betas!
// TODO - Disable it upon stable release!
@WidgetSize(Size.HALF)
@Comment("Prints a random owo in the console when the game starts.")
public final TrackedValue<Boolean> printOwoOnStart = this.value(false);
public final TrackedValue<Boolean> printOwoOnStart = this.value(true);
}

// TODO - What if we had a secret Debug section?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public void resetToPreset(ConfigEnums.ZoomPresets preset) {
case CLASSIC, SPYGLASS -> false;
default -> true;
}),
Map.entry(OkZoomerConfigManager.CONFIG.features.persistentInterface, preset != ConfigEnums.ZoomPresets.DEFAULT),
Map.entry(OkZoomerConfigManager.CONFIG.features.extraKeyBinds, preset != ConfigEnums.ZoomPresets.CLASSIC),
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomOverlay, preset == ConfigEnums.ZoomPresets.SPYGLASS ? ConfigEnums.ZoomOverlays.SPYGLASS : ConfigEnums.ZoomOverlays.OFF),
Map.entry(OkZoomerConfigManager.CONFIG.features.spyglassMode, preset == ConfigEnums.ZoomPresets.SPYGLASS ? ConfigEnums.SpyglassMode.BOTH : ConfigEnums.SpyglassMode.OFF),
Expand Down Expand Up @@ -298,11 +299,12 @@ public void resetToPreset(ConfigEnums.ZoomPresets preset) {
Map.entry(OkZoomerConfigManager.CONFIG.transitionValues.minimumLinearStep, 0.16D),
Map.entry(OkZoomerConfigManager.CONFIG.transitionValues.maximumLinearStep, 0.22D),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.resetZoomWithMouse, preset != ConfigEnums.ZoomPresets.CLASSIC),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair, preset == ConfigEnums.ZoomPresets.DEFAULT),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.forgetZoomDivisor, true),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.unbindConflictingKey, false),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.useSpyglassSounds, preset == ConfigEnums.ZoomPresets.SPYGLASS),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.showRestrictionToasts, true),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.printOwoOnStart, false)
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.printOwoOnStart, true)
);

this.newValues.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.ennuil.ok_zoomer.config.screen.components;

import io.github.ennuil.ok_zoomer.mixin.EditBoxAccessor;
import io.github.ennuil.ok_zoomer.mixin.common.EditBoxAccessor;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.EditBox;
Expand Down
59 changes: 0 additions & 59 deletions src/main/java/io/github/ennuil/ok_zoomer/mixin/GuiMixin.java

This file was deleted.

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

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.ennuil.ok_zoomer.mixin;
package io.github.ennuil.ok_zoomer.mixin.common;

import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.EditBox;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.ennuil.ok_zoomer.mixin;
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import io.github.ennuil.ok_zoomer.config.screen.components.LabelledEditBox;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.ennuil.ok_zoomer.mixin;
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalDoubleRef;
Expand All @@ -25,7 +25,7 @@ private void tickInstances(CallbackInfo info) {
Zoom.getMouseModifier().tick(zooming);
}
if (Zoom.getZoomOverlay() != null) {
Zoom.getZoomOverlay().tick(zooming, divisor, Zoom.getTransitionMode().getInternalMultiplier());
Zoom.getZoomOverlay().tick(zooming, divisor, Zoom.getTransitionMode());
}
}
}
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/io/github/ennuil/ok_zoomer/mixin/common/GuiMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@ClientOnly
@Mixin(Gui.class)
public abstract class GuiMixin {
@Unique
private boolean hideCrossbar = false;

@Shadow
protected abstract void renderCrosshair(GuiGraphics guiGraphics, DeltaTracker deltaTracker);

@Inject(
method = "renderCameraOverlays",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/DeltaTracker;getGameTimeDeltaTicks()F"
)
)
private void injectZoomOverlay(GuiGraphics graphics, DeltaTracker deltaTracker, CallbackInfo ci, @Share("cancelOverlay") LocalBooleanRef cancelOverlay) {
cancelOverlay.set(false);
if (Zoom.getZoomOverlay() != null) {
var overlay = Zoom.getZoomOverlay();
overlay.tickBeforeRender(deltaTracker);
if (overlay.getActive()) {
cancelOverlay.set(overlay.cancelOverlayRendering());
overlay.renderOverlay(graphics, deltaTracker, Zoom.getTransitionMode());
}
}
}

// Cancel the cancellable overlays
@ModifyExpressionValue(method = "renderCameraOverlays", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/CameraType;isFirstPerson()Z"))
private boolean cancelOverlay(boolean original, @Share("cancelOverlay") LocalBooleanRef cancelOverlay) {
return original && !cancelOverlay.get();
}

@ModifyExpressionValue(
method = "renderCameraOverlays",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isScoping()Z")
)
private boolean activateSpyglassOverlay(boolean isScoping) {
if (switch (OkZoomerConfigManager.CONFIG.features.spyglassMode.value()) {
case REPLACE_ZOOM, BOTH -> true;
default -> false;
}) {
return false;
}

return isScoping;
}

@WrapMethod(method = "render")
private void zoomGui(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<Void> original) {
if (OkZoomerConfigManager.CONFIG.features.persistentInterface.value() || !Zoom.getTransitionMode().getActive()) {
original.call(graphics, deltaTracker);
} else {
hideCrossbar = false;
if (!OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value()) {
graphics.pose().pushPose();
graphics.pose().translate(0.0F, 0.0F, 200.0F);
this.renderCrosshair(graphics, deltaTracker);
graphics.pose().popPose();
hideCrossbar = true;
}
double fov = Zoom.getTransitionMode().applyZoom(1.0F, deltaTracker.getGameTimeDeltaPartialTick(true));
float divisor = (float) (1.0D / fov);
double translation = 2.0D / ((1.0D / fov) - 1);
graphics.pose().pushPose();
graphics.pose().translate(-(graphics.guiWidth() / (translation)), -(graphics.guiHeight() / (translation)), 0.0F);
graphics.pose().scale(divisor, divisor, divisor);
original.call(graphics, deltaTracker);
graphics.pose().popPose();
}
}

@WrapMethod(method = "renderCrosshair")
private void hideCrosshair(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<Void> original) {
if (!hideCrossbar) {
if (!OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value() || !Zoom.getTransitionMode().getActive()) {
original.call(graphics, deltaTracker);
} else {
float fade = 1.0F - (float) Zoom.getTransitionMode().getFade(deltaTracker.getGameTimeDeltaPartialTick(true));
RenderSystem.setShaderColor(fade, fade, fade, 1.0F);
original.call(graphics, deltaTracker);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
} else {
hideCrossbar = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.ennuil.ok_zoomer.mixin;
package io.github.ennuil.ok_zoomer.mixin.common;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalDoubleRef;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import io.github.ennuil.ok_zoomer.config.ConfigEnums.ZoomModes;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
Expand All @@ -20,23 +19,6 @@
@ClientOnly
@Mixin(MouseHandler.class)
public abstract class MouseHandlerMixin {
// Handles zooming
@Inject(
method = "turnPlayer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/Options;invertYMouse()Lnet/minecraft/client/OptionInstance;"
)
)
public void applyZoomChanges(double movementTime, CallbackInfo ci, @Local(ordinal = 1) LocalDoubleRef i, @Local(ordinal = 2) LocalDoubleRef j, @Local(ordinal = 5) double f) {
if (Zoom.isModifierActive()) {
double zoomDivisor = Zoom.isZooming() ? Zoom.getZoomDivisor() : 1.0;
double transitionDivisor = Zoom.getTransitionMode().getInternalMultiplier();
i.set(Zoom.getMouseModifier().applyXModifier(i.get(), f, movementTime, zoomDivisor, transitionDivisor));
j.set(Zoom.getMouseModifier().applyYModifier(j.get(), f, movementTime, zoomDivisor, transitionDivisor));
}
}

// Handles zoom scrolling
@Inject(
method = "onScroll",
Expand Down
Loading

0 comments on commit 3e156a7

Please sign in to comment.