diff --git a/src/block/BlockLegacyIdHelper.php b/src/block/BlockLegacyIdHelper.php index c7cb2f5d7..6d298ed17 100644 --- a/src/block/BlockLegacyIdHelper.php +++ b/src/block/BlockLegacyIdHelper.php @@ -27,7 +27,7 @@ use pocketmine\block\BlockIdentifier as BID; use pocketmine\block\BlockTypeIds as Ids; use pocketmine\block\tile\Sign as TileSign; use pocketmine\block\utils\LeavesType; -use pocketmine\block\utils\TreeType; +use pocketmine\block\utils\SaplingType; use pocketmine\block\utils\WoodType; use pocketmine\item\VanillaItems; use pocketmine\utils\AssumptionFailedError; @@ -124,14 +124,14 @@ final class BlockLegacyIdHelper{ }); } - public static function getSaplingIdentifier(TreeType $treeType) : BID{ + public static function getSaplingIdentifier(SaplingType $treeType) : BID{ return new BID(match($treeType->id()){ - TreeType::OAK()->id() => Ids::OAK_SAPLING, - TreeType::SPRUCE()->id() => Ids::SPRUCE_SAPLING, - TreeType::BIRCH()->id() => Ids::BIRCH_SAPLING, - TreeType::JUNGLE()->id() => Ids::JUNGLE_SAPLING, - TreeType::ACACIA()->id() => Ids::ACACIA_SAPLING, - TreeType::DARK_OAK()->id() => Ids::DARK_OAK_SAPLING, + SaplingType::OAK()->id() => Ids::OAK_SAPLING, + SaplingType::SPRUCE()->id() => Ids::SPRUCE_SAPLING, + SaplingType::BIRCH()->id() => Ids::BIRCH_SAPLING, + SaplingType::JUNGLE()->id() => Ids::JUNGLE_SAPLING, + SaplingType::ACACIA()->id() => Ids::ACACIA_SAPLING, + SaplingType::DARK_OAK()->id() => Ids::DARK_OAK_SAPLING, default => throw new AssumptionFailedError("All tree types should be covered") }); } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 838a32ce8..73ebfeb1f 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\TreeType; +use pocketmine\block\utils\SaplingType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; @@ -39,11 +39,11 @@ use function mt_rand; class Sapling extends Flowable{ protected bool $ready = false; - private TreeType $treeType; + private SaplingType $saplingType; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, TreeType $treeType){ + public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, SaplingType $saplingType){ parent::__construct($idInfo, $name, $typeInfo); - $this->treeType = $treeType; + $this->saplingType = $saplingType; } protected function describeState(RuntimeDataDescriber $w) : void{ @@ -102,7 +102,7 @@ class Sapling extends Flowable{ private function grow(?Player $player) : bool{ $random = new Random(mt_rand()); - $tree = TreeFactory::get($random, $this->treeType); + $tree = TreeFactory::get($random, $this->saplingType->getTreeType()); $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random); if($transaction === null){ return false; diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 86534de83..ac6325d67 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -55,7 +55,7 @@ use pocketmine\block\tile\ShulkerBox as TileShulkerBox; use pocketmine\block\tile\Skull as TileSkull; use pocketmine\block\tile\Smoker as TileSmoker; use pocketmine\block\utils\LeavesType; -use pocketmine\block\utils\TreeType; +use pocketmine\block\utils\SaplingType; use pocketmine\block\utils\WoodType; use pocketmine\crafting\FurnaceType; use pocketmine\entity\projectile\Projectile; @@ -1108,9 +1108,9 @@ final class VanillaBlocks{ }); $saplingTypeInfo = new Info(BreakInfo::instant(), [Tags::POTTABLE_PLANTS]); - foreach(TreeType::getAll() as $treeType){ - $name = $treeType->getDisplayName(); - self::register($treeType->name() . "_sapling", new Sapling(BlockLegacyIdHelper::getSaplingIdentifier($treeType), $name . " Sapling", $saplingTypeInfo, $treeType)); + foreach(SaplingType::getAll() as $saplingType){ + $name = $saplingType->getDisplayName(); + self::register($saplingType->name() . "_sapling", new Sapling(BlockLegacyIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); } foreach(LeavesType::getAll() as $leavesType){ $name = $leavesType->getDisplayName(); diff --git a/src/block/utils/SaplingType.php b/src/block/utils/SaplingType.php new file mode 100644 index 000000000..516ee1516 --- /dev/null +++ b/src/block/utils/SaplingType.php @@ -0,0 +1,71 @@ +Enum___construct($enumName); + } + + public function getTreeType() : TreeType{ return $this->treeType; } + + public function getDisplayName() : string{ + return $this->treeType->getDisplayName(); + } +} diff --git a/src/world/biome/BiomeRegistry.php b/src/world/biome/BiomeRegistry.php index 470360d4b..648184209 100644 --- a/src/world/biome/BiomeRegistry.php +++ b/src/world/biome/BiomeRegistry.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\world\biome; -use pocketmine\block\utils\TreeType; use pocketmine\data\bedrock\BiomeIds; use pocketmine\utils\SingletonTrait; +use pocketmine\world\generator\object\TreeType; final class BiomeRegistry{ use SingletonTrait; diff --git a/src/world/biome/ForestBiome.php b/src/world/biome/ForestBiome.php index f75c303c4..8f80cb474 100644 --- a/src/world/biome/ForestBiome.php +++ b/src/world/biome/ForestBiome.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\world\biome; -use pocketmine\block\utils\TreeType; +use pocketmine\world\generator\object\TreeType; use pocketmine\world\generator\populator\TallGrass; use pocketmine\world\generator\populator\Tree; diff --git a/src/world/biome/TaigaBiome.php b/src/world/biome/TaigaBiome.php index b96c69bcc..cd68c9748 100644 --- a/src/world/biome/TaigaBiome.php +++ b/src/world/biome/TaigaBiome.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\world\biome; -use pocketmine\block\utils\TreeType; +use pocketmine\world\generator\object\TreeType; use pocketmine\world\generator\populator\TallGrass; use pocketmine\world\generator\populator\Tree; diff --git a/src/world/generator/object/TreeFactory.php b/src/world/generator/object/TreeFactory.php index 741ceacf9..ecab73c79 100644 --- a/src/world/generator/object/TreeFactory.php +++ b/src/world/generator/object/TreeFactory.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\world\generator\object; -use pocketmine\block\utils\TreeType; use pocketmine\utils\Random; final class TreeFactory{ diff --git a/src/block/utils/TreeType.php b/src/world/generator/object/TreeType.php similarity index 85% rename from src/block/utils/TreeType.php rename to src/world/generator/object/TreeType.php index 180f17a47..1e8bf56e9 100644 --- a/src/block/utils/TreeType.php +++ b/src/world/generator/object/TreeType.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\block\utils; +namespace pocketmine\world\generator\object; use pocketmine\utils\EnumTrait; @@ -51,7 +51,10 @@ final class TreeType{ new TreeType("birch", "Birch"), new TreeType("jungle", "Jungle"), new TreeType("acacia", "Acacia"), - new TreeType("dark_oak", "Dark Oak") + new TreeType("dark_oak", "Dark Oak"), + //TODO: cherry blossom, mangrove, azalea + //TODO: do crimson and warped "trees" belong here? I'm not sure if they're actually trees or just fungi + //TODO: perhaps huge mushrooms should be here too??? ); } diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index b98af52ee..3e5aef0a7 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -25,11 +25,11 @@ namespace pocketmine\world\generator\populator; use pocketmine\block\BlockTypeIds; use pocketmine\block\BlockTypeTags; -use pocketmine\block\utils\TreeType; use pocketmine\utils\Random; use pocketmine\world\ChunkManager; use pocketmine\world\format\Chunk; use pocketmine\world\generator\object\TreeFactory; +use pocketmine\world\generator\object\TreeType; class Tree implements Populator{ private int $randomAmount = 1;