From c85b2a8740d610cd1f1b1de456f830cb2036d290 Mon Sep 17 00:00:00 2001 From: ACL Date: Sat, 8 Aug 2026 16:58:45 +0100 Subject: [PATCH] fix: Armor swapping executed even when interacting with a block (#168) (This PR fixes [this issue](https://discord.com/channels/1482443865754701868/1534141325904183336) from the Discord server: ) Previously, when holding a piece of armor and right-clicking an interactable block (furnance, crafting table, levers, etc.) the armor would be equipped to the player. This isn't the expected behavior. The interacted block should suppress any held item functionality (if not crouched) This PR adds the "bool blockHandled" variable to the "handleUseItem" function. If the player interact with an interactable block, the variable is set to true. This variable can be used for future packets added in this function Reviewed-on: https://git.neolegacy.dev/neoStudiosLCE/neoLegacy/pulls/168 Co-authored-by: ACL Co-committed-by: ACL --- Minecraft.Client/PlayerConnection.cpp | 7 ++++--- Minecraft.Client/ServerPlayerGameMode.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Minecraft.Client/PlayerConnection.cpp b/Minecraft.Client/PlayerConnection.cpp index e4dc4144..6e8c9605 100644 --- a/Minecraft.Client/PlayerConnection.cpp +++ b/Minecraft.Client/PlayerConnection.cpp @@ -690,6 +690,7 @@ void PlayerConnection::handleUseItem(shared_ptr packet) ServerLevel *level = server->getLevel(player->dimension); shared_ptr item = player->inventory->getSelected(); bool informClient = false; + bool blockHandled = false; int x = packet->getX(); int y = packet->getY(); int z = packet->getZ(); @@ -776,8 +777,7 @@ void PlayerConnection::handleUseItem(shared_ptr packet) int savedItemId = item ? item->id : 0; int savedItemCount = item ? item->count : 0; #endif - - player->gameMode->useItemOn(player, level, item, x, y, z, face, packet->getClickX(), packet->getClickY(), packet->getClickZ()); + player->gameMode->useItemOn(player, level, item, x, y, z, face, packet->getClickX(), packet->getClickY(), packet->getClickZ(), false, &blockHandled); #if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD) if (validFace) @@ -897,7 +897,8 @@ skipUseItemOn: } //Migrate QuickEquip packet here instead - if (item != nullptr && (item->getItem()->getBaseItemType() == Item::eBaseItemType_helmet + if (item != nullptr && !blockHandled + && (item->getItem()->getBaseItemType() == Item::eBaseItemType_helmet || item->getItem()->getBaseItemType() == Item::eBaseItemType_chestplate || item->getItem()->getBaseItemType() == Item::eBaseItemType_leggings || item->getItem()->getBaseItemType() == Item::eBaseItemType_boots)) { diff --git a/Minecraft.Client/ServerPlayerGameMode.cpp b/Minecraft.Client/ServerPlayerGameMode.cpp index 28a2a836..d8c39a26 100644 --- a/Minecraft.Client/ServerPlayerGameMode.cpp +++ b/Minecraft.Client/ServerPlayerGameMode.cpp @@ -421,6 +421,7 @@ bool ServerPlayerGameMode::useItemOn(shared_ptr player, Level *level, sh if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX, clickY, clickZ)) { if(m_gameRules != nullptr) m_gameRules->onUseTile(t,x,y,z); + *pbUsedItem = true; return true; } }