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
30 changed files with 81 additions and 78 deletions

View File

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

View File

@ -22,17 +22,17 @@
declare(strict_types=1);
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\utils\AssumptionFailedError;
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). */
$factory = new \pocketmine\block\BlockFactory();
$factory = new \pocketmine\block\RuntimeBlockStateRegistry();
$remaps = [];
$new = [];
foreach(BlockFactory::getInstance()->getAllKnownStates() as $index => $block){
foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $index => $block){
if($index !== $block->getStateId()){
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 pocketmine\block\BaseBanner;
use pocketmine\block\Bed;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockTypeIds;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\Skull;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\bedrock\block\BlockStateSerializeException;
@ -43,7 +43,7 @@ final class BlockSerializerDeserializerTest extends TestCase{
}
public function testAllKnownBlockStatesSerializableAndDeserializable() : void{
foreach(BlockFactory::getInstance()->getAllKnownStates() as $block){
foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $block){
try{
$blockStateData = $this->serializer->serializeBlock($block);
}catch(BlockStateSerializeException $e){

View File

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

View File

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

View File

@ -29,16 +29,16 @@ class ChunkTest extends TestCase{
public function testClone() : void{
$chunk = new Chunk([], false);
$chunk->setFullBlock(0, 0, 0, 1);
$chunk->setBlockStateId(0, 0, 0, 1);
$chunk->setBiomeId(0, 0, 0, 1);
$chunk->setHeightMap(0, 0, 1);
$chunk2 = clone $chunk;
$chunk2->setFullBlock(0, 0, 0, 2);
$chunk2->setBlockStateId(0, 0, 0, 2);
$chunk2->setBiomeId(0, 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->getHeightMap(0, 0), $chunk2->getHeightMap(0, 0));
}

View File

@ -34,17 +34,17 @@ class SubChunkTest extends TestCase{
public function testClone() : void{
$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->getBlockSkyLightArray()->set(0, 0, 0, 1);
$sub2 = clone $sub1;
$sub2->setFullBlock(0, 0, 0, 2);
$sub2->setBlockStateId(0, 0, 0, 2);
$sub2->getBlockLightArray()->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->getBlockSkyLightArray()->get(0, 0, 0), $sub2->getBlockSkyLightArray()->get(0, 0, 0));
}