Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit b479bb9

Browse files
committed
char typed
1 parent be43547 commit b479bb9

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

patchwork-rendering/src/main/java/com/patchworkmc/mixin/rendering/MixinKeyboard.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1010

1111
import net.minecraft.client.Keyboard;
12+
import net.minecraft.client.gui.Element;
1213
import net.minecraft.client.gui.ParentElement;
1314
import net.minecraft.client.gui.screen.Screen;
1415

@@ -18,7 +19,7 @@ public abstract class MixinKeyboard {
1819
private boolean repeatEvents;
1920

2021
@Inject(method = "method_1454", at = @At("HEAD"), cancellable = true)
21-
public void preKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int j, CallbackInfo info) {
22+
private void preKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int j, CallbackInfo info) {
2223
if (i != 1 && (i != 2 || !this.repeatEvents)) {
2324
if (i == 0) {
2425
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardKeyReleasedEvent.Pre((Screen) element, key, scanCode, j))) {
@@ -35,7 +36,7 @@ public void preKeyEvent(int i, boolean[] bls, ParentElement element, int key, in
3536
}
3637

3738
@Inject(method = "method_1454", at = @At("RETURN"))
38-
public void postKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int j, CallbackInfo info) {
39+
private void postKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int j, CallbackInfo info) {
3940
if (bls[0]) {
4041
return;
4142
}
@@ -52,4 +53,22 @@ public void postKeyEvent(int i, boolean[] bls, ParentElement element, int key, i
5253
}
5354
}
5455
}
56+
57+
@Inject(method = "method_1458", at = @At("HEAD"), cancellable = true)
58+
private static void charEvent(Element element, int i, int j, CallbackInfo info) {
59+
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Pre((Screen) element, (char) i, j))) {
60+
info.cancel();
61+
} else if (!element.charTyped((char) i, j)) {
62+
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Post((Screen) element, (char) i, j));
63+
}
64+
}
65+
66+
@Inject(method = "method_1473", at = @At("HEAD"), cancellable = true)
67+
private static void charEvent(Element element, char i, int j, CallbackInfo info) {
68+
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Pre((Screen) element, i, j))) {
69+
info.cancel();
70+
} else if (!element.charTyped(i, j)) {
71+
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Post((Screen) element, i, j));
72+
}
73+
}
5574
}

patchwork-rendering/src/main/java/com/patchworkmc/mixin/rendering/MixinMouse.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void preMouseClicked(boolean[] bls, double d, double e, int button, Callb
6060
}
6161

6262
@Inject(method = "method_1611", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
63-
public void postMouseClicked(boolean[] bls, double d, double e, int button, CallbackInfo info) {
63+
private void postMouseClicked(boolean[] bls, double d, double e, int button, CallbackInfo info) {
6464
if (bls[0]) {
6565
return;
6666
}
@@ -72,15 +72,15 @@ public void postMouseClicked(boolean[] bls, double d, double e, int button, Call
7272
}
7373

7474
@Inject(method = "method_1605", at = @At("HEAD"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
75-
public void preMouseReleased(boolean[] bls, double d, double e, int button, CallbackInfo info) {
75+
private void preMouseReleased(boolean[] bls, double d, double e, int button, CallbackInfo info) {
7676
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Pre(client.currentScreen, d, e, button))) {
7777
bls[0] = true;
7878
info.cancel();
7979
}
8080
}
8181

8282
@Inject(method = "method_1605", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
83-
public void postMouseReleased(boolean[] bls, double d, double e, int button, CallbackInfo info) {
83+
private void postMouseReleased(boolean[] bls, double d, double e, int button, CallbackInfo info) {
8484
if (bls[0]) {
8585
return;
8686
}
@@ -92,21 +92,21 @@ public void postMouseReleased(boolean[] bls, double d, double e, int button, Cal
9292
}
9393

9494
@Inject(method = "method_1602", at = @At("HEAD"), cancellable = true)
95-
public void preMouseDragged(Element element, double d, double e, double f, double g, CallbackInfo info) {
95+
private void preMouseDragged(Element element, double d, double e, double f, double g, CallbackInfo info) {
9696
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseDragEvent.Pre(client.currentScreen, d, e, activeButton, f, g))) {
9797
info.cancel();
9898
}
9999
}
100100

101101
@Inject(method = "method_1602", at = @At("RETURN"))
102-
public void postMouseDragged(Element element, double d, double e, double f, double g, CallbackInfo info) {
102+
private void postMouseDragged(Element element, double d, double e, double f, double g, CallbackInfo info) {
103103
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseDragEvent.Post(client.currentScreen, d, e, activeButton, f, g));
104104
}
105105

106106
@Inject(method = "onMouseScroll", at = @At(value = "INVOKE",
107107
target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z",
108108
ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
109-
public void preMouseScrolled(long window, double d, double e, CallbackInfo ci, double f, double g, double h) {
109+
private void preMouseScrolled(long window, double d, double e, CallbackInfo ci, double f, double g, double h) {
110110
if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseScrollEvent.Pre(client.currentScreen, g, h, f))) {
111111
ci.cancel();
112112
}
@@ -115,7 +115,7 @@ public void preMouseScrolled(long window, double d, double e, CallbackInfo ci, d
115115
@Inject(method = "onMouseScroll", at = @At(value = "INVOKE",
116116
target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z",
117117
ordinal = 0, shift = At.Shift.BY, by = 2), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
118-
public void postMouseScrolled(long window, double d, double e, CallbackInfo ci, double f, double g, double h) {
118+
private void postMouseScrolled(long window, double d, double e, CallbackInfo ci, double f, double g, double h) {
119119
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseScrollEvent.Post(client.currentScreen, g, h, f));
120120
}
121121

0 commit comments

Comments
 (0)