Liquid: Update legacy code with Facing::OFFSET

This commit is contained in:
Dylan K. Taylor 2023-10-19 16:38:34 +01:00
parent 114f444ec3
commit f868c1d8c6
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 12 additions and 30 deletions

View File

@ -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);

View File

@ -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;