CropGrowthHelper: avoid unnecessary checks

This commit is contained in:
Dylan K. Taylor 2023-11-02 15:32:22 +00:00
parent 109673382d
commit a6b36d6c3c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -66,7 +66,8 @@ final class CropGrowthHelper{
$xRow = false; $xRow = false;
$zRow = false; $zRow = false;
$diagonalRow = false; $improperArrangement = false;
for($x = -1; $x <= 1; $x++){ for($x = -1; $x <= 1; $x++){
for($z = -1; $z <= 1; $z++){ for($z = -1; $z <= 1; $z++){
if($x === 0 && $z === 0){ if($x === 0 && $z === 0){
@ -74,23 +75,27 @@ final class CropGrowthHelper{
} }
$nextFarmland = $world->getBlockAt($baseX + $x, $baseY - 1, $baseZ + $z); $nextFarmland = $world->getBlockAt($baseX + $x, $baseY - 1, $baseZ + $z);
if($nextFarmland instanceof Farmland){ if(!$nextFarmland instanceof Farmland){
$result += $nextFarmland->getWetness() > 0 ? self::ADJACENT_HYDRATED_FARMLAND_BONUS : self::ADJACENT_DRY_FARMLAND_BONUS; continue;
} }
$nextCrop = $world->getBlockAt($baseX + $x, $baseY, $baseZ + $z); $result += $nextFarmland->getWetness() > 0 ? self::ADJACENT_HYDRATED_FARMLAND_BONUS : self::ADJACENT_DRY_FARMLAND_BONUS;
if($nextCrop->hasSameTypeId($block)){
match(0){ if(!$improperArrangement){
$x => $xRow = true, $nextCrop = $world->getBlockAt($baseX + $x, $baseY, $baseZ + $z);
$z => $zRow = true, if($nextCrop->hasSameTypeId($block)){
default => $diagonalRow = true, match(0){
}; $x => $zRow ? $improperArrangement = true : $xRow = true,
$z => $xRow ? $improperArrangement = true : $zRow = true,
default => $improperArrangement = true,
};
}
} }
} }
} }
//crops can be arranged in rows, but the rows must not cross and must be spaced apart by at least one block //crops can be arranged in rows, but the rows must not cross and must be spaced apart by at least one block
if(($xRow && $zRow) || $diagonalRow){ if($improperArrangement){
$result /= self::IMPROPER_ARRANGEMENT_DIVISOR; $result /= self::IMPROPER_ARRANGEMENT_DIVISOR;
} }