mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
Implement Suspicious Stew (#5224)
This commit is contained in:
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")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user