fix: Prevent mobs from targeting players in creative mode

Mobs were incorrectly targeting and attacking players who are in
creative mode (invulnerable).
This commit is contained in:
George V.
2026-04-18 20:29:47 +03:00
parent 7ee7588364
commit eabde3527c
3 changed files with 24 additions and 1 deletions
+11 -1
View File
@@ -2,6 +2,7 @@
#include "net.minecraft.world.entity.ai.control.h"
#include "net.minecraft.world.entity.h"
#include "LeapAtTargetGoal.h"
#include "Player.h"
LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd)
{
@@ -25,7 +26,16 @@ bool LeapAtTargetGoal::canUse()
bool LeapAtTargetGoal::canContinueToUse()
{
return target.lock() != nullptr && !mob->onGround;
shared_ptr<LivingEntity> mobTarget = target.lock();
if (mobTarget == nullptr) return false;
if (!mobTarget->isAlive()) return false;
if (mobTarget->instanceof(eTYPE_PLAYER)) {
shared_ptr<Player> player = dynamic_pointer_cast<Player>(mobTarget);
if (player->abilities.invulnerable) return false;
}
return !mob->onGround;
}
void LeapAtTargetGoal::start()