From 0a23e91329a8358d2c8f6dede25bd0f6b28d25ce Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Jul 2022 13:46:19 +0100 Subject: [PATCH] Rename BlockFactory::fromFullBlock() -> BlockFactory::fromStateId() --- src/block/BlockFactory.php | 12 ++++++------ src/block/InfestedStone.php | 2 +- src/block/tile/FlowerPot.php | 2 +- .../convert/BlockObjectToBlockStateSerializer.php | 2 +- src/data/bedrock/item/ItemDeserializer.php | 2 +- src/entity/object/FallingBlock.php | 2 +- src/item/ItemBlockWallOrFloor.php | 4 ++-- src/item/ItemFactory.php | 2 +- src/world/SimpleChunkManager.php | 2 +- src/world/World.php | 8 ++++---- src/world/generator/populator/GroundCover.php | 4 ++-- tests/phpunit/block/BlockTest.php | 8 ++++---- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index c5ad465b1..4efc04cb6 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -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); } diff --git a/src/block/InfestedStone.php b/src/block/InfestedStone.php index 6fbda8eea..7700b572c 100644 --- a/src/block/InfestedStone.php +++ b/src/block/InfestedStone.php @@ -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{ diff --git a/src/block/tile/FlowerPot.php b/src/block/tile/FlowerPot.php index ec5987346..3544cd5fb 100644 --- a/src/block/tile/FlowerPot.php +++ b/src/block/tile/FlowerPot.php @@ -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)); } } diff --git a/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php index 93daadec2..f114ed97d 100644 --- a/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToBlockStateSerializer.php @@ -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)); } /** diff --git a/src/data/bedrock/item/ItemDeserializer.php b/src/data/bedrock/item/ItemDeserializer.php index 287e63398..2d8570b5b 100644 --- a/src/data/bedrock/item/ItemDeserializer.php +++ b/src/data/bedrock/item/ItemDeserializer.php @@ -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])){ diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index a7e495a24..39fc2320a 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -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{ diff --git a/src/item/ItemBlockWallOrFloor.php b/src/item/ItemBlockWallOrFloor.php index cb706965a..bd1213b34 100644 --- a/src/item/ItemBlockWallOrFloor.php +++ b/src/item/ItemBlockWallOrFloor.php @@ -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{ diff --git a/src/item/ItemFactory.php b/src/item/ItemFactory.php index 6804356ae..0de8cfcd8 100644 --- a/src/item/ItemFactory.php +++ b/src/item/ItemFactory.php @@ -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); } diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index e2ed3138e..85849c450 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -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(); } diff --git a/src/world/World.php b/src/world/World.php index 2dfb00497..fab04e87d 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -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 diff --git a/src/world/generator/populator/GroundCover.php b/src/world/generator/populator/GroundCover.php index 193905cce..2aa6cca9b 100644 --- a/src/world/generator/populator/GroundCover.php +++ b/src/world/generator/populator/GroundCover.php @@ -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; } diff --git a/tests/phpunit/block/BlockTest.php b/tests/phpunit/block/BlockTest.php index 1e420beff..3b8d704d9 100644 --- a/tests/phpunit/block/BlockTest.php +++ b/tests/phpunit/block/BlockTest.php @@ -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); } }