BlockTranslator: use less ambiguous function names

This commit is contained in:
Dylan K. Taylor 2023-05-05 14:47:23 +01:00
parent 4f32f5e0b7
commit 289ede669d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
15 changed files with 19 additions and 19 deletions

View File

@ -95,7 +95,7 @@ class FlowerPot extends Spawnable{
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
if($this->plant !== null){ if($this->plant !== null){
$nbt->setTag(self::TAG_PLANT_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->toStateData($this->plant->getStateId())->toNbt()); $nbt->setTag(self::TAG_PLANT_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkStateData($this->plant->getStateId())->toNbt());
} }
} }

View File

@ -197,7 +197,7 @@ class FallingBlock extends Entity{
protected function syncNetworkData(EntityMetadataCollection $properties) : void{ protected function syncNetworkData(EntityMetadataCollection $properties) : void{
parent::syncNetworkData($properties); parent::syncNetworkData($properties);
$properties->setInt(EntityMetadataProperties::VARIANT, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId())); $properties->setInt(EntityMetadataProperties::VARIANT, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()));
} }
public function getOffsetPosition(Vector3 $vector3) : Vector3{ public function getOffsetPosition(Vector3 $vector3) : Vector3{

View File

@ -54,7 +54,7 @@ final class BlockTranslator{
$this->fallbackStateData = $this->blockStateDictionary->generateDataFromStateId($this->fallbackStateId) ?? throw new AssumptionFailedError("We just looked up this state data, so it must exist"); $this->fallbackStateData = $this->blockStateDictionary->generateDataFromStateId($this->fallbackStateId) ?? throw new AssumptionFailedError("We just looked up this state data, so it must exist");
} }
public function toRuntimeId(int $internalStateId) : int{ public function internalIdToNetworkId(int $internalStateId) : int{
if(isset($this->networkIdCache[$internalStateId])){ if(isset($this->networkIdCache[$internalStateId])){
return $this->networkIdCache[$internalStateId]; return $this->networkIdCache[$internalStateId];
} }
@ -78,11 +78,11 @@ final class BlockTranslator{
/** /**
* Looks up the network state data associated with the given internal state ID. * Looks up the network state data associated with the given internal state ID.
*/ */
public function toStateData(int $internalStateId) : BlockStateData{ public function internalIdToNetworkStateData(int $internalStateId) : BlockStateData{
//we don't directly use the blockstate serializer here - we can't assume that the network blockstate NBT is the //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 //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). //case someone wants to implement multi version).
$networkRuntimeId = $this->toRuntimeId($internalStateId); $networkRuntimeId = $this->internalIdToNetworkId($internalStateId);
return $this->blockStateDictionary->generateDataFromStateId($networkRuntimeId) ?? throw new AssumptionFailedError("We just looked up this state ID, so it must exist"); return $this->blockStateDictionary->generateDataFromStateId($networkRuntimeId) ?? throw new AssumptionFailedError("We just looked up this state ID, so it must exist");
} }

View File

@ -109,7 +109,7 @@ final class ChunkSerializer{
$nbtSerializer = new NetworkNbtSerializer(); $nbtSerializer = new NetworkNbtSerializer();
foreach($palette as $p){ foreach($palette as $p){
//TODO: introduce a binary cache for this //TODO: introduce a binary cache for this
$state = $blockStateDictionary->generateDataFromStateId($blockTranslator->toRuntimeId($p)); $state = $blockStateDictionary->generateDataFromStateId($blockTranslator->internalIdToNetworkId($p));
if($state === null){ if($state === null){
$state = $blockTranslator->getFallbackStateData(); $state = $blockTranslator->getFallbackStateData();
} }
@ -118,7 +118,7 @@ final class ChunkSerializer{
} }
}else{ }else{
foreach($palette as $p){ foreach($palette as $p){
$stream->put(Binary::writeUnsignedVarInt($blockTranslator->toRuntimeId($p) << 1)); $stream->put(Binary::writeUnsignedVarInt($blockTranslator->internalIdToNetworkId($p) << 1));
} }
} }
} }

View File

@ -1074,7 +1074,7 @@ class World implements ChunkManager{
$tile = $this->getTileAt($b->x, $b->y, $b->z); $tile = $this->getTileAt($b->x, $b->y, $b->z);
if($tile instanceof Spawnable && count($fakeStateProperties = $tile->getRenderUpdateBugWorkaroundStateProperties($fullBlock)) > 0){ if($tile instanceof Spawnable && count($fakeStateProperties = $tile->getRenderUpdateBugWorkaroundStateProperties($fullBlock)) > 0){
$originalStateData = $blockTranslator->toStateData($fullBlock->getStateId()); $originalStateData = $blockTranslator->internalIdToNetworkStateData($fullBlock->getStateId());
$fakeStateData = new BlockStateData( $fakeStateData = new BlockStateData(
$originalStateData->getName(), $originalStateData->getName(),
array_merge($originalStateData->getStates(), $fakeStateProperties), array_merge($originalStateData->getStates(), $fakeStateProperties),
@ -1089,7 +1089,7 @@ class World implements ChunkManager{
} }
$packets[] = UpdateBlockPacket::create( $packets[] = UpdateBlockPacket::create(
$blockPosition, $blockPosition,
$blockTranslator->toRuntimeId($fullBlock->getStateId()), $blockTranslator->internalIdToNetworkId($fullBlock->getStateId()),
UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::FLAG_NETWORK,
UpdateBlockPacket::DATA_LAYER_NORMAL UpdateBlockPacket::DATA_LAYER_NORMAL
); );

View File

@ -34,6 +34,6 @@ class BlockBreakParticle implements Particle{
public function __construct(private Block $b){} public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{ public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->b->getStateId()), $pos)]; return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->b->getStateId()), $pos)];
} }
} }

