Skip to content

Commit 32ef6b1

Browse files
committed
Migrated mixins
1 parent 338d7ca commit 32ef6b1

13 files changed

+114
-62
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ dependencies {
149149
// Fabric
150150
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
151151
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion")
152+
// Explicit dependency on fabric-renderer-indigo for mixin access to internal classes
153+
modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-indigo:4.1.4+1af5c5a75f")
152154
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion")
153155

154156
// Add dependencies on the required Kotlin modules.

src/main/java/com/lambda/mixin/input/KeyBindingMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class KeyBindingMixin {
3232
@ModifyReturnValue(method = "isPressed", at = @At("RETURN"))
3333
boolean modifyIsPressed(boolean original) {
3434
KeyBinding instance = (KeyBinding) (Object) this;
35-
if (!Objects.equals(instance.getTranslationKey(), "key.sprint")) return original;
35+
if (!Objects.equals(instance.getId(), "key.sprint")) return original;
3636

3737
if (Sprint.INSTANCE.isEnabled()) return true;
3838
if (Speed.INSTANCE.isEnabled() && Speed.getMode() == Speed.Mode.GrimStrafe) return true;

src/main/java/com/lambda/mixin/input/KeyboardMixin.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,45 @@
2323
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2424
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2525
import net.minecraft.client.Keyboard;
26+
import net.minecraft.client.input.CharInput;
27+
import net.minecraft.client.input.KeyInput;
2628
import net.minecraft.client.option.KeyBinding;
2729
import net.minecraft.client.util.InputUtil;
2830
import org.spongepowered.asm.mixin.Mixin;
2931
import org.spongepowered.asm.mixin.injection.At;
3032
import org.spongepowered.asm.mixin.injection.Inject;
3133
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3234

35+
/**
36+
* Mixin to intercept keyboard input events.
37+
*
38+
* Note: In 1.21.11, onKey/onChar methods were refactored to use KeyInput/CharInput records.
39+
* - onKey(long window, int action, KeyInput input) where KeyInput has key, scancode, modifiers
40+
* - onChar(long window, CharInput input) where CharInput has codepoint, modifiers
41+
*/
3342
@Mixin(Keyboard.class)
3443
public class KeyboardMixin {
3544
@WrapMethod(method = "onKey")
36-
private void onKey(long window, int key, int scancode, int action, int modifiers, Operation<Void> original) {
37-
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
38-
original.call(window, key, scancode, action, modifiers);
45+
private void onKey(long window, int action, KeyInput input, Operation<Void> original) {
46+
EventFlow.post(new KeyboardEvent.Press(input.key(), input.scancode(), action, input.modifiers()));
47+
original.call(window, action, input);
3948
}
4049

4150
@Inject(method = "onKey", at = @At("RETURN"))
42-
private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
51+
private void onKeyTail(long window, int action, KeyInput input, CallbackInfo ci) {
52+
int key = input.key();
4353
if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return;
44-
InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode);
54+
InputUtil.Key fromCode = InputUtil.fromKeyCode(input);
4555
KeyBinding.setKeyPressed(fromCode, action != 0);
4656
}
4757

4858
@WrapMethod(method = "onChar")
49-
private void onChar(long window, int codePoint, int modifiers, Operation<Void> original) {
50-
char[] chars = Character.toChars(codePoint);
59+
private void onChar(long window, CharInput input, Operation<Void> original) {
60+
char[] chars = Character.toChars(input.codepoint());
5161

5262
for (char c : chars)
5363
EventFlow.post(new KeyboardEvent.Char(c));
5464

55-
original.call(window, codePoint, modifiers);
65+
original.call(window, input);
5666
}
5767
}

src/main/java/com/lambda/mixin/network/ClientPlayNetworkHandlerMixin.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void injectJoinPacket(GameJoinS2CPacket packet, CallbackInfo ci) {
4545
void injectPlayerList(PlayerListS2CPacket.Action action, PlayerListS2CPacket.Entry receivedEntry, PlayerListEntry currentEntry, CallbackInfo ci) {
4646
if (action != PlayerListS2CPacket.Action.UPDATE_LISTED) return;
4747

48-
var name = currentEntry.getProfile().getName();
49-
var uuid = currentEntry.getProfile().getId();
48+
var name = currentEntry.getProfile().name();
49+
var uuid = currentEntry.getProfile().id();
5050

5151
if (receivedEntry.listed()) {
5252
EventFlow.post(new WorldEvent.Player.Join(name, uuid, currentEntry));
@@ -64,17 +64,19 @@ private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet,
6464
}
6565

6666
/**
67-
* Sets displayedUnsecureChatWarning to {@link NoRender#getNoChatVerificationToast()}
67+
* Sets seenInsecureChatWarning to {@link NoRender#getNoChatVerificationToast()}
6868
* <pre>{@code
6969
* this.secureChatEnforced = packet.enforcesSecureChat();
70-
* if (this.serverInfo != null && !this.displayedUnsecureChatWarning && !this.isSecureChatEnforced()) {
70+
* if (this.serverInfo != null && !this.seenInsecureChatWarning && !this.isSecureChatEnforced()) {
7171
* SystemToast systemToast = SystemToast.create(this.client, SystemToast.Type.UNSECURE_SERVER_WARNING, UNSECURE_SERVER_TOAST_TITLE, UNSECURE_SERVER_TOAST_TEXT);
7272
* this.client.getToastManager().add(systemToast);
73-
* this.displayedUnsecureChatWarning = true;
73+
* this.seenInsecureChatWarning = true;
7474
* }
7575
* }</pre>
76+
*
77+
* Note: In 1.21.11, displayedUnsecureChatWarning was renamed to seenInsecureChatWarning.
7678
*/
77-
@ModifyExpressionValue(method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;displayedUnsecureChatWarning:Z", ordinal = 0))
79+
@ModifyExpressionValue(method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;seenInsecureChatWarning:Z", ordinal = 0))
7880
public boolean onServerMetadata(boolean original) {
7981
return (NoRender.getNoChatVerificationToast() && NoRender.INSTANCE.isEnabled()) || original;
8082
}

src/main/java/com/lambda/mixin/render/AbstractTerrainRenderContextMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.spongepowered.asm.mixin.injection.Inject;
2929
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3030

31-
@SuppressWarnings("UnstableApiUsage")
3231
@Mixin(AbstractTerrainRenderContext.class)
3332
public class AbstractTerrainRenderContextMixin {
3433
@Final

src/main/java/com/lambda/mixin/render/BackgroundRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class BackgroundRendererMixin {
3838

3939
@Inject(method = "shouldApply", at = @At("HEAD"), cancellable = true)
4040
private void injectShouldApplyBlindness(CameraSubmersionType submersionType, Entity cameraEntity, CallbackInfoReturnable<Boolean> cir) {
41-
if (NoRender.getNoBlindness() && NoRender.isEnabled()) {
41+
if (NoRender.INSTANCE.getNoBlindness() && NoRender.INSTANCE.isEnabled()) {
4242
cir.setReturnValue(false);
4343
}
4444
}

src/main/java/com/lambda/mixin/render/BlockEntityRenderDispatcherMixin.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,29 @@
1919

2020
import com.lambda.module.modules.render.NoRender;
2121
import net.minecraft.block.entity.BlockEntity;
22-
import net.minecraft.client.render.VertexConsumerProvider;
23-
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
24-
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
25-
import net.minecraft.client.util.math.MatrixStack;
26-
import net.minecraft.util.math.Vec3d;
22+
import net.minecraft.client.render.block.entity.BlockEntityRenderManager;
23+
import net.minecraft.client.render.block.entity.state.BlockEntityRenderState;
24+
import net.minecraft.client.render.command.ModelCommandRenderer;
2725
import org.spongepowered.asm.mixin.Mixin;
2826
import org.spongepowered.asm.mixin.injection.At;
2927
import org.spongepowered.asm.mixin.injection.Inject;
30-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
import org.jspecify.annotations.Nullable;
3130

32-
@Mixin(BlockEntityRenderDispatcher.class)
31+
/**
32+
* Mixin to disable block entity rendering when NoRender is enabled.
33+
*
34+
* Note: In 1.21.11, BlockEntityRenderDispatcher was renamed to BlockEntityRenderManager
35+
* and uses a render state system. Returning null from getRenderState prevents rendering.
36+
*/
37+
@Mixin(BlockEntityRenderManager.class)
3338
public class BlockEntityRenderDispatcherMixin {
34-
@Inject(method = "render(Lnet/minecraft/client/render/block/entity/BlockEntityRenderer;Lnet/minecraft/block/entity/BlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/util/math/Vec3d;)V", at = @At("HEAD"), cancellable = true)
35-
private static void injectRender(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockEntity, float tickProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, Vec3d cameraPos, CallbackInfo ci) {
36-
if (NoRender.shouldOmitBlockEntity(blockEntity)) ci.cancel();
39+
@Inject(method = "getRenderState", at = @At("HEAD"), cancellable = true)
40+
private <E extends BlockEntity, S extends BlockEntityRenderState> void injectGetRenderState(
41+
E blockEntity, float tickProgress, ModelCommandRenderer.@Nullable CrumblingOverlayCommand crumblingOverlay,
42+
CallbackInfoReturnable<S> cir) {
43+
if (NoRender.shouldOmitBlockEntity(blockEntity)) {
44+
cir.setReturnValue(null);
45+
}
3746
}
3847
}

src/main/java/com/lambda/mixin/render/CapeFeatureRendererMixin.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,33 @@
2121
import com.lambda.module.modules.client.Capes;
2222
import com.lambda.network.CapeManager;
2323
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
24-
import net.minecraft.client.render.VertexConsumerProvider;
24+
import net.minecraft.client.render.command.OrderedRenderCommandQueue;
2525
import net.minecraft.client.render.entity.feature.CapeFeatureRenderer;
2626
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
2727
import net.minecraft.client.util.math.MatrixStack;
2828
import net.minecraft.util.Identifier;
2929
import org.spongepowered.asm.mixin.Mixin;
3030
import org.spongepowered.asm.mixin.injection.At;
3131

32+
/**
33+
* Mixin to override cape textures with Lambda capes.
34+
*
35+
* Note: In 1.21.11, render method uses OrderedRenderCommandQueue instead of VertexConsumerProvider.
36+
* Cape texture is now accessed via skinTextures.cape().texturePath() instead of capeTexture().
37+
*/
3238
@Mixin(CapeFeatureRenderer.class)
3339
public class CapeFeatureRendererMixin {
34-
@ModifyExpressionValue(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/client/render/entity/state/PlayerEntityRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SkinTextures;capeTexture()Lnet/minecraft/util/Identifier;"))
35-
Identifier renderCape(Identifier original, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, PlayerEntityRenderState player, float f, float g) {
36-
var entry = Lambda.getMc().getNetworkHandler().getPlayerListEntry(player.name); // this will cause issues if we try to render while not in game
40+
@ModifyExpressionValue(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;ILnet/minecraft/client/render/entity/state/PlayerEntityRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/AssetInfo$TextureAsset;texturePath()Lnet/minecraft/util/Identifier;"))
41+
Identifier renderCape(Identifier original, MatrixStack matrixStack, OrderedRenderCommandQueue commandQueue, int i, PlayerEntityRenderState player, float f, float g) {
42+
var networkHandler = Lambda.getMc().getNetworkHandler();
43+
if (networkHandler == null) return original;
44+
45+
var entry = player.playerName != null ? networkHandler.getPlayerListEntry(player.playerName.getString()) : null;
3746
if (entry == null) return original;
3847

3948
var profile = entry.getProfile();
40-
if (!Capes.INSTANCE.isEnabled() || !CapeManager.INSTANCE.getCache().containsKey(profile.getId())) return original;
49+
if (!Capes.INSTANCE.isEnabled() || !CapeManager.INSTANCE.getCache().containsKey(profile.id())) return original;
4150

42-
return Identifier.of("lambda", CapeManager.INSTANCE.getCache().get(profile.getId()));
51+
return Identifier.of("lambda", CapeManager.INSTANCE.getCache().get(profile.id()));
4352
}
4453
}

src/main/java/com/lambda/mixin/render/ChatInputSuggestorMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ private boolean refreshModify(boolean showCompletions) {
6262
return CommandManager.INSTANCE.isCommand(textField.getText());
6363
}
6464

65+
@SuppressWarnings("unchecked")
6566
@WrapOperation(method = "refresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;getCommandDispatcher()Lcom/mojang/brigadier/CommandDispatcher;"))
6667
private CommandDispatcher<CommandSource> wrapRefresh(ClientPlayNetworkHandler instance, Operation<CommandDispatcher<CommandSource>> original) {
67-
return CommandManager.INSTANCE.currentDispatcher(textField.getText());
68+
return (CommandDispatcher<CommandSource>) (Object) CommandManager.INSTANCE.currentDispatcher(textField.getText());
6869
}
6970

7071
@Inject(method = "refresh", at = @At("TAIL"))

src/main/java/com/lambda/mixin/render/DarknessEffectFogMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class DarknessEffectFogMixin {
3434

3535
@Inject(method = "shouldApply", at = @At("HEAD"), cancellable = true)
3636
private void injectShouldApplyDarkness(CameraSubmersionType submersionType, Entity cameraEntity, CallbackInfoReturnable<Boolean> cir) {
37-
if (NoRender.getNoDarkness() && NoRender.isEnabled()) {
37+
if (NoRender.INSTANCE.getNoDarkness() && NoRender.INSTANCE.isEnabled()) {
3838
cir.setReturnValue(false);
3939
}
4040
}

0 commit comments

Comments
 (0)