From 40d8a8ad7869332f1087d24326ed5b7c32ebf8fd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 29 Mar 2021 21:35:20 +0800 Subject: Publish REI 6 to Forge Signed-off-by: shedaniel --- .../rei/api/client/gui/screen/DisplayScreen.java | 54 +++++++++++++++++ .../rei/api/common/util/CollectionUtils.java | 70 ++++++++-------------- 2 files changed, 80 insertions(+), 44 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java new file mode 100644 index 000000000..259088e2f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java @@ -0,0 +1,54 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.client.gui.screen; + +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.entry.EntryStack; + +public interface DisplayScreen { + Rectangle getBounds(); + + void setIngredientStackToNotice(EntryStack stack); + + void setResultStackToNotice(EntryStack stack); + + EntryStack getIngredientStackToNotice(); + + EntryStack getResultStackToNotice(); + + default CategoryIdentifier getCurrentCategoryId() { + return getCurrentCategory().getCategoryIdentifier(); + } + + DisplayCategory getCurrentCategory(); + + void recalculateCategoryPage(); + + void previousCategory(); + + void nextCategory(); +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 45d065ee6..a191d85ce 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -47,16 +47,18 @@ import java.util.stream.StreamSupport; public class CollectionUtils { public static List getOrPutEmptyList(Map> map, A key) { List b = map.get(key); - if (b != null) + if (b != null) { return b; + } map.put(key, new ArrayList<>()); return map.get(key); } public static T findFirstOrNullEquals(Iterable list, T obj) { for (T t : list) { - if (t.equals(obj)) + if (t.equals(obj)) { return t; + } } return null; } @@ -64,26 +66,24 @@ public class CollectionUtils { public static List castAndMap(Iterable list, Class castClass) { List l = new ArrayList<>(); for (T t : list) { - if (castClass.isAssignableFrom(t.getClass())) + if (castClass.isAssignableFrom(t.getClass())) { l.add((R) t); + } } return l; } public static T findFirstOrNull(Iterable list, Predicate predicate) { for (T t : list) { - if (predicate.test(t)) + if (predicate.test(t)) { return t; + } } return null; } public static boolean anyMatch(Iterable list, Predicate predicate) { - for (T t : list) { - if (predicate.test(t)) - return true; - } - return false; + return findFirstOrNull(list, predicate) != null; } public static EntryStack findFirstOrNullEqualsExact(Iterable> list, EntryStack stack) { @@ -155,8 +155,9 @@ public class CollectionUtils { } public static Optional mapAndMax(Collection list, Function function, Comparator comparator) { - if (list.isEmpty()) + if (list.isEmpty()) { return Optional.empty(); + } return list.stream().max(Comparator.comparing(function, comparator)).map(function); } @@ -167,34 +168,28 @@ public class CollectionUtils { } public static Optional max(Collection list, Comparator comparator) { - if (list.isEmpty()) + if (list.isEmpty()) { return Optional.empty(); + } return list.stream().max(comparator); } public static Optional max(T[] list, Comparator comparator) { - if (list.length <= 0) + if (list.length <= 0) { return Optional.empty(); + } return Stream.of(list).max(comparator); } - public static String joinToString(Iterable list, String separator) { - StringJoiner joiner = new StringJoiner(separator); - for (String t : list) { - joiner.add(t); - } - return joiner.toString(); + public static String joinToString(Iterable list, CharSequence separator) { + return String.join(separator, list); } - public static String joinToString(String[] list, String separator) { - StringJoiner joiner = new StringJoiner(separator); - for (String t : list) { - joiner.add(t); - } - return joiner.toString(); + public static String joinToString(CharSequence[] list, CharSequence separator) { + return String.join(separator, list); } - public static String mapAndJoinToString(Iterable list, Function function, String separator) { + public static String mapAndJoinToString(Iterable list, Function function, CharSequence separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); @@ -202,7 +197,7 @@ public class CollectionUtils { return joiner.toString(); } - public static String mapAndJoinToString(T[] list, Function function, String separator) { + public static String mapAndJoinToString(T[] list, Function function, CharSequence separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); @@ -282,8 +277,8 @@ public class CollectionUtils { return sum; } - public static Iterable> partition(List list, int size) { - return () -> new UnmodifiableIterator>() { + public static Iterable> partition(List list, int size) { + return () -> new UnmodifiableIterator>() { int i = 0; int partitionSize = Mth.ceil(list.size() / (float) size); @@ -293,22 +288,9 @@ public class CollectionUtils { } @Override - public Iterable next() { - UnmodifiableIterator iterator = new UnmodifiableIterator() { - int cursor = i++ * size; - int curSize = cursor + Math.min(list.size() - cursor, size); - - @Override - public boolean hasNext() { - return cursor < curSize; - } - - @Override - public T next() { - return list.get(cursor++); - } - }; - return () -> iterator; + public List next() { + int cursor = i++ * size; + return list.subList(cursor, cursor + Math.min(list.size() - cursor, size)); } }; } -- cgit