diff --git a/src/block/BlockTypeIds.php b/src/block/BlockTypeIds.php index f694af279..df9868a34 100644 --- a/src/block/BlockTypeIds.php +++ b/src/block/BlockTypeIds.php @@ -740,8 +740,10 @@ final class BlockTypeIds{ public const CRIMSON_ROOTS = 10710; public const WARPED_ROOTS = 10711; public const CHISELED_BOOKSHELF = 10712; + public const TORCHFLOWER = 10713; + public const TORCHFLOWER_CROP = 10714; - public const FIRST_UNUSED_BLOCK_ID = 10713; + public const FIRST_UNUSED_BLOCK_ID = 10715; private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID; diff --git a/src/block/TorchflowerCrop.php b/src/block/TorchflowerCrop.php new file mode 100644 index 000000000..75efe142b --- /dev/null +++ b/src/block/TorchflowerCrop.php @@ -0,0 +1,90 @@ +bool($this->ready); + } + + public function isReady() : bool{ return $this->ready; } + + public function setReady(bool $ready) : self{ + $this->ready = $ready; + return $this; + } + + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND; + } + + private function getNextState() : Block{ + if($this->ready){ + return VanillaBlocks::TORCHFLOWER(); + }else{ + return VanillaBlocks::TORCHFLOWER_CROP()->setReady(true); + } + } + + public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + if($item instanceof Fertilizer){ + if(BlockEventHelper::grow($this, $this->getNextState(), $player)){ + $item->pop(); + } + + return true; + } + + return false; + } + + public function ticksRandomly() : bool{ + return true; + } + + public function onRandomTick() : void{ + if(mt_rand(0, 2) === 1){ + BlockEventHelper::grow($this, $this->getNextState(), null); + } + } + + public function asItem() : Item{ + return VanillaItems::TORCHFLOWER_SEEDS(); + } +} diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 4657b79b5..43d72ccf0 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -726,6 +726,8 @@ use function strtolower; * @method static TintedGlass TINTED_GLASS() * @method static TNT TNT() * @method static Torch TORCH() + * @method static Flower TORCHFLOWER() + * @method static TorchflowerCrop TORCHFLOWER_CROP() * @method static TrappedChest TRAPPED_CHEST() * @method static Tripwire TRIPWIRE() * @method static TripwireHook TRIPWIRE_HOOK() @@ -879,6 +881,8 @@ final class VanillaBlocks{ self::register("pink_tulip", new Flower(new BID(Ids::PINK_TULIP), "Pink Tulip", $flowerTypeInfo)); self::register("red_tulip", new Flower(new BID(Ids::RED_TULIP), "Red Tulip", $flowerTypeInfo)); self::register("white_tulip", new Flower(new BID(Ids::WHITE_TULIP), "White Tulip", $flowerTypeInfo)); + self::register("torchflower", new Flower(new BID(Ids::TORCHFLOWER), "Torchflower", $flowerTypeInfo)); + self::register("torchflower_crop", new TorchflowerCrop(new BID(Ids::TORCHFLOWER_CROP), "Torchflower Crop", new Info(BreakInfo::instant()))); self::register("flower_pot", new FlowerPot(new BID(Ids::FLOWER_POT, TileFlowerPot::class), "Flower Pot", new Info(BreakInfo::instant()))); self::register("frosted_ice", new FrostedIce(new BID(Ids::FROSTED_ICE), "Frosted Ice", new Info(BreakInfo::pickaxe(2.5)))); self::register("furnace", new Furnace(new BID(Ids::FURNACE, TileNormalFurnace::class), "Furnace", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD)), FurnaceType::FURNACE)); diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 54e77d2eb..fb0003363 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -136,6 +136,7 @@ use pocketmine\block\Sugarcane; use pocketmine\block\SweetBerryBush; use pocketmine\block\TNT; use pocketmine\block\Torch; +use pocketmine\block\TorchflowerCrop; use pocketmine\block\Trapdoor; use pocketmine\block\TrappedChest; use pocketmine\block\Tripwire; @@ -955,6 +956,7 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ $this->mapSimple(Blocks::SOUL_SOIL(), Ids::SOUL_SOIL); $this->mapSimple(Blocks::SPORE_BLOSSOM(), Ids::SPORE_BLOSSOM); $this->mapSimple(Blocks::TINTED_GLASS(), Ids::TINTED_GLASS); + $this->mapSimple(Blocks::TORCHFLOWER(), Ids::TORCHFLOWER); $this->mapSimple(Blocks::TUFF(), Ids::TUFF); $this->mapSimple(Blocks::WARPED_WART_BLOCK(), Ids::WARPED_WART_BLOCK); $this->mapSimple(Blocks::WARPED_ROOTS(), Ids::WARPED_ROOTS); @@ -1643,6 +1645,10 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ return Writer::create(Ids::TORCH) ->writeTorchFacing($block->getFacing()); }); + $this->map(Blocks::TORCHFLOWER_CROP(), function(TorchflowerCrop $block){ + return Writer::create(Ids::TORCHFLOWER_CROP) + ->writeInt(StateNames::GROWTH, $block->isReady() ? 1 : 0); + }); $this->map(Blocks::TRAPPED_CHEST(), function(TrappedChest $block) : Writer{ return Writer::create(Ids::TRAPPED_CHEST) ->writeHorizontalFacing($block->getFacing()); diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index 3198a60d4..be466de3f 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -844,6 +844,7 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ $this->mapSimple(Ids::SPORE_BLOSSOM, fn() => Blocks::SPORE_BLOSSOM()); $this->mapSimple(Ids::STONECUTTER, fn() => Blocks::LEGACY_STONECUTTER()); $this->mapSimple(Ids::TINTED_GLASS, fn() => Blocks::TINTED_GLASS()); + $this->mapSimple(Ids::TORCHFLOWER, fn() => Blocks::TORCHFLOWER()); $this->mapSimple(Ids::TUFF, fn() => Blocks::TUFF()); $this->mapSimple(Ids::UNDYED_SHULKER_BOX, fn() => Blocks::SHULKER_BOX()); $this->mapSimple(Ids::WARPED_WART_BLOCK, fn() => Blocks::WARPED_WART_BLOCK()); @@ -1565,6 +1566,11 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return Blocks::TORCH() ->setFacing($in->readTorchFacing()); }); + $this->map(Ids::TORCHFLOWER_CROP, function(Reader $in) : Block{ + return Blocks::TORCHFLOWER_CROP() + //this property can have values 0-7, but only 0-1 are valid + ->setReady($in->readBoundedInt(StateNames::GROWTH, 0, 7) !== 0); + }); $this->map(Ids::TRAPPED_CHEST, function(Reader $in) : Block{ return Blocks::TRAPPED_CHEST() ->setFacing($in->readHorizontalFacing()); diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index dd506526d..be628d071 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -359,6 +359,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::STRING, Items::STRING()); $this->map1to1Item(Ids::SUGAR, Items::SUGAR()); $this->map1to1Item(Ids::SWEET_BERRIES, Items::SWEET_BERRIES()); + $this->map1to1Item(Ids::TORCHFLOWER_SEEDS, Items::TORCHFLOWER_SEEDS()); $this->map1to1Item(Ids::TOTEM_OF_UNDYING, Items::TOTEM()); $this->map1to1Item(Ids::TROPICAL_FISH, Items::CLOWNFISH()); $this->map1to1Item(Ids::TURTLE_HELMET, Items::TURTLE_HELMET()); diff --git a/src/item/ItemTypeIds.php b/src/item/ItemTypeIds.php index 823339766..4c2f0a1ec 100644 --- a/src/item/ItemTypeIds.php +++ b/src/item/ItemTypeIds.php @@ -304,8 +304,9 @@ final class ItemTypeIds{ public const GLOW_BERRIES = 20265; public const CHERRY_SIGN = 20266; public const ENCHANTED_BOOK = 20267; + public const TORCHFLOWER_SEEDS = 20268; - public const FIRST_UNUSED_ITEM_ID = 20268; + public const FIRST_UNUSED_ITEM_ID = 20269; private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID; diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index ca8e9180f..2e05ddc6e 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -1082,6 +1082,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("tinted_glass", fn() => Blocks::TINTED_GLASS()); $result->registerBlock("tnt", fn() => Blocks::TNT()); $result->registerBlock("torch", fn() => Blocks::TORCH()); + $result->registerBlock("torchflower", fn() => Blocks::TORCHFLOWER()); $result->registerBlock("trapdoor", fn() => Blocks::OAK_TRAPDOOR()); $result->registerBlock("trapped_chest", fn() => Blocks::TRAPPED_CHEST()); $result->registerBlock("trip_wire", fn() => Blocks::TRIPWIRE()); @@ -1467,6 +1468,7 @@ final class StringToItemParser extends StringToTParser{ $result->register("suspicious_stew", fn() => Items::SUSPICIOUS_STEW()); $result->register("sweet_berries", fn() => Items::SWEET_BERRIES()); $result->register("tonic", fn() => Items::MEDICINE()->setType(MedicineType::TONIC)); + $result->register("torchflower_seeds", fn() => Items::TORCHFLOWER_SEEDS()); $result->register("totem", fn() => Items::TOTEM()); $result->register("turtle_helmet", fn() => Items::TURTLE_HELMET()); $result->register("turtle_shell_piece", fn() => Items::SCUTE()); diff --git a/src/item/TorchflowerSeeds.php b/src/item/TorchflowerSeeds.php new file mode 100644 index 000000000..123af35a0 --- /dev/null +++ b/src/item/TorchflowerSeeds.php @@ -0,0 +1,34 @@ +