PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
Cauldron.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\tile\Cauldron as TileCauldron;
27use pocketmine\block\utils\SupportType;
38use function assert;
39
40final class Cauldron extends Transparent{
41
42 public function writeStateToWorld() : void{
43 parent::writeStateToWorld();
44 $tile = $this->position->getWorld()->getTile($this->position);
45 assert($tile instanceof TileCauldron);
46
47 //empty cauldrons don't use this information
48 $tile->setCustomWaterColor(null);
49 $tile->setPotionItem(null);
50 }
51
52 protected function recalculateCollisionBoxes() : array{
53 $result = [
54 AxisAlignedBB::one()->trim(Facing::UP, 11 / 16) //bottom of the cauldron
55 ];
56
57 foreach(Facing::HORIZONTAL as $f){ //add the frame parts around the bowl
58 $result[] = AxisAlignedBB::one()->trim($f, 14 / 16);
59 }
60 return $result;
61 }
62
63 public function getSupportType(int $facing) : SupportType{
64 return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE;
65 }
66
70 private function fill(int $amount, FillableCauldron $result, Item $usedItem, Item $returnedItem, array &$returnedItems) : void{
71 $this->position->getWorld()->setBlock($this->position, $result->setFillLevel($amount));
72 $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), $result->getFillSound());
73
74 $usedItem->pop();
75 $returnedItems[] = $returnedItem;
76 }
77
78 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
79 if($item->getTypeId() === ItemTypeIds::WATER_BUCKET){
80 $this->fill(FillableCauldron::MAX_FILL_LEVEL, VanillaBlocks::WATER_CAULDRON(), $item, VanillaItems::BUCKET(), $returnedItems);
81 }elseif($item->getTypeId() === ItemTypeIds::LAVA_BUCKET){
82 $this->fill(FillableCauldron::MAX_FILL_LEVEL, VanillaBlocks::LAVA_CAULDRON(), $item, VanillaItems::BUCKET(), $returnedItems);
83 }elseif($item->getTypeId() === ItemTypeIds::POWDER_SNOW_BUCKET){
84 //TODO: powder snow cauldron
85 }elseif($item instanceof Potion || $item instanceof SplashPotion){ //TODO: lingering potion
86 if($item->getType() === PotionType::WATER){
87 $this->fill(WaterCauldron::WATER_BOTTLE_FILL_AMOUNT, VanillaBlocks::WATER_CAULDRON(), $item, VanillaItems::GLASS_BOTTLE(), $returnedItems);
88 }else{
89 $this->fill(PotionCauldron::POTION_FILL_AMOUNT, VanillaBlocks::POTION_CAULDRON()->setPotionItem($item), $item, VanillaItems::GLASS_BOTTLE(), $returnedItems);
90 }
91 }
92
93 return true;
94 }
95
96 public function onNearbyBlockChange() : void{
97 $world = $this->position->getWorld();
98 if($world->getBlock($this->position->up())->getTypeId() === BlockTypeIds::WATER){
99 $cauldron = VanillaBlocks::WATER_CAULDRON()->setFillLevel(FillableCauldron::MAX_FILL_LEVEL);
100 $world->setBlock($this->position, $cauldron);
101 $world->addSound($this->position->add(0.5, 0.5, 0.5), $cauldron->getFillSound());
102 }
103 }
104}
getSupportType(int $facing)
Definition: Cauldron.php:63
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: Cauldron.php:78
pop(int $count=1)
Definition: Item.php:430