Air::class, self::STONE => Stone::class, self::GRASS => Grass::class, self::DIRT => Dirt::class, self::COBBLESTONE => Cobblestone::class, self::PLANKS => Planks::class, self::SAPLING => Sapling::class, self::BEDROCK => Bedrock::class, self::WATER => Water::class, self::STILL_WATER => StillWater::class, self::LAVA => Lava::class, self::STILL_LAVA => StillLava::class, self::SAND => Sand::class, self::GRAVEL => Gravel::class, self::GOLD_ORE => GoldOre::class, self::IRON_ORE => IronOre::class, self::COAL_ORE => CoalOre::class, self::WOOD => Wood::class, self::LEAVES => Leaves::class, self::SPONGE => Sponge::class, self::GLASS => Glass::class, self::LAPIS_ORE => LapisOre::class, self::LAPIS_BLOCK => Lapis::class, self::SANDSTONE => Sandstone::class, self::BED_BLOCK => Bed::class, self::COBWEB => Cobweb::class, self::TALL_GRASS => TallGrass::class, self::DEAD_BUSH => DeadBush::class, self::WOOL => Wool::class, self::DANDELION => Dandelion::class, self::POPPY => CyanFlower::class, self::BROWN_MUSHROOM => BrownMushroom::class, self::RED_MUSHROOM => RedMushroom::class, self::GOLD_BLOCK => Gold::class, self::IRON_BLOCK => Iron::class, self::DOUBLE_SLAB => DoubleSlab::class, self::SLAB => Slab::class, self::BRICKS_BLOCK => Bricks::class, self::TNT => TNT::class, self::BOOKSHELF => Bookshelf::class, self::MOSS_STONE => MossStone::class, self::OBSIDIAN => Obsidian::class, self::TORCH => Torch::class, self::FIRE => Fire::class, self::MONSTER_SPAWNER => MonsterSpawner::class, self::WOOD_STAIRS => WoodStairs::class, self::CHEST => Chest::class, self::DIAMOND_ORE => DiamondOre::class, self::DIAMOND_BLOCK => Diamond::class, self::WORKBENCH => Workbench::class, self::WHEAT_BLOCK => Wheat::class, self::FARMLAND => Farmland::class, self::FURNACE => Furnace::class, self::BURNING_FURNACE => BurningFurnace::class, self::SIGN_POST => SignPost::class, self::WOOD_DOOR_BLOCK => WoodDoor::class, self::LADDER => Ladder::class, self::COBBLESTONE_STAIRS => CobblestoneStairs::class, self::WALL_SIGN => WallSign::class, self::IRON_DOOR_BLOCK => IronDoor::class, self::REDSTONE_ORE => RedstoneOre::class, self::GLOWING_REDSTONE_ORE => GlowingRedstoneOre::class, self::SNOW_LAYER => SnowLayer::class, self::ICE => Ice::class, self::SNOW_BLOCK => Snow::class, self::CACTUS => Cactus::class, self::CLAY_BLOCK => Clay::class, self::SUGARCANE_BLOCK => Sugarcane::class, self::FENCE => Fence::class, self::PUMPKIN => Pumpkin::class, self::NETHERRACK => Netherrack::class, self::SOUL_SAND => SoulSand::class, self::GLOWSTONE_BLOCK => Glowstone::class, self::LIT_PUMPKIN => LitPumpkin::class, self::CAKE_BLOCK => Cake::class, self::TRAPDOOR => Trapdoor::class, self::STONE_BRICKS => StoneBricks::class, self::IRON_BARS => IronBars::class, self::GLASS_PANE => GlassPane::class, self::MELON_BLOCK => Melon::class, self::PUMPKIN_STEM => PumpkinStem::class, self::MELON_STEM => MelonStem::class, self::VINE => Vine::class, self::FENCE_GATE => FenceGate::class, self::BRICK_STAIRS => BrickStairs::class, self::STONE_BRICK_STAIRS => StoneBrickStairs::class, self::MYCELIUM => Mycelium::class, self::NETHER_BRICKS => NetherBrick::class, self::NETHER_BRICKS_STAIRS => NetherBrickStairs::class, self::END_PORTAL => EndPortal::class, self::END_STONE => EndStone::class, self::SANDSTONE_STAIRS => SandstoneStairs::class, self::EMERALD_ORE => EmeraldOre::class, self::EMERALD_BLOCK => Emerald::class, self::SPRUCE_WOOD_STAIRS => SpruceWoodStairs::class, self::BIRCH_WOOD_STAIRS => BirchWoodStairs::class, self::JUNGLE_WOOD_STAIRS => JungleWoodStairs::class, self::STONE_WALL => StoneWall::class, self::CARROT_BLOCK => Carrot::class, self::POTATO_BLOCK => Potato::class, self::QUARTZ_BLOCK => Quartz::class, self::QUARTZ_STAIRS => QuartzStairs::class, self::DOUBLE_WOOD_SLAB => DoubleWoodSlab::class, self::WOOD_SLAB => WoodSlab::class, self::STAINED_CLAY => StainedClay::class, self::LEAVES2 => Leaves2::class, self::WOOD2 => Wood2::class, self::ACACIA_WOOD_STAIRS => AcaciaWoodStairs::class, self::DARK_OAK_WOOD_STAIRS => DarkOakWoodStairs::class, self::HAY_BALE => HayBale::class, self::CARPET => Carpet::class, self::HARDENED_CLAY => HardenedClay::class, self::COAL_BLOCK => Coal::class, self::PODZOL => Podzol::class, self::BEETROOT_BLOCK => Beetroot::class, self::STONECUTTER => Stonecutter::class, self::GLOWING_OBSIDIAN => GlowingObsidian::class, self::NETHER_REACTOR => NetherReactor::class, ]; } } /** * @param int $id * @param int $meta * @param Position $pos * * @return Block */ public static function get($id, $meta = 0, Position $pos = null){ if(isset(self::$list[$id])){ $block = self::$list[$id]; $block = new $block($meta); }else{ $block = new Block($id, $meta); } if($pos instanceof Position){ $block->x = $pos->x; $block->y = $pos->y; $block->z = $pos->z; $block->level = $pos->level; } return $block; } /** * @param int $id * @param int $meta * @param string $name */ public function __construct($id, $meta = 0, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; $this->name = $name; } /** * Places the Block, using block space and block target, and side. Returns if the block has been placed. * * @param Item $item * @param Block $block * @param Block $target * @param int $face * @param float $fx * @param float $fy * @param float $fz * @param Player $player = null * * @return bool */ public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ return $this->getLevel()->setBlock($this, $this, true, true); } /** * Returns if the item can be broken with an specific Item * * @param Item $item * * @return bool */ public function isBreakable(Item $item){ return $this->breakable; } /** * Do the actions needed so the block is broken with the Item * * @param Item $item * * @return mixed */ public function onBreak(Item $item){ return $this->getLevel()->setBlock($this, new Air(), true, true); } /** * Fires a block update on the Block * * @param int $type * * @return void */ public function onUpdate($type){ } /** * Do actions when activated by Item. Returns if it has done anything * * @param Item $item * @param Player $player * * @return bool */ public function onActivate(Item $item, Player $player = null){ return $this->isActivable; } /** * @return int */ final public function getHardness(){ return $this->hardness; } /** * @return string */ final public function getName(){ return $this->name; } /** * @return int */ final public function getID(){ return $this->id; } public function addVelocityToEntity(Entity $entity, Vector3 $vector){ } /** * @return int */ final public function getDamage(){ return $this->meta; } /** * @param int $meta */ final public function setDamage($meta){ $this->meta = $meta & 0x0F; } /** * Sets the block position to a new Position object * * @param Position $v */ final public function position(Position $v){ $this->x = (int) $v->x; $this->y = (int) $v->y; $this->z = (int) $v->z; $this->level = $v->level; } /** * Returns an array of Item objects to be dropped * * @param Item $item * * @return array */ public function getDrops(Item $item){ if(!isset(self::$list[$this->id])){ //Unknown blocks return []; }else{ return [ [$this->id, $this->meta, 1], ]; } } /** * Returns the seconds that this block takes to be broken using an specific Item * * @param Item $item * * @return float */ public function getBreakTime(Item $item){ return $this->breakTime; } /** * Returns the Block on the side $side, works like Vector3::side() * * @param int $side * @param int $step * * @return Block */ public function getSide($side, $step = 1){ $v = parent::getSide($side, $step); if($this->isValid()){ return $this->getLevel()->getBlock($v); } return Block::get(Item::AIR, 0, $v); } /** * @return string */ final public function __toString(){ return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")"; } /** * Checks for collision against an AxisAlignedBB * * @param AxisAlignedBB $bb * @param Block[] $list */ public function collidesWithBB(AxisAlignedBB $bb, &$list = []){ $bb2 = $this->getBoundingBox(); if($bb2 !== null and $bb2->intersectsWith($bb)){ $list[] = $bb2; } } /** * @param Entity $entity */ public function onEntityCollide(Entity $entity){ } /** * @return AxisAlignedBB */ public function getBoundingBox(){ return AxisAlignedBB::getBoundingBoxFromPool( $this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1 ); } public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){ $bb = $this->getBoundingBox(); if($bb === null){ return null; } $v1 = $pos1->getIntermediateWithXValue($pos2, $bb->minX); $v2 = $pos1->getIntermediateWithXValue($pos2, $bb->maxX); $v3 = $pos1->getIntermediateWithYValue($pos2, $bb->minY); $v4 = $pos1->getIntermediateWithYValue($pos2, $bb->maxY); $v5 = $pos1->getIntermediateWithZValue($pos2, $bb->minZ); $v6 = $pos1->getIntermediateWithZValue($pos2, $bb->maxZ); if($v1 !== null and !$bb->isVectorInYZ($v1)){ $v1 = null; } if($v2 !== null and !$bb->isVectorInYZ($v2)){ $v2 = null; } if($v3 !== null and !$bb->isVectorInXZ($v3)){ $v3 = null; } if($v4 !== null and !$bb->isVectorInXZ($v4)){ $v4 = null; } if($v5 !== null and !$bb->isVectorInXY($v5)){ $v5 = null; } if($v6 !== null and !$bb->isVectorInXY($v6)){ $v6 = null; } $vector = $v1; if($v2 !== null and ($vector === null or $pos1->distanceSquared($v2) < $pos1->distanceSquared($vector))){ $vector = $v2; } if($v3 !== null and ($vector === null or $pos1->distanceSquared($v3) < $pos1->distanceSquared($vector))){ $vector = $v3; } if($v4 !== null and ($vector === null or $pos1->distanceSquared($v4) < $pos1->distanceSquared($vector))){ $vector = $v4; } if($v5 !== null and ($vector === null or $pos1->distanceSquared($v5) < $pos1->distanceSquared($vector))){ $vector = $v5; } if($v6 !== null and ($vector === null or $pos1->distanceSquared($v6) < $pos1->distanceSquared($vector))){ $vector = $v6; } if($vector === null){ return null; } $f = -1; if($vector === $v1){ $f = 4; }elseif($vector === $v2){ $f = 5; }elseif($vector === $v3){ $f = 0; }elseif($vector === $v4){ $f = 1; }elseif($vector === $v5){ $f = 2; }elseif($vector === $v6){ $f = 3; } return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z)); } public function setMetadata($metadataKey, MetadataValue $metadataValue){ if($this->getLevel() instanceof Level){ $this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue); } } public function getMetadata($metadataKey){ if($this->getLevel() instanceof Level){ $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey); } } public function hasMetadata($metadataKey){ if($this->getLevel() instanceof Level){ $this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey); } } public function removeMetadata($metadataKey, Plugin $plugin){ if($this->getLevel() instanceof Level){ $this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin); } } }