mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Implemented basic tool durability
This commit is contained in:
parent
a7b739d17f
commit
68e78ba40b
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,14 +135,48 @@ class Item{
|
||||
|
||||
}
|
||||
|
||||
public function useOn($object){
|
||||
if($this->isTool()){
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user