Added mangrove, azalea and flowering azalea leaves

This commit is contained in:
Dylan K. Taylor 2023-01-25 18:50:14 +00:00
parent cbaff1caec
commit 2f469ef4a0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
11 changed files with 150 additions and 45 deletions

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
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\WoodType;
use pocketmine\item\VanillaItems;
@ -108,15 +109,18 @@ final class BlockLegacyIdHelper{
});
}
public static function getLeavesIdentifier(TreeType $treeType) : BID{
return new BID(match($treeType->id()){
TreeType::OAK()->id() => Ids::OAK_LEAVES,
TreeType::SPRUCE()->id() => Ids::SPRUCE_LEAVES,
TreeType::BIRCH()->id() => Ids::BIRCH_LEAVES,
TreeType::JUNGLE()->id() => Ids::JUNGLE_LEAVES,
TreeType::ACACIA()->id() => Ids::ACACIA_LEAVES,
TreeType::DARK_OAK()->id() => Ids::DARK_OAK_LEAVES,
default => throw new AssumptionFailedError("All tree types should be covered")
public static function getLeavesIdentifier(LeavesType $leavesType) : BID{
return new BID(match($leavesType->id()){
LeavesType::OAK()->id() => Ids::OAK_LEAVES,
LeavesType::SPRUCE()->id() => Ids::SPRUCE_LEAVES,
LeavesType::BIRCH()->id() => Ids::BIRCH_LEAVES,
LeavesType::JUNGLE()->id() => Ids::JUNGLE_LEAVES,
LeavesType::ACACIA()->id() => Ids::ACACIA_LEAVES,
LeavesType::DARK_OAK()->id() => Ids::DARK_OAK_LEAVES,
LeavesType::MANGROVE()->id() => Ids::MANGROVE_LEAVES,
LeavesType::AZALEA()->id() => Ids::AZALEA_LEAVES,
LeavesType::FLOWERING_AZALEA()->id() => Ids::FLOWERING_AZALEA_LEAVES,
default => throw new AssumptionFailedError("All leaves types should be covered")
});
}

View File

@ -709,8 +709,11 @@ final class BlockTypeIds{
public const CHAIN = 10682;
public const SCULK = 10683;
public const GLOWING_ITEM_FRAME = 10684;
public const MANGROVE_LEAVES = 10685;
public const AZALEA_LEAVES = 10686;
public const FLOWERING_AZALEA_LEAVES = 10687;
public const FIRST_UNUSED_BLOCK_ID = 10685;
public const FIRST_UNUSED_BLOCK_ID = 10688;
private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\LeavesType;
use pocketmine\block\utils\SupportType;
use pocketmine\block\utils\TreeType;
use pocketmine\data\runtime\RuntimeDataReader;
@ -39,13 +40,13 @@ use pocketmine\world\World;
use function mt_rand;
class Leaves extends Transparent{
protected TreeType $treeType;
protected LeavesType $leavesType; //immutable for now
protected bool $noDecay = false;
protected bool $checkDecay = false;
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, TreeType $treeType){
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, LeavesType $leavesType){
parent::__construct($idInfo, $name, $typeInfo);
$this->treeType = $treeType;
$this->leavesType = $leavesType;
}
public function getRequiredStateDataBits() : int{ return 2; }
@ -55,6 +56,8 @@ class Leaves extends Transparent{
$w->bool($this->checkDecay);
}
public function getLeavesType() : LeavesType{ return $this->leavesType; }
public function isNoDecay() : bool{ return $this->noDecay; }
/** @return $this */
@ -140,17 +143,22 @@ class Leaves extends Transparent{
$drops = [];
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = (match($this->treeType){
TreeType::ACACIA() => VanillaBlocks::ACACIA_SAPLING(),
TreeType::BIRCH() => VanillaBlocks::BIRCH_SAPLING(),
TreeType::DARK_OAK() => VanillaBlocks::DARK_OAK_SAPLING(),
TreeType::JUNGLE() => VanillaBlocks::JUNGLE_SAPLING(),
TreeType::OAK() => VanillaBlocks::OAK_SAPLING(),
TreeType::SPRUCE() => VanillaBlocks::SPRUCE_SAPLING(),
$sapling = (match($this->leavesType){
LeavesType::ACACIA() => VanillaBlocks::ACACIA_SAPLING(),
LeavesType::BIRCH() => VanillaBlocks::BIRCH_SAPLING(),
LeavesType::DARK_OAK() => VanillaBlocks::DARK_OAK_SAPLING(),
LeavesType::JUNGLE() => VanillaBlocks::JUNGLE_SAPLING(),
LeavesType::OAK() => VanillaBlocks::OAK_SAPLING(),
LeavesType::SPRUCE() => VanillaBlocks::SPRUCE_SAPLING(),
LeavesType::MANGROVE(), //TODO: mangrove propagule
LeavesType::AZALEA(), LeavesType::FLOWERING_AZALEA() => null, //TODO: azalea
default => throw new AssumptionFailedError("Unreachable")
})->asItem();
})?->asItem();
if($sapling !== null){
$drops[] = $sapling;
}
}
if(($this->treeType->equals(TreeType::OAK()) || $this->treeType->equals(TreeType::DARK_OAK())) && mt_rand(1, 200) === 1){ //Apples
if(($this->leavesType->equals(LeavesType::OAK()) || $this->leavesType->equals(LeavesType::DARK_OAK())) && mt_rand(1, 200) === 1){ //Apples
$drops[] = VanillaItems::APPLE();
}
if(mt_rand(1, 50) === 1){

View File

@ -54,6 +54,7 @@ use pocketmine\block\tile\Note as TileNote;
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\WoodType;
use pocketmine\crafting\FurnaceType;
@ -99,6 +100,7 @@ use function mb_strtolower;
* @method static Stair ANDESITE_STAIRS()
* @method static Wall ANDESITE_WALL()
* @method static Anvil ANVIL()
* @method static Leaves AZALEA_LEAVES()
* @method static Flower AZURE_BLUET()
* @method static Bamboo BAMBOO()
* @method static BambooSapling BAMBOO_SAPLING()
@ -402,6 +404,7 @@ use function mb_strtolower;
* @method static TallGrass FERN()
* @method static Fire FIRE()
* @method static FletchingTable FLETCHING_TABLE()
* @method static Leaves FLOWERING_AZALEA_LEAVES()
* @method static FlowerPot FLOWER_POT()
* @method static Froglight FROGLIGHT()
* @method static FrostedIce FROSTED_ICE()
@ -485,6 +488,7 @@ use function mb_strtolower;
* @method static WoodenDoor MANGROVE_DOOR()
* @method static WoodenFence MANGROVE_FENCE()
* @method static FenceGate MANGROVE_FENCE_GATE()
* @method static Leaves MANGROVE_LEAVES()
* @method static Wood MANGROVE_LOG()
* @method static Planks MANGROVE_PLANKS()
* @method static WoodenPressurePlate MANGROVE_PRESSURE_PLATE()
@ -1106,7 +1110,10 @@ final class VanillaBlocks{
foreach(TreeType::getAll() as $treeType){
$name = $treeType->getDisplayName();
self::register($treeType->name() . "_sapling", new Sapling(BlockLegacyIdHelper::getSaplingIdentifier($treeType), $name . " Sapling", $saplingTypeInfo, $treeType));
self::register($treeType->name() . "_leaves", new Leaves(BlockLegacyIdHelper::getLeavesIdentifier($treeType), $name . " Leaves", $leavesBreakInfo, $treeType));
}
foreach(LeavesType::getAll() as $leavesType){
$name = $leavesType->getDisplayName();
self::register($leavesType->name() . "_leaves", new Leaves(BlockLegacyIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType));
}
$sandstoneBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD()));

View File

@ -0,0 +1,74 @@
<?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;
/**
* 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 LeavesType ACACIA()
* @method static LeavesType AZALEA()
* @method static LeavesType BIRCH()
* @method static LeavesType DARK_OAK()
* @method static LeavesType FLOWERING_AZALEA()
* @method static LeavesType JUNGLE()
* @method static LeavesType MANGROVE()
* @method static LeavesType OAK()
* @method static LeavesType SPRUCE()
*/
final class LeavesType{
use EnumTrait {
register as Enum_register;
__construct as Enum___construct;
}
protected static function setup() : void{
self::registerAll(
new self("oak", "Oak"),
new self("spruce", "Spruce"),
new self("birch", "Birch"),
new self("jungle", "Jungle"),
new self("acacia", "Acacia"),
new self("dark_oak", "Dark Oak"),
new self("mangrove", "Mangrove"),
new self("azalea", "Azalea"),
new self("flowering_azalea", "Flowering Azalea")
);
}
private function __construct(
string $enumName,
private string $displayName
){
$this->Enum___construct($enumName);
}
public function getDisplayName() : string{
return $this->displayName;
}
}

View File

@ -605,6 +605,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
default => throw new BlockStateSerializeException("Invalid Anvil damage {$damage}"),
});
});
$this->map(Blocks::AZALEA_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::AZALEA_LEAVES)));
$this->map(Blocks::AZURE_BLUET(), fn() => Helper::encodeRedFlower(StringValues::FLOWER_TYPE_HOUSTONIA));
$this->map(Blocks::BAMBOO(), function(Bamboo $block) : Writer{
return Writer::create(Ids::BAMBOO)
@ -950,6 +951,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
return Writer::create(Ids::FLOWER_POT)
->writeBool(StateNames::UPDATE_BIT, false); //to keep MCPE happy
});
$this->map(Blocks::FLOWERING_AZALEA_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::AZALEA_LEAVES_FLOWERED)));
$this->map(Blocks::FROGLIGHT(), function(Froglight $block){
return Writer::create(match($block->getFroglightType()){
FroglightType::OCHRE() => Ids::OCHRE_FROGLIGHT,
@ -1086,6 +1088,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
$this->map(Blocks::MANGROVE_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::MANGROVE_BUTTON)));
$this->map(Blocks::MANGROVE_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::MANGROVE_DOOR)));
$this->map(Blocks::MANGROVE_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::MANGROVE_FENCE_GATE)));
$this->map(Blocks::MANGROVE_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::MANGROVE_LEAVES)));
$this->map(Blocks::MANGROVE_LOG(), fn(Wood $block) => Helper::encodeNewLog($block, Ids::MANGROVE_LOG, Ids::STRIPPED_MANGROVE_LOG));
$this->map(Blocks::MANGROVE_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::MANGROVE_PRESSURE_PLATE)));
$this->map(Blocks::MANGROVE_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::MANGROVE_STANDING_SIGN)));

