PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
BrewingStand.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\BrewingStand as TileBrewingStand;
27use pocketmine\block\utils\BrewingStandSlot;
28use pocketmine\block\utils\SupportType;
36use function array_key_exists;
37use function spl_object_id;
38
40
45 protected array $slots = [];
46
47 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
48 $w->enumSet($this->slots, BrewingStandSlot::cases());
49 }
50
51 protected function recalculateCollisionBoxes() : array{
52 return [
53 //bottom slab part - in PC this is also inset on X/Z by 1/16, but Bedrock sucks
54 AxisAlignedBB::one()->trim(Facing::UP, 7 / 8),
55
56 //center post
57 AxisAlignedBB::one()
58 ->squash(Axis::X, 7 / 16)
59 ->squash(Axis::Z, 7 / 16)
60 ->trim(Facing::UP, 1 / 8)
61 ];
62 }
63
64 public function getSupportType(int $facing) : SupportType{
65 return SupportType::NONE;
66 }
67
68 public function hasSlot(BrewingStandSlot $slot) : bool{
69 return array_key_exists(spl_object_id($slot), $this->slots);
70 }
71
72 public function setSlot(BrewingStandSlot $slot, bool $occupied) : self{
73 if($occupied){
74 $this->slots[spl_object_id($slot)] = $slot;
75 }else{
76 unset($this->slots[spl_object_id($slot)]);
77 }
78 return $this;
79 }
80
85 public function getSlots() : array{
86 return $this->slots;
87 }
88
90 public function setSlots(array $slots) : self{
91 $this->slots = [];
92 foreach($slots as $slot){
93 $this->slots[spl_object_id($slot)] = $slot;
94 }
95 return $this;
96 }
97
98 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
99 if($player instanceof Player){
100 $stand = $this->position->getWorld()->getTile($this->position);
101 if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){
102 $player->setCurrentWindow($stand->getInventory());
103 }
104 }
105
106 return true;
107 }
108
109 public function onScheduledUpdate() : void{
110 $world = $this->position->getWorld();
111 $brewing = $world->getTile($this->position);
112 if($brewing instanceof TileBrewingStand){
113 if($brewing->onUpdate()){
114 $world->scheduleDelayedBlockUpdate($this->position, 1);
115 }
116
117 $changed = false;
118 foreach(BrewingStandSlot::cases() as $slot){
119 $occupied = !$brewing->getInventory()->isSlotEmpty($slot->getSlotNumber());
120 if($occupied !== $this->hasSlot($slot)){
121 $this->setSlot($slot, $occupied);
122 $changed = true;
123 }
124 }
125
126 if($changed){
127 $world->setBlock($this->position, $this);
128 }
129 }
130 }
131}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
describeBlockOnlyState(RuntimeDataDescriber $w)