Skip to content

Commit

Permalink
[1.6.4] Fix crash when trying to register more than one keybinding.
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jul 2, 2024
1 parent c49e800 commit 281301e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KeybindingTest implements ClientModInitializer {
@Override
public void onInitializeClient() {
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey", Keyboard.KEY_F, "key.categories.lftesting"));
KeyBinding keyBinding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey2", Keyboard.KEY_G, "key.categories.lftesting"));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (keyBinding.wasPressed()) {
System.out.printf("The key %s was pressed%n", Keyboard.getKeyName(keyBinding.getCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KeybindingTest implements ClientModInitializer {
@Override
public void onInitializeClient() {
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey", Keyboard.KEY_F));
KeyBinding keyBinding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey2", Keyboard.KEY_G));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (keyBinding.wasPressed()) {
System.out.printf("The key %s was pressed%n", Keyboard.getKeyName(keyBinding.code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KeybindingTest implements ClientModInitializer {
@Override
public void onInitializeClient() {
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey", Keyboard.KEY_F, "key.categories.lftesting"));
KeyBinding keyBinding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey2", Keyboard.KEY_G, "key.categories.lftesting"));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (keyBinding.wasPressed()) {
System.out.printf("The key %s was pressed%n", Keyboard.getKeyName(keyBinding.getCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KeybindingTest implements ClientModInitializer {
@Override
public void onInitializeClient() {
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey", Keyboard.KEY_F, "key.categories.lftesting"));
KeyBinding keyBinding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding("api.keybinding.testTranslationKey2", Keyboard.KEY_G, "key.categories.lftesting"));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (keyBinding.wasPressed()) {
System.out.printf("The key %s was pressed%n", Keyboard.getKeyName(keyBinding.getCode()));
Expand Down
3 changes: 3 additions & 0 deletions legacy-fabric-keybindings-api-v1/common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loom {
accessWidenerPath = file("src/main/resources/legacy-fabric-keybinding-api-v1-common.accesswidener")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private KeyBindingRegistryImpl() {
public static KeyBinding registerKeyBinding(KeyBinding binding) {
for (KeyBinding existingKeyBindings : moddedKeyBindings) {
if (existingKeyBindings == binding) {
throw new RuntimeException("Attempted to register same key binding twice " + binding.getTranslationKey() + "!");
} else if (existingKeyBindings.getTranslationKey().equals(binding.getTranslationKey())) {
throw new RuntimeException("Attempted to register two key bindings with equal ID: " + binding.getTranslationKey() + "!");
throw new RuntimeException("Attempted to register same key binding twice " + binding.translationKey + "!");
} else if (existingKeyBindings.translationKey.equals(binding.translationKey)) {
throw new RuntimeException("Attempted to register two key bindings with equal ID: " + binding.translationKey + "!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"mixins": [
"legacy-fabric-keybinding-api-v1-common.mixins.json"
],
"accessWidener": "legacy-fabric-keybinding-api-v1-common.accesswidener",
"description": "Hooks that help adding keybindings",
"custom": {
"modmenu": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v1 named

accessible field net/minecraft/client/option/KeyBinding translationKey Ljava/lang/String;

0 comments on commit 281301e

Please sign in to comment.