fixed potential loss of resources in hotbar if armor will break, damaging an item will be registred in expected slots

This commit is contained in:
GameHerobrine 2025-05-30 09:43:46 +03:00
parent b272c1ec6a
commit 02a038a7f7
2 changed files with 9 additions and 4 deletions

View file

@ -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();
}

View file

@ -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();
}
}
}
}