Fixed durability handling (ish)

This commit is contained in:
Dylan K. Taylor
2022-06-29 15:17:16 +01:00
parent dd63681f94
commit 2cb722b674
3 changed files with 20 additions and 28 deletions

View File

@@ -32,10 +32,6 @@ abstract class Durable extends Item{
protected int $damage = 0;
private bool $unbreakable = false;
public function getMeta() : int{
return $this->damage;
}
/**
* Returns whether this item will take damage when used.
*/
@@ -124,10 +120,17 @@ abstract class Durable extends Item{
protected function deserializeCompoundTag(CompoundTag $tag) : void{
parent::deserializeCompoundTag($tag);
$this->unbreakable = $tag->getByte("Unbreakable", 0) !== 0;
$damage = $tag->getInt("Damage", $this->damage);
if($damage !== $this->damage && $damage >= 0 && $damage <= $this->getMaxDurability()){
//TODO: out-of-bounds damage should be an error
$this->setDamage($damage);
}
}
protected function serializeCompoundTag(CompoundTag $tag) : void{
parent::serializeCompoundTag($tag);
$this->unbreakable ? $tag->setByte("Unbreakable", 1) : $tag->removeTag("Unbreakable");
$tag->setInt("Damage", $this->damage);
}
}