diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-27 01:12:02 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-27 01:12:02 +0800 |
| commit | b11c3866aada638f0ad758ced4068c71e620ce23 (patch) | |
| tree | 332f3ddab9be3da68b06d84823683608028d5b4c | |
| parent | 659027baa60c56b5aeab38d4f7c676c37857ec68 (diff) | |
| download | RoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.tar.gz RoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.tar.bz2 RoughlyEnoughItems-b11c3866aada638f0ad758ced4068c71e620ce23.zip | |
Make Recipe Transfer work
Signed-off-by: shedaniel <daniel@shedaniel.me>
23 files changed, 253 insertions, 113 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/search/SearchFilter.java b/api/src/main/java/me/shedaniel/rei/api/client/search/SearchFilter.java index 735e5fddf..ce77fe569 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/search/SearchFilter.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/search/SearchFilter.java @@ -27,6 +27,11 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import java.util.function.Predicate; +/** + * A search filter that respects different prefixes, matches a {@link EntryStack}. + * + * @see SearchProvider + */ public interface SearchFilter extends Predicate<EntryStack<?>> { static SearchFilter matchAll() { return new SearchFilter() { 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 103586d35..cd179180f 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 @@ -28,6 +28,8 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import java.util.List; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; /** * An immutable representation of a list of {@link EntryStack}. @@ -59,7 +61,7 @@ public interface EntryIngredient extends List<EntryStack<?>> { return Internals.getEntryIngredientProvider().builder(initialCapacity); } - static EntryIngredient from(ListTag tag) { + static EntryIngredient read(ListTag tag) { if (tag.isEmpty()) return empty(); EntryStack<?>[] stacks = new EntryStack[tag.size()]; for (int i = 0; i < tag.size(); i++) { @@ -75,6 +77,10 @@ public interface EntryIngredient extends List<EntryStack<?>> { return (List<EntryStack<T>>) (List) this; } + EntryIngredient filter(Predicate<EntryStack<?>> filter); + + EntryIngredient map(UnaryOperator<EntryStack<?>> transformer); + interface Builder { Builder add(EntryStack<?> stack); 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 07cbe62f7..ce7201d51 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 @@ -50,10 +50,7 @@ import net.minecraft.util.Unit; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; @@ -108,7 +105,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { EntryDefinition<?> definition = EntryTypeRegistry.getInstance().get(new ResourceLocation(tag.getString("type"))); EntrySerializer<?> serializer = definition.getSerializer(); if (serializer != null && serializer.supportReading()) { - return EntryStack.of((EntryType<Object>) definition, serializer.read(tag)); + return EntryStack.of((EntryDefinition<Object>) definition, serializer.read(tag)); } throw new UnsupportedOperationException(definition.getType().getId() + " does not support deserialization!"); } @@ -163,6 +160,8 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { EntryStack<T> normalize(); + Collection<ResourceLocation> getTagsFor(); + @Deprecated int hashCode(); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryDefinition.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryDefinition.java index f08480de1..04ea05d7f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryDefinition.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryDefinition.java @@ -31,6 +31,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; 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; @@ -67,7 +68,7 @@ public interface EntryDefinition<T> { Component asFormattedText(EntryStack<T> entry, T value); - Collection<ResourceLocation> getTagsFor(EntryStack<T> entry, T value); + Collection<ResourceLocation> getTagsFor(TagContainer tagContainer, EntryStack<T> entry, T value); @ApiStatus.NonExtendable default <O> EntryDefinition<O> cast() { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java index 12c35f604..4cd223fa7 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java @@ -55,7 +55,7 @@ public interface PluginManager<P extends REIPlugin<?>> extends ParentReloadable< } static List<PluginManager<? extends REIPlugin<?>>> getActiveInstances() { - return EnvExecutor.getEnvSpecific(() -> () -> Arrays.asList(getInstance(), getClientInstance()), + return EnvExecutor.getEnvSpecific(() -> () -> Arrays.asList(getInstance(), getClientInstance(), getServerInstance()), () -> () -> Arrays.asList(getInstance(), getServerInstance())); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java index 9b022ff28..786a212fc 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java @@ -158,7 +158,7 @@ public final class EntryIngredients { } ImmutableList.Builder<EntryIngredient> ingredients = ImmutableList.builder(); for (Tag tag : listTag) { - ingredients.add(EntryIngredient.from((ListTag) tag)); + ingredients.add(EntryIngredient.read((ListTag) tag)); } return ingredients.build(); } 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 3e72b8710..1b303c869 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 @@ -38,6 +38,7 @@ import me.shedaniel.rei.plugin.common.displays.*; import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconBaseDisplay; import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconDisplay; import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconPaymentDisplay; +import me.shedaniel.rei.plugin.common.displays.brewing.DefaultBrewingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultBlastingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultSmeltingDisplay; @@ -94,6 +95,7 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { registry.register(CAMPFIRE, DefaultCampfireDisplay.serializer()); registry.register(STONE_CUTTING, DefaultStoneCuttingDisplay.serializer()); registry.register(STRIPPING, DefaultStrippingDisplay.serializer()); + registry.register(BREWING, DefaultBrewingDisplay.serializer()); registry.register(COMPOSTING, DefaultCompostingDisplay.serializer()); registry.register(FUEL, DefaultFuelDisplay.serializer()); registry.register(SMITHING, DefaultSmithingDisplay.serializer()); @@ -106,13 +108,13 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { @Override public void registerMenuInfo(MenuInfoRegistry registry) { - registry.register(BuiltinPlugin.CRAFTING, CraftingMenu.class,new RecipeBookGridMenuInfo<CraftingMenu, DefaultCraftingDisplay>() { + registry.register(BuiltinPlugin.CRAFTING, CraftingMenu.class, new RecipeBookGridMenuInfo<CraftingMenu, DefaultCraftingDisplay>() { @Override public List<List<ItemStack>> getDisplayInputs(MenuInfoContext<CraftingMenu, ?, DefaultCraftingDisplay> context) { return context.getDisplay().getOrganisedInputEntries(this, context.getMenu()); } }); - registry.register(BuiltinPlugin.CRAFTING, InventoryMenu.class,new RecipeBookGridMenuInfo<InventoryMenu, DefaultCraftingDisplay>() { + registry.register(BuiltinPlugin.CRAFTING, InventoryMenu.class, new RecipeBookGridMenuInfo<InventoryMenu, DefaultCraftingDisplay>() { @Override public List<List<ItemStack>> getDisplayInputs(MenuInfoContext<InventoryMenu, ?, DefaultCraftingDisplay> context) { return context.getDisplay().getOrganisedInputEntries(this, context.getMenu()); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java index 370c072ac..519405a0e 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java @@ -119,7 +119,7 @@ public class DefaultInformationDisplay implements Display { @Override public DefaultInformationDisplay read(CompoundTag tag) { - EntryIngredient stacks = EntryIngredient.from(tag.getList("stacks", NbtType.COMPOUND)); + EntryIngredient stacks = EntryIngredient.read(tag.getList("stacks", NbtType.COMPOUND)); Component name = Component.Serializer.fromJson(tag.getString("name")); List<Component> descriptions = new ArrayList<>(); for (Tag descriptionTag : tag.getList("descriptions", NbtType.STRING)) { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java index d7d6abc72..6abff9561 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java @@ -24,8 +24,10 @@ package me.shedaniel.rei.plugin.common.displays.brewing; import com.google.common.collect.Lists; +import me.shedaniel.architectury.utils.NbtType; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.display.DisplaySerializer; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryIngredients; @@ -34,6 +36,7 @@ import me.shedaniel.rei.plugin.common.BuiltinPlugin; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -54,17 +57,9 @@ public class DefaultBrewingDisplay implements Display { } @ApiStatus.Internal - public DefaultBrewingDisplay(EntryIngredient inputs, EntryIngredient reactants, EntryStack<?> output) { - EntryIngredient.Builder inputBuilder = EntryIngredient.builder(inputs.size()); - for (EntryStack<?> input : inputs) { - inputBuilder.add(input.copy().tooltip(new TranslatableComponent("category.rei.brewing.input").withStyle(ChatFormatting.YELLOW))); - } - this.input = inputBuilder.build(); - EntryIngredient.Builder reactantBuilder = EntryIngredient.builder(reactants.size()); - for (EntryStack<?> reactant : reactants) { - reactantBuilder.add(reactant.copy().tooltip(new TranslatableComponent("category.rei.brewing.reactant").withStyle(ChatFormatting.YELLOW))); - } - this.reactant = reactantBuilder.build(); + public DefaultBrewingDisplay(EntryIngredient input, EntryIngredient reactant, EntryStack<?> output) { + this.input = input.map(stack -> stack.copy().tooltip(new TranslatableComponent("category.rei.brewing.input").withStyle(ChatFormatting.YELLOW))); + this.reactant = reactant.map(stack -> stack.copy().tooltip(new TranslatableComponent("category.rei.brewing.reactant").withStyle(ChatFormatting.YELLOW))); this.output = output.copy().tooltip(new TranslatableComponent("category.rei.brewing.result").withStyle(ChatFormatting.YELLOW)); } @@ -91,4 +86,24 @@ public class DefaultBrewingDisplay implements Display { stack.add(output); return stack; } + + public static DisplaySerializer<DefaultBrewingDisplay> serializer() { + return new DisplaySerializer<DefaultBrewingDisplay>() { + @Override + public CompoundTag save(CompoundTag tag, DefaultBrewingDisplay display) { + tag.put("input", display.input.save()); + tag.put("reactant", display.reactant.save()); + tag.put("output", display.output.save()); + return tag; + } + + @Override + public DefaultBrewingDisplay read(CompoundTag tag) { + EntryIngredient input = EntryIngredient.read(tag.getList("input", NbtType.COMPOUND)); + EntryIngredient reactant = EntryIngredient.read(tag.getList("reactant", NbtType.COMPOUND)); + EntryStack<?> output = EntryStack.read(tag.getCompound("output")); + return new DefaultBrewingDisplay(input, reactant, output); + } + }; + } } 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()); + } } |
