mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 20:14:31 +00:00
Avoid bogus assumptions about block and item NBT on tiles
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
@@ -94,6 +94,18 @@ final class RuntimeBlockMapping{
|
||||
return $this->networkIdCache[$internalStateId] = $networkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the network state data associated with the given internal state ID.
|
||||
*/
|
||||
public function toStateData(int $internalStateId) : BlockStateData{
|
||||
//we don't directly use the blockstate serializer here - we can't assume that the network blockstate NBT is the
|
||||
//same as the disk blockstate NBT, in case we decide to have different world version than network version (or in
|
||||
//case someone wants to implement multi version).
|
||||
$networkRuntimeId = $this->toRuntimeId($internalStateId);
|
||||
|
||||
return $this->blockStateDictionary->getDataFromStateId($networkRuntimeId) ?? throw new AssumptionFailedError("We just looked up this state ID, so it must exist");
|
||||
}
|
||||
|
||||
public function getBlockStateDictionary() : BlockStateDictionary{ return $this->blockStateDictionary; }
|
||||
|
||||
public function getFallbackStateData() : BlockStateData{ return $this->fallbackStateData; }
|
||||
|
Reference in New Issue
Block a user