From 5661d0496f37d0565a0aa2861843faaa5e93d669 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 20 Sep 2020 12:16:11 +0100 Subject: [PATCH] RuntimeBlockMapping::toRuntimeId() now accepts a single integer instead of id/meta the expectation is that eventually this will receive arbitrary internal runtime IDs instead of static id/meta, and RuntimeBlockMapping doesn't really care about this crap anyway. --- src/entity/object/FallingBlock.php | 2 +- src/network/mcpe/convert/RuntimeBlockMapping.php | 16 +++++----------- src/network/mcpe/serializer/ChunkSerializer.php | 2 +- src/world/World.php | 2 +- src/world/particle/BlockPunchParticle.php | 2 +- src/world/particle/DestroyBlockParticle.php | 2 +- src/world/particle/TerrainParticle.php | 2 +- src/world/sound/BlockBreakSound.php | 2 +- src/world/sound/BlockPlaceSound.php | 2 +- src/world/sound/BlockPunchSound.php | 2 +- src/world/sound/EntityLandSound.php | 2 +- 11 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index cfca869ea..784123353 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -147,7 +147,7 @@ class FallingBlock extends Entity{ protected function syncNetworkData(EntityMetadataCollection $properties) : void{ parent::syncNetworkData($properties); - $properties->setInt(EntityMetadataProperties::VARIANT, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta())); + $properties->setInt(EntityMetadataProperties::VARIANT, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId())); } public function getOffsetPosition(Vector3 $vector3) : Vector3{ diff --git a/src/network/mcpe/convert/RuntimeBlockMapping.php b/src/network/mcpe/convert/RuntimeBlockMapping.php index 805d6bb79..3f17ebd1e 100644 --- a/src/network/mcpe/convert/RuntimeBlockMapping.php +++ b/src/network/mcpe/convert/RuntimeBlockMapping.php @@ -135,21 +135,15 @@ final class RuntimeBlockMapping{ return $table; } - public function toRuntimeId(int $id, int $meta = 0) : int{ - /* - * try id+meta first - * if not found, try id+0 (strip meta) - * if still not found, return update! block - */ - return $this->legacyToRuntimeMap[($id << 4) | $meta] ?? $this->legacyToRuntimeMap[$id << 4] ?? $this->legacyToRuntimeMap[BlockLegacyIds::INFO_UPDATE << 4]; + public function toRuntimeId(int $internalStateId) : int{ + return $this->legacyToRuntimeMap[$internalStateId] ?? $this->legacyToRuntimeMap[BlockLegacyIds::INFO_UPDATE << 4]; } /** - * @return int[] [id, meta] + * @return int */ - public function fromRuntimeId(int $runtimeId) : array{ - $v = $this->runtimeToLegacyMap[$runtimeId]; - return [$v >> 4, $v & 0xf]; + public function fromRuntimeId(int $runtimeId) : int{ + return $this->runtimeToLegacyMap[$runtimeId]; } private function registerMapping(int $staticRuntimeId, int $legacyId, int $legacyMeta) : void{ diff --git a/src/network/mcpe/serializer/ChunkSerializer.php b/src/network/mcpe/serializer/ChunkSerializer.php index 4b730757e..abf0e1b25 100644 --- a/src/network/mcpe/serializer/ChunkSerializer.php +++ b/src/network/mcpe/serializer/ChunkSerializer.php @@ -71,7 +71,7 @@ final class ChunkSerializer{ //zigzag and just shift directly. $stream->putUnsignedVarInt(count($palette) << 1); //yes, this is intentionally zigzag foreach($palette as $p){ - $stream->put(Binary::writeUnsignedVarInt($blockMapper->toRuntimeId($p >> 4, $p & 0xf) << 1)); + $stream->put(Binary::writeUnsignedVarInt($blockMapper->toRuntimeId($p) << 1)); } } } diff --git a/src/world/World.php b/src/world/World.php index a457f5cb6..95de642d9 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -829,7 +829,7 @@ class World implements ChunkManager{ } $fullBlock = $this->getBlockAt($b->x, $b->y, $b->z); - $packets[] = UpdateBlockPacket::create($b->x, $b->y, $b->z, RuntimeBlockMapping::getInstance()->toRuntimeId($fullBlock->getId(), $fullBlock->getMeta())); + $packets[] = UpdateBlockPacket::create($b->x, $b->y, $b->z, RuntimeBlockMapping::getInstance()->toRuntimeId($fullBlock->getFullId())); $tile = $this->getTileAt($b->x, $b->y, $b->z); if($tile instanceof Spawnable){ diff --git a/src/world/particle/BlockPunchParticle.php b/src/world/particle/BlockPunchParticle.php index a932099a6..be99c9452 100644 --- a/src/world/particle/BlockPunchParticle.php +++ b/src/world/particle/BlockPunchParticle.php @@ -44,6 +44,6 @@ class BlockPunchParticle implements Particle{ } public function encode(Vector3 $pos){ - return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()) | ($this->face << 24), $pos); + return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) | ($this->face << 24), $pos); } } diff --git a/src/world/particle/DestroyBlockParticle.php b/src/world/particle/DestroyBlockParticle.php index 0d4d96274..d43b84850 100644 --- a/src/world/particle/DestroyBlockParticle.php +++ b/src/world/particle/DestroyBlockParticle.php @@ -38,6 +38,6 @@ class DestroyBlockParticle implements Particle{ } public function encode(Vector3 $pos){ - return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()), $pos); + return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos); } } diff --git a/src/world/particle/TerrainParticle.php b/src/world/particle/TerrainParticle.php index e96ad680b..4b9f07c66 100644 --- a/src/world/particle/TerrainParticle.php +++ b/src/world/particle/TerrainParticle.php @@ -38,6 +38,6 @@ class TerrainParticle implements Particle{ } public function encode(Vector3 $pos){ - return LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()), $pos); + return LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos); } } diff --git a/src/world/sound/BlockBreakSound.php b/src/world/sound/BlockBreakSound.php index 4d5e6a76e..81809e126 100644 --- a/src/world/sound/BlockBreakSound.php +++ b/src/world/sound/BlockBreakSound.php @@ -38,6 +38,6 @@ class BlockBreakSound implements Sound{ } public function encode(?Vector3 $pos){ - return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BREAK, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta())); + return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BREAK, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId())); } } diff --git a/src/world/sound/BlockPlaceSound.php b/src/world/sound/BlockPlaceSound.php index d6d9eef29..9441e5bc9 100644 --- a/src/world/sound/BlockPlaceSound.php +++ b/src/world/sound/BlockPlaceSound.php @@ -38,6 +38,6 @@ class BlockPlaceSound implements Sound{ } public function encode(?Vector3 $pos){ - return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_PLACE, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta())); + return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_PLACE, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId())); } } diff --git a/src/world/sound/BlockPunchSound.php b/src/world/sound/BlockPunchSound.php index ef9930285..33a15cce5 100644 --- a/src/world/sound/BlockPunchSound.php +++ b/src/world/sound/BlockPunchSound.php @@ -44,7 +44,7 @@ class BlockPunchSound implements Sound{ return LevelSoundEventPacket::create( LevelSoundEventPacket::SOUND_HIT, $pos, - RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()) + RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) ); } } diff --git a/src/world/sound/EntityLandSound.php b/src/world/sound/EntityLandSound.php index 53b2d033b..47e9736ab 100644 --- a/src/world/sound/EntityLandSound.php +++ b/src/world/sound/EntityLandSound.php @@ -48,7 +48,7 @@ class EntityLandSound implements Sound{ return LevelSoundEventPacket::create( LevelSoundEventPacket::SOUND_LAND, $pos, - RuntimeBlockMapping::getInstance()->toRuntimeId($this->blockLandedOn->getId(), $this->blockLandedOn->getMeta()), + RuntimeBlockMapping::getInstance()->toRuntimeId($this->blockLandedOn->getFullId()), $this->entity::getNetworkTypeId() //TODO: does isBaby have any relevance here? );