22declare(strict_types=1);
27use pocketmine\block\utils\ChiseledBookshelfSlot;
28use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
29use pocketmine\block\utils\HorizontalFacingTrait;
39use
function spl_object_id;
42 use HorizontalFacingTrait;
43 use FacesOppositePlacingPlayerTrait;
49 private array $slots = [];
52 $w->horizontalFacing($this->facing);
53 $w->
enumSet($this->slots, ChiseledBookshelfSlot::cases());
60 public function hasSlot(ChiseledBookshelfSlot $slot) : bool{
61 return isset($this->slots[spl_object_id($slot)]);
74 public function setSlot(ChiseledBookshelfSlot $slot,
bool $occupied) : self{
76 $this->slots[spl_object_id($slot)] = $slot;
78 unset($this->slots[spl_object_id($slot)]);
96 if($face !== $this->facing){
100 $x = Facing::axis($face) === Axis::X ? $clickVector->z : $clickVector->x;
101 $slot = ChiseledBookshelfSlot::fromBlockFaceCoordinates(
102 Facing::isPositive(Facing::rotateY($face,
true)) ? 1 - $x : $x,
105 $tile = $this->position->getWorld()->getTile($this->position);
106 if(!$tile instanceof TileChiseledBookshelf){
110 $inventory = $tile->getInventory();
111 if(!$inventory->isSlotEmpty($slot->value)){
112 $returnedItems[] = $inventory->getItem($slot->value);
113 $inventory->clear($slot->value);
114 $this->setSlot($slot,
false);
115 }elseif($item instanceof WritableBookBase || $item instanceof Book || $item instanceof EnchantedBook){
117 $inventory->setItem($slot->value, $item->pop());
118 $this->setSlot($slot,
true);
123 $this->position->getWorld()->setBlock($this->position, $this);
setSlot(ChiseledBookshelfSlot $slot, bool $occupied)
getDropsForCompatibleTool(Item $item)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
describeBlockOnlyState(RuntimeDataDescriber $w)
hasSlot(ChiseledBookshelfSlot $slot)
enumSet(array &$set, array $allCases)