mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 11:27:07 +00:00
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:
parent
299ff5d912
commit
2c81446e5b
@ -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")
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
71
src/block/utils/SaplingType.php
Normal file
71
src/block/utils/SaplingType.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
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.
|
||||
* This must be regenerated whenever registry members are added, removed or changed.
|
||||
* @see build/generate-registry-annotations.php
|
||||
* @generate-registry-docblock
|
||||
*
|
||||
* @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 SaplingType{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
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 TreeType $treeType,
|
||||
){
|
||||
$this->Enum___construct($enumName);
|
||||
}
|
||||
|
||||
public function getTreeType() : TreeType{ return $this->treeType; }
|
||||
|
||||
public function getDisplayName() : string{
|
||||
return $this->treeType->getDisplayName();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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{
|
||||
|
@ -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???
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user