aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-06-14 20:45:12 +0800
committershedaniel <daniel@shedaniel.me>2021-06-14 20:45:12 +0800
commit3d90cdd1204b6b6a2c57b121cdf82de2448bb951 (patch)
treeef52f2aa6869538c7044c3ebf42a0376b0f32846
parent2932350cc1315534c4ee9a8c9fe17a9b0815f2e9 (diff)
downloadRoughlyEnoughItems-3d90cdd1204b6b6a2c57b121cdf82de2448bb951.tar.gz
RoughlyEnoughItems-3d90cdd1204b6b6a2c57b121cdf82de2448bb951.tar.bz2
RoughlyEnoughItems-3d90cdd1204b6b6a2c57b121cdf82de2448bb951.zip
Fix auto crafting patterns & refactor internals providers
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/display/SimpleDisplaySerializer.java15
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java37
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java1
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java2
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java16
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java25
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java6
-rw-r--r--fabric/build.gradle2
-rw-r--r--gradle.properties2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java101
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java71
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/DelegatingFavoriteEntryProviderImpl.java115
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/DeferringEntryTypeProviderImpl.java107
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java90
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryStackProviderImpl.java50
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/comparison/NbtHasherProviderImpl.java3
16 files changed, 399 insertions, 244 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/SimpleDisplaySerializer.java b/api/src/main/java/me/shedaniel/rei/api/common/display/SimpleDisplaySerializer.java
index ad2ca952d..4863f90fd 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/display/SimpleDisplaySerializer.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/display/SimpleDisplaySerializer.java
@@ -23,17 +23,28 @@
package me.shedaniel.rei.api.common.display;
+import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import net.minecraft.nbt.CompoundTag;
+import java.util.List;
+
public interface SimpleDisplaySerializer<D extends Display> extends DisplaySerializer<D> {
@Override
default CompoundTag save(CompoundTag tag, D display) {
- tag.put("input", EntryIngredients.save(display.getInputEntries()));
- tag.put("output", EntryIngredients.save(display.getOutputEntries()));
+ tag.put("input", EntryIngredients.save(getInputIngredients(display)));
+ tag.put("output", EntryIngredients.save(getOutputIngredients(display)));
tag = saveExtra(tag, display);
return tag;
}
+ default List<EntryIngredient> getInputIngredients(D display) {
+ return display.getInputEntries();
+ }
+
+ default List<EntryIngredient> getOutputIngredients(D display) {
+ return display.getOutputEntries();
+ }
+
CompoundTag saveExtra(CompoundTag tag, D display);
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java b/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java
index 1d0ac2dfe..da78fc0b1 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java
@@ -30,6 +30,7 @@ import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
@@ -67,6 +68,8 @@ public abstract class BasicDisplay implements Display {
public static class Serializer<P extends BasicDisplay> implements SimpleDisplaySerializer<P> {
protected final Constructor<P> constructor;
protected final ExtraSerializer<P> extraSerializer;
+ protected EntryIngredientsProvider<P> inputEntries = EntryIngredientsProvider.pass();
+ protected EntryIngredientsProvider<P> outputEntries = EntryIngredientsProvider.pass();
public static <P extends BasicDisplay> Serializer<P> ofSimple(SimpleConstructor<P> constructor) {
return new Serializer<>(constructor, (p, tag) -> {});
@@ -109,6 +112,16 @@ public abstract class BasicDisplay implements Display {
this.extraSerializer = extraSerializer;
}
+ public Serializer<P> inputProvider(EntryIngredientsProvider<P> provider) {
+ this.inputEntries = provider;
+ return this;
+ }
+
+ public Serializer<P> outputProvider(EntryIngredientsProvider<P> provider) {
+ this.outputEntries = provider;
+ return this;
+ }
+
@Override
public CompoundTag saveExtra(CompoundTag tag, P display) {
display.getDisplayLocation().ifPresent(location -> tag.putString("location", location.toString()));
@@ -129,6 +142,20 @@ public abstract class BasicDisplay implements Display {
return constructor.construct(input, output, Optional.ofNullable(location), tag);
}
+ @Override
+ public List<EntryIngredient> getInputIngredients(P display) {
+ List<EntryIngredient> entries = this.inputEntries.getEntries(display);
+ if (entries != null) return entries;
+ return SimpleDisplaySerializer.super.getInputIngredients(display);
+ }
+
+ @Override
+ public List<EntryIngredient> getOutputIngredients(P display) {
+ List<EntryIngredient> entries = this.outputEntries.getEntries(display);
+ if (entries != null) return entries;
+ return SimpleDisplaySerializer.super.getOutputIngredients(display);
+ }
+
@FunctionalInterface
public interface Constructor<R> {
R construct(List<EntryIngredient> input, List<EntryIngredient> output, Optional<ResourceLocation> location, CompoundTag tag);
@@ -168,5 +195,15 @@ public abstract class BasicDisplay implements Display {
public interface ExtraSerializer<R extends Display> {
void serialize(R display, CompoundTag tag);
}
+
+ @FunctionalInterface
+ public interface EntryIngredientsProvider<R extends Display> {
+ @Nullable
+ List<EntryIngredient> getEntries(R display);
+
+ static <R extends Display> EntryIngredientsProvider<R> pass() {
+ return display -> null;
+ }
+ }
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
index c9810211d..1789ccbae 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
@@ -66,6 +66,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
static EntryStack<?> read(CompoundTag tag) {
EntryDefinition<?> definition = EntryTypeRegistry.getInstance().get(new ResourceLocation(tag.getString("type")));
+ if (definition == null) throw new NullPointerException("Read missing entry type: " + definition);
EntrySerializer<?> serializer = definition.getSerializer();
if (serializer != null && serializer.supportReading()) {
return EntryStack.of((EntryDefinition<Object>) definition, serializer.read(tag));
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 e9f87d51f..313ab23de 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
@@ -99,7 +99,7 @@ public interface MenuInfo<T extends AbstractContainerMenu, D extends Display> ex
*/
default void markDirty(MenuInfoContext<T, ? extends ServerPlayer, D> context) {
context.getPlayerEntity().getInventory().setChanged();
- context.getMenu().broadcastChanges();
+ context.getMenu().sendAllDataToRemote();
}
/**
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
index 6eadc9d81..902e51f76 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
@@ -34,7 +34,6 @@ import me.shedaniel.rei.api.common.entry.comparison.EntryComparator;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
-import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext;
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
import me.shedaniel.rei.api.common.transfer.info.simple.RecipeBookGridMenuInfo;
import me.shedaniel.rei.api.common.util.EntryStacks;
@@ -59,7 +58,6 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.ApiStatus;
-import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
@@ -127,18 +125,8 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin {
@Override
public void registerMenuInfo(MenuInfoRegistry registry) {
- registry.register(BuiltinPlugin.CRAFTING, CraftingMenu.class, new RecipeBookGridMenuInfo<>() {
- @Override
- public List<List<ItemStack>> getInputs(MenuInfoContext<CraftingMenu, ?, DefaultCraftingDisplay<?>> context) {
- return context.getDisplay().getOrganisedInputEntries(this, context.getMenu());
- }
- });
- registry.register(BuiltinPlugin.CRAFTING, InventoryMenu.class, new RecipeBookGridMenuInfo<>() {
- @Override
- public List<List<ItemStack>> getInputs(MenuInfoContext<InventoryMenu, ?, DefaultCraftingDisplay<?>> context) {
- return context.getDisplay().getOrganisedInputEntries(this, context.getMenu());
- }
- });
+ registry.register(BuiltinPlugin.CRAFTING, CraftingMenu.class, new RecipeBookGridMenuInfo<>());
+ registry.register(BuiltinPlugin.CRAFTING, InventoryMenu.class, new RecipeBookGridMenuInfo<>());
registry.register(BuiltinPlugin.SMELTING, FurnaceMenu.class, new RecipeBookGridMenuInfo<>());
registry.register(BuiltinPlugin.SMOKING, SmokerMenu.class, new RecipeBookGridMenuInfo<>());
registry.register(BuiltinPlugin.BLASTING, BlastFurnaceMenu.class, new RecipeBookGridMenuInfo<>());
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
index 18baa55ab..2fc43dbaf 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java
@@ -38,7 +38,6 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -65,21 +64,24 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD
}
public <T extends AbstractContainerMenu> List<List<ItemStack>> getOrganisedInputEntries(SimpleGridMenuInfo<T, DefaultCraftingDisplay<?>> menuInfo, T container) {
- List<List<ItemStack>> list = new ArrayList<>(menuInfo.getCraftingWidth(container) * menuInfo.getCraftingHeight(container));
- for (int i = 0; i < menuInfo.getCraftingWidth(container) * menuInfo.getCraftingHeight(container); i++) {
- list.add(Collections.emptyList());
+ return CollectionUtils.map(getOrganisedInputEntries(menuInfo.getCraftingWidth(container), menuInfo.getCraftingHeight(container)), ingredient ->
+ CollectionUtils.<EntryStack<?>, ItemStack>filterAndMap(ingredient, stack -> stack.getType() == VanillaEntryTypes.ITEM,
+ EntryStack::castValue));
+ }
+
+ public <T extends AbstractContainerMenu> List<EntryIngredient> getOrganisedInputEntries(int menuWidth, int menuHeight) {
+ List<EntryIngredient> list = new ArrayList<>(menuWidth * menuHeight);
+ for (int i = 0; i < menuWidth * menuHeight; i++) {
+ list.add(EntryIngredient.empty());
}
for (int i = 0; i < getInputEntries().size(); i++) {
- @SuppressWarnings("RedundantTypeArguments")
- List<ItemStack> stacks = CollectionUtils.<EntryStack<?>, ItemStack>filterAndMap(getInputEntries().get(i), stack -> stack.getType() == VanillaEntryTypes.ITEM,
- EntryStack::castValue);
- list.set(getSlotWithSize(this, i, menuInfo.getCraftingWidth(container)), stacks);
+ list.set(getSlotWithSize(this, i, menuWidth), getInputEntries().get(i));
}
return list;
}
- public static int getSlotWithSize(DefaultCraftingDisplay<?> recipeDisplay, int index, int craftingGridWidth) {
- return getSlotWithSize(recipeDisplay.getWidth(), index, craftingGridWidth);
+ public static int getSlotWithSize(DefaultCraftingDisplay<?> display, int index, int craftingGridWidth) {
+ return getSlotWithSize(display.getWidth(), index, craftingGridWidth);
}
public static int getSlotWithSize(int recipeWidth, int index, int craftingGridWidth) {
@@ -89,6 +91,7 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD
}
public static BasicDisplay.Serializer<DefaultCraftingDisplay<?>> serializer() {
- return BasicDisplay.Serializer.ofSimple(DefaultCustomDisplay::simple);
+ return BasicDisplay.Serializer.<DefaultCraftingDisplay<?>>ofSimple(DefaultCustomDisplay::simple)
+ .inputProvider(display -> display.getOrganisedInputEntries(3, 3));
}
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java
index 5b1a28d53..45cd6eed4 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomDisplay.java
@@ -44,14 +44,14 @@ public class DefaultCustomDisplay extends DefaultCraftingDisplay<Recipe<?>> {
BitSet column = new BitSet(3);
for (int i = 0; i < 9; i++)
if (i < input.size()) {
- List<? extends EntryStack<?>> stacks = input.get(i);
+ EntryIngredient stacks = input.get(i);
if (stacks.stream().anyMatch(stack -> !stack.isEmpty())) {
row.set((i - (i % 3)) / 3);
column.set(i % 3);
}
}
- this.width = row.cardinality();
- this.height = column.cardinality();
+ this.width = column.cardinality();
+ this.height = row.cardinality();
}
public static DefaultCustomDisplay simple(List<EntryIngredient> input, List<EntryIngredient> output, Optional<ResourceLocation> location) {
diff --git a/fabric/build.gradle b/fabric/build.gradle
index 2a38e7b44..c182229c0 100644
--- a/fabric/build.gradle
+++ b/fabric/build.gradle
@@ -105,7 +105,7 @@ curseforge {
apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key')
project {
id = "310111"
- releaseType = "beta"
+ releaseType = "release"
changelogType = "html"
changelog = rootProject.releaseChangelog
addGameVersion "1.17"
diff --git a/gradle.properties b/gradle.properties
index f53110ed1..877337dee 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx3G
base_version=6.0
unstable=true
-supported_version=1.17-pre2
+supported_version=1.17
minecraft_version=1.17-pre2
forgeEnabled=false
forge_version=36.0.43
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 144479217..fe495d876 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -27,12 +27,8 @@ import dev.architectury.platform.Platform;
import dev.architectury.registry.ReloadListenerRegistry;
import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
-import me.shedaniel.rei.api.client.gui.Renderer;
-import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
-import me.shedaniel.rei.api.common.entry.type.BuiltinEntryTypes;
-import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
import me.shedaniel.rei.api.common.entry.type.EntryType;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
@@ -42,24 +38,19 @@ import me.shedaniel.rei.api.common.plugins.REIPlugin;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
import me.shedaniel.rei.impl.Internals;
-import me.shedaniel.rei.impl.client.entry.type.types.RenderingEntryDefinition;
import me.shedaniel.rei.impl.common.category.CategoryIdentifierImpl;
import me.shedaniel.rei.impl.common.display.DisplaySerializerRegistryImpl;
-import me.shedaniel.rei.impl.common.entry.EmptyEntryStack;
+import me.shedaniel.rei.impl.common.entry.DeferringEntryTypeProviderImpl;
import me.shedaniel.rei.impl.common.entry.EntryIngredientImpl;
-import me.shedaniel.rei.impl.common.entry.TypedEntryStack;
+import me.shedaniel.rei.impl.common.entry.EntryStackProviderImpl;
import me.shedaniel.rei.impl.common.entry.comparison.FluidComparatorRegistryImpl;
import me.shedaniel.rei.impl.common.entry.comparison.ItemComparatorRegistryImpl;
import me.shedaniel.rei.impl.common.entry.comparison.NbtHasherProviderImpl;
-import me.shedaniel.rei.impl.common.entry.type.EntryTypeDeferred;
import me.shedaniel.rei.impl.common.entry.type.EntryTypeRegistryImpl;
-import me.shedaniel.rei.impl.common.entry.type.types.EmptyEntryDefinition;
import me.shedaniel.rei.impl.common.fluid.FluidSupportProviderImpl;
import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl;
import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl;
import me.shedaniel.rei.impl.common.transfer.MenuInfoRegistryImpl;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.Unit;
@@ -68,9 +59,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.UnaryOperator;
@@ -88,87 +76,10 @@ public class RoughlyEnoughItemsCore {
public static void attachCommonInternals() {
CategoryIdentifierImpl.attach();
- Internals.attachInstance((Function<ResourceLocation, EntryType<?>>) new Function<ResourceLocation, EntryType<?>>() {
- ResourceLocation RENDERING_ID = new ResourceLocation("rendering");
- private Map<ResourceLocation, EntryType<?>> typeCache = new ConcurrentHashMap<>();
- private EntryType<Unit> empty;
- @Environment(EnvType.CLIENT)
- private EntryType<Renderer> render;
-
- @Override
- public EntryType<?> apply(ResourceLocation id) {
- if (id.equals(BuiltinEntryTypes.EMPTY_ID)) {
- return typeCache.computeIfAbsent(id, this::emptyType);
- } else if (id.equals(RENDERING_ID) && Platform.getEnv() == EnvType.CLIENT) {
- return typeCache.computeIfAbsent(id, this::renderingType);
- }
- return typeCache.computeIfAbsent(id, EntryTypeDeferred::new);
- }
-
- public EntryType<Unit> emptyType(ResourceLocation id) {
- if (empty == null) {
- int hashCode = id.hashCode();
- empty = new EntryType<>() {
- @Override
- public ResourceLocation getId() {
- return id;
- }
-
- @Override
- public EntryDefinition<Unit> getDefinition() {
- return EmptyEntryDefinition.EMPTY;
- }
-
- @Override
- public int hashCode() {
- return hashCode;
- }
- };
- }
- return empty;
- }
-
- @Environment(EnvType.CLIENT)
- public EntryType<Renderer> renderingType(ResourceLocation id) {
- if (render == null) {
- int hashCode = id.hashCode();
- render = new EntryType<>() {
- @Override
- public ResourceLocation getId() {
- return id;
- }
-
- @Override
- public EntryDefinition<Renderer> getDefinition() {
- return RenderingEntryDefinition.RENDERING;
- }
-
- @Override
- public int hashCode() {
- return hashCode;
- }
- };
- }
- return render;
- }
- }, "entryTypeDeferred");
- Internals.attachInstance(new Internals.EntryStackProvider() {
- @Override
- public EntryStack<Unit> empty() {
- return EmptyEntryStack.EMPTY;
- }
-
- @Override
- public <T> EntryStack<T> of(EntryDefinition<T> definition, T value) {
- if (Objects.equals(definition.getType().getId(), BuiltinEntryTypes.EMPTY_ID)) {
- return empty().cast();
- }
-
- return new TypedEntryStack<>(definition, value);
- }
- }, Internals.EntryStackProvider.class);
- Internals.attachInstance(new NbtHasherProviderImpl(), Internals.NbtHasherProvider.class);
- Internals.attachInstance(EntryIngredientImpl.provide(), Internals.EntryIngredientProvider.class);
+ Internals.attachInstance((Function<ResourceLocation, EntryType<?>>) DeferringEntryTypeProviderImpl.INSTANCE, "entryTypeDeferred");
+ Internals.attachInstance(EntryStackProviderImpl.INSTANCE, Internals.EntryStackProvider.class);
+ Internals.attachInstance(NbtHasherProviderImpl.INSTANCE, Internals.NbtHasherProvider.class);
+ Internals.attachInstance(EntryIngredientImpl.INSTANCE, Internals.EntryIngredientProvider.class);
Internals.attachInstanceSupplier(new PluginManagerImpl<>(
REIPlugin.class,
UnaryOperator.identity(),
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
index a8bddc1c3..1985e68b5 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
@@ -53,6 +53,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
+import me.shedaniel.rei.impl.client.favorites.DelegatingFavoriteEntryProviderImpl;
import me.shedaniel.rei.impl.client.favorites.FavoriteEntryTypeRegistryImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets;
@@ -118,75 +119,7 @@ public class RoughlyEnoughItemsCoreClient {
InternalWidgets.attach();
EmptyEntryDefinition.EmptyRenderer emptyEntryRenderer = new EmptyEntryDefinition.EmptyRenderer();
ClientInternals.attachInstance((Supplier<EntryRenderer<?>>) () -> emptyEntryRenderer, "emptyEntryRenderer");
- ClientInternals.attachInstance((BiFunction<Supplier<FavoriteEntry>, Supplier<CompoundTag>, FavoriteEntry>) (supplier, toJson) -> new FavoriteEntry() {
- FavoriteEntry value = null;
-
- @Override
- public FavoriteEntry getUnwrapped() {
- if (this.value == null) {
- this.value = supplier.get();
- }
- return Objects.requireNonNull(value).getUnwrapped();
- }
-
- @Override
- public UUID getUuid() {
- return getUnwrapped().getUuid();
- }
-
- @Override
- public boolean isInvalid() {
- try {
- return getUnwrapped().isInvalid();
- } catch (Exception e) {
- return true;
- }
- }
-
- @Override
- public Renderer getRenderer(boolean showcase) {
- return getUnwrapped().getRenderer(showcase);
- }
-
- @Override
- public boolean doAction(int button) {
- return getUnwrapped().doAction(button);
- }
-
- @Override
- public Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() {
- return getUnwrapped().getMenuEntries();
- }
-
- @Override
- public long hashIgnoreAmount() {
- return getUnwrapped().hashIgnoreAmount();
- }
-
- @Override
- public FavoriteEntry copy() {
- return FavoriteEntry.delegate(supplier, toJson);
- }
-
- @Override
- public ResourceLocation getType() {
- return getUnwrapped().getType();
- }
-
- @Override
- public CompoundTag save(CompoundTag tag) {
- if (toJson == null) {
- return getUnwrapped().save(tag);
- }
-
- return tag.merge(toJson.get());
- }
-
- @Override
- public boolean isSame(FavoriteEntry other) {
- return getUnwrapped().isSame(other.getUnwrapped());
- }
- }, "delegateFavoriteEntry");
+ ClientInternals.attachInstance((BiFunction<Supplier<FavoriteEntry>, Supplier<CompoundTag>, FavoriteEntry>) DelegatingFavoriteEntryProviderImpl::new, "delegateFavoriteEntry");
ClientInternals.attachInstance((Function<CompoundTag, FavoriteEntry>) (object) -> {
String type = object.getString(FavoriteEntry.TYPE_KEY);
ResourceLocation id = new ResourceLocation(type);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/DelegatingFavoriteEntryProviderImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/DelegatingFavoriteEntryProviderImpl.java
new file mode 100644
index 000000000..d58f7e6e4
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/DelegatingFavoriteEntryProviderImpl.java
@@ -0,0 +1,115 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.impl.client.favorites;
+
+import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
+import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry;
+import me.shedaniel.rei.api.client.gui.Renderer;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.resources.ResourceLocation;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Supplier;
+
+public class DelegatingFavoriteEntryProviderImpl extends FavoriteEntry {
+ private final Supplier<FavoriteEntry> supplier;
+ private final Supplier<CompoundTag> toJson;
+ private FavoriteEntry value = null;
+
+ public DelegatingFavoriteEntryProviderImpl(Supplier<FavoriteEntry> supplier, Supplier<CompoundTag> toJson) {
+ this.supplier = supplier;
+ this.toJson = toJson;
+ }
+
+ @Override
+ public FavoriteEntry getUnwrapped() {
+ synchronized (this) {
+ if (this.value == null) {
+ this.value = supplier.get();
+ }
+ }
+ return Objects.requireNonNull(value).getUnwrapped();
+ }
+
+ @Override
+ public UUID getUuid() {
+ return getUnwrapped().getUuid();
+ }
+
+ @Override
+ public boolean isInvalid() {
+ try {
+ return getUnwrapped().isInvalid();
+ } catch (Exception e) {
+ return true;
+ }
+ }
+
+ @Override
+ public Renderer getRenderer(boolean showcase) {
+ return getUnwrapped().getRenderer(showcase);
+ }
+
+ @Override
+ public boolean doAction(int button) {
+ return getUnwrapped().doAction(button);
+ }
+
+ @Override
+ public Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() {
+ return getUnwrapped().getMenuEntries();
+ }
+
+ @Override
+ public long hashIgnoreAmount() {
+ return getUnwrapped().hashIgnoreAmount();
+ }
+
+ @Override
+ public FavoriteEntry copy() {
+ return FavoriteEntry.delegate(supplier, toJson);
+ }
+
+ @Override
+ public ResourceLocation getType() {
+ return getUnwrapped().getType();
+ }
+
+ @Override
+ public CompoundTag save(CompoundTag tag) {
+ if (toJson == null) {
+ return getUnwrapped().save(tag);
+ }
+
+ return tag.merge(toJson.get());
+ }
+
+ @Override
+ public boolean isSame(FavoriteEntry other) {
+ return getUnwrapped().isSame(other.getUnwrapped());
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/