Fix crash when querying abilities for a slot

This commit is contained in:
Sollace 2020-09-22 15:52:44 +02:00
parent b4e6b3a037
commit b312188171
2 changed files with 3 additions and 2 deletions

View file

@ -15,8 +15,8 @@ public interface Abilities {
Registry<Ability<?>> REGISTRY = Registries.createSimple(new Identifier("unicopia", "abilities"));
// unicorn / alicorn
Ability<?> TELEPORT = register(new UnicornTeleportAbility(), "teleport", AbilitySlot.SECONDARY);
Ability<?> CAST = register(new UnicornCastingAbility(), "cast", AbilitySlot.PRIMARY);
Ability<?> TELEPORT = register(new UnicornTeleportAbility(), "teleport", AbilitySlot.SECONDARY);
// earth / alicorn
Ability<?> STOMP = register(new EarthPonyStompAbility(), "stomp", AbilitySlot.PRIMARY);

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.ability;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
@ -177,7 +178,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
public Optional<Ability<?>> getAbility() {
Race race = player.getSpecies();
return Abilities.BY_SLOT.get(slot).stream().filter(a -> a.canUse(race)).findFirst();
return Abilities.BY_SLOT.computeIfAbsent(slot, c -> Collections.emptySet()).stream().filter(a -> a.canUse(race)).findFirst();
}
protected synchronized void setActiveAbility(Ability<?> power) {