mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Fixed durability handling (ish)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user