PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
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
27use pocketmine\block\tile\BrewingStand as TileBrewingStand;
28use pocketmine\block\utils\BrewingStandSlot;
30use pocketmine\block\utils\ContainerTrait;
31use pocketmine\block\utils\SupportType;
39use function array_key_exists;
40use function spl_object_id;
41
42class BrewingStand extends Transparent implements Container{
43 use ContainerTrait;
44
49 protected array $slots = [];
50
51 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
52 $w->enumSet($this->slots, BrewingStandSlot::cases());
53 }
54
55 protected function recalculateCollisionBoxes() : array{
56 return [
57 //bottom slab part - in PC this is also inset on X/Z by 1/16, but Bedrock sucks
58 AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8),
59
60 //center post
61 AxisAlignedBB::one()
62 ->squashedCopy(Axis::X, 7 / 16)
63 ->squashedCopy(Axis::Z, 7 / 16)
64 ->trimmedCopy(Facing::UP, 1 / 8)
65 ];
66 }
67
68 public function getSupportType(Facing $facing) : SupportType{
69 return SupportType::NONE;
70 }
71
72 public function hasSlot(BrewingStandSlot $slot) : bool{
73 return array_key_exists(spl_object_id($slot), $this->slots);
74 }
75
76 public function setSlot(BrewingStandSlot $slot, bool $occupied) : self{
77 if($occupied){
78 $this->slots[spl_object_id($slot)] = $slot;
79 }else{
80 unset($this->slots[spl_object_id($slot)]);
81 }
82 return $this;
83 }
84
89 public function getSlots() : array{
90 return $this->slots;
91 }
92
94 public function setSlots(array $slots) : self{
95 $this->slots = [];
96 foreach($slots as $slot){
97 $this->slots[spl_object_id($slot)] = $slot;
98 }
99 return $this;
100 }
101
102 protected function newMenu(Player $player, Inventory $inventory, Position $position) : BrewingStandInventoryWindow{
103 return new BrewingStandInventoryWindow($player, $inventory, $position);
104 }
105
106 public function onScheduledUpdate() : void{
107 $world = $this->position->getWorld();
108 $brewing = $world->getTile($this->position);
109 if($brewing instanceof TileBrewingStand){
110 if($brewing->onUpdate()){
111 $world->scheduleDelayedBlockUpdate($this->position, 1);
112 }
113
114 $changed = false;
115 foreach(BrewingStandSlot::cases() as $slot){
116 $occupied = !$brewing->getInventory()->isSlotEmpty($slot->getSlotNumber());
117 if($occupied !== $this->hasSlot($slot)){
118 $this->setSlot($slot, $occupied);
119 $changed = true;
120 }
121 }
122
123 if($changed){
124 $world->setBlock($this->position, $this);
125 }
126 }
127 }
128}
describeBlockOnlyState(RuntimeDataDescriber $w)