Clean up terminology around block state IDs and their handling

This commit is contained in:
Dylan K. Taylor 2023-01-25 18:53:11 +00:00
parent 2f469ef4a0
commit 0a3ecfdae9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
30 changed files with 81 additions and 78 deletions

View File

@ -97,7 +97,7 @@ class Block{
* Returns the full blockstate ID of this block. This is a compact way of representing a blockstate used to store * Returns the full blockstate ID of this block. This is a compact way of representing a blockstate used to store
* blocks in chunks at runtime. * blocks in chunks at runtime.
* *
* This ID can be used to later obtain a copy of this block using {@link BlockFactory::fromStateId()}. * This ID can be used to later obtain a copy of this block using {@link RuntimeBlockStateRegistry::fromStateId()}.
*/ */
public function getStateId() : int{ public function getStateId() : int{
return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->computeStateData(); return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->computeStateData();
@ -216,7 +216,7 @@ class Block{
*/ */
public function writeStateToWorld() : void{ public function writeStateToWorld() : void{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$world->getOrLoadChunkAtPosition($this->position)->setFullBlock($this->position->x & Chunk::COORD_MASK, $this->position->y, $this->position->z & Chunk::COORD_MASK, $this->getStateId()); $world->getOrLoadChunkAtPosition($this->position)->setBlockStateId($this->position->x & Chunk::COORD_MASK, $this->position->y, $this->position->z & Chunk::COORD_MASK, $this->getStateId());
$tileType = $this->idInfo->getTileClass(); $tileType = $this->idInfo->getTileClass();
$oldTile = $world->getTile($this->position); $oldTile = $world->getTile($this->position);

View File

@ -35,7 +35,7 @@ final class InfestedStone extends Opaque{
} }
public function getImitatedBlock() : Block{ public function getImitatedBlock() : Block{
return BlockFactory::getInstance()->fromStateId($this->imitated); return RuntimeBlockStateRegistry::getInstance()->fromStateId($this->imitated);
} }
public function getDropsForCompatibleTool(Item $item) : array{ public function getDropsForCompatibleTool(Item $item) : array{

View File

@ -32,10 +32,13 @@ use pocketmine\world\light\LightUpdate;
use function min; use function min;
/** /**
* Manages deserializing block types from their legacy blockIDs and metadata. * Blocks are stored as state IDs in chunks at runtime (it would waste far too much memory to represent every block as
* This is primarily needed for loading chunks from disk. * an object). This class maps block state IDs to their corresponding block objects when reading blocks from chunks at
* runtime.
*
* @internal Plugin devs shouldn't need to interact with this class at all, unless registering a new block type.
*/ */
class BlockFactory{ class RuntimeBlockStateRegistry{
use SingletonTrait; use SingletonTrait;
/** /**

View File

@ -25,7 +25,7 @@ namespace pocketmine\block\tile;
use pocketmine\block\Air; use pocketmine\block\Air;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\data\bedrock\block\BlockStateDeserializeException; use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\BlockStateNames; use pocketmine\data\bedrock\block\BlockStateNames;
use pocketmine\data\SavedDataLoadingException; use pocketmine\data\SavedDataLoadingException;
@ -67,7 +67,7 @@ class FlowerPot extends Spawnable{
}catch(BlockStateDeserializeException $e){ }catch(BlockStateDeserializeException $e){
throw new SavedDataLoadingException("Error deserializing plant for flower pot: " . $e->getMessage(), 0, $e); throw new SavedDataLoadingException("Error deserializing plant for flower pot: " . $e->getMessage(), 0, $e);
} }
$this->setPlant(BlockFactory::getInstance()->fromStateId($blockStateId)); $this->setPlant(RuntimeBlockStateRegistry::getInstance()->fromStateId($blockStateId));
} }
} }

View File

@ -32,7 +32,6 @@ use pocketmine\block\Bed;
use pocketmine\block\Beetroot; use pocketmine\block\Beetroot;
use pocketmine\block\Bell; use pocketmine\block\Bell;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BoneBlock; use pocketmine\block\BoneBlock;
use pocketmine\block\BrewingStand; use pocketmine\block\BrewingStand;
use pocketmine\block\BrownMushroomBlock; use pocketmine\block\BrownMushroomBlock;
@ -107,6 +106,7 @@ use pocketmine\block\RedstoneOre;
use pocketmine\block\RedstoneRepeater; use pocketmine\block\RedstoneRepeater;
use pocketmine\block\RedstoneTorch; use pocketmine\block\RedstoneTorch;
use pocketmine\block\RedstoneWire; use pocketmine\block\RedstoneWire;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\Sapling; use pocketmine\block\Sapling;
use pocketmine\block\SeaPickle; use pocketmine\block\SeaPickle;
use pocketmine\block\SimplePillar; use pocketmine\block\SimplePillar;
@ -197,7 +197,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
public function serialize(int $stateId) : BlockStateData{ public function serialize(int $stateId) : BlockStateData{
//TODO: singleton usage not ideal //TODO: singleton usage not ideal
//TODO: we may want to deduplicate cache entries to avoid wasting memory //TODO: we may want to deduplicate cache entries to avoid wasting memory
return $this->cache[$stateId] ??= $this->serializeBlock(BlockFactory::getInstance()->fromStateId($stateId)); return $this->cache[$stateId] ??= $this->serializeBlock(RuntimeBlockStateRegistry::getInstance()->fromStateId($stateId));
} }
/** /**

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\item; namespace pocketmine\data\bedrock\item;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\data\bedrock\block\BlockStateDeserializeException; use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\BlockStateDeserializer; use pocketmine\data\bedrock\block\BlockStateDeserializer;
use pocketmine\data\bedrock\block\convert\UnsupportedBlockStateException; use pocketmine\data\bedrock\block\convert\UnsupportedBlockStateException;
@ -76,7 +76,7 @@ final class ItemDeserializer{
} }
//TODO: worth caching this or not? //TODO: worth caching this or not?
return BlockFactory::getInstance()->fromStateId($block)->asItem(); return RuntimeBlockStateRegistry::getInstance()->fromStateId($block)->asItem();
} }
$id = $data->getName(); $id = $data->getName();
if(!isset($this->deserializers[$id])){ if(!isset($this->deserializers[$id])){

View File

@ -26,7 +26,7 @@ namespace pocketmine\entity;
use DaveRandom\CallbackValidator\CallbackType; use DaveRandom\CallbackValidator\CallbackType;
use DaveRandom\CallbackValidator\ParameterType; use DaveRandom\CallbackValidator\ParameterType;
use DaveRandom\CallbackValidator\ReturnType; use DaveRandom\CallbackValidator\ReturnType;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap; use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\data\bedrock\PotionTypeIdMap; use pocketmine\data\bedrock\PotionTypeIdMap;
use pocketmine\data\bedrock\PotionTypeIds; use pocketmine\data\bedrock\PotionTypeIds;
@ -112,7 +112,7 @@ final class EntityFactory{
}, ['XPOrb', 'minecraft:xp_orb']); }, ['XPOrb', 'minecraft:xp_orb']);
$this->register(FallingBlock::class, function(World $world, CompoundTag $nbt) : FallingBlock{ $this->register(FallingBlock::class, function(World $world, CompoundTag $nbt) : FallingBlock{
return new FallingBlock(Helper::parseLocation($nbt, $world), FallingBlock::parseBlockNBT(BlockFactory::getInstance(), $nbt), $nbt); return new FallingBlock(Helper::parseLocation($nbt, $world), FallingBlock::parseBlockNBT(RuntimeBlockStateRegistry::getInstance(), $nbt), $nbt);
}, ['FallingSand', 'minecraft:falling_block']); }, ['FallingSand', 'minecraft:falling_block']);
$this->register(ItemEntity::class, function(World $world, CompoundTag $nbt) : ItemEntity{ $this->register(ItemEntity::class, function(World $world, CompoundTag $nbt) : ItemEntity{

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\entity\object; namespace pocketmine\entity\object;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\utils\Fallable; use pocketmine\block\utils\Fallable;
use pocketmine\data\bedrock\block\BlockStateDeserializeException; use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\SavedDataLoadingException; use pocketmine\data\SavedDataLoadingException;
@ -66,7 +66,7 @@ class FallingBlock extends Entity{
protected function getInitialGravity() : float{ return 0.04; } protected function getInitialGravity() : float{ return 0.04; }
public static function parseBlockNBT(BlockFactory $factory, CompoundTag $nbt) : Block{ public static function parseBlockNBT(RuntimeBlockStateRegistry $factory, CompoundTag $nbt) : Block{
//TODO: 1.8+ save format //TODO: 1.8+ save format
$blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader(); $blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader();

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\VanillaBlocks; use pocketmine\block\VanillaBlocks;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
@ -59,7 +59,7 @@ final class ItemBlock extends Item{
public function getBlock(?int $clickedFace = null) : Block{ public function getBlock(?int $clickedFace = null) : Block{
//TODO: HACKY MESS, CLEAN IT UP //TODO: HACKY MESS, CLEAN IT UP
$factory = BlockFactory::getInstance(); $factory = RuntimeBlockStateRegistry::getInstance();
if(!$factory->isRegistered($this->blockTypeId)){ if(!$factory->isRegistered($this->blockTypeId)){
return VanillaBlocks::AIR(); return VanillaBlocks::AIR();
} }

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\math\Axis; use pocketmine\math\Axis;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -40,9 +40,9 @@ class ItemBlockWallOrFloor extends Item{
public function getBlock(?int $clickedFace = null) : Block{ public function getBlock(?int $clickedFace = null) : Block{
if($clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y){ if($clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y){
return BlockFactory::getInstance()->fromStateId($this->wallVariant); return RuntimeBlockStateRegistry::getInstance()->fromStateId($this->wallVariant);
} }
return BlockFactory::getInstance()->fromStateId($this->floorVariant); return RuntimeBlockStateRegistry::getInstance()->fromStateId($this->floorVariant);
} }
public function getFuelTime() : int{ public function getFuelTime() : int{

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world; namespace pocketmine\world;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\TNT; use pocketmine\block\TNT;
use pocketmine\block\VanillaBlocks; use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
@ -81,7 +81,7 @@ class Explosion{
return false; return false;
} }
$blockFactory = BlockFactory::getInstance(); $blockFactory = RuntimeBlockStateRegistry::getInstance();
$mRays = $this->rays - 1; $mRays = $this->rays - 1;
for($i = 0; $i < $this->rays; ++$i){ for($i = 0; $i < $this->rays; ++$i){
@ -112,7 +112,7 @@ class Explosion{
continue; continue;
} }
$state = $this->subChunkExplorer->currentSubChunk->getFullBlock($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK); $state = $this->subChunkExplorer->currentSubChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);
$blastResistance = $blockFactory->blastResistance[$state] ?? 0; $blastResistance = $blockFactory->blastResistance[$state] ?? 0;
if($blastResistance >= 0){ if($blastResistance >= 0){

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world; namespace pocketmine\world;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\VanillaBlocks; use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Limits; use pocketmine\utils\Limits;
use pocketmine\world\format\Chunk; use pocketmine\world\format\Chunk;
@ -41,14 +41,14 @@ class SimpleChunkManager implements ChunkManager{
public function getBlockAt(int $x, int $y, int $z) : Block{ public function getBlockAt(int $x, int $y, int $z) : Block{
if($this->isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){ if($this->isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){
return BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK)); return RuntimeBlockStateRegistry::getInstance()->fromStateId($chunk->getBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
} }
return VanillaBlocks::AIR(); return VanillaBlocks::AIR();
} }
public function setBlockAt(int $x, int $y, int $z, Block $block) : void{ public function setBlockAt(int $x, int $y, int $z, Block $block) : void{
if(($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){ if(($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){
$chunk->setFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK, $block->getStateId()); $chunk->setBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK, $block->getStateId());
}else{ }else{
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds"); throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
} }

View File

@ -28,8 +28,8 @@ namespace pocketmine\world;
use pocketmine\block\Air; use pocketmine\block\Air;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockTypeIds; use pocketmine\block\BlockTypeIds;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\tile\Spawnable; use pocketmine\block\tile\Spawnable;
use pocketmine\block\tile\Tile; use pocketmine\block\tile\Tile;
use pocketmine\block\tile\TileFactory; use pocketmine\block\tile\TileFactory;
@ -533,7 +533,7 @@ class World implements ChunkManager{
if($blockStateData === null){ if($blockStateData === null){
continue; continue;
} }
$block = BlockFactory::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData)); $block = RuntimeBlockStateRegistry::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));
}else{ }else{
//TODO: we probably ought to log an error here //TODO: we probably ought to log an error here
continue; continue;
@ -544,7 +544,7 @@ class World implements ChunkManager{
} }
} }
foreach(BlockFactory::getInstance()->getAllKnownStates() as $state){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){
$dontTickName = $dontTickBlocks[$state->getTypeId()] ?? null; $dontTickName = $dontTickBlocks[$state->getTypeId()] ?? null;
if($dontTickName === null && $state->ticksRandomly()){ if($dontTickName === null && $state->ticksRandomly()){
$this->randomTickBlocks[$state->getStateId()] = true; $this->randomTickBlocks[$state->getStateId()] = true;
@ -1295,7 +1295,7 @@ class World implements ChunkManager{
$entity->onRandomUpdate(); $entity->onRandomUpdate();
} }
$blockFactory = BlockFactory::getInstance(); $blockFactory = RuntimeBlockStateRegistry::getInstance();
foreach($chunk->getSubChunks() as $Y => $subChunk){ foreach($chunk->getSubChunks() as $Y => $subChunk){
if(!$subChunk->isEmptyFast()){ if(!$subChunk->isEmptyFast()){
$k = 0; $k = 0;
@ -1309,7 +1309,7 @@ class World implements ChunkManager{
$z = ($k >> (SubChunk::COORD_BIT_SIZE * 2)) & SubChunk::COORD_MASK; $z = ($k >> (SubChunk::COORD_BIT_SIZE * 2)) & SubChunk::COORD_MASK;
$k >>= (SubChunk::COORD_BIT_SIZE * 3); $k >>= (SubChunk::COORD_BIT_SIZE * 3);
$state = $subChunk->getFullBlock($x, $y, $z); $state = $subChunk->getBlockStateId($x, $y, $z);
if(isset($this->randomTickBlocks[$state])){ if(isset($this->randomTickBlocks[$state])){
$block = $blockFactory->fromStateId($state); $block = $blockFactory->fromStateId($state);
@ -1609,7 +1609,7 @@ class World implements ChunkManager{
return; return;
} }
$blockFactory = BlockFactory::getInstance(); $blockFactory = RuntimeBlockStateRegistry::getInstance();
$this->timings->doBlockSkyLightUpdates->startTiming(); $this->timings->doBlockSkyLightUpdates->startTiming();
if($this->skyLightUpdate === null){ if($this->skyLightUpdate === null){
$this->skyLightUpdate = new SkyLightUpdate(new SubChunkExplorer($this), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight); $this->skyLightUpdate = new SkyLightUpdate(new SubChunkExplorer($this), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
@ -1732,7 +1732,7 @@ class World implements ChunkManager{
$chunk = $this->chunks[$chunkHash] ?? null; $chunk = $this->chunks[$chunkHash] ?? null;
if($chunk !== null){ if($chunk !== null){
$block = BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK)); $block = RuntimeBlockStateRegistry::getInstance()->fromStateId($chunk->getBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
}else{ }else{
$addToCache = false; $addToCache = false;
$block = VanillaBlocks::AIR(); $block = VanillaBlocks::AIR();
@ -2371,7 +2371,7 @@ class World implements ChunkManager{
$localY = $tilePosition->getFloorY(); $localY = $tilePosition->getFloorY();
$localZ = $tilePosition->getFloorZ() & Chunk::COORD_MASK; $localZ = $tilePosition->getFloorZ() & Chunk::COORD_MASK;
$newBlock = BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($localX, $localY, $localZ)); $newBlock = RuntimeBlockStateRegistry::getInstance()->fromStateId($chunk->getBlockStateId($localX, $localY, $localZ));
$expectedTileClass = $newBlock->getIdInfo()->getTileClass(); $expectedTileClass = $newBlock->getIdInfo()->getTileClass();
if( if(
$expectedTileClass === null || //new block doesn't expect a tile $expectedTileClass === null || //new block doesn't expect a tile

View File

@ -93,15 +93,15 @@ class Chunk{
* *
* @return int bitmap, (id << 4) | meta * @return int bitmap, (id << 4) | meta
*/ */
public function getFullBlock(int $x, int $y, int $z) : int{ public function getBlockStateId(int $x, int $y, int $z) : int{
return $this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->getFullBlock($x, $y & SubChunk::COORD_MASK, $z); return $this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->getBlockStateId($x, $y & SubChunk::COORD_MASK, $z);
} }
/** /**
* Sets the blockstate at the given coordinate by internal ID. * Sets the blockstate at the given coordinate by internal ID.
*/ */
public function setFullBlock(int $x, int $y, int $z, int $block) : void{ public function setBlockStateId(int $x, int $y, int $z, int $block) : void{
$this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setFullBlock($x, $y & SubChunk::COORD_MASK, $z, $block); $this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setBlockStateId($x, $y & SubChunk::COORD_MASK, $z, $block);
$this->terrainDirtyFlags |= self::DIRTY_FLAG_BLOCKS; $this->terrainDirtyFlags |= self::DIRTY_FLAG_BLOCKS;
} }

View File

@ -69,14 +69,14 @@ class SubChunk{
*/ */
public function getEmptyBlockId() : int{ return $this->emptyBlockId; } public function getEmptyBlockId() : int{ return $this->emptyBlockId; }
public function getFullBlock(int $x, int $y, int $z) : int{ public function getBlockStateId(int $x, int $y, int $z) : int{
if(count($this->blockLayers) === 0){ if(count($this->blockLayers) === 0){
return $this->emptyBlockId; return $this->emptyBlockId;
} }
return $this->blockLayers[0]->get($x, $y, $z); return $this->blockLayers[0]->get($x, $y, $z);
} }
public function setFullBlock(int $x, int $y, int $z, int $block) : void{ public function setBlockStateId(int $x, int $y, int $z, int $block) : void{
if(count($this->blockLayers) === 0){ if(count($this->blockLayers) === 0){
$this->blockLayers[] = new PalettedBlockArray($this->emptyBlockId); $this->blockLayers[] = new PalettedBlockArray($this->emptyBlockId);
} }

View File

@ -77,7 +77,7 @@ class Flat extends Generator{
for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){ for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){
for($X = 0; $X < SubChunk::EDGE_LENGTH; ++$X){ for($X = 0; $X < SubChunk::EDGE_LENGTH; ++$X){
$subchunk->setFullBlock($X, $y, $Z, $id); $subchunk->setBlockStateId($X, $y, $Z, $id);
} }
} }
} }

View File

@ -85,16 +85,16 @@ class Nether extends Generator{
for($y = 0; $y < 128; ++$y){ for($y = 0; $y < 128; ++$y){
if($y === 0 || $y === 127){ if($y === 0 || $y === 127){
$chunk->setFullBlock($x, $y, $z, $bedrock); $chunk->setBlockStateId($x, $y, $z, $bedrock);
continue; continue;
} }
$noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y]; $noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y];
$noiseValue -= 1 - $this->density; $noiseValue -= 1 - $this->density;
if($noiseValue > 0){ if($noiseValue > 0){
$chunk->setFullBlock($x, $y, $z, $netherrack); $chunk->setBlockStateId($x, $y, $z, $netherrack);
}elseif($y <= $this->waterHeight){ }elseif($y <= $this->waterHeight){
$chunk->setFullBlock($x, $y, $z, $stillLava); $chunk->setBlockStateId($x, $y, $z, $stillLava);
} }
} }
} }

View File

@ -194,15 +194,15 @@ class Normal extends Generator{
for($y = 0; $y < 128; ++$y){ for($y = 0; $y < 128; ++$y){
if($y === 0){ if($y === 0){
$chunk->setFullBlock($x, $y, $z, $bedrock); $chunk->setBlockStateId($x, $y, $z, $bedrock);
continue; continue;
} }
$noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum); $noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum);
if($noiseValue > 0){ if($noiseValue > 0){
$chunk->setFullBlock($x, $y, $z, $stone); $chunk->setBlockStateId($x, $y, $z, $stone);
}elseif($y <= $this->waterHeight){ }elseif($y <= $this->waterHeight){
$chunk->setFullBlock($x, $y, $z, $stillWater); $chunk->setBlockStateId($x, $y, $z, $stillWater);
} }
} }
} }

View File

@ -23,9 +23,9 @@ declare(strict_types=1);
namespace pocketmine\world\generator\populator; namespace pocketmine\world\generator\populator;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockTypeIds; use pocketmine\block\BlockTypeIds;
use pocketmine\block\Liquid; use pocketmine\block\Liquid;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\utils\Random; use pocketmine\utils\Random;
use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\biome\BiomeRegistry;
use pocketmine\world\ChunkManager; use pocketmine\world\ChunkManager;
@ -37,7 +37,7 @@ class GroundCover implements Populator{
public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{
$chunk = $world->getChunk($chunkX, $chunkZ); $chunk = $world->getChunk($chunkX, $chunkZ);
$factory = BlockFactory::getInstance(); $factory = RuntimeBlockStateRegistry::getInstance();
$biomeRegistry = BiomeRegistry::getInstance(); $biomeRegistry = BiomeRegistry::getInstance();
for($x = 0; $x < Chunk::EDGE_LENGTH; ++$x){ for($x = 0; $x < Chunk::EDGE_LENGTH; ++$x){
for($z = 0; $z < Chunk::EDGE_LENGTH; ++$z){ for($z = 0; $z < Chunk::EDGE_LENGTH; ++$z){
@ -51,7 +51,7 @@ class GroundCover implements Populator{
$startY = 127; $startY = 127;
for(; $startY > 0; --$startY){ for(; $startY > 0; --$startY){
if(!$factory->fromStateId($chunk->getFullBlock($x, $startY, $z))->isTransparent()){ if(!$factory->fromStateId($chunk->getBlockStateId($x, $startY, $z))->isTransparent()){
break; break;
} }
} }
@ -59,7 +59,7 @@ class GroundCover implements Populator{
$endY = $startY - count($cover); $endY = $startY - count($cover);
for($y = $startY; $y > $endY && $y >= 0; --$y){ for($y = $startY; $y > $endY && $y >= 0; --$y){
$b = $cover[$startY - $y]; $b = $cover[$startY - $y];
$id = $factory->fromStateId($chunk->getFullBlock($x, $y, $z)); $id = $factory->fromStateId($chunk->getBlockStateId($x, $y, $z));
if($id->getTypeId() === BlockTypeIds::AIR && $b->isSolid()){ if($id->getTypeId() === BlockTypeIds::AIR && $b->isSolid()){
break; break;
} }
@ -67,7 +67,7 @@ class GroundCover implements Populator{
continue; continue;
} }
$chunk->setFullBlock($x, $y, $z, $b->getStateId()); $chunk->setBlockStateId($x, $y, $z, $b->getStateId());
} }
} }
} }

View File

@ -50,7 +50,7 @@ class BlockLightUpdate extends LightUpdate{
public function recalculateNode(int $x, int $y, int $z) : void{ public function recalculateNode(int $x, int $y, int $z) : void{
if($this->subChunkExplorer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){ if($this->subChunkExplorer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){
$block = $this->subChunkExplorer->currentSubChunk->getFullBlock($x & SubChunk::COORD_MASK, $y & SubChunk::COORD_MASK, $z & SubChunk::COORD_MASK); $block = $this->subChunkExplorer->currentSubChunk->getBlockStateId($x & SubChunk::COORD_MASK, $y & SubChunk::COORD_MASK, $z & SubChunk::COORD_MASK);
$this->setAndUpdateLight($x, $y, $z, max($this->lightEmitters[$block] ?? 0, $this->getHighestAdjacentLight($x, $y, $z) - ($this->lightFilters[$block] ?? self::BASE_LIGHT_FILTER))); $this->setAndUpdateLight($x, $y, $z, max($this->lightEmitters[$block] ?? 0, $this->getHighestAdjacentLight($x, $y, $z) - ($this->lightFilters[$block] ?? self::BASE_LIGHT_FILTER)));
} }
} }
@ -83,7 +83,7 @@ class BlockLightUpdate extends LightUpdate{
for($x = 0; $x < SubChunk::EDGE_LENGTH; ++$x){ for($x = 0; $x < SubChunk::EDGE_LENGTH; ++$x){
for($z = 0; $z < SubChunk::EDGE_LENGTH; ++$z){ for($z = 0; $z < SubChunk::EDGE_LENGTH; ++$z){
for($y = 0; $y < SubChunk::EDGE_LENGTH; ++$y){ for($y = 0; $y < SubChunk::EDGE_LENGTH; ++$y){
$light = $this->lightEmitters[$subChunk->getFullBlock($x, $y, $z)] ?? 0; $light = $this->lightEmitters[$subChunk->getBlockStateId($x, $y, $z)] ?? 0;
if($light > 0){ if($light > 0){
$this->setAndUpdateLight( $this->setAndUpdateLight(
$baseX + $x, $baseX + $x,

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\light; namespace pocketmine\world\light;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use pocketmine\world\format\Chunk; use pocketmine\world\format\Chunk;
use pocketmine\world\format\io\FastChunkSerializer; use pocketmine\world\format\io\FastChunkSerializer;
@ -57,7 +57,7 @@ class LightPopulationTask extends AsyncTask{
$manager = new SimpleChunkManager(World::Y_MIN, World::Y_MAX); $manager = new SimpleChunkManager(World::Y_MIN, World::Y_MAX);
$manager->setChunk(0, 0, $chunk); $manager->setChunk(0, 0, $chunk);
$blockFactory = BlockFactory::getInstance(); $blockFactory = RuntimeBlockStateRegistry::getInstance();
foreach([ foreach([
"Block" => new BlockLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->light), "Block" => new BlockLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->light),
"Sky" => new SkyLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight), "Sky" => new SkyLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight),

View File

@ -191,7 +191,7 @@ abstract class LightUpdate{
$ly = $y & SubChunk::COORD_MASK; $ly = $y & SubChunk::COORD_MASK;
$lz = $z & SubChunk::COORD_MASK; $lz = $z & SubChunk::COORD_MASK;
$current = $lightArray->get($lx, $ly, $lz); $current = $lightArray->get($lx, $ly, $lz);
$potentialLight = $newAdjacentLevel - ($this->lightFilters[$this->subChunkExplorer->currentSubChunk->getFullBlock($lx, $ly, $lz)] ?? self::BASE_LIGHT_FILTER); $potentialLight = $newAdjacentLevel - ($this->lightFilters[$this->subChunkExplorer->currentSubChunk->getBlockStateId($lx, $ly, $lz)] ?? self::BASE_LIGHT_FILTER);
if($current < $potentialLight){ if($current < $potentialLight){
$lightArray->set($lx, $ly, $lz, $potentialLight); $lightArray->set($lx, $ly, $lz, $potentialLight);

View File

@ -66,7 +66,7 @@ class SkyLightUpdate extends LightUpdate{
$chunk = $this->subChunkExplorer->currentChunk; $chunk = $this->subChunkExplorer->currentChunk;
$oldHeightMap = $chunk->getHeightMap($x & Chunk::COORD_MASK, $z & Chunk::COORD_MASK); $oldHeightMap = $chunk->getHeightMap($x & Chunk::COORD_MASK, $z & Chunk::COORD_MASK);
$source = $this->subChunkExplorer->currentSubChunk->getFullBlock($x & SubChunk::COORD_MASK, $y & SubChunk::COORD_MASK, $z & SubChunk::COORD_MASK); $source = $this->subChunkExplorer->currentSubChunk->getBlockStateId($x & SubChunk::COORD_MASK, $y & SubChunk::COORD_MASK, $z & SubChunk::COORD_MASK);
$yPlusOne = $y + 1; $yPlusOne = $y + 1;
@ -194,7 +194,7 @@ class SkyLightUpdate extends LightUpdate{
$result->set($x, $z, World::Y_MIN); $result->set($x, $z, World::Y_MIN);
}else{ }else{
for(; $y >= World::Y_MIN; --$y){ for(; $y >= World::Y_MIN; --$y){
if(isset($directSkyLightBlockers[$chunk->getFullBlock($x, $y, $z)])){ if(isset($directSkyLightBlockers[$chunk->getBlockStateId($x, $y, $z)])){
$result->set($x, $z, $y + 1); $result->set($x, $z, $y + 1);
break; break;
} }
@ -221,7 +221,7 @@ class SkyLightUpdate extends LightUpdate{
return World::Y_MIN; return World::Y_MIN;
} }
for(; $y >= World::Y_MIN; --$y){ for(; $y >= World::Y_MIN; --$y){
if(isset($directSkyLightBlockers[$chunk->getFullBlock($x, $y, $z)])){ if(isset($directSkyLightBlockers[$chunk->getBlockStateId($x, $y, $z)])){
break; break;
} }
} }

View File

@ -33,11 +33,11 @@ use const SORT_STRING;
class BlockTest extends TestCase{ class BlockTest extends TestCase{
/** @var BlockFactory */ /** @var RuntimeBlockStateRegistry */
private $blockFactory; private $blockFactory;
public function setUp() : void{ public function setUp() : void{
$this->blockFactory = new BlockFactory(); $this->blockFactory = new RuntimeBlockStateRegistry();
} }
/** /**

View File

@ -22,17 +22,17 @@
declare(strict_types=1); declare(strict_types=1);
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\AssumptionFailedError;
require dirname(__DIR__, 3) . '/vendor/autoload.php'; require dirname(__DIR__, 3) . '/vendor/autoload.php';
/* This script needs to be re-run after any intentional blockfactory change (adding or removing a block state). */ /* This script needs to be re-run after any intentional blockfactory change (adding or removing a block state). */
$factory = new \pocketmine\block\BlockFactory(); $factory = new \pocketmine\block\RuntimeBlockStateRegistry();
$remaps = []; $remaps = [];
$new = []; $new = [];
foreach(BlockFactory::getInstance()->getAllKnownStates() as $index => $block){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $index => $block){
if($index !== $block->getStateId()){ if($index !== $block->getStateId()){
throw new AssumptionFailedError("State index should always match state ID"); throw new AssumptionFailedError("State index should always match state ID");
} }

View File

@ -26,8 +26,8 @@ namespace pocketmine\data\bedrock\block\convert;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use pocketmine\block\BaseBanner; use pocketmine\block\BaseBanner;
use pocketmine\block\Bed; use pocketmine\block\Bed;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockTypeIds; use pocketmine\block\BlockTypeIds;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\Skull; use pocketmine\block\Skull;
use pocketmine\data\bedrock\block\BlockStateDeserializeException; use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\BlockStateSerializeException; use pocketmine\data\bedrock\block\BlockStateSerializeException;
@ -43,7 +43,7 @@ final class BlockSerializerDeserializerTest extends TestCase{
} }
public function testAllKnownBlockStatesSerializableAndDeserializable() : void{ public function testAllKnownBlockStatesSerializableAndDeserializable() : void{
foreach(BlockFactory::getInstance()->getAllKnownStates() as $block){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $block){
try{ try{
$blockStateData = $this->serializer->serializeBlock($block); $blockStateData = $this->serializer->serializeBlock($block);
}catch(BlockStateSerializeException $e){ }catch(BlockStateSerializeException $e){

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\item; namespace pocketmine\data\bedrock\item;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\item\VanillaItems; use pocketmine\item\VanillaItems;
use pocketmine\world\format\io\GlobalBlockStateHandlers; use pocketmine\world\format\io\GlobalBlockStateHandlers;
@ -60,7 +60,7 @@ final class ItemSerializerDeserializerTest extends TestCase{
} }
public function testAllVanillaBlocksSerializableAndDeserializable() : void{ public function testAllVanillaBlocksSerializableAndDeserializable() : void{
foreach(BlockFactory::getInstance()->getAllKnownStates() as $block){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $block){
$item = $block->asItem(); $item = $block->asItem();
if($item->isNull()){ if($item->isNull()){
continue; continue;

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\convert; namespace pocketmine\network\mcpe\convert;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use pocketmine\block\BlockFactory; use pocketmine\block\RuntimeBlockStateRegistry;
class RuntimeBlockMappingTest extends TestCase{ class RuntimeBlockMappingTest extends TestCase{
@ -32,7 +32,7 @@ class RuntimeBlockMappingTest extends TestCase{
* @doesNotPerformAssertions * @doesNotPerformAssertions
*/ */
public function testAllBlockStatesSerialize() : void{ public function testAllBlockStatesSerialize() : void{
foreach(BlockFactory::getInstance()->getAllKnownStates() as $state){ foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){
RuntimeBlockMapping::getInstance()->toRuntimeId($state->getStateId()); RuntimeBlockMapping::getInstance()->toRuntimeId($state->getStateId());
} }
} }

View File

@ -29,16 +29,16 @@ class ChunkTest extends TestCase{
public function testClone() : void{ public function testClone() : void{
$chunk = new Chunk([], false); $chunk = new Chunk([], false);
$chunk->setFullBlock(0, 0, 0, 1); $chunk->setBlockStateId(0, 0, 0, 1);
$chunk->setBiomeId(0, 0, 0, 1); $chunk->setBiomeId(0, 0, 0, 1);
$chunk->setHeightMap(0, 0, 1); $chunk->setHeightMap(0, 0, 1);
$chunk2 = clone $chunk; $chunk2 = clone $chunk;
$chunk2->setFullBlock(0, 0, 0, 2); $chunk2->setBlockStateId(0, 0, 0, 2);
$chunk2->setBiomeId(0, 0, 0, 2); $chunk2->setBiomeId(0, 0, 0, 2);
$chunk2->setHeightMap(0, 0, 2); $chunk2->setHeightMap(0, 0, 2);
self::assertNotSame($chunk->getFullBlock(0, 0, 0), $chunk2->getFullBlock(0, 0, 0)); self::assertNotSame($chunk->getBlockStateId(0, 0, 0), $chunk2->getBlockStateId(0, 0, 0));
self::assertNotSame($chunk->getBiomeId(0, 0, 0), $chunk2->getBiomeId(0, 0, 0)); self::assertNotSame($chunk->getBiomeId(0, 0, 0), $chunk2->getBiomeId(0, 0, 0));
self::assertNotSame($chunk->getHeightMap(0, 0), $chunk2->getHeightMap(0, 0)); self::assertNotSame($chunk->getHeightMap(0, 0), $chunk2->getHeightMap(0, 0));
} }

View File

@ -34,17 +34,17 @@ class SubChunkTest extends TestCase{
public function testClone() : void{ public function testClone() : void{
$sub1 = new SubChunk(0, [], new PalettedBlockArray(BiomeIds::OCEAN)); $sub1 = new SubChunk(0, [], new PalettedBlockArray(BiomeIds::OCEAN));
$sub1->setFullBlock(0, 0, 0, 1); $sub1->setBlockStateId(0, 0, 0, 1);
$sub1->getBlockLightArray()->set(0, 0, 0, 1); $sub1->getBlockLightArray()->set(0, 0, 0, 1);
$sub1->getBlockSkyLightArray()->set(0, 0, 0, 1); $sub1->getBlockSkyLightArray()->set(0, 0, 0, 1);
$sub2 = clone $sub1; $sub2 = clone $sub1;
$sub2->setFullBlock(0, 0, 0, 2); $sub2->setBlockStateId(0, 0, 0, 2);
$sub2->getBlockLightArray()->set(0, 0, 0, 2); $sub2->getBlockLightArray()->set(0, 0, 0, 2);
$sub2->getBlockSkyLightArray()->set(0, 0, 0, 2); $sub2->getBlockSkyLightArray()->set(0, 0, 0, 2);
self::assertNotSame($sub1->getFullBlock(0, 0, 0), $sub2->getFullBlock(0, 0, 0)); self::assertNotSame($sub1->getBlockStateId(0, 0, 0), $sub2->getBlockStateId(0, 0, 0));
self::assertNotSame($sub1->getBlockLightArray()->get(0, 0, 0), $sub2->getBlockLightArray()->get(0, 0, 0)); self::assertNotSame($sub1->getBlockLightArray()->get(0, 0, 0), $sub2->getBlockLightArray()->get(0, 0, 0));
self::assertNotSame($sub1->getBlockSkyLightArray()->get(0, 0, 0), $sub2->getBlockSkyLightArray()->get(0, 0, 0)); self::assertNotSame($sub1->getBlockSkyLightArray()->get(0, 0, 0), $sub2->getBlockSkyLightArray()->get(0, 0, 0));
} }