Avoid bogus assumptions about block and item NBT on tiles

This commit is contained in:
Dylan K. Taylor
2022-07-17 21:23:41 +01:00
parent 4f2f9b4352
commit 012b668537
6 changed files with 31 additions and 4 deletions

View File

@ -28,6 +28,7 @@ use pocketmine\data\bedrock\item\ItemSerializer;
use pocketmine\data\bedrock\item\ItemTypeDeserializeException;
use pocketmine\data\bedrock\item\ItemTypeSerializeException;
use pocketmine\data\bedrock\item\SavedItemData;
use pocketmine\data\bedrock\item\SavedItemStackData;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
use pocketmine\utils\AssumptionFailedError;
@ -96,6 +97,16 @@ final class ItemTranslator{
return [$numericId, $itemData->getMeta(), $blockRuntimeId];
}
/**
* @throws ItemTypeSerializeException
*/
public function toNetworkNbt(Item $item) : SavedItemStackData{
//TODO: this relies on the assumption that network item NBT is the same as disk item NBT, which may not always
//be true - if we stick on an older world version while updating network version, this could be a problem (and
//may be a problem for multi version implementations)
return $this->itemSerializer->serializeStack($item);
}
/**
* @throws TypeConversionException
*/