mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Clean up terminology around block state IDs and their handling
This commit is contained in:
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\world;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\block\TNT;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\entity\Entity;
|
||||
@ -81,7 +81,7 @@ class Explosion{
|
||||
return false;
|
||||
}
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$blockFactory = RuntimeBlockStateRegistry::getInstance();
|
||||
|
||||
$mRays = $this->rays - 1;
|
||||
for($i = 0; $i < $this->rays; ++$i){
|
||||
@ -112,7 +112,7 @@ class Explosion{
|
||||
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;
|
||||
if($blastResistance >= 0){
|
||||
|
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\world;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\utils\Limits;
|
||||
use pocketmine\world\format\Chunk;
|
||||
@ -41,14 +41,14 @@ class SimpleChunkManager implements ChunkManager{
|
||||
|
||||
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){
|
||||
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();
|
||||
}
|
||||
|
||||
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){
|
||||
$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{
|
||||
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ namespace pocketmine\world;
|
||||
|
||||
use pocketmine\block\Air;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BlockTypeIds;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\block\tile\Spawnable;
|
||||
use pocketmine\block\tile\Tile;
|
||||
use pocketmine\block\tile\TileFactory;
|
||||
@ -533,7 +533,7 @@ class World implements ChunkManager{
|
||||
if($blockStateData === null){
|
||||
continue;
|
||||
}
|
||||
$block = BlockFactory::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));
|
||||
$block = RuntimeBlockStateRegistry::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));
|
||||
}else{
|
||||
//TODO: we probably ought to log an error here
|
||||
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;
|
||||
if($dontTickName === null && $state->ticksRandomly()){
|
||||
$this->randomTickBlocks[$state->getStateId()] = true;
|
||||
@ -1295,7 +1295,7 @@ class World implements ChunkManager{
|
||||
$entity->onRandomUpdate();
|
||||
}
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$blockFactory = RuntimeBlockStateRegistry::getInstance();
|
||||
foreach($chunk->getSubChunks() as $Y => $subChunk){
|
||||
if(!$subChunk->isEmptyFast()){
|
||||
$k = 0;
|
||||
@ -1309,7 +1309,7 @@ class World implements ChunkManager{
|
||||
$z = ($k >> (SubChunk::COORD_BIT_SIZE * 2)) & SubChunk::COORD_MASK;
|
||||
$k >>= (SubChunk::COORD_BIT_SIZE * 3);
|
||||
|
||||
$state = $subChunk->getFullBlock($x, $y, $z);
|
||||
$state = $subChunk->getBlockStateId($x, $y, $z);
|
||||
|
||||
if(isset($this->randomTickBlocks[$state])){
|
||||
$block = $blockFactory->fromStateId($state);
|
||||
@ -1609,7 +1609,7 @@ class World implements ChunkManager{
|
||||
return;
|
||||
}
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$blockFactory = RuntimeBlockStateRegistry::getInstance();
|
||||
$this->timings->doBlockSkyLightUpdates->startTiming();
|
||||
if($this->skyLightUpdate === null){
|
||||
$this->skyLightUpdate = new SkyLightUpdate(new SubChunkExplorer($this), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
|
||||
@ -1732,7 +1732,7 @@ class World implements ChunkManager{
|
||||
|
||||
$chunk = $this->chunks[$chunkHash] ?? 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{
|
||||
$addToCache = false;
|
||||
$block = VanillaBlocks::AIR();
|
||||
@ -2371,7 +2371,7 @@ class World implements ChunkManager{
|
||||
$localY = $tilePosition->getFloorY();
|
||||
$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();
|
||||
if(
|
||||
$expectedTileClass === null || //new block doesn't expect a tile
|
||||
|
@ -93,15 +93,15 @@ class Chunk{
|
||||
*
|
||||
* @return int bitmap, (id << 4) | meta
|
||||
*/
|
||||
public function getFullBlock(int $x, int $y, int $z) : int{
|
||||
return $this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->getFullBlock($x, $y & SubChunk::COORD_MASK, $z);
|
||||
public function getBlockStateId(int $x, int $y, int $z) : int{
|
||||
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.
|
||||
*/
|
||||
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
|
||||
$this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setFullBlock($x, $y & SubChunk::COORD_MASK, $z, $block);
|
||||
public function setBlockStateId(int $x, int $y, int $z, int $block) : void{
|
||||
$this->getSubChunk($y >> SubChunk::COORD_BIT_SIZE)->setBlockStateId($x, $y & SubChunk::COORD_MASK, $z, $block);
|
||||
$this->terrainDirtyFlags |= self::DIRTY_FLAG_BLOCKS;
|
||||
}
|
||||
|
||||
|
@ -69,14 +69,14 @@ class SubChunk{
|
||||
*/
|
||||
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){
|
||||
return $this->emptyBlockId;
|
||||
}
|
||||
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){
|
||||
$this->blockLayers[] = new PalettedBlockArray($this->emptyBlockId);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class Flat extends Generator{
|
||||
|
||||
for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){
|
||||
for($X = 0; $X < SubChunk::EDGE_LENGTH; ++$X){
|
||||
$subchunk->setFullBlock($X, $y, $Z, $id);
|
||||
$subchunk->setBlockStateId($X, $y, $Z, $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,16 +85,16 @@ class Nether extends Generator{
|
||||
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
if($y === 0 || $y === 127){
|
||||
$chunk->setFullBlock($x, $y, $z, $bedrock);
|
||||
$chunk->setBlockStateId($x, $y, $z, $bedrock);
|
||||
continue;
|
||||
}
|
||||
$noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y];
|
||||
$noiseValue -= 1 - $this->density;
|
||||
|
||||
if($noiseValue > 0){
|
||||
$chunk->setFullBlock($x, $y, $z, $netherrack);
|
||||
$chunk->setBlockStateId($x, $y, $z, $netherrack);
|
||||
}elseif($y <= $this->waterHeight){
|
||||
$chunk->setFullBlock($x, $y, $z, $stillLava);
|
||||
$chunk->setBlockStateId($x, $y, $z, $stillLava);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,15 +194,15 @@ class Normal extends Generator{
|
||||
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
if($y === 0){
|
||||
$chunk->setFullBlock($x, $y, $z, $bedrock);
|
||||
$chunk->setBlockStateId($x, $y, $z, $bedrock);
|
||||
continue;
|
||||
}
|
||||
$noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum);
|
||||
|
||||
if($noiseValue > 0){
|
||||
$chunk->setFullBlock($x, $y, $z, $stone);
|
||||
$chunk->setBlockStateId($x, $y, $z, $stone);
|
||||
}elseif($y <= $this->waterHeight){
|
||||
$chunk->setFullBlock($x, $y, $z, $stillWater);
|
||||
$chunk->setBlockStateId($x, $y, $z, $stillWater);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\generator\populator;
|
||||
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BlockTypeIds;
|
||||
use pocketmine\block\Liquid;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\world\biome\BiomeRegistry;
|
||||
use pocketmine\world\ChunkManager;
|
||||
@ -37,7 +37,7 @@ class GroundCover implements Populator{
|
||||
|
||||
public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{
|
||||
$chunk = $world->getChunk($chunkX, $chunkZ);
|
||||
$factory = BlockFactory::getInstance();
|
||||
$factory = RuntimeBlockStateRegistry::getInstance();
|
||||
$biomeRegistry = BiomeRegistry::getInstance();
|
||||
for($x = 0; $x < Chunk::EDGE_LENGTH; ++$x){
|
||||
for($z = 0; $z < Chunk::EDGE_LENGTH; ++$z){
|
||||
@ -51,7 +51,7 @@ class GroundCover implements Populator{
|
||||
|
||||
$startY = 127;
|
||||
for(; $startY > 0; --$startY){
|
||||
if(!$factory->fromStateId($chunk->getFullBlock($x, $startY, $z))->isTransparent()){
|
||||
if(!$factory->fromStateId($chunk->getBlockStateId($x, $startY, $z))->isTransparent()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ class GroundCover implements Populator{
|
||||
$endY = $startY - count($cover);
|
||||
for($y = $startY; $y > $endY && $y >= 0; --$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()){
|
||||
break;
|
||||
}
|
||||
@ -67,7 +67,7 @@ class GroundCover implements Populator{
|
||||
continue;
|
||||
}
|
||||
|
||||
$chunk->setFullBlock($x, $y, $z, $b->getStateId());
|
||||
$chunk->setBlockStateId($x, $y, $z, $b->getStateId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class BlockLightUpdate extends LightUpdate{
|
||||
|
||||
public function recalculateNode(int $x, int $y, int $z) : void{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ class BlockLightUpdate extends LightUpdate{
|
||||
for($x = 0; $x < SubChunk::EDGE_LENGTH; ++$x){
|
||||
for($z = 0; $z < SubChunk::EDGE_LENGTH; ++$z){
|
||||
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){
|
||||
$this->setAndUpdateLight(
|
||||
$baseX + $x,
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\light;
|
||||
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\RuntimeBlockStateRegistry;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\format\io\FastChunkSerializer;
|
||||
@ -57,7 +57,7 @@ class LightPopulationTask extends AsyncTask{
|
||||
$manager = new SimpleChunkManager(World::Y_MIN, World::Y_MAX);
|
||||
$manager->setChunk(0, 0, $chunk);
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$blockFactory = RuntimeBlockStateRegistry::getInstance();
|
||||
foreach([
|
||||
"Block" => new BlockLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->light),
|
||||
"Sky" => new SkyLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight),
|
||||
|
@ -191,7 +191,7 @@ abstract class LightUpdate{
|
||||
$ly = $y & SubChunk::COORD_MASK;
|
||||
$lz = $z & SubChunk::COORD_MASK;
|
||||
$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){
|
||||
$lightArray->set($lx, $ly, $lz, $potentialLight);
|
||||
|
@ -66,7 +66,7 @@ class SkyLightUpdate extends LightUpdate{
|
||||
$chunk = $this->subChunkExplorer->currentChunk;
|
||||
|
||||
$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;
|
||||
|
||||
@ -194,7 +194,7 @@ class SkyLightUpdate extends LightUpdate{
|
||||
$result->set($x, $z, World::Y_MIN);
|
||||
}else{
|
||||
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);
|
||||
break;
|
||||
}
|
||||
@ -221,7 +221,7 @@ class SkyLightUpdate extends LightUpdate{
|
||||
return World::Y_MIN;
|
||||
}
|
||||
for(; $y >= World::Y_MIN; --$y){
|
||||
if(isset($directSkyLightBlockers[$chunk->getFullBlock($x, $y, $z)])){
|
||||
if(isset($directSkyLightBlockers[$chunk->getBlockStateId($x, $y, $z)])){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user