11package gregtech .common .metatileentities .storage ;
22
3- import com .cleanroommc .modularui .api .drawable .IDrawable ;
4-
5- import com .cleanroommc .modularui .widget .ParentWidget ;
6-
73import gregtech .api .capability .GregtechDataCodes ;
84import gregtech .api .capability .impl .ItemHandlerList ;
95import gregtech .api .items .itemhandlers .GTItemStackHandler ;
3935import codechicken .lib .render .pipeline .ColourMultiplier ;
4036import codechicken .lib .render .pipeline .IVertexOperation ;
4137import codechicken .lib .vec .Matrix4 ;
38+ import com .cleanroommc .modularui .api .drawable .IDrawable ;
4239import com .cleanroommc .modularui .api .drawable .IKey ;
4340import com .cleanroommc .modularui .api .widget .IWidget ;
4441import com .cleanroommc .modularui .api .widget .Interactable ;
5451import com .cleanroommc .modularui .value .sync .GuiSyncManager ;
5552import com .cleanroommc .modularui .value .sync .IntSyncValue ;
5653import com .cleanroommc .modularui .value .sync .SyncHandlers ;
54+ import com .cleanroommc .modularui .widget .ParentWidget ;
5755import com .cleanroommc .modularui .widget .Widget ;
5856import com .cleanroommc .modularui .widget .scroll .VerticalScrollData ;
5957import com .cleanroommc .modularui .widgets .ItemSlot ;
@@ -242,9 +240,9 @@ public boolean usesMui2() {
242240 @ Override
243241 public ModularPanel buildUI (PosGuiData guiData , GuiSyncManager guiSyncManager ) {
244242 getCraftingRecipeLogic ().updateCurrentRecipe ();
245- if (!guiSyncManager .isClient ()) {
246- writeCustomData (UPDATE_CLIENT_STACKS , getCraftingRecipeLogic ()::writeAvailableStacks );
247- }
243+ // if (!guiSyncManager.isClient()) {
244+ // writeCustomData(UPDATE_CLIENT_STACKS, getCraftingRecipeLogic()::writeAvailableStacks);
245+ // }
248246
249247 guiSyncManager .syncValue ("recipe_logic" , this .recipeLogic );
250248
@@ -270,7 +268,6 @@ public ModularPanel buildUI(PosGuiData guiData, GuiSyncManager guiSyncManager) {
270268 .top (22 )
271269 .margin (7 )
272270 .widthRel (0.9f )
273- // .bottom(100)
274271 .controller (controller )
275272 // workstation page
276273 .addPage (new Column ()
@@ -284,13 +281,7 @@ public ModularPanel buildUI(PosGuiData guiData, GuiSyncManager guiSyncManager) {
284281 .child (createCraftingGrid ())
285282 .child (createCraftingOutput (guiData , guiSyncManager ))
286283 // recipe memory
287- .child (SlotGroupWidget .builder ()
288- .matrix ("XXX" ,
289- "XXX" ,
290- "XXX" )
291- .key ('X' , i -> new RecipeMemorySlot (this .recipeMemory , i ))
292- .build ().right (0 ))
293- )
284+ .child (createRecipeMemoryGrid (guiSyncManager )))
294285 // tool inventory
295286 .child (createToolInventory (guiSyncManager ))
296287 // internal inventory
@@ -360,6 +351,15 @@ public IWidget createCraftingOutput(PosGuiData guiData, GuiSyncManager syncManag
360351 .asWidget ().widthRel (1f ));
361352 }
362353
354+ public IWidget createRecipeMemoryGrid (GuiSyncManager syncManager ) {
355+ return SlotGroupWidget .builder ()
356+ .matrix ("XXX" ,
357+ "XXX" ,
358+ "XXX" )
359+ .key ('X' , i -> new RecipeMemorySlot (this .recipeMemory , i ))
360+ .build ().right (0 );
361+ }
362+
363363 public IWidget createInventoryPage (GuiSyncManager syncManager ) {
364364 var connected = new SlotGroup ("connected_inventory" , 8 , true );
365365 syncManager .registerSlotGroup (connected );
@@ -399,35 +399,26 @@ public IWidget createInventoryPage(GuiSyncManager syncManager) {
399399 }
400400
401401 public void sendHandlerToClient (PacketBuffer buffer ) {
402- int combined = this .combinedInventory .getSlots (),
403- connected = this .connectedInventory .getSlots ();
404-
405- buffer .writeVarInt (connected );
406- buffer .writeVarInt (combined - connected );
407- getCraftingRecipeLogic ().writeAvailableStacks (buffer );
402+ buffer .writeVarInt (this .connectedInventory .getSlots ());
408403 }
409404
410405 @ Override
411406 public void receiveCustomData (int dataId , @ NotNull PacketBuffer buf ) {
412407 super .receiveCustomData (dataId , buf );
413- if (dataId == UPDATE_CLIENT_STACKS ) {
414- getCraftingRecipeLogic ()
415- .updateClientStacks (buf );
408+ if (dataId == UPDATE_CLIENT_HANDLER ) {
409+ int connected = buf .readVarInt ();
416410
417- } else if (dataId == UPDATE_CLIENT_HANDLER ) {
418- int connected = buf .readVarInt (), internal = buf .readVarInt ();
411+ // check if sizes have changed, and keep any existing items
419412
420413 // set connected inventory
421414 this .connectedInventory = new ItemStackHandler (connected );
422415
423416 // set combined inventory
424- this .combinedInventory = new ItemHandlerList (Arrays .asList (this .connectedInventory , new ItemStackHandler (internal )));
417+ this .combinedInventory = new ItemHandlerList (
418+ Arrays .asList (this .connectedInventory , this .internalInventory ));
425419
426420 getCraftingRecipeLogic ()
427421 .updateInventory (this .combinedInventory );
428-
429- getCraftingRecipeLogic ()
430- .updateClientStacks (buf );
431422 }
432423 }
433424
@@ -532,10 +523,14 @@ public CraftingOutputSlot(IItemHandler itemHandler, IntSyncValue syncValue) {
532523 @ Override
533524 public boolean canTakeStack (EntityPlayer playerIn ) {
534525 if (recipeLogic .getSyncManager ().isClient ()) {
535- recipeLogic .syncToServer (3 );
526+ // recipeLogic.syncToServer(3);
536527 return false ;
537528 }
538- return recipeLogic .isRecipeValid () && recipeLogic .consumeRecipeItems (true );
529+
530+ if (recipeLogic .isRecipeValid ())
531+ recipeLogic .collectAvailableItems ();
532+
533+ return recipeLogic .attemptMatchRecipe ();
539534 }
540535
541536 @ Override
@@ -547,16 +542,16 @@ public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack) {
547542
548543 @ Override
549544 public void putStack (@ NotNull ItemStack stack ) {
550- super .putStack (recipeLogic . getCachedRecipeData (). getRecipeOutput ());
545+ super .putStack (getStack ());
551546 }
552547
553548 @ Override
554- public ItemStack decrStackSize (int amount ) {
549+ public @ NotNull ItemStack decrStackSize (int amount ) {
555550 return getStack ();
556551 }
557552
558553 public void handleItemCraft (ItemStack itemStack , EntityPlayer player ) {
559- itemStack .onCrafting (getWorld () , player , 1 );
554+ itemStack .onCrafting (player . world , player , 1 );
560555
561556 var inventoryCrafting = recipeLogic .getCraftingMatrix ();
562557
@@ -569,10 +564,11 @@ public void handleItemCraft(ItemStack itemStack, EntityPlayer player) {
569564 }
570565 if (cachedRecipe != null ) {
571566 ItemStack resultStack = cachedRecipe .getCraftingResult (inventoryCrafting );
572- this .syncValue .setValue (this .syncValue .getValue () + resultStack .getCount (), true , false );
567+ this .syncValue .setValue (this .syncValue .getValue () + resultStack .getCount (), true , true );
573568 // itemsCrafted += resultStack.getCount();
574569 recipeMemory .notifyRecipePerformed (craftingGrid , resultStack );
575570 }
571+ // call method from recipe logic to sync to client
576572 }
577573 }
578574
0 commit comments