mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
lazy-init RuntimeBlockMapping
This commit is contained in:
parent
0840ba8067
commit
b5a98a993f
@ -40,8 +40,8 @@ final class RuntimeBlockMapping{
|
|||||||
private static $legacyToRuntimeMap = [];
|
private static $legacyToRuntimeMap = [];
|
||||||
/** @var int[] */
|
/** @var int[] */
|
||||||
private static $runtimeToLegacyMap = [];
|
private static $runtimeToLegacyMap = [];
|
||||||
/** @var mixed[] */
|
/** @var mixed[]|null */
|
||||||
private static $bedrockKnownStates;
|
private static $bedrockKnownStates = null;
|
||||||
|
|
||||||
private function __construct(){
|
private function __construct(){
|
||||||
//NOOP
|
//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.
|
* 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
|
* 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
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function toStaticRuntimeId(int $id, int $meta = 0) : int{
|
public static function toStaticRuntimeId(int $id, int $meta = 0) : int{
|
||||||
|
self::lazyInit();
|
||||||
/*
|
/*
|
||||||
* try id+meta first
|
* try id+meta first
|
||||||
* if not found, try id+0 (strip meta)
|
* if not found, try id+0 (strip meta)
|
||||||
@ -115,6 +122,7 @@ final class RuntimeBlockMapping{
|
|||||||
* @return int[] [id, meta]
|
* @return int[] [id, meta]
|
||||||
*/
|
*/
|
||||||
public static function fromStaticRuntimeId(int $runtimeId) : array{
|
public static function fromStaticRuntimeId(int $runtimeId) : array{
|
||||||
|
self::lazyInit();
|
||||||
$v = self::$runtimeToLegacyMap[$runtimeId];
|
$v = self::$runtimeToLegacyMap[$runtimeId];
|
||||||
return [$v >> 4, $v & 0xf];
|
return [$v >> 4, $v & 0xf];
|
||||||
}
|
}
|
||||||
@ -128,7 +136,7 @@ final class RuntimeBlockMapping{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getBedrockKnownStates() : array{
|
public static function getBedrockKnownStates() : array{
|
||||||
|
self::lazyInit();
|
||||||
return self::$bedrockKnownStates;
|
return self::$bedrockKnownStates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RuntimeBlockMapping::init();
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user