From 964195590502e056340a4682a0f2541c47290f8c Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 8 Jul 2023 15:25:26 -0700 Subject: [PATCH] KeyBind: Fix category not being added to the Map on KeyBinding This caused a crash when viewing the control screen --- .../com/chattriggers/ctjs/mixins/KeyBindingAccessor.java | 4 ++++ .../com/chattriggers/ctjs/minecraft/objects/KeyBind.kt | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chattriggers/ctjs/mixins/KeyBindingAccessor.java b/src/main/java/com/chattriggers/ctjs/mixins/KeyBindingAccessor.java index ed41561d..45cd9b51 100644 --- a/src/main/java/com/chattriggers/ctjs/mixins/KeyBindingAccessor.java +++ b/src/main/java/com/chattriggers/ctjs/mixins/KeyBindingAccessor.java @@ -5,10 +5,14 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import java.util.Map; import java.util.Set; @Mixin(KeyBinding.class) public interface KeyBindingAccessor { + @Accessor("CATEGORY_ORDER_MAP") + static Map getCategoryMap() { throw new IllegalStateException(); } + @Accessor("KEY_CATEGORIES") static Set getKeyCategories() { throw new IllegalStateException(); diff --git a/src/main/kotlin/com/chattriggers/ctjs/minecraft/objects/KeyBind.kt b/src/main/kotlin/com/chattriggers/ctjs/minecraft/objects/KeyBind.kt index c73b1f21..1b4e235e 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/minecraft/objects/KeyBind.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/minecraft/objects/KeyBind.kt @@ -10,6 +10,7 @@ import com.chattriggers.ctjs.utils.Initializer import com.chattriggers.ctjs.utils.InternalApi import com.chattriggers.ctjs.utils.asMixin import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents +import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl import net.minecraft.client.option.KeyBinding import net.minecraft.client.resource.language.I18n import org.apache.commons.lang3.ArrayUtils @@ -24,7 +25,6 @@ class KeyBind { private var down: Boolean = false init { - @Suppress("LeakingThis") keyBinds.add(this) } @@ -211,6 +211,10 @@ class KeyBind { Client.getMinecraft().options.allKeys, keyBinding )) + + val categoryMap = KeyBindingAccessor.getCategoryMap() + val maxInt = categoryMap.values.max() ?: 0 + categoryMap[keyBinding.category] = maxInt + 1 } private fun removeRawKeyBinding(keyBinding: KeyBinding) {