@@ -549,17 +549,20 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
549549 Flow row = Flow .row ()
550550 .height (3 * 18 )
551551 .debugName ("row:recipemapui.parent" )
552+ .alignX (0.5f )
552553 .crossAxisAlignment (Alignment .CrossAxis .CENTER )
553554 .top (23 - 7 );
554555
555- // this isn't great but it works for now
556- // panel size is hardcoded because you can't get the panel size from the panel
557- int m = calculateCenter (importItems .getSlots (), importFluids .getTanks (), 176 + 20 );
556+ int progressSize = 20 ;
558557 int margin = 6 ;
558+ row .width (calculateWidth (importItems .getSlots (), importFluids .getTanks (),
559+ exportItems .getSlots (), exportFluids .getTanks (),
560+ progressSize , margin ));
561+
562+ if (!this .isLeftGreater ) row .mainAxisAlignment (Alignment .MainAxis .END );
559563
560564 if (importItems .getSlots () > 0 || importFluids .getTanks () > 0 ) {
561- row .child (makeInventorySlotGroup (importItems , importFluids , false )
562- .marginLeft (m - margin ));
565+ row .child (makeInventorySlotGroup (importItems , importFluids , false ));
563566 }
564567 RecipeProgressWidget progressWidget = new RecipeProgressWidget ();
565568 if (this .extraOverlays != null ) {
@@ -568,7 +571,7 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
568571 row .child (progressWidget
569572 .recipeMap (recipeMap )
570573 .debugName ("recipe.progress" )
571- .size (20 )
574+ .size (progressSize )
572575 .margin (margin , 0 )
573576 .value (progressValue )
574577 .texture (progressTexture , 20 )
@@ -579,15 +582,31 @@ public ModularPanel constructPanel(ModularPanel panel, DoubleSupplier progressSu
579582 return panel .child (row );
580583 }
581584
582- private int calculateCenter (int inputItems , int inputFluids , int panelSize ) {
583- int [] ints = determineSlotsGrid (inputItems , inputFluids );
584- int leftSize = ints [1 ] >= inputFluids && ints [0 ] < 3 ?
585- (ints [0 ] + ints [2 ]) * 18 :
586- Math .max (ints [0 ] * 18 , ints [2 ] * 18 );
587- int p = panelSize / 2 ;
588- p -= 10 ;
589- p -= leftSize ;
590- return p ;
585+ boolean isLeftGreater = false ;
586+
587+ private int calculateWidth (int inputItems , int inputFluids ,
588+ int outputItems , int outputFluids ,
589+ int progressSize , int margin ) {
590+ int [] inputGrid = determineSlotsGrid (inputItems , inputFluids );
591+ int [] outputGrid = determineSlotsGrid (outputItems , outputFluids );
592+
593+ int w1 = getGridWidth (inputGrid , inputFluids );
594+ int w2 = getGridWidth (outputGrid , outputFluids );
595+
596+ this .isLeftGreater = w1 >= w2 ;
597+ return (Math .max (w1 , w2 ) + margin ) * 2 + progressSize ;
598+ }
599+
600+ private int getGridWidth (int [] grid , int fluidCount ) {
601+ if (isSingleRow (grid , fluidCount )) {
602+ return (grid [0 ] + grid [2 ]) * 18 ;
603+ } else {
604+ return Math .max (grid [0 ] * 18 , (grid [2 ] * 18 ));
605+ }
606+ }
607+
608+ private boolean isSingleRow (int [] grid , int fluidCount ) {
609+ return grid [1 ] >= fluidCount && grid [0 ] < 3 ;
591610 }
592611
593612 private Widget <?> makeItemGroup (int width , IItemHandlerModifiable handler , boolean isOutputs ) {
@@ -641,10 +660,11 @@ protected Widget<?> makeInventorySlotGroup(@NotNull IItemHandlerModifiable itemH
641660
642661 int fluidGridWidth = slotGridSizes [2 ];
643662 int fluidGridHeight = slotGridSizes [3 ];
644- boolean singleRow = itemGridHeight >= fluidInputsCount && itemGridWidth < 3 ;
663+ boolean singleRow = isSingleRow ( slotGridSizes , fluidInputsCount ) ;
645664
646- Flow flow = (singleRow ? Flow .row () : Flow .column ()).coverChildren ()
647- .debugName (singleRow ? "parent.row" : "parent.col" );
665+ Flow flow = (singleRow ? Flow .row () : Flow .column ())
666+ .coverChildren ()
667+ .debugName (singleRow ? "row:parent" : "col:parent" );
648668 flow .crossAxisAlignment (isOutputs ? Alignment .CrossAxis .START : Alignment .CrossAxis .END );
649669
650670 if (!onlyFluids && fluidGridHeight > 1 ) {
0 commit comments