mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 08:35:20 +00:00
Unify block serializers (#6769)
This has several advantages: Easier to implement new blocks (one less file to modify) Easier to adjust serialization of existing blocks Guaranteed consistency between serializers and deserializers Potentially, exposes more metadata for programmatic analysis, instead of having everything baked inside opaque Closures There are some exceptions which still use the old approach: big dripleaf, cauldrons, mushroom stems, and pitcher crops. These all have multiple PM block types for a single ID, with relatively complex logic to select which to use. These weren't worth the effort to unify due to their small number. I may revisit this in the future, but I already spent a lot of brainpower on it.
This commit is contained in:
@ -600,6 +600,12 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/crash/CrashDumpRenderer.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$faces of method pocketmine\\block\\Vine\:\:setFaces\(\) expects list\<2\|3\|4\|5\>, array\<int\> given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: ../../../src/data/bedrock/block/convert/VanillaBlockMappings.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$blockToItemId of class pocketmine\\data\\bedrock\\item\\BlockItemIdMap constructor expects array\<string, string\>, array\<mixed, mixed\> given\.$#'
|
||||
identifier: argument.type
|
||||
|
@ -42,6 +42,8 @@ final class BlockSerializerDeserializerTest extends TestCase{
|
||||
public function setUp() : void{
|
||||
$this->deserializer = new BlockStateToObjectDeserializer();
|
||||
$this->serializer = new BlockObjectToStateSerializer();
|
||||
$registrar = new BlockSerializerDeserializerRegistrar($this->deserializer, $this->serializer);
|
||||
VanillaBlockMappings::init($registrar);
|
||||
}
|
||||
|
||||
public function testAllKnownBlockStatesSerializableAndDeserializable() : void{
|
||||
@ -49,12 +51,12 @@ final class BlockSerializerDeserializerTest extends TestCase{
|
||||
try{
|
||||
$blockStateData = $this->serializer->serializeBlock($block);
|
||||
}catch(BlockStateSerializeException $e){
|
||||
self::fail($e->getMessage());
|
||||
self::fail("Failed to serialize " . $block->getName() . ": " . $e->getMessage());
|
||||
}
|
||||
try{
|
||||
$newBlock = $this->deserializer->deserializeBlock($blockStateData);
|
||||
}catch(BlockStateDeserializeException $e){
|
||||
self::fail($e->getMessage());
|
||||
self::fail("Failed to deserialize " . $blockStateData->getName() . ": " . $e->getMessage() . " with data " . $blockStateData->toNbt());
|
||||
}
|
||||
|
||||
if($block->getTypeId() === BlockTypeIds::POTION_CAULDRON){
|
||||
|
Reference in New Issue
Block a user