Implemented basic tool durability

This commit is contained in:
Shoghi Cervantes 2013-08-19 17:37:08 +02:00
parent a7b739d17f
commit 68e78ba40b
4 changed files with 47 additions and 4 deletions

View File

@ -275,6 +275,9 @@ class BlockAPI{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
$item->useOn($target); $item->useOn($target);
if($item->getMetadata() >= $item->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
}
$drops = $target->getDrops($item, $player); $drops = $target->getDrops($item, $player);
}else{ }else{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);

View File

@ -1473,6 +1473,9 @@ class Player{
$target->harm($damage, $this->eid); $target->harm($damage, $this->eid);
if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){ if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){
$slot->useOn($target); $slot->useOn($target);
if($slot->getMetadata() >= $slot->getMaxDurability()){
$this->setSlot($this->slot, new Item(AIR, 0, 0), false);
}
} }
} }
} }

View File

@ -135,14 +135,48 @@ class Item{
} }
public function useOn($object){ public function useOn($object, $force = false){
if($this->isTool()){ if($this->isTool() or $force === true){
$this->meta++; if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
}else{
$this->meta++;
}
} }
} }
final public function isTool(){ 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 final public function isPickaxe(){ //Returns false or level of the pickaxe

View File

@ -39,6 +39,9 @@ class FlintSteelItem extends Item{
return true; return true;
} }
$this->useOn($block); $this->useOn($block);
if($this->getMetadata() >= $this->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
}
return false; return false;
} }
} }