Skip to content

Commit 66d2ca3

Browse files
committed
Merge
2 parents a8ec983 + fd28921 commit 66d2ca3

File tree

13 files changed

+73
-54
lines changed

13 files changed

+73
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bin/
3131
# fabric
3232

3333
run/
34+
remappedSrc/
3435

3536
# java
3637

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '1.10-SNAPSHOT'
2+
id 'fabric-loom' version "${loom_version}"
33
id 'maven-publish'
44
}
55

@@ -17,8 +17,8 @@ repositories {
1717
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
1818
// for more information about repositories.
1919
repositories {
20-
maven { url "https://maven.shedaniel.me/" }
21-
maven { url "https://maven.terraformersmc.com/releases/" }
20+
maven { url = "https://maven.shedaniel.me/" }
21+
maven { url = "https://maven.terraformersmc.com/releases/" }
2222
}
2323
}
2424

gradle.properties

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ org.gradle.jvmargs=-Xmx1G
33
org.gradle.parallel=true
44
# Fabric Properties
55
# check these on https://fabricmc.net/develop
6-
minecraft_version=1.21.6
7-
yarn_mappings=1.21.6+build.1
8-
loader_version=0.16.14
6+
minecraft_version=1.21.9
7+
yarn_mappings=1.21.9+build.1
8+
loader_version=0.17.2
9+
loom_version=1.11-SNAPSHOT
910
# Mod Properties
10-
mod_version=1.1.0
11+
mod_version=1.2.0
1112
maven_group=dev.cerus.searchr
1213
archives_base_name=searchr
1314
# Dependencies
14-
fabric_version=0.127.1+1.21.6
15+
fabric_version=0.134.0+1.21.9
1516
# Misc
1617
mod_menu_version=9.0.0
1718
cloth_config_version=13.0.121

gradle/wrapper/gradle-wrapper.jar

1.95 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package dev.cerus.searchr.config;
22

33
import dev.cerus.searchr.interfaces.KeyData;
4+
import net.minecraft.client.MinecraftClient;
45
import net.minecraft.client.gui.screen.Screen;
6+
import net.minecraft.client.input.KeyInput;
57
import net.minecraft.client.option.KeyBinding;
8+
import net.minecraft.client.util.InputUtil;
9+
import net.minecraft.util.Identifier;
10+
import org.lwjgl.glfw.GLFW;
611

712
/**
813
* Custom key bind class
@@ -12,7 +17,7 @@ public class SearchrKeyBind extends KeyBinding {
1217
private boolean requiresCtrl;
1318

1419
public SearchrKeyBind(final String translationKey, final int code) {
15-
super("key.searchr." + translationKey, code, "category.searchr");
20+
super("key.searchr." + translationKey, code, Category.create(Identifier.of("searchr", "searchr")));
1621
}
1722

1823
public SearchrKeyBind requiresCtrl(final boolean b) {
@@ -25,28 +30,37 @@ public boolean isPressed() {
2530
if (!this.requiresCtrl) {
2631
return super.isPressed();
2732
}
28-
return super.isPressed() && Screen.hasControlDown();
33+
return super.isPressed() && hasControlDown();
2934
}
3035

3136
/**
3237
* Check if this key bind was pressed.
3338
* Must be called from keyPressed() method of screens / widgets.
3439
*
35-
* @param keyCode The pressed keycode
40+
* @param keyInput The key input
3641
*
3742
* @return if the pressed keycode matches this key
3843
*/
39-
public boolean wasPressed(final int keyCode) {
40-
final boolean pressed = ((KeyData) this).getBoundKey().getCode() == keyCode;
41-
return pressed && (!this.requiresCtrl || Screen.hasControlDown());
44+
public boolean wasPressed(final KeyInput keyInput) {
45+
final boolean pressed = ((KeyData) this).getBoundKey().getCode() == keyInput.key();
46+
return pressed && (!this.requiresCtrl || keyInput.hasCtrl());
4247
}
4348

4449
@Override
4550
public boolean wasPressed() {
4651
if (!this.requiresCtrl) {
4752
return super.wasPressed();
4853
}
49-
return super.wasPressed() && Screen.hasControlDown();
54+
return super.wasPressed() && hasControlDown();
5055
}
5156

57+
private static boolean hasControlDown() {
58+
return InputUtil.isKeyPressed(
59+
MinecraftClient.getInstance().getWindow(),
60+
GLFW.GLFW_KEY_LEFT_CONTROL
61+
) || InputUtil.isKeyPressed(
62+
MinecraftClient.getInstance().getWindow(),
63+
GLFW.GLFW_KEY_RIGHT_CONTROL
64+
);
65+
}
5266
}

src/main/java/dev/cerus/searchr/mixin/ChatScreenMixin.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import net.minecraft.client.gui.screen.ChatScreen;
1313
import net.minecraft.client.gui.screen.Screen;
1414
import net.minecraft.client.gui.widget.TextFieldWidget;
15+
import net.minecraft.client.input.KeyInput;
16+
import net.minecraft.client.util.InputUtil;
1517
import net.minecraft.text.Text;
1618
import org.lwjgl.glfw.GLFW;
1719
import org.spongepowered.asm.mixin.Mixin;
@@ -47,9 +49,10 @@ private void injectInit(final CallbackInfo ci) {
4749
((Configurable) this.chatField).setConfig(this.config);
4850
}
4951

