From b4606a4cd042ce9b6bd83cf22c1f0ceed7b20895 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 6 May 2020 13:17:16 +0100 Subject: [PATCH] remove PM resource interaction from StartGamePacket also lose the cache, because it's not very useful ... --- .../bedrock/LegacyItemIdToStringIdMap.php | 40 +++++++++++++++++++ .../mcpe/handler/PreSpawnPacketHandler.php | 3 +- src/network/mcpe/protocol/StartGamePacket.php | 18 ++------- 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/data/bedrock/LegacyItemIdToStringIdMap.php diff --git a/src/data/bedrock/LegacyItemIdToStringIdMap.php b/src/data/bedrock/LegacyItemIdToStringIdMap.php new file mode 100644 index 000000000..03efcc161 --- /dev/null +++ b/src/data/bedrock/LegacyItemIdToStringIdMap.php @@ -0,0 +1,40 @@ +levelId = ""; $pk->worldName = $this->server->getMotd(); $pk->blockTable = RuntimeBlockMapping::getInstance()->getStartGamePaletteCache(); - + $pk->itemTable = LegacyItemIdToStringIdMap::getInstance()->getStringToLegacyMap(); //TODO: check if this is actually needed $this->session->sendDataPacket($pk); $this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers()); diff --git a/src/network/mcpe/protocol/StartGamePacket.php b/src/network/mcpe/protocol/StartGamePacket.php index 1ebae773b..f31eb6c81 100644 --- a/src/network/mcpe/protocol/StartGamePacket.php +++ b/src/network/mcpe/protocol/StartGamePacket.php @@ -38,9 +38,6 @@ use const pocketmine\RESOURCE_PATH; class StartGamePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::START_GAME_PACKET; - /** @var string|null */ - private static $itemTableCache = null; - /** @var int */ public $entityUniqueId; /** @var int */ @@ -155,10 +152,10 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{ */ public $blockTable; /** - * @var int[]|null string (name) => int16 (legacyID) - * @phpstan-var array|null + * @var int[] string (name) => int16 (legacyID) + * @phpstan-var array */ - public $itemTable = null; + public $itemTable = []; protected function decodePayload(NetworkBinaryStream $in) : void{ $this->entityUniqueId = $in->getEntityUniqueId(); @@ -285,14 +282,7 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{ $out->put($this->blockTable->getEncodedNbt()); - if($this->itemTable === null){ - if(self::$itemTableCache === null){ - self::$itemTableCache = self::serializeItemTable(json_decode(file_get_contents(RESOURCE_PATH . '/vanilla/item_id_map.json'), true)); - } - $out->put(self::$itemTableCache); - }else{ - $out->put(self::serializeItemTable($this->itemTable)); - } + $out->put(self::serializeItemTable($this->itemTable)); $out->putString($this->multiplayerCorrelationId); }