mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
VanillaBlocks: use BlockFactory::fromTypeId()
This commit is contained in:
parent
d9544b5d0e
commit
bd773c2f84
@ -882,12 +882,12 @@ class BlockFactory{
|
|||||||
* @internal
|
* @internal
|
||||||
* Returns the default state of the block type associated with the given type ID.
|
* 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])){
|
if(isset($this->typeIndex[$typeId])){
|
||||||
return clone $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{
|
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.
|
* Returns whether a specified block state is already registered in the block factory.
|
||||||
*/
|
*/
|
||||||
public function isRegistered(int $typeId, int $stateData = 0) : bool{
|
public function isRegistered(int $typeId) : bool{
|
||||||
$index = ($typeId << Block::INTERNAL_STATE_DATA_BITS) | $stateData;
|
$b = $this->typeIndex[$typeId] ?? null;
|
||||||
$b = $this->fullList[$index] ?? null;
|
|
||||||
return $b !== null && !($b instanceof UnknownBlock);
|
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{
|
public function getBlock(?int $clickedFace = null) : Block{
|
||||||
//TODO: HACKY MESS, CLEAN IT UP
|
//TODO: HACKY MESS, CLEAN IT UP
|
||||||
$blockType = BlockFactory::getInstance()->fromTypeId($this->blockTypeId);
|
$factory = BlockFactory::getInstance();
|
||||||
if($blockType === null){
|
if(!$factory->isRegistered($this->blockTypeId)){
|
||||||
return VanillaBlocks::AIR();
|
return VanillaBlocks::AIR();
|
||||||
}
|
}
|
||||||
|
$blockType = BlockFactory::getInstance()->fromTypeId($this->blockTypeId);
|
||||||
$blockType->decodeTypeData($this->blockTypeData);
|
$blockType->decodeTypeData($this->blockTypeData);
|
||||||
return $blockType;
|
return $blockType;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user