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 <puffymono@gmail.com> Co-committed-by: ACL <puffymono@gmail.com>
This commit is contained in:
@@ -690,6 +690,7 @@ void PlayerConnection::handleUseItem(shared_ptr<UseItemPacket> packet)
|
||||
ServerLevel *level = server->getLevel(player->dimension);
|
||||
shared_ptr<ItemInstance> 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<UseItemPacket> 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)) {
|
||||
|
||||
Reference in New Issue
Block a user