aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-api/src/main
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-10-26 10:49:27 +0800
committershedaniel <daniel@shedaniel.me>2020-10-29 14:02:27 +0800
commit9ea4a22e9a194fd8fdc2fb03226ab38ee175a6cc (patch)
treeb4db2569bc4a90d7bb835ff451fe5e11e86e8968 /RoughlyEnoughItems-api/src/main
parentb7f8fc61dcaa6d202809651d46cf0946b63beef7 (diff)
downloadRoughlyEnoughItems-9ea4a22e9a194fd8fdc2fb03226ab38ee175a6cc.tar.gz
RoughlyEnoughItems-9ea4a22e9a194fd8fdc2fb03226ab38ee175a6cc.tar.bz2
RoughlyEnoughItems-9ea4a22e9a194fd8fdc2fb03226ab38ee175a6cc.zip
Favorites Dragging
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-api/src/main')
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java19
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java21
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntry.java109
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java79
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteMenuEntry.java46
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/package-info.java27
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java18
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java14
8 files changed, 319 insertions, 14 deletions
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
index 948c969dc..62482d09b 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
@@ -24,11 +24,13 @@
package me.shedaniel.rei.api;
import me.shedaniel.clothconfig2.api.ModifierKeyCode;
+import me.shedaniel.rei.api.favorites.FavoriteEntry;
import me.shedaniel.rei.gui.config.*;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.ApiStatus;
+import java.util.Collections;
import java.util.List;
@Environment(EnvType.CLIENT)
@@ -57,6 +59,8 @@ public interface ConfigObject {
boolean isGrabbingItems();
+ boolean isReducedMotion();
+
boolean isToastDisplayedOnCopyIdentifier();
@Deprecated
@@ -123,7 +127,11 @@ public interface ConfigObject {
boolean doDebugRenderTimeRequired();
- boolean doSearchFavorites();
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
+ default boolean doSearchFavorites() {
+ return false;
+ }
ModifierKeyCode getFavoriteKeyCode();
@@ -149,7 +157,14 @@ public interface ConfigObject {
boolean isLowerConfigButton();
- List<EntryStack> getFavorites();
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
+ default List<EntryStack> getFavorites() {
+ return Collections.emptyList();
+ }
+
+ @ApiStatus.Experimental
+ List<FavoriteEntry> getFavoriteEntries();
List<EntryStack> getFilteredStacks();
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
index bb1ec1fda..70c8a06bc 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
@@ -27,8 +27,8 @@ import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
-import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
-import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
+import com.mojang.serialization.Dynamic;
+import com.mojang.serialization.JsonOps;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.fluid.FluidSupportProvider;
@@ -40,9 +40,11 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.TagParser;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
@@ -166,9 +168,11 @@ public interface EntryStack extends TextRepresentable {
static EntryStack readFromJson(JsonElement jsonElement) {
try {
JsonObject obj = jsonElement.getAsJsonObject();
- switch (obj.getAsJsonPrimitive("type").getAsString()) {
+ switch (GsonHelper.getAsString(obj, "type")) {
case "stack":
return EntryStack.create(ItemStack.of(TagParser.parseTag(obj.get("nbt").getAsString())));
+ case "item":
+ return EntryStack.create(ItemStack.of((CompoundTag) Dynamic.convert(JsonOps.INSTANCE, NbtOps.INSTANCE, obj)));
case "fluid":
return EntryStack.create(Registry.FLUID.get(ResourceLocation.tryParse(obj.get("id").getAsString())));
case "empty":
@@ -188,9 +192,8 @@ public interface EntryStack extends TextRepresentable {
try {
switch (getType()) {
case ITEM:
- JsonObject obj1 = new JsonObject();
- obj1.addProperty("type", "stack");
- obj1.addProperty("nbt", getItemStack().save(new CompoundTag()).toString());
+ JsonObject obj1 = Dynamic.convert(NbtOps.INSTANCE, JsonOps.INSTANCE, getItemStack().save(new CompoundTag())).getAsJsonObject();
+ obj1.addProperty("type", "item");
return obj1;
case FLUID:
Optional<ResourceLocation> optionalIdentifier = getIdentifier();
@@ -368,7 +371,7 @@ public interface EntryStack extends TextRepresentable {
class Settings<T> {
@ApiStatus.Internal
- private static final Short2ObjectMap<Settings<?>> ID_TO_SETTINGS = new Short2ObjectOpenHashMap<>();
+ private static final List<Settings<?>> SETTINGS = new ArrayList<>();
public static final Supplier<Boolean> TRUE = () -> true;
public static final Supplier<Boolean> FALSE = () -> false;
@@ -389,12 +392,12 @@ public interface EntryStack extends TextRepresentable {
public Settings(T defaultValue) {
this.defaultValue = defaultValue;
this.id = nextId++;
- ID_TO_SETTINGS.put(this.id, this);
+ SETTINGS.add(this);
}
@ApiStatus.Internal
public static <T> Settings<T> getById(short id) {
- return (Settings<T>) ID_TO_SETTINGS.get(id);
+ return (Settings<T>) SETTINGS.get(id);
}
public T getDefaultValue() {
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntry.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntry.java
new file mode 100644
index 000000000..211dbc915
--- /dev/null
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntry.java
@@ -0,0 +1,109 @@
+/*
+ * 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.favorites;
+
+import com.google.gson.JsonObject;
+import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.impl.Internals;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Supplier;
+
+public abstract class FavoriteEntry {
+ public static final String TYPE_KEY = "type";
+ private final UUID uuid = UUID.randomUUID();
+
+ @NotNull
+ public static FavoriteEntry delegate(@NotNull Supplier<FavoriteEntry> supplier, @Nullable Supplier<JsonObject> toJson) {
+ return Internals.delegateFavoriteEntry(supplier, toJson);
+ }
+
+ @Nullable
+ public static FavoriteEntry fromJson(@NotNull JsonObject object) {
+ return Internals.favoriteEntryFromJson(object);
+ }
+
+ @NotNull
+ public static FavoriteEntry fromEntryStack(@NotNull EntryStack stack) {
+ return delegate(() -> FavoriteEntryType.registry().get(FavoriteEntryType.ENTRY_STACK).fromArgs(stack), null);
+ }
+
+ public static boolean isEntryInvalid(@Nullable FavoriteEntry entry) {
+ return entry == null || entry.isInvalid();
+ }
+
+ @NotNull
+ public JsonObject toJson(@NotNull JsonObject object) {
+ object.addProperty(TYPE_KEY, getType().toString());
+ return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(getType())).toJson(this, object));
+ }
+
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public abstract boolean isInvalid();
+
+ public abstract EntryStack getWidget(boolean showcase);
+
+ public abstract boolean doAction(int button);
+
+ @NotNull
+ public Optional<Supplier<Collection<@NotNull FavoriteMenuEntry>>> getMenuEntries() {
+ return Optional.empty();
+ }
+
+ public abstract int hashIgnoreAmount();
+
+ public abstract FavoriteEntry copy();
+
+ public abstract ResourceLocation getType();
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof FavoriteEntry)) return false;
+ FavoriteEntry that = (FavoriteEntry) o;
+ FavoriteEntry unwrapped = getUnwrapped();
+ FavoriteEntry thatUnwrapped = that.getUnwrapped();
+ return unwrapped == thatUnwrapped || unwrapped.isSame(thatUnwrapped);
+ }
+
+ @Override
+ public int hashCode() {
+ return hashIgnoreAmount();
+ }
+
+ public abstract boolean isSame(FavoriteEntry other);
+
+ public FavoriteEntry getUnwrapped() {
+ return this;
+ }
+}
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java
new file mode 100644
index 000000000..2df0332fc
--- /dev/null
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteEntryType.java
@@ -0,0 +1,79 @@
+/*
+ * 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.favorites;
+
+import com.google.gson.JsonObject;
+import me.shedaniel.rei.impl.Internals;
+import net.minecraft.network.chat.Component;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public interface FavoriteEntryType<T extends FavoriteEntry> {
+ ResourceLocation ENTRY_STACK = new ResourceLocation("roughlyenoughitems", "entry_stack");
+
+ @NotNull
+ static Registry registry() {
+ return Internals.getFavoriteEntryTypeRegistry();
+ }
+
+ @NotNull
+ T fromJson(@NotNull JsonObject object);
+
+ @NotNull
+ T fromArgs(Object... args);
+
+ @NotNull
+ JsonObject toJson(@NotNull T entry, @NotNull JsonObject object);
+
+ @ApiStatus.NonExtendable
+ interface Registry {
+ void register(ResourceLocation id, FavoriteEntryType<?> type);
+
+ @Nullable <A extends FavoriteEntry> FavoriteEntryType<A> get(ResourceLocation id);
+
+ @Nullable
+ ResourceLocation getId(FavoriteEntryType<?> type);
+
+ @NotNull
+ Section getOrCrateSection(Component text);
+
+ @NotNull
+ Iterable<Section> sections();
+ }
+
+ @ApiStatus.NonExtendable
+ interface Section {
+ void add(@NotNull FavoriteEntry... entries);
+
+ @NotNull
+ Component getText();
+
+ @NotNull
+ List<FavoriteEntry> getEntries();
+ }
+}
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteMenuEntry.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteMenuEntry.java
new file mode 100644
index 000000000..575682f58
--- /dev/null
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/FavoriteMenuEntry.java
@@ -0,0 +1,46 @@
+/*
+ * 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.favorites;
+
+import me.shedaniel.rei.gui.widget.Widget;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
+
+public abstract class FavoriteMenuEntry extends Widget {
+ @Nullable
+ @ApiStatus.Internal
+ public Runnable closeMenu = null;
+
+ public abstract int getEntryWidth();
+
+ public abstract int getEntryHeight();
+
+ public abstract void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width);
+
+ public void closeMenu() {
+ if (closeMenu != null) {
+ closeMenu.run();
+ }
+ }
+}
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/package-info.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/package-info.java
new file mode 100644
index 000000000..a2ba8f361
--- /dev/null
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/favorites/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+@ApiStatus.Experimental
+package me.shedaniel.rei.api.favorites;
+
+import org.jetbrains.annotations.ApiStatus; \ No newline at end of file
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java
index d8fc9fc6d..29d9ddecc 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/impl/Internals.java
@@ -23,9 +23,12 @@
package me.shedaniel.rei.impl;
+import com.google.gson.JsonObject;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.*;
+import me.shedaniel.rei.api.favorites.FavoriteEntry;
+import me.shedaniel.rei.api.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.fluid.FluidSupportProvider;
import me.shedaniel.rei.api.fractions.Fraction;
import me.shedaniel.rei.api.subsets.SubsetsRegistry;
@@ -61,6 +64,9 @@ public final class Internals {
private static Supplier<DisplayHelper> displayHelper = Internals::throwNotSetup;
private static Supplier<WidgetsProvider> widgetsProvider = Internals::throwNotSetup;
private static Supplier<ClientHelper.ViewSearchBuilder> viewSearchBuilder = Internals::throwNotSetup;
+ private static Supplier<FavoriteEntryType.Registry> favoriteEntryTypeRegistry = Internals::throwNotSetup;
+ private static BiFunction<Supplier<FavoriteEntry>, Supplier<JsonObject>, FavoriteEntry> delegateFavoriteEntry = (supplier, toJson) -> throwNotSetup();
+ private static Function<JsonObject, FavoriteEntry> favoriteEntryFromJson = (object) -> throwNotSetup();
private static Function<@NotNull Boolean, ClickAreaHandler.Result> clickAreaHandlerResult = (result) -> throwNotSetup();
private static BiFunction<@Nullable Point, Collection<Component>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup();
private static Supplier<BuiltinPlugin> builtinPlugin = Internals::throwNotSetup;
@@ -125,6 +131,10 @@ public final class Internals {
return viewSearchBuilder.get();
}
+ public static FavoriteEntryType.Registry getFavoriteEntryTypeRegistry() {
+ return favoriteEntryTypeRegistry.get();
+ }
+
@NotNull
public static ClickAreaHandler.Result createClickAreaHandlerResult(boolean applicable) {
return clickAreaHandlerResult.apply(applicable);
@@ -161,6 +171,14 @@ public final class Internals {
}
}
+ public static FavoriteEntry delegateFavoriteEntry(Supplier<FavoriteEntry> supplier, Supplier<JsonObject> toJoin) {
+ return delegateFavoriteEntry.apply(supplier, toJoin);
+ }
+
+ public static FavoriteEntry favoriteEntryFromJson(JsonObject object) {
+ return favoriteEntryFromJson.apply(object);
+ }
+
public interface EntryStackProvider {
EntryStack empty();
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java
index 1060a6bdc..fd4cac467 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java
@@ -26,15 +26,15 @@ package me.shedaniel.rei.utils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.UnmodifiableIterator;
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import it.unimi.dsi.fastutil.ints.IntList;
import me.shedaniel.rei.api.EntryStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.Mth;
import java.util.*;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
+import java.util.function.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -162,6 +162,14 @@ public class CollectionUtils {
return l;
}
+ public static <T> IntList mapToInt(Collection<T> list, ToIntFunction<T> function) {
+ IntList l = new IntArrayList(list.size() + 1);
+ for (T t : list) {
+ l.add(function.applyAsInt(t));
+ }
+ return l;
+ }
+
public static <T, R> List<R> mapParallel(Collection<T> list, Function<T, R> function) {
return list.parallelStream().map(function).collect(Collectors.toList());
}