From 6a3ec70c72e79603b2cc618269461204fd578f2b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Oct 2023 13:25:32 +0100 Subject: [PATCH] =?UTF-8?q?=C3=82Block:=20use=20Facing::OFFSET=20in=20getS?= =?UTF-8?q?ide()=20instead=20of=20the=20comically=20inefficient=20getBlock?= =?UTF-8?q?()=20+=20throwaway=20Position->getSide()=20This=20improved=20th?= =?UTF-8?q?e=20function's=20performance=20by=202.3x.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/block/Block.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index 189c0419d..011d81c4f 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -747,8 +747,14 @@ class Block{ * @return Block */ public function getSide(int $side, int $step = 1){ - if($this->position->isValid()){ - return $this->position->getWorld()->getBlock($this->position->getSide($side, $step)); + $position = $this->position; + if($position->isValid()){ + [$dx, $dy, $dz] = Facing::OFFSET[$side] ?? throw new \InvalidArgumentException("Unknown side $side"); + return $position->getWorld()->getBlockAt( + $position->x + ($dx * $step), + $position->y + ($dy * $step), + $position->z + ($dz * $step) + ); } throw new \LogicException("Block does not have a valid world");