42 private array $changedSlots = [];
44 public function __construct(
45 private int $requestId,
49 public function addSlot(
int $containerInterfaceId,
int $slotId) :
void{
50 $this->changedSlots[$containerInterfaceId][$slotId] = $slotId;
56 private function getInventoryAndSlot(
int $containerInterfaceId,
int $slotId) : ?array{
58 $windowAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slotId);
59 if($windowAndSlot ===
null){
62 [$inventory, $slot] = $windowAndSlot;
63 if(!$inventory->slotExists($slot)){
67 return [$inventory, $slot];
71 $responseInfosByContainer = [];
72 foreach($this->changedSlots as $containerInterfaceId => $slotIds){
73 if($containerInterfaceId === ContainerUIIds::CREATED_OUTPUT){
76 foreach($slotIds as $slotId){
77 $inventoryAndSlot = $this->getInventoryAndSlot($containerInterfaceId, $slotId);
78 if($inventoryAndSlot ===
null){
82 [$inventory, $slot] = $inventoryAndSlot;
84 $itemStackInfo = $this->inventoryManager->getItemStackInfo($inventory, $slot);
85 if($itemStackInfo ===
null){
88 $item = $inventory->getItem($slot);
94 $itemStackInfo->getStackId(),
95 $item->getCustomName(),
96 $item->getCustomName(),
97 $item instanceof
Durable ? $item->getDamage() : 0,
102 $responseContainerInfos = [];
103 foreach($responseInfosByContainer as $containerInterfaceId => $responseInfos){
107 return new ItemStackResponse(ItemStackResponse::RESULT_OK, $this->requestId, $responseContainerInfos);