Implement Chiseled Bookshelf (#5827)

This commit is contained in:
HimmelKreis4865
2023-09-28 16:56:46 +02:00
committed by GitHub
parent a6b030f2b3
commit d94391af57
14 changed files with 313 additions and 2 deletions

View File

@@ -51,6 +51,7 @@ use pocketmine\block\CaveVines;
use pocketmine\block\Chain;
use pocketmine\block\ChemistryTable;
use pocketmine\block\Chest;
use pocketmine\block\ChiseledBookshelf;
use pocketmine\block\ChorusFlower;
use pocketmine\block\CocoaBlock;
use pocketmine\block\Concrete;
@@ -1115,6 +1116,15 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
return Writer::create(Ids::CHEST)
->writeHorizontalFacing($block->getFacing());
});
$this->map(Blocks::CHISELED_BOOKSHELF(), function(ChiseledBookshelf $block) : Writer{
$flags = 0;
foreach($block->getSlots() as $slot){
$flags |= 1 << $slot->value;
}
return Writer::create(Ids::CHISELED_BOOKSHELF)
->writeLegacyHorizontalFacing($block->getFacing())
->writeInt(StateNames::BOOKS_STORED, $flags);
});
$this->map(Blocks::CHISELED_QUARTZ(), fn(SimplePillar $block) => Helper::encodeQuartz(StringValues::CHISEL_TYPE_CHISELED, $block->getAxis()));
$this->map(Blocks::CHISELED_RED_SANDSTONE(), fn() => Helper::encodeSandstone(Ids::RED_SANDSTONE, StringValues::SAND_STONE_TYPE_HEIROGLYPHS));
$this->map(Blocks::CHISELED_SANDSTONE(), fn() => Helper::encodeSandstone(Ids::SANDSTONE, StringValues::SAND_STONE_TYPE_HEIROGLYPHS));

View File

@@ -34,6 +34,7 @@ use pocketmine\block\Slab;
use pocketmine\block\Stair;
use pocketmine\block\SweetBerryBush;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\ChiseledBookshelfSlot;
use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DirtType;
@@ -992,6 +993,18 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
return Blocks::CHAIN()
->setAxis($in->readPillarAxis());
});
$this->map(Ids::CHISELED_BOOKSHELF, function(Reader $in) : Block{
$block = Blocks::CHISELED_BOOKSHELF()
->setFacing($in->readLegacyHorizontalFacing());
//we don't use API constant for bounds here as the data bounds might be different to what we support internally
$flags = $in->readBoundedInt(StateNames::BOOKS_STORED, 0, (1 << 6) - 1);
foreach(ChiseledBookshelfSlot::cases() as $slot){
$block->setSlot($slot, ($flags & (1 << $slot->value)) !== 0);
}
return $block;
});
$this->map(Ids::CHEMISTRY_TABLE, function(Reader $in) : Block{
return (match($type = $in->readString(StateNames::CHEMISTRY_TABLE_TYPE)){
StringValues::CHEMISTRY_TABLE_TYPE_COMPOUND_CREATOR => Blocks::COMPOUND_CREATOR(),

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\runtime;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\ChiseledBookshelfSlot;
use pocketmine\block\utils\WallConnectionType;
use pocketmine\math\Facing;
@@ -78,6 +79,12 @@ interface RuntimeDataDescriber extends RuntimeEnumDescriber{
public function straightOnlyRailShape(int &$railShape) : void;
/**
* @param ChiseledBookshelfSlot[] $slots
* @phpstan-param array<int, ChiseledBookshelfSlot> $slots
*/
public function chiseledBookshelfSlots(array &$slots) : void;
/**
* @phpstan-template T of \UnitEnum
* @phpstan-param T $case

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\runtime;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\ChiseledBookshelfSlot;
use pocketmine\block\utils\RailConnectionInfo;
use pocketmine\block\utils\WallConnectionType;
use pocketmine\math\Axis;
@@ -211,6 +212,20 @@ final class RuntimeDataReader implements RuntimeDataDescriber{
$railShape = $result;
}
/**
* @param ChiseledBookshelfSlot[] $slots
* @phpstan-param array<int, ChiseledBookshelfSlot> $slots
*/
public function chiseledBookshelfSlots(array &$slots) : void{
$result = [];
foreach(ChiseledBookshelfSlot::cases() as $member){
if($this->readBool()){
$result[spl_object_id($member)] = $member;
}
}
$slots = $result;
}
public function enum(\UnitEnum &$case) : void{
$metadata = RuntimeEnumMetadata::from($case);
$raw = $this->readInt($metadata->bits);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\runtime;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\ChiseledBookshelfSlot;
use pocketmine\math\Facing;
use function count;
@@ -96,6 +97,10 @@ final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{
$this->addBits(3);
}
public function chiseledBookshelfSlots(array &$slots) : void{
$this->addBits(count(ChiseledBookshelfSlot::cases()));
}
public function enum(\UnitEnum &$case) : void{
$metadata = RuntimeEnumMetadata::from($case);
$this->addBits($metadata->bits);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\data\runtime;
use pocketmine\block\utils\BrewingStandSlot;
use pocketmine\block\utils\ChiseledBookshelfSlot;
use pocketmine\block\utils\WallConnectionType;
use pocketmine\math\Axis;
use pocketmine\math\Facing;
@@ -174,6 +175,16 @@ final class RuntimeDataWriter implements RuntimeDataDescriber{
$this->int(3, $railShape);
}
/**
* @param ChiseledBookshelfSlot[] $slots
* @phpstan-param array<int, ChiseledBookshelfSlot> $slots
*/
public function chiseledBookshelfSlots(array &$slots) : void{
foreach(ChiseledBookshelfSlot::cases() as $member){
$this->writeBool(isset($slots[spl_object_id($member)]));
}
}
public function enum(\UnitEnum &$case) : void{
$metadata = RuntimeEnumMetadata::from($case);
$this->writeInt($metadata->bits, $metadata->enumToInt($case));