From 5348e12aca9526557d4ce6d32218a37958976135 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 3 Mar 2024 14:15:20 +0000 Subject: [PATCH] Fix #290 and exclude spectators from being affected by magic --- .../java/com/minelittlepony/unicopia/EquinePredicates.java | 6 ++++-- .../unicopia/ability/magic/spell/effect/TargetSelecter.java | 2 -- .../unicopia/projectile/MagicProjectileEntity.java | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java index de83f274..6286b123 100644 --- a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java +++ b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java @@ -35,11 +35,13 @@ public interface EquinePredicates { Predicate IS_CASTER = e -> !e.isRemoved() && (e instanceof Caster || IS_PLAYER.test(e)); Predicate IS_PLACED_SPELL = e -> e instanceof Caster && !e.isRemoved(); - Predicate IS_MAGIC_IMMUNE = e -> (e instanceof MagicImmune || !(e instanceof LivingEntity)) + Predicate IS_MAGIC_IMMUNE = EntityPredicates.VALID_ENTITY.negate() + .or(EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.negate() + .or(e -> (e instanceof MagicImmune || !(e instanceof LivingEntity)) && !(e instanceof ItemEntity) && !(e instanceof ExperienceOrbEntity) && !(e instanceof BoatEntity) - && !(e instanceof ProjectileEntity); + && !(e instanceof ProjectileEntity))); Predicate EXCEPT_MAGIC_IMMUNE = IS_MAGIC_IMMUNE.negate(); Predicate VALID_LIVING_AND_NOT_MAGIC_IMMUNE = EntityPredicates.VALID_LIVING_ENTITY.and(EXCEPT_MAGIC_IMMUNE); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TargetSelecter.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TargetSelecter.java index a6a3724c..c00d360b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TargetSelecter.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TargetSelecter.java @@ -12,7 +12,6 @@ import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Spell; import net.minecraft.entity.Entity; -import net.minecraft.predicate.entity.EntityPredicates; public class TargetSelecter { private final Map targets = new TreeMap<>(); @@ -46,7 +45,6 @@ public class TargetSelecter { public Stream getEntities(Caster source, double radius) { targets.values().removeIf(Target::tick); return source.findAllEntitiesInRange(radius) - .filter(EntityPredicates.VALID_ENTITY) .filter(EquinePredicates.EXCEPT_MAGIC_IMMUNE) .filter(entity -> entity != source.asEntity() && checkAlliegance(spell, source, entity) && filter.test(source, entity)) .map(i -> { diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index 23c7f67d..3b8064ae 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -27,7 +27,6 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.particle.ItemStackParticleEffect; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleTypes; -import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; @@ -208,7 +207,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements WeaklyOwn protected void onEntityHit(EntityHitResult hit) { Entity entity = hit.getEntity(); - if (EquinePredicates.IS_MAGIC_IMMUNE.test(entity) || !EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity)) { + if (EquinePredicates.IS_MAGIC_IMMUNE.test(entity)) { return; }