PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
FillableCauldron.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\utils\SupportType;
32use function min;
33
34abstract class FillableCauldron extends Transparent{
35 public const MIN_FILL_LEVEL = 1;
36 public const MAX_FILL_LEVEL = 6;
37
38 private int $fillLevel = self::MIN_FILL_LEVEL;
39
40 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
41 $w->boundedIntAuto(self::MIN_FILL_LEVEL, self::MAX_FILL_LEVEL, $this->fillLevel);
42 }
43
44 public function getFillLevel() : int{ return $this->fillLevel; }
45
47 public function setFillLevel(int $fillLevel) : self{
48 if($fillLevel < self::MIN_FILL_LEVEL || $fillLevel > self::MAX_FILL_LEVEL){
49 throw new \InvalidArgumentException("Fill level must be in range " . self::MIN_FILL_LEVEL . " ... " . self::MAX_FILL_LEVEL);
50 }
51 $this->fillLevel = $fillLevel;
52 return $this;
53 }
54
55 protected function recalculateCollisionBoxes() : array{
56 $result = [
57 AxisAlignedBB::one()->trim(Facing::UP, 11 / 16) //bottom of the cauldron
58 ];
59
60 foreach(Facing::HORIZONTAL as $f){ //add the frame parts around the bowl
61 $result[] = AxisAlignedBB::one()->trim($f, 14 / 16);
62 }
63 return $result;
64 }
65
66 public function getSupportType(int $facing) : SupportType{
67 return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE;
68 }
69
70 protected function withFillLevel(int $fillLevel) : Block{
71 return $fillLevel === 0 ? VanillaBlocks::CAULDRON() : $this->setFillLevel(min(self::MAX_FILL_LEVEL, $fillLevel));
72 }
73
77 protected function addFillLevels(int $amount, Item $usedItem, Item $returnedItem, array &$returnedItems) : void{
78 if($this->fillLevel >= self::MAX_FILL_LEVEL){
79 return;
80 }
81 $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel + $amount));
82 $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), $this->getFillSound());
83
84 $usedItem->pop();
85 $returnedItems[] = $returnedItem;
86 }
87
91 protected function removeFillLevels(int $amount, Item $usedItem, Item $returnedItem, array &$returnedItems) : void{
92 if($this->fillLevel < $amount){
93 return;
94 }
95
96 $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->fillLevel - $amount));
97 $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), $this->getEmptySound());
98
99 $usedItem->pop();
100 $returnedItems[] = $returnedItem;
101 }
102
106 abstract public function getFillSound() : Sound;
107
111 abstract public function getEmptySound() : Sound;
112
116 protected function mix(Item $usedItem, Item $returnedItem, array &$returnedItems) : void{
117 $this->position->getWorld()->setBlock($this->position, VanillaBlocks::CAULDRON());
118 //TODO: sounds and particles
119
120 $usedItem->pop();
121 $returnedItems[] = $returnedItem;
122 }
123
124 public function asItem() : Item{
125 return VanillaBlocks::CAULDRON()->asItem();
126 }
127}
mix(Item $usedItem, Item $returnedItem, array &$returnedItems)
removeFillLevels(int $amount, Item $usedItem, Item $returnedItem, array &$returnedItems)
addFillLevels(int $amount, Item $usedItem, Item $returnedItem, array &$returnedItems)
describeBlockOnlyState(RuntimeDataDescriber $w)
pop(int $count=1)
Definition: Item.php:430