ChorusPlant: fixed recalculateCollisionBoxes() depending on the world

This commit is contained in:
Dylan K. Taylor 2025-01-27 21:28:26 +00:00
parent fc86d3a44e
commit 70fb9bbdfd
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -34,11 +34,16 @@ use function mt_rand;
final class ChorusPlant extends Flowable{ final class ChorusPlant extends Flowable{
use StaticSupportTrait; use StaticSupportTrait;
/**
* @var true[]
* @phpstan-var array<int, true>
*/
protected array $connections = [];
protected function recalculateCollisionBoxes() : array{ protected function recalculateCollisionBoxes() : array{
$bb = AxisAlignedBB::one(); $bb = AxisAlignedBB::one();
foreach($this->getAllSides() as $facing => $block){ foreach(Facing::ALL as $facing){
$id = $block->getTypeId(); if(!isset($this->connections[$facing])){
if($id !== BlockTypeIds::END_STONE && $id !== BlockTypeIds::CHORUS_FLOWER && !$block->hasSameTypeId($this)){
$bb->trim($facing, 2 / 16); $bb->trim($facing, 2 / 16);
} }
} }
@ -46,6 +51,26 @@ final class ChorusPlant extends Flowable{
return [$bb]; return [$bb];
} }
public function readStateFromWorld() : Block{
parent::readStateFromWorld();
$this->collisionBoxes = null;
foreach(Facing::ALL as $facing){
$block = $this->getSide($facing);
if(match($block->getTypeId()){
BlockTypeIds::END_STONE, BlockTypeIds::CHORUS_FLOWER, $this->getTypeId() => true,
default => false
}){
$this->connections[$facing] = true;
}else{
unset($this->connections[$facing]);
}
}
return $this;
}
private function canBeSupportedBy(Block $block) : bool{ private function canBeSupportedBy(Block $block) : bool{
return $block->hasSameTypeId($this) || $block->getTypeId() === BlockTypeIds::END_STONE; return $block->hasSameTypeId($this) || $block->getTypeId() === BlockTypeIds::END_STONE;
} }