diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-29 21:35:20 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-29 21:35:20 +0800 |
| commit | 40d8a8ad7869332f1087d24326ed5b7c32ebf8fd (patch) | |
| tree | 89b246a6d5140e4747585122b6c37da28a559749 /api/src/main/java/me | |
| parent | 096a01c606f491f2bb7a07c3df8ac83f6d313086 (diff) | |
| download | RoughlyEnoughItems-40d8a8ad7869332f1087d24326ed5b7c32ebf8fd.tar.gz RoughlyEnoughItems-40d8a8ad7869332f1087d24326ed5b7c32ebf8fd.tar.bz2 RoughlyEnoughItems-40d8a8ad7869332f1087d24326ed5b7c32ebf8fd.zip | |
Publish REI 6 to Forge
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'api/src/main/java/me')
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java | 54 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java | 70 |
2 files changed, 80 insertions, 44 deletions
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<Display> 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 <A, B> List<B> getOrPutEmptyList(Map<A, List<B>> map, A key) { List<B> b = map.get(key); - if (b != null) + if (b != null) { return b; + } map.put(key, new ArrayList<>()); return map.get(key); } public static <T> T findFirstOrNullEquals(Iterable<T> 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 <T, R> List<R> castAndMap(Iterable<T> list, Class<R> castClass) { List<R> 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> T findFirstOrNull(Iterable<T> list, Predicate<T> predicate) { for (T t : list) { - if (predicate.test(t)) + if (predicate.test(t)) { return t; + } } return null; } public static <T> boolean anyMatch(Iterable<T> list, Predicate<T> predicate) { - for (T t : list) { - if (predicate.test(t)) - return true; - } - return false; + return findFirstOrNull(list, predicate) != null; } public static EntryStack<?> findFirstOrNullEqualsExact(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { @@ -155,8 +155,9 @@ public class CollectionUtils { } public static <T, R> Optional<R> mapAndMax(Collection<T> list, Function<T, R> function, Comparator<R> 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 <T> Optional<T> max(Collection<T> list, Comparator<T> comparator) { - if (list.isEmpty()) + if (list.isEmpty()) { return Optional.empty(); + } return list.stream().max(comparator); } public static <T> Optional<T> max(T[] list, Comparator<T> comparator) { - if (list.length <= 0) + if (list.length <= 0) { return Optional.empty(); + } return Stream.of(list).max(comparator); } - public static String joinToString(Iterable<String> list, String separator) { - StringJoiner joiner = new StringJoiner(separator); - for (String t : list) { - joiner.add(t); - } - return joiner.toString(); + public static String joinToString(Iterable<CharSequence> 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 <T> String mapAndJoinToString(Iterable<T> list, Function<T, String> function, String separator) { + public static <T> String mapAndJoinToString(Iterable<T> list, Function<T, CharSequence> 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 <T> String mapAndJoinToString(T[] list, Function<T, String> function, String separator) { + public static <T> String mapAndJoinToString(T[] list, Function<T, CharSequence> 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 <T> Iterable<Iterable<T>> partition(List<T> list, int size) { - return () -> new UnmodifiableIterator<Iterable<T>>() { + public static <T> Iterable<List<T>> partition(List<T> list, int size) { + return () -> new UnmodifiableIterator<List<T>>() { int i = 0; int partitionSize = Mth.ceil(list.size() / (float) size); @@ -293,22 +288,9 @@ public class CollectionUtils { } @Override - public Iterable<T> next() { - UnmodifiableIterator<T> iterator = new UnmodifiableIterator<T>() { - 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<T> next() { + int cursor = i++ * size; + return list.subList(cursor, cursor + Math.min(list.size() - cursor, size)); } }; } |
