aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-03-27 01:12:02 +0800
committershedaniel <daniel@shedaniel.me>2021-03-27 01:12:02 +0800
commitb11c3866aada638f0ad758ced4068c71e620ce23 (patch)
tree332f3ddab9be3da68b06d84823683608028d5b4c /runtime/src
parent659027baa60c56b5aeab38d4f7c676c37857ec68 (diff)
downloadRoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.tar.gz
RoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.tar.bz2
RoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.zip
Make Recipe Transfer work
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java8
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java7
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/type/TagArgumentType.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/display/DisplaySerializerRegistryImpl.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java70
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EmptyEntryStack.java45
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java45
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/TypedEntryStack.java63
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/types/BuiltinEntryDefinition.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java19
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java10
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java5
14 files changed, 202 insertions, 90 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 7bc63e0b3..f82444644 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
@@ -32,6 +32,7 @@ import me.shedaniel.architectury.event.events.client.ClientScreenInputEvent;
import me.shedaniel.architectury.networking.NetworkManager;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.utils.Env;
+import me.shedaniel.architectury.utils.EnvExecutor;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.REIHelper;
import me.shedaniel.rei.api.client.REIOverlay;
@@ -74,6 +75,7 @@ import me.shedaniel.rei.impl.client.transfer.TransferHandlerRegistryImpl;
import me.shedaniel.rei.impl.client.view.ViewsImpl;
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.EntryIngredientImpl;
import me.shedaniel.rei.impl.common.entry.TypedEntryStack;
import me.shedaniel.rei.impl.common.entry.comparison.ItemComparatorRegistryImpl;
@@ -84,6 +86,7 @@ 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 me.shedaniel.rei.impl.common.util.IssuesDetector;
import me.shedaniel.rei.plugin.test.REITestPlugin;
@@ -148,6 +151,7 @@ public class RoughlyEnoughItemsCore {
REIPlugin.class,
UnaryOperator.identity(),
new EntryTypeRegistryImpl(),
+ new RecipeManagerContextImpl<>(RecipeManagerContextImpl.supplier()),
new ItemComparatorRegistryImpl(),
new DisplaySerializerRegistryImpl(),
new FluidSupportProviderImpl()), "commonPluginManager");
@@ -210,7 +214,7 @@ public class RoughlyEnoughItemsCore {
Internals.attachInstance(new Internals.EntryStackProvider() {
@Override
public EntryStack<Unit> empty() {
- return TypedEntryStack.EMPTY;
+ return EmptyEntryStack.EMPTY;
}
@Override
@@ -428,7 +432,7 @@ public class RoughlyEnoughItemsCore {
@Environment(EnvType.CLIENT)
private void loadTestPlugins() {
- if ( System.getProperty("rei.test", "false").equals("true")) {
+ if (System.getProperty("rei.test", "false").equals("true")) {
PluginView.getClientInstance().registerPlugin(new REITestPlugin());
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
index d3fc3b757..8db620c00 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
@@ -101,11 +101,12 @@ public final class InternalWidgets {
visible[0] = false;
IntList redSlots = null;
TransferHandler.Context context = TransferHandler.Context.create(false, containerScreen, displaySupplier.get());
- for (TransferHandler autoTransferHandler : TransferHandlerRegistry.getInstance()) {
+ for (TransferHandler transferHandler : TransferHandlerRegistry.getInstance()) {
try {
- TransferHandler.Result result = autoTransferHandler.handle(context);
- if (result.isApplicable())
+ TransferHandler.Result result = transferHandler.handle(context);
+ if (result.isApplicable()) {
visible[0] = true;
+ }
if (result.isSuccessful()) {
button.setEnabled(true);
error = null;
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
index 2635039fc..1fa56fe0b 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
@@ -51,6 +51,10 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
private final List<DisplayFiller<?, ?>> fillers = new ArrayList<>();
private final MutableInt displayCount = new MutableInt(0);
+ public DisplayRegistryImpl() {
+ super(RecipeManagerContextImpl.supplier());
+ }
+
@Override
public void acceptPlugin(REIClientPlugin plugin) {
plugin.registerDisplays(this);
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
index f654ce076..67520b666 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java
@@ -51,7 +51,7 @@ import java.util.regex.Pattern;
@Environment(EnvType.CLIENT)
public class Argument<T, R> {
public static final String SPACE = " ", EMPTY = "";
- static final Argument<Unit, Unit> ALWAYS = new Argument<>(AlwaysMatchingArgumentType.INSTANCE, EMPTY, true, -1, -1);
+ static final Argument<Unit, Unit> ALWAYS = new Argument<>(AlwaysMatchingArgumentType.INSTANCE, EMPTY, true, -1, -1, true);
private ArgumentType<T, R> argumentType;
private String text;
private T filterData;
@@ -60,10 +60,6 @@ public class Argument<T, R> {
private final int end;
private static final Pattern SPLIT_PATTERN = Pattern.compile("(?:\"([^\"]*)\")|([^\\s]+)");
- public Argument(ArgumentType<T, R> argumentType, String text, boolean regular, int start, int end) {
- this(argumentType, text, regular, start, end, true);
- }
-
public Argument(ArgumentType<T, R> argumentType, String text, boolean regular, int start, int end, boolean lowercase) {
this.argumentType = argumentType;
this.text = lowercase ? text.toLowerCase(Locale.ROOT) : text;
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/type/TagArgumentType.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/type/TagArgumentType.java
index a46e07317..a6495fc41 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/type/TagArgumentType.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/type/TagArgumentType.java
@@ -26,7 +26,6 @@ package me.shedaniel.rei.impl.client.search.argument.type;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.config.SearchMode;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Style;
@@ -70,7 +69,7 @@ public final class TagArgumentType extends ArgumentType<Unit, String[]> {
@Override
public boolean matches(Mutable<String[]> data, EntryStack<?> stack, String searchText, Unit filterData) {
if (data.getValue() == null) {
- Collection<ResourceLocation> tags = ((EntryDefinition<Object>) stack.getDefinition()).getTagsFor((EntryStack<Object>) stack, stack.getValue());
+ Collection<ResourceLocation> tags = stack.getTagsFor();
if (tags.isEmpty()) {
data.setValue(EMPTY_ARRAY);
} else {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/display/DisplaySerializerRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/display/DisplaySerializerRegistryImpl.java
index 7c8b8c127..fed8f7c79 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/display/DisplaySerializerRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/display/DisplaySerializerRegistryImpl.java
@@ -61,12 +61,12 @@ public class DisplaySerializerRegistryImpl implements DisplaySerializerRegistry
@Override
public <D extends Display> CompoundTag save(CategoryIdentifier<? extends D> categoryId, D display, CompoundTag tag) {
- return null;
+ return ((DisplaySerializer<D>) serializers.get(categoryId).serializer.get()).save(tag, display);
}
@Override
public <D extends Display> D read(CategoryIdentifier<? extends D> categoryId, CompoundTag tag) {
- return null;
+ return ((DisplaySerializer<D>) serializers.get(categoryId).serializer.get()).read(tag);
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java
index 5a0a5db08..d0edb1602 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java
@@ -27,6 +27,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
import it.unimi.dsi.fastutil.shorts.Short2ObjectMaps;
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
+import me.shedaniel.architectury.platform.Platform;
+import me.shedaniel.architectury.utils.Env;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.ClientHelper;
@@ -35,12 +37,20 @@ import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext;
import me.shedaniel.rei.api.common.util.EntryStacks;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
+import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.SerializationTags;
+import net.minecraft.tags.TagContainer;
import org.apache.commons.lang3.mutable.Mutable;
import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
+import java.util.Collection;
+
@ApiStatus.Internal
public abstract class AbstractEntryStack<A> extends AbstractRenderer implements EntryStack<A> {
private static final Short2ObjectMap<Object> EMPTY_SETTINGS = Short2ObjectMaps.emptyMap();
@@ -93,6 +103,40 @@ public abstract class AbstractEntryStack<A> extends AbstractRenderer implements
}
@Override
+ @Nullable
+ public ResourceLocation getIdentifier() {
+ return getDefinition().getIdentifier(this, getValue());
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getDefinition().isEmpty(this, getValue());
+ }
+
+ @Override
+ public EntryStack<A> copy() {
+ return wrap(getDefinition().copy(this, getValue()));
+ }
+
+ @Override
+ public EntryStack<A> rewrap() {
+ return wrap(getValue());
+ }
+
+ @Override
+ public EntryStack<A> normalize() {
+ return wrap(getDefinition().normalize(this, getValue()));
+ }
+
+ public EntryStack<A> wrap(A value) {
+ TypedEntryStack<A> stack = new TypedEntryStack<>(getDefinition(), value);
+ for (Short2ObjectMap.Entry<Object> entry : getSettings().short2ObjectEntrySet()) {
+ stack.setting(EntryStack.Settings.getById(entry.getShortKey()), entry.getValue());
+ }
+ return stack;
+ }
+
+ @Override
public <T> T get(Settings<T> settings) {
Object o = this.settings == null ? null : this.settings.get(settings.getId());
if (o == null) {
@@ -132,7 +176,33 @@ public abstract class AbstractEntryStack<A> extends AbstractRenderer implements
}
@Override
+ public int hash(ComparisonContext context) {
+ return getDefinition().hash(this, getValue(), context);
+ }
+
+ @Override
public int hashCode() {
return hash(ComparisonContext.EXACT);
}
+
+ @Override
+ public Collection<ResourceLocation> getTagsFor() {
+ TagContainer container;
+ if (Platform.getEnvironment() == Env.CLIENT) {
+ container = getClientTagContainer();
+ } else {
+ container = SerializationTags.getInstance();
+ }
+ return getDefinition().getTagsFor(container, this, getValue());
+ }
+
+ @Environment(EnvType.CLIENT)
+ private static TagContainer getClientTagContainer() {
+ return Minecraft.getInstance().getConnection().getTags();
+ }
+
+ @Override
+ public Component asFormattedText() {
+ return getDefinition().asFormattedText(this, getValue());
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EmptyEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EmptyEntryStack.java
new file mode 100644
index 000000000..337f80fe6
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EmptyEntryStack.java
@@ -0,0 +1,45 @@
+/*
+ * 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.impl.common.entry;
+
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.type.BuiltinEntryTypes;
+import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
+import net.minecraft.util.Unit;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+public class EmptyEntryStack extends AbstractEntryStack<Unit> {
+ public static final EntryStack<Unit> EMPTY = new EmptyEntryStack();
+
+ @Override
+ public EntryDefinition<Unit> getDefinition() {
+ return BuiltinEntryTypes.EMPTY.getDefinition();
+ }
+
+ @Override
+ public Unit getValue() {
+ return Unit.INSTANCE;
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java
index 759020cf4..892d34b0d 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java
@@ -37,11 +37,10 @@ import java.util.stream.StreamSupport;
public class EntryIngredientImpl {
public static Internals.EntryIngredientProvider provide() {
- EmptyEntryIngredient empty = new EmptyEntryIngredient();
return new Internals.EntryIngredientProvider() {
@Override
public EntryIngredient empty() {
- return empty;
+ return EmptyEntryIngredient.EMPTY;
}
@Override
@@ -51,7 +50,7 @@ public class EntryIngredientImpl {
@Override
public EntryIngredient of(EntryStack<?>... stacks) {
- if (stacks.length == 0) return empty;
+ if (stacks.length == 0) return empty();
if (stacks.length == 1) return of(stacks[0]);
return _of(stacks);
}
@@ -61,7 +60,7 @@ public class EntryIngredientImpl {
if (stacks instanceof EntryIngredient) return (EntryIngredient) stacks;
if (stacks instanceof Collection) {
int size = ((Collection<EntryStack<?>>) stacks).size();
- if (size == 0) return empty;
+ if (size == 0) return empty();
if (size == 1) return of(stacks.iterator().next());
return _of(((Collection<EntryStack<?>>) stacks).toArray(new EntryStack[0]));
}
@@ -146,6 +145,7 @@ public class EntryIngredientImpl {
}
private static class EmptyEntryIngredient extends AbstractList<EntryStack<?>> implements EntryIngredient, RandomAccess {
+ private static final EmptyEntryIngredient EMPTY = new EmptyEntryIngredient();
@Override
public Iterator<EntryStack<?>> iterator() {
return Collections.emptyIterator();
@@ -232,6 +232,16 @@ public class EntryIngredientImpl {
public ListTag save() {
return new ListTag();
}
+
+ @Override
+ public EntryIngredient filter(Predicate<EntryStack<?>> filter) {
+ return this;
+ }
+
+ @Override
+ public EntryIngredient map(UnaryOperator<EntryStack<?>> transformer) {
+ return this;
+ }
}
private static class SingletonEntryIngredient extends AbstractList<EntryStack<?>> implements EntryIngredient, RandomAccess {
@@ -343,6 +353,19 @@ public class EntryIngredientImpl {
listTag.add(stack.save());
return listTag;
}
+
+ @Override
+ public EntryIngredient filter(Predicate<EntryStack<?>> filter) {
+ if (filter.test(stack)) {
+ return this;
+ }
+ return EmptyEntryIngredient.EMPTY;
+ }
+
+ @Override
+ public EntryIngredient map(UnaryOperator<EntryStack<?>> transformer) {
+ return new SingletonEntryIngredient(transformer.apply(stack));
+ }
}
private static class ArrayIngredient extends AbstractList<EntryStack<?>> implements EntryIngredient, RandomAccess {
@@ -437,5 +460,19 @@ public class EntryIngredientImpl {
}
return listTag;
}
+
+ @Override
+ public EntryIngredient filter(Predicate<EntryStack<?>> filter) {
+ return EntryIngredient.of(stream().filter(filter).toArray(EntryStack[]::new));
+ }
+
+ @Override
+ public EntryIngredient map(UnaryOperator<EntryStack<?>> transformer) {
+ EntryStack<?>[] out = new EntryStack[array.length];
+ for (int i = 0; i < array.length; i++) {
+ out[i] = transformer.apply(array[i]);
+ }
+ return new ArrayIngredient(out);
+ }
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/TypedEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/TypedEntryStack.java
index 9eada5a65..90600718f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/TypedEntryStack.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/TypedEntryStack.java
@@ -23,29 +23,14 @@
package me.shedaniel.rei.impl.common.entry;
-import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
-import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext;
-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 net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraft.util.Unit;
import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.Nullable;
@ApiStatus.Internal
public class TypedEntryStack<T> extends AbstractEntryStack<T> {
- public static final EntryStack<Unit> EMPTY = new TypedEntryStack<>(BuiltinEntryTypes.EMPTY, Unit.INSTANCE);
-
private final EntryDefinition<T> definition;
private T value;
- public TypedEntryStack(EntryType<T> type, T value) {
- this(type.getDefinition(), value);
- }
-
public TypedEntryStack(EntryDefinition<T> definition, T value) {
this.definition = definition;
this.value = value;
@@ -60,52 +45,4 @@ public class TypedEntryStack<T> extends AbstractEntryStack<T> {
public T getValue() {
return value;
}
-
- @Override
- @Nullable
- public ResourceLocation getIdentifier() {
- return getDefinition().getIdentifier(this, value);
- }
-
- @Override
- public boolean isEmpty() {
- return getDefinition().isEmpty(this, value);
- }
-
- @Override
- public EntryStack<T> copy() {
- TypedEntryStack<T> stack = new TypedEntryStack<>(definition, getDefinition().copy(this, value));
- for (Short2ObjectMap.Entry<Object> entry : getSettings().short2ObjectEntrySet()) {
- stack.setting(EntryStack.Settings.getById(entry.getShortKey()), entry.getValue());
- }
- return stack;
- }
-
- @Override
- public EntryStack<T> rewrap() {
- TypedEntryStack<T> stack = new TypedEntryStack<>(definition, value);
- for (Short2ObjectMap.Entry<Object> entry : getSettings().short2ObjectEntrySet()) {
- stack.setting(EntryStack.Settings.getById(entry.getShortKey()), entry.getValue());
- }
- return stack;
- }
-
- @Override
- public EntryStack<T> normalize() {
- TypedEntryStack<T> stack = new TypedEntryStack<>(definition, getDefinition().normalize(this, value));
- for (Short2ObjectMap.Entry<Object> entry : getSettings().short2ObjectEntrySet()) {
- stack.setting(EntryStack.Settings.getById(entry.getShortKey()), entry.getValue());
- }
- return stack;
- }
-
- @Override
- public int hash(ComparisonContext context) {
- return getDefinition().hash(this, value, context);
- }
-
- @Override
- public Component asFormattedText() {
- return getDefinition().asFormattedText(this, value);
- }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/types/BuiltinEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/types/BuiltinEntryDefinition.java
index 2c14fb335..84eccfc5f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/types/BuiltinEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/types/BuiltinEntryDefinition.java
@@ -33,6 +33,7 @@ import me.shedaniel.rei.api.common.util.ImmutableTextComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.TagContainer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
@@ -115,7 +116,7 @@ public class BuiltinEntryDefinition<T> implements EntryDefinition<T>, EntrySeria
}
@Override
- public Collection<ResourceLocation> getTagsFor(EntryStack<T> entry, T value) {
+ public Collection<ResourceLocation> getTagsFor(TagContainer tagContainer, EntryStack<T> entry, T value) {
return Collections.emptyList();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java
index 14ce8aa47..c4081bc9c 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java
@@ -23,7 +23,9 @@
package me.shedaniel.rei.impl.common.registry;
-import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.architectury.utils.EnvExecutor;
+import me.shedaniel.architectury.utils.GameInstance;
+import me.shedaniel.rei.api.common.plugins.REIPlugin;
import me.shedaniel.rei.api.common.registry.RecipeManagerContext;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.crafting.Recipe;
@@ -32,12 +34,23 @@ import net.minecraft.world.item.crafting.RecipeManager;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
-public class RecipeManagerContextImpl<P extends REIClientPlugin> implements RecipeManagerContext<P> {
+public class RecipeManagerContextImpl<P extends REIPlugin<?>> implements RecipeManagerContext<P> {
private static final Comparator<Recipe<?>> RECIPE_COMPARATOR = Comparator.comparing((Recipe<?> o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath());
+ private final Supplier<RecipeManager> recipeManager;
private List<Recipe<?>> sortedRecipes = null;
+ public RecipeManagerContextImpl(Supplier<RecipeManager> recipeManager) {
+ this.recipeManager = recipeManager;
+ }
+
+ public static Supplier<RecipeManager> supplier() {
+ return () -> EnvExecutor.getEnvSpecific(() -> () -> Minecraft.getInstance().getConnection().getRecipeManager(),
+ () -> () -> GameInstance.getServer().getRecipeManager());
+ }
+
@Override
public List<Recipe<?>> getAllSortedRecipes() {
if (sortedRecipes == null) {
@@ -49,7 +62,7 @@ public class RecipeManagerContextImpl<P extends REIClientPlugin> implements Reci
@Override
public RecipeManager getRecipeManager() {
- return Minecraft.getInstance().getConnection().getRecipeManager();
+ return recipeManager.get();
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
index bc87ddf98..c1c2fdf1a 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
@@ -54,8 +54,11 @@ import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
+import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagCollection;
+import net.minecraft.tags.TagContainer;
+import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.Nullable;
@@ -157,12 +160,13 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS
@Override
public Component asFormattedText(EntryStack<FluidStack> entry, FluidStack value) {
- return value.getFluid().defaultFluidState().createLegacyBlock().getBlock().getName();
+ Block block = value.getFluid().defaultFluidState().createLegacyBlock().getBlock();
+ return new TranslatableComponent(block.getDescriptionId());
}
@Override
- public Collection<ResourceLocation> getTagsFor(EntryStack<FluidStack> entry, FluidStack value) {
- TagCollection<Fluid> collection = Minecraft.getInstance().getConnection().getTags().getFluids();
+ public Collection<ResourceLocation> getTagsFor(TagContainer tagContainer, EntryStack<FluidStack> entry, FluidStack value) {
+ TagCollection<Fluid> collection = tagContainer.getFluids();
return collection == null ? Collections.emptyList() : collection.getMatchingTags(value.getFluid());
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
index 59129f9d1..13b09cf88 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
@@ -56,6 +56,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagCollection;
+import net.minecraft.tags.TagContainer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
@@ -167,8 +168,8 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer