From f868c1d8c634f67d4ac346c9a512d4b5d3d1c033 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Oct 2023 16:38:34 +0100 Subject: [PATCH] Liquid: Update legacy code with Facing::OFFSET --- src/block/Liquid.php | 13 +++------ src/block/utils/MinimumCostFlowCalculator.php | 29 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 9a9e49af4..142aed261 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -170,16 +170,11 @@ abstract class Liquid extends Transparent{ $world = $this->position->getWorld(); foreach(Facing::HORIZONTAL as $j){ - $x = $this->position->x; - $y = $this->position->y; - $z = $this->position->z; + [$dx, $dy, $dz] = Facing::OFFSET[$j]; - match($j){ - Facing::WEST => --$x, - Facing::EAST => ++$x, - Facing::NORTH => --$z, - Facing::SOUTH => ++$z - }; + $x = $this->position->x + $dx; + $y = $this->position->y + $dy; + $z = $this->position->z + $dz; $sideBlock = $world->getBlockAt($x, $y, $z); $blockDecay = $this->getEffectiveFlowDecay($sideBlock); diff --git a/src/block/utils/MinimumCostFlowCalculator.php b/src/block/utils/MinimumCostFlowCalculator.php index 84b003bbd..a690a7487 100644 --- a/src/block/utils/MinimumCostFlowCalculator.php +++ b/src/block/utils/MinimumCostFlowCalculator.php @@ -58,17 +58,10 @@ final class MinimumCostFlowCalculator{ if($j === $originOpposite || $j === $lastOpposite){ continue; } - - $x = $blockX; - $y = $blockY; - $z = $blockZ; - - match($j){ - Facing::WEST => --$x, - Facing::EAST => ++$x, - Facing::NORTH => --$z, - Facing::SOUTH => ++$z - }; + [$dx, $dy, $dz] = Facing::OFFSET[$j]; + $x = $blockX + $dx; + $y = $blockY + $dy; + $z = $blockZ + $dz; if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){ if(!$this->world->isInWorld($x, $y, $z) || !$this->canFlowInto($this->world->getBlockAt($x, $y, $z))){ @@ -109,16 +102,10 @@ final class MinimumCostFlowCalculator{ $flowCost = array_fill_keys(Facing::HORIZONTAL, 1000); $maxCost = intdiv(4, $this->flowDecayPerBlock); foreach(Facing::HORIZONTAL as $j){ - $x = $originX; - $y = $originY; - $z = $originZ; - - match($j){ - Facing::WEST => --$x, - Facing::EAST => ++$x, - Facing::NORTH => --$z, - Facing::SOUTH => ++$z - }; + [$dx, $dy, $dz] = Facing::OFFSET[$j]; + $x = $originX + $dx; + $y = $originY + $dy; + $z = $originZ + $dz; if(!$this->world->isInWorld($x, $y, $z) || !$this->canFlowInto($this->world->getBlockAt($x, $y, $z))){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED;