From b5a98a993faebc39033b0fdb24c3a57bdb19a657 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 27 Oct 2019 20:58:43 +0000 Subject: [PATCH] lazy-init RuntimeBlockMapping --- .../mcpe/protocol/types/RuntimeBlockMapping.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/types/RuntimeBlockMapping.php b/src/pocketmine/network/mcpe/protocol/types/RuntimeBlockMapping.php index 9ba73cbb4..606148d1b 100644 --- a/src/pocketmine/network/mcpe/protocol/types/RuntimeBlockMapping.php +++ b/src/pocketmine/network/mcpe/protocol/types/RuntimeBlockMapping.php @@ -40,8 +40,8 @@ final class RuntimeBlockMapping{ private static $legacyToRuntimeMap = []; /** @var int[] */ private static $runtimeToLegacyMap = []; - /** @var mixed[] */ - private static $bedrockKnownStates; + /** @var mixed[]|null */ + private static $bedrockKnownStates = null; private function __construct(){ //NOOP @@ -77,6 +77,12 @@ final class RuntimeBlockMapping{ } } + private static function lazyInit() : void{ + if(self::$bedrockKnownStates === null){ + self::init(); + } + } + /** * Randomizes the order of the runtimeID table to prevent plugins relying on them. * Plugins shouldn't use this stuff anyway, but plugin devs have an irritating habit of ignoring what they @@ -101,6 +107,7 @@ final class RuntimeBlockMapping{ * @return int */ public static function toStaticRuntimeId(int $id, int $meta = 0) : int{ + self::lazyInit(); /* * try id+meta first * if not found, try id+0 (strip meta) @@ -115,6 +122,7 @@ final class RuntimeBlockMapping{ * @return int[] [id, meta] */ public static function fromStaticRuntimeId(int $runtimeId) : array{ + self::lazyInit(); $v = self::$runtimeToLegacyMap[$runtimeId]; return [$v >> 4, $v & 0xf]; } @@ -128,7 +136,7 @@ final class RuntimeBlockMapping{ * @return array */ public static function getBedrockKnownStates() : array{ + self::lazyInit(); return self::$bedrockKnownStates; } } -RuntimeBlockMapping::init();