From 9478bc281f21675e0cc9a4631a9ce88b7029f9ef Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 11 Feb 2018 16:44:04 +0000 Subject: [PATCH] Human: Save skin data as TAG_ByteArray instead of TAG_String TAG_String has a UTF-8 payload, which makes it more expensive to work with. Also, skins can contain bytes which are not valid UTF-8 characters and will therefore be treated as corrupted by external tools. Additionally a TAG_String can only hold 32767 bytes, which might become a problem in the future. A TAG_ByteArray can hold up to 2GB of data, and there is no character encoding restrictions on it. --- src/pocketmine/entity/Human.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 7c2a67688..6d46914c5 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -36,6 +36,7 @@ use pocketmine\item\FoodSource; use pocketmine\item\Item as ItemItem; use pocketmine\level\Level; use pocketmine\nbt\NBT; +use pocketmine\nbt\tag\ByteArrayTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; @@ -485,7 +486,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($skin !== null){ $this->setSkin(new Skin( $skin->getString("Name"), - $skin->getString("Data") + $skin->hasTag("Data", StringTag::class) ? $skin->getString("Data") : $skin->getByteArray("Data") //old data (this used to be saved as a StringTag in older versions of PM) )); } @@ -673,7 +674,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($this->skin !== null){ $this->namedtag->setTag(new CompoundTag("Skin", [ //TODO: save cape & geometry - new StringTag("Data", $this->skin->getSkinData()), + new ByteArrayTag("Data", $this->skin->getSkinData()), new StringTag("Name", $this->skin->getSkinId()) ])); }