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
26 changed files with 88 additions and 130 deletions

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())
)];
}
}