aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/main/java')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/display/Display.java8
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/InputIngredient.java72
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java46
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java14
4 files changed, 137 insertions, 3 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java
index 82505f971..bf6dc0cef 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java
@@ -25,8 +25,11 @@ package me.shedaniel.rei.api.common.display;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.InputIngredient;
import me.shedaniel.rei.api.common.transfer.info.MenuInfo;
import me.shedaniel.rei.api.common.transfer.info.MenuSerializationContext;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.impl.display.DisplaySpec;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
@@ -49,10 +52,15 @@ public interface Display extends DisplaySpec {
*/
List<EntryIngredient> getInputEntries();
+ @Deprecated
default List<EntryIngredient> getInputEntries(MenuSerializationContext<?, ?, ?> context, MenuInfo<?, ?> info, boolean fill) {
return getInputEntries();
}
+ default List<InputIngredient<EntryStack<?>>> getInputIngredients(MenuSerializationContext<?, ?, ?> context, MenuInfo<?, ?> info, boolean fill) {
+ return CollectionUtils.mapIndexed(getInputEntries(context, info, fill), InputIngredient::of);
+ }
+
/**
* @return a list of outputs
*/
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/InputIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/InputIngredient.java
new file mode 100644
index 000000000..99dd3dcaa
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/InputIngredient.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import me.shedaniel.rei.api.common.entry.type.EntryType;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
+
+import java.util.Collections;
+import java.util.List;
+
+public interface InputIngredient<T> {
+ static <T> InputIngredient<T> empty(int index) {
+ return of(index, Collections.emptyList());
+ }
+
+ static <T> InputIngredient<T> of(int index, List<T> ingredient) {
+ return new InputIngredient<T>() {
+ @Override
+ public List<T> get() {
+ return ingredient;
+ }
+
+ @Override
+ public int getIndex() {
+ return index;
+ }
+ };
+ }
+
+ static <T> InputIngredient<T> withType(InputIngredient<EntryStack<?>> ingredient, EntryType<T> type) {
+ return new InputIngredient<T>() {
+ @SuppressWarnings("RedundantTypeArguments")
+ List<T> list = CollectionUtils.<EntryStack<?>, T>filterAndMap(ingredient.get(),
+ stack -> stack.getType() == type, EntryStack::castValue);
+
+ @Override
+ public List<T> get() {
+ return list;
+ }
+
+ @Override
+ public int getIndex() {
+ return ingredient.getIndex();
+ }
+ };
+ }
+
+ List<T> get();
+
+ int getIndex();
+}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java
index ad9a0e3cc..ca3b8ba74 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java
@@ -25,6 +25,7 @@ package me.shedaniel.rei.api.common.transfer.info;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.ints.IntList;
+import it.unimi.dsi.fastutil.ints.IntSet;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
@@ -32,6 +33,7 @@ import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.InputIngredient;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.api.common.transfer.RecipeFinder;
import me.shedaniel.rei.api.common.transfer.RecipeFinderPopulator;
@@ -133,10 +135,12 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
* otherwise it should be aligned for the display category
* @return the list of lists of items
*/
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
default List<List<ItemStack>> getInputs(MenuInfoContext<T, ?, D> context, boolean fill) {
if (context.getDisplay() == null) return Collections.emptyList();
- return CollectionUtils.map(context.getDisplay().getInputEntries(context, this, fill), inputEntry ->
- CollectionUtils.<EntryStack<?>, ItemStack>filterAndMap(inputEntry,
+ return CollectionUtils.map(context.getDisplay().getInputIngredients(context, this, fill), inputEntry ->
+ CollectionUtils.<EntryStack<?>, ItemStack>filterAndMap(inputEntry.get(),
stack -> stack.getType() == VanillaEntryTypes.ITEM, EntryStack::castValue));
}
@@ -153,6 +157,20 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
}
/**
+ * Returns the inputs of the {@link Display}. The nested lists are possible stacks for that specific slot.
+ *
+ * @param context the context of the transfer
+ * @param fill whether this call is for a fill or not, if it is for a fill, the returned list should be aligned for the menu,
+ * otherwise it should be aligned for the display category
+ * @return the list of lists of items
+ */
+ default List<InputIngredient<ItemStack>> getInputsIndexed(MenuInfoContext<T, ?, D> context, boolean fill) {
+ if (context.getDisplay() == null) return Collections.emptyList();
+ return CollectionUtils.map(context.getDisplay().getInputIngredients(context, this, fill), entry ->
+ InputIngredient.withType(entry, VanillaEntryTypes.ITEM));
+ }
+
+ /**
* Serializes the {@link Display} as {@link CompoundTag}, sent to the server for further info for the transfer.
*
* @param context the context of the transfer
@@ -181,6 +199,7 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
*
* @param context the context of the transfer
* @param inputs the list of inputs
+ * @param missing the list of missing stacks
* @param missingIndices the indices of the missing stacks
* @param matrices the rendering transforming matrices
* @param mouseX the mouse x position
@@ -190,7 +209,7 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
* @param bounds the bounds of the display
*/
@Environment(EnvType.CLIENT)
- default void renderMissingInput(MenuInfoContext<T, ?, D> context, List<List<ItemStack>> inputs, IntList missingIndices, PoseStack matrices, int mouseX, int mouseY,
+ default void renderMissingInput(MenuInfoContext<T, ?, D> context, List<InputIngredient<ItemStack>> inputs, List<InputIngredient<ItemStack>> missing, IntSet missingIndices, PoseStack matrices, int mouseX, int mouseY,
float delta, List<Widget> widgets, Rectangle bounds) {
int i = 0;
for (Widget widget : widgets) {
@@ -205,4 +224,25 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
}
}
}
+
+ /**
+ * Renders the missing ingredients of the transfer.
+ * The indices of the missing stacks are provided, this aligns with the list returned by {@link #getInputs(MenuInfoContext, boolean)}.
+ *
+ * @param context the context of the transfer
+ * @param inputs the list of inputs
+ * @param missingIndices the indices of the missing stacks
+ * @param matrices the rendering transforming matrices
+ * @param mouseX the mouse x position
+ * @param mouseY the mouse y position
+ * @param delta the delta frame time
+ * @param widgets the widgets set-up by the category
+ * @param bounds the bounds of the display
+ */
+ @Environment(EnvType.CLIENT)
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
+ default void renderMissingInput(MenuInfoContext<T, ?, D> context, List<List<ItemStack>> inputs, IntList missingIndices, PoseStack matrices, int mouseX, int mouseY,
+ float delta, List<Widget> widgets, Rectangle bounds) {
+ }
}
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 6efbc1901..7d00c76ec 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
@@ -130,6 +130,20 @@ public class CollectionUtils {
return l;
}
+ public static <T, R> List<R> mapIndexed(Iterable<T> list, IndexedFunction<T, R> function) {
+ List<R> l = list instanceof Collection ? new ArrayList<>(((Collection<T>) list).size() + 1) : new ArrayList<>();
+ int i = 0;
+ for (T t : list) {
+ l.add(function.apply(i++, t));
+ }
+ return l;
+ }
+
+ @FunctionalInterface
+ public interface IndexedFunction<T, R> {
+ R apply(int index, T object);
+ }
+
public static <T, R> List<R> flatMap(Iterable<T> list, Function<T, Collection<R>> function) {
List<R> l = new ArrayList<>();
for (T t : list) {