Skip to content

Commit a30e8a8

Browse files
committed
port to 26.1-snapshot-10
1 parent 9b1fdab commit a30e8a8

File tree

11 files changed

+101
-52
lines changed

11 files changed

+101
-52
lines changed

src/main/java/dev/isxander/controlify/compatibility/yacl/screenop/StringControllerElementComponentProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ public boolean supportsCharInput() {
3939

4040
@Override
4141
public boolean acceptChar(char ch, int modifiers) {
42-
//? if >=1.21.9 {
43-
return element.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
44-
//?} else {
45-
/*return element.charTyped(ch, modifiers);
42+
//? if >=26.1 {
43+
return element.charTyped(new net.minecraft.client.input.CharacterEvent(ch));
44+
//?} elif >=1.21.9 {
45+
/*return element.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
46+
*///?} else {
47+
/*return element.charTyped(ch);
4648
*///?}
4749
}
4850

src/main/java/dev/isxander/controlify/ingame/InGameInputHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ protected void handleKeybinds() {
200200
this.minecraft.gameDirectory,
201201
this.minecraft.getMainRenderTarget(),
202202
component -> this.minecraft.execute(() -> {
203-
this.minecraft.gui.getChat().addMessage(component);
203+
//? if >=26.1 {
204+
this.minecraft.gui.getChat().addClientSystemMessage(component);
205+
//?} else {
206+
/*this.minecraft.gui.getChat().addMessage(component);
207+
*///?}
204208

205209
// TODO: this currently does not work, yet to debug why not
206210
SteamDeckDriver.getDeck().ifPresent(deck -> {

src/main/java/dev/isxander/controlify/mixins/core/KeyboardHandlerMixin.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import dev.isxander.controlify.InputMode;
88
import net.minecraft.client.KeyboardHandler;
99
import net.minecraft.client.Minecraft;
10-
import org.lwjgl.glfw.GLFWCharModsCallbackI;
11-
import org.lwjgl.glfw.GLFWKeyCallbackI;
10+
import org.lwjgl.glfw.*;
1211
import org.spongepowered.asm.mixin.Final;
1312
import org.spongepowered.asm.mixin.Mixin;
1413
import org.spongepowered.asm.mixin.Shadow;
@@ -23,29 +22,49 @@ public class KeyboardHandlerMixin {
2322
method = "setup",
2423
at = @At(
2524
value = "INVOKE",
26-
//? if >=1.21.9 {
27-
target = "Lcom/mojang/blaze3d/platform/InputConstants;setupKeyboardCallbacks(Lcom/mojang/blaze3d/platform/Window;Lorg/lwjgl/glfw/GLFWKeyCallbackI;Lorg/lwjgl/glfw/GLFWCharModsCallbackI;)V"
28-
//?} else {
25+
//? if >=26.1 {
26+
target = "Lcom/mojang/blaze3d/platform/InputConstants;setupKeyboardCallbacks(Lcom/mojang/blaze3d/platform/Window;Lorg/lwjgl/glfw/GLFWKeyCallbackI;Lorg/lwjgl/glfw/GLFWCharCallbackI;Lorg/lwjgl/glfw/GLFWPreeditCallbackI;Lorg/lwjgl/glfw/GLFWIMEStatusCallbackI;)V"
27+
//?} elif >=1.21.9 {
28+
/*target = "Lcom/mojang/blaze3d/platform/InputConstants;setupKeyboardCallbacks(Lcom/mojang/blaze3d/platform/Window;Lorg/lwjgl/glfw/GLFWKeyCallbackI;Lorg/lwjgl/glfw/GLFWCharModsCallbackI;)V"
29+
*///?} else {
2930
/*target = "Lcom/mojang/blaze3d/platform/InputConstants;setupKeyboardCallbacks(JLorg/lwjgl/glfw/GLFWKeyCallbackI;Lorg/lwjgl/glfw/GLFWCharModsCallbackI;)V"
3031
*///?}
3132
)
3233
)
3334
private void wrapKeyboardEvents(
3435
/*? if >=1.21.9 {*/ Window /*?} else {*/ /*long *//*?}*/ window,
35-
GLFWKeyCallbackI keyCallback,
36-
GLFWCharModsCallbackI charCallback,
36+
GLFWKeyCallbackI keyPressCallback,
37+
//? if >=26.1 {
38+
GLFWCharCallbackI charTypedCallback,
39+
GLFWPreeditCallbackI preeditCallback,
40+
GLFWIMEStatusCallbackI imeStatusCallback,
41+
//?} else {
42+
/*GLFWCharModsCallbackI charCallback,
43+
*///?}
3744
Operation<Void> original
3845
) {
3946
original.call(
4047
window,
4148
(GLFWKeyCallbackI) (w, k, s, a, m) -> {
4249
onKeyboardInput();
43-
keyCallback.invoke(w, k, s, a, m);
50+
keyPressCallback.invoke(w, k, s, a, m);
4451
},
45-
(GLFWCharModsCallbackI) (w, c, m) -> {
52+
//? if >=26.1 {
53+
(GLFWCharCallbackI) (w, c) -> {
4654
onKeyboardInput();
47-
charCallback.invoke(w, c, m);
55+
charTypedCallback.invoke(w, c);
56+
},
57+
(GLFWPreeditCallbackI) (w, pc, s, bc, bs, fb, c) -> {
58+
onKeyboardInput();
59+
preeditCallback.invoke(w, pc, s, bc, bs, fb, c);
60+
},
61+
imeStatusCallback
62+
//?} else {
63+
/*(GLFWCharModsCallbackI) (w, c, m) -> {
64+
onKeyboardInput();
65+
charTypedCallback.invoke(w, c, m);
4866
}
67+
*///?}
4968
);
5069
}
5170

src/main/java/dev/isxander/controlify/mixins/feature/input/MinecraftMixin.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,38 @@
1111
@Mixin(Minecraft.class)
1212
public abstract class MinecraftMixin implements PickBlockAccessor {
1313
@Unique
14-
private boolean useNbtPick;
14+
private final ThreadLocal<Boolean> useNbtPick = ThreadLocal.withInitial(() -> null);
1515

16+
//? if >=26.1 {
1617
@Shadow
18+
protected abstract void pickBlockOrEntity();
19+
//?} else {
20+
/*@Shadow
1721
protected abstract void pickBlock();
1822
23+
private void pickBlockOrEntity() {
24+
return pickBlock();
25+
}
26+
*///?}
27+
1928
@Override
2029
public void controlify$pickBlock() {
21-
useNbtPick = false;
22-
pickBlock();
30+
this.useNbtPick.set(false);
31+
pickBlockOrEntity();
2332
}
2433

2534
@Override
2635
public void controlify$pickBlockWithNbt() {
27-
useNbtPick = true;
28-
pickBlock();
36+
this.useNbtPick.set(true);
37+
pickBlockOrEntity();
2938
}
3039

3140
@ModifyExpressionValue(
32-
method = "pickBlock",
41+
//? if >=26.1 {
42+
method = "pickBlockOrEntity",
43+
//?} else {
44+
/*method = "pickBlock",
45+
*///?}
3346
at = @At(
3447
value = "INVOKE",
3548
//? if >=1.21.9 {
@@ -40,9 +53,10 @@ public abstract class MinecraftMixin implements PickBlockAccessor {
4053
)
4154
)
4255
private boolean shouldUseNbtPick(boolean hasControlDown) {
43-
if (useNbtPick) {
44-
useNbtPick = false;
45-
return true;
56+
Boolean useNbtPick = this.useNbtPick.get();
57+
if (useNbtPick != null) {
58+
this.useNbtPick.remove();
59+
return useNbtPick;
4660
}
4761
return hasControlDown;
4862
}

src/main/java/dev/isxander/controlify/mixins/feature/screenop/impl/chat/ChatComponentMixin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public abstract class ChatComponentMixin {
2828

2929
// in >=1.21.11, there render method is overloaded
3030
@Unique private static final String RENDER_METHOD =
31-
//? if >=1.21.11 {
32-
"render(Lnet/minecraft/client/gui/components/ChatComponent$ChatGraphicsAccess;IIZ)V";
33-
//?} else {
31+
//? if >=26.1 {
32+
"render(Lnet/minecraft/client/gui/components/ChatComponent$ChatGraphicsAccess;IILnet/minecraft/client/gui/components/ChatComponent$DisplayMode;)V";
33+
//?} elif >=1.21.11 {
34+
/*"render(Lnet/minecraft/client/gui/components/ChatComponent$ChatGraphicsAccess;IIZ)V";
35+
*///?} else {
3436
/*"render";
3537
*///?}
3638

src/main/java/dev/isxander/controlify/mixins/feature/screenop/impl/chat/ChatScreenMixin.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ private int modifyMaxSuggestionCount(int count) {
111111

112112
@Override
113113
public boolean controlify$acceptChar(char ch, int modifiers) {
114-
//? if >=1.21.9 {
115-
this.input.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
116-
//?} else {
117-
/*this.input.charTyped(ch, modifiers);
118-
*///?}
114+
//? if >=26.1 {
115+
this.input.charTyped(new net.minecraft.client.input.CharacterEvent(ch));
116+
//?} elif >=1.21.9 {
117+
/*this.input.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
118+
*///?} else {
119+
/*this.input.charTyped(ch);
120+
*///?}
119121
return true;
120122
}
121123

src/main/java/dev/isxander/controlify/mixins/feature/screenop/impl/elements/EditBoxMixin.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package dev.isxander.controlify.mixins.feature.screenop.impl.elements;
22

3-
import com.llamalad7.mixinextras.expression.Definition;
4-
import com.llamalad7.mixinextras.expression.Expression;
53
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
64
import com.llamalad7.mixinextras.sugar.Local;
75
import com.llamalad7.mixinextras.sugar.Share;
86
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
97
import dev.isxander.controlify.api.ControlifyApi;
108
import dev.isxander.controlify.bindings.ControlifyBindings;
11-
import dev.isxander.controlify.font.BindingFontHelper;
129
import dev.isxander.controlify.screenop.ComponentProcessor;
1310
import dev.isxander.controlify.screenop.ComponentProcessorProvider;
1411
import dev.isxander.controlify.screenop.compat.vanilla.EditBoxComponentProcessor;
15-
import dev.isxander.controlify.screenop.keyboard.ComponentKeyboardBehaviour;
1612
import dev.isxander.controlify.screenop.keyboard.CommonKeyboardHints;
13+
import dev.isxander.controlify.screenop.keyboard.ComponentKeyboardBehaviour;
1714
import dev.isxander.controlify.screenop.keyboard.KeyboardOverlayScreen;
1815
import dev.isxander.controlify.utils.render.CGuiPose;
1916
import net.minecraft.client.Minecraft;
@@ -28,6 +25,7 @@
2825
import org.spongepowered.asm.mixin.Shadow;
2926
import org.spongepowered.asm.mixin.Unique;
3027
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
3129

3230
@Mixin(EditBox.class)
3331
public abstract class EditBoxMixin extends AbstractWidget implements ComponentProcessorProvider {
@@ -105,12 +103,16 @@ private String renderHintText(String renderedValue, @Local(argsOnly = true) GuiG
105103
return renderedValue;
106104
}
107105

108-
@Definition(id = "isFocused", method = "Lnet/minecraft/client/gui/components/EditBox;isFocused()Z")
106+
//? if >=26.1 {
107+
@ModifyVariable(method = "renderWidget", at = @At("STORE"), name = "cursorOnScreen")
108+
//?} else {
109+
/*@Definition(id = "isFocused", method = "Lnet/minecraft/client/gui/components/EditBox;isFocused()Z")
109110
@Definition(id = "focusedTime", field = "Lnet/minecraft/client/gui/components/EditBox;focusedTime:J")
110111
@Expression("(?() - this.focusedTime) / 300 % 2 == 0")
111112
@ModifyExpressionValue(method = "renderWidget", at = @At("MIXINEXTRAS:EXPRESSION"))
112-
private boolean preventShowingCursor(boolean showCursor, @Share("renderHint") LocalBooleanRef renderHint) {
113-
return showCursor && !renderHint.get();
113+
*///?}
114+
private boolean preventShowingCursor(boolean cursorOnScreen, @Share("renderHint") LocalBooleanRef renderHint) {
115+
return cursorOnScreen && !renderHint.get();
114116
}
115117

116118
@Override

src/main/java/dev/isxander/controlify/mixins/feature/screenop/impl/sign/AbstractSignEditScreenMixin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ private boolean preventDrawingTitle(GuiGraphics instance, Font font, Component t
118118
@Override
119119
public boolean controlify$acceptChar(char ch, int modifiers) {
120120
if (this.signField == null) return false;
121-
//? if >=1.21.9 {
122-
return this.signField.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
123-
//?} else {
121+
//? if >=26.1 {
122+
return this.signField.charTyped(new net.minecraft.client.input.CharacterEvent(ch));
123+
//?} elif >=1.21.9 {
124+
/*return this.signField.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
125+
*///?} else {
124126
/*return this.signField.charTyped(ch);
125127
*///?}
126128
}

src/main/java/dev/isxander/controlify/screenop/compat/vanilla/EditBoxComponentProcessor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ public boolean supportsCharInput() {
8181

8282
@Override
8383
public boolean acceptChar(char ch, int modifiers) {
84-
//? if >=1.21.9 {
85-
this.editBox.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
86-
//?} else {
87-
/*this.editBox.charTyped(ch, modifiers);
88-
*///?}
84+
//? if >=26.1 {
85+
this.editBox.charTyped(new net.minecraft.client.input.CharacterEvent(ch));
86+
//?} elif >=1.21.9 {
87+
/*this.editBox.charTyped(new net.minecraft.client.input.CharacterEvent(ch, modifiers));
88+
*///?} else {
89+
/*this.editBox.charTyped(ch);
90+
*///?}
8991
return true;
9092
}
9193

src/main/java/dev/isxander/controlify/utils/DebugOverlayHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static void debugComponent(ChatFormatting formatting, Component message)
9696
mc
9797
.gui
9898
.getChat()
99-
.addMessage(
99+
./*? if >=26.1 {*/addClientSystemMessage/*?} else {*//*addMessage*//*?}*/(
100100
Component.empty().append(Component.translatable("debug.prefix").withStyle(formatting, ChatFormatting.BOLD)).append(CommonComponents.SPACE).append(message)
101101
);
102102
}

0 commit comments

Comments
 (0)