Skip to content

Commit

Permalink
KeyBind: Fix category not being added to the Map on KeyBinding
Browse files Browse the repository at this point in the history
This caused a crash when viewing the control screen
  • Loading branch information
mattco98 committed Jul 8, 2023
1 parent 2de212d commit 9641955
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> getCategoryMap() { throw new IllegalStateException(); }

@Accessor("KEY_CATEGORIES")
static Set<String> getKeyCategories() {
throw new IllegalStateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +25,6 @@ class KeyBind {
private var down: Boolean = false

init {
@Suppress("LeakingThis")
keyBinds.add(this)
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9641955

Please sign in to comment.