From d09af2e30da6b393dfeb47f1e5cd2f2f5417f5bd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Nov 2023 17:15:17 +0000 Subject: [PATCH] World: don't assume that random Vector3 are int vectors we can safely assume this for blocks (though the type info doesn't reflect it) but this is not safe to assume for random APIs that might be used by plugins. --- src/block/utils/CropGrowthHelper.php | 2 +- src/world/World.php | 10 ++++++-- tests/phpstan/configs/actual-problems.neon | 30 +++++++++++----------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/block/utils/CropGrowthHelper.php b/src/block/utils/CropGrowthHelper.php index b5fc31362..e85b0b82d 100644 --- a/src/block/utils/CropGrowthHelper.php +++ b/src/block/utils/CropGrowthHelper.php @@ -109,7 +109,7 @@ final class CropGrowthHelper{ $world = $position->getWorld(); //crop growth is not affected by time of day since 1.11 or so - return $world->getPotentialLight($position) >= $minLevel; + return $world->getPotentialLightAt($position->x, $position->y, $position->z) >= $minLevel; } public static function canGrow(Block $block) : bool{ diff --git a/src/world/World.php b/src/world/World.php index 59b02be1a..f554479c9 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1670,7 +1670,10 @@ class World implements ChunkManager{ * time of day. */ public function getFullLight(Vector3 $pos) : int{ - return $this->getFullLightAt($pos->x, $pos->y, $pos->z); + $floorX = $pos->getFloorX(); + $floorY = $pos->getFloorY(); + $floorZ = $pos->getFloorZ(); + return $this->getFullLightAt($floorX, $floorY, $floorZ); } /** @@ -1699,7 +1702,10 @@ class World implements ChunkManager{ * This is not affected by weather or time of day. */ public function getPotentialLight(Vector3 $pos) : int{ - return $this->getPotentialLightAt($pos->x, $pos->y, $pos->z); + $floorX = $pos->getFloorX(); + $floorY = $pos->getFloorY(); + $floorZ = $pos->getFloorZ(); + return $this->getPotentialLightAt($floorX, $floorY, $floorZ); } /** diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index cf7e9b02f..1e5d83dda 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -425,6 +425,21 @@ parameters: count: 3 path: ../../../src/block/tile/Spawnable.php + - + message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + + - + message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + + - + message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + - message: "#^Cannot call method addParticle\\(\\) on pocketmine\\\\world\\\\World\\|null\\.$#" count: 1 @@ -910,11 +925,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 @@ -940,11 +950,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 @@ -975,11 +980,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1