potionItem; } public function setPotionItem(?Item $potionItem) : void{ $this->potionItem = $potionItem; } public function getCustomWaterColor() : ?Color{ return $this->customWaterColor; } public function setCustomWaterColor(?Color $customWaterColor) : void{ $this->customWaterColor = $customWaterColor; } protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setShort(self::TAG_POTION_CONTAINER_TYPE, match($this->potionItem?->getTypeId()){ ItemTypeIds::POTION => self::POTION_CONTAINER_TYPE_NORMAL, ItemTypeIds::SPLASH_POTION => self::POTION_CONTAINER_TYPE_SPLASH, ItemTypeIds::LINGERING_POTION => self::POTION_CONTAINER_TYPE_LINGERING, null => self::POTION_CONTAINER_TYPE_NONE, default => throw new AssumptionFailedError("Unexpected potion item type") }); //TODO: lingering potion $type = $this->potionItem instanceof Potion || $this->potionItem instanceof SplashPotion ? $this->potionItem->getType() : null; $nbt->setShort(self::TAG_POTION_ID, $type === null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type)); if($this->customWaterColor !== null){ $nbt->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB())); } } public function readSaveData(CompoundTag $nbt) : void{ $containerType = $nbt->getShort(self::TAG_POTION_CONTAINER_TYPE, self::POTION_CONTAINER_TYPE_NONE); $potionId = $nbt->getShort(self::TAG_POTION_ID, self::POTION_ID_NONE); if($containerType !== self::POTION_CONTAINER_TYPE_NONE && $potionId !== self::POTION_ID_NONE){ $potionType = PotionTypeIdMap::getInstance()->fromId($potionId); if($potionType === null){ throw new SavedDataLoadingException("Unknown potion type ID $potionId"); } $this->potionItem = match($containerType){ self::POTION_CONTAINER_TYPE_NORMAL => VanillaItems::POTION()->setType($potionType), self::POTION_CONTAINER_TYPE_SPLASH => VanillaItems::SPLASH_POTION()->setType($potionType), self::POTION_CONTAINER_TYPE_LINGERING => throw new SavedDataLoadingException("Not implemented"), default => throw new SavedDataLoadingException("Invalid potion container type ID $containerType") }; }else{ $this->potionItem = null; } $this->customWaterColor = ($customColorTag = $nbt->getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag ? Color::fromARGB(Binary::unsignInt($customColorTag->getValue())) : null; } protected function writeSaveData(CompoundTag $nbt) : void{ $nbt->setShort(self::TAG_POTION_CONTAINER_TYPE, match($this->potionItem?->getTypeId()){ ItemTypeIds::POTION => self::POTION_CONTAINER_TYPE_NORMAL, ItemTypeIds::SPLASH_POTION => self::POTION_CONTAINER_TYPE_SPLASH, ItemTypeIds::LINGERING_POTION => self::POTION_CONTAINER_TYPE_LINGERING, null => self::POTION_CONTAINER_TYPE_NONE, default => throw new AssumptionFailedError("Unexpected potion item type") }); //TODO: lingering potion $type = $this->potionItem instanceof Potion || $this->potionItem instanceof SplashPotion ? $this->potionItem->getType() : null; $nbt->setShort(self::TAG_POTION_ID, $type === null ? self::POTION_ID_NONE : PotionTypeIdMap::getInstance()->toId($type)); if($this->customWaterColor !== null){ $nbt->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customWaterColor->toARGB())); } } public function getRenderUpdateBugWorkaroundStateProperties(Block $block) : array{ if($block instanceof FillableCauldron){ $realFillLevel = $block->getFillLevel(); return [BlockStateNames::FILL_LEVEL => new IntTag($realFillLevel === FillableCauldron::MAX_FILL_LEVEL ? FillableCauldron::MIN_FILL_LEVEL : $realFillLevel + 1)]; } return []; } }