44 private const POTION_CONTAINER_TYPE_NONE = -1;
45 private const POTION_CONTAINER_TYPE_NORMAL = 0;
46 private const POTION_CONTAINER_TYPE_SPLASH = 1;
47 private const POTION_CONTAINER_TYPE_LINGERING = 2;
49 private const POTION_ID_NONE = -1;
51 private const TAG_POTION_ID =
"PotionId";
52 private const TAG_POTION_CONTAINER_TYPE =
"PotionType";
53 private const TAG_CUSTOM_COLOR =
"CustomColor";
55 private ?
Item $potionItem =
null;
56 private ?
Color $customWaterColor =
null;
58 public function getPotionItem() : ?
Item{
return $this->potionItem; }
60 public function setPotionItem(?
Item $potionItem) :
void{
61 $this->potionItem = $potionItem;
64 public function getCustomWaterColor() : ?
Color{
return $this->customWaterColor; }
66 public function setCustomWaterColor(?
Color $customWaterColor) :
void{
67 $this->customWaterColor = $customWaterColor;
71 $nbt->setShort(self::TAG_POTION_CONTAINER_TYPE, match($this->potionItem?->getTypeId()){
72 ItemTypeIds::POTION => self::POTION_CONTAINER_TYPE_NORMAL,
73 ItemTypeIds::SPLASH_POTION => self::POTION_CONTAINER_TYPE_SPLASH,
74 ItemTypeIds::LINGERING_POTION => self::POTION_CONTAINER_TYPE_LINGERING,
75 null => self::POTION_CONTAINER_TYPE_NONE,
79 $type = $this->potionItem instanceof
Potion || $this->potionItem instanceof
SplashPotion ? $this->potionItem->getType() :
null;
80 $nbt->setShort(self::TAG_POTION_ID, $type ===
null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type));
82 if($this->customWaterColor !==
null){
83 $nbt->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB()));
87 public function readSaveData(
CompoundTag $nbt) : void{
88 $containerType = $nbt->getShort(self::TAG_POTION_CONTAINER_TYPE, self::POTION_CONTAINER_TYPE_NONE);
89 $potionId = $nbt->getShort(self::TAG_POTION_ID, self::POTION_ID_NONE);
90 if($containerType !== self::POTION_CONTAINER_TYPE_NONE && $potionId !== self::POTION_ID_NONE){
91 $potionType = PotionTypeIdMap::getInstance()->fromId($potionId);
92 if($potionType ===
null){
93 throw new SavedDataLoadingException(
"Unknown potion type ID $potionId");
95 $this->potionItem = match($containerType){
96 self::POTION_CONTAINER_TYPE_NORMAL => VanillaItems::POTION()->setType($potionType),
97 self::POTION_CONTAINER_TYPE_SPLASH => VanillaItems::SPLASH_POTION()->setType($potionType),
98 self::POTION_CONTAINER_TYPE_LINGERING => VanillaItems::LINGERING_POTION()->setType($potionType),
99 default =>
throw new SavedDataLoadingException(
"Invalid potion container type ID $containerType")
102 $this->potionItem =
null;
105 $this->customWaterColor = ($customColorTag = $nbt->
getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag ? Color::fromARGB(Binary::unsignInt($customColorTag->getValue())) :
null;
109 $nbt->setShort(self::TAG_POTION_CONTAINER_TYPE, match($this->potionItem?->getTypeId()){
110 ItemTypeIds::POTION => self::POTION_CONTAINER_TYPE_NORMAL,
111 ItemTypeIds::SPLASH_POTION => self::POTION_CONTAINER_TYPE_SPLASH,
112 ItemTypeIds::LINGERING_POTION => self::POTION_CONTAINER_TYPE_LINGERING,
113 null => self::POTION_CONTAINER_TYPE_NONE,
117 $type = $this->potionItem instanceof
Potion || $this->potionItem instanceof
SplashPotion ? $this->potionItem->getType() :
null;
118 $nbt->
setShort(self::TAG_POTION_ID, $type ===
null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type));
120 if($this->customWaterColor !==
null){
121 $nbt->
setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB()));
127 $realFillLevel = $block->getFillLevel();
128 return [BlockStateNames::FILL_LEVEL =>
new IntTag($realFillLevel === FillableCauldron::MAX_FILL_LEVEL ? FillableCauldron::MIN_FILL_LEVEL : $realFillLevel + 1)];