4848import com .cleanroommc .modularui .utils .Alignment ;
4949import com .cleanroommc .modularui .value .sync .IntSyncValue ;
5050import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
51- import com .cleanroommc .modularui .value .sync .SyncHandlers ;
5251import com .cleanroommc .modularui .widget .scroll .VerticalScrollData ;
5352import com .cleanroommc .modularui .widgets .ButtonWidget ;
5453import com .cleanroommc .modularui .widgets .ItemSlot ;
5756import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
5857import com .cleanroommc .modularui .widgets .layout .Flow ;
5958import com .cleanroommc .modularui .widgets .layout .Grid ;
59+ import com .cleanroommc .modularui .widgets .slot .ModularSlot ;
6060import com .cleanroommc .modularui .widgets .slot .SlotGroup ;
6161import com .google .common .base .Preconditions ;
6262import org .apache .commons .lang3 .ArrayUtils ;
6666
6767import java .util .ArrayList ;
6868import java .util .Arrays ;
69+ import java .util .Collections ;
6970import java .util .List ;
7071
7172public class MetaTileEntityWorkbench extends MetaTileEntity {
@@ -80,8 +81,8 @@ public class MetaTileEntityWorkbench extends MetaTileEntity {
8081 private final ItemStackHandler internalInventory = new GTItemStackHandler (this , 18 );
8182 private final ItemStackHandler toolInventory = new ToolItemStackHandler (9 );
8283
83- private IItemHandlerModifiable combinedInventory ;
84- private IItemHandlerModifiable connectedInventory ;
84+ private ItemHandlerList combinedInventory ;
85+ private ItemHandlerList connectedInventory ;
8586
8687 private final CraftingRecipeMemory recipeMemory = new CraftingRecipeMemory (9 , this .craftingGrid );
8788 private CraftingRecipeLogic recipeLogic = null ;
@@ -202,6 +203,7 @@ public boolean usesMui2() {
202203 @ Override
203204 public ModularPanel buildUI (PosGuiData guiData , PanelSyncManager syncManager ) {
204205 getCraftingRecipeLogic ().updateCurrentRecipe ();
206+ this .recipeLogic .clearSlotMap ();
205207
206208 syncManager .syncValue ("recipe_logic" , this .recipeLogic );
207209 syncManager .syncValue ("recipe_memory" , this .recipeMemory );
@@ -259,6 +261,13 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager) {
259261 .bindPlayerInventory ();
260262 }
261263
264+ private ModularSlot trackSlot (IItemHandler handler , int slot ) {
265+ int offset = combinedInventory .getIndexOffset (handler );
266+ if (offset == -1 ) throw new NullPointerException ("handler cannot be found" );
267+ this .recipeLogic .updateSlotMap (offset , slot );
268+ return new ModularSlot (handler , slot );
269+ }
270+
262271 public IWidget createToolInventory (PanelSyncManager syncManager ) {
263272 var toolSlots = new SlotGroup ("tool_slots" , 9 , -120 , true );
264273 syncManager .registerSlotGroup (toolSlots );
@@ -267,7 +276,7 @@ public IWidget createToolInventory(PanelSyncManager syncManager) {
267276 .row ("XXXXXXXXX" )
268277 .key ('X' , i -> new ItemSlot ()
269278 .background (GTGuiTextures .SLOT , GTGuiTextures .TOOL_SLOT_OVERLAY )
270- .slot (SyncHandlers . itemSlot (this .toolInventory , i )
279+ .slot (trackSlot (this .toolInventory , i )
271280 .slotGroup (toolSlots )))
272281 .build ().marginTop (2 );
273282 }
@@ -280,7 +289,7 @@ public IWidget createInternalInventory(PanelSyncManager syncManager) {
280289 .row ("XXXXXXXXX" )
281290 .row ("XXXXXXXXX" )
282291 .key ('X' , i -> new ItemSlot ()
283- .slot (SyncHandlers . itemSlot (this .internalInventory , i )
292+ .slot (trackSlot (this .internalInventory , i )
284293 .slotGroup (inventory )))
285294 .build ().marginTop (2 );
286295 }
@@ -364,7 +373,7 @@ public IWidget createInventoryPage(PanelSyncManager syncManager) {
364373 int slot = itemSlot .getSlot ().getSlotIndex ();
365374 return slot < this .connectedInventory .getSlots ();
366375 })
367- .slot (SyncHandlers . itemSlot (this .connectedInventory , i )
376+ .slot (trackSlot (this .connectedInventory , i )
368377 .slotGroup (connected )));
369378 }
370379
@@ -400,7 +409,7 @@ public void readHandler(PacketBuffer buf) {
400409 int connected = buf .readVarInt ();
401410
402411 // set connected inventory
403- this .connectedInventory = new ItemStackHandler (connected );
412+ this .connectedInventory = new ItemHandlerList ( Collections . singletonList ( new ItemStackHandler (connected )) );
404413
405414 // set combined inventory
406415 this .combinedInventory = new ItemHandlerList (Arrays .asList (
0 commit comments