Added rooted dirt

This commit is contained in:
Dylan K. Taylor
2022-07-23 15:57:37 +01:00
parent bedf79e2cd
commit a7313ed9d9
11 changed files with 124 additions and 20 deletions

View File

@ -132,6 +132,7 @@ use pocketmine\block\TripwireHook;
use pocketmine\block\UnderwaterTorch;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DirtType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\LeverFacing;
use pocketmine\block\VanillaBlocks as Blocks;
@ -886,8 +887,16 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
$this->mapStairs(Blocks::DIORITE_STAIRS(), Ids::DIORITE_STAIRS);
$this->map(Blocks::DIORITE_WALL(), fn(Wall $block) => Helper::encodeLegacyWall($block, StringValues::WALL_BLOCK_TYPE_DIORITE));
$this->map(Blocks::DIRT(), function(Dirt $block) : Writer{
$dirtType = $block->getDirtType();
if($dirtType->equals(DirtType::ROOTED())){
return new Writer(Ids::DIRT_WITH_ROOTS);
}
return Writer::create(Ids::DIRT)
->writeString(StateNames::DIRT_TYPE, $block->isCoarse() ? StringValues::DIRT_TYPE_COARSE : StringValues::DIRT_TYPE_NORMAL);
->writeString(StateNames::DIRT_TYPE, match($dirtType){
DirtType::COARSE() => StringValues::DIRT_TYPE_COARSE,
DirtType::NORMAL() => StringValues::DIRT_TYPE_NORMAL,
default => throw new AssumptionFailedError("Unhandled dirt type " . $dirtType->name())
});
});
$this->map(Blocks::DOUBLE_TALLGRASS(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_GRASS, Writer::create(Ids::DOUBLE_PLANT)));
$this->map(Blocks::DYED_SHULKER_BOX(), function(DyedShulkerBox $block) : Writer{

View File

@ -33,6 +33,7 @@ use pocketmine\block\SweetBerryBush;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DirtType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\LeverFacing;
use pocketmine\block\utils\SlabType;
@ -641,12 +642,13 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
$this->mapStairs(Ids::DIORITE_STAIRS, fn() => Blocks::DIORITE_STAIRS());
$this->map(Ids::DIRT, function(Reader $in) : Block{
return Blocks::DIRT()
->setCoarse(match($value = $in->readString(StateNames::DIRT_TYPE)){
StringValues::DIRT_TYPE_NORMAL => false,
StringValues::DIRT_TYPE_COARSE => true,
->setDirtType(match($value = $in->readString(StateNames::DIRT_TYPE)){
StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL(),
StringValues::DIRT_TYPE_COARSE => DirtType::COARSE(),
default => throw $in->badValueException(StateNames::DIRT_TYPE, $value),
});
});
$this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED()));
$this->map(Ids::DOUBLE_PLANT, function(Reader $in) : Block{
return (match($type = $in->readString(StateNames::DOUBLE_PLANT_TYPE)){
StringValues::DOUBLE_PLANT_TYPE_FERN => Blocks::LARGE_FERN(),