mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
VanillaBlocks: use BlockFactory::fromTypeId()
This commit is contained in:
parent
d9544b5d0e
commit
bd773c2f84
@ -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
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user