PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Block.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\block;
26 
40 
41 
42 class Block extends Position implements Metadatable{
43  const AIR = 0;
44  const STONE = 1;
45  const GRASS = 2;
46  const DIRT = 3;
47  const COBBLESTONE = 4;
48  const COBBLE = 4;
49  const PLANK = 5;
50  const PLANKS = 5;
51  const WOODEN_PLANK = 5;
52  const WOODEN_PLANKS = 5;
53  const SAPLING = 6;
54  const SAPLINGS = 6;
55  const BEDROCK = 7;
56  const WATER = 8;
57  const STILL_WATER = 9;
58  const LAVA = 10;
59  const STILL_LAVA = 11;
60  const SAND = 12;
61  const GRAVEL = 13;
62  const GOLD_ORE = 14;
63  const IRON_ORE = 15;
64  const COAL_ORE = 16;
65  const WOOD = 17;
66  const TRUNK = 17;
67  const LOG = 17;
68  const LEAVES = 18;
69  const LEAVE = 18;
70  const SPONGE = 19;
71  const GLASS = 20;
72  const LAPIS_ORE = 21;
73  const LAPIS_BLOCK = 22;
74 
75  const SANDSTONE = 24;
76 
77  const BED_BLOCK = 26;
78 
79 
80  const COBWEB = 30;
81  const TALL_GRASS = 31;
82  const BUSH = 32;
83  const DEAD_BUSH = 32;
84  const WOOL = 35;
85  const DANDELION = 37;
86  const ROSE = 38;
87  const POPPY = 38;
88  const BROWN_MUSHROOM = 39;
89  const RED_MUSHROOM = 40;
90  const GOLD_BLOCK = 41;
91  const IRON_BLOCK = 42;
92  const DOUBLE_SLAB = 43;
93  const DOUBLE_SLABS = 43;
94  const SLAB = 44;
95  const SLABS = 44;
96  const BRICKS = 45;
97  const BRICKS_BLOCK = 45;
98  const TNT = 46;
99  const BOOKSHELF = 47;
100  const MOSS_STONE = 48;
101  const MOSSY_STONE = 48;
102  const OBSIDIAN = 49;
103  const TORCH = 50;
104  const FIRE = 51;
105  const MONSTER_SPAWNER = 52;
106  const WOOD_STAIRS = 53;
107  const WOODEN_STAIRS = 53;
108  const OAK_WOOD_STAIRS = 53;
109  const OAK_WOODEN_STAIRS = 53;
110  const CHEST = 54;
111 
112  const DIAMOND_ORE = 56;
113  const DIAMOND_BLOCK = 57;
114  const CRAFTING_TABLE = 58;
115  const WORKBENCH = 58;
116  const WHEAT_BLOCK = 59;
117  const FARMLAND = 60;
118  const FURNACE = 61;
119  const BURNING_FURNACE = 62;
120  const LIT_FURNACE = 62;
121  const SIGN_POST = 63;
122  const DOOR_BLOCK = 64;
123  const WOODEN_DOOR_BLOCK = 64;
124  const WOOD_DOOR_BLOCK = 64;
125  const LADDER = 65;
126 
127  const COBBLE_STAIRS = 67;
128  const COBBLESTONE_STAIRS = 67;
129  const WALL_SIGN = 68;
130 
131  const IRON_DOOR_BLOCK = 71;
132 
133  const REDSTONE_ORE = 73;
134  const GLOWING_REDSTONE_ORE = 74;
135  const LIT_REDSTONE_ORE = 74;
136 
137  const SNOW = 78;
138  const SNOW_LAYER = 78;
139  const ICE = 79;
140  const SNOW_BLOCK = 80;
141  const CACTUS = 81;
142  const CLAY_BLOCK = 82;
143  const REEDS = 83;
144  const SUGARCANE_BLOCK = 83;
145 
146  const FENCE = 85;
147  const FENCE_OAK = 85;
148  const PUMPKIN = 86;
149  const NETHERRACK = 87;
150  const SOUL_SAND = 88;
151  const GLOWSTONE = 89;
152  const GLOWSTONE_BLOCK = 89;
153 
154 
155  const LIT_PUMPKIN = 91;
156  const JACK_O_LANTERN = 91;
157  const CAKE_BLOCK = 92;
158 
159  const TRAPDOOR = 96;
160 
161  const STONE_BRICKS = 98;
162  const STONE_BRICK = 98;
163 
164  const IRON_BAR = 101;
165  const IRON_BARS = 101;
166  const GLASS_PANE = 102;
167  const GLASS_PANEL = 102;
168  const MELON_BLOCK = 103;
169  const PUMPKIN_STEM = 104;
170  const MELON_STEM = 105;
171  const VINE = 106;
172  const VINES = 106;
173  const FENCE_GATE = 107;
174  const BRICK_STAIRS = 108;
175  const STONE_BRICK_STAIRS = 109;
176  const MYCELIUM = 110;
177 
178  const NETHER_BRICKS = 112;
179  const NETHER_BRICK_BLOCK = 112;
180 
181  const NETHER_BRICKS_STAIRS = 114;
182 
183  const END_PORTAL_FRAME = 120;
184  const END_STONE = 121;
185 
186  const SANDSTONE_STAIRS = 128;
187  const EMERALD_ORE = 129;
188 
189  const EMERALD_BLOCK = 133;
190  const SPRUCE_WOOD_STAIRS = 134;
191  const SPRUCE_WOODEN_STAIRS = 134;
192  const BIRCH_WOOD_STAIRS = 135;
193  const BIRCH_WOODEN_STAIRS = 135;
194  const JUNGLE_WOOD_STAIRS = 136;
195  const JUNGLE_WOODEN_STAIRS = 136;
196 
197  const COBBLE_WALL = 139;
198  const STONE_WALL = 139;
199  const COBBLESTONE_WALL = 139;
200 
201  const CARROT_BLOCK = 141;
202  const POTATO_BLOCK = 142;
203 
204  const QUARTZ_BLOCK = 155;
205  const QUARTZ_STAIRS = 156;
206  const DOUBLE_WOOD_SLAB = 157;
207  const DOUBLE_WOODEN_SLAB = 157;
208  const DOUBLE_WOOD_SLABS = 157;
209  const DOUBLE_WOODEN_SLABS = 157;
210  const WOOD_SLAB = 158;
211  const WOODEN_SLAB = 158;
212  const WOOD_SLABS = 158;
213  const WOODEN_SLABS = 158;
214  const STAINED_CLAY = 159;
215  const STAINED_HARDENED_CLAY = 159;
216 
217  const LEAVES2 = 161;
218  const LEAVE2 = 161;
219  const WOOD2 = 162;
220  const TRUNK2 = 162;
221  const LOG2 = 162;
222  const ACACIA_WOOD_STAIRS = 163;
223  const ACACIA_WOODEN_STAIRS = 163;
224  const DARK_OAK_WOOD_STAIRS = 164;
225  const DARK_OAK_WOODEN_STAIRS = 164;
226 
227  const HAY_BALE = 170;
228  const CARPET = 171;
229  const HARDENED_CLAY = 172;
230  const COAL_BLOCK = 173;
231 
232  const DOUBLE_PLANT = 175;
233 
234  const FENCE_GATE_SPRUCE = 183;
235  const FENCE_GATE_BIRCH = 184;
236  const FENCE_GATE_JUNGLE = 185;
237  const FENCE_GATE_DARK_OAK = 186;
238  const FENCE_GATE_ACACIA = 187;
239  const FENCE_SPRUCE = 188;
240  const FENCE_BIRCH = 189;
241  const FENCE_JUNGLE = 190;
242  const FENCE_DARK_OAK = 191;
243  const FENCE_ACACIA = 192;
244 
245  const PODZOL = 243;
246  const BEETROOT_BLOCK = 244;
247  const STONECUTTER = 245;
248  const GLOWING_OBSIDIAN = 246;
249  const NETHER_REACTOR = 247;
250 
251  public static $creative = [
252  //Building
253  [Item::COBBLESTONE, 0],
254  [Item::STONE_BRICKS, 0],
255  [Item::STONE_BRICKS, 1],
256  [Item::STONE_BRICKS, 2],
257  [Item::STONE_BRICKS, 3],
258  [Item::MOSS_STONE, 0],
259  [Item::WOODEN_PLANKS, 0],
260  [Item::WOODEN_PLANKS, 1],
261  [Item::WOODEN_PLANKS, 2],
262  [Item::WOODEN_PLANKS, 3],
263  [Item::WOODEN_PLANKS, 4],
264  [Item::WOODEN_PLANKS, 5],
265  [Item::BRICKS, 0],
266 
267  [Item::STONE, 0],
268  [Item::STONE, 1],
269  [Item::STONE, 2],
270  [Item::STONE, 3],
271  [Item::STONE, 4],
272  [Item::STONE, 5],
273  [Item::STONE, 6],
274  [Item::DIRT, 0],
275  [Item::PODZOL, 0],
276  [Item::GRASS, 0],
277  [Item::MYCELIUM, 0],
278  [Item::CLAY_BLOCK, 0],
279  [Item::HARDENED_CLAY, 0],
280  [Item::STAINED_CLAY, 0],
281  [Item::STAINED_CLAY, 7],
282  [Item::STAINED_CLAY, 6],
283  [Item::STAINED_CLAY, 5],
284  [Item::STAINED_CLAY, 4],
285  [Item::STAINED_CLAY, 3],
286  [Item::STAINED_CLAY, 2],
287  [Item::STAINED_CLAY, 1],
288  [Item::STAINED_CLAY, 15],
289  [Item::STAINED_CLAY, 14],
290  [Item::STAINED_CLAY, 13],
291  [Item::STAINED_CLAY, 12],
292  [Item::STAINED_CLAY, 11],
293  [Item::STAINED_CLAY, 10],
294  [Item::STAINED_CLAY, 9],
295  [Item::STAINED_CLAY, 8],
296  [Item::SANDSTONE, 0],
297  [Item::SANDSTONE, 1],
298  [Item::SANDSTONE, 2],
299  [Item::SAND, 0],
300  [Item::SAND, 1],
301  [Item::GRAVEL, 0],
302  [Item::TRUNK, 0],
303  [Item::TRUNK, 1],
304  [Item::TRUNK, 2],
305  [Item::TRUNK, 3],
306  [Item::TRUNK2, 0],
307  [Item::TRUNK2, 1],
308  [Item::NETHER_BRICKS, 0],
309  [Item::NETHERRACK, 0],
310  [Item::BEDROCK, 0],
311  [Item::COBBLESTONE_STAIRS, 0],
312  [Item::OAK_WOODEN_STAIRS, 0],
313  [Item::SPRUCE_WOODEN_STAIRS, 0],
314  [Item::BIRCH_WOODEN_STAIRS, 0],
315  [Item::JUNGLE_WOODEN_STAIRS, 0],
316  [Item::ACACIA_WOODEN_STAIRS, 0],
317  [Item::DARK_OAK_WOODEN_STAIRS, 0],
318  [Item::BRICK_STAIRS, 0],
319  [Item::SANDSTONE_STAIRS, 0],
320  [Item::STONE_BRICK_STAIRS, 0],
321  [Item::NETHER_BRICKS_STAIRS, 0],
322  [Item::QUARTZ_STAIRS, 0],
323  [Item::SLAB, 0],
324  [Item::SLAB, 1],
325  [Item::WOODEN_SLAB, 0],
326  [Item::WOODEN_SLAB, 1],
327  [Item::WOODEN_SLAB, 2],
328  [Item::WOODEN_SLAB, 3],
329  [Item::WOODEN_SLAB, 4],
330  [Item::WOODEN_SLAB, 5],
331  [Item::SLAB, 3],
332  [Item::SLAB, 4],
333  [Item::SLAB, 5],
334  [Item::SLAB, 6],
335  [Item::QUARTZ_BLOCK, 0],
336  [Item::QUARTZ_BLOCK, 1],
337  [Item::QUARTZ_BLOCK, 2],
338  [Item::COAL_ORE, 0],
339  [Item::IRON_ORE, 0],
340  [Item::GOLD_ORE, 0],
341  [Item::DIAMOND_ORE, 0],
342  [Item::LAPIS_ORE, 0],
343  [Item::REDSTONE_ORE, 0],
344  [Item::EMERALD_ORE, 0],
345  [Item::OBSIDIAN, 0],
346  [Item::ICE, 0],
347  [Item::SNOW_BLOCK, 0],
348  [Item::END_STONE, 0],
349 
350  //Decoration
351  [Item::COBBLESTONE_WALL, 0],
352  [Item::COBBLESTONE_WALL, 1],
353  //TODO: Lilly Pad
354  [Item::GOLD_BLOCK, 0],
355  [Item::IRON_BLOCK, 0],
356  [Item::DIAMOND_BLOCK, 0],
357  [Item::LAPIS_BLOCK, 0],
358  [Item::COAL_BLOCK, 0],
359  [Item::EMERALD_BLOCK, 0],
360  [Item::SNOW_LAYER, 0],
361  [Item::GLASS, 0],
362  [Item::GLOWSTONE_BLOCK, 0],
363  [Item::VINES, 0],
364  [Item::NETHER_REACTOR, 0],
365  [Item::LADDER, 0],
366  [Item::SPONGE, 0],
367  [Item::GLASS_PANE, 0],
368  [Item::WOODEN_DOOR, 0],
369  [Item::TRAPDOOR, 0],
370  [Item::FENCE, 0],
371  [Item::FENCE_SPRUCE, 0],
372  [Item::FENCE_BIRCH, 0],
373  [Item::FENCE_DARK_OAK, 0],
374  [Item::FENCE_JUNGLE, 0],
375  [Item::FENCE_GATE, 0],
376  [Item::FENCE_GATE_BIRCH, 0],
377  [Item::FENCE_GATE_SPRUCE, 0],
378  [Item::FENCE_GATE_DARK_OAK, 0],
379  [Item::FENCE_GATE_JUNGLE, 0],
380  [Item::FENCE_GATE_ACACIA, 0],
381  [Item::IRON_BARS, 0],
382  [Item::BED, 0],
383  [Item::BOOKSHELF, 0],
384  [Item::PAINTING, 0],
385  [Item::WORKBENCH, 0],
386  [Item::STONECUTTER, 0],
387  [Item::CHEST, 0],
388  [Item::FURNACE, 0],
389  [Item::END_PORTAL, 0],
390  [Item::DANDELION, 0],
391  [Item::POPPY, 0],
392  //TODO: blue orchid
393  //TODO: Allium
394  //TODO: Azure Bluet
395  //TODO: Red Tulip
396  //TODO: Orange Tulip
397  //TODO: White Tulip
398  //TODO: Pink Tulip
399  //TODO: Oxeye Daisy
400  //TODO: Lilac
401  //TODO: Double Tallgrass
402  //TODO: Large Fern
403  //TODO: Rose Bush
404  //TODO: Peony
405  [Item::BROWN_MUSHROOM, 0],
406  [Item::RED_MUSHROOM, 0],
407  //TODO: Mushroom block (brown, cover)
408  //TODO: Mushroom block (red, cover)
409  //TODO: Mushroom block (brown, stem)
410  //TODO: Mushroom block (red, stem)
411  [Item::CACTUS, 0],
412  [Item::MELON_BLOCK, 0],
413  [Item::PUMPKIN, 0],
414  [Item::LIT_PUMPKIN, 0],
415  [Item::COBWEB, 0],
416  [Item::HAY_BALE, 0],
417  [Item::TALL_GRASS, 1],
418  [Item::TALL_GRASS, 2],
419  [Item::DEAD_BUSH, 0],
420  [Item::SAPLING, 0],
421  [Item::SAPLING, 1],
422  [Item::SAPLING, 2],
423  [Item::SAPLING, 3],
424  [Item::SAPLING, 4],
425  [Item::SAPLING, 5],
426  [Item::LEAVES, 0],
427  [Item::LEAVES, 1],
428  [Item::LEAVES, 2],
429  [Item::LEAVES, 3],
430  [Item::LEAVES, 3],
431  [Item::LEAVES2, 0],
432  [Item::LEAVES2, 1],
433  [Item::CAKE, 0],
434  [Item::SIGN, 0],
435  [Item::MONSTER_SPAWNER, 0],
436  [Item::WOOL, 0],
437  [Item::WOOL, 7],
438  [Item::WOOL, 6],
439  [Item::WOOL, 5],
440  [Item::WOOL, 4],
441  [Item::WOOL, 3],
442  [Item::WOOL, 2],
443  [Item::WOOL, 1],
444  [Item::WOOL, 15],
445  [Item::WOOL, 14],
446  [Item::WOOL, 13],
447  [Item::WOOL, 12],
448  [Item::WOOL, 11],
449  [Item::WOOL, 10],
450  [Item::WOOL, 9],
451  [Item::WOOL, 8],
452  [Item::CARPET, 0],
453  [Item::CARPET, 7],
454  [Item::CARPET, 6],
455  [Item::CARPET, 5],
456  [Item::CARPET, 4],
457  [Item::CARPET, 3],
458  [Item::CARPET, 2],
459  [Item::CARPET, 1],
460  [Item::CARPET, 15],
461  [Item::CARPET, 14],
462  [Item::CARPET, 13],
463  [Item::CARPET, 12],
464  [Item::CARPET, 11],
465  [Item::CARPET, 10],
466  [Item::CARPET, 9],
467  [Item::CARPET, 8],
468 
469  //Tools
470  //TODO [Item::RAILS, 0],
471  //TODO [Item::POWERED_RAILS, 0],
472  [Item::TORCH, 0],
473  [Item::BUCKET, 0],
474  [Item::BUCKET, 8],
475  [Item::BUCKET, 10],
476  [Item::TNT, 0],
477  [Item::IRON_HOE, 0],
478  [Item::IRON_SWORD, 0],
479  [Item::BOW, 0],
480  [Item::SHEARS, 0],
481  [Item::FLINT_AND_STEEL, 0],
482  [Item::CLOCK, 0],
483  [Item::COMPASS, 0],
484  [Item::MINECART, 0],
485  [Item::SPAWN_EGG, Villager::NETWORK_ID],
486  //[Item::SPAWN_EGG, 10], //Chicken
487  //[Item::SPAWN_EGG, 11], //Cow
488  //[Item::SPAWN_EGG, 12], //Pig
489  //[Item::SPAWN_EGG, 13], //Sheep
490  //TODO: Wolf
491  //TODO: Mooshroom
492  //TODO: Creeper
493  //TODO: Enderman
494  //TODO: Silverfish
495  //TODO: Skeleton
496  //TODO: Slime
497  [Item::SPAWN_EGG, Zombie::NETWORK_ID],
498  //TODO: PigZombie
499  //TODO: Replace with Entity constants
500 
501 
502  //Seeds
503  [Item::SUGARCANE, 0],
504  [Item::WHEAT, 0],
505  [Item::SEEDS, 0],
506  [Item::MELON_SEEDS, 0],
507  [Item::PUMPKIN_SEEDS, 0],
508  [Item::CARROT, 0],
509  [Item::POTATO, 0],
510  [Item::BEETROOT_SEEDS, 0],
511  [Item::EGG, 0],
512  [Item::DYE, 0],
513  [Item::DYE, 7],
514  [Item::DYE, 6],
515  [Item::DYE, 5],
516  [Item::DYE, 4],
517  [Item::DYE, 3],
518  [Item::DYE, 2],
519  [Item::DYE, 1],
520  [Item::DYE, 15],
521  [Item::DYE, 14],
522  [Item::DYE, 13],
523  [Item::DYE, 12],
524  [Item::DYE, 11],
525  [Item::DYE, 10],
526  [Item::DYE, 9],
527  [Item::DYE, 8],
528 
529  ];
530 
532  public static $list = null;
534  public static $fullList = null;
535 
537  public static $light = null;
539  public static $lightFilter = null;
541  public static $solid = null;
543  public static $hardness = null;
545  public static $transparent = null;
546 
547  protected $id;
548  protected $meta = 0;
549 
551  protected $boundingBox = null;
552 
562  public function __get($key){
563  static $map = [
564  "hardness" => "getHardness",
565  "lightLevel" => "getLightLevel",
566  "frictionFactor" => "getFrictionFactor",
567  "name" => "getName",
568  "isPlaceable" => "canBePlaced",
569  "isReplaceable" => "canBeReplaced",
570  "isTransparent" => "isTransparent",
571  "isSolid" => "isSolid",
572  "isFlowable" => "canBeFlowedInto",
573  "isActivable" => "canBeActivated",
574  "hasEntityCollision" => "hasEntityCollision"
575  ];
576  return isset($map[$key]) ? $this->{$map[$key]}() : null;
577  }
578 
579  public static function init(){
580  if(self::$list === null){
581  self::$list = new \SplFixedArray(256);
582  self::$fullList = new \SplFixedArray(4096);
583  self::$light = new \SplFixedArray(256);
584  self::$lightFilter = new \SplFixedArray(256);
585  self::$solid = new \SplFixedArray(256);
586  self::$hardness = new \SplFixedArray(256);
587  self::$transparent = new \SplFixedArray(256);
588  self::$list[self::AIR] = Air::class;
589  self::$list[self::STONE] = Stone::class;
590  self::$list[self::GRASS] = Grass::class;
591  self::$list[self::DIRT] = Dirt::class;
592  self::$list[self::COBBLESTONE] = Cobblestone::class;
593  self::$list[self::PLANKS] = Planks::class;
594  self::$list[self::SAPLING] = Sapling::class;
595  self::$list[self::BEDROCK] = Bedrock::class;
596  self::$list[self::WATER] = Water::class;
597  self::$list[self::STILL_WATER] = StillWater::class;
598  self::$list[self::LAVA] = Lava::class;
599  self::$list[self::STILL_LAVA] = StillLava::class;
600  self::$list[self::SAND] = Sand::class;
601  self::$list[self::GRAVEL] = Gravel::class;
602  self::$list[self::GOLD_ORE] = GoldOre::class;
603  self::$list[self::IRON_ORE] = IronOre::class;
604  self::$list[self::COAL_ORE] = CoalOre::class;
605  self::$list[self::WOOD] = Wood::class;
606  self::$list[self::LEAVES] = Leaves::class;
607  self::$list[self::SPONGE] = Sponge::class;
608  self::$list[self::GLASS] = Glass::class;
609  self::$list[self::LAPIS_ORE] = LapisOre::class;
610  self::$list[self::LAPIS_BLOCK] = Lapis::class;
611  self::$list[self::SANDSTONE] = Sandstone::class;
612  self::$list[self::BED_BLOCK] = Bed::class;
613  self::$list[self::COBWEB] = Cobweb::class;
614  self::$list[self::TALL_GRASS] = TallGrass::class;
615  self::$list[self::DEAD_BUSH] = DeadBush::class;
616  self::$list[self::WOOL] = Wool::class;
617  self::$list[self::DANDELION] = Dandelion::class;
618  self::$list[self::POPPY] = Poppy::class;
619  self::$list[self::BROWN_MUSHROOM] = BrownMushroom::class;
620  self::$list[self::RED_MUSHROOM] = RedMushroom::class;
621  self::$list[self::GOLD_BLOCK] = Gold::class;
622  self::$list[self::IRON_BLOCK] = Iron::class;
623  self::$list[self::DOUBLE_SLAB] = DoubleSlab::class;
624  self::$list[self::SLAB] = Slab::class;
625  self::$list[self::BRICKS_BLOCK] = Bricks::class;
626  self::$list[self::TNT] = TNT::class;
627  self::$list[self::BOOKSHELF] = Bookshelf::class;
628  self::$list[self::MOSS_STONE] = MossStone::class;
629  self::$list[self::OBSIDIAN] = Obsidian::class;
630  self::$list[self::TORCH] = Torch::class;
631  self::$list[self::FIRE] = Fire::class;
632  self::$list[self::MONSTER_SPAWNER] = MonsterSpawner::class;
633  self::$list[self::WOOD_STAIRS] = WoodStairs::class;
634  self::$list[self::CHEST] = Chest::class;
635 
636  self::$list[self::DIAMOND_ORE] = DiamondOre::class;
637  self::$list[self::DIAMOND_BLOCK] = Diamond::class;
638  self::$list[self::WORKBENCH] = Workbench::class;
639  self::$list[self::WHEAT_BLOCK] = Wheat::class;
640  self::$list[self::FARMLAND] = Farmland::class;
641  self::$list[self::FURNACE] = Furnace::class;
642  self::$list[self::BURNING_FURNACE] = BurningFurnace::class;
643  self::$list[self::SIGN_POST] = SignPost::class;
644  self::$list[self::WOOD_DOOR_BLOCK] = WoodDoor::class;
645  self::$list[self::LADDER] = Ladder::class;
646 
647  self::$list[self::COBBLESTONE_STAIRS] = CobblestoneStairs::class;
648  self::$list[self::WALL_SIGN] = WallSign::class;
649 
650  self::$list[self::IRON_DOOR_BLOCK] = IronDoor::class;
651  self::$list[self::REDSTONE_ORE] = RedstoneOre::class;
652  self::$list[self::GLOWING_REDSTONE_ORE] = GlowingRedstoneOre::class;
653 
654  self::$list[self::SNOW_LAYER] = SnowLayer::class;
655  self::$list[self::ICE] = Ice::class;
656  self::$list[self::SNOW_BLOCK] = Snow::class;
657  self::$list[self::CACTUS] = Cactus::class;
658  self::$list[self::CLAY_BLOCK] = Clay::class;
659  self::$list[self::SUGARCANE_BLOCK] = Sugarcane::class;
660 
661  self::$list[self::FENCE] = Fence::class;
662  self::$list[self::PUMPKIN] = Pumpkin::class;
663  self::$list[self::NETHERRACK] = Netherrack::class;
664  self::$list[self::SOUL_SAND] = SoulSand::class;
665  self::$list[self::GLOWSTONE_BLOCK] = Glowstone::class;
666 
667  self::$list[self::LIT_PUMPKIN] = LitPumpkin::class;
668  self::$list[self::CAKE_BLOCK] = Cake::class;
669 
670  self::$list[self::TRAPDOOR] = Trapdoor::class;
671 
672  self::$list[self::STONE_BRICKS] = StoneBricks::class;
673 
674  self::$list[self::IRON_BARS] = IronBars::class;
675  self::$list[self::GLASS_PANE] = GlassPane::class;
676  self::$list[self::MELON_BLOCK] = Melon::class;
677  self::$list[self::PUMPKIN_STEM] = PumpkinStem::class;
678  self::$list[self::MELON_STEM] = MelonStem::class;
679  self::$list[self::VINE] = Vine::class;
680  self::$list[self::FENCE_GATE] = FenceGate::class;
681  self::$list[self::BRICK_STAIRS] = BrickStairs::class;
682  self::$list[self::STONE_BRICK_STAIRS] = StoneBrickStairs::class;
683 
684  self::$list[self::MYCELIUM] = Mycelium::class;
685  self::$list[self::NETHER_BRICKS] = NetherBrick::class;
686 
687  self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class;
688 
689  self::$list[self::END_PORTAL_FRAME] = EndPortalFrame::class;
690  self::$list[self::END_STONE] = EndStone::class;
691  self::$list[self::SANDSTONE_STAIRS] = SandstoneStairs::class;
692  self::$list[self::EMERALD_ORE] = EmeraldOre::class;
693 
694  self::$list[self::EMERALD_BLOCK] = Emerald::class;
695  self::$list[self::SPRUCE_WOOD_STAIRS] = SpruceWoodStairs::class;
696  self::$list[self::BIRCH_WOOD_STAIRS] = BirchWoodStairs::class;
697  self::$list[self::JUNGLE_WOOD_STAIRS] = JungleWoodStairs::class;
698  self::$list[self::STONE_WALL] = StoneWall::class;
699 
700  self::$list[self::CARROT_BLOCK] = Carrot::class;
701  self::$list[self::POTATO_BLOCK] = Potato::class;
702 
703  self::$list[self::QUARTZ_BLOCK] = Quartz::class;
704  self::$list[self::QUARTZ_STAIRS] = QuartzStairs::class;
705  self::$list[self::DOUBLE_WOOD_SLAB] = DoubleWoodSlab::class;
706  self::$list[self::WOOD_SLAB] = WoodSlab::class;
707  self::$list[self::STAINED_CLAY] = StainedClay::class;
708 
709  self::$list[self::LEAVES2] = Leaves2::class;
710  self::$list[self::WOOD2] = Wood2::class;
711  self::$list[self::ACACIA_WOOD_STAIRS] = AcaciaWoodStairs::class;
712  self::$list[self::DARK_OAK_WOOD_STAIRS] = DarkOakWoodStairs::class;
713 
714  self::$list[self::HAY_BALE] = HayBale::class;
715  self::$list[self::CARPET] = Carpet::class;
716  self::$list[self::HARDENED_CLAY] = HardenedClay::class;
717  self::$list[self::COAL_BLOCK] = Coal::class;
718 
719  self::$list[self::DOUBLE_PLANT] = DoublePlant::class;
720 
721  self::$list[self::FENCE_GATE_SPRUCE] = FenceGateSpruce::class;
722  self::$list[self::FENCE_GATE_BIRCH] = FenceGateBirch::class;
723  self::$list[self::FENCE_GATE_JUNGLE] = FenceGateJungle::class;
724  self::$list[self::FENCE_GATE_DARK_OAK] = FenceGateDarkOak::class;
725  self::$list[self::FENCE_GATE_ACACIA] = FenceGateAcacia::class;
726  self::$list[self::FENCE_SPRUCE] = FenceSpruce::class;
727  self::$list[self::FENCE_BIRCH] = FenceBirch::class;
728  self::$list[self::FENCE_DARK_OAK] = FenceDarkOak::class;
729  self::$list[self::FENCE_JUNGLE] = FenceJungle::class;
730  self::$list[self::FENCE_ACACIA] = FenceAcacia::class;
731 
732  self::$list[self::PODZOL] = Podzol::class;
733  self::$list[self::BEETROOT_BLOCK] = Beetroot::class;
734  self::$list[self::STONECUTTER] = Stonecutter::class;
735  self::$list[self::GLOWING_OBSIDIAN] = GlowingObsidian::class;
736  self::$list[self::NETHER_REACTOR] = NetherReactor::class;
737 
738  foreach(self::$list as $id => $class){
739  if($class !== null){
741  $block = new $class();
742 
743  for($data = 0; $data < 16; ++$data){
744  self::$fullList[($id << 4) | $data] = new $class($data);
745  }
746 
747  self::$solid[$id] = $block->isSolid();
748  self::$transparent[$id] = $block->isTransparent();
749  self::$hardness[$id] = $block->getHardness();
750  self::$light[$id] = $block->getLightLevel();
751 
752  if($block->isSolid()){
753  if($block->isTransparent()){
754  if($block instanceof Liquid or $block instanceof Ice){
755  self::$lightFilter[$id] = 2;
756  }else{
757  self::$lightFilter[$id] = 1;
758  }
759  }else{
760  self::$lightFilter[$id] = 15;
761  }
762  }else{
763  self::$lightFilter[$id] = 1;
764  }
765  }else{
766  self::$lightFilter[$id] = 1;
767  for($data = 0; $data < 16; ++$data){
768  self::$fullList[($id << 4) | $data] = new Block($id, $data);
769  }
770  }
771  }
772  }
773  }
774 
782  public static function get($id, $meta = 0, Position $pos = null){
783  try{
784  $block = self::$list[$id];
785  if($block !== null){
786  $block = new $block($meta);
787  }else{
788  $block = new Block($id, $meta);
789  }
790  }catch(\RuntimeException $e){
791  $block = new Block($id, $meta);
792  }
793 
794  if($pos !== null){
795  $block->x = $pos->x;
796  $block->y = $pos->y;
797  $block->z = $pos->z;
798  $block->level = $pos->level;
799  }
800 
801  return $block;
802  }
803 
808  public function __construct($id, $meta = 0){
809  $this->id = (int) $id;
810  $this->meta = (int) $meta;
811  }
812 
827  public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
828  return $this->getLevel()->setBlock($this, $this, true, true);
829  }
830 
838  public function isBreakable(Item $item){
839  return true;
840  }
841 
849  public function onBreak(Item $item){
850  return $this->getLevel()->setBlock($this, new Air(), true, true);
851  }
852 
860  public function onUpdate($type){
861 
862  }
863 
872  public function onActivate(Item $item, Player $player = null){
873  return false;
874  }
875 
879  public function getHardness(){
880  return 10;
881  }
882 
886  public function getFrictionFactor(){
887  return 0.6;
888  }
889 
893  public function getLightLevel(){
894  return 0;
895  }
896 
902  public function canBePlaced(){
903  return true;
904  }
905 
911  public function canBeReplaced(){
912  return false;
913  }
914 
918  public function isTransparent(){
919  return false;
920  }
921 
922  public function isSolid(){
923  return true;
924  }
925 
931  public function canBeFlowedInto(){
932  return false;
933  }
934 
940  public function canBeActivated(){
941  return false;
942  }
943 
944  public function hasEntityCollision(){
945  return false;
946  }
947 
951  public function getName(){
952  return "Unknown";
953  }
954 
958  final public function getId(){
959  return $this->id;
960  }
961 
962  public function addVelocityToEntity(Entity $entity, Vector3 $vector){
963 
964  }
965 
969  final public function getDamage(){
970  return $this->meta;
971  }
972 
976  final public function setDamage($meta){
977  $this->meta = $meta & 0x0f;
978  }
979 
985  final public function position(Position $v){
986  $this->x = (int) $v->x;
987  $this->y = (int) $v->y;
988  $this->z = (int) $v->z;
989  $this->level = $v->level;
990  }
991 
999  public function getDrops(Item $item){
1000  if(!isset(self::$list[$this->id])){ //Unknown blocks
1001  return [];
1002  }else{
1003  return [
1004  [$this->id, $this->meta, 1],
1005  ];
1006  }
1007  }
1008 
1016  public function getBreakTime(Item $item){
1017  return 0.20;
1018  }
1019 
1028  public function getSide($side, $step = 1){
1029  if($this->isValid()){
1030  return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
1031  }
1032 
1033  return Block::get(Item::AIR, 0, new Position($v->x, $v->y, $v->z, null));
1034  }
1035 
1039  public function __toString(){
1040  return "Block[" . $this->getName() . "] (" . $this->id . ":" . $this->meta . ")";
1041  }
1042 
1049  public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
1050  $bb2 = $this->getBoundingBox();
1051  if($bb2 !== null and $bb2->intersectsWith($bb)){
1052  $list[] = $bb2;
1053  }
1054  }
1055 
1059  public function onEntityCollide(Entity $entity){
1060 
1061  }
1062 
1066  public function getBoundingBox(){
1067  if($this->boundingBox !== null){
1068  return $this->boundingBox;
1069  }else{
1070  return $this->boundingBox = $this->recalculateBoundingBox();
1071  }
1072  }
1073 
1077  protected function recalculateBoundingBox(){
1078  return new AxisAlignedBB(
1079  $this->x,
1080  $this->y,
1081  $this->z,
1082  $this->x + 1,
1083  $this->y + 1,
1084  $this->z + 1
1085  );
1086  }
1087 
1088  public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){
1089  $bb = $this->getBoundingBox();
1090  if($bb === null){
1091  return null;
1092  }
1093 
1094  $v1 = $pos1->getIntermediateWithXValue($pos2, $bb->minX);
1095  $v2 = $pos1->getIntermediateWithXValue($pos2, $bb->maxX);
1096  $v3 = $pos1->getIntermediateWithYValue($pos2, $bb->minY);
1097  $v4 = $pos1->getIntermediateWithYValue($pos2, $bb->maxY);
1098  $v5 = $pos1->getIntermediateWithZValue($pos2, $bb->minZ);
1099  $v6 = $pos1->getIntermediateWithZValue($pos2, $bb->maxZ);
1100 
1101  if($v1 !== null and !$bb->isVectorInYZ($v1)){
1102  $v1 = null;
1103  }
1104 
1105  if($v2 !== null and !$bb->isVectorInYZ($v2)){
1106  $v2 = null;
1107  }
1108 
1109  if($v3 !== null and !$bb->isVectorInXZ($v3)){
1110  $v3 = null;
1111  }
1112 
1113  if($v4 !== null and !$bb->isVectorInXZ($v4)){
1114  $v4 = null;
1115  }
1116 
1117  if($v5 !== null and !$bb->isVectorInXY($v5)){
1118  $v5 = null;
1119  }
1120 
1121  if($v6 !== null and !$bb->isVectorInXY($v6)){
1122  $v6 = null;
1123  }
1124 
1125  $vector = $v1;
1126 
1127  if($v2 !== null and ($vector === null or $pos1->distanceSquared($v2) < $pos1->distanceSquared($vector))){
1128  $vector = $v2;
1129  }
1130 
1131  if($v3 !== null and ($vector === null or $pos1->distanceSquared($v3) < $pos1->distanceSquared($vector))){
1132  $vector = $v3;
1133  }
1134 
1135  if($v4 !== null and ($vector === null or $pos1->distanceSquared($v4) < $pos1->distanceSquared($vector))){
1136  $vector = $v4;
1137  }
1138 
1139  if($v5 !== null and ($vector === null or $pos1->distanceSquared($v5) < $pos1->distanceSquared($vector))){
1140  $vector = $v5;
1141  }
1142 
1143  if($v6 !== null and ($vector === null or $pos1->distanceSquared($v6) < $pos1->distanceSquared($vector))){
1144  $vector = $v6;
1145  }
1146 
1147  if($vector === null){
1148  return null;
1149  }
1150 
1151  $f = -1;
1152 
1153  if($vector === $v1){
1154  $f = 4;
1155  }elseif($vector === $v2){
1156  $f = 5;
1157  }elseif($vector === $v3){
1158  $f = 0;
1159  }elseif($vector === $v4){
1160  $f = 1;
1161  }elseif($vector === $v5){
1162  $f = 2;
1163  }elseif($vector === $v6){
1164  $f = 3;
1165  }
1166 
1167  return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
1168  }
1169 
1170  public function setMetadata($metadataKey, MetadataValue $metadataValue){
1171  if($this->getLevel() instanceof Level){
1172  $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue);
1173  }
1174  }
1175 
1176  public function getMetadata($metadataKey){
1177  if($this->getLevel() instanceof Level){
1178  $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
1179  }
1180  }
1181 
1182  public function hasMetadata($metadataKey){
1183  if($this->getLevel() instanceof Level){
1184  $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey);
1185  }
1186  }
1187 
1188  public function removeMetadata($metadataKey, Plugin $plugin){
1189  if($this->getLevel() instanceof Level){
1190  $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin);
1191  }
1192  }
1193 }
onBreak(Item $item)
Definition: Block.php:849
onEntityCollide(Entity $entity)
Definition: Block.php:1059
getIntermediateWithZValue(Vector3 $v, $z)
Definition: Vector3.php:295
place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player=null)
Definition: Block.php:827
hasMetadata($metadataKey)
Definition: Block.php:1182
getMetadata($metadataKey)
Definition: Block.php:1176
isBreakable(Item $item)
Definition: Block.php:838
onActivate(Item $item, Player $player=null)
Definition: Block.php:872
collidesWithBB(AxisAlignedBB $bb, &$list=[])
Definition: Block.php:1049
getBreakTime(Item $item)
Definition: Block.php:1016
position(Position $v)
Definition: Block.php:985
getSide($side, $step=1)
Definition: Block.php:1028
setMetadata($metadataKey, MetadataValue $metadataValue)
Definition: Block.php:1170
static fromBlock($x, $y, $z, $side, Vector3 $hitVector)
getIntermediateWithYValue(Vector3 $v, $y)
Definition: Vector3.php:268
removeMetadata($metadataKey, Plugin $plugin)
Definition: Block.php:1188
static get($id, $meta=0, Position $pos=null)
Definition: Block.php:782
getDrops(Item $item)
Definition: Block.php:999
__construct($id, $meta=0)
Definition: Block.php:808
getIntermediateWithXValue(Vector3 $v, $x)
Definition: Vector3.php:241