enumSet($this->faces, HorizontalFacingOption::cases()); } /** @return HorizontalFacingOption[] */ public function getFaces() : array{ return $this->faces; } public function hasFace(HorizontalFacingOption $face) : bool{ return isset($this->faces[spl_object_id($face)]); } /** * @param HorizontalFacingOption[] $faces * @return $this */ public function setFaces(array $faces) : self{ $uniqueFaces = []; foreach($faces as $face){ if(!$face instanceof HorizontalFacingOption){ throw new \InvalidArgumentException("Expected array of HorizontalFacingOption"); } $uniqueFaces[spl_object_id($face)] = $face; } $this->faces = $uniqueFaces; return $this; } /** @return $this */ public function setFace(HorizontalFacingOption $face, bool $value) : self{ if($value){ $this->faces[spl_object_id($face)] = $face; }else{ unset($this->faces[spl_object_id($face)]); } return $this; } public function hasEntityCollision() : bool{ return true; } public function canClimb() : bool{ return true; } public function canBeReplaced() : bool{ return true; } public function onEntityInside(Entity $entity) : bool{ $entity->resetFallDistance(); return true; } protected function recalculateCollisionBoxes() : array{ return []; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $oppositeFace = Facing::opposite($face); $hzFacing = HorizontalFacingOption::tryFromFacing($oppositeFace); if($hzFacing === null || !$blockReplace->getSide($oppositeFace)->isFullCube()){ return false; } $this->faces = $blockReplace instanceof Vine ? $blockReplace->faces : []; $this->faces[spl_object_id($hzFacing)] = $hzFacing; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ $changed = false; $up = $this->getSide(Facing::UP); //check which faces have corresponding vines in the block above $supportedFaces = $up instanceof Vine ? array_intersect_key($this->faces, $up->faces) : []; foreach($this->faces as $face){ if(!isset($supportedFaces[spl_object_id($face)]) && !$this->getSide($face->toFacing())->isSolid()){ unset($this->faces[spl_object_id($face)]); $changed = true; } } if($changed){ $world = $this->position->getWorld(); if(count($this->faces) === 0){ $world->useBreakOn($this->position); }else{ $world->setBlock($this->position, $this); } } } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ //TODO: vine growth } public function getDrops(Item $item) : array{ if(($item->getBlockToolType() & BlockToolType::SHEARS) !== 0){ return $this->getDropsForCompatibleTool($item); } return []; } public function getFlameEncouragement() : int{ return 15; } public function getFlammability() : int{ return 100; } }