50-
@Inject(method = "keyPressed(III)Z", at = @At("HEAD"), cancellable = true)
51-
public void injectOnKeyPress(final int keyCode, final int scanCode, final int modifiers, final CallbackInfoReturnable<Boolean> ci) {
52-
if (KeyBinds.ACTIVATE.wasPressed(keyCode)) {
52+
@Inject(method = "keyPressed(Lnet/minecraft/client/input/KeyInput;)Z", at = @At("HEAD"), cancellable = true)
53+
public void injectOnKeyPress(final KeyInput keyInput, final CallbackInfoReturnable<Boolean> ci) {
54+
int keyCode = keyInput.key();
55+
if (KeyBinds.ACTIVATE.wasPressed(keyInput)) {
5356
if (!this.isSearchEnabled()) {
5457
this.enableSearch();
5558
} else {
@@ -58,7 +61,7 @@ public void injectOnKeyPress(final int keyCode, final int scanCode, final int mo
5861
this.updateSuggestion(this.chatField.getText());
5962
}
6063
ci.setReturnValue(true);
61-
} else if (this.shouldExit(keyCode) && this.isSearchEnabled()) {
64+
} else if (this.shouldExit(keyInput) && this.isSearchEnabled()) {
6265
// Exit search without keeping any text
6366
this.disableSearch();
6467
this.chatField.setText("");
@@ -74,8 +77,9 @@ public void injectOnKeyPress(final int keyCode, final int scanCode, final int mo
7477
}
7578
}
7679

77-
private boolean shouldExit(final int keyCode) {
78-
final boolean ctrlC = this.config.keys.allowCtrlC && keyCode == GLFW.GLFW_KEY_C && Screen.hasControlDown();
80+
private boolean shouldExit(final KeyInput keyInput) {
81+
final int keyCode = keyInput.key();
82+
final boolean ctrlC = this.config.keys.allowCtrlC && keyCode == GLFW.GLFW_KEY_C && keyInput.hasCtrl();
7983
final boolean normalExit = keyCode == GLFW.GLFW_KEY_ESCAPE;
8084
return normalExit || ctrlC;
8185
}

src/main/java/dev/cerus/searchr/mixin/TextFieldWidgetMixin.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.client.gui.screen.Screen;
99
import net.minecraft.client.gui.widget.ClickableWidget;
1010
import net.minecraft.client.gui.widget.TextFieldWidget;
11+
import net.minecraft.client.input.KeyInput;
1112
import net.minecraft.text.Text;
1213

1314
import org.lwjgl.glfw.GLFW;
@@ -28,6 +29,7 @@ public abstract class TextFieldWidgetMixin extends ClickableWidget implements Se
2829

2930
@Shadow private TextRenderer textRenderer;
3031
@Shadow private String text;
32+
@Shadow private int textY;
3133

3234
private ModConfig config;
3335
private boolean searchEnabled;
@@ -45,9 +47,6 @@ public TextFieldWidgetMixin(final int x, final int y, final int width, final int
4547
@Shadow
4648
public abstract void setCursorToEnd(boolean shiftKeyPressed);
4749

48-
@Shadow
49-
private int textY;
50-
5150
@Inject(
5251
method = "renderWidget(Lnet/minecraft/client/gui/DrawContext;IIF)V",
5352
at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(III)I", shift = At.Shift.AFTER),
@@ -58,7 +57,6 @@ private void injectOnRenderWidget(final DrawContext context, final int mouseX, f
5857
if (this.searchEnabled) {
5958
final int posX = $$10; // See local k of TextFieldWidget#render()
6059
final int posY = this.textY;
61-
6260

6361
if (this.suggestion == null) {
6462
if (this.text.isEmpty()) {
@@ -89,15 +87,16 @@ private void injectOnRenderWidget(final DrawContext context, final int mouseX, f
8987
}
9088
}
9189

92-
@Inject(method = "keyPressed(III)Z", at = @At("HEAD"), cancellable = true)
93-
public void injectOnKeyPressed(final int keyCode, final int scanCode, final int modifiers, final CallbackInfoReturnable<Boolean> ci) {
90+
@Inject(method = "keyPressed(Lnet/minecraft/client/input/KeyInput;)Z", at = @At("HEAD"), cancellable = true)
91+
public void injectOnKeyPressed(final KeyInput keyInput, final CallbackInfoReturnable<Boolean> ci) {
9492
// Block a bunch of special keys while search is enabled
93+
int keyCode = keyInput.key();
9594
if (this.isSearchEnabled() && (keyCode == GLFW.GLFW_KEY_LEFT
9695
|| keyCode == GLFW.GLFW_KEY_RIGHT
9796
|| keyCode == GLFW.GLFW_KEY_HOME
9897
|| keyCode == GLFW.GLFW_KEY_END
99-
|| Screen.isSelectAll(keyCode)
100-
|| Screen.isPaste(keyCode))) {
98+
|| keyInput.isSelectAll()
99+
|| keyInput.isPaste())) {
101100
ci.setReturnValue(true);
102101
}
103102
}

0 commit comments

Comments
 (0)