extend ability system to support dynamic slot counts, add skill tree validation, new prerequisites API, and extended mod commands
This commit is contained in:
@@ -4,43 +4,45 @@ import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.fretux.skillengine.network.PacketHandler;
|
||||
import net.fretux.skillengine.network.ServerboundActivateAbilityPacket;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class AbilityKeybindHandler {
|
||||
|
||||
public static final KeyMapping ABILITY_1 = new KeyMapping(
|
||||
"key.skillengine.ability1", KeyConflictContext.IN_GAME,
|
||||
InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_Y, "key.categories.gameplay"
|
||||
);
|
||||
public static final int MAX_REGISTERED_ABILITY_SLOTS = 9;
|
||||
public static final KeyMapping[] ABILITY_KEYS = new KeyMapping[MAX_REGISTERED_ABILITY_SLOTS];
|
||||
|
||||
public static final KeyMapping ABILITY_2 = new KeyMapping(
|
||||
"key.skillengine.ability2", KeyConflictContext.IN_GAME,
|
||||
InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_X, "key.categories.gameplay"
|
||||
);
|
||||
|
||||
public static final KeyMapping ABILITY_3 = new KeyMapping(
|
||||
"key.skillengine.ability3", KeyConflictContext.IN_GAME,
|
||||
InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_C, "key.categories.gameplay"
|
||||
);
|
||||
static {
|
||||
for (int slot = 1; slot <= MAX_REGISTERED_ABILITY_SLOTS; slot++) {
|
||||
ABILITY_KEYS[slot - 1] = new KeyMapping(
|
||||
"key.skillengine.ability" + slot,
|
||||
KeyConflictContext.IN_GAME,
|
||||
InputConstants.Type.KEYSYM,
|
||||
defaultKeyForSlot(slot),
|
||||
"key.categories.gameplay"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onInput(InputEvent.Key event) {
|
||||
if (ABILITY_1.consumeClick()) {
|
||||
if (SkilltreeClientState.getClientCooldown(1) <= 0) {
|
||||
PacketHandler.CHANNEL.sendToServer(new ServerboundActivateAbilityPacket(1));
|
||||
}
|
||||
}
|
||||
if (ABILITY_2.consumeClick()) {
|
||||
if (SkilltreeClientState.getClientCooldown(2) <= 0) {
|
||||
PacketHandler.CHANNEL.sendToServer(new ServerboundActivateAbilityPacket(2));
|
||||
}
|
||||
}
|
||||
if (ABILITY_3.consumeClick()) {
|
||||
if (SkilltreeClientState.getClientCooldown(3) <= 0) {
|
||||
PacketHandler.CHANNEL.sendToServer(new ServerboundActivateAbilityPacket(3));
|
||||
int activeSlots = SkilltreeClientState.getAbilitySlots().length;
|
||||
int handledSlots = Math.min(activeSlots, ABILITY_KEYS.length);
|
||||
for (int slot = 1; slot <= handledSlots; slot++) {
|
||||
if (ABILITY_KEYS[slot - 1].consumeClick()) {
|
||||
if (SkilltreeClientState.getClientCooldown(slot) <= 0) {
|
||||
PacketHandler.CHANNEL.sendToServer(new ServerboundActivateAbilityPacket(slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int defaultKeyForSlot(int slot) {
|
||||
return switch (slot) {
|
||||
case 1 -> GLFW.GLFW_KEY_Z;
|
||||
case 2 -> GLFW.GLFW_KEY_X;
|
||||
case 3 -> GLFW.GLFW_KEY_C;
|
||||
default -> InputConstants.UNKNOWN.getValue();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user