PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Tool.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 
23 namespace pocketmine\item;
24 
27 
28 abstract class Tool extends Item{
29  const TIER_WOODEN = 1;
30  const TIER_GOLD = 2;
31  const TIER_STONE = 3;
32  const TIER_IRON = 4;
33  const TIER_DIAMOND = 5;
34 
35  public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
36  parent::__construct($id, $meta, $count, $name);
37  }
38 
39  public function getMaxStackSize(){
40  return 1;
41  }
42 
50  public function useOn($object){
51  if($this->isHoe()){
52  if(($object instanceof Block) and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)){
53  $this->meta++;
54  }
55  }elseif(($object instanceof Entity) and !$this->isSword()){
56  $this->meta += 2;
57  }else{
58  $this->meta++;
59  }
60 
61  return true;
62  }
63 
69  public function getMaxDurability(){
70 
71  $levels = [
72  2 => 33,
73  1 => 60,
74  3 => 132,
75  4 => 251,
76  5 => 1562,
77  self::FLINT_STEEL => 65,
78  self::SHEARS => 239,
79  self::BOW => 385,
80  ];
81 
82  if(($type = $this->isPickaxe()) === false){
83  if(($type = $this->isAxe()) === false){
84  if(($type = $this->isSword()) === false){
85  if(($type = $this->isShovel()) === false){
86  if(($type = $this->isHoe()) === false){
87  $type = $this->id;
88  }
89  }
90  }
91  }
92  }
93 
94  return $levels[$type];
95  }
96 
97  public function isPickaxe(){
98  return false;
99  }
100 
101  public function isAxe(){
102  return false;
103  }
104 
105  public function isSword(){
106  return false;
107  }
108 
109  public function isShovel(){
110  return false;
111  }
112 
113  public function isHoe(){
114  return false;
115  }
116 
117  public function isShears(){
118  return ($this->id === self::SHEARS);
119  }
120 
121  public function isTool(){
122  return ($this->id === self::FLINT_STEEL or $this->id === self::SHEARS or $this->id === self::BOW or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false);
123  }
124 }
useOn($object)
Definition: Tool.php:50