remove PM resource interaction from StartGamePacket

also lose the cache, because it's not very useful ...
This commit is contained in:
Dylan K. Taylor 2020-05-06 13:17:16 +01:00
parent 218f32f5b8
commit b4606a4cd0
3 changed files with 46 additions and 15 deletions

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\bedrock;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\SingletonTrait;
use function file_get_contents;
use function is_array;
use function is_int;
use function is_string;
use function json_decode;
final class LegacyItemIdToStringIdMap extends LegacyToStringBidirectionalIdMap{
use SingletonTrait;
public function __construct(){
parent::__construct(\pocketmine\RESOURCE_PATH . 'vanilla/item_id_map.json');
}
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\handler;
use pocketmine\data\bedrock\LegacyItemIdToStringIdMap;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
@ -78,7 +79,7 @@ class PreSpawnPacketHandler extends PacketHandler{
$pk->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());

View File

@ -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<string, int>|null
* @var int[] string (name) => int16 (legacyID)
* @phpstan-var array<string, int>
*/
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->putString($this->multiplayerCorrelationId);
}