Block: get rid of getRuntimeId()

the runtime ID mapping should be non-global in case of multiple protocols.
This commit is contained in:
Dylan K. Taylor 2020-07-06 11:18:29 +01:00
parent ad99dc5884
commit 909f3f39de
10 changed files with 18 additions and 17 deletions

View File

@ -38,7 +38,6 @@ use pocketmine\math\Facing;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\world\BlockTransaction; use pocketmine\world\BlockTransaction;
use pocketmine\world\Position; use pocketmine\world\Position;
@ -105,13 +104,6 @@ class Block{
return ItemFactory::getInstance()->get($this->idInfo->getItemId(), $this->idInfo->getVariant()); return ItemFactory::getInstance()->get($this->idInfo->getItemId(), $this->idInfo->getVariant());
} }
/**
* @internal
*/
public function getRuntimeId() : int{
return RuntimeBlockMapping::getInstance()->toRuntimeId($this->getId(), $this->getMeta());
}
public function getMeta() : int{ public function getMeta() : int{
$stateMeta = $this->writeStateToMeta(); $stateMeta = $this->writeStateToMeta();
assert(($stateMeta & ~$this->getStateBitmask()) === 0); assert(($stateMeta & ~$this->getStateBitmask()) === 0);

View File

@ -34,6 +34,7 @@ use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
@ -146,7 +147,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, $this->block->getRuntimeId()); $properties->setInt(EntityMetadataProperties::VARIANT, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()));
} }
public function getOffsetPosition(Vector3 $vector3) : Vector3{ public function getOffsetPosition(Vector3 $vector3) : Vector3{

View File

@ -52,6 +52,7 @@ use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser; use pocketmine\item\LegacyStringToItemParser;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\BlockActorDataPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
@ -829,7 +830,7 @@ class World implements ChunkManager{
} }
$fullBlock = $this->getBlockAt($b->x, $b->y, $b->z); $fullBlock = $this->getBlockAt($b->x, $b->y, $b->z);
$packets[] = UpdateBlockPacket::create($b->x, $b->y, $b->z, $fullBlock->getRuntimeId()); $packets[] = UpdateBlockPacket::create($b->x, $b->y, $b->z, RuntimeBlockMapping::getInstance()->toRuntimeId($fullBlock->getId(), $fullBlock->getMeta()));
$tile = $this->getTileAt($b->x, $b->y, $b->z); $tile = $this->getTileAt($b->x, $b->y, $b->z);
if($tile instanceof Spawnable){ if($tile instanceof Spawnable){

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
/** /**
@ -43,6 +44,6 @@ class BlockPunchParticle implements Particle{
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos){
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $this->block->getRuntimeId() | ($this->face << 24), $pos); return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()) | ($this->face << 24), $pos);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DestroyBlockParticle implements Particle{ class DestroyBlockParticle implements Particle{
@ -37,6 +38,6 @@ class DestroyBlockParticle implements Particle{
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos){
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, $this->block->getRuntimeId(), $pos); return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()), $pos);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\particle;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds; use pocketmine\network\mcpe\protocol\types\ParticleIds;
@ -37,6 +38,6 @@ class TerrainParticle implements Particle{
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos){
return LevelEventPacket::standardParticle(ParticleIds::TERRAIN, $this->block->getRuntimeId(), $pos); return LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()), $pos);
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
class BlockBreakSound implements Sound{ class BlockBreakSound implements Sound{
@ -37,6 +38,6 @@ class BlockBreakSound implements Sound{
} }
public function encode(?Vector3 $pos){ public function encode(?Vector3 $pos){
return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BREAK, $pos, $this->block->getRuntimeId()); return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BREAK, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()));
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
class BlockPlaceSound implements Sound{ class BlockPlaceSound implements Sound{
@ -37,6 +38,6 @@ class BlockPlaceSound implements Sound{
} }
public function encode(?Vector3 $pos){ public function encode(?Vector3 $pos){
return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_PLACE, $pos, $this->block->getRuntimeId()); return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_PLACE, $pos, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta()));
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
/** /**
@ -43,7 +44,7 @@ class BlockPunchSound implements Sound{
return LevelSoundEventPacket::create( return LevelSoundEventPacket::create(
LevelSoundEventPacket::SOUND_HIT, LevelSoundEventPacket::SOUND_HIT,
$pos, $pos,
$this->block->getRuntimeId() RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getId(), $this->block->getMeta())
); );
} }
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\world\sound;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
/** /**
@ -47,7 +48,7 @@ class EntityLandSound implements Sound{
return LevelSoundEventPacket::create( return LevelSoundEventPacket::create(
LevelSoundEventPacket::SOUND_LAND, LevelSoundEventPacket::SOUND_LAND,
$pos, $pos,
$this->blockLandedOn->getRuntimeId(), RuntimeBlockMapping::getInstance()->toRuntimeId($this->blockLandedOn->getId(), $this->blockLandedOn->getMeta()),
$this->entity::getNetworkTypeId() $this->entity::getNetworkTypeId()
//TODO: does isBaby have any relevance here? //TODO: does isBaby have any relevance here?
); );