mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed abilities not triggering and fixed teleporting
This commit is contained in:
parent
6b9e0eaa30
commit
21a7902a81
4 changed files with 18 additions and 9 deletions
|
@ -70,7 +70,7 @@ public class AbilityDispatcher implements Updatable, NbtSerialisable {
|
|||
@Nullable
|
||||
protected synchronized Optional<Ability<?>> 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 <T extends Hit> void activate(Ability<T> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
|
|||
}
|
||||
}
|
||||
|
||||
player.setPos(
|
||||
player.teleport(
|
||||
data.x + (player.getX() - Math.floor(player.getX())),
|
||||
data.y,
|
||||
data.z + (player.getZ() - Math.floor(player.getZ())));
|
||||
|
|
|
@ -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<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> pressed = new HashSet<>();
|
||||
|
||||
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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue