From eabde3527ce8629ffb9f2edd8fca6b89c7d57294 Mon Sep 17 00:00:00 2001 From: "George V." Date: Sat, 18 Apr 2026 20:29:47 +0300 Subject: [PATCH] fix: Prevent mobs from targeting players in creative mode Mobs were incorrectly targeting and attacking players who are in creative mode (invulnerable). --- Minecraft.World/LeapAtTargetGoal.cpp | 12 +++++++++++- Minecraft.World/PathfinderMob.cpp | 8 ++++++++ Minecraft.World/TargetGoal.cpp | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Minecraft.World/LeapAtTargetGoal.cpp b/Minecraft.World/LeapAtTargetGoal.cpp index b559ef7d..c8bdb95d 100644 --- a/Minecraft.World/LeapAtTargetGoal.cpp +++ b/Minecraft.World/LeapAtTargetGoal.cpp @@ -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 mobTarget = target.lock(); + if (mobTarget == nullptr) return false; + if (!mobTarget->isAlive()) return false; + + if (mobTarget->instanceof(eTYPE_PLAYER)) { + shared_ptr player = dynamic_pointer_cast(mobTarget); + if (player->abilities.invulnerable) return false; + } + + return !mob->onGround; } void LeapAtTargetGoal::start() diff --git a/Minecraft.World/PathfinderMob.cpp b/Minecraft.World/PathfinderMob.cpp index 840a6020..1d620b53 100644 --- a/Minecraft.World/PathfinderMob.cpp +++ b/Minecraft.World/PathfinderMob.cpp @@ -63,6 +63,14 @@ void PathfinderMob::serverAiStep() { if (attackTarget->isAlive()) { + if (attackTarget->instanceof(eTYPE_PLAYER)) { + shared_ptr player = dynamic_pointer_cast(attackTarget); + if (player->abilities.invulnerable) + { + attackTarget = nullptr; + return; + } + } float d = attackTarget->distanceTo(shared_from_this()); if (canSee(attackTarget)) { diff --git a/Minecraft.World/TargetGoal.cpp b/Minecraft.World/TargetGoal.cpp index 0c2b9363..7e8703b8 100644 --- a/Minecraft.World/TargetGoal.cpp +++ b/Minecraft.World/TargetGoal.cpp @@ -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 = dynamic_pointer_cast(target); + if (player->abilities.invulnerable) return false; + } + double within = getFollowDistance(); if (mob->distanceToSqr(target) > within * within) return false; if (mustSee)