aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-12-25 00:10:10 +0800
committershedaniel <daniel@shedaniel.me>2024-04-16 00:38:17 +0900
commitc93345b568ba0c6231986cac30485e689212c731 (patch)
treef99a81395cf624315f4de3e56296cfa811668902 /api/src
parentffe21652b40a93a00f33a27a5ecf41479b48bcd9 (diff)
downloadRoughlyEnoughItems-c93345b568ba0c6231986cac30485e689212c731.tar.gz
RoughlyEnoughItems-c93345b568ba0c6231986cac30485e689212c731.tar.bz2
RoughlyEnoughItems-c93345b568ba0c6231986cac30485e689212c731.zip
Implement Unified Ingredients
Diffstat (limited to 'api/src')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java51
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntryIngredientSetting.java33
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java9
3 files changed, 90 insertions, 3 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java
index f0c634b11..f21719676 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java
@@ -23,13 +23,16 @@
package me.shedaniel.rei.api.common.entry;
+import me.shedaniel.rei.api.common.entry.settings.EntryIngredientSetting;
import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
import me.shedaniel.rei.impl.Internals;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
import java.util.List;
+import java.util.UUID;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collector;
@@ -198,6 +201,54 @@ public interface EntryIngredient extends List<EntryStack<?>> {
*/
EntryIngredient map(UnaryOperator<EntryStack<?>> transformer);
+ /**
+ * Returns the value of a {@link EntryIngredientSetting} of this {@link EntryIngredient}.
+ * <p>
+ * This method returns {@code null} if the setting is not set.
+ *
+ * @param setting the setting to get
+ * @param <T> the type of the setting
+ * @return the value of the setting
+ */
+ @Nullable
+ @ApiStatus.Experimental
+ <T> T getSetting(EntryIngredientSetting<T> setting);
+
+ /**
+ * Applies a setting to this {@link EntryIngredient}.
+ * <p>
+ * It is generally not recommended to use this method, but to instead use the helper
+ * methods such as {@link EntryIngredient#unifyFocuses(EntryIngredient...)}.
+ *
+ * @param setting the setting to apply
+ * @param value the value of the setting to apply
+ * @param <T> the type of the setting
+ * @return this {@link EntryStack}
+ */
+ @ApiStatus.Experimental
+ <T> EntryIngredient setting(EntryIngredientSetting<T> setting, T value);
+
+ /**
+ * Unifies focuses for the given {@link EntryIngredient}s, so the selection for these
+ * {@link EntryIngredient}s will be the same.
+ * <p>
+ * For example, a recipe that accepts some type of banner pattern and will output a certain
+ * type of cloned banner pattern should have both these ingredients unified, such that
+ * the natural cycling of the ingredient should still make sure these two ingredients
+ * are matching.
+ * <p>
+ * For that reason, all ingredients passed to this method must have the same size.
+ *
+ * @param ingredients the ingredients to unify
+ */
+ @ApiStatus.Experimental
+ static void unifyFocuses(EntryIngredient... ingredients) {
+ UUID uuid = UUID.randomUUID();
+ for (EntryIngredient ingredient : ingredients) {
+ ingredient.setting(EntryIngredientSetting.FOCUS_UUID, uuid);
+ }
+ }
+
@ApiStatus.NonExtendable
interface Builder {
Builder add(EntryStack<?> stack);
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntryIngredientSetting.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntryIngredientSetting.java
new file mode 100644
index 000000000..88766ff5d
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntryIngredientSetting.java
@@ -0,0 +1,33 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.common.entry.settings;
+
+import org.jetbrains.annotations.ApiStatus;
+
+import java.util.UUID;
+
+@ApiStatus.Experimental
+public interface EntryIngredientSetting<T> {
+ EntryIngredientSetting<UUID> FOCUS_UUID = new EntryIngredientSetting<>() {};
+}
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 bd8376e53..3ac72cdf1 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
@@ -514,6 +514,10 @@ public class CollectionUtils {
@SafeVarargs
public static <T> List<T> concatUnmodifiable(List<? extends T>... lists) {
+ return new ListConcatenationView<>(Arrays.asList(lists));
+ }
+
+ public static <T> List<T> concatUnmodifiable(Iterable<List<? extends T>> lists) {
return new ListConcatenationView<>(lists);
}
@@ -521,10 +525,9 @@ public class CollectionUtils {
* A list which acts as view of the concatenation of a number of lists.
*/
private static class ListConcatenationView<E> extends AbstractList<E> {
- private final List<? extends E>[] lists;
+ private final Iterable<List<? extends E>> lists;
- @SafeVarargs
- public ListConcatenationView(List<? extends E>... lists) {
+ public ListConcatenationView(Iterable<List<? extends E>> lists) {
this.lists = lists;
}