Durable: Allow subclasses to override behaviour when the item breaks

This commit is contained in:
Dylan K. Taylor 2018-01-18 14:37:22 +00:00
parent c7f15a556d
commit 9551e5b8e5

View File

@ -59,7 +59,7 @@ abstract class Durable extends Item{
$this->meta = min($this->meta + $amount, $this->getMaxDurability());
if($this->isBroken()){
$this->pop();
$this->onBroken();
}
return true;
@ -82,6 +82,12 @@ abstract class Durable extends Item{
return 0;
}
/**
* Called when the item's damage exceeds its maximum durability.
*/
protected function onBroken() : void{
$this->pop();
}
/**
* Returns the maximum amount of damage this item can take before it breaks.