11package com .cleanroommc .modularui .screen ;
22
33import com .cleanroommc .modularui .widgets .slot .ModularSlot ;
4-
54import com .cleanroommc .modularui .widgets .slot .SlotGroup ;
65
76import net .minecraft .entity .player .EntityPlayer ;
87import net .minecraft .entity .player .InventoryPlayer ;
98import net .minecraft .inventory .ClickType ;
9+ import net .minecraft .inventory .Container ;
1010import net .minecraft .inventory .IInventory ;
1111import net .minecraft .inventory .Slot ;
1212import net .minecraft .item .ItemStack ;
13-
1413import net .minecraft .world .World ;
1514import net .minecraftforge .items .ItemHandlerHelper ;
1615
@@ -140,6 +139,40 @@ public void onContainerClosed() {}
140139 }
141140 clickedSlot .onSlotChanged ();
142141 }
142+ container .detectAndSendChanges ();
143+ return returnable ;
144+ } else if (clickTypeIn == ClickType .PICKUP_ALL && slotId >= 0 ) {
145+ Slot slot = container .inventorySlots .get (slotId );
146+ ItemStack itemstack1 = inventoryplayer .getItemStack ();
147+
148+ if (!itemstack1 .isEmpty () && (slot == null || !slot .getHasStack () || !slot .canTakeStack (player ))) {
149+ int i = mouseButton == 0 ? 0 : container .inventorySlots .size () - 1 ;
150+ int j = mouseButton == 0 ? 1 : -1 ;
151+
152+ for (int k = 0 ; k < 2 ; ++k ) {
153+ for (int l = i ; l >= 0 && l < container .inventorySlots .size () && itemstack1 .getCount () < itemstack1 .getMaxStackSize (); l += j ) {
154+ Slot slot1 = container .inventorySlots .get (l );
155+ if (slot1 instanceof ModularSlot modularSlot && modularSlot .isPhantom ()) continue ;
156+
157+ if (slot1 .getHasStack () && Container .canAddItemToSlot (slot1 , itemstack1 , true ) && slot1 .canTakeStack (player ) && canMergeSlot (itemstack1 , slot1 )) {
158+ ItemStack itemstack2 = slot1 .getStack ();
159+
160+ if (k != 0 || itemstack2 .getCount () != itemstack2 .getMaxStackSize ()) {
161+ int i1 = Math .min (itemstack1 .getMaxStackSize () - itemstack1 .getCount (), itemstack2 .getCount ());
162+ ItemStack itemstack3 = slot1 .decrStackSize (i1 );
163+ itemstack1 .grow (i1 );
164+
165+ if (itemstack3 .isEmpty ()) {
166+ slot1 .putStack (ItemStack .EMPTY );
167+ }
168+
169+ slot1 .onTake (player , itemstack3 );
170+ }
171+ }
172+ }
173+ }
174+ }
175+
143176 container .detectAndSendChanges ();
144177 return returnable ;
145178 }
@@ -154,7 +187,7 @@ public void onContainerClosed() {}
154187 if (!stack .isEmpty ()) {
155188 stack = stack .copy ();
156189 int base = 0 ;
157- if (stack .getCount () > stack .getMaxStackSize ()) {
190+ if (stack .getCount () > stack .getMaxStackSize ()) {
158191 base = stack .getCount () - stack .getMaxStackSize ();
159192 stack .setCount (stack .getMaxStackSize ());
160193 }
0 commit comments