Move TreeType to generator package, added dedicated SaplingType enum

TreeType includes a bunch of stuff that don't have regular saplings associated with them, such as mangrove and azalea trees.
Mangrove has a dedicated propagule block with different behaviour than the others, and azalea trees are grown from azalea blocks, which are solid and have different behaviour to saplings.

We may also want to account for crimson and warped 'trees' in TreeType too, although I'm not sure if those belong there or not.
This commit is contained in:
Dylan K. Taylor
2023-05-04 16:54:10 +01:00
parent 299ff5d912
commit 2c81446e5b
10 changed files with 97 additions and 24 deletions

View File

@ -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")
});
}

View File

@ -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;

View File

@ -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();

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block\utils;
use pocketmine\utils\EnumTrait;
use pocketmine\world\generator\object\TreeType;
/**
* This doc-block is generated automatically, do not modify it manually.
@ -31,38 +32,40 @@ use pocketmine\utils\EnumTrait;
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static TreeType ACACIA()
* @method static TreeType BIRCH()
* @method static TreeType DARK_OAK()
* @method static TreeType JUNGLE()
* @method static TreeType OAK()
* @method static TreeType SPRUCE()
* @method static SaplingType ACACIA()
* @method static SaplingType BIRCH()
* @method static SaplingType DARK_OAK()
* @method static SaplingType JUNGLE()
* @method static SaplingType OAK()
* @method static SaplingType SPRUCE()
*/
final class TreeType{
final class SaplingType{
use EnumTrait {
register as Enum_register;
__construct as Enum___construct;
}
protected static function setup() : void{
self::registerAll(
new TreeType("oak", "Oak"),
new TreeType("spruce", "Spruce"),
new TreeType("birch", "Birch"),
new TreeType("jungle", "Jungle"),
new TreeType("acacia", "Acacia"),
new TreeType("dark_oak", "Dark Oak")
new self("oak", TreeType::OAK()),
new self("spruce", TreeType::SPRUCE()),
new self("birch", TreeType::BIRCH()),
new self("jungle", TreeType::JUNGLE()),
new self("acacia", TreeType::ACACIA()),
new self("dark_oak", TreeType::DARK_OAK()),
//TODO: cherry
);
}
private function __construct(
string $enumName,
private string $displayName
private TreeType $treeType,
){
$this->Enum___construct($enumName);
}
public function getTreeType() : TreeType{ return $this->treeType; }
public function getDisplayName() : string{
return $this->displayName;
return $this->treeType->getDisplayName();
}
}