mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Revert "ItemBlock: drop the charade about overriding built-in block types"
This reverts commit f64dc01bd1
.
I forgot that the ItemBlock constructor implicitly strips off any states
of the origin block, which is something that we unfortunately can't do
any other way right now, since the blocks don't remember their default
states.
This commit is contained in:
@ -151,6 +151,18 @@ class RuntimeBlockStateRegistry{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Returns the default state of the block type associated with the given type ID.
|
||||
*/
|
||||
public function fromTypeId(int $typeId) : Block{
|
||||
if(isset($this->typeIndex[$typeId])){
|
||||
return clone $this->typeIndex[$typeId];
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Block ID $typeId is not registered");
|
||||
}
|
||||
|
||||
public function fromStateId(int $stateId) : Block{
|
||||
if($stateId < 0){
|
||||
throw new \InvalidArgumentException("Block state ID cannot be negative");
|
||||
@ -166,6 +178,22 @@ class RuntimeBlockStateRegistry{
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a specified block state is already registered in the block factory.
|
||||
*/
|
||||
public function isRegistered(int $typeId) : bool{
|
||||
$b = $this->typeIndex[$typeId] ?? null;
|
||||
return $b !== null && !($b instanceof UnknownBlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block[]
|
||||
* @phpstan-return array<int, Block>
|
||||
*/
|
||||
public function getAllKnownTypes() : array{
|
||||
return $this->typeIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user