4848import org .jetbrains .annotations .Nullable ;
4949
5050import java .util .ArrayList ;
51- import java .util .HashMap ;
51+ import java .util .LinkedHashMap ;
5252import java .util .List ;
5353import java .util .Map ;
5454import java .util .function .BiFunction ;
@@ -872,29 +872,20 @@ public Builder addRecipeOutputLine(@NotNull List<ItemStack> itemOutputs, @NotNul
872872 */
873873 public Builder addItemOutputLine (@ NotNull List <ItemStack > itemOutputs , int recipeLength ) {
874874 Preconditions .checkNotNull (itemOutputs , "Passed null item list to MultiblockUIFactory#addItemOutputLine" );
875- if (!isStructureFormed || !isActive ) return this ;
876-
877- if (!itemOutputs .isEmpty ()) {
878- Map <String , Long > nameMap = new HashMap <>();
879-
880- for (ItemStack stack : itemOutputs ) {
881- if (stack .isEmpty ()) continue ;
882- nameMap .merge (stack .getDisplayName (), (long ) stack .getCount (), Long ::sum );
883- }
884-
885- for (Map .Entry <String , Long > entry : nameMap .entrySet ()) {
875+ if (!isStructureFormed || !isActive || itemOutputs .isEmpty ()) return this ;
886876
887- }
877+ Map <String , Long > itemMap = new LinkedHashMap <>();
878+ for (ItemStack itemStack : itemOutputs ) {
879+ if (itemStack .isEmpty ()) continue ;
880+ itemMap .merge (itemStack .getDisplayName (), (long ) itemStack .getCount (), Long ::sum );
888881 }
889882
890- itemOutputs .forEach (stack -> {
891- int amount = stack .getCount ();
892-
893- IKey itemName = KeyUtil .string (TextFormatting .AQUA , stack .getDisplayName ());
894- IKey itemAmount = KeyUtil .number (TextFormatting .GOLD , amount );
895- IKey itemRate = KeyUtil .string (TextFormatting .WHITE , formatRecipeRate (recipeLength , amount ));
883+ for (Map .Entry <String , Long > entry : itemMap .entrySet ()) {
884+ IKey itemName = KeyUtil .string (TextFormatting .AQUA , entry .getKey ());
885+ IKey itemAmount = KeyUtil .number (TextFormatting .GOLD , entry .getValue ());
886+ IKey itemRate = KeyUtil .string (TextFormatting .WHITE , formatRecipeRate (recipeLength , entry .getValue ()));
896887 addKey (KeyUtil .string (TextFormatting .WHITE , "%s x %s (%s)" , itemName , itemAmount , itemRate ));
897- });
888+ }
898889
899890 return this ;
900891 }
@@ -908,26 +899,30 @@ public Builder addItemOutputLine(@NotNull List<ItemStack> itemOutputs, int recip
908899 public Builder addFluidOutputLine (@ NotNull List <FluidStack > fluidOutputs , int recipeLength ) {
909900 Preconditions .checkNotNull (fluidOutputs ,
910901 "Passed null fluid list to MultiblockUIFactory#addFluidOutputLine" );
911- if (!isStructureFormed || !isActive ) return this ;
902+ if (!isStructureFormed || !isActive || fluidOutputs . isEmpty () ) return this ;
912903
913- fluidOutputs .forEach (stack -> {
914- int amount = stack .amount ;
904+ Map <FluidStack , Long > fluidMap = new LinkedHashMap <>();
905+ for (FluidStack fluidStack : fluidOutputs ) {
906+ if (fluidStack .amount < 1 ) continue ;
907+ fluidMap .merge (fluidStack , (long ) fluidStack .amount , Long ::sum );
908+ }
915909
916- IKey fluidName = KeyUtil .fluid (TextFormatting .AQUA , stack );
917- IKey fluidAmount = KeyUtil .number (TextFormatting .GOLD , amount );
918- IKey fluidRate = KeyUtil .string (TextFormatting .WHITE , formatRecipeRate (recipeLength , amount ));
910+ for (Map .Entry <FluidStack , Long > entry : fluidMap .entrySet ()) {
911+ IKey fluidName = KeyUtil .fluid (TextFormatting .AQUA , entry .getKey ());
912+ IKey fluidAmount = KeyUtil .number (TextFormatting .GOLD , entry .getValue ());
913+ IKey fluidRate = KeyUtil .string (TextFormatting .WHITE , formatRecipeRate (recipeLength , entry .getValue ()));
919914 addKey (KeyUtil .string (TextFormatting .WHITE , "%s x %s (%s)" , fluidName , fluidAmount , fluidRate ));
920- });
915+ }
921916
922917 return this ;
923918 }
924919
925- private static String formatRecipeRate (int recipeLength , int amount ) {
920+ private static String formatRecipeRate (int recipeLength , long amount ) {
926921 float perSecond = ((float ) amount / recipeLength ) * 20f ;
927922
928923 String rate ;
929924 if (perSecond > 1 ) {
930- rate = String .format ("%.2f" , perSecond ).replaceAll ("\\ .?0+$" , "" ) + "s" ;
925+ rate = String .format ("%.2f" , perSecond ).replaceAll ("\\ .?0+$" , "" ) + "/ s" ;
931926 } else {
932927 rate = String .format ("%.2f" , 1 / (perSecond )).replaceAll ("\\ .?0+$" , "" ) + "s/ea" ;
933928 }
0 commit comments