deduplicate weighted pressure plate deserializer code

This commit is contained in:
Dylan K. Taylor 2022-01-31 20:45:33 +00:00
parent cdafb1b0c4
commit a91e7f7202
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 8 additions and 8 deletions

View File

@ -510,10 +510,7 @@ final class BlockStateDeserializer{
//TODO: intentionally ignored "deprecated" blockstate (useless) //TODO: intentionally ignored "deprecated" blockstate (useless)
return VanillaBlocks::HAY_BALE()->setAxis($in->readPillarAxis()); return VanillaBlocks::HAY_BALE()->setAxis($in->readPillarAxis());
}); });
$this->map(Ids::HEAVY_WEIGHTED_PRESSURE_PLATE, function(BlockStateReader $in) : Block{ $this->map(Ids::HEAVY_WEIGHTED_PRESSURE_PLATE, fn(BlockStateReader $in) => Helper::decodeWeightedPressurePlate(VanillaBlocks::WEIGHTED_PRESSURE_PLATE_HEAVY(), $in));
return VanillaBlocks::WEIGHTED_PRESSURE_PLATE_HEAVY()
->setOutputSignalStrength($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15));
});
$this->map(Ids::HOPPER, function(BlockStateReader $in) : Block{ $this->map(Ids::HOPPER, function(BlockStateReader $in) : Block{
return VanillaBlocks::HOPPER() return VanillaBlocks::HOPPER()
->setFacing($in->readFacingWithoutUp()) ->setFacing($in->readFacingWithoutUp())
@ -589,10 +586,7 @@ final class BlockStateDeserializer{
}); });
}); });
$this->map(Ids::LIGHT_BLUE_GLAZED_TERRACOTTA, fn(BlockStateReader $in) => Helper::decodeGlazedTerracotta(VanillaBlocks::LIGHT_BLUE_GLAZED_TERRACOTTA(), $in)); $this->map(Ids::LIGHT_BLUE_GLAZED_TERRACOTTA, fn(BlockStateReader $in) => Helper::decodeGlazedTerracotta(VanillaBlocks::LIGHT_BLUE_GLAZED_TERRACOTTA(), $in));
$this->map(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE, function(BlockStateReader $in) : Block{ $this->map(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE, fn(BlockStateReader $in) => Helper::decodeWeightedPressurePlate(VanillaBlocks::WEIGHTED_PRESSURE_PLATE_LIGHT(), $in));
return VanillaBlocks::WEIGHTED_PRESSURE_PLATE_LIGHT()
->setOutputSignalStrength($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15));
});
$this->map(Ids::LIME_GLAZED_TERRACOTTA, fn(BlockStateReader $in) => Helper::decodeGlazedTerracotta(VanillaBlocks::LIME_GLAZED_TERRACOTTA(), $in)); $this->map(Ids::LIME_GLAZED_TERRACOTTA, fn(BlockStateReader $in) => Helper::decodeGlazedTerracotta(VanillaBlocks::LIME_GLAZED_TERRACOTTA(), $in));
$this->map(Ids::LIT_BLAST_FURNACE, function(BlockStateReader $in) : Block{ $this->map(Ids::LIT_BLAST_FURNACE, function(BlockStateReader $in) : Block{
return VanillaBlocks::BLAST_FURNACE() return VanillaBlocks::BLAST_FURNACE()

View File

@ -46,6 +46,7 @@ use pocketmine\block\VanillaBlocks;
use pocketmine\block\Wall; use pocketmine\block\Wall;
use pocketmine\block\WallCoralFan; use pocketmine\block\WallCoralFan;
use pocketmine\block\WallSign; use pocketmine\block\WallSign;
use pocketmine\block\WeightedPressurePlate;
use pocketmine\data\bedrock\blockstate\BlockStateStringValues as StringValues; use pocketmine\data\bedrock\blockstate\BlockStateStringValues as StringValues;
use pocketmine\data\bedrock\MushroomBlockTypeIdMap; use pocketmine\data\bedrock\MushroomBlockTypeIdMap;
use pocketmine\math\Axis; use pocketmine\math\Axis;
@ -209,6 +210,11 @@ final class BlockStateDeserializerHelper{
->setFacing($in->readHorizontalFacing()); ->setFacing($in->readHorizontalFacing());
} }
public static function decodeWeightedPressurePlate(WeightedPressurePlate $block, BlockStateReader $in) : WeightedPressurePlate{
return $block
->setOutputSignalStrength($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15));
}
/** @throws BlockStateDeserializeException */ /** @throws BlockStateDeserializeException */
public static function mapStoneSlab1Type(BlockStateReader $in) : Slab{ public static function mapStoneSlab1Type(BlockStateReader $in) : Slab{
//* stone_slab_type (StringTag) = brick, cobblestone, nether_brick, quartz, sandstone, smooth_stone, stone_brick, wood //* stone_slab_type (StringTag) = brick, cobblestone, nether_brick, quartz, sandstone, smooth_stone, stone_brick, wood