Rename BlockFactory::fromFullBlock() -> BlockFactory::fromStateId()

This commit is contained in:
Dylan K. Taylor 2022-07-05 13:46:19 +01:00
parent a059d03b37
commit 0a23e91329
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
12 changed files with 25 additions and 25 deletions

View File

@ -866,15 +866,15 @@ class BlockFactory{
throw new \InvalidArgumentException("Block ID $typeId is not registered");
}
public function fromFullBlock(int $fullState) : Block{
if($fullState < 0){
public function fromStateId(int $stateId) : Block{
if($stateId < 0){
throw new \InvalidArgumentException("Block state ID cannot be negative");
}
if(isset($this->fullList[$fullState])) { //hot
$block = clone $this->fullList[$fullState];
if(isset($this->fullList[$stateId])) { //hot
$block = clone $this->fullList[$stateId];
}else{
$typeId = $fullState >> Block::INTERNAL_STATE_DATA_BITS;
$stateData = $fullState & Block::INTERNAL_STATE_DATA_MASK;
$typeId = $stateId >> Block::INTERNAL_STATE_DATA_BITS;
$stateData = $stateId & Block::INTERNAL_STATE_DATA_MASK;
$block = new UnknownBlock(new BID($typeId), BreakInfo::instant(), $stateData);
}

View File

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

View File

@ -64,7 +64,7 @@ class FlowerPot extends Spawnable{
}catch(BlockStateDeserializeException $e){
throw new SavedDataLoadingException("Error deserializing plant for flower pot: " . $e->getMessage(), 0, $e);
}
$this->setPlant(BlockFactory::getInstance()->fromFullBlock($blockStateId));
$this->setPlant(BlockFactory::getInstance()->fromStateId($blockStateId));
}
}

View File

@ -172,7 +172,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
public function serialize(int $stateId) : BlockStateData{
//TODO: singleton usage not ideal
return $this->serializeBlock(BlockFactory::getInstance()->fromFullBlock($stateId));
return $this->serializeBlock(BlockFactory::getInstance()->fromStateId($stateId));
}
/**

View File

@ -76,7 +76,7 @@ final class ItemDeserializer{
}
//TODO: worth caching this or not?
return BlockFactory::getInstance()->fromFullBlock($block)->asItem();
return BlockFactory::getInstance()->fromStateId($block)->asItem();
}
$id = $data->getName();
if(!isset($this->deserializers[$id])){

View File

@ -90,7 +90,7 @@ class FallingBlock extends Entity{
throw new SavedDataLoadingException($e->getMessage(), 0, $e);
}
return $factory->fromFullBlock($blockStateId);
return $factory->fromStateId($blockStateId);
}
public function canCollideWith(Entity $entity) : bool{

View File

@ -40,9 +40,9 @@ class ItemBlockWallOrFloor extends Item{
public function getBlock(?int $clickedFace = null) : Block{
if($clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y){
return BlockFactory::getInstance()->fromFullBlock($this->wallVariant);
return BlockFactory::getInstance()->fromStateId($this->wallVariant);
}
return BlockFactory::getInstance()->fromFullBlock($this->floorVariant);
return BlockFactory::getInstance()->fromStateId($this->floorVariant);
}
public function getFuelTime() : int{

View File

@ -473,7 +473,7 @@ class ItemFactory{
if($blockStateData !== null){
try{
$blockStateId = GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData);
$item = new ItemBlock(BlockFactory::getInstance()->fromFullBlock($blockStateId));
$item = new ItemBlock(BlockFactory::getInstance()->fromStateId($blockStateId));
}catch(BlockStateDeserializeException $e){
throw new SavedDataLoadingException("Failed to deserialize itemblock: " . $e->getMessage(), 0, $e);
}

View File

@ -41,7 +41,7 @@ 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()->fromFullBlock($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
return BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
}
return VanillaBlocks::AIR();
}

View File

@ -444,7 +444,7 @@ class World implements ChunkManager{
if($blockStateData === null){
continue;
}
$block = BlockFactory::getInstance()->fromFullBlock(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));
$block = BlockFactory::getInstance()->fromStateId(GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData));
}else{
//TODO: we probably ought to log an error here
continue;
@ -1112,7 +1112,7 @@ class World implements ChunkManager{
$state = $subChunk->getFullBlock($x, $y, $z);
if(isset($this->randomTickBlocks[$state])){
$block = $blockFactory->fromFullBlock($state);
$block = $blockFactory->fromStateId($state);
$block->position($this, $chunkX * Chunk::EDGE_LENGTH + $x, ($Y << SubChunk::COORD_BIT_SIZE) + $y, $chunkZ * Chunk::EDGE_LENGTH + $z);
$block->onRandomTick();
}
@ -1528,7 +1528,7 @@ class World implements ChunkManager{
$chunk = $this->chunks[$chunkHash] ?? null;
if($chunk !== null){
$block = BlockFactory::getInstance()->fromFullBlock($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
$block = BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
}else{
$addToCache = false;
$block = VanillaBlocks::AIR();
@ -2146,7 +2146,7 @@ class World implements ChunkManager{
$localY = $tilePosition->getFloorY();
$localZ = $tilePosition->getFloorZ() & Chunk::COORD_MASK;
$newBlock = BlockFactory::getInstance()->fromFullBlock($chunk->getFullBlock($localX, $localY, $localZ));
$newBlock = BlockFactory::getInstance()->fromStateId($chunk->getFullBlock($localX, $localY, $localZ));
$expectedTileClass = $newBlock->getIdInfo()->getTileClass();
if(
$expectedTileClass === null || //new block doesn't expect a tile

View File

@ -51,7 +51,7 @@ class GroundCover implements Populator{
$startY = 127;
for(; $startY > 0; --$startY){
if(!$factory->fromFullBlock($chunk->getFullBlock($x, $startY, $z))->isTransparent()){
if(!$factory->fromStateId($chunk->getFullBlock($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->fromFullBlock($chunk->getFullBlock($x, $y, $z));
$id = $factory->fromStateId($chunk->getFullBlock($x, $y, $z));
if($id->getTypeId() === BlockTypeIds::AIR && $b->isSolid()){
break;
}

View File

@ -54,7 +54,7 @@ class BlockTest extends TestCase{
public function testDeliberateOverrideBlock() : void{
$block = new MyCustomBlock(new BlockIdentifier(BlockTypeIds::COBBLESTONE), "Cobblestone", BlockBreakInfo::instant());
$this->blockFactory->register($block, true);
self::assertInstanceOf(MyCustomBlock::class, $this->blockFactory->fromFullBlock($block->getStateId()));
self::assertInstanceOf(MyCustomBlock::class, $this->blockFactory->fromStateId($block->getStateId()));
}
/**
@ -65,7 +65,7 @@ class BlockTest extends TestCase{
if(!$this->blockFactory->isRegistered($i)){
$b = new StrangeNewBlock(new BlockIdentifier($i), "Strange New Block", BlockBreakInfo::instant());
$this->blockFactory->register($b);
self::assertInstanceOf(StrangeNewBlock::class, $this->blockFactory->fromFullBlock($b->getStateId()));
self::assertInstanceOf(StrangeNewBlock::class, $this->blockFactory->fromStateId($b->getStateId()));
return;
}
}
@ -88,8 +88,8 @@ class BlockTest extends TestCase{
*/
public function testBlockFactoryClone() : void{
foreach($this->blockFactory->getAllKnownStates() as $k => $state){
$b1 = $this->blockFactory->fromFullBlock($k);
$b2 = $this->blockFactory->fromFullBlock($k);
$b1 = $this->blockFactory->fromStateId($k);
$b2 = $this->blockFactory->fromStateId($k);
self::assertNotSame($b1, $b2);
}
}