Centralize all conversion-related stuff under TypeConverter

instead of having singletons for everything, which are a nightmare to manage for multi version
This commit is contained in:
Dylan K. Taylor 2023-05-03 16:33:17 +01:00
parent 5e462db0f8
commit 01f340985a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
26 changed files with 88 additions and 130 deletions

View File

@ -53,7 +53,7 @@ use pocketmine\network\mcpe\compression\CompressBatchPromise;
use pocketmine\network\mcpe\compression\CompressBatchTask;
use pocketmine\network\mcpe\compression\Compressor;
use pocketmine\network\mcpe\compression\ZlibCompressor;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\encryption\EncryptionContext;
use pocketmine\network\mcpe\EntityEventBroadcaster;
use pocketmine\network\mcpe\NetworkSession;
@ -1204,7 +1204,7 @@ class Server{
private function startupPrepareNetworkInterfaces() : bool{
$useQuery = $this->configGroup->getConfigBool("enable-query", true);
$packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$packetSerializerContext = new PacketSerializerContext(TypeConverter::getInstance()->getItemTypeDictionary());
$packetBroadcaster = new StandardPacketBroadcaster($this, $packetSerializerContext);
$entityEventBroadcaster = new StandardEntityEventBroadcaster($packetBroadcaster);

View File

@ -33,7 +33,7 @@ use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\world\format\io\GlobalBlockStateHandlers;
/**
@ -95,7 +95,7 @@ class FlowerPot extends Spawnable{
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
if($this->plant !== null){
$nbt->setTag(self::TAG_PLANT_BLOCK, RuntimeBlockMapping::getInstance()->toStateData($this->plant->getStateId())->toNbt());
$nbt->setTag(self::TAG_PLANT_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->toStateData($this->plant->getStateId())->toNbt());
}
}

View File

@ -27,7 +27,7 @@ use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\world\World;
/**
@ -100,7 +100,7 @@ class ItemFrame extends Spawnable{
$nbt->setFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance);
$nbt->setByte(self::TAG_ITEM_ROTATION, $this->itemRotation);
if(!$this->item->isNull()){
$nbt->setTag(self::TAG_ITEM, ItemTranslator::getInstance()->toNetworkNbt($this->item));
$nbt->setTag(self::TAG_ITEM, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->item));
}
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\block\tile;
use pocketmine\item\Item;
use pocketmine\item\Record;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\TypeConverter;
class Jukebox extends Spawnable{
private const TAG_RECORD = "RecordItem"; //Item CompoundTag
@ -59,7 +59,7 @@ class Jukebox extends Spawnable{
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
//this is needed for the note particles to show on the client side
if($this->record !== null){
$nbt->setTag(self::TAG_RECORD, ItemTranslator::getInstance()->toNetworkNbt($this->record));
$nbt->setTag(self::TAG_RECORD, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->record));
}
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\block\tile;
use pocketmine\item\Item;
use pocketmine\item\WritableBookBase;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\TypeConverter;
use function count;
/**
@ -81,7 +81,7 @@ class Lectern extends Spawnable{
$nbt->setByte(self::TAG_HAS_BOOK, $this->book !== null ? 1 : 0);
$nbt->setInt(self::TAG_PAGE, $this->viewedPage);
if($this->book !== null){
$nbt->setTag(self::TAG_BOOK, ItemTranslator::getInstance()->toNetworkNbt($this->book));
$nbt->setTag(self::TAG_BOOK, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->book));
$nbt->setInt(self::TAG_TOTAL_PAGES, count($this->book->getPages()));
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\entity\animation;
use pocketmine\entity\Human;
use pocketmine\item\Item;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\ActorEventPacket;
use pocketmine\network\mcpe\protocol\types\ActorEvent;
@ -37,7 +37,7 @@ final class ConsumingItemAnimation implements Animation{
){}
public function encode() : array{
[$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($this->item);
[$netId, $netData] = TypeConverter::getInstance()->getItemTranslator()->toNetworkId($this->item);
return [
//TODO: need to check the data values
ActorEventPacket::create($this->human->getId(), ActorEvent::EATING_ITEM, ($netId << 16) | $netData)

View File

@ -39,7 +39,7 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
@ -197,7 +197,7 @@ class FallingBlock extends Entity{
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
parent::syncNetworkData($properties);
$properties->setInt(EntityMetadataProperties::VARIANT, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId()));
$properties->setInt(EntityMetadataProperties::VARIANT, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()));
}
public function getOffsetPosition(Vector3 $vector3) : Vector3{

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\mcpe;
use pocketmine\network\mcpe\compression\CompressBatchPromise;
use pocketmine\network\mcpe\compression\Compressor;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelChunkPacket;
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
@ -67,8 +66,9 @@ class ChunkRequestTask extends AsyncTask{
public function onRun() : void{
$chunk = FastChunkSerializer::deserializeTerrain($this->chunk);
$subCount = ChunkSerializer::getSubChunkCount($chunk);
$encoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$payload = ChunkSerializer::serializeFullChunk($chunk, RuntimeBlockMapping::getInstance(), $encoderContext, $this->tiles);
$converter = TypeConverter::getInstance();
$encoderContext = new PacketSerializerContext($converter->getItemTypeDictionary());
$payload = ChunkSerializer::serializeFullChunk($chunk, $converter->getBlockTranslator(), $encoderContext, $this->tiles);
$stream = new BinaryStream();
PacketBatch::encodePackets($stream, $encoderContext, [LevelChunkPacket::create(new ChunkPosition($this->chunkX, $this->chunkZ), $subCount, false, null, $payload)]);

View File

@ -30,7 +30,6 @@ use pocketmine\crafting\ShapedRecipe;
use pocketmine\crafting\ShapelessRecipe;
use pocketmine\crafting\ShapelessRecipeType;
use pocketmine\item\Item;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
@ -173,7 +172,7 @@ final class CraftingDataCache{
}
$potionContainerChangeRecipes = [];
$itemTypeDictionary = GlobalItemTypeDictionary::getInstance()->getDictionary();
$itemTypeDictionary = TypeConverter::getInstance()->getItemTypeDictionary();
foreach($manager->getPotionContainerChangeRecipes() as $recipe){
$input = $itemTypeDictionary->fromStringId($recipe->getInputItemId());
$ingredient = $converter->coreRecipeIngredientToNet($recipe->getIngredient())->getDescriptor();

View File

@ -1,45 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\convert;
use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
use pocketmine\utils\Filesystem;
use pocketmine\utils\SingletonTrait;
final class GlobalItemTypeDictionary{
use SingletonTrait;
private static function make() : self{
$data = Filesystem::fileGetContents(BedrockDataFiles::REQUIRED_ITEM_LIST_JSON);
$dictionary = ItemTypeDictionaryFromDataHelper::loadFromString($data);
return new self($dictionary);
}
public function __construct(
private ItemTypeDictionary $dictionary
){}
public function getDictionary() : ItemTypeDictionary{ return $this->dictionary; }
}

View File

@ -32,8 +32,6 @@ use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\SingletonTrait;
use pocketmine\world\format\io\GlobalItemDataHandlers;
/**
* This class handles translation between network item ID+metadata to PocketMine-MP internal ID+metadata and vice versa.
@ -41,17 +39,6 @@ use pocketmine\world\format\io\GlobalItemDataHandlers;
final class ItemTranslator{
public const NO_BLOCK_RUNTIME_ID = 0;
use SingletonTrait;
private static function make() : self{
return new self(
GlobalItemTypeDictionary::getInstance()->getDictionary(),
RuntimeBlockMapping::getInstance()->getBlockStateDictionary(),
GlobalItemDataHandlers::getSerializer(),
GlobalItemDataHandlers::getDeserializer()
);
}
public function __construct(
private ItemTypeDictionary $itemTypeDictionary,
private BlockStateDictionary $blockStateDictionary,

View File

@ -23,22 +23,16 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\convert;
use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\data\bedrock\block\BlockStateData;
use pocketmine\data\bedrock\block\BlockStateSerializeException;
use pocketmine\data\bedrock\block\BlockStateSerializer;
use pocketmine\data\bedrock\block\BlockTypeNames;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Filesystem;
use pocketmine\utils\SingletonTrait;
use pocketmine\world\format\io\GlobalBlockStateHandlers;
/**
* @internal
*/
final class RuntimeBlockMapping{
use SingletonTrait;
/**
* @var int[]
* @phpstan-var array<int, int>
@ -49,15 +43,6 @@ final class RuntimeBlockMapping{
private BlockStateData $fallbackStateData;
private int $fallbackStateId;
private static function make() : self{
$canonicalBlockStatesRaw = Filesystem::fileGetContents(BedrockDataFiles::CANONICAL_BLOCK_STATES_NBT);
$metaMappingRaw = Filesystem::fileGetContents(BedrockDataFiles::BLOCK_STATE_META_MAP_JSON);
return new self(
BlockStateDictionary::loadFromString($canonicalBlockStatesRaw, $metaMappingRaw),
GlobalBlockStateHandlers::getSerializer()
);
}
public function __construct(
private BlockStateDictionary $blockStateDictionary,
private BlockStateSerializer $blockStateSerializer

View File

@ -28,11 +28,13 @@ use pocketmine\crafting\ExactRecipeIngredient;
use pocketmine\crafting\MetaWildcardRecipeIngredient;
use pocketmine\crafting\RecipeIngredient;
use pocketmine\crafting\TagWildcardRecipeIngredient;
use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\data\bedrock\item\BlockItemIdMap;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\nbt\NbtException;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
use pocketmine\network\mcpe\protocol\types\GameMode as ProtocolGameMode;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\recipe\IntIdMetaItemDescriptor;
@ -41,7 +43,10 @@ use pocketmine\network\mcpe\protocol\types\recipe\StringIdMetaItemDescriptor;
use pocketmine\network\mcpe\protocol\types\recipe\TagItemDescriptor;
use pocketmine\player\GameMode;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Filesystem;
use pocketmine\utils\SingletonTrait;
use pocketmine\world\format\io\GlobalBlockStateHandlers;
use pocketmine\world\format\io\GlobalItemDataHandlers;
use function get_class;
use function morton2d_encode;
@ -52,13 +57,40 @@ class TypeConverter{
private const RECIPE_INPUT_WILDCARD_META = 0x7fff;
private BlockItemIdMap $blockItemIdMap;
private RuntimeBlockMapping $blockTranslator;
private ItemTranslator $itemTranslator;
private ItemTypeDictionary $itemTypeDictionary;
private int $shieldRuntimeId;
public function __construct(){
//TODO: inject stuff via constructor
$this->shieldRuntimeId = GlobalItemTypeDictionary::getInstance()->getDictionary()->fromStringId("minecraft:shield");
$this->blockItemIdMap = BlockItemIdMap::getInstance();
$canonicalBlockStatesRaw = Filesystem::fileGetContents(BedrockDataFiles::CANONICAL_BLOCK_STATES_NBT);
$metaMappingRaw = Filesystem::fileGetContents(BedrockDataFiles::BLOCK_STATE_META_MAP_JSON);
$this->blockTranslator = new RuntimeBlockMapping(
BlockStateDictionary::loadFromString($canonicalBlockStatesRaw, $metaMappingRaw),
GlobalBlockStateHandlers::getSerializer()
);
$this->itemTypeDictionary = ItemTypeDictionaryFromDataHelper::loadFromString(Filesystem::fileGetContents(BedrockDataFiles::REQUIRED_ITEM_LIST_JSON));
$this->shieldRuntimeId = $this->itemTypeDictionary->fromStringId("minecraft:shield");
$this->itemTranslator = new ItemTranslator(
$this->itemTypeDictionary,
$this->blockTranslator->getBlockStateDictionary(),
GlobalItemDataHandlers::getSerializer(),
GlobalItemDataHandlers::getDeserializer()
);
}
public function getBlockTranslator() : RuntimeBlockMapping{ return $this->blockTranslator; }
public function getItemTypeDictionary() : ItemTypeDictionary{ return $this->itemTypeDictionary; }
public function getItemTranslator() : ItemTranslator{ return $this->itemTranslator; }
/**
* Returns a client-friendly gamemode of the specified real gamemode
* This function takes care of handling gamemodes known to MCPE (as of 1.1.0.3, that includes Survival, Creative and Adventure)
@ -100,14 +132,14 @@ class TypeConverter{
return new ProtocolRecipeIngredient(null, 0);
}
if($ingredient instanceof MetaWildcardRecipeIngredient){
$id = GlobalItemTypeDictionary::getInstance()->getDictionary()->fromStringId($ingredient->getItemId());
$id = $this->itemTypeDictionary->fromStringId($ingredient->getItemId());
$meta = self::RECIPE_INPUT_WILDCARD_META;
$descriptor = new IntIdMetaItemDescriptor($id, $meta);
}elseif($ingredient instanceof ExactRecipeIngredient){
$item = $ingredient->getItem();
[$id, $meta, $blockRuntimeId] = ItemTranslator::getInstance()->toNetworkId($item);
[$id, $meta, $blockRuntimeId] = $this->itemTranslator->toNetworkId($item);
if($blockRuntimeId !== ItemTranslator::NO_BLOCK_RUNTIME_ID){
$meta = RuntimeBlockMapping::getInstance()->getBlockStateDictionary()->getMetaFromStateId($blockRuntimeId);
$meta = $this->blockTranslator->getBlockStateDictionary()->getMetaFromStateId($blockRuntimeId);
if($meta === null){
throw new AssumptionFailedError("Every block state should have an associated meta value");
}
@ -133,7 +165,7 @@ class TypeConverter{
}
if($descriptor instanceof IntIdMetaItemDescriptor){
$stringId = GlobalItemTypeDictionary::getInstance()->getDictionary()->fromIntId($descriptor->getId());
$stringId = $this->itemTypeDictionary->fromIntId($descriptor->getId());
$meta = $descriptor->getMeta();
}elseif($descriptor instanceof StringIdMetaItemDescriptor){
$stringId = $descriptor->getId();
@ -147,14 +179,14 @@ class TypeConverter{
}
$blockRuntimeId = null;
if(($blockId = BlockItemIdMap::getInstance()->lookupBlockId($stringId)) !== null){
$blockRuntimeId = RuntimeBlockMapping::getInstance()->getBlockStateDictionary()->lookupStateIdFromIdMeta($blockId, $meta);
if(($blockId = $this->blockItemIdMap->lookupBlockId($stringId)) !== null){
$blockRuntimeId = $this->blockTranslator->getBlockStateDictionary()->lookupStateIdFromIdMeta($blockId, $meta);
if($blockRuntimeId !== null){
$meta = 0;
}
}
$result = ItemTranslator::getInstance()->fromNetworkId(
GlobalItemTypeDictionary::getInstance()->getDictionary()->fromStringId($stringId),
$result = $this->itemTranslator->fromNetworkId(
$this->itemTypeDictionary->fromStringId($stringId),
$meta,
$blockRuntimeId ?? ItemTranslator::NO_BLOCK_RUNTIME_ID
);
@ -172,11 +204,11 @@ class TypeConverter{
$nbt = clone $nbt;
}
$idMeta = ItemTranslator::getInstance()->toNetworkIdQuiet($itemStack);
$idMeta = $this->itemTranslator->toNetworkIdQuiet($itemStack);
if($idMeta === null){
//Display unmapped items as INFO_UPDATE, but stick something in their NBT to make sure they don't stack with
//other unmapped items.
[$id, $meta, $blockRuntimeId] = ItemTranslator::getInstance()->toNetworkId(VanillaBlocks::INFO_UPDATE()->asItem());
[$id, $meta, $blockRuntimeId] = $this->itemTranslator->toNetworkId(VanillaBlocks::INFO_UPDATE()->asItem());
if($nbt === null){
$nbt = new CompoundTag();
}
@ -206,7 +238,7 @@ class TypeConverter{
}
$compound = $itemStack->getNbt();
$itemResult = ItemTranslator::getInstance()->fromNetworkId($itemStack->getId(), $itemStack->getMeta(), $itemStack->getBlockRuntimeId());
$itemResult = $this->itemTranslator->fromNetworkId($itemStack->getId(), $itemStack->getMeta(), $itemStack->getBlockRuntimeId());
if($compound !== null){
$compound = clone $compound;

View File

@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe\handler;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\cache\CraftingDataCache;
use pocketmine\network\mcpe\cache\StaticPacketCache;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\InventoryManager;
use pocketmine\network\mcpe\NetworkSession;
@ -108,7 +107,7 @@ class PreSpawnPacketHandler extends PacketHandler{
false,
[],
0,
GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(),
TypeConverter::getInstance()->getItemTypeDictionary()->getEntries(),
));
$this->session->getLogger()->debug("Sending actor identifiers");

View File

@ -67,7 +67,7 @@ use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\NetworkBroadcastUtils;
use pocketmine\network\mcpe\protocol\BlockActorDataPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
@ -1062,7 +1062,7 @@ class World implements ChunkManager{
public function createBlockUpdatePackets(array $blocks) : array{
$packets = [];
$blockMapping = RuntimeBlockMapping::getInstance();
$blockMapping = TypeConverter::getInstance()->getBlockTranslator();
foreach($blocks as $b){
if(!($b instanceof Vector3)){

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
@ -34,6 +34,6 @@ class BlockBreakParticle implements Particle{
public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getStateId()), $pos)];
return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->b->getStateId()), $pos)];
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
@ -39,6 +39,6 @@ class BlockPunchParticle implements Particle{
){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId()) | ($this->face << 24), $pos)];
return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()) | ($this->face << 24), $pos)];
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty;
@ -95,7 +95,7 @@ class FloatingTextParticle implements Particle{
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($name),
EntityMetadataProperties::VARIANT => new IntMetadataProperty(RuntimeBlockMapping::getInstance()->toRuntimeId(VanillaBlocks::AIR()->getStateId())),
EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId(VanillaBlocks::AIR()->getStateId())),
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
];
$p[] = AddActorPacket::create(

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\ItemTranslator;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
@ -33,7 +33,7 @@ class ItemBreakParticle implements Particle{
public function __construct(private Item $item){}
public function encode(Vector3 $pos) : array{
[$id, $meta] = ItemTranslator::getInstance()->toNetworkId($this->item);
[$id, $meta] = TypeConverter::getInstance()->getItemTranslator()->toNetworkId($this->item);
return [LevelEventPacket::standardParticle(ParticleIds::ITEM_BREAK, ($id << 16) | $meta, $pos)];
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
@ -33,6 +33,6 @@ class TerrainParticle implements Particle{
public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getStateId()), $pos)];
return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->b->getStateId()), $pos)];
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
@ -33,6 +33,6 @@ class BlockBreakSound implements Sound{
public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId()))];
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()))];
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
@ -33,6 +33,6 @@ class BlockPlaceSound implements Sound{
public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId()))];
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()))];
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
@ -40,7 +40,7 @@ class BlockPunchSound implements Sound{
LevelSoundEvent::HIT,
$pos,
false,
RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId())
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId())
)];
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
@ -43,7 +43,7 @@ class EntityLandSound implements Sound{
return [LevelSoundEventPacket::create(
LevelSoundEvent::LAND,
$pos,
RuntimeBlockMapping::getInstance()->toRuntimeId($this->blockLandedOn->getStateId()),
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->blockLandedOn->getStateId()),
$this->entity::getNetworkTypeId(),
false, //TODO: does isBaby have any relevance here?
false

View File

@ -25,7 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
@ -42,7 +42,7 @@ final class ItemUseOnBlockSound implements Sound{
LevelSoundEvent::ITEM_USE_ON,
$pos,
false,
RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getStateId())
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId())
)];
}
}

View File

@ -32,8 +32,9 @@ class RuntimeBlockMappingTest extends TestCase{
* @doesNotPerformAssertions
*/
public function testAllBlockStatesSerialize() : void{
$blockTranslator = TypeConverter::getInstance()->getBlockTranslator();
foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){
RuntimeBlockMapping::getInstance()->toRuntimeId($state->getStateId());
$blockTranslator->toRuntimeId($state->getStateId());
}
}
}