Skip to content

Commit

Permalink
Prepare for 10.0.0-beta.3!
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Oct 16, 2024
1 parent 20e5097 commit e942e5e
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 708 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parchment = "2024.07.28"
quilt_loom = "1.7.4"
quilt_loader = "0.26.4"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.events.*;
import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds;
import io.github.ennuil.ok_zoomer.packets.ZoomPackets;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
Expand All @@ -27,9 +26,6 @@ public void onInitializeClient() {
KeyBindingHelper.registerKeyBinding(ZoomKeyBinds.RESET_ZOOM_KEY);
}

// Register the zoom-controlling packets
ZoomPackets.registerPackets();

// Register events without entrypoints aughhhhhhhh
ClientTickEvents.START_CLIENT_TICK.register(ManageZoomEvent::startClientTick);
ClientTickEvents.START_CLIENT_TICK.register(ManageExtraKeysEvent::startClientTick);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.github.ennuil.ok_zoomer.utils.ZoomUtils;

public class TrinketsCompat {

public static void init() {
ZoomUtils.addSpyglassProvider(player -> {
// Trinkets inventory is an AutoSyncedComponent and therefore safe to query on the client
Expand Down
56 changes: 9 additions & 47 deletions src/main/java/io/github/ennuil/ok_zoomer/config/ConfigEnums.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,41 @@ public class ConfigEnums {
public enum CinematicCameraOptions implements ConfigEnum {
OFF,
VANILLA,
MULTIPLIED;

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
MULTIPLIED
}

public enum ZoomTransitionOptions implements ConfigEnum {
OFF,
SMOOTH,
LINEAR;

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
LINEAR
}

public enum ZoomModes implements ConfigEnum {
HOLD,
TOGGLE,
PERSISTENT;

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
PERSISTENT
}

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

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
SPYGLASS
}

public enum SpyglassMode implements ConfigEnum {
OFF,
REQUIRE_ITEM,
REPLACE_ZOOM,
BOTH;

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
BOTH
}

public enum ZoomPresets implements ConfigEnum {
DEFAULT,
CLASSIC_ZOOMER,
CAMERA,
COMPETITIVE,
CLASSIC,
PERSISTENT,
SPYGLASS;

@Override
public Enum<?> next() {
var enumValues = this.getDeclaringClass().getEnumConstants();
return enumValues[this.ordinal() + 1 < enumValues.length ? this.ordinal() + 1 : 0];
}
SPYGLASS
}

public interface ConfigEnum {
Enum<?> next();
}
public interface ConfigEnum {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void init() {
var presetButton = CycleButton.<ConfigEnums.ZoomPresets>builder(value -> Component.translatable(String.format("config.ok_zoomer.presets.preset.%s", value.toString().toLowerCase(Locale.ROOT))))
.withValues(ConfigEnums.ZoomPresets.values())
.withTooltip(value -> Tooltip.create(Component.translatable(String.format("config.ok_zoomer.presets.preset.%s.tooltip", value.toString().toLowerCase(Locale.ROOT)))))
.withInitialValue(ConfigEnums.ZoomPresets.DEFAULT)
.withInitialValue(ConfigEnums.ZoomPresets.CAMERA)
.create(0, 0, 150, 20,
Component.translatable("config.ok_zoomer.presets.preset"));
var resetButton = Button.builder(
Expand Down Expand Up @@ -266,15 +266,15 @@ public void resetToPreset(ConfigEnums.ZoomPresets preset) {
Map.entry(OkZoomerConfigManager.CONFIG.features.reduceSensitivity, preset != ConfigEnums.ZoomPresets.CLASSIC),
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomTransition, preset == ConfigEnums.ZoomPresets.CLASSIC ? ConfigEnums.ZoomTransitionOptions.OFF : ConfigEnums.ZoomTransitionOptions.SMOOTH),
Map.entry(OkZoomerConfigManager.CONFIG.features.reduceViewBobbing, switch (preset) {
case CLASSIC, CLASSIC_ZOOMER, SPYGLASS -> false;
case CLASSIC, COMPETITIVE, SPYGLASS -> false;
default -> true;
}),
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomMode, preset == ConfigEnums.ZoomPresets.PERSISTENT ? ConfigEnums.ZoomModes.PERSISTENT : ConfigEnums.ZoomModes.HOLD),
Map.entry(OkZoomerConfigManager.CONFIG.features.zoomScrolling, switch (preset) {
case CLASSIC, SPYGLASS -> false;
default -> true;
}),
Map.entry(OkZoomerConfigManager.CONFIG.features.persistentInterface, preset != ConfigEnums.ZoomPresets.DEFAULT),
Map.entry(OkZoomerConfigManager.CONFIG.features.persistentInterface, preset != ConfigEnums.ZoomPresets.CAMERA),
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 All @@ -300,7 +300,7 @@ public void resetToPreset(ConfigEnums.ZoomPresets preset) {
Map.entry(OkZoomerConfigManager.CONFIG.transitionValues.minimumLinearStep, 0.16),
Map.entry(OkZoomerConfigManager.CONFIG.transitionValues.maximumLinearStep, 0.22),
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.hideCrosshair, preset == ConfigEnums.ZoomPresets.CAMERA),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.forgetZoomDivisor, true),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.unbindConflictingKey, false),
Map.entry(OkZoomerConfigManager.CONFIG.tweaks.useSpyglassSounds, preset == ConfigEnums.ZoomPresets.SPYGLASS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class ManageExtraKeysEvent {
public static void startClientTick(Minecraft minecraft) {
if (!ZoomKeyBinds.areExtraKeyBindsEnabled()) return;
if (!OkZoomerConfigManager.CONFIG.features.extraKeyBinds.value()) return;
if (OkZoomerConfigManager.CONFIG.features.zoomScrolling.isBeingOverridden()) return;

if (ZoomKeyBinds.DECREASE_ZOOM_KEY.isDown() && !ZoomKeyBinds.INCREASE_ZOOM_KEY.isDown()) {
ZoomUtils.changeZoomDivisor(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.github.ennuil.ok_zoomer.events;

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;
import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds;
import io.github.ennuil.ok_zoomer.packets.ZoomPackets;
import io.github.ennuil.ok_zoomer.utils.ZoomUtils;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.Minecraft;
import net.minecraft.sounds.SoundEvents;

Expand All @@ -22,11 +21,13 @@ public static void startClientTick(Minecraft minecraft) {
if (minecraft.player == null) return;

// If zoom is disabled, do not allow for zooming at all
boolean disableZoom = ZoomPackets.shouldDisableZoom() ||
(switch (OkZoomerConfigManager.CONFIG.features.spyglassMode.value()) {
/* If you want to reimplement mandatory spyglass control? It's easy:
* Quilt Config has value overrides, use them. This mod is ARR but it's anti-vulture;
* You can make a third-party addon mod, I won't bite. */
boolean disableZoom = switch (OkZoomerConfigManager.CONFIG.features.spyglassMode.value()) {
case REQUIRE_ITEM, BOTH -> true;
default -> false;
} && !ZoomUtils.hasSpyglass(minecraft.player));
} && !ZoomUtils.hasSpyglass(minecraft.player);

if (disableZoom) {
Zoom.setZooming(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.ennuil.ok_zoomer.events;

import io.github.ennuil.ok_zoomer.commands.OkZoomerCommandScreen;
import io.github.ennuil.ok_zoomer.config.screen.OkZoomerConfigScreen;
import io.github.ennuil.ok_zoomer.utils.ZoomUtils;
import net.minecraft.client.Minecraft;

public class OpenScreenEvent {
public static void endClientTick(Minecraft minecraft) {
if (ZoomUtils.shouldOpenCommandScreen()) {
minecraft.setScreen(new OkZoomerCommandScreen());
minecraft.setScreen(new OkZoomerConfigScreen(minecraft.screen));
ZoomUtils.setOpenCommandScreen(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -11,7 +13,10 @@
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.DebugScreenOverlay;
import org.joml.Vector3f;
import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -25,6 +30,12 @@ public abstract class GuiMixin {
@Unique
private boolean hideCrossbar = false;

@Unique
private double translation = 0.0;

@Unique
private float scale = 0.0F;

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

Expand Down Expand Up @@ -82,11 +93,11 @@ private void zoomGui(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<
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);
translation = 2.0D / ((1.0D / fov) - 1);
scale = (float) (1.0D / fov);
graphics.pose().pushPose();
graphics.pose().translate(-(graphics.guiWidth() / (translation)), -(graphics.guiHeight() / (translation)), 0.0F);
graphics.pose().scale(divisor, divisor, divisor);
graphics.pose().translate(-(graphics.guiWidth() / translation), -(graphics.guiHeight() / translation), 0.0F);
graphics.pose().scale(scale, scale, 1.0F);
original.call(graphics, deltaTracker);
graphics.pose().popPose();
}
Expand All @@ -107,4 +118,33 @@ private void hideCrosshair(GuiGraphics graphics, DeltaTracker deltaTracker, Oper
hideCrossbar = false;
}
}

// TODO - This is a very promising method to get individual HUDs persistent, but I'm not sure if it's bulletproof!
// It doesn't crash with Sodium nor ImmediatelyFast though, and that's good
@WrapOperation(
method = {
"method_55807",
"lambda$new$6" // Heck yeah! It's Neo-specific hack time!
},
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/components/DebugScreenOverlay;render(Lnet/minecraft/client/gui/GuiGraphics;)V"
),
allow = 1
)
private void ensureDebugHudVisibility(DebugScreenOverlay instance, GuiGraphics graphics, Operation<Void> original, @Local(argsOnly = true) DeltaTracker deltaTracker) {
if (OkZoomerConfigManager.CONFIG.features.persistentInterface.value() || !Zoom.getTransitionMode().getActive()) {
original.call(instance, graphics);
} else {
var lastPose = graphics.pose().last().pose();
graphics.pose().popPose();
graphics.pose().popPose();
graphics.pose().pushPose();
graphics.pose().translate(0.0F, 0.0F, lastPose.getTranslation(new Vector3f()).z);
original.call(instance, graphics);
graphics.pose().pushPose();
graphics.pose().translate(-(graphics.guiWidth() / translation), -(graphics.guiHeight() / translation), 0.0F);
graphics.pose().scale(scale, scale, 1.0F);
}
}
}
Loading

0 comments on commit e942e5e

Please sign in to comment.