diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java index 9e45a4a5..8262f789 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; +import java.util.List; + import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Situation; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; @@ -70,10 +72,13 @@ public class IceSpell extends AbstractSpell { } protected boolean applyEntities(Caster source, Vec3d pos) { - return !VecHelper.findInRange(source.asEntity(), source.asWorld(), pos, 3, i -> applyEntitySingle(source, i)).isEmpty(); + List entities = VecHelper.findInRange(source.asEntity(), source.asWorld(), pos, 3); + entities.forEach(entity -> applyEntitySingle(source, entity)); + return !entities.isEmpty(); + } - protected boolean applyEntitySingle(Caster source, Entity e) { + protected void applyEntitySingle(Caster source, Entity e) { if (e instanceof TntEntity) { e.remove(RemovalReason.DISCARDED); e.getEntityWorld().setBlockState(e.getBlockPos(), Blocks.TNT.getDefaultState()); @@ -82,8 +87,6 @@ public class IceSpell extends AbstractSpell { } else { e.damage(MagicalDamageSource.create("cold", source.getMaster()), 2); } - - return true; } private boolean applyBlockSingle(Entity owner, World world, BlockPos pos, Situation situation) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java index a8607ee4..1e2b46ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; import java.util.List; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -20,6 +21,7 @@ import com.minelittlepony.unicopia.util.MagicalDamageSource; import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.shape.Sphere; +import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; @@ -33,6 +35,7 @@ import net.minecraft.util.math.Vec3d; * A spell that pulls health from other entities and delivers it to the caster. */ public class SiphoningSpell extends AbstractAreaEffectSpell { + static final Predicate TARGET_PREDICATE = EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(EntityPredicates.VALID_LIVING_ENTITY); private int ticksUpset; @@ -80,9 +83,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { } private Stream getTargets(Caster source) { - return VecHelper.findInRange(null, source.asWorld(), source.getOriginVector(), 4 + source.getLevel().getScaled(6), EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(e -> e instanceof LivingEntity)) - .stream() - .map(e -> (LivingEntity)e); + return VecHelper.findInRange(null, source.asWorld(), source.getOriginVector(), 4 + source.getLevel().getScaled(6), TARGET_PREDICATE).stream().map(e -> (LivingEntity)e); } private void distributeHealth(Caster source) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java index a7688b1b..7139b7bb 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.item; import java.util.*; +import java.util.function.Predicate; import java.util.function.Supplier; import com.google.common.base.Suppliers; @@ -31,6 +32,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Artifact { + static final Predicate TARGET_PREDICATE = EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(EntityPredicates.VALID_ENTITY).and(e -> (e instanceof PlayerEntity || e instanceof MobEntity)); private static final Supplier> ITEM_MAP = Suppliers.memoize(() -> { return Map.of( Items.BUCKET, UItems.LOVE_BUCKET, @@ -115,7 +117,7 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art List outputs = new ArrayList<>(); List containers = new ArrayList<>(); - VecHelper.findInRange(entity, entity.world, entity.getPos(), 20, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(e -> !e.isRemoved() && (e instanceof PlayerEntity || e instanceof MobEntity))).forEach(e -> { + VecHelper.findInRange(entity, entity.world, entity.getPos(), 20, TARGET_PREDICATE).forEach(e -> { LivingEntity living = (LivingEntity)e; if (e instanceof PlayerEntity diff --git a/src/main/java/com/minelittlepony/unicopia/util/VecHelper.java b/src/main/java/com/minelittlepony/unicopia/util/VecHelper.java index f6c3e4a2..864cd416 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/VecHelper.java +++ b/src/main/java/com/minelittlepony/unicopia/util/VecHelper.java @@ -32,4 +32,9 @@ public interface VecHelper { double diameter = radius * 2; return w.getOtherEntities(origin, Box.of(pos, diameter, diameter, diameter), predicate == null ? inRange(pos, radius) : inRange(pos, radius).and(predicate)); } + + static List findInRange(@Nullable Entity origin, EntityView w, Vec3d pos, double radius) { + double diameter = radius * 2; + return w.getOtherEntities(origin, Box.of(pos, diameter, diameter, diameter), inRange(pos, radius)); + } }