mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 13:09:44 +00:00
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:
parent
b272c1ec6a
commit
02a038a7f7
2 changed files with 9 additions and 4 deletions
|
|
@ -1566,7 +1566,7 @@ class Entity extends Position
|
||||||
if($v2 < 1) $v2 = 1;
|
if($v2 < 1) $v2 = 1;
|
||||||
|
|
||||||
foreach($this->player->armor as $slot => $part){
|
foreach($this->player->armor as $slot => $part){
|
||||||
$part->hurtAndBreak($v2, $this->player);
|
$part->hurtAndBreak($v2, $this->player, helditem: false);
|
||||||
}
|
}
|
||||||
$this->player->sendArmor();
|
$this->player->sendArmor();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -223,14 +223,19 @@ class Item{
|
||||||
/**
|
/**
|
||||||
* @param int $dmg - damage dealt to item
|
* @param int $dmg - damage dealt to item
|
||||||
* @param Player $player - player who used the 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(($player->gamemode & 1) !== 0) return; //dont break items in creative
|
||||||
|
|
||||||
if($this->getMaxDurability() !== false){
|
if($this->getMaxDurability() !== false){
|
||||||
$this->meta += $dmg;
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue