Fixed abilities not triggering and fixed teleporting

This commit is contained in:
Sollace 2020-04-27 00:18:11 +02:00
parent 6b9e0eaa30
commit 21a7902a81
4 changed files with 18 additions and 9 deletions

View file

@ -70,7 +70,7 @@ public class AbilityDispatcher implements Updatable, NbtSerialisable {
@Nullable @Nullable
protected synchronized Optional<Ability<?>> getUsableAbility() { protected synchronized Optional<Ability<?>> getUsableAbility() {
return activeAbility.filter(ability -> { 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 <T extends Hit> void activate(Ability<T> ability) { private <T extends Hit> void activate(Ability<T> ability) {
if (warmup > 0) { if (warmup > 0) {
warmup--; warmup--;
System.out.println("warming up");
ability.preApply(player); ability.preApply(player);
return; return;
} }
if (cooldown > 0) { if (cooldown > 0) {
cooldown--; cooldown--;
System.out.println("cooling down");
ability.postApply(player); ability.postApply(player);
if (cooldown <= 0) {
setAbility(null);
}
return; return;
} }

View file

@ -118,7 +118,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
} }
} }
player.setPos( player.teleport(
data.x + (player.getX() - Math.floor(player.getX())), data.x + (player.getX() - Math.floor(player.getX())),
data.y, data.y,
data.z + (player.getZ() - Math.floor(player.getZ()))); data.z + (player.getZ() - Math.floor(player.getZ())));

View file

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.Abilities;
import com.minelittlepony.unicopia.ability.Ability; import com.minelittlepony.unicopia.ability.Ability;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
@ -23,14 +24,14 @@ import net.minecraft.util.Identifier;
class KeyBindingsHandler { class KeyBindingsHandler {
private final String KEY_CATEGORY = "unicopia.category.name"; private final String KEY_CATEGORY = "unicopia.category.name";
private final Map<KeyBinding, List<Ability<? extends Hit>>> keyPools = new HashMap<>(); private final Map<InputUtil.KeyCode, List<Ability<? extends Hit>>> keyPools = new HashMap<>();
private final Set<KeyBinding> bindings = new HashSet<>(); private final Set<KeyBinding> bindings = new HashSet<>();
private final Set<KeyBinding> pressed = new HashSet<>(); private final Set<KeyBinding> pressed = new HashSet<>();
private Collection<Ability<?>> getKeyCodePool(KeyBinding keyCode) { private Collection<Ability<?>> getKeyCodePool(KeyBinding keyCode) {
return keyPools.computeIfAbsent(keyCode, i -> new ArrayList<>()); return keyPools.computeIfAbsent(keyCode.getDefaultKeyCode(), i -> new ArrayList<>());
} }
public void addKeybind(Ability<?> p) { public void addKeybind(Ability<?> p) {
@ -40,7 +41,7 @@ class KeyBindingsHandler {
int code = Abilities.KEYS_CODES.get(id); int code = Abilities.KEYS_CODES.get(id);
FabricKeyBinding b = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, code, KEY_CATEGORY).build(); FabricKeyBinding b = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, code, KEY_CATEGORY).build();
KeyBindingRegistry.INSTANCE.register(b);
getKeyCodePool(b).add(p); getKeyCodePool(b).add(p);
bindings.add(b); bindings.add(b);
} }
@ -54,15 +55,16 @@ class KeyBindingsHandler {
for (KeyBinding i : bindings) { for (KeyBinding i : bindings) {
if (i.isPressed()) { if (i.isPressed()) {
if (pressed.add(i)) { if (pressed.add(i)) {
getKeyCodePool(i) System.out.println("key press " + i);
.stream() Race race = iplayer.getSpecies();
.filter(power -> power.canUse(iplayer.getSpecies())) getKeyCodePool(i).stream()
.filter(power -> power.canUse(race))
.findFirst() .findFirst()
.ifPresent(iplayer.getAbilities()::tryUseAbility); .ifPresent(iplayer.getAbilities()::tryUseAbility);
} }
} else if (pressed.remove(i)) { } else if (pressed.remove(i)) {
System.out.println("key release " + i);
iplayer.getAbilities().tryClearAbility(); iplayer.getAbilities().tryClearAbility();
} }
} }

View file

@ -172,6 +172,7 @@ public class PlayerImpl implements Pony, MagicReserves {
dirty = false; dirty = false;
if (entity instanceof ServerPlayerEntity) { if (entity instanceof ServerPlayerEntity) {
System.out.println("Sending capabilities for player");
Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this)); Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this));
} }
} }