Living: avoid updates of non-armor slots and armor slots which took no damage

this was also updating empty slots ...
This commit is contained in:
Dylan K. Taylor 2023-07-18 13:04:11 +01:00
parent 0051b34797
commit c053742f5d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -484,14 +484,16 @@ abstract class Living extends Entity{
public function damageArmor(float $damage) : void{
$durabilityRemoved = (int) max(floor($damage / 4), 1);
$armor = $this->armorInventory->getContents(true);
foreach($armor as $item){
$armor = $this->armorInventory->getContents();
foreach($armor as $slotId => $item){
if($item instanceof Armor){
$oldItem = clone $item;
$this->damageItem($item, $durabilityRemoved);
if(!$item->equalsExact($oldItem)){
$this->armorInventory->setItem($slotId, $item);
}
}
}
$this->armorInventory->setContents($armor);
}
private function damageItem(Durable $item, int $durabilityRemoved) : void{