View File

@ -37,6 +37,7 @@ use pocketmine\block\FloorCoralFan;
use pocketmine\block\FloorSign;
use pocketmine\block\GlazedTerracotta;
use pocketmine\block\ItemFrame;
use pocketmine\block\Leaves;
use pocketmine\block\Liquid;
use pocketmine\block\RedMushroomBlock;
use pocketmine\block\RedstoneComparator;
@ -178,6 +179,13 @@ final class BlockStateDeserializerHelper{
->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT));
}
/** @throws BlockStateDeserializeException */
public static function decodeLeaves(Leaves $block, BlockStateReader $in) : Leaves{
return $block
->setNoDecay($in->readBool(StateNames::PERSISTENT_BIT))
->setCheckDecay($in->readBool(StateNames::UPDATE_BIT));
}
/** @throws BlockStateDeserializeException */
public static function decodeLiquid(Liquid $block, BlockStateReader $in, bool $still) : Liquid{
$fluidHeightState = $in->readBoundedInt(BlockStateNames::LIQUID_DEPTH, 0, 15);

View File

@ -147,7 +147,7 @@ final class BlockStateSerializerHelper{
->writeFacingDirection($block->getFacing());
}
private static function encodeLeaves(Leaves $block, BlockStateWriter $out) : BlockStateWriter{
public static function encodeLeaves(Leaves $block, BlockStateWriter $out) : BlockStateWriter{
return $out
->writeBool(BlockStateNames::PERSISTENT_BIT, $block->isNoDecay())
->writeBool(BlockStateNames::UPDATE_BIT, $block->isCheckDecay());

View File

@ -457,6 +457,8 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
})
->setFacing($in->readLegacyHorizontalFacing());
});
$this->map(Ids::AZALEA_LEAVES, fn(Reader $in) => Helper::decodeLeaves(Blocks::AZALEA_LEAVES(), $in));
$this->map(Ids::AZALEA_LEAVES_FLOWERED, fn(Reader $in) => Helper::decodeLeaves(Blocks::FLOWERING_AZALEA_LEAVES(), $in));
$this->map(Ids::BAMBOO, function(Reader $in) : Block{
return Blocks::BAMBOO()
->setLeafSize(match($value = $in->readString(StateNames::BAMBOO_LEAF_SIZE)){
@ -787,26 +789,18 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
->setHanging($in->readBool(StateNames::HANGING));
});
$this->map(Ids::LAVA, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::LAVA(), $in));
$this->map(Ids::LEAVES, function(Reader $in) : Block{
return (match($type = $in->readString(StateNames::OLD_LEAF_TYPE)){
StringValues::OLD_LEAF_TYPE_BIRCH => Blocks::BIRCH_LEAVES(),
StringValues::OLD_LEAF_TYPE_JUNGLE => Blocks::JUNGLE_LEAVES(),
StringValues::OLD_LEAF_TYPE_OAK => Blocks::OAK_LEAVES(),
StringValues::OLD_LEAF_TYPE_SPRUCE => Blocks::SPRUCE_LEAVES(),
default => throw $in->badValueException(StateNames::OLD_LEAF_TYPE, $type),
})
->setNoDecay($in->readBool(StateNames::PERSISTENT_BIT))
->setCheckDecay($in->readBool(StateNames::UPDATE_BIT));
});
$this->map(Ids::LEAVES2, function(Reader $in) : Block{
return (match($type = $in->readString(StateNames::NEW_LEAF_TYPE)){
StringValues::NEW_LEAF_TYPE_ACACIA => Blocks::ACACIA_LEAVES(),
StringValues::NEW_LEAF_TYPE_DARK_OAK => Blocks::DARK_OAK_LEAVES(),
default => throw $in->badValueException(StateNames::NEW_LEAF_TYPE, $type),
})
->setNoDecay($in->readBool(StateNames::PERSISTENT_BIT))
->setCheckDecay($in->readBool(StateNames::UPDATE_BIT));
});
$this->map(Ids::LEAVES, fn(Reader $in) => Helper::decodeLeaves(match($type = $in->readString(StateNames::OLD_LEAF_TYPE)){
StringValues::OLD_LEAF_TYPE_BIRCH => Blocks::BIRCH_LEAVES(),
StringValues::OLD_LEAF_TYPE_JUNGLE => Blocks::JUNGLE_LEAVES(),
StringValues::OLD_LEAF_TYPE_OAK => Blocks::OAK_LEAVES(),
StringValues::OLD_LEAF_TYPE_SPRUCE => Blocks::SPRUCE_LEAVES(),
default => throw $in->badValueException(StateNames::OLD_LEAF_TYPE, $type),
}, $in));
$this->map(Ids::LEAVES2, fn(Reader $in) => Helper::decodeLeaves(match($type = $in->readString(StateNames::NEW_LEAF_TYPE)){
StringValues::NEW_LEAF_TYPE_ACACIA => Blocks::ACACIA_LEAVES(),
StringValues::NEW_LEAF_TYPE_DARK_OAK => Blocks::DARK_OAK_LEAVES(),
default => throw $in->badValueException(StateNames::NEW_LEAF_TYPE, $type),
}, $in));
$this->map(Ids::LECTERN, function(Reader $in) : Block{
return Blocks::LECTERN()
->setFacing($in->readLegacyHorizontalFacing())
@ -887,6 +881,7 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
$this->map(Ids::MANGROVE_DOOR, fn(Reader $in) => Helper::decodeDoor(Blocks::MANGROVE_DOOR(), $in));
$this->mapSlab(Ids::MANGROVE_SLAB, Ids::MANGROVE_DOUBLE_SLAB, fn() => Blocks::MANGROVE_SLAB());
$this->map(Ids::MANGROVE_FENCE_GATE, fn(Reader $in) => Helper::decodeFenceGate(Blocks::MANGROVE_FENCE_GATE(), $in));
$this->map(Ids::MANGROVE_LEAVES, fn(Reader $in) => Helper::decodeLeaves(Blocks::MANGROVE_LEAVES(), $in));
$this->map(Ids::MANGROVE_LOG, fn(Reader $in) => Helper::decodeLog(Blocks::MANGROVE_LOG(), false, $in));
$this->map(Ids::MANGROVE_PRESSURE_PLATE, fn(Reader $in) => Helper::decodeSimplePressurePlate(Blocks::MANGROVE_PRESSURE_PLATE(), $in));
$this->mapStairs(Ids::MANGROVE_STAIRS, fn() => Blocks::MANGROVE_STAIRS());

View File

@ -140,6 +140,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("andesite_wall", fn() => Blocks::ANDESITE_WALL());
$result->registerBlock("anvil", fn() => Blocks::ANVIL());
$result->registerBlock("ateupd_block", fn() => Blocks::INFO_UPDATE2());
$result->registerBlock("azalea_leaves", fn() => Blocks::AZALEA_LEAVES());
$result->registerBlock("azure_bluet", fn() => Blocks::AZURE_BLUET());
$result->registerBlock("bamboo", fn() => Blocks::BAMBOO());
$result->registerBlock("bamboo_sapling", fn() => Blocks::BAMBOO_SAPLING());
@ -625,6 +626,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("fletching_table", fn() => Blocks::FLETCHING_TABLE());
$result->registerBlock("flower_pot", fn() => Blocks::FLOWER_POT());
$result->registerBlock("flower_pot_block", fn() => Blocks::FLOWER_POT());
$result->registerBlock("flowering_azalea_leaves", fn() => Blocks::FLOWERING_AZALEA_LEAVES());
$result->registerBlock("flowing_lava", fn() => Blocks::LAVA());
$result->registerBlock("flowing_water", fn() => Blocks::WATER());
$result->registerBlock("frame", fn() => Blocks::ITEM_FRAME());
@ -755,6 +757,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("mangrove_door", fn() => Blocks::MANGROVE_DOOR());
$result->registerBlock("mangrove_fence", fn() => Blocks::MANGROVE_FENCE());
$result->registerBlock("mangrove_fence_gate", fn() => Blocks::MANGROVE_FENCE_GATE());
$result->registerBlock("mangrove_leaves", fn() => Blocks::MANGROVE_LEAVES());
$result->registerBlock("mangrove_log", fn() => Blocks::MANGROVE_LOG()->setStripped(false));
$result->registerBlock("mangrove_planks", fn() => Blocks::MANGROVE_PLANKS());
$result->registerBlock("mangrove_pressure_plate", fn() => Blocks::MANGROVE_PRESSURE_PLATE());

File diff suppressed because one or more lines are too long