package com.minelittlepony.unicopia.client; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.lwjgl.glfw.GLFW; import com.minelittlepony.unicopia.ability.AbilitySlot; import com.minelittlepony.unicopia.equine.player.Pony; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.options.KeyBinding; class KeyBindingsHandler { private final String KEY_CATEGORY = "unicopia.category.name"; private final Map keys = new HashMap<>(); private final Set pressed = new HashSet<>(); public KeyBindingsHandler() { addKeybind(GLFW.GLFW_KEY_O, AbilitySlot.PRIMARY); addKeybind(GLFW.GLFW_KEY_P, AbilitySlot.SECONDARY); addKeybind(GLFW.GLFW_KEY_L, AbilitySlot.TERTIARY); } public void addKeybind(int code, AbilitySlot slot) { keys.put(KeyBindingHelper.registerKeyBinding(new KeyBinding("key.unicopia" + slot.name().toLowerCase(), code, KEY_CATEGORY)), slot); } public void tick(MinecraftClient client) { if (client.currentScreen != null || client.player == null) { return; } Pony iplayer = Pony.of(client.player); for (KeyBinding i : keys.keySet()) { AbilitySlot slot = keys.get(i); if (slot == AbilitySlot.PRIMARY && client.options.keySneak.isPressed()) { slot = AbilitySlot.PASSIVE; } if (i.isPressed()) { if (pressed.add(i)) { System.out.println("Key down " + slot); iplayer.getAbilities().activate(slot); } } else if (pressed.remove(i)) { System.out.println("Key up " + slot); iplayer.getAbilities().clear(slot); } } } }