treeType = $treeType; } protected function writeStateToMeta() : int{ return ($this->noDecay ? 0x04 : 0) | ($this->checkDecay ? 0x08 : 0); } public function readStateFromMeta(int $meta) : void{ $this->noDecay = ($meta & 0x04) !== 0; $this->checkDecay = ($meta & 0x08) !== 0; } public function getStateBitmask() : int{ return 0b1100; } public function getHardness() : float{ return 0.2; } public function getToolType() : int{ return BlockToolType::TYPE_SHEARS; } public function diffusesSkyLight() : bool{ return true; } protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{ $index = Level::blockHash($pos->x, $pos->y, $pos->z); if(isset($visited[$index])){ return false; } $visited[$index] = true; $id = $pos->getId(); if($id === Block::WOOD or $id === Block::WOOD2){ return true; } if($pos->getId() === $this->getId() and $distance <= 4){ foreach(Facing::ALL as $side){ if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ return true; } } } return false; } public function onNearbyBlockChange() : void{ if(!$this->noDecay and !$this->checkDecay){ $this->checkDecay = true; $this->getLevel()->setBlock($this, $this, false); } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ if(!$this->noDecay and $this->checkDecay){ $ev = new LeavesDecayEvent($this); $ev->call(); if($ev->isCancelled() or $this->findLog($this)){ $this->checkDecay = false; $this->getLevel()->setBlock($this, $this, false); }else{ $this->getLevel()->useBreakOn($this); } } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->noDecay = true; //artificial leaves don't decay return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getDrops(Item $item) : array{ if($item->getBlockToolType() & BlockToolType::TYPE_SHEARS){ return $this->getDropsForCompatibleTool($item); } $drops = []; if(mt_rand(1, 20) === 1){ //Saplings $drops[] = ItemFactory::get(Item::SAPLING, $this->treeType->getMagicNumber()); } if(($this->treeType === TreeType::$OAK or $this->treeType === TreeType::$DARK_OAK) and mt_rand(1, 200) === 1){ //Apples $drops[] = ItemFactory::get(Item::APPLE); } return $drops; } public function getFlameEncouragement() : int{ return 30; } public function getFlammability() : int{ return 60; } }