From 909c8fd04fa86a10d1b31c53daaba2f53e9798ec Mon Sep 17 00:00:00 2001 From: Jacob M Date: Wed, 11 Mar 2026 12:10:02 -0400 Subject: [PATCH 1/3] fixed zombie pigmen attacking player in creative mode --- Minecraft.World/PigZombie.cpp | 2 +- Minecraft.World/Player.cpp | 5 +++++ Minecraft.World/Player.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Minecraft.World/PigZombie.cpp b/Minecraft.World/PigZombie.cpp index 1be123d7a..84daf7363 100644 --- a/Minecraft.World/PigZombie.cpp +++ b/Minecraft.World/PigZombie.cpp @@ -105,7 +105,7 @@ shared_ptr PigZombie::findAttackTarget() bool PigZombie::hurt(DamageSource *source, float dmg) { shared_ptr sourceEntity = source->getEntity(); - if ( sourceEntity != nullptr && sourceEntity->instanceof(eTYPE_PLAYER) ) + if ( sourceEntity != nullptr && sourceEntity->instanceof(eTYPE_PLAYER) && sourceEntity->isAttackable()) { vector > *nearby = level->getEntities( shared_from_this(), bb->grow(32, 32, 32)); for (auto& e : *nearby) diff --git a/Minecraft.World/Player.cpp b/Minecraft.World/Player.cpp index 00c7148e4..25ad8e422 100644 --- a/Minecraft.World/Player.cpp +++ b/Minecraft.World/Player.cpp @@ -195,6 +195,11 @@ bool Player::isUsingItem() return useItem != nullptr; } +bool Player::isAttackable() +{ + return !abilities.invulnerable; +} + int Player::getTicksUsingItem() { if (isUsingItem()) diff --git a/Minecraft.World/Player.h b/Minecraft.World/Player.h index 2e223a1e5..c3139ee4b 100644 --- a/Minecraft.World/Player.h +++ b/Minecraft.World/Player.h @@ -495,6 +495,8 @@ class Player : public LivingEntity, public CommandSender, public ScoreHolder void setPlayerGamePrivilege(EPlayerGamePrivileges privilege, unsigned int value); static void setPlayerGamePrivilege(unsigned int &uiGamePrivileges, EPlayerGamePrivileges privilege, unsigned int value); + virtual bool isAttackable(); + bool isAllowedToUse(Tile *tile); bool isAllowedToUse(shared_ptr item); bool isAllowedToInteract(shared_ptr target); From 4e3fec0d9707ee0fc01fa099d8532abefa859293 Mon Sep 17 00:00:00 2001 From: Jacob M Date: Wed, 11 Mar 2026 17:17:45 -0400 Subject: [PATCH 2/3] swapped isAttackable function for isInvulnerable function in Player class; Also added isInvulnerable check to wolf agro function --- Minecraft.World/PigZombie.cpp | 2 +- Minecraft.World/Player.cpp | 4 ++-- Minecraft.World/Player.h | 2 +- Minecraft.World/Wolf.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Minecraft.World/PigZombie.cpp b/Minecraft.World/PigZombie.cpp index 84daf7363..c0780861d 100644 --- a/Minecraft.World/PigZombie.cpp +++ b/Minecraft.World/PigZombie.cpp @@ -105,7 +105,7 @@ shared_ptr PigZombie::findAttackTarget() bool PigZombie::hurt(DamageSource *source, float dmg) { shared_ptr sourceEntity = source->getEntity(); - if ( sourceEntity != nullptr && sourceEntity->instanceof(eTYPE_PLAYER) && sourceEntity->isAttackable()) + if ( sourceEntity != nullptr && sourceEntity->instanceof(eTYPE_PLAYER) && !sourceEntity->isInvulnerable()) { vector > *nearby = level->getEntities( shared_from_this(), bb->grow(32, 32, 32)); for (auto& e : *nearby) diff --git a/Minecraft.World/Player.cpp b/Minecraft.World/Player.cpp index 25ad8e422..9e5e08dee 100644 --- a/Minecraft.World/Player.cpp +++ b/Minecraft.World/Player.cpp @@ -195,9 +195,9 @@ bool Player::isUsingItem() return useItem != nullptr; } -bool Player::isAttackable() +bool Player::isInvulnerable() { - return !abilities.invulnerable; + return abilities.invulnerable || hasInvulnerablePrivilege(); } int Player::getTicksUsingItem() diff --git a/Minecraft.World/Player.h b/Minecraft.World/Player.h index c3139ee4b..b1a27d270 100644 --- a/Minecraft.World/Player.h +++ b/Minecraft.World/Player.h @@ -495,7 +495,7 @@ class Player : public LivingEntity, public CommandSender, public ScoreHolder void setPlayerGamePrivilege(EPlayerGamePrivileges privilege, unsigned int value); static void setPlayerGamePrivilege(unsigned int &uiGamePrivileges, EPlayerGamePrivileges privilege, unsigned int value); - virtual bool isAttackable(); + virtual bool isInvulnerable(); bool isAllowedToUse(Tile *tile); bool isAllowedToUse(shared_ptr item); diff --git a/Minecraft.World/Wolf.cpp b/Minecraft.World/Wolf.cpp index 7588a67b0..e16ff217d 100644 --- a/Minecraft.World/Wolf.cpp +++ b/Minecraft.World/Wolf.cpp @@ -286,7 +286,7 @@ bool Wolf::hurt(DamageSource *source, float dmg) if (isTame()) { shared_ptr entity = source->getDirectEntity(); - if (entity != nullptr && entity->instanceof(eTYPE_PLAYER)) + if (entity != nullptr && entity->instanceof(eTYPE_PLAYER) && !entity->isInvulnerable()) { shared_ptr attacker = dynamic_pointer_cast(entity); attacker->canHarmPlayer(getOwnerUUID()); From cc910b9b7b4b322e9688489894a6a16bcd4d1ce6 Mon Sep 17 00:00:00 2001 From: Jacob M Date: Wed, 11 Mar 2026 17:29:03 -0400 Subject: [PATCH 3/3] removed redundant wolf agro fix --- Minecraft.World/Wolf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Minecraft.World/Wolf.cpp b/Minecraft.World/Wolf.cpp index e16ff217d..7588a67b0 100644 --- a/Minecraft.World/Wolf.cpp +++ b/Minecraft.World/Wolf.cpp @@ -286,7 +286,7 @@ bool Wolf::hurt(DamageSource *source, float dmg) if (isTame()) { shared_ptr entity = source->getDirectEntity(); - if (entity != nullptr && entity->instanceof(eTYPE_PLAYER) && !entity->isInvulnerable()) + if (entity != nullptr && entity->instanceof(eTYPE_PLAYER)) { shared_ptr attacker = dynamic_pointer_cast(entity); attacker->canHarmPlayer(getOwnerUUID());