From 9f4418e01d74a3bd86b3ab5b3fe986741d5c80f1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 24 Mar 2022 12:52:51 +0000 Subject: [PATCH] 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. --- src/block/Wall.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/block/Wall.php b/src/block/Wall.php index 6c827d190..06e7d061a 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -35,16 +35,31 @@ class Wall extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); + $this->recalculateConnections(); + } + + protected function recalculateConnections() : bool{ + $changed = 0; foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); if($block instanceof static || $block instanceof FenceGate || ($block->isSolid() && !$block->isTransparent())){ - $this->connections[$facing] = $facing; - }else{ + if(!isset($this->connections[$facing])){ + $this->connections[$facing] = $facing; + $changed++; + } + }elseif(isset($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{