Change to check for a particular spell rather than any spell

This commit is contained in:
Sollace 2021-12-24 00:36:54 +02:00
parent 063d4e6dd2
commit d026a6c06a
5 changed files with 31 additions and 13 deletions

View file

@ -5,7 +5,6 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect;
@ -41,7 +40,7 @@ public class PegasusRainboomAbility implements Ability<Hit> {
return null;
}
if (player.getPhysics().isFlying() && !player.getSpellSlot().isPresent()) {
if (player.getPhysics().isFlying() && !SpellType.RAINBOOM.isOn(player)) {
return Hit.INSTANCE;
}
@ -65,7 +64,7 @@ public class PegasusRainboomAbility implements Ability<Hit> {
return;
}
if (player.getPhysics().isFlying() && !player.getSpellSlot().isPresent()) {
if (player.getPhysics().isFlying() && !SpellType.RAINBOOM.isOn(player)) {
player.getMagicalReserves().getMana().multiply(0.1F);
player.addParticle(new OrientedBillboardParticleEffect(UParticles.RAINBOOM_RING, player.getPhysics().getMotionAngle()), player.getOriginVector(), Vec3d.ZERO);
SpellType.RAINBOOM.withTraits().apply(player);

View file

@ -43,6 +43,13 @@ public interface SpellContainer {
*/
boolean contains(UUID id);
/**
* Checks if any matching spells are active.
*/
default boolean contains(@Nullable SpellPredicate<?> type) {
return get(type, true).isPresent();
}
/**
* Gets the active effect for this caster updating it if needed.
*/
@ -52,9 +59,12 @@ public interface SpellContainer {
/**
* Returns true if this caster has an active effect attached to it.
*
* @deprecated To be removed
*/
@Deprecated
default boolean isPresent() {
return get(true).isPresent();
return contains((SpellPredicate<?>)null);
}
/**
@ -95,6 +105,11 @@ public interface SpellContainer {
return delegate().contains(id);
}
@Override
default boolean contains(@Nullable SpellPredicate<?> type) {
return delegate().contains(type);
}
@Override
default <T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type, boolean update) {
return delegate().get(type, update);

View file

@ -14,6 +14,6 @@ public interface SpellPredicate<T extends Spell> extends Predicate<Spell> {
SpellPredicate<AbstractDisguiseSpell> IS_DISGUISE = s -> s instanceof AbstractDisguiseSpell;
default boolean isOn(Caster<?> caster) {
return caster.getSpellSlot().get(this, false).isPresent();
return caster.getSpellSlot().contains(this);
}
}

View file

@ -16,6 +16,7 @@ import com.minelittlepony.unicopia.WorldTribeManager;
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
import com.minelittlepony.unicopia.ability.EarthPonyStompAbility;
import com.minelittlepony.unicopia.ability.magic.Affine;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.ability.magic.spell.Spell;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.TraitDiscovery;
@ -161,7 +162,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
@Override
public boolean isInvisible() {
return invisible && getSpellSlot().isPresent();
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
}
public boolean isSpeciesPersisted() {

View file

@ -46,14 +46,14 @@ public class EffectSync implements SpellContainer {
}
@Override
@SuppressWarnings("unchecked")
public <T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type, boolean update) {
return (Optional<T>)(type == null ? read(update, true).findFirst() : read(update, true).filter(type).findFirst());
public boolean contains(@Nullable SpellPredicate<?> type) {
return read(type, true, false).findFirst().isPresent();
}
@Override
public boolean isPresent() {
return read(true, false).findFirst().isPresent();
@SuppressWarnings("unchecked")
public <T extends Spell> Optional<T> get(@Nullable SpellPredicate<T> type, boolean update) {
return (Optional<T>)(read(type, update, true).findFirst());
}
@Override
@ -99,13 +99,16 @@ public class EffectSync implements SpellContainer {
}
}
private Stream<Spell> read(boolean synchronize, boolean sendUpdate) {
private Stream<Spell> read(@Nullable SpellPredicate<?> type, boolean synchronize, boolean sendUpdate) {
if (synchronize && spells.fromNbt(owner.getEntity().getDataTracker().get(param)) && sendUpdate) {
owner.getEntity().getDataTracker().set(param, spells.toNbt());
}
if (type == null) {
return spells.getReferences();
}
return spells.getReferences().filter(type);
}
public boolean reduce(Alteration alteration) {
spells.fromNbt(owner.getEntity().getDataTracker().get(param));