mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Clean up confusing mess around block and item overriding
right now, I don't see an obvious reason to do this. If it turns out I was wrong later on, we can add functionality back, but we can't remove functionality after release.
This commit is contained in:
parent
c9bb4335a1
commit
9621836e36
@ -81,22 +81,16 @@ class RuntimeBlockStateRegistry{
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a block type to its corresponding type ID. This is necessary for the block to be recognized when loading
|
||||
* from disk, and also when being read at runtime.
|
||||
* Maps a block type's state permutations to its corresponding state IDs. This is necessary for the block to be
|
||||
* recognized when fetching it by its state ID from chunks at runtime.
|
||||
*
|
||||
* NOTE: If you are registering a new block type, you will need to add it to the creative inventory yourself - it
|
||||
* will not automatically appear there.
|
||||
*
|
||||
* @param bool $override Whether to override existing registrations
|
||||
*
|
||||
* @throws \InvalidArgumentException if something attempted to override an already-registered block without specifying the
|
||||
* $override parameter.
|
||||
* @throws \InvalidArgumentException if the desired block type ID is already registered
|
||||
*/
|
||||
public function register(Block $block, bool $override = false) : void{
|
||||
public function register(Block $block) : void{
|
||||
$typeId = $block->getTypeId();
|
||||
|
||||
if(!$override && isset($this->typeIndex[$typeId])){
|
||||
throw new \InvalidArgumentException("Block ID $typeId is already used by another block, and override was not requested");
|
||||
if(isset($this->typeIndex[$typeId])){
|
||||
throw new \InvalidArgumentException("Block ID $typeId is already used by another block");
|
||||
}
|
||||
|
||||
$this->typeIndex[$typeId] = clone $block;
|
||||
|
@ -210,8 +210,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
|
||||
*/
|
||||
public function map(Block $block, \Closure $serializer) : void{
|
||||
if(isset($this->serializers[$block->getTypeId()])){
|
||||
//TODO: REMOVE ME
|
||||
throw new AssumptionFailedError("Registering the same block twice!");
|
||||
throw new \InvalidArgumentException("Block type ID " . $block->getTypeId() . " already has a serializer registered");
|
||||
}
|
||||
$this->serializers[$block->getTypeId()][get_class($block)] = $serializer;
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ final class ItemDeserializer{
|
||||
* @phpstan-param \Closure(Data) : Item $deserializer
|
||||
*/
|
||||
public function map(string $id, \Closure $deserializer) : void{
|
||||
if(isset($this->deserializers[$id])){
|
||||
throw new \InvalidArgumentException("Deserializer is already assigned for \"$id\"");
|
||||
}
|
||||
$this->deserializers[$id] = $deserializer;
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,7 @@ final class ItemSerializer{
|
||||
public function map(Item $item, \Closure $serializer) : void{
|
||||
$index = $item->getTypeId();
|
||||
if(isset($this->itemSerializers[$index])){
|
||||
//TODO: REMOVE ME
|
||||
throw new AssumptionFailedError("Registering the same item twice!");
|
||||
throw new \InvalidArgumentException("Item type ID " . $index . " already has a serializer registered");
|
||||
}
|
||||
$this->itemSerializers[$index][get_class($item)] = $serializer;
|
||||
}
|
||||
|
@ -49,15 +49,6 @@ class BlockTest extends TestCase{
|
||||
$this->blockFactory->register($block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test registering a block deliberately overwriting another block works as expected
|
||||
*/
|
||||
public function testDeliberateOverrideBlock() : void{
|
||||
$block = new MyCustomBlock(new BlockIdentifier(BlockTypeIds::COBBLESTONE), "Cobblestone", new BlockTypeInfo(BlockBreakInfo::instant()));
|
||||
$this->blockFactory->register($block, true);
|
||||
self::assertInstanceOf(MyCustomBlock::class, $this->blockFactory->fromStateId($block->getStateId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test registering a new block which does not yet exist
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user