Merge branch 'stable' into minor-next

This commit is contained in:
Dylan K. Taylor 2023-09-08 12:48:40 +01:00
commit 093b1e1b18
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 8 deletions

View File

@ -77,7 +77,8 @@ class CaveVines extends Flowable{
}
private function canBeSupportedAt(Block $block) : bool{
return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL || $block->hasSameTypeId($this);
$supportBlock = $block->getSide(Facing::UP);
return $supportBlock->getSupportType(Facing::DOWN) === SupportType::FULL || $supportBlock->hasSameTypeId($this);
}
public function onNearbyBlockChange() : void{

View File

@ -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::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{
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);
}
}

View File

@ -37,8 +37,8 @@ use function preg_match;
*/
trait RegistryTrait{
/**
* @var object[]
* @phpstan-var array<string, object>
* @var object[]|null
* @phpstan-var array<string, object>|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"));
}
}