44 protected array $faces = [];
47 $w->facingFlags($this->faces);
51 public function getFaces() : array{ return $this->faces; }
53 public function hasFace(
int $face) : bool{
54 return isset($this->faces[$face]);
63 foreach($faces as $face){
64 Facing::validate($face);
65 $uniqueFaces[$face] = $face;
67 $this->faces = $uniqueFaces;
72 public function setFace(
int $face,
bool $value) : self{
75 $this->faces[$face] = $face;
77 unset($this->faces[$face]);
98 return SupportType::NONE;
106 $this->faces = $blockReplace instanceof
GlowLichen ? $blockReplace->faces : [];
107 $availableFaces = $this->getAvailableFaces();
109 if(count($availableFaces) === 0){
113 $opposite = Facing::opposite($face);
114 $placedFace = isset($availableFaces[$opposite]) ? $opposite : array_key_first($availableFaces);
115 $this->faces[$placedFace] = $placedFace;
117 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
123 foreach($this->faces as $face){
124 if($this->getAdjacentSupportType($face) !== SupportType::FULL){
125 unset($this->faces[$face]);
131 $world = $this->position->getWorld();
132 if(count($this->faces) === 0){
133 $world->useBreakOn($this->position);
135 $world->setBlock($this->position, $this);
140 private function getSpreadBlock(Block $replace,
int $spreadFace) : ?Block{
141 if($replace instanceof self && $replace->hasSameTypeId($this)){
142 if($replace->hasFace($spreadFace)){
146 }elseif($replace->getTypeId() === BlockTypeIds::AIR){
147 $result = VanillaBlocks::GLOW_LICHEN();
152 return $result->setFace($spreadFace,
true);
155 private function spread(World $world, Vector3 $replacePos,
int $spreadFace) : bool{
156 $supportBlock = $world->getBlock($replacePos->getSide($spreadFace));
157 $supportFace = Facing::opposite($spreadFace);
159 if($supportBlock->getSupportType($supportFace) !== SupportType::FULL){
163 $replacedBlock = $supportBlock->getSide($supportFace);
164 $replacementBlock = $this->getSpreadBlock($replacedBlock, Facing::opposite($supportFace));
165 if($replacementBlock ===
null){
169 return BlockEventHelper::spread($replacedBlock, $replacementBlock, $this);
175 private static function getShuffledSpreadFaces(
int $sourceFace) : \Generator{
176 $skipAxis = Facing::axis($sourceFace);
178 $faces = Facing::ALL;
180 foreach($faces as $spreadFace){
181 if(Facing::axis($spreadFace) !== $skipAxis){
187 private function spreadAroundSupport(
int $sourceFace) : bool{
188 $world = $this->position->getWorld();
190 $supportPos = $this->position->getSide($sourceFace);
191 foreach(self::getShuffledSpreadFaces($sourceFace) as $spreadFace){
192 $replacePos = $supportPos->getSide($spreadFace);
193 if($this->spread($world, $replacePos, Facing::opposite($spreadFace))){
201 private function spreadAdjacentToSupport(
int $sourceFace) : bool{
202 $world = $this->position->getWorld();
204 foreach(self::getShuffledSpreadFaces($sourceFace) as $spreadFace){
205 $replacePos = $this->position->getSide($spreadFace);
206 if($this->spread($world, $replacePos, $sourceFace)){
213 private function spreadWithinSelf(
int $sourceFace) : bool{
214 foreach(self::getShuffledSpreadFaces($sourceFace) as $spreadFace){
215 if(!$this->hasFace($spreadFace) && $this->spread($this->position->getWorld(), $this->position, $spreadFace)){
224 if($item instanceof
Fertilizer && count($this->faces) > 0){
225 $shuffledFaces = $this->faces;
226 shuffle($shuffledFaces);
229 $this->spreadAroundSupport(...),
230 $this->spreadAdjacentToSupport(...),
231 $this->spreadWithinSelf(...),
233 shuffle($spreadMethods);
235 foreach($shuffledFaces as $sourceFace){
236 foreach($spreadMethods as $spreadMethod){
237 if($spreadMethod($sourceFace)){
250 if(($item->getBlockToolType() &
BlockToolType::SHEARS) !== 0){
251 return $this->getDropsForCompatibleTool($item);
268 private function getAvailableFaces() : array{
270 foreach(Facing::ALL as $face){
271 if(!$this->hasFace($face) && $this->getAdjacentSupportType($face) === SupportType::FULL){
272 $faces[$face] = $face;
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)