diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 484a98ed8..2c8624d72 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -275,6 +275,9 @@ class BlockAPI{ return $this->cancelAction($target, $player, false); } $item->useOn($target); + if($item->getMetadata() >= $item->getMaxDurability()){ + $player->setSlot($player->slot, new Item(AIR, 0, 0), false); + } $drops = $target->getDrops($item, $player); }else{ return $this->cancelAction($target, $player, false); diff --git a/src/Player.php b/src/Player.php index 32191cd22..173591f29 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1473,6 +1473,9 @@ class Player{ $target->harm($damage, $this->eid); if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){ $slot->useOn($target); + if($slot->getMetadata() >= $slot->getMaxDurability()){ + $this->setSlot($this->slot, new Item(AIR, 0, 0), false); + } } } } diff --git a/src/material/Item.php b/src/material/Item.php index f6d0a8729..a33502173 100644 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -135,14 +135,48 @@ class Item{ } - public function useOn($object){ - if($this->isTool()){ - $this->meta++; + public function useOn($object, $force = false){ + if($this->isTool() or $force === true){ + if(($object instanceof Entity) and !$this->isSword()){ + $this->meta += 2; + }else{ + $this->meta++; + } } } final public function isTool(){ - return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false or $this->isHoe() !== false); + return ($this->id === FLINT_STEEL or $this->id === SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false); + } + + final public function getMaxDurability(){ + if(!$this->isTool() and $this->isHoe() === false and $this->id !== BOW){ + return false; + } + + $levels = array( + 2 => 33, + 1 => 60, + 3 => 132, + 4 => 251, + 5 => 1562, + FLINT_STEEL => 65, + SHEARS => 239, + BOW => 385, + ); + + if(($type = $this->isPickaxe()) === false){ + if(($type = $this->isAxe()) === false){ + if(($type = $this->isSword()) === false){ + if(($type = $this->isShovel()) === false){ + if(($type = $this->isHoe()) === false){ + $type = $this->id; + } + } + } + } + } + return $levels[$type]; } final public function isPickaxe(){ //Returns false or level of the pickaxe diff --git a/src/material/item/tool/FlintSteel.php b/src/material/item/tool/FlintSteel.php index 58b5c2e8b..431500f85 100644 --- a/src/material/item/tool/FlintSteel.php +++ b/src/material/item/tool/FlintSteel.php @@ -39,6 +39,9 @@ class FlintSteelItem extends Item{ return true; } $this->useOn($block); + if($this->getMetadata() >= $this->getMaxDurability()){ + $player->setSlot($player->slot, new Item(AIR, 0, 0), false); + } return false; } } \ No newline at end of file