View File

@ -39,6 +39,6 @@ class BlockPunchParticle implements Particle{
){} ){}
public function encode(Vector3 $pos) : array{ public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()) | ($this->face << 24), $pos)]; return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()) | ($this->face << 24), $pos)];
} }
} }

View File

@ -95,7 +95,7 @@ class FloatingTextParticle implements Particle{
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0), EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0), EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($name), EntityMetadataProperties::NAMETAG => new StringMetadataProperty($name),
EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId(VanillaBlocks::AIR()->getStateId())), EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId(VanillaBlocks::AIR()->getStateId())),
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1), EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
]; ];
$p[] = AddActorPacket::create( $p[] = AddActorPacket::create(

View File

@ -33,6 +33,6 @@ class TerrainParticle implements Particle{
public function __construct(private Block $b){} public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{ public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->b->getStateId()), $pos)]; return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->b->getStateId()), $pos)];
} }
} }

View File

@ -33,6 +33,6 @@ class BlockBreakSound implements Sound{
public function __construct(private Block $block){} public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{ public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()))]; return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()))];
} }
} }

View File

@ -33,6 +33,6 @@ class BlockPlaceSound implements Sound{
public function __construct(private Block $block){} public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{ public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()))]; return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()))];
} }
} }

View File

@ -40,7 +40,7 @@ class BlockPunchSound implements Sound{
LevelSoundEvent::HIT, LevelSoundEvent::HIT,
$pos, $pos,
false, false,
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()) TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId())
)]; )];
} }
} }

View File

@ -43,7 +43,7 @@ class EntityLandSound implements Sound{
return [LevelSoundEventPacket::create( return [LevelSoundEventPacket::create(
LevelSoundEvent::LAND, LevelSoundEvent::LAND,
$pos, $pos,
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->blockLandedOn->getStateId()), TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->blockLandedOn->getStateId()),
$this->entity::getNetworkTypeId(), $this->entity::getNetworkTypeId(),
false, //TODO: does isBaby have any relevance here? false, //TODO: does isBaby have any relevance here?
false false

View File

@ -42,7 +42,7 @@ final class ItemUseOnBlockSound implements Sound{
LevelSoundEvent::ITEM_USE_ON, LevelSoundEvent::ITEM_USE_ON,
$pos, $pos,
false, false,
TypeConverter::getInstance()->getBlockTranslator()->toRuntimeId($this->block->getStateId()) TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId())
)]; )];
} }
} }

View File

@ -34,7 +34,7 @@ class BlockTranslatorTest extends TestCase{
public function testAllBlockStatesSerialize() : void{ public function testAllBlockStatesSerialize() : void{
$blockTranslator = TypeConverter::getInstance()->getBlockTranslator(); $blockTranslator = TypeConverter::getInstance()->getBlockTranslator();
foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){
$blockTranslator->toRuntimeId($state->getStateId()); $blockTranslator->internalIdToNetworkId($state->getStateId());
} }
} }
} }