From 36211a96c12c8539b7cb895c6bdfec9dad0365d2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 24 Aug 2025 23:24:38 +0100 Subject: [PATCH] Strip deprecated leftovers from #6769 --- src/data/bedrock/MushroomBlockTypeIdMap.php | 44 --- .../convert/BlockObjectToStateSerializer.php | 33 -- .../BlockSerializerDeserializerRegistrar.php | 4 +- .../convert/BlockStateDeserializerHelper.php | 359 ------------------ .../block/convert/BlockStateReader.php | 225 ----------- .../convert/BlockStateSerializerHelper.php | 264 ------------- .../BlockStateToObjectDeserializer.php | 38 -- .../block/convert/BlockStateWriter.php | 225 ----------- 8 files changed, 2 insertions(+), 1190 deletions(-) delete mode 100644 src/data/bedrock/MushroomBlockTypeIdMap.php delete mode 100644 src/data/bedrock/block/convert/BlockStateDeserializerHelper.php delete mode 100644 src/data/bedrock/block/convert/BlockStateSerializerHelper.php diff --git a/src/data/bedrock/MushroomBlockTypeIdMap.php b/src/data/bedrock/MushroomBlockTypeIdMap.php deleted file mode 100644 index 6357d3e14..000000000 --- a/src/data/bedrock/MushroomBlockTypeIdMap.php +++ /dev/null @@ -1,44 +0,0 @@ - */ - use IntSaveIdMapTrait; - - public function __construct(){ - $newMapping = ValueMappings::getInstance()->mushroomBlockType; - foreach(MushroomBlockType::cases() as $case){ - $this->register($newMapping->valueToRaw($case), $case); - } - } -} diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 90f6af97a..d007900e0 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -25,14 +25,9 @@ namespace pocketmine\data\bedrock\block\convert; use pocketmine\block\Block; use pocketmine\block\RuntimeBlockStateRegistry; -use pocketmine\block\Slab; -use pocketmine\block\Stair; -use pocketmine\block\Wood; use pocketmine\data\bedrock\block\BlockStateData; use pocketmine\data\bedrock\block\BlockStateSerializeException; use pocketmine\data\bedrock\block\BlockStateSerializer; -use pocketmine\data\bedrock\block\BlockTypeNames as Ids; -use pocketmine\data\bedrock\block\convert\BlockStateSerializerHelper as Helper; use pocketmine\data\bedrock\block\convert\BlockStateWriter as Writer; use function get_class; @@ -75,34 +70,6 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ $this->serializers[$block->getTypeId()] = $serializer instanceof Writer ? $serializer->getBlockStateData() : $serializer; } - /** - * @deprecated - */ - public function mapSimple(Block $block, string $id) : void{ - $this->map($block, BlockStateData::current($id, [])); - } - - /** - * @deprecated - */ - public function mapSlab(Slab $block, string $singleId, string $doubleId) : void{ - $this->map($block, fn(Slab $block) => Helper::encodeSlab($block, $singleId, $doubleId)); - } - - /** - * @deprecated - */ - public function mapStairs(Stair $block, string $id) : void{ - $this->map($block, fn(Stair $block) => Helper::encodeStairs($block, Writer::create($id))); - } - - /** - * @deprecated - */ - public function mapLog(Wood $block, string $unstrippedId, string $strippedId) : void{ - $this->map($block, fn(Wood $block) => Helper::encodeLog($block, $unstrippedId, $strippedId)); - } - /** * @phpstan-template TBlockType of Block * @phpstan-param TBlockType $blockState diff --git a/src/data/bedrock/block/convert/BlockSerializerDeserializerRegistrar.php b/src/data/bedrock/block/convert/BlockSerializerDeserializerRegistrar.php index 02491bae6..5fc1d3eef 100644 --- a/src/data/bedrock/block/convert/BlockSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/block/convert/BlockSerializerDeserializerRegistrar.php @@ -121,8 +121,8 @@ final class BlockSerializerDeserializerRegistrar{ } public function mapSimple(Block $block, string $id) : void{ - $this->deserializer->mapSimple($id, fn() => clone $block); - $this->serializer->mapSimple($block, $id); + $this->deserializer->map($id, fn() => clone $block); + $this->serializer->map($block, BlockStateData::current($id, [])); } /** diff --git a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php deleted file mode 100644 index 1d48ec76f..000000000 --- a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php +++ /dev/null @@ -1,359 +0,0 @@ -setFacing($in->readFacingDirection()) - ->setPressed($in->readBool(BlockStateNames::BUTTON_PRESSED_BIT)); - } - - /** - * @deprecated - * @phpstan-template TCandle of Candle - * @phpstan-param TCandle $block - * @phpstan-return TCandle - * - * @throws BlockStateDeserializeException - */ - public static function decodeCandle(Candle $block, BlockStateReader $in) : Candle{ - return $block - ->setCount($in->readBoundedInt(StateNames::CANDLES, 0, 3) + 1) - ->setLit($in->readBool(StateNames::LIT)); - } - - /** - * @phpstan-template TCrops of Crops - * @phpstan-param TCrops $block - * @phpstan-return TCrops - * - * @throws BlockStateDeserializeException - */ - public static function decodeCrops(Crops $block, BlockStateReader $in) : Crops{ - return $block->setAge($in->readBoundedInt(BlockStateNames::GROWTH, 0, 7)); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeComparator(RedstoneComparator $block, BlockStateReader $in) : RedstoneComparator{ - return $block - ->setFacing($in->readCardinalHorizontalFacing()) - ->setPowered($in->readBool(BlockStateNames::OUTPUT_LIT_BIT)) - ->setSubtractMode($in->readBool(BlockStateNames::OUTPUT_SUBTRACT_BIT)); - } - - /** - * @deprecated - * @phpstan-template TBlock of CopperMaterial - * - * @phpstan-param TBlock $block - * @phpstan-return TBlock - */ - public static function decodeCopper(CopperMaterial $block, CopperOxidation $oxidation) : CopperMaterial{ - $block->setOxidation($oxidation); - $block->setWaxed(false); - return $block; - } - - /** - * @deprecated - * @phpstan-template TBlock of CopperMaterial - * - * @phpstan-param TBlock $block - * @phpstan-return TBlock - */ - public static function decodeWaxedCopper(CopperMaterial $block, CopperOxidation $oxidation) : CopperMaterial{ - $block->setOxidation($oxidation); - $block->setWaxed(true); - return $block; - } - - /** @throws BlockStateDeserializeException */ - public static function decodeDaylightSensor(DaylightSensor $block, BlockStateReader $in) : DaylightSensor{ - return $block - ->setOutputSignalStrength($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15)); - } - - /** - * @deprecated - * @phpstan-template TDoor of Door - * @phpstan-param TDoor $block - * @phpstan-return TDoor - * - * @throws BlockStateDeserializeException - */ - public static function decodeDoor(Door $block, BlockStateReader $in) : Door{ - //TODO: check if these need any special treatment to get the appropriate data to both halves of the door - return $block - ->setTop($in->readBool(BlockStateNames::UPPER_BLOCK_BIT)) - //a door facing "east" is actually facing north - thanks mojang - ->setFacing(Facing::rotateY($in->readCardinalHorizontalFacing(), clockwise: false)) - ->setHingeRight($in->readBool(BlockStateNames::DOOR_HINGE_BIT)) - ->setOpen($in->readBool(BlockStateNames::OPEN_BIT)); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeDoublePlant(DoublePlant $block, BlockStateReader $in) : DoublePlant{ - return $block - ->setTop($in->readBool(BlockStateNames::UPPER_BLOCK_BIT)); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public static function decodeFenceGate(FenceGate $block, BlockStateReader $in) : FenceGate{ - return $block - ->setFacing($in->readCardinalHorizontalFacing()) - ->setInWall($in->readBool(BlockStateNames::IN_WALL_BIT)) - ->setOpen($in->readBool(BlockStateNames::OPEN_BIT)); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public static function decodeFloorCoralFan(FloorCoralFan $block, BlockStateReader $in) : FloorCoralFan{ - return $block - ->setAxis($in->mapIntFromInt(BlockStateNames::CORAL_FAN_DIRECTION, ValueMappings::getInstance()->coralAxis)); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public static function decodeFloorSign(FloorSign $block, BlockStateReader $in) : FloorSign{ - return $block - ->setRotation($in->readBoundedInt(BlockStateNames::GROUND_SIGN_DIRECTION, 0, 15)); - } - - public static function decodeItemFrame(ItemFrame $block, BlockStateReader $in) : ItemFrame{ - $in->todo(StateNames::ITEM_FRAME_PHOTO_BIT); //TODO: not sure what the point of this is - return $block - ->setFacing($in->readFacingDirection()) - ->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT)); - } - - /** - * @throws BlockStateDeserializeException - * @deprecated - */ - public static function decodeLeaves(Leaves $block, BlockStateReader $in) : Leaves{ - return $block - ->setNoDecay($in->readBool(StateNames::PERSISTENT_BIT)) - ->setCheckDecay($in->readBool(StateNames::UPDATE_BIT)); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeLiquid(Liquid $block, BlockStateReader $in, bool $still) : Liquid{ - $fluidHeightState = $in->readBoundedInt(BlockStateNames::LIQUID_DEPTH, 0, 15); - return $block - ->setDecay($fluidHeightState & 0x7) - ->setFalling(($fluidHeightState & 0x8) !== 0) - ->setStill($still); - } - - public static function decodeFlowingLiquid(Liquid $block, BlockStateReader $in) : Liquid{ - return self::decodeLiquid($block, $in, false); - } - - public static function decodeStillLiquid(Liquid $block, BlockStateReader $in) : Liquid{ - return self::decodeLiquid($block, $in, true); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeLog(Wood $block, bool $stripped, BlockStateReader $in) : Wood{ - return $block - ->setAxis($in->readPillarAxis()) - ->setStripped($stripped); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeMushroomBlock(RedMushroomBlock $block, BlockStateReader $in) : Block{ - switch($type = $in->readBoundedInt(BlockStateNames::HUGE_MUSHROOM_BITS, 0, 15)){ - case BlockLegacyMetadata::MUSHROOM_BLOCK_ALL_STEM: - case BlockLegacyMetadata::MUSHROOM_BLOCK_STEM: throw new BlockStateDeserializeException("This state does not exist"); - default: - //invalid types get left as default - $type = MushroomBlockTypeIdMap::getInstance()->fromId($type); - return $type !== null ? $block->setMushroomBlockType($type) : $block; - } - } - - /** @throws BlockStateDeserializeException */ - public static function decodeRepeater(RedstoneRepeater $block, BlockStateReader $in) : RedstoneRepeater{ - return $block - ->setFacing($in->readCardinalHorizontalFacing()) - ->setDelay($in->readBoundedInt(BlockStateNames::REPEATER_DELAY, 0, 3) + 1); - } - - /** - * @throws BlockStateDeserializeException - * @deprecated - */ - public static function decodeSapling(Sapling $block, BlockStateReader $in) : Sapling{ - return $block - ->setReady($in->readBool(BlockStateNames::AGE_BIT)); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeSimplePressurePlate(SimplePressurePlate $block, BlockStateReader $in) : SimplePressurePlate{ - //TODO: not sure what the deal is here ... seems like a mojang bug / artifact of bad implementation? - //best to keep this separate from weighted plates anyway... - return $block->setPressed($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15) !== 0); - } - - /** - * @phpstan-template TSlab of Slab - * @phpstan-param TSlab $block - * @phpstan-return TSlab - * - * @throws BlockStateDeserializeException - */ - public static function decodeSingleSlab(Slab $block, BlockStateReader $in) : Slab{ - return $block->setSlabType($in->readSlabPosition()); - } - - /** - * @phpstan-template TSlab of Slab - * @phpstan-param TSlab $block - * @phpstan-return TSlab - * - * @throws BlockStateDeserializeException - */ - public static function decodeDoubleSlab(Slab $block, BlockStateReader $in) : Slab{ - $in->ignored(StateNames::MC_VERTICAL_HALF); - return $block->setSlabType(SlabType::DOUBLE); - } - - /** - * @deprecated - * @phpstan-template TStair of Stair - * @phpstan-param TStair $block - * @phpstan-return TStair - * - * @throws BlockStateDeserializeException - */ - public static function decodeStairs(Stair $block, BlockStateReader $in) : Stair{ - return $block - ->setUpsideDown($in->readBool(BlockStateNames::UPSIDE_DOWN_BIT)) - ->setFacing($in->readWeirdoHorizontalFacing()); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeStem(Stem $block, BlockStateReader $in) : Stem{ - //In PM, we use Facing::UP to indicate that the stem is not attached to a pumpkin/melon, since this makes the - //most intuitive sense (the stem is pointing at the sky). However, Bedrock uses the DOWN state for this, which - //is absurd, and I refuse to make our API similarly absurd. - $facing = $in->readFacingWithoutUp(); - return self::decodeCrops($block, $in) - ->setFacing($facing === Facing::DOWN ? Facing::UP : $facing); - } - - /** - * @deprecated - * @phpstan-template TTrapdoor of Trapdoor - * @phpstan-param TTrapdoor $block - * @phpstan-return TTrapdoor - * - * @throws BlockStateDeserializeException - */ - public static function decodeTrapdoor(Trapdoor $block, BlockStateReader $in) : Trapdoor{ - return $block - ->setFacing($in->read5MinusHorizontalFacing()) - ->setTop($in->readBool(BlockStateNames::UPSIDE_DOWN_BIT)) - ->setOpen($in->readBool(BlockStateNames::OPEN_BIT)); - } - - /** @throws BlockStateDeserializeException */ - public static function decodeWall(Wall $block, BlockStateReader $in) : Wall{ - $block->setPost($in->readBool(BlockStateNames::WALL_POST_BIT)); - $block->setConnection(Facing::NORTH, $in->readWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_NORTH)); - $block->setConnection(Facing::SOUTH, $in->readWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_SOUTH)); - $block->setConnection(Facing::WEST, $in->readWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_WEST)); - $block->setConnection(Facing::EAST, $in->readWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_EAST)); - - return $block; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public static function decodeWallSign(WallSign $block, BlockStateReader $in) : WallSign{ - return $block - ->setFacing($in->readHorizontalFacing()); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public static function decodeWeightedPressurePlate(WeightedPressurePlate $block, BlockStateReader $in) : WeightedPressurePlate{ - return $block - ->setOutputSignalStrength($in->readBoundedInt(BlockStateNames::REDSTONE_SIGNAL, 0, 15)); - } -} diff --git a/src/data/bedrock/block/convert/BlockStateReader.php b/src/data/bedrock/block/convert/BlockStateReader.php index 4d09d2f85..adcdf9709 100644 --- a/src/data/bedrock/block/convert/BlockStateReader.php +++ b/src/data/bedrock/block/convert/BlockStateReader.php @@ -23,19 +23,8 @@ declare(strict_types=1); namespace pocketmine\data\bedrock\block\convert; -use pocketmine\block\utils\BellAttachmentType; -use pocketmine\block\utils\SlabType; -use pocketmine\block\utils\WallConnectionType; -use pocketmine\data\bedrock\block\BlockLegacyMetadata; use pocketmine\data\bedrock\block\BlockStateData; use pocketmine\data\bedrock\block\BlockStateDeserializeException; -use pocketmine\data\bedrock\block\BlockStateNames; -use pocketmine\data\bedrock\block\BlockStateStringValues as StringValues; -use pocketmine\data\bedrock\block\convert\property\EnumFromRawStateMap; -use pocketmine\data\bedrock\block\convert\property\IntFromRawStateMap; -use pocketmine\data\bedrock\block\convert\property\ValueMappings; -use pocketmine\math\Axis; -use pocketmine\math\Facing; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; @@ -114,220 +103,6 @@ final class BlockStateReader{ throw $this->missingOrWrongTypeException($name, $tag); } - /** - * @deprecated - * @phpstan-param IntFromRawStateMap $map - * @throws BlockStateDeserializeException - */ - public function mapIntFromString(string $name, IntFromRawStateMap $map) : int{ - $raw = $this->readString($name); - - return $map->rawToValue($raw) ?? throw $this->badValueException($name, $raw); - } - - /** - * @deprecated - * @phpstan-param IntFromRawStateMap $map - * @throws BlockStateDeserializeException - */ - public function mapIntFromInt(string $name, IntFromRawStateMap $map) : int{ - $raw = $this->readInt($name); - - return $map->rawToValue($raw) ?? throw $this->badValueException($name, (string) $raw); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readFacingDirection() : int{ - return $this->mapIntFromInt(BlockStateNames::FACING_DIRECTION, ValueMappings::getInstance()->facing); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readBlockFace() : int{ - return $this->mapIntFromString(BlockStateNames::MC_BLOCK_FACE, ValueMappings::getInstance()->blockFace); - } - - /** - * @deprecated - * @return int[] - * @phpstan-return array - */ - public function readFacingFlags() : array{ - $result = []; - $flags = $this->readBoundedInt(BlockStateNames::MULTI_FACE_DIRECTION_BITS, 0, 63); - foreach([ - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_DOWN => Facing::DOWN, - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_UP => Facing::UP, - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_NORTH => Facing::NORTH, - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_SOUTH => Facing::SOUTH, - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_WEST => Facing::WEST, - BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_EAST => Facing::EAST - ] as $flag => $facing){ - if(($flags & $flag) !== 0){ - $result[$facing] = $facing; - } - } - - return $result; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readEndRodFacingDirection() : int{ - $result = $this->readFacingDirection(); - return Facing::axis($result) !== Axis::Y ? Facing::opposite($result) : $result; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readHorizontalFacing() : int{ - return $this->mapIntFromInt(BlockStateNames::FACING_DIRECTION, ValueMappings::getInstance()->horizontalFacingClassic); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readWeirdoHorizontalFacing() : int{ - return $this->mapIntFromInt(BlockStateNames::WEIRDO_DIRECTION, ValueMappings::getInstance()->horizontalFacing5Minus); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readLegacyHorizontalFacing() : int{ - return $this->mapIntFromInt(BlockStateNames::DIRECTION, ValueMappings::getInstance()->horizontalFacingSWNE); - } - - /** - * @deprecated - * This is for trapdoors, because Mojang botched the conversion in 1.13 - * @throws BlockStateDeserializeException - */ - public function read5MinusHorizontalFacing() : int{ - return $this->mapIntFromInt(BlockStateNames::DIRECTION, ValueMappings::getInstance()->horizontalFacing5Minus); - } - - /** - * @deprecated - * Used by pumpkins as of 1.20.0.23 beta - * @throws BlockStateDeserializeException - */ - public function readCardinalHorizontalFacing() : int{ - return $this->mapIntFromString(BlockStateNames::MC_CARDINAL_DIRECTION, ValueMappings::getInstance()->cardinalDirection); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readCoralFacing() : int{ - return $this->mapIntFromInt(BlockStateNames::CORAL_DIRECTION, ValueMappings::getInstance()->horizontalFacingCoral); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readFacingWithoutDown() : int{ - $result = $this->readFacingDirection(); - if($result === Facing::DOWN){ //shouldn't be legal, but 1.13 allows it - $result = Facing::UP; - } - return $result; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readFacingWithoutUp() : int{ - $result = $this->readFacingDirection(); - if($result === Facing::UP){ - $result = Facing::DOWN; //shouldn't be legal, but 1.13 allows it - } - return $result; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readPillarAxis() : int{ - return $this->mapIntFromString(BlockStateNames::PILLAR_AXIS, ValueMappings::getInstance()->pillarAxis); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readSlabPosition() : SlabType{ - return match($rawValue = $this->readString(BlockStateNames::MC_VERTICAL_HALF)){ - StringValues::MC_VERTICAL_HALF_BOTTOM => SlabType::BOTTOM, - StringValues::MC_VERTICAL_HALF_TOP => SlabType::TOP, - default => throw $this->badValueException(BlockStateNames::MC_VERTICAL_HALF, $rawValue, "Invalid slab position"), - }; - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readTorchFacing() : int{ - return $this->mapIntFromString(BlockStateNames::TORCH_FACING_DIRECTION, ValueMappings::getInstance()->torchFacing); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readBellAttachmentType() : BellAttachmentType{ - return $this->readUnitEnum(BlockStateNames::ATTACHMENT, ValueMappings::getInstance()->bellAttachmentType); - } - - /** - * @deprecated - * @throws BlockStateDeserializeException - */ - public function readWallConnectionType(string $name) : ?WallConnectionType{ - return match($type = $this->readString($name)){ - //TODO: this looks a bit confusing due to use of EAST, but the values are the same for all connections - //we need to find a better way to auto-generate the constant names when they are reused - //for now, using these constants is better than nothing since it still gives static analysability - StringValues::WALL_CONNECTION_TYPE_EAST_NONE => null, - StringValues::WALL_CONNECTION_TYPE_EAST_SHORT => WallConnectionType::SHORT, - StringValues::WALL_CONNECTION_TYPE_EAST_TALL => WallConnectionType::TALL, - default => throw $this->badValueException($name, $type), - }; - } - - /** - * @deprecated - * @phpstan-template TEnum of \UnitEnum - * @phpstan-param EnumFromRawStateMap $map - * @phpstan-return TEnum - * @throws BlockStateDeserializeException - */ - public function readUnitEnum(string $name, EnumFromRawStateMap $map) : \UnitEnum{ - $value = $this->readString($name); - - $mapped = $map->rawToValue($value); - if($mapped === null){ - throw $this->badValueException($name, $value); - } - return $mapped; - } - /** * Explicitly mark a property as unused, so it doesn't get flagged as an error when debug mode is enabled */ diff --git a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php b/src/data/bedrock/block/convert/BlockStateSerializerHelper.php deleted file mode 100644 index da3dbb387..000000000 --- a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php +++ /dev/null @@ -1,264 +0,0 @@ -writeFacingDirection($block->getFacing()) - ->writeBool(BlockStateNames::BUTTON_PRESSED_BIT, $block->isPressed()); - } - - public static function encodeCandle(Candle $block, Writer $out) : Writer{ - return $out - ->writeBool(StateNames::LIT, $block->isLit()) - ->writeInt(StateNames::CANDLES, $block->getCount() - 1); - } - - public static function encodeChemistryTable(ChemistryTable $block, Writer $out) : Writer{ - return $out - ->writeLegacyHorizontalFacing(Facing::opposite($block->getFacing())); - } - - public static function encodeCrops(Crops $block, Writer $out) : Writer{ - return $out->writeInt(BlockStateNames::GROWTH, $block->getAge()); - } - - /** - * @deprecated - */ - public static function encodeTorch(Torch $block, Writer $out) : Writer{ - return $out - ->writeTorchFacing($block->getFacing()); - } - - public static function encodeCauldron(string $liquid, int $fillLevel) : Writer{ - return Writer::create(Ids::CAULDRON) - ->writeString(BlockStateNames::CAULDRON_LIQUID, $liquid) - ->writeInt(BlockStateNames::FILL_LEVEL, $fillLevel); - } - - public static function selectCopperId(CopperOxidation $oxidation, string $noneId, string $exposedId, string $weatheredId, string $oxidizedId) : string{ - return match($oxidation){ - CopperOxidation::NONE => $noneId, - CopperOxidation::EXPOSED => $exposedId, - CopperOxidation::WEATHERED => $weatheredId, - CopperOxidation::OXIDIZED => $oxidizedId, - }; - } - - /** - * @deprecated - */ - public static function encodeDoor(Door $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop()) - //a door facing north is encoded as "east" - ->writeCardinalHorizontalFacing(Facing::rotateY($block->getFacing(), clockwise: true)) - ->writeBool(BlockStateNames::DOOR_HINGE_BIT, $block->isHingeRight()) - ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen()); - } - - public static function encodeDoublePlant(DoublePlant $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop()); - } - - /** - * @deprecated - */ - public static function encodeFenceGate(FenceGate $block, Writer $out) : Writer{ - return $out - ->writeCardinalHorizontalFacing($block->getFacing()) - ->writeBool(BlockStateNames::IN_WALL_BIT, $block->isInWall()) - ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen()); - } - - /** - * @deprecated - */ - public static function encodeFloorSign(FloorSign $block, Writer $out) : Writer{ - return $out - ->writeInt(BlockStateNames::GROUND_SIGN_DIRECTION, $block->getRotation()); - } - - public static function encodeFurnace(Furnace $block, string $unlitId, string $litId) : Writer{ - return Writer::create($block->isLit() ? $litId : $unlitId) - ->writeCardinalHorizontalFacing($block->getFacing()); - } - - public static function encodeItemFrame(ItemFrame $block, string $id) : Writer{ - return Writer::create($id) - ->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap()) - ->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT, false) - ->writeFacingDirection($block->getFacing()); - } - - /** - * @deprecated - */ - public static function encodeLeaves(Leaves $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::PERSISTENT_BIT, $block->isNoDecay()) - ->writeBool(BlockStateNames::UPDATE_BIT, $block->isCheckDecay()); - } - - public static function encodeLiquid(Liquid $block, string $stillId, string $flowingId) : Writer{ - return Writer::create($block->isStill() ? $stillId : $flowingId) - ->writeInt(BlockStateNames::LIQUID_DEPTH, $block->getDecay() | ($block->isFalling() ? 0x8 : 0)); - } - - public static function encodeLog(Wood $block, string $unstrippedId, string $strippedId) : Writer{ - $out = $block->isStripped() ? - Writer::create($strippedId) : - Writer::create($unstrippedId); - return $out - ->writePillarAxis($block->getAxis()); - } - - public static function encodeMushroomBlock(RedMushroomBlock $block, Writer $out) : Writer{ - return $out - ->writeInt(BlockStateNames::HUGE_MUSHROOM_BITS, MushroomBlockTypeIdMap::getInstance()->toId($block->getMushroomBlockType())); - } - - /** - * @deprecated - */ - public static function encodeQuartz(int $axis, Writer $out) : Writer{ - return $out - ->writePillarAxis($axis); //this isn't needed for all types, but we have to write it anyway - } - - /** - * @deprecated - */ - public static function encodeSapling(Sapling $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::AGE_BIT, $block->isReady()); - } - - public static function encodeSimplePressurePlate(SimplePressurePlate $block, Writer $out) : Writer{ - //TODO: not sure what the deal is here ... seems like a mojang bug / artifact of bad implementation? - //best to keep this separate from weighted plates anyway... - return $out - ->writeInt(BlockStateNames::REDSTONE_SIGNAL, $block->isPressed() ? 15 : 0); - } - - private static function encodeSingleSlab(Slab $block, string $id) : Writer{ - return Writer::create($id) - ->writeSlabPosition($block->getSlabType()); - } - - private static function encodeDoubleSlab(Slab $block, string $id) : Writer{ - return Writer::create($id) - //this is (intentionally) also written for double slabs (as zero) to maintain bug parity with MCPE - ->writeSlabPosition(SlabType::BOTTOM); - } - - public static function encodeSlab(Slab $block, string $singleId, string $doubleId) : Writer{ - return $block->getSlabType() === SlabType::DOUBLE ? - self::encodeDoubleSlab($block, $doubleId) : - self::encodeSingleSlab($block, $singleId); - } - - /** - * @deprecated - */ - public static function encodeStairs(Stair $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isUpsideDown()) - ->writeWeirdoHorizontalFacing($block->getFacing()); - } - - public static function encodeStem(Stem $block, Writer $out) : Writer{ - //In PM, we use Facing::UP to indicate that the stem is not attached to a pumpkin/melon, since this makes the - //most intuitive sense (the stem is pointing at the sky). However, Bedrock uses the DOWN state for this, which - //is absurd, and I refuse to make our API similarly absurd. - $facing = $block->getFacing(); - return self::encodeCrops($block, $out) - ->writeFacingWithoutUp($facing === Facing::UP ? Facing::DOWN : $facing); - } - - /** - * @deprecated - */ - public static function encodeTrapdoor(Trapdoor $block, Writer $out) : Writer{ - return $out - ->write5MinusHorizontalFacing($block->getFacing()) - ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isTop()) - ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen()); - } - - public static function encodeWall(Wall $block, Writer $out) : Writer{ - return $out - ->writeBool(BlockStateNames::WALL_POST_BIT, $block->isPost()) - ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_EAST, $block->getConnection(Facing::EAST)) - ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_NORTH, $block->getConnection(Facing::NORTH)) - ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_SOUTH, $block->getConnection(Facing::SOUTH)) - ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_WEST, $block->getConnection(Facing::WEST)); - } - - /** - * @deprecated - */ - public static function encodeWallSign(WallSign $block, Writer $out) : Writer{ - return $out - ->writeHorizontalFacing($block->getFacing()); - } -} diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index ca5c12412..18d549774 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -25,13 +25,9 @@ namespace pocketmine\data\bedrock\block\convert; use pocketmine\block\Block; use pocketmine\block\RuntimeBlockStateRegistry; -use pocketmine\block\Slab; -use pocketmine\block\Stair; -use pocketmine\block\Wood; use pocketmine\data\bedrock\block\BlockStateData; use pocketmine\data\bedrock\block\BlockStateDeserializeException; use pocketmine\data\bedrock\block\BlockStateDeserializer; -use pocketmine\data\bedrock\block\convert\BlockStateDeserializerHelper as Helper; use pocketmine\data\bedrock\block\convert\BlockStateReader as Reader; use function array_key_exists; use function count; @@ -86,40 +82,6 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return $this->deserializeFuncs[$id] ?? null; } - /** - * @deprecated - * @phpstan-param \Closure() : Block $getBlock - */ - public function mapSimple(string $id, \Closure $getBlock) : void{ - $this->map($id, $getBlock); - } - - /** - * @deprecated - * @phpstan-param \Closure(Reader) : Slab $getBlock - */ - public function mapSlab(string $singleId, string $doubleId, \Closure $getBlock) : void{ - $this->map($singleId, fn(Reader $in) => Helper::decodeSingleSlab($getBlock($in), $in)); - $this->map($doubleId, fn(Reader $in) => Helper::decodeDoubleSlab($getBlock($in), $in)); - } - - /** - * @deprecated - * @phpstan-param \Closure() : Stair $getBlock - */ - public function mapStairs(string $id, \Closure $getBlock) : void{ - $this->map($id, fn(Reader $in) : Stair => Helper::decodeStairs($getBlock(), $in)); - } - - /** - * @deprecated - * @phpstan-param \Closure() : Wood $getBlock - */ - public function mapLog(string $unstrippedId, string $strippedId, \Closure $getBlock) : void{ - $this->map($unstrippedId, fn(Reader $in) => Helper::decodeLog($getBlock(), false, $in)); - $this->map($strippedId, fn(Reader $in) => Helper::decodeLog($getBlock(), true, $in)); - } - /** @throws BlockStateDeserializeException */ public function deserializeBlock(BlockStateData $blockStateData) : Block{ $id = $blockStateData->getName(); diff --git a/src/data/bedrock/block/convert/BlockStateWriter.php b/src/data/bedrock/block/convert/BlockStateWriter.php index 0119bd02e..d58bbd7c3 100644 --- a/src/data/bedrock/block/convert/BlockStateWriter.php +++ b/src/data/bedrock/block/convert/BlockStateWriter.php @@ -23,24 +23,11 @@ declare(strict_types=1); namespace pocketmine\data\bedrock\block\convert; -use pocketmine\block\utils\BellAttachmentType; -use pocketmine\block\utils\SlabType; -use pocketmine\block\utils\WallConnectionType; -use pocketmine\data\bedrock\block\BlockLegacyMetadata; use pocketmine\data\bedrock\block\BlockStateData; -use pocketmine\data\bedrock\block\BlockStateNames; -use pocketmine\data\bedrock\block\BlockStateSerializeException; -use pocketmine\data\bedrock\block\BlockStateStringValues as StringValues; -use pocketmine\data\bedrock\block\convert\property\EnumFromRawStateMap; -use pocketmine\data\bedrock\block\convert\property\IntFromRawStateMap; -use pocketmine\data\bedrock\block\convert\property\ValueMappings; -use pocketmine\math\Axis; -use pocketmine\math\Facing; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\Tag; -use pocketmine\utils\AssumptionFailedError; final class BlockStateWriter{ @@ -76,218 +63,6 @@ final class BlockStateWriter{ return $this; } - /** - * @deprecated - * @phpstan-param IntFromRawStateMap $map - * @return $this - */ - public function mapIntToString(string $name, IntFromRawStateMap $map, int $value) : self{ - $raw = $map->valueToRaw($value); - $this->writeString($name, $raw); - return $this; - } - - /** - * @deprecated - * @phpstan-param IntFromRawStateMap $map - * @return $this - */ - public function mapIntToInt(string $name, IntFromRawStateMap $map, int $value) : self{ - $raw = $map->valueToRaw($value); - $this->writeInt($name, $raw); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writeFacingDirection(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::FACING_DIRECTION, ValueMappings::getInstance()->facing, $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeBlockFace(int $value) : self{ - $this->mapIntToString(BlockStateNames::MC_BLOCK_FACE, ValueMappings::getInstance()->blockFace, $value); - return $this; - } - - /** - * @deprecated - * @param int[] $faces - * @phpstan-param array $faces - * @return $this - */ - public function writeFacingFlags(array $faces) : self{ - $result = 0; - foreach($faces as $face){ - $result |= match($face){ - Facing::DOWN => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_DOWN, - Facing::UP => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_UP, - Facing::NORTH => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_NORTH, - Facing::SOUTH => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_SOUTH, - Facing::WEST => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_WEST, - Facing::EAST => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_EAST, - default => throw new AssumptionFailedError("Unhandled face $face") - }; - } - - return $this->writeInt(BlockStateNames::MULTI_FACE_DIRECTION_BITS, $result); - } - - /** - * @deprecated - * @return $this - */ - public function writeEndRodFacingDirection(int $value) : self{ - //end rods are stupid in bedrock and have everything except up/down the wrong way round - return $this->writeFacingDirection(Facing::axis($value) !== Axis::Y ? Facing::opposite($value) : $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeHorizontalFacing(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::FACING_DIRECTION, ValueMappings::getInstance()->horizontalFacingClassic, $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeWeirdoHorizontalFacing(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::WEIRDO_DIRECTION, ValueMappings::getInstance()->horizontalFacing5Minus, $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeLegacyHorizontalFacing(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::DIRECTION, ValueMappings::getInstance()->horizontalFacingSWNE, $value); - } - - /** - * @deprecated - * This is for trapdoors, because Mojang botched the conversion in 1.13 - * @return $this - */ - public function write5MinusHorizontalFacing(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::DIRECTION, ValueMappings::getInstance()->horizontalFacing5Minus, $value); - } - - /** - * @deprecated - * Used by pumpkins as of 1.20.0.23 beta - * @return $this - */ - public function writeCardinalHorizontalFacing(int $value) : self{ - return $this->mapIntToString(BlockStateNames::MC_CARDINAL_DIRECTION, ValueMappings::getInstance()->cardinalDirection, $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeCoralFacing(int $value) : self{ - return $this->mapIntToInt(BlockStateNames::CORAL_DIRECTION, ValueMappings::getInstance()->horizontalFacingCoral, $value); - } - - /** - * @deprecated - * @return $this - */ - public function writeFacingWithoutDown(int $value) : self{ - if($value === Facing::DOWN){ - throw new BlockStateSerializeException("Invalid facing DOWN"); - } - $this->writeFacingDirection($value); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writeFacingWithoutUp(int $value) : self{ - if($value === Facing::UP){ - throw new BlockStateSerializeException("Invalid facing UP"); - } - $this->writeFacingDirection($value); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writePillarAxis(int $axis) : self{ - $this->mapIntToString(BlockStateNames::PILLAR_AXIS, ValueMappings::getInstance()->pillarAxis, $axis); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writeSlabPosition(SlabType $slabType) : self{ - $this->writeString(BlockStateNames::MC_VERTICAL_HALF, match($slabType){ - SlabType::TOP => StringValues::MC_VERTICAL_HALF_TOP, - SlabType::BOTTOM => StringValues::MC_VERTICAL_HALF_BOTTOM, - default => throw new BlockStateSerializeException("Invalid slab type " . $slabType->name) - }); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writeTorchFacing(int $facing) : self{ - $this->mapIntToString(BlockStateNames::TORCH_FACING_DIRECTION, ValueMappings::getInstance()->torchFacing, $facing); - return $this; - } - - /** - * @deprecated - * @return $this - */ - public function writeBellAttachmentType(BellAttachmentType $attachmentType) : self{ - return $this->writeUnitEnum(BlockStateNames::ATTACHMENT, ValueMappings::getInstance()->bellAttachmentType, $attachmentType); - } - - /** - * @deprecated - * @return $this - */ - public function writeWallConnectionType(string $name, ?WallConnectionType $wallConnectionType) : self{ - $this->writeString($name, match($wallConnectionType){ - null => StringValues::WALL_CONNECTION_TYPE_EAST_NONE, - WallConnectionType::SHORT => StringValues::WALL_CONNECTION_TYPE_EAST_SHORT, - WallConnectionType::TALL => StringValues::WALL_CONNECTION_TYPE_EAST_TALL, - }); - return $this; - } - - /** - * @deprecated - * @phpstan-template TEnum of \UnitEnum - * @phpstan-param EnumFromRawStateMap $map - * @phpstan-param TEnum $case - * - * @return $this - */ - public function writeUnitEnum(string $name, EnumFromRawStateMap $map, \UnitEnum $case) : self{ - $value = $map->valueToRaw($case); - $this->writeString($name, $value); - - return $this; - } - public function getBlockStateData() : BlockStateData{ return BlockStateData::current($this->id, $this->states); }