From 02a038a7f7ec238032e64ec076e94f6e992d57b7 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 30 May 2025 09:43:46 +0300 Subject: [PATCH] fixed potential loss of resources in hotbar if armor will break, damaging an item will be registred in expected slots --- src/entity/Entity.php | 2 +- src/material/Item.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 9fa7297f..43a6183c 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1566,7 +1566,7 @@ class Entity extends Position if($v2 < 1) $v2 = 1; foreach($this->player->armor as $slot => $part){ - $part->hurtAndBreak($v2, $this->player); + $part->hurtAndBreak($v2, $this->player, helditem: false); } $this->player->sendArmor(); } diff --git a/src/material/Item.php b/src/material/Item.php index fa194dde..f67a52be 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -223,14 +223,19 @@ class Item{ /** * @param int $dmg - damage dealt to item * @param Player $player - player who used the item + * @param boolean $helditem - modify player's helditem state or not - should be false if using by non-held item(armor damaging for example) */ - public function hurtAndBreak($dmg, Player $player){ + public function hurtAndBreak($dmg, Player $player, $helditem = true){ if(($player->gamemode & 1) !== 0) return; //dont break items in creative if($this->getMaxDurability() !== false){ $this->meta += $dmg; - if($this->meta > $this->getMaxDurability()){ - $player->consumeSingleItem(); + + if($helditem){ + $player->setSlot($player->slot, $this, send: false); + if($this->meta > $this->getMaxDurability()){ + $player->consumeSingleItem(); + } } } }