diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java index 90941956..5efafa2d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java @@ -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 { 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 { 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); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java index 5bc337c2..0b96ed53 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java @@ -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 Optional get(@Nullable SpellPredicate type, boolean update) { return delegate().get(type, update); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java index 9c0be101..c0ae2284 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java @@ -14,6 +14,6 @@ public interface SpellPredicate extends Predicate { SpellPredicate IS_DISGUISE = s -> s instanceof AbstractDisguiseSpell; default boolean isOn(Caster caster) { - return caster.getSpellSlot().get(this, false).isPresent(); + return caster.getSpellSlot().contains(this); } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 637c6111..197d2e0e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -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 implements Transmittable, Copieab @Override public boolean isInvisible() { - return invisible && getSpellSlot().isPresent(); + return invisible && SpellPredicate.IS_DISGUISE.isOn(this); } public boolean isSpeciesPersisted() { diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java index 1f8d1138..e3f38291 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java @@ -46,14 +46,14 @@ public class EffectSync implements SpellContainer { } @Override - @SuppressWarnings("unchecked") - public Optional get(@Nullable SpellPredicate type, boolean update) { - return (Optional)(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 Optional get(@Nullable SpellPredicate type, boolean update) { + return (Optional)(read(type, update, true).findFirst()); } @Override @@ -99,12 +99,15 @@ public class EffectSync implements SpellContainer { } } - private Stream read(boolean synchronize, boolean sendUpdate) { + private Stream 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()); } - return spells.getReferences(); + if (type == null) { + return spells.getReferences(); + } + return spells.getReferences().filter(type); } public boolean reduce(Alteration alteration) {