mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-08 22:12:56 +00:00
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:
parent
7ee7588364
commit
eabde3527c
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -63,6 +63,14 @@ void PathfinderMob::serverAiStep()
|
|||
{
|
||||
if (attackTarget->isAlive())
|
||||
{
|
||||
if (attackTarget->instanceof(eTYPE_PLAYER)) {
|
||||
shared_ptr<Player> player = dynamic_pointer_cast<Player>(attackTarget);
|
||||
if (player->abilities.invulnerable)
|
||||
{
|
||||
attackTarget = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
float d = attackTarget->distanceTo(shared_from_this());
|
||||
if (canSee(attackTarget))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ bool TargetGoal::canContinueToUse()
|
|||
if (target == nullptr) return false;
|
||||
if (!target->isAlive()) return false;
|
||||
|
||||
if (target->instanceof(eTYPE_PLAYER)) {
|
||||
shared_ptr<Player> player = dynamic_pointer_cast<Player>(target);
|
||||
if (player->abilities.invulnerable) return false;
|
||||
}
|
||||
|
||||
double within = getFollowDistance();
|
||||
if (mob->distanceToSqr(target) > within * within) return false;
|
||||
if (mustSee)
|
||||
|
|
|
|||
Loading…
Reference in a new issue