mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Implement Suspicious Stew (#5224)
This commit is contained in:
parent
223de3ad23
commit
b65e0f64f6
@ -34,6 +34,7 @@ use pocketmine\block\utils\MushroomBlockType;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\utils\SlabType;
|
||||
use pocketmine\item\PotionType;
|
||||
use pocketmine\item\SuspiciousStewType;
|
||||
use function array_key_first;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
@ -167,6 +168,7 @@ $enumsUsed = [
|
||||
MushroomBlockType::getAll(),
|
||||
SkullType::getAll(),
|
||||
SlabType::getAll(),
|
||||
SuspiciousStewType::getAll(),
|
||||
PotionType::getAll()
|
||||
];
|
||||
|
||||
|
72
src/data/bedrock/SuspiciousStewTypeIdMap.php
Normal file
72
src/data/bedrock/SuspiciousStewTypeIdMap.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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\data\bedrock;
|
||||
|
||||
use pocketmine\item\SuspiciousStewType;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
|
||||
final class SuspiciousStewTypeIdMap{
|
||||
use SingletonTrait;
|
||||
|
||||
/**
|
||||
* @var SuspiciousStewType[]
|
||||
* @phpstan-var array<int, SuspiciousStewType>
|
||||
*/
|
||||
private array $idToEnum;
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
* @phpstan-var array<int, int>
|
||||
*/
|
||||
private array $enumToId;
|
||||
|
||||
private function __construct(){
|
||||
$this->register(SuspiciousStewTypeIds::POPPY, SuspiciousStewType::POPPY());
|
||||
$this->register(SuspiciousStewTypeIds::CORNFLOWER, SuspiciousStewType::CORNFLOWER());
|
||||
$this->register(SuspiciousStewTypeIds::TULIP, SuspiciousStewType::TULIP());
|
||||
$this->register(SuspiciousStewTypeIds::AZURE_BLUET, SuspiciousStewType::AZURE_BLUET());
|
||||
$this->register(SuspiciousStewTypeIds::LILY_OF_THE_VALLEY, SuspiciousStewType::LILY_OF_THE_VALLEY());
|
||||
$this->register(SuspiciousStewTypeIds::DANDELION, SuspiciousStewType::DANDELION());
|
||||
$this->register(SuspiciousStewTypeIds::BLUE_ORCHID, SuspiciousStewType::BLUE_ORCHID());
|
||||
$this->register(SuspiciousStewTypeIds::ALLIUM, SuspiciousStewType::ALLIUM());
|
||||
$this->register(SuspiciousStewTypeIds::OXEYE_DAISY, SuspiciousStewType::OXEYE_DAISY());
|
||||
$this->register(SuspiciousStewTypeIds::WITHER_ROSE, SuspiciousStewType::WITHER_ROSE());
|
||||
}
|
||||
|
||||
private function register(int $id, SuspiciousStewType $type) : void{
|
||||
$this->idToEnum[$id] = $type;
|
||||
$this->enumToId[$type->id()] = $id;
|
||||
}
|
||||
|
||||
public function fromId(int $id) : ?SuspiciousStewType{
|
||||
return $this->idToEnum[$id] ?? null;
|
||||
}
|
||||
|
||||
public function toId(SuspiciousStewType $type) : int{
|
||||
if(!isset($this->enumToId[$type->id()])){
|
||||
throw new \InvalidArgumentException("Type does not have a mapped ID");
|
||||
}
|
||||
return $this->enumToId[$type->id()];
|
||||
}
|
||||
}
|
37
src/data/bedrock/SuspiciousStewTypeIds.php
Normal file
37
src/data/bedrock/SuspiciousStewTypeIds.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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\data\bedrock;
|
||||
|
||||
final class SuspiciousStewTypeIds{
|
||||
public const POPPY = 0;
|
||||
public const CORNFLOWER = 1;
|
||||
public const TULIP = 2;
|
||||
public const AZURE_BLUET = 3;
|
||||
public const LILY_OF_THE_VALLEY = 4;
|
||||
public const DANDELION = 5;
|
||||
public const BLUE_ORCHID = 6;
|
||||
public const ALLIUM = 7;
|
||||
public const OXEYE_DAISY = 8;
|
||||
public const WITHER_ROSE = 9;
|
||||
}
|
@ -37,6 +37,7 @@ use pocketmine\data\bedrock\EntityLegacyIds;
|
||||
use pocketmine\data\bedrock\item\ItemTypeNames as Ids;
|
||||
use pocketmine\data\bedrock\item\SavedItemData as Data;
|
||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||
use pocketmine\data\bedrock\SuspiciousStewTypeIdMap;
|
||||
use pocketmine\item\Durable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems as Items;
|
||||
@ -583,7 +584,14 @@ final class ItemDeserializer{
|
||||
$this->map(Ids::STRING, fn() => Items::STRING());
|
||||
$this->map(Ids::SUGAR, fn() => Items::SUGAR());
|
||||
$this->map(Ids::SUGAR_CANE, fn() => Blocks::SUGARCANE()->asItem());
|
||||
//TODO: minecraft:suspicious_stew
|
||||
$this->map(Ids::SUSPICIOUS_STEW, function(Data $data) : Item{
|
||||
$meta = $data->getMeta();
|
||||
$suspiciousStewType = SuspiciousStewTypeIdMap::getInstance()->fromId($meta);
|
||||
if($suspiciousStewType === null){
|
||||
throw new ItemTypeDeserializeException("Unknown suspicious stew type ID $meta");
|
||||
}
|
||||
return Items::SUSPICIOUS_STEW()->setType($suspiciousStewType);
|
||||
});
|
||||
$this->map(Ids::SWEET_BERRIES, fn() => Items::SWEET_BERRIES());
|
||||
//TODO: minecraft:tadpole_bucket
|
||||
//TODO: minecraft:tadpole_spawn_egg
|
||||
|
@ -36,6 +36,7 @@ use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\data\bedrock\item\ItemTypeNames as Ids;
|
||||
use pocketmine\data\bedrock\item\SavedItemData as Data;
|
||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||
use pocketmine\data\bedrock\SuspiciousStewTypeIdMap;
|
||||
use pocketmine\item\Banner;
|
||||
use pocketmine\item\CoralFan;
|
||||
use pocketmine\item\Dye;
|
||||
@ -43,6 +44,7 @@ use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemBlock;
|
||||
use pocketmine\item\Potion;
|
||||
use pocketmine\item\SplashPotion;
|
||||
use pocketmine\item\SuspiciousStew;
|
||||
use pocketmine\item\VanillaItems as Items;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use function class_parents;
|
||||
@ -513,6 +515,7 @@ final class ItemSerializer{
|
||||
$this->map(Items::STONE_SWORD(), self::id(Ids::STONE_SWORD));
|
||||
$this->map(Items::STRING(), self::id(Ids::STRING));
|
||||
$this->map(Items::SUGAR(), self::id(Ids::SUGAR));
|
||||
$this->map(Items::SUSPICIOUS_STEW(), fn(SuspiciousStew $item) => new Data(Ids::SUSPICIOUS_STEW, SuspiciousStewTypeIdMap::getInstance()->toId($item->getType())));
|
||||
$this->map(Items::SWEET_BERRIES(), self::id(Ids::SWEET_BERRIES));
|
||||
$this->map(Items::TOTEM(), self::id(Ids::TOTEM_OF_UNDYING));
|
||||
$this->map(Items::VILLAGER_SPAWN_EGG(), self::id(Ids::VILLAGER_SPAWN_EGG));
|
||||
|
@ -202,4 +202,20 @@ trait RuntimeEnumDeserializerTrait{
|
||||
};
|
||||
}
|
||||
|
||||
public function suspiciousStewType(\pocketmine\item\SuspiciousStewType &$value) : void{
|
||||
$value = match($this->readInt(4)){
|
||||
0 => \pocketmine\item\SuspiciousStewType::ALLIUM(),
|
||||
1 => \pocketmine\item\SuspiciousStewType::AZURE_BLUET(),
|
||||
2 => \pocketmine\item\SuspiciousStewType::BLUE_ORCHID(),
|
||||
3 => \pocketmine\item\SuspiciousStewType::CORNFLOWER(),
|
||||
4 => \pocketmine\item\SuspiciousStewType::DANDELION(),
|
||||
5 => \pocketmine\item\SuspiciousStewType::LILY_OF_THE_VALLEY(),
|
||||
6 => \pocketmine\item\SuspiciousStewType::OXEYE_DAISY(),
|
||||
7 => \pocketmine\item\SuspiciousStewType::POPPY(),
|
||||
8 => \pocketmine\item\SuspiciousStewType::TULIP(),
|
||||
9 => \pocketmine\item\SuspiciousStewType::WITHER_ROSE(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SuspiciousStewType")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -202,4 +202,20 @@ trait RuntimeEnumSerializerTrait{
|
||||
});
|
||||
}
|
||||
|
||||
public function suspiciousStewType(\pocketmine\item\SuspiciousStewType $value) : void{
|
||||
$this->int(4, match($value){
|
||||
\pocketmine\item\SuspiciousStewType::ALLIUM() => 0,
|
||||
\pocketmine\item\SuspiciousStewType::AZURE_BLUET() => 1,
|
||||
\pocketmine\item\SuspiciousStewType::BLUE_ORCHID() => 2,
|
||||
\pocketmine\item\SuspiciousStewType::CORNFLOWER() => 3,
|
||||
\pocketmine\item\SuspiciousStewType::DANDELION() => 4,
|
||||
\pocketmine\item\SuspiciousStewType::LILY_OF_THE_VALLEY() => 5,
|
||||
\pocketmine\item\SuspiciousStewType::OXEYE_DAISY() => 6,
|
||||
\pocketmine\item\SuspiciousStewType::POPPY() => 7,
|
||||
\pocketmine\item\SuspiciousStewType::TULIP() => 8,
|
||||
\pocketmine\item\SuspiciousStewType::WITHER_ROSE() => 9,
|
||||
default => throw new \pocketmine\utils\AssumptionFailedError("All SuspiciousStewType cases should be covered")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -297,8 +297,9 @@ final class ItemTypeIds{
|
||||
public const POWDER_SNOW_BUCKET = 20258;
|
||||
public const LINGERING_POTION = 20259;
|
||||
public const FIRE_CHARGE = 20260;
|
||||
public const SUSPICIOUS_STEW = 20261;
|
||||
|
||||
public const FIRST_UNUSED_ITEM_ID = 20261;
|
||||
public const FIRST_UNUSED_ITEM_ID = 20262;
|
||||
|
||||
private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;
|
||||
|
||||
|
@ -1118,6 +1118,11 @@ final class StringToItemParser extends StringToTParser{
|
||||
|
||||
$result->register($prefix("dye"), fn() => Items::DYE()->setColor($color));
|
||||
}
|
||||
foreach(SuspiciousStewType::getAll() as $suspiciousStewType){
|
||||
$prefix = fn(string $name) => $suspiciousStewType->name() . "_" . $name;
|
||||
|
||||
$result->register($prefix("suspicious_stew"), fn() => Items::SUSPICIOUS_STEW()->setType($suspiciousStewType));
|
||||
}
|
||||
}
|
||||
|
||||
private static function registerItems(self $result) : void{
|
||||
@ -1474,6 +1479,7 @@ final class StringToItemParser extends StringToTParser{
|
||||
$result->register("strong_turtle_master_potion", fn() => Items::POTION()->setType(PotionType::STRONG_TURTLE_MASTER()));
|
||||
$result->register("strong_turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_TURTLE_MASTER()));
|
||||
$result->register("sugar", fn() => Items::SUGAR());
|
||||
$result->register("suspicious_stew", fn() => Items::SUSPICIOUS_STEW());
|
||||
$result->register("sweet_berries", fn() => Items::SWEET_BERRIES());
|
||||
$result->register("swiftness_potion", fn() => Items::POTION()->setType(PotionType::SWIFTNESS()));
|
||||
$result->register("swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SWIFTNESS()));
|
||||
|
74
src/item/SuspiciousStew.php
Normal file
74
src/item/SuspiciousStew.php
Normal 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\item;
|
||||
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
|
||||
class SuspiciousStew extends Food{
|
||||
|
||||
private SuspiciousStewType $suspiciousStewType;
|
||||
|
||||
public function __construct(ItemIdentifier $identifier, string $name){
|
||||
$this->suspiciousStewType = SuspiciousStewType::POPPY();
|
||||
parent::__construct($identifier, $name);
|
||||
}
|
||||
|
||||
protected function encodeType(RuntimeDataWriter $w) : void{
|
||||
$w->suspiciousStewType($this->suspiciousStewType);
|
||||
}
|
||||
|
||||
public function getType() : SuspiciousStewType{ return $this->suspiciousStewType; }
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setType(SuspiciousStewType $type) : self{
|
||||
$this->suspiciousStewType = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function requiresHunger() : bool{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getSaturationRestore() : float{
|
||||
return 7.2;
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
return $this->suspiciousStewType->getEffects();
|
||||
}
|
||||
|
||||
public function getResidue() : Item{
|
||||
return VanillaItems::BOWL();
|
||||
}
|
||||
}
|
104
src/item/SuspiciousStewType.php
Normal file
104
src/item/SuspiciousStewType.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?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\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\effect\VanillaEffects;
|
||||
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 SuspiciousStewType ALLIUM()
|
||||
* @method static SuspiciousStewType AZURE_BLUET()
|
||||
* @method static SuspiciousStewType BLUE_ORCHID()
|
||||
* @method static SuspiciousStewType CORNFLOWER()
|
||||
* @method static SuspiciousStewType DANDELION()
|
||||
* @method static SuspiciousStewType LILY_OF_THE_VALLEY()
|
||||
* @method static SuspiciousStewType OXEYE_DAISY()
|
||||
* @method static SuspiciousStewType POPPY()
|
||||
* @method static SuspiciousStewType TULIP()
|
||||
* @method static SuspiciousStewType WITHER_ROSE()
|
||||
*/
|
||||
final class SuspiciousStewType{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("poppy", fn() => [
|
||||
new EffectInstance(VanillaEffects::NIGHT_VISION(), 80)
|
||||
]),
|
||||
new self("cornflower", fn() => [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 80)
|
||||
]),
|
||||
new self("tulip", fn() => [
|
||||
new EffectInstance(VanillaEffects::WEAKNESS(), 140)
|
||||
]),
|
||||
new self("azure_bluet", fn() => [
|
||||
new EffectInstance(VanillaEffects::BLINDNESS(), 120)
|
||||
]),
|
||||
new self("lily_of_the_valley", fn() => [
|
||||
new EffectInstance(VanillaEffects::POISON(), 200)
|
||||
]),
|
||||
new self("dandelion", fn() => [
|
||||
new EffectInstance(VanillaEffects::SATURATION(), 6)
|
||||
]),
|
||||
new self("blue_orchid", fn() => [
|
||||
new EffectInstance(VanillaEffects::SATURATION(), 6)
|
||||
]),
|
||||
new self("allium", fn() => [
|
||||
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 40)
|
||||
]),
|
||||
new self("oxeye_daisy", fn() => [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 120)
|
||||
]),
|
||||
new self("wither_rose", fn() => [
|
||||
new EffectInstance(VanillaEffects::WITHER(), 120)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure() : list<EffectInstance> $effectsGetter
|
||||
*/
|
||||
private function __construct(
|
||||
string $enumName,
|
||||
private \Closure $effectsGetter
|
||||
){
|
||||
$this->Enum___construct($enumName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EffectInstance[]
|
||||
* @phpstan-return list<EffectInstance>
|
||||
*/
|
||||
public function getEffects() : array{
|
||||
return ($this->effectsGetter)();
|
||||
}
|
||||
}
|
@ -286,6 +286,7 @@ use pocketmine\world\World;
|
||||
* @method static Sword STONE_SWORD()
|
||||
* @method static StringItem STRING()
|
||||
* @method static Item SUGAR()
|
||||
* @method static SuspiciousStew SUSPICIOUS_STEW()
|
||||
* @method static SweetBerries SWEET_BERRIES()
|
||||
* @method static Totem TOTEM()
|
||||
* @method static SpawnEgg VILLAGER_SPAWN_EGG()
|
||||
@ -518,6 +519,7 @@ final class VanillaItems{
|
||||
self::register("stick", new Stick(new IID(Ids::STICK), "Stick"));
|
||||
self::register("string", new StringItem(new IID(Ids::STRING), "String"));
|
||||
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("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()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user