diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index ac6325d67..cbe373346 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -1110,11 +1110,11 @@ final class VanillaBlocks{ foreach(SaplingType::getAll() as $saplingType){ $name = $saplingType->getDisplayName(); - self::register($saplingType->name() . "_sapling", new Sapling(BlockLegacyIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); + self::register($saplingType->name() . "_sapling", new Sapling(WoodLikeBlockIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); } foreach(LeavesType::getAll() as $leavesType){ $name = $leavesType->getDisplayName(); - self::register($leavesType->name() . "_leaves", new Leaves(BlockLegacyIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); + self::register($leavesType->name() . "_leaves", new Leaves(WoodLikeBlockIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); } $sandstoneBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD())); @@ -1234,22 +1234,22 @@ final class VanillaBlocks{ $name = $woodType->getDisplayName(); $idName = fn(string $suffix) => $woodType->name() . "_" . $suffix; - self::register($idName(mb_strtolower($woodType->getStandardLogSuffix() ?? "log", 'US-ASCII')), new Wood(BlockLegacyIdHelper::getLogIdentifier($woodType), $name . " " . ($woodType->getStandardLogSuffix() ?? "Log"), $logBreakInfo, $woodType)); - self::register($idName(mb_strtolower($woodType->getAllSidedLogSuffix() ?? "wood", 'US-ASCII')), new Wood(BlockLegacyIdHelper::getAllSidedLogIdentifier($woodType), $name . " " . ($woodType->getAllSidedLogSuffix() ?? "Wood"), $logBreakInfo, $woodType)); + self::register($idName(mb_strtolower($woodType->getStandardLogSuffix() ?? "log", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getLogIdentifier($woodType), $name . " " . ($woodType->getStandardLogSuffix() ?? "Log"), $logBreakInfo, $woodType)); + self::register($idName(mb_strtolower($woodType->getAllSidedLogSuffix() ?? "wood", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getAllSidedLogIdentifier($woodType), $name . " " . ($woodType->getAllSidedLogSuffix() ?? "Wood"), $logBreakInfo, $woodType)); - self::register($idName("planks"), new Planks(BlockLegacyIdHelper::getWoodenPlanksIdentifier($woodType), $name . " Planks", $planksBreakInfo, $woodType)); - self::register($idName("fence"), new WoodenFence(BlockLegacyIdHelper::getWoodenFenceIdentifier($woodType), $name . " Fence", $planksBreakInfo, $woodType)); - self::register($idName("slab"), new WoodenSlab(BlockLegacyIdHelper::getWoodenSlabIdentifier($woodType), $name, $planksBreakInfo, $woodType)); + self::register($idName("planks"), new Planks(WoodLikeBlockIdHelper::getPlanksIdentifier($woodType), $name . " Planks", $planksBreakInfo, $woodType)); + self::register($idName("fence"), new WoodenFence(WoodLikeBlockIdHelper::getFenceIdentifier($woodType), $name . " Fence", $planksBreakInfo, $woodType)); + self::register($idName("slab"), new WoodenSlab(WoodLikeBlockIdHelper::getSlabIdentifier($woodType), $name, $planksBreakInfo, $woodType)); - self::register($idName("fence_gate"), new FenceGate(BlockLegacyIdHelper::getWoodenFenceGateIdentifier($woodType), $name . " Fence Gate", $planksBreakInfo, $woodType)); - self::register($idName("stairs"), new WoodenStairs(BlockLegacyIdHelper::getWoodenStairsIdentifier($woodType), $name . " Stairs", $planksBreakInfo, $woodType)); - self::register($idName("door"), new WoodenDoor(BlockLegacyIdHelper::getWoodenDoorIdentifier($woodType), $name . " Door", $woodenDoorBreakInfo, $woodType)); + self::register($idName("fence_gate"), new FenceGate(WoodLikeBlockIdHelper::getFenceGateIdentifier($woodType), $name . " Fence Gate", $planksBreakInfo, $woodType)); + self::register($idName("stairs"), new WoodenStairs(WoodLikeBlockIdHelper::getStairsIdentifier($woodType), $name . " Stairs", $planksBreakInfo, $woodType)); + self::register($idName("door"), new WoodenDoor(WoodLikeBlockIdHelper::getDoorIdentifier($woodType), $name . " Door", $woodenDoorBreakInfo, $woodType)); - self::register($idName("button"), new WoodenButton(BlockLegacyIdHelper::getWoodenButtonIdentifier($woodType), $name . " Button", $woodenButtonBreakInfo, $woodType)); - self::register($idName("pressure_plate"), new WoodenPressurePlate(BlockLegacyIdHelper::getWoodenPressurePlateIdentifier($woodType), $name . " Pressure Plate", $woodenPressurePlateBreakInfo, $woodType)); - self::register($idName("trapdoor"), new WoodenTrapdoor(BlockLegacyIdHelper::getWoodenTrapdoorIdentifier($woodType), $name . " Trapdoor", $woodenDoorBreakInfo, $woodType)); + self::register($idName("button"), new WoodenButton(WoodLikeBlockIdHelper::getButtonIdentifier($woodType), $name . " Button", $woodenButtonBreakInfo, $woodType)); + self::register($idName("pressure_plate"), new WoodenPressurePlate(WoodLikeBlockIdHelper::getPressurePlateIdentifier($woodType), $name . " Pressure Plate", $woodenPressurePlateBreakInfo, $woodType)); + self::register($idName("trapdoor"), new WoodenTrapdoor(WoodLikeBlockIdHelper::getTrapdoorIdentifier($woodType), $name . " Trapdoor", $woodenDoorBreakInfo, $woodType)); - [$floorSignId, $wallSignId, $signAsItem] = BlockLegacyIdHelper::getWoodenSignInfo($woodType); + [$floorSignId, $wallSignId, $signAsItem] = WoodLikeBlockIdHelper::getSignInfo($woodType); self::register($idName("sign"), new FloorSign($floorSignId, $name . " Sign", $signBreakInfo, $woodType, $signAsItem)); self::register($idName("wall_sign"), new WallSign($wallSignId, $name . " Wall Sign", $signBreakInfo, $woodType, $signAsItem)); } diff --git a/src/block/BlockLegacyIdHelper.php b/src/block/WoodLikeBlockIdHelper.php similarity index 88% rename from src/block/BlockLegacyIdHelper.php rename to src/block/WoodLikeBlockIdHelper.php index 6d298ed17..a7aacb649 100644 --- a/src/block/BlockLegacyIdHelper.php +++ b/src/block/WoodLikeBlockIdHelper.php @@ -32,9 +32,20 @@ use pocketmine\block\utils\WoodType; use pocketmine\item\VanillaItems; use pocketmine\utils\AssumptionFailedError; -final class BlockLegacyIdHelper{ +/** + * All wood-like blocks have different IDs for different wood types. + * + * We can't make these dynamic, because some types of wood have different type properties (e.g. crimson and warped planks + * are not flammable, but all other planks are). + * + * In the future, it's entirely within the realm of reason that the other types of wood may differ in other ways, such + * as flammability, hardness, required tool tier, etc. + * Therefore, to stay on the safe side of Mojang, wood-like blocks have static types. This does unfortunately generate + * a lot of ugly code. + */ +final class WoodLikeBlockIdHelper{ - public static function getWoodenPlanksIdentifier(WoodType $type) : BID{ + public static function getPlanksIdentifier(WoodType $type) : BID{ return new BID(match($type->id()){ WoodType::OAK()->id() => Ids::OAK_PLANKS, WoodType::SPRUCE()->id() => Ids::SPRUCE_PLANKS, @@ -49,7 +60,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenFenceIdentifier(WoodType $type) : BID{ + public static function getFenceIdentifier(WoodType $type) : BID{ return new BID(match($type->id()){ WoodType::OAK()->id() => Ids::OAK_FENCE, WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE, @@ -64,7 +75,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenSlabIdentifier(WoodType $type) : BID{ + public static function getSlabIdentifier(WoodType $type) : BID{ return new BID(match($type->id()){ WoodType::OAK()->id() => Ids::OAK_SLAB, WoodType::SPRUCE()->id() => Ids::SPRUCE_SLAB, @@ -140,7 +151,7 @@ final class BlockLegacyIdHelper{ * @return BID[]|\Closure[] * @phpstan-return array{BID, BID, \Closure() : \pocketmine\item\Item} */ - public static function getWoodenSignInfo(WoodType $treeType) : array{ + public static function getSignInfo(WoodType $treeType) : array{ switch($treeType->id()){ case WoodType::OAK()->id(): return [ @@ -201,7 +212,7 @@ final class BlockLegacyIdHelper{ throw new AssumptionFailedError("Switch should cover all wood types"); } - public static function getWoodenTrapdoorIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getTrapdoorIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_TRAPDOOR, WoodType::SPRUCE()->id() => Ids::SPRUCE_TRAPDOOR, @@ -216,7 +227,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenButtonIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getButtonIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_BUTTON, WoodType::SPRUCE()->id() => Ids::SPRUCE_BUTTON, @@ -231,7 +242,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenPressurePlateIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getPressurePlateIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_PRESSURE_PLATE, WoodType::SPRUCE()->id() => Ids::SPRUCE_PRESSURE_PLATE, @@ -246,7 +257,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenDoorIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getDoorIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_DOOR, WoodType::SPRUCE()->id() => Ids::SPRUCE_DOOR, @@ -261,7 +272,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenFenceGateIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getFenceGateIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_FENCE_GATE, WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE_GATE, @@ -276,7 +287,7 @@ final class BlockLegacyIdHelper{ }); } - public static function getWoodenStairsIdentifier(WoodType $treeType) : BlockIdentifier{ + public static function getStairsIdentifier(WoodType $treeType) : BlockIdentifier{ return new BID(match($treeType->id()){ WoodType::OAK()->id() => Ids::OAK_STAIRS, WoodType::SPRUCE()->id() => Ids::SPRUCE_STAIRS,