22declare(strict_types=1);
38 public const POTION_FILL_AMOUNT = 2;
40 private ?
Item $potionItem =
null;
43 parent::__construct($idInfo, $name, $typeInfo);
48 $tile = $this->position->getWorld()->getTile($this->position);
49 $this->potionItem = $tile instanceof TileCauldron ? $tile->getPotionItem() :
null;
55 parent::writeStateToWorld();
56 $tile = $this->position->getWorld()->getTile($this->position);
57 assert($tile instanceof TileCauldron);
58 $tile->setCustomWaterColor(
null);
59 $tile->setPotionItem($this->potionItem);
62 public function getPotionItem() : ?
Item{ return $this->potionItem === null ? null : clone $this->potionItem; }
66 if($potionItem !== null && !match($potionItem->getTypeId()){
68 ItemTypeIds::SPLASH_POTION,
69 ItemTypeIds::LINGERING_POTION =>
true,
72 throw new \InvalidArgumentException(
"Item must be a POTION, SPLASH_POTION or LINGERING_POTION");
74 $this->potionItem = $potionItem !==
null ? (clone $potionItem)->setCount(1) :
null;
90 if($this->potionItem !== null && !$usedItem->equals($this->potionItem, true, false)){
91 $this->mix($usedItem, $returnedItem, $returnedItems);
93 $this->addFillLevels($amount, $usedItem, $returnedItem, $returnedItems);
98 match($item->getTypeId()){
99 ItemTypeIds::LINGERING_POTION, ItemTypeIds::POTION, ItemTypeIds::SPLASH_POTION => $this->addFillLevelsOrMix(self::POTION_FILL_AMOUNT, $item, VanillaItems::GLASS_BOTTLE(), $returnedItems),
100 ItemTypeIds::GLASS_BOTTLE => $this->potionItem ===
null ? null : $this->removeFillLevels(self::POTION_FILL_AMOUNT, $item, clone $this->potionItem, $returnedItems),
101 ItemTypeIds::LAVA_BUCKET, ItemTypeIds::POWDER_SNOW_BUCKET, ItemTypeIds::WATER_BUCKET => $this->mix($item, VanillaItems::BUCKET(), $returnedItems),
109 $world = $this->position->getWorld();
110 if($world->getBlock($this->position->up())->getTypeId() === BlockTypeIds::WATER){
111 $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL);
112 $world->setBlock($this->position, $cauldron);
113 $world->addSound($this->position->add(0.5, 0.5, 0.5), $cauldron->getFillSound());
setPotionItem(?Item $potionItem)
addFillLevelsOrMix(int $amount, Item $usedItem, Item $returnedItem, array &$returnedItems)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
__construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo)