mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Implement torchflower, its seeds and its crop
This commit is contained in:
parent
78cc5ba635
commit
31cd096b4b
@ -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;
|
||||
|
||||
|
90
src/block/TorchflowerCrop.php
Normal file
90
src/block/TorchflowerCrop.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?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;
|
||||
|
||||
use pocketmine\block\utils\BlockEventHelper;
|
||||
use pocketmine\block\utils\StaticSupportTrait;
|
||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||
use pocketmine\item\Fertilizer;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use function mt_rand;
|
||||
|
||||
final class TorchflowerCrop extends Flowable{
|
||||
use StaticSupportTrait;
|
||||
|
||||
private bool $ready = false;
|
||||
|
||||
public function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
||||
$w->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();
|
||||
}
|
||||
}
|
@ -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));
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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());
|
||||
|
34
src/item/TorchflowerSeeds.php
Normal file
34
src/item/TorchflowerSeeds.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
|
||||
final class TorchflowerSeeds extends Item{
|
||||
|
||||
public function getBlock(?int $clickedFace = null) : Block{
|
||||
return VanillaBlocks::TORCHFLOWER_CROP();
|
||||
}
|
||||
}
|
@ -296,6 +296,7 @@ use function strtolower;
|
||||
* @method static Item SUGAR()
|
||||
* @method static SuspiciousStew SUSPICIOUS_STEW()
|
||||
* @method static SweetBerries SWEET_BERRIES()
|
||||
* @method static TorchflowerSeeds TORCHFLOWER_SEEDS()
|
||||
* @method static Totem TOTEM()
|
||||
* @method static TurtleHelmet TURTLE_HELMET()
|
||||
* @method static SpawnEgg VILLAGER_SPAWN_EGG()
|
||||
@ -538,6 +539,7 @@ final class VanillaItems{
|
||||
self::register("sugar", new Item(new IID(Ids::SUGAR), "Sugar"));
|
||||
self::register("suspicious_stew", new SuspiciousStew(new IID(Ids::SUSPICIOUS_STEW), "Suspicious Stew"));
|
||||
self::register("sweet_berries", new SweetBerries(new IID(Ids::SWEET_BERRIES), "Sweet Berries"));
|
||||
self::register("torchflower_seeds", new TorchflowerSeeds(new IID(Ids::TORCHFLOWER_SEEDS), "Torchflower Seeds"));
|
||||
self::register("totem", new Totem(new IID(Ids::TOTEM), "Totem of Undying"));
|
||||
self::register("warped_sign", new ItemBlockWallOrFloor(new IID(Ids::WARPED_SIGN), Blocks::WARPED_SIGN(), Blocks::WARPED_WALL_SIGN()));
|
||||
self::register("water_bucket", new LiquidBucket(new IID(Ids::WATER_BUCKET), "Water Bucket", Blocks::WATER()));
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user