From 135b8b3eadaba0353f01b3291c098f388a3d9783 Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Fri, 21 Jun 2024 11:02:22 -0500 Subject: [PATCH 1/8] Implement Copper Bulb --- src/block/BlockTypeIds.php | 3 +- src/block/CopperBulb.php | 68 +++++++++++++++++++ src/block/VanillaBlocks.php | 2 + .../convert/BlockObjectToStateSerializer.php | 18 +++++ .../convert/BlockStateDeserializerHelper.php | 9 +-- .../BlockStateToObjectDeserializer.php | 40 +++++++++++ src/item/StringToItemParser.php | 1 + 7 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 src/block/CopperBulb.php diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index dec31eff11f..3790220dc5d 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -745,8 +745,9 @@ private function __construct(){ public const PITCHER_PLANT = 10715; public const PITCHER_CROP = 10716; public const DOUBLE_PITCHER_CROP = 10717; + public const COPPER_BULB = 10718; - public const FIRST_UNUSED_BLOCK_ID = 10718; + public const FIRST_UNUSED_BLOCK_ID = 10719; private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID; diff --git a/src/block/CopperBulb.php b/src/block/CopperBulb.php new file mode 100644 index 00000000000..02caabefd8e --- /dev/null +++ b/src/block/CopperBulb.php @@ -0,0 +1,68 @@ +encodeLitState($w); + $w->bool($this->powered); + } + + /** @return $this */ + public function togglePowered(bool $powered) : self{ + if($powered === $this->powered){ + return $this; + } + if ($powered) { + $this->setLit(!$this->lit); + } + $this->setPowered($powered); + return $this; + } + + public function getLightLevel() : int{ + if ($this->lit) { + return match($this->oxidation){ + CopperOxidation::NONE => 15, + CopperOxidation::EXPOSED => 12, + CopperOxidation::WEATHERED => 8, + CopperOxidation::OXIDIZED => 4, + }; + } + + return 0; + } +} diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 9c0e7d3b7c7..4dc4bfa0527 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -205,6 +205,7 @@ * @method static Concrete CONCRETE() * @method static ConcretePowder CONCRETE_POWDER() * @method static Copper COPPER() + * @method static CopperBulb COPPER_BULB() * @method static CopperOre COPPER_ORE() * @method static Coral CORAL() * @method static CoralBlock CORAL_BLOCK() @@ -1624,6 +1625,7 @@ public function isAffectedBySilkTouch() : bool{ self::register("cut_copper", new Copper(new BID(Ids::CUT_COPPER), "Cut Copper Block", $copperBreakInfo)); self::register("cut_copper_slab", new CopperSlab(new BID(Ids::CUT_COPPER_SLAB), "Cut Copper Slab", $copperBreakInfo)); self::register("cut_copper_stairs", new CopperStairs(new BID(Ids::CUT_COPPER_STAIRS), "Cut Copper Stairs", $copperBreakInfo)); + self::register("copper_bulb", new CopperBulb(new BID(Ids::COPPER_BULB), "Copper Bulb", $copperBreakInfo)); $candleBreakInfo = new Info(new BreakInfo(0.1)); self::register("candle", new Candle(new BID(Ids::CANDLE), "Candle", $candleBreakInfo)); diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index ab98e75f36b..6fe6a923a2b 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -57,6 +57,7 @@ use pocketmine\block\Concrete; use pocketmine\block\ConcretePowder; use pocketmine\block\Copper; +use pocketmine\block\CopperBulb; use pocketmine\block\CopperSlab; use pocketmine\block\CopperStairs; use pocketmine\block\Coral; @@ -1281,6 +1282,23 @@ private function registerSerializers() : void{ ) ); }); + $this->map(Blocks::COPPER_BULB(), function(CopperBulb $block) : Writer{ + $oxidation = $block->getOxidation(); + return Writer::create($block->isWaxed() ? + Helper::selectCopperId($oxidation, + Ids::WAXED_COPPER_BULB, + Ids::WAXED_EXPOSED_COPPER_BULB, + Ids::WAXED_WEATHERED_COPPER_BULB, + Ids::WAXED_OXIDIZED_COPPER_BULB) : + Helper::selectCopperId($oxidation, + Ids::COPPER_BULB, + Ids::EXPOSED_COPPER_BULB, + Ids::WEATHERED_COPPER_BULB, + Ids::OXIDIZED_COPPER_BULB + )) + ->writeBool(StateNames::LIT, $block->isLit()) + ->writeBool(StateNames::POWERED_BIT, $block->isPowered()); + }); $this->map(Blocks::COCOA_POD(), function(CocoaBlock $block) : Writer{ return Writer::create(Ids::COCOA) ->writeInt(StateNames::AGE, $block->getAge()) diff --git a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php index 6dda9fb81a1..ba80f46b55d 100644 --- a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php @@ -27,6 +27,7 @@ use pocketmine\block\Button; use pocketmine\block\Candle; use pocketmine\block\Copper; +use pocketmine\block\CopperBulb; use pocketmine\block\CopperSlab; use pocketmine\block\CopperStairs; use pocketmine\block\Crops; @@ -102,24 +103,24 @@ public static function decodeComparator(RedstoneComparator $block, BlockStateRea } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeCopper(Copper|CopperSlab|CopperStairs $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs{ + public static function decodeCopper(Copper|CopperSlab|CopperStairs|CopperBulb $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb{ $block->setOxidation($oxidation); $block->setWaxed(false); return $block; } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs{ + public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs|CopperBulb $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb{ $block->setOxidation($oxidation); $block->setWaxed(true); return $block; diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index 4c9ec4b798e..401d535c553 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -1118,6 +1118,11 @@ private function registerDeserializers() : void{ $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); + $this->map(Ids::COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeCopper(Blocks::COPPER_BULB(), CopperOxidation::NONE) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::CORAL_FAN_HANG, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN : CoralType::TUBE)); $this->map(Ids::CORAL_FAN_HANG2, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) @@ -1182,6 +1187,11 @@ private function registerDeserializers() : void{ $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); + $this->map(Ids::EXPOSED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeCopper(Blocks::COPPER_BULB(), CopperOxidation::EXPOSED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::FARMLAND, function(Reader $in) : Block{ return Blocks::FARMLAND() ->setWetness($in->readBoundedInt(StateNames::MOISTURIZED_AMOUNT, 0, 7)); @@ -1338,6 +1348,11 @@ private function registerDeserializers() : void{ $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::OXIDIZED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeCopper(Blocks::COPPER_BULB(), CopperOxidation::OXIDIZED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT)->setAxis($in->readPillarAxis())); $this->map(Ids::PINK_PETALS, function(Reader $in) : Block{ //Pink petals only uses 0-3, but GROWTH state can go up to 7 @@ -1652,22 +1667,47 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeWaxedCopper(Blocks::COPPER_BULB(), CopperOxidation::NONE) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_EXPOSED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeWaxedCopper(Blocks::COPPER_BULB(), CopperOxidation::EXPOSED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_OXIDIZED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeWaxedCopper(Blocks::COPPER_BULB(), CopperOxidation::OXIDIZED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); + $this->map(Ids::WAXED_WEATHERED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeWaxedCopper(Blocks::COPPER_BULB(), CopperOxidation::WEATHERED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_COPPER_BULB, function(Reader $in) : Block{ + return Helper::decodeCopper(Blocks::COPPER_BULB(), CopperOxidation::WEATHERED) + ->setLit($in->readBool(StateNames::LIT)) + ->setPowered($in->readBool(StateNames::POWERED_BIT)); + }); $this->map(Ids::WEEPING_VINES, function(Reader $in) : Block{ return Blocks::WEEPING_VINES() ->setAge($in->readBoundedInt(StateNames::WEEPING_VINES_AGE, 0, 25)); diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 91fd2ab4a43..9f1f3512b14 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -101,6 +101,7 @@ private static function registerDynamicBlocks(self $result) : void{ $register("cut_copper_block", fn() => Blocks::CUT_COPPER()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_stairs", fn() => Blocks::CUT_COPPER_STAIRS()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_slab", fn() => Blocks::CUT_COPPER_SLAB()->setOxidation($oxidation)->setWaxed($waxed)); + $register("copper_bulb", fn() => Blocks::COPPER_BULB()->setOxidation($oxidation)->setWaxed($waxed)); } } From 14862634d590aadc0b611ddf944a5025dfdacf72 Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Sat, 22 Jun 2024 17:25:28 -0500 Subject: [PATCH 2/8] Implement Copper Door & Copper Trapdoor --- src/block/BlockTypeIds.php | 4 +- src/block/CopperDoor.php | 63 +++++++++++++++++++ src/block/CopperTrapdoor.php | 43 +++++++++++++ src/block/Door.php | 6 +- src/block/VanillaBlocks.php | 6 ++ .../convert/BlockObjectToStateSerializer.php | 46 ++++++++++++++ .../convert/BlockStateDeserializerHelper.php | 10 +-- .../BlockStateToObjectDeserializer.php | 16 +++++ .../ItemSerializerDeserializerRegistrar.php | 28 +++++++++ src/item/StringToItemParser.php | 2 + tests/phpstan/configs/phpstan-bugs.neon | 10 +++ 11 files changed, 228 insertions(+), 6 deletions(-) create mode 100644 src/block/CopperDoor.php create mode 100644 src/block/CopperTrapdoor.php diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index 3790220dc5d..c6180128b4d 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -746,8 +746,10 @@ private function __construct(){ public const PITCHER_CROP = 10716; public const DOUBLE_PITCHER_CROP = 10717; public const COPPER_BULB = 10718; + public const COPPER_DOOR = 10719; + public const COPPER_TRAPDOOR = 10720; - public const FIRST_UNUSED_BLOCK_ID = 10719; + public const FIRST_UNUSED_BLOCK_ID = 10721; private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID; diff --git a/src/block/CopperDoor.php b/src/block/CopperDoor.php new file mode 100644 index 00000000000..dbb4f0c2bb0 --- /dev/null +++ b/src/block/CopperDoor.php @@ -0,0 +1,63 @@ +isSneaking()) { + return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); + } + + if ($this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { + //copy copper properties to other half + $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); + $world = $this->position->getWorld(); + if ($other instanceof CopperDoor) { + $other->setOxidation($this->oxidation); + $other->setWaxed($this->waxed); + $world->setBlock($other->position, $other); + } + return true; + } + + return false; + } + + protected function isCompatibleForHinge(Block $other) : bool{ + return parent::isCompatibleForHinge($other) && + $other instanceof CopperDoor && + $this->getOxidation() === $other->getOxidation() && + $this->isWaxed() === $other->isWaxed(); + } +} diff --git a/src/block/CopperTrapdoor.php b/src/block/CopperTrapdoor.php new file mode 100644 index 00000000000..4fd96ec4a5c --- /dev/null +++ b/src/block/CopperTrapdoor.php @@ -0,0 +1,43 @@ +isSneaking()) { + return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); + } + + return $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems); + } +} diff --git a/src/block/Door.php b/src/block/Door.php index 82ddaab518b..2378a9384a4 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -127,7 +127,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo $next = $this->getSide(Facing::rotateY($this->facing, false)); $next2 = $this->getSide(Facing::rotateY($this->facing, true)); - if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge + if($this->isCompatibleForHinge($next) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge $this->hingeRight = true; } @@ -176,4 +176,8 @@ public function getAffectedBlocks() : array{ private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport(); } + + protected function isCompatibleForHinge(Block $other) : bool{ + return $other->hasSameTypeId($this); + } } diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 4dc4bfa0527..54d3e5ea687 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -206,7 +206,9 @@ * @method static ConcretePowder CONCRETE_POWDER() * @method static Copper COPPER() * @method static CopperBulb COPPER_BULB() + * @method static CopperDoor COPPER_DOOR() * @method static CopperOre COPPER_ORE() + * @method static CopperTrapdoor COPPER_TRAPDOOR() * @method static Coral CORAL() * @method static CoralBlock CORAL_BLOCK() * @method static FloorCoralFan CORAL_FAN() @@ -1627,6 +1629,10 @@ public function isAffectedBySilkTouch() : bool{ self::register("cut_copper_stairs", new CopperStairs(new BID(Ids::CUT_COPPER_STAIRS), "Cut Copper Stairs", $copperBreakInfo)); self::register("copper_bulb", new CopperBulb(new BID(Ids::COPPER_BULB), "Copper Bulb", $copperBreakInfo)); + $copperDoorBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE, 30.0)); + self::register("copper_door", new CopperDoor(new BID(Ids::COPPER_DOOR), "Copper Door", $copperDoorBreakInfo)); + self::register("copper_trapdoor", new CopperTrapdoor(new BID(Ids::COPPER_TRAPDOOR), "Copper Trapdoor", $copperDoorBreakInfo)); + $candleBreakInfo = new Info(new BreakInfo(0.1)); self::register("candle", new Candle(new BID(Ids::CANDLE), "Candle", $candleBreakInfo)); self::register("dyed_candle", new DyedCandle(new BID(Ids::DYED_CANDLE), "Dyed Candle", $candleBreakInfo)); diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 6fe6a923a2b..75e331ce4e7 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -58,8 +58,10 @@ use pocketmine\block\ConcretePowder; use pocketmine\block\Copper; use pocketmine\block\CopperBulb; +use pocketmine\block\CopperDoor; use pocketmine\block\CopperSlab; use pocketmine\block\CopperStairs; +use pocketmine\block\CopperTrapdoor; use pocketmine\block\Coral; use pocketmine\block\CoralBlock; use pocketmine\block\DaylightSensor; @@ -1299,6 +1301,50 @@ private function registerSerializers() : void{ ->writeBool(StateNames::LIT, $block->isLit()) ->writeBool(StateNames::POWERED_BIT, $block->isPowered()); }); + $this->map(Blocks::COPPER_DOOR(), function(CopperDoor $block) : Writer{ + $oxidation = $block->getOxidation(); + return Helper::encodeDoor( + $block, + new Writer($block->isWaxed() ? + Helper::selectCopperId( + $oxidation, + Ids::WAXED_COPPER_DOOR, + Ids::WAXED_EXPOSED_COPPER_DOOR, + Ids::WAXED_WEATHERED_COPPER_DOOR, + Ids::WAXED_OXIDIZED_COPPER_DOOR + ) : + Helper::selectCopperId( + $oxidation, + Ids::COPPER_DOOR, + Ids::EXPOSED_COPPER_DOOR, + Ids::WEATHERED_COPPER_DOOR, + Ids::OXIDIZED_COPPER_DOOR + ) + ) + ); + }); + $this->map(Blocks::COPPER_TRAPDOOR(), function(CopperTrapdoor $block) : Writer{ + $oxidation = $block->getOxidation(); + return Helper::encodeTrapdoor( + $block, + new Writer($block->isWaxed() ? + Helper::selectCopperId( + $oxidation, + Ids::WAXED_COPPER_TRAPDOOR, + Ids::WAXED_EXPOSED_COPPER_TRAPDOOR, + Ids::WAXED_WEATHERED_COPPER_TRAPDOOR, + Ids::WAXED_OXIDIZED_COPPER_TRAPDOOR + ) : + Helper::selectCopperId( + $oxidation, + Ids::COPPER_TRAPDOOR, + Ids::EXPOSED_COPPER_TRAPDOOR, + Ids::WEATHERED_COPPER_TRAPDOOR, + Ids::OXIDIZED_COPPER_TRAPDOOR + ) + ) + ); + }); $this->map(Blocks::COCOA_POD(), function(CocoaBlock $block) : Writer{ return Writer::create(Ids::COCOA) ->writeInt(StateNames::AGE, $block->getAge()) diff --git a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php index ba80f46b55d..ace5fe9c087 100644 --- a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php @@ -28,8 +28,10 @@ use pocketmine\block\Candle; use pocketmine\block\Copper; use pocketmine\block\CopperBulb; +use pocketmine\block\CopperDoor; use pocketmine\block\CopperSlab; use pocketmine\block\CopperStairs; +use pocketmine\block\CopperTrapdoor; use pocketmine\block\Crops; use pocketmine\block\DaylightSensor; use pocketmine\block\Door; @@ -103,24 +105,24 @@ public static function decodeComparator(RedstoneComparator $block, BlockStateRea } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeCopper(Copper|CopperSlab|CopperStairs|CopperBulb $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb{ + public static function decodeCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor{ $block->setOxidation($oxidation); $block->setWaxed(false); return $block; } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs|CopperBulb $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb{ + public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor{ $block->setOxidation($oxidation); $block->setWaxed(true); return $block; diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index 401d535c553..ea5964004d8 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -1123,6 +1123,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeCopper(Blocks::COPPER_DOOR(), CopperOxidation::NONE), $in)); + $this->map(Ids::COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::NONE), $in)); $this->map(Ids::CORAL_FAN_HANG, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN : CoralType::TUBE)); $this->map(Ids::CORAL_FAN_HANG2, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) @@ -1192,6 +1194,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::EXPOSED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeCopper(Blocks::COPPER_DOOR(), CopperOxidation::EXPOSED), $in)); + $this->map(Ids::EXPOSED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::EXPOSED), $in)); $this->map(Ids::FARMLAND, function(Reader $in) : Block{ return Blocks::FARMLAND() ->setWetness($in->readBoundedInt(StateNames::MOISTURIZED_AMOUNT, 0, 7)); @@ -1353,6 +1357,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::OXIDIZED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeCopper(Blocks::COPPER_DOOR(), CopperOxidation::OXIDIZED), $in)); + $this->map(Ids::OXIDIZED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::OXIDIZED), $in)); $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT)->setAxis($in->readPillarAxis())); $this->map(Ids::PINK_PETALS, function(Reader $in) : Block{ //Pink petals only uses 0-3, but GROWTH state can go up to 7 @@ -1672,6 +1678,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::WAXED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::NONE), $in)); + $this->map(Ids::WAXED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::NONE), $in)); $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); @@ -1681,6 +1689,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::WAXED_EXPOSED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::EXPOSED), $in)); + $this->map(Ids::WAXED_EXPOSED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::EXPOSED), $in)); $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); @@ -1690,6 +1700,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::WAXED_OXIDIZED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::OXIDIZED), $in)); + $this->map(Ids::WAXED_OXIDIZED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::OXIDIZED), $in)); $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); @@ -1699,6 +1711,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::WAXED_WEATHERED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::WEATHERED), $in)); + $this->map(Ids::WAXED_WEATHERED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::WEATHERED), $in)); $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); @@ -1708,6 +1722,8 @@ private function registerDeserializers() : void{ ->setLit($in->readBool(StateNames::LIT)) ->setPowered($in->readBool(StateNames::POWERED_BIT)); }); + $this->map(Ids::WEATHERED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeCopper(Blocks::COPPER_DOOR(), CopperOxidation::WEATHERED), $in)); + $this->map(Ids::WEATHERED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::WEATHERED), $in)); $this->map(Ids::WEEPING_VINES, function(Reader $in) : Block{ return Blocks::WEEPING_VINES() ->setAge($in->readBoundedInt(StateNames::WEEPING_VINES_AGE, 0, 25)); diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index 7a720559eaa..f7c1957fc4c 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -25,7 +25,9 @@ use pocketmine\block\Bed; use pocketmine\block\Block; +use pocketmine\block\CopperDoor; use pocketmine\block\MobHead; +use pocketmine\block\utils\CopperOxidation; use pocketmine\block\utils\DyeColor; use pocketmine\block\VanillaBlocks as Blocks; use pocketmine\data\bedrock\CompoundTypeIds; @@ -56,6 +58,7 @@ public function __construct( $this->register1to1BlockWithMetaMappings(); $this->register1to1ItemWithMetaMappings(); $this->register1ToNItemMappings(); + $this->registerMiscBlockMappings(); $this->registerMiscItemMappings(); } @@ -536,4 +539,29 @@ private function registerMiscItemMappings() : void{ } $this->serializer?->map(Items::DYE(), fn(Dye $item) => new Data(DyeColorIdMap::getInstance()->toItemId($item->getColor()))); } + + /** + * Registers serializers and deserializers for PocketMine-MP blockitems that don't fit any other pattern. + * Ideally we want to get rid of this completely, if possible. + * + * Most of these are single PocketMine-MP blocks which map to multiple IDs depending on their properties, which is + * complex to implement in a generic way. + */ + private function registerMiscBlockMappings() : void{ + $copperDoorStateIdMap = []; + foreach ([ + [Ids::COPPER_DOOR, CopperOxidation::NONE, false], + [Ids::EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, false], + [Ids::WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, false], + [Ids::OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, false], + [Ids::WAXED_COPPER_DOOR, CopperOxidation::NONE, true], + [Ids::WAXED_EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, true], + [Ids::WAXED_WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, true], + [Ids::WAXED_OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, true] + ] as [$id, $oxidation, $waxed]) { + $copperDoorStateIdMap[$oxidation->value][$waxed ? 1 : 0] = $id; + $this->deserializer?->mapBlock($id, fn() => Blocks::COPPER_DOOR()->setOxidation($oxidation)->setWaxed($waxed)); + } + $this->serializer?->mapBlock(Blocks::COPPER_DOOR(), fn(CopperDoor $block) => new Data($copperDoorStateIdMap[$block->getOxidation()->value][$block->isWaxed() ? 1 : 0])); + } } diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 9f1f3512b14..90be7890560 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -102,6 +102,8 @@ private static function registerDynamicBlocks(self $result) : void{ $register("cut_copper_stairs", fn() => Blocks::CUT_COPPER_STAIRS()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_slab", fn() => Blocks::CUT_COPPER_SLAB()->setOxidation($oxidation)->setWaxed($waxed)); $register("copper_bulb", fn() => Blocks::COPPER_BULB()->setOxidation($oxidation)->setWaxed($waxed)); + $register("copper_door", fn() => Blocks::COPPER_DOOR()->setOxidation($oxidation)->setWaxed($waxed)); + $register("copper_trapdoor", fn() => Blocks::COPPER_TRAPDOOR()->setOxidation($oxidation)->setWaxed($waxed)); } } diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index de38903bd39..0ead377ba0f 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -10,6 +10,16 @@ parameters: count: 1 path: ../../../src/block/DoubleTallGrass.php + - + message: "#^Method pocketmine\\\\block\\\\CopperDoor\\:\\:onInteractCopper\\(\\) has parameter \\$returnedItems with no value type specified in iterable type array\\.$#" + count: 1 + path: ../../../src/block/utils/CopperTrait.php + + - + message: "#^Method pocketmine\\\\block\\\\CopperTrapdoor\\:\\:onInteractCopper\\(\\) has parameter \\$returnedItems with no value type specified in iterable type array\\.$#" + count: 1 + path: ../../../src/block/utils/CopperTrait.php + - message: "#^Call to function assert\\(\\) with false and 'unknown hit type' will always evaluate to false\\.$#" count: 1 From fc054a2949ff669e6a377d5c1f47282b91eb6e46 Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Sat, 22 Jun 2024 20:01:57 -0500 Subject: [PATCH 3/8] Implement Chiseled Copper block --- src/block/BlockTypeIds.php | 3 ++- src/block/VanillaBlocks.php | 2 ++ .../convert/BlockObjectToStateSerializer.php | 17 +++++++++++++++++ .../convert/BlockStateToObjectDeserializer.php | 8 ++++++++ src/item/StringToItemParser.php | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index c6180128b4d..cb6e23fb9bf 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -748,8 +748,9 @@ private function __construct(){ public const COPPER_BULB = 10718; public const COPPER_DOOR = 10719; public const COPPER_TRAPDOOR = 10720; + public const CHISELED_COPPER = 10721; - public const FIRST_UNUSED_BLOCK_ID = 10721; + public const FIRST_UNUSED_BLOCK_ID = 10722; private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID; diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 54d3e5ea687..38d5d964551 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -179,6 +179,7 @@ * @method static Wood CHERRY_WOOD() * @method static Chest CHEST() * @method static ChiseledBookshelf CHISELED_BOOKSHELF() + * @method static Copper CHISELED_COPPER() * @method static Opaque CHISELED_DEEPSLATE() * @method static Opaque CHISELED_NETHER_BRICKS() * @method static Opaque CHISELED_POLISHED_BLACKSTONE() @@ -1624,6 +1625,7 @@ public function isAffectedBySilkTouch() : bool{ self::register("lightning_rod", new LightningRod(new BID(Ids::LIGHTNING_ROD), "Lightning Rod", $copperBreakInfo)); self::register("copper", new Copper(new BID(Ids::COPPER), "Copper Block", $copperBreakInfo)); + self::register("chiseled_copper", new Copper(new BID(Ids::CHISELED_COPPER), "Chiseled Copper", $copperBreakInfo)); self::register("cut_copper", new Copper(new BID(Ids::CUT_COPPER), "Cut Copper Block", $copperBreakInfo)); self::register("cut_copper_slab", new CopperSlab(new BID(Ids::CUT_COPPER_SLAB), "Cut Copper Slab", $copperBreakInfo)); self::register("cut_copper_stairs", new CopperStairs(new BID(Ids::CUT_COPPER_STAIRS), "Cut Copper Stairs", $copperBreakInfo)); diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 75e331ce4e7..4b0255593e4 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -1217,6 +1217,23 @@ private function registerSerializers() : void{ Helper::selectCopperId($oxidation, Ids::COPPER_BLOCK, Ids::EXPOSED_COPPER, Ids::WEATHERED_COPPER, Ids::OXIDIZED_COPPER) ); }); + $this->map(Blocks::CHISELED_COPPER(), function(Copper $block) : Writer{ + $oxidation = $block->getOxidation(); + return new Writer($block->isWaxed() ? + Helper::selectCopperId($oxidation, + Ids::WAXED_CHISELED_COPPER, + Ids::WAXED_EXPOSED_CHISELED_COPPER, + Ids::WAXED_WEATHERED_CHISELED_COPPER, + Ids::WAXED_OXIDIZED_CHISELED_COPPER + ) : + Helper::selectCopperId($oxidation, + Ids::CHISELED_COPPER, + Ids::EXPOSED_CHISELED_COPPER, + Ids::WEATHERED_CHISELED_COPPER, + Ids::OXIDIZED_CHISELED_COPPER + ) + ); + }); $this->map(Blocks::CUT_COPPER(), function(Copper $block) : Writer{ $oxidation = $block->getOxidation(); return new Writer($block->isWaxed() ? diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index ea5964004d8..06e587656de 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -1115,6 +1115,7 @@ private function registerDeserializers() : void{ Blocks::RED_TORCH()->setFacing($in->readTorchFacing()); }); $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::NONE)); $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); @@ -1186,6 +1187,7 @@ private function registerDeserializers() : void{ ->setFacing($in->readCardinalHorizontalFacing()); }); $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::EXPOSED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); @@ -1349,6 +1351,7 @@ private function registerDeserializers() : void{ $this->mapStairs(Ids::NORMAL_STONE_STAIRS, fn() => Blocks::STONE_STAIRS()); $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE)->setAxis($in->readPillarAxis())); $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::OXIDIZED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); @@ -1670,6 +1673,7 @@ private function registerDeserializers() : void{ }); $this->map(Ids::WATER, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::WATER(), $in)); $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::NONE)); $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); @@ -1681,6 +1685,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::NONE), $in)); $this->map(Ids::WAXED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::NONE), $in)); $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_EXPOSED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); @@ -1692,6 +1697,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_EXPOSED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::EXPOSED), $in)); $this->map(Ids::WAXED_EXPOSED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::EXPOSED), $in)); $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_OXIDIZED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); @@ -1703,6 +1709,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_OXIDIZED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::OXIDIZED), $in)); $this->map(Ids::WAXED_OXIDIZED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::OXIDIZED), $in)); $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WAXED_WEATHERED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); @@ -1714,6 +1721,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_WEATHERED_COPPER_DOOR, fn(Reader $in) => Helper::decodeDoor(Helper::decodeWaxedCopper(Blocks::COPPER_DOOR(), CopperOxidation::WEATHERED), $in)); $this->map(Ids::WAXED_WEATHERED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::WEATHERED), $in)); $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 90be7890560..708f42d6626 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -98,6 +98,7 @@ private static function registerDynamicBlocks(self $result) : void{ foreach(["" => false, "waxed_" => true] as $waxedPrefix => $waxed){ $register = fn(string $name, \Closure $callback) => $result->registerBlock($waxedPrefix . $oxPrefix . $name, $callback); $register("copper_block", fn() => Blocks::COPPER()->setOxidation($oxidation)->setWaxed($waxed)); + $register("chiseled_copper", fn() => Blocks::CHISELED_COPPER()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_block", fn() => Blocks::CUT_COPPER()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_stairs", fn() => Blocks::CUT_COPPER_STAIRS()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_slab", fn() => Blocks::CUT_COPPER_SLAB()->setOxidation($oxidation)->setWaxed($waxed)); From b81f59ed3252e650d8a03d93304e3b9770a7b44f Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Sat, 22 Jun 2024 21:08:03 -0500 Subject: [PATCH 4/8] Implement Copper Grate block --- src/block/BlockTypeIds.php | 3 +- src/block/CopperGrate.php | 32 +++++++++++++++++++ src/block/VanillaBlocks.php | 2 ++ .../convert/BlockObjectToStateSerializer.php | 18 +++++++++++ .../convert/BlockStateDeserializerHelper.php | 9 +++--- .../BlockStateToObjectDeserializer.php | 8 +++++ src/item/StringToItemParser.php | 1 + 7 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/block/CopperGrate.php diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index cb6e23fb9bf..4967cf3b543 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -749,8 +749,9 @@ private function __construct(){ public const COPPER_DOOR = 10719; public const COPPER_TRAPDOOR = 10720; public const CHISELED_COPPER = 10721; + public const COPPER_GRATE = 10722; - public const FIRST_UNUSED_BLOCK_ID = 10722; + public const FIRST_UNUSED_BLOCK_ID = 10723; private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID; diff --git a/src/block/CopperGrate.php b/src/block/CopperGrate.php new file mode 100644 index 00000000000..bc0f6f29d29 --- /dev/null +++ b/src/block/CopperGrate.php @@ -0,0 +1,32 @@ +map(Blocks::COPPER_GRATE(), function(CopperGrate $block) : Writer{ + $oxidation = $block->getOxidation(); + return new Writer($block->isWaxed() ? + Helper::selectCopperId($oxidation, + Ids::WAXED_COPPER_GRATE, + Ids::WAXED_EXPOSED_COPPER_GRATE, + Ids::WAXED_WEATHERED_COPPER_GRATE, + Ids::WAXED_OXIDIZED_COPPER_GRATE + ) : + Helper::selectCopperId($oxidation, + Ids::COPPER_GRATE, + Ids::EXPOSED_COPPER_GRATE, + Ids::WEATHERED_COPPER_GRATE, + Ids::OXIDIZED_COPPER_GRATE + ) + ); + }); $this->map(Blocks::CUT_COPPER(), function(Copper $block) : Writer{ $oxidation = $block->getOxidation(); return new Writer($block->isWaxed() ? diff --git a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php index ace5fe9c087..dbd865182bd 100644 --- a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php @@ -29,6 +29,7 @@ use pocketmine\block\Copper; use pocketmine\block\CopperBulb; use pocketmine\block\CopperDoor; +use pocketmine\block\CopperGrate; use pocketmine\block\CopperSlab; use pocketmine\block\CopperStairs; use pocketmine\block\CopperTrapdoor; @@ -105,24 +106,24 @@ public static function decodeComparator(RedstoneComparator $block, BlockStateRea } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor{ + public static function decodeCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate{ $block->setOxidation($oxidation); $block->setWaxed(false); return $block; } /** - * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor + * @phpstan-template TBlock of Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate * * @phpstan-param TBlock $block * @phpstan-return TBlock */ - public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor{ + public static function decodeWaxedCopper(Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate $block, CopperOxidation $oxidation) : Copper|CopperSlab|CopperStairs|CopperBulb|CopperDoor|CopperTrapdoor|CopperGrate{ $block->setOxidation($oxidation); $block->setWaxed(true); return $block; diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index 06e587656de..4f914708630 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -1116,6 +1116,7 @@ private function registerDeserializers() : void{ }); $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE)); $this->map(Ids::CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::NONE)); + $this->map(Ids::COPPER_GRATE, fn() => Helper::decodeCopper(Blocks::COPPER_GRATE(), CopperOxidation::NONE)); $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); @@ -1188,6 +1189,7 @@ private function registerDeserializers() : void{ }); $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::EXPOSED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::EXPOSED_COPPER_GRATE, fn() => Helper::decodeCopper(Blocks::COPPER_GRATE(), CopperOxidation::EXPOSED)); $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); @@ -1352,6 +1354,7 @@ private function registerDeserializers() : void{ $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE)->setAxis($in->readPillarAxis())); $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::OXIDIZED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::OXIDIZED_COPPER_GRATE, fn() => Helper::decodeCopper(Blocks::COPPER_GRATE(), CopperOxidation::OXIDIZED)); $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); @@ -1674,6 +1677,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WATER, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::WATER(), $in)); $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE)); $this->map(Ids::WAXED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_COPPER_GRATE, fn() => Helper::decodeWaxedCopper(Blocks::COPPER_GRATE(), CopperOxidation::NONE)); $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); @@ -1686,6 +1690,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::NONE), $in)); $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); $this->map(Ids::WAXED_EXPOSED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_EXPOSED_COPPER_GRATE, fn() => Helper::decodeWaxedCopper(Blocks::COPPER_GRATE(), CopperOxidation::EXPOSED)); $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); @@ -1698,6 +1703,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_EXPOSED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::EXPOSED), $in)); $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); $this->map(Ids::WAXED_OXIDIZED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_OXIDIZED_COPPER_GRATE, fn() => Helper::decodeWaxedCopper(Blocks::COPPER_GRATE(), CopperOxidation::OXIDIZED)); $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); @@ -1710,6 +1716,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_OXIDIZED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::OXIDIZED), $in)); $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WAXED_WEATHERED_CHISELED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CHISELED_COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WAXED_WEATHERED_COPPER_GRATE, fn() => Helper::decodeWaxedCopper(Blocks::COPPER_GRATE(), CopperOxidation::WEATHERED)); $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); @@ -1722,6 +1729,7 @@ private function registerDeserializers() : void{ $this->map(Ids::WAXED_WEATHERED_COPPER_TRAPDOOR, fn(Reader $in) => Helper::decodeTrapdoor(Helper::decodeWaxedCopper(Blocks::COPPER_TRAPDOOR(), CopperOxidation::WEATHERED), $in)); $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); $this->map(Ids::WEATHERED_CHISELED_COPPER, fn() => Helper::decodeCopper(Blocks::CHISELED_COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_COPPER_GRATE, fn() => Helper::decodeCopper(Blocks::COPPER_GRATE(), CopperOxidation::WEATHERED)); $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index 708f42d6626..c3fe3050d50 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -99,6 +99,7 @@ private static function registerDynamicBlocks(self $result) : void{ $register = fn(string $name, \Closure $callback) => $result->registerBlock($waxedPrefix . $oxPrefix . $name, $callback); $register("copper_block", fn() => Blocks::COPPER()->setOxidation($oxidation)->setWaxed($waxed)); $register("chiseled_copper", fn() => Blocks::CHISELED_COPPER()->setOxidation($oxidation)->setWaxed($waxed)); + $register("copper_grate", fn() => Blocks::COPPER_GRATE()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_block", fn() => Blocks::CUT_COPPER()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_stairs", fn() => Blocks::CUT_COPPER_STAIRS()->setOxidation($oxidation)->setWaxed($waxed)); $register("cut_copper_slab", fn() => Blocks::CUT_COPPER_SLAB()->setOxidation($oxidation)->setWaxed($waxed)); From 53b612169f405144b24dff4493d5d0c2d7d9ed4d Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Sat, 22 Jun 2024 21:54:57 -0500 Subject: [PATCH 5/8] Update block_factory_consistency_check.json --- tests/phpunit/block/block_factory_consistency_check.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/phpunit/block/block_factory_consistency_check.json b/tests/phpunit/block/block_factory_consistency_check.json index 27bf831841b..5716a269eb0 100644 --- a/tests/phpunit/block/block_factory_consistency_check.json +++ b/tests/phpunit/block/block_factory_consistency_check.json @@ -104,6 +104,7 @@ "CHERRY_WOOD": 6, "CHEST": 4, "CHISELED_BOOKSHELF": 256, + "CHISELED_COPPER": 8, "CHISELED_DEEPSLATE": 1, "CHISELED_NETHER_BRICKS": 1, "CHISELED_POLISHED_BLACKSTONE": 1, @@ -130,7 +131,11 @@ "CONCRETE": 16, "CONCRETE_POWDER": 16, "COPPER": 8, + "COPPER_BULB": 32, + "COPPER_DOOR": 256, + "COPPER_GRATE": 8, "COPPER_ORE": 1, + "COPPER_TRAPDOOR": 128, "CORAL": 10, "CORAL_BLOCK": 10, "CORAL_FAN": 20, From 4054d71085a336cd995eae96db88805667b1c3f2 Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Mon, 8 Jul 2024 17:19:35 -0500 Subject: [PATCH 6/8] Allow players opening copper door and trapdoor when sneaking without an item --- src/block/CopperDoor.php | 8 ++------ src/block/CopperTrapdoor.php | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/block/CopperDoor.php b/src/block/CopperDoor.php index dbb4f0c2bb0..dfd87d30ed6 100644 --- a/src/block/CopperDoor.php +++ b/src/block/CopperDoor.php @@ -35,11 +35,7 @@ class CopperDoor extends Door{ } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ - if ($player !== null && !$player->isSneaking()) { - return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); - } - - if ($this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { + if ($player !== null && $player->isSneaking() && $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { //copy copper properties to other half $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); $world = $this->position->getWorld(); @@ -51,7 +47,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return true; } - return false; + return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } protected function isCompatibleForHinge(Block $other) : bool{ diff --git a/src/block/CopperTrapdoor.php b/src/block/CopperTrapdoor.php index 4fd96ec4a5c..986180d3b20 100644 --- a/src/block/CopperTrapdoor.php +++ b/src/block/CopperTrapdoor.php @@ -34,10 +34,10 @@ class CopperTrapdoor extends Trapdoor{ } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ - if ($player !== null && !$player->isSneaking()) { - return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); + if ($player !== null && $player->isSneaking() && $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { + return true; } - return $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems); + return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } } From 36e7e355cc2cebf23b72705be72047f1be4894f0 Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Mon, 23 Sep 2024 16:25:22 -0500 Subject: [PATCH 7/8] Usage of new ICopper interface --- src/block/CopperBulb.php | 3 ++- src/block/CopperDoor.php | 3 ++- src/block/CopperGrate.php | 3 ++- src/block/CopperTrapdoor.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/block/CopperBulb.php b/src/block/CopperBulb.php index 02caabefd8e..223c63527f2 100644 --- a/src/block/CopperBulb.php +++ b/src/block/CopperBulb.php @@ -25,11 +25,12 @@ use pocketmine\block\utils\CopperOxidation; use pocketmine\block\utils\CopperTrait; +use pocketmine\block\utils\ICopper; use pocketmine\block\utils\LightableTrait; use pocketmine\block\utils\PoweredByRedstoneTrait; use pocketmine\data\runtime\RuntimeDataDescriber; -class CopperBulb extends Opaque{ +class CopperBulb extends Opaque implements ICopper{ use CopperTrait; use PoweredByRedstoneTrait; use LightableTrait{ diff --git a/src/block/CopperDoor.php b/src/block/CopperDoor.php index dfd87d30ed6..7cf73363621 100644 --- a/src/block/CopperDoor.php +++ b/src/block/CopperDoor.php @@ -24,12 +24,13 @@ namespace pocketmine\block; use pocketmine\block\utils\CopperTrait; +use pocketmine\block\utils\ICopper; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -class CopperDoor extends Door{ +class CopperDoor extends Door implements ICopper{ use CopperTrait{ onInteract as onInteractCopper; } diff --git a/src/block/CopperGrate.php b/src/block/CopperGrate.php index bc0f6f29d29..fb59d846e86 100644 --- a/src/block/CopperGrate.php +++ b/src/block/CopperGrate.php @@ -24,8 +24,9 @@ namespace pocketmine\block; use pocketmine\block\utils\CopperTrait; +use pocketmine\block\utils\ICopper; -class CopperGrate extends Transparent{ +class CopperGrate extends Transparent implements ICopper{ use CopperTrait; //TODO: waterlogging! diff --git a/src/block/CopperTrapdoor.php b/src/block/CopperTrapdoor.php index 986180d3b20..ab743af44ba 100644 --- a/src/block/CopperTrapdoor.php +++ b/src/block/CopperTrapdoor.php @@ -24,11 +24,12 @@ namespace pocketmine\block; use pocketmine\block\utils\CopperTrait; +use pocketmine\block\utils\ICopper; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\player\Player; -class CopperTrapdoor extends Trapdoor{ +class CopperTrapdoor extends Trapdoor implements ICopper{ use CopperTrait{ onInteract as onInteractCopper; } From ff4467ba84af42f8c23bf308d89e5f6d5653bb4d Mon Sep 17 00:00:00 2001 From: IvanCraft623 Date: Mon, 23 Sep 2024 16:28:26 -0500 Subject: [PATCH 8/8] Remove `Door::isCompatibleForHinge()` change No longer valid behavior on newer versions --- src/block/CopperDoor.php | 7 ------- src/block/Door.php | 6 +----- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/block/CopperDoor.php b/src/block/CopperDoor.php index 7cf73363621..d53be2323c1 100644 --- a/src/block/CopperDoor.php +++ b/src/block/CopperDoor.php @@ -50,11 +50,4 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } - - protected function isCompatibleForHinge(Block $other) : bool{ - return parent::isCompatibleForHinge($other) && - $other instanceof CopperDoor && - $this->getOxidation() === $other->getOxidation() && - $this->isWaxed() === $other->isWaxed(); - } } diff --git a/src/block/Door.php b/src/block/Door.php index 2378a9384a4..82ddaab518b 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -127,7 +127,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo $next = $this->getSide(Facing::rotateY($this->facing, false)); $next2 = $this->getSide(Facing::rotateY($this->facing, true)); - if($this->isCompatibleForHinge($next) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge + if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge $this->hingeRight = true; } @@ -176,8 +176,4 @@ public function getAffectedBlocks() : array{ private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport(); } - - protected function isCompatibleForHinge(Block $other) : bool{ - return $other->hasSameTypeId($this); - } }