Skip to content

Commit

Permalink
Port to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
EnnuiL committed Oct 20, 2024
1 parent 5e62672 commit b91144b
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 189 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ dependencies {

modCompileOnly libs.wrench.wrapper

modCompileOnly libs.bundles.trinkets
modLocalRuntime libs.bundles.trinkets
//modCompileOnly libs.bundles.trinkets
//modLocalRuntime libs.bundles.trinkets

include libs.wrench.wrapper
}
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# The latest versions are available at https://quiltmc.org/en/usage/latest-versions/
[versions]
minecraft = "1.21.1"
minecraft = "1.21.2-rc1"
parchment = "2024.07.28"

quilt_loom = "1.8.3"
quilt_loader = "0.27.0-beta.1"

fabric_api = "0.106.0+1.21.1"
fabric_api = "0.106.0+1.21.2"
wrench_wrapper = "0.5.0"
modmenu = "11.0.3"
modmenu = "12.0.0-beta.1"

trinkets = "3.10.0"
cca = "6.1.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.ennuil.ok_zoomer;

import io.github.ennuil.ok_zoomer.compat.TrinketsCompat;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.events.*;
import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds;
Expand All @@ -9,7 +8,6 @@
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;

// This class is responsible for registering the commands and packets
public class OkZoomerClientMod implements ClientModInitializer {
Expand All @@ -33,9 +31,11 @@ public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(OpenScreenEvent::endClientTick);
ClientCommandRegistrationCallback.EVENT.register(RegisterCommands::registerCommands);

/*
// mod compat
if (FabricLoader.getInstance().isModLoaded("trinkets")) {
TrinketsCompat.init();
}
*/
}
}
61 changes: 0 additions & 61 deletions src/main/java/io/github/ennuil/ok_zoomer/OkZoomerMixinPlugin.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.ennuil.ok_zoomer.config.screen.components;

import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.Minecraft;
Expand All @@ -18,6 +17,7 @@
import net.minecraft.client.gui.navigation.ScreenAxis;
import net.minecraft.client.gui.navigation.ScreenDirection;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -135,19 +135,15 @@ protected void narrateListElementPosition(NarrationElementOutput narrationElemen
}

private void renderListBackground(GuiGraphics graphics) {
RenderSystem.enableBlend();
var backgroundLocation = this.minecraft.level == null ? MENU_LIST_BACKGROUND : INWORLD_MENU_LIST_BACKGROUND;
graphics.blit(backgroundLocation, this.getX(), this.getY(), this.getRight(), this.getBottom() + this.getScrollAmount(), this.width, this.height, 32,32);
RenderSystem.disableBlend();
graphics.blit(RenderType::guiTextured, backgroundLocation, this.getX(), this.getY(), this.getRight(), this.getBottom() + this.getScrollAmount(), this.width, this.height, 32,32);
}

private void renderListSeparators(GuiGraphics graphics) {
RenderSystem.enableBlend();
var headerSeparatorLocation = this.minecraft.level == null ? Screen.HEADER_SEPARATOR : Screen.INWORLD_HEADER_SEPARATOR;
var footerSeparatorLocation = this.minecraft.level == null ? Screen.FOOTER_SEPARATOR : Screen.INWORLD_FOOTER_SEPARATOR;
graphics.blit(headerSeparatorLocation, this.getX(), this.getY() - 2, 0.0F, 0.0F, this.width, 2, 32, 2);
graphics.blit(footerSeparatorLocation, this.getX(), this.getBottom(), 0.0F, 0.0F, this.width, 2, 32, 2);
RenderSystem.disableBlend();
graphics.blit(RenderType::guiTextured, headerSeparatorLocation, this.getX(), this.getY() - 2, 0.0F, 0.0F, this.width, 2, 32, 2);
graphics.blit(RenderType::guiTextured, footerSeparatorLocation, this.getX(), this.getBottom(), 0.0F, 0.0F, this.width, 2, 32, 2);
}

