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,
80 $type = $this->potionItem instanceof
Potion || $this->potionItem instanceof
SplashPotion ? $this->potionItem->getType() :
null;
81 $nbt->setShort(self::TAG_POTION_ID, $type ===
null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type));
83 if($this->customWaterColor !==
null){
84 $nbt->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB()));
88 public function readSaveData(
CompoundTag $nbt) : void{
89 $containerType = $nbt->getShort(self::TAG_POTION_CONTAINER_TYPE, self::POTION_CONTAINER_TYPE_NONE);
90 $potionId = $nbt->getShort(self::TAG_POTION_ID, self::POTION_ID_NONE);
91 if($containerType !== self::POTION_CONTAINER_TYPE_NONE && $potionId !== self::POTION_ID_NONE){
92 $potionType = PotionTypeIdMap::getInstance()->fromId($potionId);
93 if($potionType ===
null){
94 throw new SavedDataLoadingException(
"Unknown potion type ID $potionId");
96 $this->potionItem = match($containerType){
97 self::POTION_CONTAINER_TYPE_NORMAL => VanillaItems::POTION()->setType($potionType),
98 self::POTION_CONTAINER_TYPE_SPLASH => VanillaItems::SPLASH_POTION()->setType($potionType),
99 self::POTION_CONTAINER_TYPE_LINGERING =>
throw new SavedDataLoadingException(
"Not implemented"),
100 default =>
throw new SavedDataLoadingException(
"Invalid potion container type ID $containerType")
103 $this->potionItem =
null;
106 $this->customWaterColor = ($customColorTag = $nbt->
getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag ? Color::fromARGB(Binary::unsignInt($customColorTag->getValue())) :
null;
110 $nbt->setShort(self::TAG_POTION_CONTAINER_TYPE, match($this->potionItem?->getTypeId()){
111 ItemTypeIds::POTION => self::POTION_CONTAINER_TYPE_NORMAL,
112 ItemTypeIds::SPLASH_POTION => self::POTION_CONTAINER_TYPE_SPLASH,
113 ItemTypeIds::LINGERING_POTION => self::POTION_CONTAINER_TYPE_LINGERING,
114 null => self::POTION_CONTAINER_TYPE_NONE,
119 $type = $this->potionItem instanceof
Potion || $this->potionItem instanceof
SplashPotion ? $this->potionItem->getType() :
null;
120 $nbt->
setShort(self::TAG_POTION_ID, $type ===
null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type));
122 if($this->customWaterColor !==
null){
123 $nbt->
setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB()));
129 $realFillLevel = $block->getFillLevel();
130 return [BlockStateNames::FILL_LEVEL =>
new IntTag($realFillLevel === FillableCauldron::MAX_FILL_LEVEL ? FillableCauldron::MIN_FILL_LEVEL : $realFillLevel + 1)];