meta = $meta; } public function getName() : string{ static $names = [ 0 => "Oak Sapling", 1 => "Spruce Sapling", 2 => "Birch Sapling", 3 => "Jungle Sapling", 4 => "Acacia Sapling", 5 => "Dark Oak Sapling" ]; return $names[$this->meta & 0x07] ?? "Unknown"; } public function ticksRandomly() : bool{ return true; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } return false; } public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal //TODO: change log type Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07); $item->count--; return true; } return false; } public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } }elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth if(mt_rand(1, 7) === 1){ if(($this->meta & 0x08) === 0x08){ Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07); }else{ $this->meta |= 0x08; $this->getLevel()->setBlock($this, $this, true); return Level::BLOCK_UPDATE_RANDOM; } }else{ return Level::BLOCK_UPDATE_RANDOM; } } return false; } public function getDrops(Item $item) : array{ return [ ItemFactory::get($this->getItemId(), $this->getDamage() & 0x07, 1) ]; } public function getFuelTime() : int{ return 100; } }