From 1f461977d442cccb2ce02613b1e1b9f9a2539342 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Oct 2023 17:28:19 +0100 Subject: [PATCH] Block: Avoid useless Vector3 allocations in getHorizontalSides and getAllSides --- src/block/Block.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index ee1f9500b..0bbb8d370 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -768,8 +768,14 @@ class Block{ */ public function getHorizontalSides() : \Generator{ $world = $this->position->getWorld(); - foreach($this->position->sidesAroundAxis(Axis::Y) as $vector3){ - yield $world->getBlock($vector3); + foreach(Facing::HORIZONTAL as $facing){ + [$dx, $dy, $dz] = Facing::OFFSET[$facing]; + //TODO: yield Facing as the key? + yield $world->getBlockAt( + $this->position->x + $dx, + $this->position->y + $dy, + $this->position->z + $dz + ); } } @@ -781,8 +787,13 @@ class Block{ */ public function getAllSides() : \Generator{ $world = $this->position->getWorld(); - foreach($this->position->sides() as $vector3){ - yield $world->getBlock($vector3); + foreach(Facing::OFFSET as [$dx, $dy, $dz]){ + //TODO: yield Facing as the key? + yield $world->getBlockAt( + $this->position->x + $dx, + $this->position->y + $dy, + $this->position->z + $dz + ); } }