Fixed bulb attacking players in creative and spectator mode

This commit is contained in:
Sollace 2024-02-07 13:02:20 +00:00
parent 7b78cbc49c
commit b467aae7b2
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 22 additions and 13 deletions

View file

@ -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);
});
}

View file

@ -171,6 +171,9 @@ public class TentacleEntity extends AbstractDecorationEntity {
if (isAttacking()) {
if (--attackingTicks == 12) {
if (target != null) {
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);
@ -184,6 +187,7 @@ public class TentacleEntity extends AbstractDecorationEntity {
ParticleUtils.spawnParticles(ParticleTypes.CLOUD, target, 10);
}
}
}
target = null;
}
@ -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);
}