Wall: separate connection calculation into its own method

we'll need this once wall connections start actually being stored instead of just being recalculated on every read.
This commit is contained in:
Dylan K. Taylor 2022-03-24 12:52:51 +00:00
parent 8bf1fb7b1d
commit 9f4418e01d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -35,16 +35,31 @@ class Wall extends Transparent{
public function readStateFromWorld() : void{ public function readStateFromWorld() : void{
parent::readStateFromWorld(); parent::readStateFromWorld();
$this->recalculateConnections();
}
protected function recalculateConnections() : bool{
$changed = 0;
foreach(Facing::HORIZONTAL as $facing){ foreach(Facing::HORIZONTAL as $facing){
$block = $this->getSide($facing); $block = $this->getSide($facing);
if($block instanceof static || $block instanceof FenceGate || ($block->isSolid() && !$block->isTransparent())){ if($block instanceof static || $block instanceof FenceGate || ($block->isSolid() && !$block->isTransparent())){
$this->connections[$facing] = $facing; if(!isset($this->connections[$facing])){
}else{ $this->connections[$facing] = $facing;
$changed++;
}
}elseif(isset($this->connections[$facing])){
unset($this->connections[$facing]); unset($this->connections[$facing]);
$changed++;
} }
} }
$this->up = $this->getSide(Facing::UP)->getId() !== BlockLegacyIds::AIR; $up = $this->getSide(Facing::UP)->getId() !== BlockLegacyIds::AIR;
if($up !== $this->up){
$this->up = $up;
$changed++;
}
return $changed > 0;
} }
protected function recalculateCollisionBoxes() : array{ protected function recalculateCollisionBoxes() : array{