mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 08:56:15 +00:00
Block: Separate encoding of type and state data
the terminology of this needs improvement, but... the basic concept here is that 'type' data will persist on an itemstack, while 'state' data will not. Type data consists of things like: - Colour - Coral type - Wet/dry (sponges) - Live/dead (coral) - Wood type State data consists of things like: - Facing - Axis - Powered/unpowered - Open/closed In the past, with the old system, this information was separated by way of getStateBitmask(). This solution was fraught with problems, but achieved the basic goal: removing unwanted block properties from items.
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -24,9 +24,14 @@ declare(strict_types=1);
|
||||
namespace pocketmine\data\bedrock\block\convert;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use pocketmine\block\Bed;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BlockTypeIds;
|
||||
use pocketmine\block\Skull;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
|
||||
use pocketmine\data\bedrock\block\BlockStateSerializeException;
|
||||
use pocketmine\block\BaseBanner;
|
||||
use function print_r;
|
||||
|
||||
final class BlockSerializerDeserializerTest extends TestCase{
|
||||
@ -51,6 +56,19 @@ final class BlockSerializerDeserializerTest extends TestCase{
|
||||
self::fail($e->getMessage());
|
||||
}
|
||||
|
||||
//The following are workarounds for differences in blockstate representation in Bedrock vs PM
|
||||
//In these cases, some properties are not stored in the blockstate (but rather in the block entity NBT), but
|
||||
//they do form part of the internal blockstate hash in PM. This leads to inconsistencies when serializing
|
||||
//and deserializing blockstates.
|
||||
if(
|
||||
($block instanceof BaseBanner && $newBlock instanceof BaseBanner) ||
|
||||
($block instanceof Bed && $newBlock instanceof Bed)
|
||||
){
|
||||
$newBlock->setColor($block->getColor());
|
||||
}elseif($block instanceof Skull && $newBlock instanceof Skull){
|
||||
$newBlock->setSkullType($block->getSkullType());
|
||||
}
|
||||
|
||||
self::assertSame($block->getStateId(), $newBlock->getStateId(), "Mismatch of blockstate for " . $block->getName() . ", " . print_r($block, true) . " vs " . print_r($newBlock, true));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user