mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-08-20 09:57:09 +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.ai.control.h"
|
||||||
#include "net.minecraft.world.entity.h"
|
#include "net.minecraft.world.entity.h"
|
||||||
#include "LeapAtTargetGoal.h"
|
#include "LeapAtTargetGoal.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd)
|
LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd)
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +26,16 @@ bool LeapAtTargetGoal::canUse()
|
||||||
|
|
||||||
bool LeapAtTargetGoal::canContinueToUse()
|
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()
|
void LeapAtTargetGoal::start()
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,14 @@ void PathfinderMob::serverAiStep()
|
||||||
{
|
{
|
||||||
if (attackTarget->isAlive())
|
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());
|
float d = attackTarget->distanceTo(shared_from_this());
|
||||||
if (canSee(attackTarget))
|
if (canSee(attackTarget))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ bool TargetGoal::canContinueToUse()
|
||||||
if (target == nullptr) return false;
|
if (target == nullptr) return false;
|
||||||
if (!target->isAlive()) 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();
|
double within = getFollowDistance();
|
||||||
if (mob->distanceToSqr(target) > within * within) return false;
|
if (mob->distanceToSqr(target) > within * within) return false;
|
||||||
if (mustSee)
|
if (mustSee)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue