From b467aae7b288ec822ab95539bf7cf4e578e898cd Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 7 Feb 2024 13:02:20 +0000 Subject: [PATCH] Fixed bulb attacking players in creative and spectator mode --- .../entity/mob/IgnominiousBulbEntity.java | 9 +++++-- .../unicopia/entity/mob/TentacleEntity.java | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java index 224a2b0f..82e99bf7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java @@ -181,6 +181,10 @@ public class IgnominiousBulbEntity extends MobEntity { } } LivingEntity target = getAttacker(); + if (!canTarget(target)) { + target = null; + setAttacker(null); + } if (angryTicks > 0) { angryTicks--; @@ -194,13 +198,14 @@ public class IgnominiousBulbEntity extends MobEntity { Pony.of(player).getMagicalReserves().getEnergy().add(6); } + final LivingEntity t = target; tentacles.values() .stream() .flatMap(tentacle -> tentacle.getOrEmpty(getWorld()).stream()) - .sorted(Comparator.comparing(a -> a.distanceTo(target))) + .sorted(Comparator.comparing(a -> a.distanceTo(t))) .limit(2) .forEach(tentacle -> { - tentacle.setTarget(target); + tentacle.setTarget(t); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java index 9e056950..0273b4fb 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java @@ -171,17 +171,21 @@ public class TentacleEntity extends AbstractDecorationEntity { if (isAttacking()) { if (--attackingTicks == 12) { if (target != null) { - target.damage(getDamageSources().create(DamageTypes.MOB_ATTACK, this), 15); - Vec3d diff = target.getPos().subtract(getPos()); - target.takeKnockback(1, diff.x, diff.z); + if (!canTarget(target)) { + target = null; + } else { + target.damage(getDamageSources().create(DamageTypes.MOB_ATTACK, this), 15); + Vec3d diff = target.getPos().subtract(getPos()); + target.takeKnockback(1, diff.x, diff.z); - ParticleUtils.spawnParticles(ParticleTypes.CLOUD, target, 10); + ParticleUtils.spawnParticles(ParticleTypes.CLOUD, target, 10); - for (Entity bystander : getWorld().getOtherEntities(target, target.getBoundingBox().expand(3))) { - if (bystander instanceof LivingEntity l) { - diff = l.getPos().subtract(getPos()); - l.takeKnockback(1, diff.x, diff.z); - ParticleUtils.spawnParticles(ParticleTypes.CLOUD, target, 10); + for (Entity bystander : getWorld().getOtherEntities(target, target.getBoundingBox().expand(3))) { + if (bystander instanceof LivingEntity l) { + diff = l.getPos().subtract(getPos()); + l.takeKnockback(1, diff.x, diff.z); + ParticleUtils.spawnParticles(ParticleTypes.CLOUD, target, 10); + } } } @@ -258,9 +262,9 @@ public class TentacleEntity extends AbstractDecorationEntity { protected boolean canTarget(LivingEntity target) { return target != null - && !target.isRemoved() + && target.isPartOfGame() + && target.canTakeDamage() && !target.isSneaky() - && !(target instanceof PlayerEntity player && (player.isCreative() || player.isSpectator())) && canSee(target); }