VanillaBlocks: use BlockFactory::fromTypeId()

This commit is contained in:
Dylan K. Taylor 2022-07-05 13:40:07 +01:00
parent d9544b5d0e
commit bd773c2f84
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 602 additions and 602 deletions

View File

@ -882,12 +882,12 @@ class BlockFactory{
* @internal
* Returns the default state of the block type associated with the given type ID.
*/
public function fromTypeId(int $typeId) : ?Block{
public function fromTypeId(int $typeId) : Block{
if(isset($this->typeIndex[$typeId])){
return clone $this->typeIndex[$typeId];
}
return null;
throw new \InvalidArgumentException("Block ID $typeId is not registered");
}
public function fromFullBlock(int $fullState) : Block{
@ -897,9 +897,8 @@ class BlockFactory{
/**
* Returns whether a specified block state is already registered in the block factory.
*/
public function isRegistered(int $typeId, int $stateData = 0) : bool{
$index = ($typeId << Block::INTERNAL_STATE_DATA_BITS) | $stateData;
$b = $this->fullList[$index] ?? null;
public function isRegistered(int $typeId) : bool{
$b = $this->typeIndex[$typeId] ?? null;
return $b !== null && !($b instanceof UnknownBlock);
}

File diff suppressed because it is too large Load Diff

View File

@ -45,10 +45,11 @@ final class ItemBlock extends Item{
public function getBlock(?int $clickedFace = null) : Block{
//TODO: HACKY MESS, CLEAN IT UP
$blockType = BlockFactory::getInstance()->fromTypeId($this->blockTypeId);
if($blockType === null){
$factory = BlockFactory::getInstance();
if(!$factory->isRegistered($this->blockTypeId)){
return VanillaBlocks::AIR();
}
$blockType = BlockFactory::getInstance()->fromTypeId($this->blockTypeId);
$blockType->decodeTypeData($this->blockTypeData);
return $blockType;
}