PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
item/Item.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 
25 namespace pocketmine\item;
26 
32 
33 class Item{
34  //All Block IDs are here too
35  const AIR = 0;
36  const STONE = 1;
37  const GRASS = 2;
38  const DIRT = 3;
39  const COBBLESTONE = 4;
40  const COBBLE = 4;
41  const PLANK = 5;
42  const PLANKS = 5;
43  const WOODEN_PLANK = 5;
44  const WOODEN_PLANKS = 5;
45  const SAPLING = 6;
46  const SAPLINGS = 6;
47  const BEDROCK = 7;
48  const WATER = 8;
49  const STILL_WATER = 9;
50  const LAVA = 10;
51  const STILL_LAVA = 11;
52  const SAND = 12;
53  const GRAVEL = 13;
54  const GOLD_ORE = 14;
55  const IRON_ORE = 15;
56  const COAL_ORE = 16;
57  const LOG = 17;
58  const WOOD = 17;
59  const TRUNK = 17;
60  const LEAVES = 18;
61  const LEAVE = 18;
62  const SPONGE = 19;
63  const GLASS = 20;
64  const LAPIS_ORE = 21;
65  const LAPIS_BLOCK = 22;
66 
67  const SANDSTONE = 24;
68 
69  const BED_BLOCK = 26;
70 
71 
72  const COBWEB = 30;
73  const TALL_GRASS = 31;
74  const BUSH = 32;
75  const DEAD_BUSH = 32;
76  const WOOL = 35;
77  const DANDELION = 37;
78  const ROSE = 38;
79  const POPPY = 38;
80  const BROWN_MUSHROOM = 39;
81  const RED_MUSHROOM = 40;
82  const GOLD_BLOCK = 41;
83  const IRON_BLOCK = 42;
84  const DOUBLE_SLAB = 43;
85  const DOUBLE_SLABS = 43;
86  const SLAB = 44;
87  const SLABS = 44;
88  const BRICKS = 45;
89  const BRICKS_BLOCK = 45;
90  const TNT = 46;
91  const BOOKSHELF = 47;
92  const MOSS_STONE = 48;
93  const MOSSY_STONE = 48;
94  const OBSIDIAN = 49;
95  const TORCH = 50;
96  const FIRE = 51;
97  const MONSTER_SPAWNER = 52;
98  const WOOD_STAIRS = 53;
99  const WOODEN_STAIRS = 53;
100  const OAK_WOOD_STAIRS = 53;
101  const OAK_WOODEN_STAIRS = 53;
102  const CHEST = 54;
103 
104  const DIAMOND_ORE = 56;
105  const DIAMOND_BLOCK = 57;
106  const CRAFTING_TABLE = 58;
107  const WORKBENCH = 58;
108  const WHEAT_BLOCK = 59;
109  const FARMLAND = 60;
110  const FURNACE = 61;
111  const BURNING_FURNACE = 62;
112  const LIT_FURNACE = 62;
113  const SIGN_POST = 63;
114  const DOOR_BLOCK = 64;
115  const WOODEN_DOOR_BLOCK = 64;
116  const WOOD_DOOR_BLOCK = 64;
117  const LADDER = 65;
118 
119  const COBBLE_STAIRS = 67;
120  const COBBLESTONE_STAIRS = 67;
121  const WALL_SIGN = 68;
122 
123  const IRON_DOOR_BLOCK = 71;
124 
125  const REDSTONE_ORE = 73;
126  const GLOWING_REDSTONE_ORE = 74;
127  const LIT_REDSTONE_ORE = 74;
128 
129  const SNOW = 78;
130  const SNOW_LAYER = 78;
131  const ICE = 79;
132  const SNOW_BLOCK = 80;
133  const CACTUS = 81;
134  const CLAY_BLOCK = 82;
135  const REEDS = 83;
136  const SUGARCANE_BLOCK = 83;
137 
138  const FENCE = 85;
139  const PUMPKIN = 86;
140  const NETHERRACK = 87;
141  const SOUL_SAND = 88;
142  const GLOWSTONE = 89;
143  const GLOWSTONE_BLOCK = 89;
144 
145 
146  const LIT_PUMPKIN = 91;
147  const JACK_O_LANTERN = 91;
148  const CAKE_BLOCK = 92;
149 
150  const TRAPDOOR = 96;
151 
152  const STONE_BRICKS = 98;
153  const STONE_BRICK = 98;
154 
155  const IRON_BAR = 101;
156  const IRON_BARS = 101;
157  const GLASS_PANE = 102;
158  const GLASS_PANEL = 102;
159  const MELON_BLOCK = 103;
160  const PUMPKIN_STEM = 104;
161  const MELON_STEM = 105;
162  const VINE = 106;
163  const VINES = 106;
164  const FENCE_GATE = 107;
165  const BRICK_STAIRS = 108;
166  const STONE_BRICK_STAIRS = 109;
167  const MYCELIUM = 110;
168 
169  const NETHER_BRICKS = 112;
170  const NETHER_BRICK_BLOCK = 112;
171 
172  const NETHER_BRICKS_STAIRS = 114;
173 
174  const END_PORTAL = 120;
175  const END_STONE = 121;
176 
177  const SANDSTONE_STAIRS = 128;
178  const EMERALD_ORE = 129;
179 
180  const EMERALD_BLOCK = 133;
181  const SPRUCE_WOOD_STAIRS = 134;
182  const SPRUCE_WOODEN_STAIRS = 134;
183  const BIRCH_WOOD_STAIRS = 135;
184  const BIRCH_WOODEN_STAIRS = 135;
185  const JUNGLE_WOOD_STAIRS = 136;
186  const JUNGLE_WOODEN_STAIRS = 136;
187 
188  const COBBLE_WALL = 139;
189  const STONE_WALL = 139;
190  const COBBLESTONE_WALL = 139;
191 
192  const CARROT_BLOCK = 141;
193  const POTATO_BLOCK = 142;
194 
195  const QUARTZ_BLOCK = 155;
196  const QUARTZ_STAIRS = 156;
197  const DOUBLE_WOOD_SLAB = 157;
198  const DOUBLE_WOODEN_SLAB = 157;
199  const DOUBLE_WOOD_SLABS = 157;
200  const DOUBLE_WOODEN_SLABS = 157;
201  const WOOD_SLAB = 158;
202  const WOODEN_SLAB = 158;
203  const WOOD_SLABS = 158;
204  const WOODEN_SLABS = 158;
205  const STAINED_CLAY = 159;
206  const STAINED_HARDENED_CLAY = 159;
207 
208  const LEAVES2 = 161;
209  const LEAVE2 = 161;
210  const WOOD2 = 162;
211  const TRUNK2 = 162;
212  const LOG2 = 162;
213  const ACACIA_WOOD_STAIRS = 163;
214  const ACACIA_WOODEN_STAIRS = 163;
215  const DARK_OAK_WOOD_STAIRS = 164;
216  const DARK_OAK_WOODEN_STAIRS = 164;
217 
218  const HAY_BALE = 170;
219  const CARPET = 171;
220  const HARDENED_CLAY = 172;
221  const COAL_BLOCK = 173;
222 
223  const DOUBLE_PLANT = 175;
224 
225  const FENCE_GATE_SPRUCE = 183;
226  const FENCE_GATE_BIRCH = 184;
227  const FENCE_GATE_JUNGLE = 185;
228  const FENCE_GATE_DARK_OAK = 186;
229  const FENCE_GATE_ACACIA = 187;
230  const FENCE_SPRUCE = 188;
231  const FENCE_BIRCH = 189;
232  const FENCE_JUNGLE = 190;
233  const FENCE_DARK_OAK = 191;
234  const FENCE_ACACIA = 192;
235 
236  const PODZOL = 243;
237  const BEETROOT_BLOCK = 244;
238  const STONECUTTER = 245;
239  const GLOWING_OBSIDIAN = 246;
240  const NETHER_REACTOR = 247;
241 
242 
243  //Normal Item IDs
244 
245  const IRON_SHOVEL = 256; //
246  const IRON_PICKAXE = 257; //
247  const IRON_AXE = 258; //
248  const FLINT_STEEL = 259; //
249  const FLINT_AND_STEEL = 259; //
250  const APPLE = 260; //
251  const BOW = 261;
252  const ARROW = 262;
253  const COAL = 263; //
254  const DIAMOND = 264; //
255  const IRON_INGOT = 265; //
256  const GOLD_INGOT = 266; //
257  const IRON_SWORD = 267;
258  const WOODEN_SWORD = 268; //
259  const WOODEN_SHOVEL = 269; //
260  const WOODEN_PICKAXE = 270; //
261  const WOODEN_AXE = 271; //
262  const STONE_SWORD = 272;
263  const STONE_SHOVEL = 273;
264  const STONE_PICKAXE = 274;
265  const STONE_AXE = 275;
266  const DIAMOND_SWORD = 276;
267  const DIAMOND_SHOVEL = 277;
268  const DIAMOND_PICKAXE = 278;
269  const DIAMOND_AXE = 279;
270  const STICK = 280; //
271  const STICKS = 280;
272  const BOWL = 281; //
273  const MUSHROOM_STEW = 282;
274  const GOLD_SWORD = 283;
275  const GOLD_SHOVEL = 284;
276  const GOLD_PICKAXE = 285;
277  const GOLD_AXE = 286;
278  const GOLDEN_SWORD = 283;
279  const GOLDEN_SHOVEL = 284;
280  const GOLDEN_PICKAXE = 285;
281  const GOLDEN_AXE = 286;
282  const STRING = 287;
283  const FEATHER = 288; //
284  const GUNPOWDER = 289;
285  const WOODEN_HOE = 290;
286  const STONE_HOE = 291;
287  const IRON_HOE = 292; //
288  const DIAMOND_HOE = 293;
289  const GOLD_HOE = 294;
290  const GOLDEN_HOE = 294;
291  const SEEDS = 295;
292  const WHEAT_SEEDS = 295;
293  const WHEAT = 296;
294  const BREAD = 297;
295  const LEATHER_CAP = 298;
296  const LEATHER_TUNIC = 299;
297  const LEATHER_PANTS = 300;
298  const LEATHER_BOOTS = 301;
299  const CHAIN_HELMET = 302;
300  const CHAIN_CHESTPLATE = 303;
301  const CHAIN_LEGGINGS = 304;
302  const CHAIN_BOOTS = 305;
303  const IRON_HELMET = 306;
304  const IRON_CHESTPLATE = 307;
305  const IRON_LEGGINGS = 308;
306  const IRON_BOOTS = 309;
307  const DIAMOND_HELMET = 310;
308  const DIAMOND_CHESTPLATE = 311;
309  const DIAMOND_LEGGINGS = 312;
310  const DIAMOND_BOOTS = 313;
311  const GOLD_HELMET = 314;
312  const GOLD_CHESTPLATE = 315;
313  const GOLD_LEGGINGS = 316;
314  const GOLD_BOOTS = 317;
315  const FLINT = 318;
316  const RAW_PORKCHOP = 319;
317  const COOKED_PORKCHOP = 320;
318  const PAINTING = 321;
319  const GOLDEN_APPLE = 322;
320  const SIGN = 323;
321  const WOODEN_DOOR = 324;
322  const BUCKET = 325;
323 
324  const MINECART = 329;
325 
326  const IRON_DOOR = 330;
327  const REDSTONE = 331;
328  const REDSTONE_DUST = 331;
329  const SNOWBALL = 332;
330 
331  const LEATHER = 334;
332 
333  const BRICK = 336;
334  const CLAY = 337;
335  const SUGARCANE = 338;
336  const SUGAR_CANE = 338;
337  const SUGAR_CANES = 338;
338  const PAPER = 339;
339  const BOOK = 340;
340  const SLIMEBALL = 341;
341 
342  const EGG = 344;
343  const COMPASS = 345;
344 
345  const CLOCK = 347;
346  const GLOWSTONE_DUST = 348;
347  //const RAW_FISH = 349;
348  //const COOKED_FISH = 350;
349  const DYE = 351;
350  const BONE = 352;
351  const SUGAR = 353;
352  const CAKE = 354;
353  const BED = 355;
354 
355 
356  //const COOKIE = 357;
357 
358 
359  const SHEARS = 359;
360  const MELON = 360;
361  const MELON_SLICE = 360;
362  const PUMPKIN_SEEDS = 361;
363  const MELON_SEEDS = 362;
364  const RAW_BEEF = 363;
365  const STEAK = 364;
366  const COOKED_BEEF = 364;
367 
368  const RAW_CHICKEN = 365;
369  const COOKED_CHICKEN = 366;
370 
371  const SPAWN_EGG = 383;
372 
373  const EMERALD = 388;
374 
375  const CARROT = 391;
376  const CARROTS = 391;
377  const POTATO = 392;
378  const POTATOES = 392;
379  const BAKED_POTATO = 393;
380  const BAKED_POTATOES = 393;
381 
382  const PUMPKIN_PIE = 400;
383 
384  const NETHER_BRICK = 405;
385  const QUARTZ = 406;
386  const NETHER_QUARTZ = 406;
387 
388  const CAMERA = 456;
389  const BEETROOT = 457;
390  const BEETROOT_SEEDS = 458;
391  const BEETROOT_SEED = 458;
392  const BEETROOT_SOUP = 459;
393 
394 
396  public static $list = null;
397  protected $block;
398  protected $id;
399  protected $meta;
400  public $count;
401  protected $durability = 0;
402  protected $name;
403 
404  public function canBeActivated(){
405  return false;
406  }
407 
408  public static function init(){
409  if(self::$list === null){
410  self::$list = new \SplFixedArray(65536);
411  self::$list[self::SUGARCANE] = Sugarcane::class;
412  self::$list[self::WHEAT_SEEDS] = WheatSeeds::class;
413  self::$list[self::PUMPKIN_SEEDS] = PumpkinSeeds::class;
414  self::$list[self::MELON_SEEDS] = MelonSeeds::class;
415  self::$list[self::MUSHROOM_STEW] = MushroomStew::class;
416  self::$list[self::BEETROOT_SOUP] = BeetrootSoup::class;
417  self::$list[self::CARROT] = Carrot::class;
418  self::$list[self::POTATO] = Potato::class;
419  self::$list[self::BEETROOT_SEEDS] = BeetrootSeeds::class;
420  self::$list[self::SIGN] = Sign::class;
421  self::$list[self::WOODEN_DOOR] = WoodenDoor::class;
422  self::$list[self::BUCKET] = Bucket::class;
423  self::$list[self::IRON_DOOR] = IronDoor::class;
424  self::$list[self::CAKE] = Cake::class;
425  self::$list[self::BED] = Bed::class;
426  self::$list[self::PAINTING] = Painting::class;
427  self::$list[self::COAL] = Coal::class;
428  self::$list[self::APPLE] = Apple::class;
429  self::$list[self::SPAWN_EGG] = SpawnEgg::class;
430  self::$list[self::DIAMOND] = Diamond::class;
431  self::$list[self::STICK] = Stick::class;
432  self::$list[self::SNOWBALL] = Snowball::class;
433  self::$list[self::BOWL] = Bowl::class;
434  self::$list[self::FEATHER] = Feather::class;
435  self::$list[self::BRICK] = Brick::class;
436  self::$list[self::LEATHER_CAP] = LeatherCap::class;
437  self::$list[self::LEATHER_TUNIC] = LeatherTunic::class;
438  self::$list[self::LEATHER_PANTS] = LeatherPants::class;
439  self::$list[self::CHAIN_HELMET] = ChainHelmet::class;
440  self::$list[self::CHAIN_CHESTPLATE] = ChainChestplate::class;
441  self::$list[self::CHAIN_LEGGINGS] = ChainLeggings::class;
442  self::$list[self::CHAIN_BOOTS] = ChainBoots::class;
443  self::$list[self::IRON_HELMET] = IronHelmet::class;
444  self::$list[self::IRON_CHESTPLATE] = IronChestplate::class;
445  self::$list[self::IRON_LEGGINGS] = IronLeggings::class;
446  self::$list[self::IRON_BOOTS] = IronBoots::class;
447  self::$list[self::GOLD_HELMET] = GoldHelmet::class;
448  self::$list[self::GOLD_CHESTPLATE] = GoldChestplate::class;
449  self::$list[self::GOLD_LEGGINGS] = GoldLeggings::class;
450  self::$list[self::GOLD_BOOTS] = GoldBoots::class;
451  self::$list[self::DIAMOND_HELMET] = DiamondHelmet::class;
452  self::$list[self::DIAMOND_CHESTPLATE] = DiamondChestplate::class;
453  self::$list[self::DIAMOND_LEGGINGS] = DiamondLeggings::class;
454  self::$list[self::DIAMOND_BOOTS] = DiamondBoots::class;
455  self::$list[self::IRON_SWORD] = IronSword::class;
456  self::$list[self::IRON_INGOT] = IronIngot::class;
457  self::$list[self::GOLD_INGOT] = GoldIngot::class;
458  self::$list[self::IRON_SHOVEL] = IronShovel::class;
459  self::$list[self::IRON_PICKAXE] = IronPickaxe::class;
460  self::$list[self::IRON_AXE] = IronAxe::class;
461  self::$list[self::IRON_HOE] = IronHoe::class;
462  self::$list[self::DIAMOND_SWORD] = DiamondSword::class;
463  self::$list[self::DIAMOND_SHOVEL] = DiamondShovel::class;
464  self::$list[self::DIAMOND_PICKAXE] = DiamondPickaxe::class;
465  self::$list[self::DIAMOND_AXE] = DiamondAxe::class;
466  self::$list[self::DIAMOND_HOE] = DiamondHoe::class;
467  self::$list[self::GOLD_SWORD] = GoldSword::class;
468  self::$list[self::GOLD_SHOVEL] = GoldShovel::class;
469  self::$list[self::GOLD_PICKAXE] = GoldPickaxe::class;
470  self::$list[self::GOLD_AXE] = GoldAxe::class;
471  self::$list[self::GOLD_HOE] = GoldHoe::class;
472  self::$list[self::STONE_SWORD] = StoneSword::class;
473  self::$list[self::STONE_SHOVEL] = StoneShovel::class;
474  self::$list[self::STONE_PICKAXE] = StonePickaxe::class;
475  self::$list[self::STONE_AXE] = StoneAxe::class;
476  self::$list[self::STONE_HOE] = StoneHoe::class;
477  self::$list[self::WOODEN_SWORD] = WoodenSword::class;
478  self::$list[self::WOODEN_SHOVEL] = WoodenShovel::class;
479  self::$list[self::WOODEN_PICKAXE] = WoodenPickaxe::class;
480  self::$list[self::WOODEN_AXE] = WoodenAxe::class;
481  self::$list[self::WOODEN_HOE] = WoodenHoe::class;
482  self::$list[self::FLINT_STEEL] = FlintSteel::class;
483  self::$list[self::SHEARS] = Shears::class;
484  self::$list[self::BOW] = Bow::class;
485 
486  for($i = 0; $i < 256; ++$i){
487  if(Block::$list[$i] !== null){
488  self::$list[$i] = Block::$list[$i];
489  }
490  }
491  }
492  }
493 
494  public static function get($id, $meta = 0, $count = 1){
495  try{
496  $class = self::$list[$id];
497  if($class === null){
498  return new Item($id, $meta, $count);
499  }elseif($id < 256){
500  return new ItemBlock(new $class($meta), $meta, $count);
501  }else{
502  return new $class($meta, $count);
503  }
504  }catch(\RuntimeException $e){
505  return new Item($id, $meta, $count);
506  }
507  }
508 
509  public static function fromString($str, $multiple = false){
510  if($multiple === true){
511  $blocks = [];
512  foreach(explode(",", $str) as $b){
513  $blocks[] = self::fromString($b, false);
514  }
515 
516  return $blocks;
517  }else{
518  $b = explode(":", str_replace(" ", "_", trim($str)));
519  if(!isset($b[1])){
520  $meta = 0;
521  }else{
522  $meta = $b[1] & 0xFFFF;
523  }
524 
525  if(defined(Item::class . "::" . strtoupper($b[0]))){
526  $item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta);
527  if($item->getId() === self::AIR and strtoupper($b[0]) !== "AIR"){
528  $item = self::get($b[0] & 0xFFFF, $meta);
529  }
530  }else{
531  $item = self::get($b[0] & 0xFFFF, $meta);
532  }
533 
534  return $item;
535  }
536  }
537 
538  public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
539  $this->id = $id & 0xffff;
540  $this->meta = $meta !== null ? $meta & 0xffff : null;
541  $this->count = (int) $count;
542  $this->name = $name;
543  if(!isset($this->block) and $this->id <= 0xff and isset(Block::$list[$this->id])){
544  $this->block = Block::get($this->id, $this->meta);
545  $this->name = $this->block->getName();
546  }
547  }
548 
549 
550  public function getCount(){
551  return $this->count;
552  }
553 
554  public function setCount($count){
555  $this->count = (int) $count;
556  }
557 
558  final public function getName(){
559  return $this->name;
560  }
561 
562  final public function isPlaceable(){
563  return (($this->block instanceof Block) and $this->block->isPlaceable === true);
564  }
565 
566  public function getBlock(){
567  if($this->block instanceof Block){
568  return $this->block;
569  }else{
570  return Block::get(self::AIR);
571  }
572  }
573 
574  final public function getId(){
575  return $this->id;
576  }
577 
578  final public function getDamage(){
579  return $this->meta;
580  }
581 
582  public function setDamage($meta){
583  $this->meta = $meta !== null ? $meta & 0xFFFF : null;
584  }
585 
586  public function getMaxStackSize(){
587  return 64;
588  }
589 
590  final public function getFuelTime(){
591  if(!isset(Fuel::$duration[$this->id])){
592  return null;
593  }
594  if($this->id !== self::BUCKET or $this->meta === 10){
595  return Fuel::$duration[$this->id];
596  }
597 
598  return null;
599  }
600 
606  public function useOn($object){
607  return false;
608  }
609 
613  public function isTool(){
614  return false;
615  }
616 
620  public function getMaxDurability(){
621  return false;
622  }
623 
624  public function isPickaxe(){
625  return false;
626  }
627 
628  public function isAxe(){
629  return false;
630  }
631 
632  public function isSword(){
633  return false;
634  }
635 
636  public function isShovel(){
637  return false;
638  }
639 
640  public function isHoe(){
641  return false;
642  }
643 
644  public function isShears(){
645  return false;
646  }
647 
648  final public function __toString(){
649  return "Item " . $this->name . " (" . $this->id . ":" . ($this->meta === null ? "?" : $this->meta) . ")x" . $this->count;
650  }
651 
652  public function getDestroySpeed(Block $block, Player $player){
653  return 1;
654  }
655 
656  public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
657  return false;
658  }
659 
660  public final function equals(Item $item, $checkDamage = false){
661  return $this->id === $item->getId() and ($checkDamage === false or $this->getDamage() === $item->getDamage());
662  }
663 
664 }
static get($id, $meta=0, Position $pos=null)
Definition: Block.php:782