From a5aeabd83662ad9bd52dd83650b4a9684df23383 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Sep 2023 12:16:16 +0100 Subject: [PATCH 1/4] RegistryTrait: fixed mishandling of self::$members Since PHPStan doesn't warn about potential nulls on untyped properties, this flew under the radar. --- src/utils/RegistryTrait.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/RegistryTrait.php b/src/utils/RegistryTrait.php index 573f4737f..2071f4c07 100644 --- a/src/utils/RegistryTrait.php +++ b/src/utils/RegistryTrait.php @@ -37,8 +37,8 @@ use function preg_match; */ trait RegistryTrait{ /** - * @var object[] - * @phpstan-var array + * @var object[]|null + * @phpstan-var array|null */ private static $members = null; @@ -54,6 +54,9 @@ trait RegistryTrait{ * @throws \InvalidArgumentException */ private static function _registryRegister(string $name, object $member) : void{ + if(self::$members === null){ + throw new AssumptionFailedError("Cannot register members outside of " . self::class . "::setup()"); + } self::verifyName($name); $upperName = mb_strtoupper($name); if(isset(self::$members[$upperName])){ @@ -86,6 +89,9 @@ trait RegistryTrait{ */ private static function _registryFromString(string $name) : object{ self::checkInit(); + if(self::$members === null){ + throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly"); + } $upperName = mb_strtoupper($name); if(!isset(self::$members[$upperName])){ throw new \InvalidArgumentException("No such registry member: " . self::class . "::" . $upperName); @@ -121,6 +127,6 @@ trait RegistryTrait{ */ private static function _registryGetAll() : array{ self::checkInit(); - return array_map(self::preprocessMember(...), self::$members); + return array_map(self::preprocessMember(...), self::$members ?? throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly")); } } From 03ecc98a24cb7d1a985d9400f2c33b9d0216e04a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Sep 2023 12:16:45 +0100 Subject: [PATCH 2/4] HangingRoots: fixed support conditions --- src/block/HangingRoots.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/block/HangingRoots.php b/src/block/HangingRoots.php index cd85bcea7..b5ddf7f60 100644 --- a/src/block/HangingRoots.php +++ b/src/block/HangingRoots.php @@ -32,19 +32,19 @@ use pocketmine\world\BlockTransaction; final class HangingRoots extends Flowable{ - private function canBeSupportedBy(Block $block) : bool{ - return $block->isSolid(); //TODO: not sure if this is the correct logic + private function canBeSupportedAt(Block $block) : bool{ + return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$blockReplace->getSide(Facing::UP)->isSolid()){ + if(!$this->canBeSupportedAt($blockReplace)){ return false; } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::UP))){ + if(!$this->canBeSupportedAt($this)){ $this->position->getWorld()->useBreakOn($this->position); } } From 0e87ee1e0e9d8a259e6e8b8b28325cc29b998162 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Sep 2023 12:22:00 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=C3=82HangingRoots:=20fixed=20incorrect=20s?= =?UTF-8?q?upport=20face?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/block/HangingRoots.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/block/HangingRoots.php b/src/block/HangingRoots.php index b5ddf7f60..0e03f4468 100644 --- a/src/block/HangingRoots.php +++ b/src/block/HangingRoots.php @@ -33,7 +33,7 @@ use pocketmine\world\BlockTransaction; final class HangingRoots extends Flowable{ private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences + return $block->getAdjacentSupportType(Facing::UP)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ From d7f69c5e2484ce6b52266e7ed4d0dfb2523be194 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Sep 2023 12:47:46 +0100 Subject: [PATCH 4/4] CaveVines: fixed incorrect support condition --- src/block/CaveVines.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 6ff934881..ce8fdd970 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -88,7 +88,8 @@ class CaveVines extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()) || $block->hasSameTypeId($this); + $supportBlock = $block->getSide(Facing::UP); + return $supportBlock->getSupportType(Facing::DOWN)->equals(SupportType::FULL()) || $supportBlock->hasSameTypeId($this); } public function onNearbyBlockChange() : void{