private void renderScrollBar(GuiGraphics graphics) {
Expand All @@ -157,10 +153,8 @@ private void renderScrollBar(GuiGraphics graphics) {
var scale = (this.scrollAmount / (double) (this.contentHeight - this.height));
var y = this.getY() + (int) (scale * (this.height - size));

RenderSystem.enableBlend();
graphics.blitSprite(SCROLLER_BACKGROUND_SPRITE, x, this.getY(), 6, this.height);
graphics.blitSprite(SCROLLER_SPRITE, x, y, 6, size);
RenderSystem.disableBlend();
graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, x, this.getY(), 6, this.height);
graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, x, y, 6, size);
}

protected int getScrollBarPosX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalDoubleRef;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.Camera;
Expand Down Expand Up @@ -57,12 +57,11 @@ private int modifyCulling(int original) {
ordinal = 0
)
)
private void getZoomedFov(Camera activeRenderInfo, float partialTicks, boolean useFOVSetting, CallbackInfoReturnable<Double> cir, @Local LocalDoubleRef internalFov) {
double zoomedFov = internalFov.get();
private void getZoomedFov(Camera activeRenderInfo, float partialTicks, boolean useFOVSetting, CallbackInfoReturnable<Float> cir, @Local(ordinal = 1) LocalFloatRef internalFov) {
float zoomedFov = internalFov.get();

if (Zoom.isTransitionActive()) {
// This looks bad now, but don't worry, it *will* make sense on Minecraft 1.21.2
zoomedFov = Zoom.getTransitionMode().applyZoom((float) zoomedFov, partialTicks);
zoomedFov = Zoom.getTransitionMode().applyZoom(zoomedFov, partialTicks);
}

internalFov.set(zoomedFov);
Expand Down
44 changes: 13 additions & 31 deletions src/main/java/io/github/ennuil/ok_zoomer/mixin/common/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager;
import io.github.ennuil.ok_zoomer.zoom.Zoom;
import net.minecraft.client.DeltaTracker;
Expand All @@ -16,7 +15,6 @@
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.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -92,46 +90,30 @@ private void zoomGui(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<
private void hideCrosshair(GuiGraphics graphics, DeltaTracker deltaTracker, Operation<Void> original) {
boolean persistentInterface = OkZoomerConfigManager.CONFIG.features.persistentInterface.value();
boolean hideCrosshair = OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value();
if ((persistentInterface && !hideCrosshair) || !Zoom.isTransitionActive()) {
if (persistentInterface || hideCrosshair || !Zoom.isTransitionActive()) {
original.call(graphics, deltaTracker);
} else {
if (hideCrosshair) {
float fade = 1.0F - Zoom.getTransitionMode().getFade(deltaTracker.getGameTimeDeltaPartialTick(true));
RenderSystem.setShaderColor(fade, fade, fade, fade);
}
if (!persistentInterface && !hideCrosshair) {
// TODO - This has been recycled once, this should become a method
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(graphics, deltaTracker);
graphics.pose().pushPose();
graphics.pose().translate(-(graphics.guiWidth() / translation), -(graphics.guiHeight() / translation), 0.0F);
graphics.pose().scale(scale, scale, 1.0F);
} else {
original.call(graphics, deltaTracker);
}
if (hideCrosshair) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
// TODO - This has been recycled once, this should become a method
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(graphics, deltaTracker);
graphics.pose().pushPose();
graphics.pose().translate(-(graphics.guiWidth() / translation), -(graphics.guiHeight() / translation), 0.0F);
graphics.pose().scale(scale, scale, 1.0F);
}
}

// 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
@Dynamic
@WrapOperation(
method = {
"method_55807",
"lambda$new$6" // Heck yeah! It's Neo-specific hack time!
},
method = "method_55807",
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class MouseHandlerMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isSpectator()Z"),
cancellable = true
)
private void zoomerOnMouseScroll(CallbackInfo ci, @Local(ordinal = 2) int k) {
private void zoomerOnMouseScroll(CallbackInfo ci, @Local int k) {
if (k != 0) {
if (OkZoomerConfigManager.CONFIG.features.zoomScrolling.value()) {
if (OkZoomerConfigManager.CONFIG.features.zoomMode.value().equals(ZoomModes.PERSISTENT)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.ennuil.ok_zoomer.mixin.common;

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.Minecraft;
import net.minecraft.client.renderer.RenderStateShard;
import org.quiltmc.loader.api.minecraft.ClientOnly;
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.CallbackInfo;

@ClientOnly
@Mixin(RenderStateShard.class)
public abstract class RenderStateShardMixin {
@Inject(method = "method_62269", at = @At("TAIL"))
private static void fadeCrosshair(CallbackInfo ci) {
if (OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value()) {
float fade = 1.0F - Zoom.getTransitionMode().getFade(Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaPartialTick(true));
RenderSystem.setShaderColor(fade, fade, fade, fade);
}
}

@Inject(method = "method_62268", at = @At("HEAD"))
private static void resetCrosshairFade(CallbackInfo ci) {
if (OkZoomerConfigManager.CONFIG.tweaks.hideCrosshair.value()) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void validateZoomCulling(Minecraft minecraft) {
int zoomCullingFov = Math.ceilDiv(fov, divisor);

if (zoomCullingFov != lastZoomCullingFov) {
minecraft.levelRenderer.needsUpdate();
minecraft.levelRenderer.getSectionOcclusionGraph().invalidate();
}

lastZoomCullingFov = zoomCullingFov;
Expand Down Expand Up @@ -102,7 +102,7 @@ public static void unbindConflictingKey(Minecraft client, boolean userPrompted)
if (client.options.keySaveHotbarActivator.isDefault()) {
if (userPrompted) {
ZoomUtils.LOGGER.info("[Ok Zoomer] The \"Save Toolbar Activator\" keybind was occupying C! Unbinding...");
client.getToasts().addToast(SystemToast.multiline(
client.getToastManager().addToast(SystemToast.multiline(
client, TOAST_ID, Component.translatable("toast.ok_zoomer.title"),
Component.translatable("toast.ok_zoomer.unbind_conflicting_key.success")));
} else {
Expand All @@ -114,7 +114,7 @@ public static void unbindConflictingKey(Minecraft client, boolean userPrompted)
} else {
ZoomUtils.LOGGER.info("[Ok Zoomer] No conflicts with the \"Save Toolbar Activator\" keybind were found!");
if (userPrompted) {
client.getToasts().addToast(SystemToast.multiline(
client.getToastManager().addToast(SystemToast.multiline(
client, TOAST_ID, Component.translatable("toast.ok_zoomer.title"),
Component.translatable("toast.ok_zoomer.unbind_conflicting_key.no_conflict")));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.ennuil.ok_zoomer.zoom.overlays;

import com.mojang.blaze3d.systems.RenderSystem;
import io.github.ennuil.ok_zoomer.zoom.transitions.TransitionMode;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -46,9 +45,7 @@ public void renderOverlay(GuiGraphics graphics, DeltaTracker deltaTracker, Trans
int y = (guiHeight - height) / 2;
int borderX = x + width;
int borderY = y + height;
RenderSystem.enableBlend();
graphics.blit(textureId, x, y, -90, 0.0F, 0.0F, width, height, width, height);
RenderSystem.disableBlend();
graphics.blit(RenderType::guiTextured, textureId, x, y, 0.0F, 0.0F, width, height, width, height);
graphics.fill(RenderType.guiOverlay(), 0, borderY, guiWidth, guiHeight, -90, CommonColors.BLACK);
graphics.fill(RenderType.guiOverlay(), 0, 0, guiWidth, y, -90, CommonColors.BLACK);
graphics.fill(RenderType.guiOverlay(), 0, y, x, borderY, -90, CommonColors.BLACK);
Expand Down
Loading

0 comments on commit b91144b

Please sign in to comment.