mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 13:35:29 +00:00
ItemTranslator: Accept dynamic BlockStateDictionary instead of using singleton
this will be needed for handling protocol updates in the future
This commit is contained in:
parent
c89f7f8e5e
commit
860fa719b2
@ -41,11 +41,17 @@ final class ItemTranslator{
|
||||
use SingletonTrait;
|
||||
|
||||
private static function make() : self{
|
||||
return new self(GlobalItemTypeDictionary::getInstance()->getDictionary(), new ItemSerializer(), new ItemDeserializer());
|
||||
return new self(
|
||||
GlobalItemTypeDictionary::getInstance()->getDictionary(),
|
||||
RuntimeBlockMapping::getInstance()->getBlockStateDictionary(),
|
||||
new ItemSerializer(),
|
||||
new ItemDeserializer()
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
private ItemTypeDictionary $dictionary,
|
||||
private ItemTypeDictionary $itemTypeDictionary,
|
||||
private BlockStateDictionary $blockStateDictionary,
|
||||
private ItemSerializer $itemSerializer,
|
||||
private ItemDeserializer $itemDeserializer
|
||||
){}
|
||||
@ -73,11 +79,11 @@ final class ItemTranslator{
|
||||
|
||||
$itemData = $this->itemSerializer->serialize($item);
|
||||
|
||||
$numericId = $this->dictionary->fromStringId($itemData->getName());
|
||||
$numericId = $this->itemTypeDictionary->fromStringId($itemData->getName());
|
||||
$blockStateData = $itemData->getBlock();
|
||||
|
||||
if($blockStateData !== null){
|
||||
$blockRuntimeId = RuntimeBlockMapping::getInstance()->getBlockStateDictionary()->lookupStateIdFromData($blockStateData);
|
||||
$blockRuntimeId = $this->blockStateDictionary->lookupStateIdFromData($blockStateData);
|
||||
if($blockRuntimeId === null){
|
||||
throw new AssumptionFailedError("Unmapped blockstate returned by blockstate serializer: " . $blockStateData->toNbt());
|
||||
}
|
||||
@ -92,10 +98,10 @@ final class ItemTranslator{
|
||||
* @throws TypeConversionException
|
||||
*/
|
||||
public function fromNetworkId(int $networkId, int $networkMeta, int $networkBlockRuntimeId) : Item{
|
||||
$stringId = $this->dictionary->fromIntId($networkId);
|
||||
$stringId = $this->itemTypeDictionary->fromIntId($networkId);
|
||||
|
||||
$blockStateData = $networkBlockRuntimeId !== self::NO_BLOCK_RUNTIME_ID ?
|
||||
RuntimeBlockMapping::getInstance()->getBlockStateDictionary()->getDataFromStateId($networkBlockRuntimeId) :
|
||||
$this->blockStateDictionary->getDataFromStateId($networkBlockRuntimeId) :
|
||||
null;
|
||||
|
||||
return $this->itemDeserializer->deserialize(new SavedItemData($stringId, $networkMeta, $blockStateData));
|
||||
|
Loading…
x
Reference in New Issue
Block a user