From 21a7902a81781c1c2f731075e67444e408fe9ea2 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 27 Apr 2020 00:18:11 +0200 Subject: [PATCH] Fixed abilities not triggering and fixed teleporting --- .../unicopia/ability/AbilityDispatcher.java | 8 +++++++- .../unicopia/ability/UnicornTeleportAbility.java | 2 +- .../unicopia/client/KeyBindingsHandler.java | 16 +++++++++------- .../unicopia/entity/player/PlayerImpl.java | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index 5461d3f0..140e8712 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -70,7 +70,7 @@ public class AbilityDispatcher implements Updatable, NbtSerialisable { @Nullable protected synchronized Optional> getUsableAbility() { return activeAbility.filter(ability -> { - return (triggered && warmup == 0 && cooldown == 0) && ability.canUse(player.getSpecies()); + return (!(ability == null || (triggered && warmup == 0 && cooldown == 0)) && ability.canUse(player.getSpecies())); }); } @@ -86,13 +86,19 @@ public class AbilityDispatcher implements Updatable, NbtSerialisable { private void activate(Ability ability) { if (warmup > 0) { warmup--; + System.out.println("warming up"); ability.preApply(player); return; } if (cooldown > 0) { cooldown--; + System.out.println("cooling down"); ability.postApply(player); + + if (cooldown <= 0) { + setAbility(null); + } return; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index ab364cbc..6dc9e67b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -118,7 +118,7 @@ public class UnicornTeleportAbility implements Ability { } } - player.setPos( + player.teleport( data.x + (player.getX() - Math.floor(player.getX())), data.y, data.z + (player.getZ() - Math.floor(player.getZ()))); diff --git a/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java b/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java index 3f4b56da..b5d93e6f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/client/KeyBindingsHandler.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.Ability; import com.minelittlepony.unicopia.ability.data.Hit; @@ -23,14 +24,14 @@ import net.minecraft.util.Identifier; class KeyBindingsHandler { private final String KEY_CATEGORY = "unicopia.category.name"; - private final Map>> keyPools = new HashMap<>(); + private final Map>> keyPools = new HashMap<>(); private final Set bindings = new HashSet<>(); private final Set pressed = new HashSet<>(); private Collection> getKeyCodePool(KeyBinding keyCode) { - return keyPools.computeIfAbsent(keyCode, i -> new ArrayList<>()); + return keyPools.computeIfAbsent(keyCode.getDefaultKeyCode(), i -> new ArrayList<>()); } public void addKeybind(Ability p) { @@ -40,7 +41,7 @@ class KeyBindingsHandler { int code = Abilities.KEYS_CODES.get(id); FabricKeyBinding b = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, code, KEY_CATEGORY).build(); - KeyBindingRegistry.INSTANCE.register(b); + getKeyCodePool(b).add(p); bindings.add(b); } @@ -54,15 +55,16 @@ class KeyBindingsHandler { for (KeyBinding i : bindings) { if (i.isPressed()) { - if (pressed.add(i)) { - getKeyCodePool(i) - .stream() - .filter(power -> power.canUse(iplayer.getSpecies())) + System.out.println("key press " + i); + Race race = iplayer.getSpecies(); + getKeyCodePool(i).stream() + .filter(power -> power.canUse(race)) .findFirst() .ifPresent(iplayer.getAbilities()::tryUseAbility); } } else if (pressed.remove(i)) { + System.out.println("key release " + i); iplayer.getAbilities().tryClearAbility(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java index b06e2c20..11283e19 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerImpl.java @@ -172,6 +172,7 @@ public class PlayerImpl implements Pony, MagicReserves { dirty = false; if (entity instanceof ServerPlayerEntity) { + System.out.println("Sending capabilities for player"); Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this)); } }