Selaa lähdekoodia

limit the size

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 4 vuotta sitten
vanhempi
sitoutus
038c3cb1f8

+ 5 - 12
RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java

@@ -34,6 +34,7 @@ import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 public class CollectionUtils {
     public static <A, B> List<B> getOrPutEmptyList(Map<A, List<B>> map, A key) {
@@ -178,33 +179,25 @@ public class CollectionUtils {
     public static <T, R> Optional<R> mapAndMax(List<T> list, Function<T, R> function, Comparator<R> comparator) {
         if (list.isEmpty())
             return Optional.empty();
-        List<R> copyOf = CollectionUtils.map(list, function);
-        copyOf.sort(comparator);
-        return Optional.ofNullable(copyOf.get(copyOf.size() - 1));
+        return list.stream().max(Comparator.comparing(function, comparator)).map(function);
     }
     
     public static <T, R> Optional<R> mapAndMax(T[] list, Function<T, R> function, Comparator<R> comparator) {
         if (list.length <= 0)
             return Optional.empty();
-        List<R> copyOf = CollectionUtils.map(list, function);
-        copyOf.sort(comparator);
-        return Optional.ofNullable(copyOf.get(copyOf.size() - 1));
+        return Stream.of(list).max(Comparator.comparing(function, comparator)).map(function);
     }
     
     public static <T> Optional<T> max(List<T> list, Comparator<T> comparator) {
         if (list.isEmpty())
             return Optional.empty();
-        ArrayList<T> ts = new ArrayList<>(list);
-        ts.sort(comparator);
-        return Optional.ofNullable(ts.get(ts.size() - 1));
+        return list.stream().max(comparator);
     }
     
     public static <T> Optional<T> max(T[] list, Comparator<T> comparator) {
         if (list.length <= 0)
             return Optional.empty();
-        T[] copyOf = list.clone();
-        Arrays.sort(copyOf, comparator);
-        return Optional.ofNullable(copyOf[copyOf.length - 1]);
+        return Stream.of(list).max(comparator);
     }
     
     public static String joinToString(List<String> list, String separator) {

+ 1 - 1
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java

@@ -227,7 +227,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen {
         this.largestWidth = width - 100;
         this.largestHeight = Math.max(height - 34 - 30, 100);
         int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), selectedCategory::getDisplayWidth, Comparator.naturalOrder()).orElse(150);
-        this.guiWidth = Math.max(maxWidthDisplay + 40, 0);
+        this.guiWidth = Math.max(maxWidthDisplay + 40, 190);
         this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight));
         if (!ConfigObject.getInstance().shouldResizeDynamically()) this.guiHeight = largestHeight;
         this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize));

+ 1 - 1
gradle.properties

@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx3G
-mod_version=5.0.2-unstable
+mod_version=5.0.3-unstable
 supported_version=1.16.2+
 minecraft_version=1.16.2-pre1
 yarn_version=1.16.2-pre1+build.1+legacy.20w09a+build.8