mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 11:58:00 +00:00
making tile spawn compound cache use CacheableNbt instead of strings
This commit is contained in:
@@ -36,7 +36,7 @@ use pocketmine\item\VanillaItems;
|
||||
use pocketmine\item\WritableBook;
|
||||
use pocketmine\item\WrittenBook;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\NbtDataException;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
||||
@@ -72,7 +72,6 @@ use pocketmine\network\mcpe\protocol\PlayerHotbarPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
|
||||
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
|
||||
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
|
||||
@@ -87,6 +86,7 @@ use pocketmine\network\mcpe\protocol\types\inventory\ReleaseItemTransactionData;
|
||||
use pocketmine\network\mcpe\protocol\types\inventory\UseItemOnEntityTransactionData;
|
||||
use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use function array_push;
|
||||
use function base64_encode;
|
||||
use function count;
|
||||
@@ -554,12 +554,8 @@ class InGamePacketHandler extends PacketHandler{
|
||||
}
|
||||
|
||||
$block = $this->player->getLocation()->getWorldNonNull()->getBlock($pos);
|
||||
try{
|
||||
$offset = 0;
|
||||
$nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->mustGetCompoundTag();
|
||||
}catch(NbtDataException $e){
|
||||
throw BadPacketException::wrap($e);
|
||||
}
|
||||
$nbt = $packet->namedtag->getRoot();
|
||||
if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit
|
||||
|
||||
if($block instanceof Sign){
|
||||
if($nbt->hasTag("Text", StringTag::class)){
|
||||
@@ -580,7 +576,7 @@ class InGamePacketHandler extends PacketHandler{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->session->getLogger()->debug("Invalid sign update data: " . base64_encode($packet->namedtag));
|
||||
$this->session->getLogger()->debug("Invalid sign update data: " . base64_encode($packet->namedtag->getEncodedNbt()));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -25,7 +25,10 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\nbt\NbtDataException;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkBinaryStream;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
||||
|
||||
class BlockActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
|
||||
public const NETWORK_ID = ProtocolInfo::BLOCK_ACTOR_DATA_PACKET;
|
||||
@@ -36,10 +39,16 @@ class BlockActorDataPacket extends DataPacket implements ClientboundPacket, Serv
|
||||
public $y;
|
||||
/** @var int */
|
||||
public $z;
|
||||
/** @var string */
|
||||
/**
|
||||
* @var CacheableNbt
|
||||
* @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>
|
||||
*/
|
||||
public $namedtag;
|
||||
|
||||
public static function create(int $x, int $y, int $z, string $nbt) : self{
|
||||
/**
|
||||
* @phpstan-param CacheableNbt<\pocketmine\nbt\tag\CompoundTag> $nbt
|
||||
*/
|
||||
public static function create(int $x, int $y, int $z, CacheableNbt $nbt) : self{
|
||||
$result = new self;
|
||||
[$result->x, $result->y, $result->z] = [$x, $y, $z];
|
||||
$result->namedtag = $nbt;
|
||||
@@ -48,12 +57,20 @@ class BlockActorDataPacket extends DataPacket implements ClientboundPacket, Serv
|
||||
|
||||
protected function decodePayload(NetworkBinaryStream $in) : void{
|
||||
$in->getBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->namedtag = $in->getRemaining();
|
||||
try{
|
||||
$offset = $in->getOffset();
|
||||
$this->namedtag = new CacheableNbt(
|
||||
(new NetworkNbtSerializer())->read($this->getBinaryStream()->getBuffer(), $offset, 512)->mustGetCompoundTag()
|
||||
);
|
||||
$in->setOffset($offset);
|
||||
}catch(NbtDataException $e){
|
||||
throw PacketDecodeException::wrap($e, "Failed decoding block actor NBT");
|
||||
}
|
||||
}
|
||||
|
||||
protected function encodePayload(NetworkBinaryStream $out) : void{
|
||||
$out->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$out->put($this->namedtag);
|
||||
$out->put($this->namedtag->getEncodedNbt());
|
||||
}
|
||||
|
||||
public function handle(PacketHandlerInterface $handler) : bool{
|
||||
|
@@ -90,7 +90,7 @@ final class ChunkSerializer{
|
||||
$stream = new BinaryStream();
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
if($tile instanceof Spawnable){
|
||||
$stream->put($tile->getSerializedSpawnCompound());
|
||||
$stream->put($tile->getSerializedSpawnCompound()->getEncodedNbt());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user