From 8984313c6cd387dbb9448d5b1d824ab147a3b003 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 15:12:25 +0800 Subject: Allow filtering the displays with filtering rules --- api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java | 3 +++ api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 8d35049c2..8449851e7 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -151,6 +151,9 @@ public interface ConfigObject { List> getFilteredStackProviders(); + @ApiStatus.Experimental + boolean shouldFilterDisplays(); + @ApiStatus.Experimental boolean shouldAsyncSearch(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index 919644e09..d44731cc9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api.client.gui.widgets; +import me.shedaniel.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; @@ -134,7 +135,7 @@ public interface Tooltip { Tooltip withContextStack(EntryStack stack); default void queue() { - EnvExecutor.runInEnv(EnvType.CLIENT, () -> () -> REIRuntime.getInstance().queueTooltip(this)); + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> REIRuntime.getInstance().queueTooltip(this)); } @ApiStatus.NonExtendable -- cgit From 69e26e78b69f7eeb745b604b2347ac30fe32666f Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 17:50:10 +0800 Subject: Rewrite on how TransferHandler render errors, and fix #580 --- .../registry/display/TransferDisplayCategory.java | 2 + .../client/registry/transfer/TransferHandler.java | 62 ++++++++++++++++------ .../transfer/TransferHandlerErrorRenderer.java | 31 +++++++++++ .../shedaniel/rei/api/common/display/Display.java | 6 +++ .../rei/api/common/transfer/info/MenuInfo.java | 56 ++++++++++++++++++- .../rei/api/common/util/CollectionUtils.java | 23 ++++++++ 6 files changed, 162 insertions(+), 18 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/TransferDisplayCategory.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/TransferDisplayCategory.java index 5cc0fc459..00843f57a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/TransferDisplayCategory.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/TransferDisplayCategory.java @@ -35,6 +35,8 @@ import org.jetbrains.annotations.ApiStatus; import java.util.List; @Environment(EnvType.CLIENT) +@Deprecated +@ApiStatus.ScheduledForRemoval public interface TransferDisplayCategory extends DisplayCategory { @ApiStatus.OverrideOnly @ApiStatus.ScheduledForRemoval diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java index 9ec3a3a15..2d8a8ef83 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.client.registry.transfer; -import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.rei.api.client.registry.display.TransferDisplayCategory; import me.shedaniel.rei.api.common.display.Display; @@ -36,6 +35,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.function.Supplier; /** @@ -63,6 +63,16 @@ public interface TransferHandler extends Comparable { return Double.compare(getPriority(), o.getPriority()); } + @Environment(EnvType.CLIENT) + @Nullable + default TransferHandlerErrorRenderer provideErrorRenderer(Context context, Object data) { + if (data instanceof IntList) { + return TransferHandlerErrorRenderer.forRedSlots((IntList) data); + } + + return null; + } + @ApiStatus.NonExtendable interface Result { /** @@ -86,7 +96,7 @@ public interface TransferHandler extends Comparable { * @param error The error itself */ static Result createFailed(Component error) { - return new ResultImpl(error, new IntArrayList(), 0x67ff0000); + return new ResultImpl(error, 0x67ff0000); } /** @@ -97,7 +107,7 @@ public interface TransferHandler extends Comparable { * @param color A special color for the button */ static Result createFailedCustomButtonColor(Component error, int color) { - return new ResultImpl(error, new IntArrayList(), color); + return createFailed(error).color(color); } /** @@ -107,7 +117,7 @@ public interface TransferHandler extends Comparable { * @param redSlots A list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. */ static Result createFailed(Component error, IntList redSlots) { - return new ResultImpl(error, redSlots, 0x67ff0000); + return createFailed(error).errorRenderer(redSlots); } /** @@ -119,7 +129,7 @@ public interface TransferHandler extends Comparable { * @param redSlots A list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. */ static Result createFailedCustomButtonColor(Component error, IntList redSlots, int color) { - return new ResultImpl(error, redSlots, color); + return createFailed(error).errorRenderer(redSlots).color(color); } /** @@ -138,12 +148,17 @@ public interface TransferHandler extends Comparable { * @return the color in which the button should be displayed in. */ int getColor(); - + /** * Sets the color in which the button should be displayed in. */ Result color(int color); + /** + * Sets the error data, to be passed to {@link TransferHandler#provideErrorRenderer(Context, Object)}. + */ + Result errorRenderer(Object data); + /** * @return whether this handler has successfully handled the transfer. */ @@ -173,10 +188,12 @@ public interface TransferHandler extends Comparable { */ Component getError(); - /** - * @return a list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}. - */ - IntList getIntegers(); + @Environment(EnvType.CLIENT) + @ApiStatus.Internal + TransferHandlerErrorRenderer getErrorRenderer(TransferHandler handler, Context context); + + @ApiStatus.Internal + void fillTooltip(List components); } @ApiStatus.NonExtendable @@ -211,7 +228,7 @@ public interface TransferHandler extends Comparable { final class ResultImpl implements Result { private boolean successful, applicable, returningToScreen, blocking; private Component error; - private IntList integers = new IntArrayList(); + private Object errorRenderer; private int color; private ResultImpl() { @@ -227,12 +244,10 @@ public interface TransferHandler extends Comparable { this.applicable = applicable; } - public ResultImpl(Component error, IntList integers, int color) { + public ResultImpl(Component error, int color) { this.successful = false; this.applicable = true; this.error = error; - if (integers != null) - this.integers = integers; this.color = color; } @@ -254,6 +269,12 @@ public interface TransferHandler extends Comparable { return this; } + @Override + public Result errorRenderer(Object data) { + this.errorRenderer = data; + return this; + } + @Override public boolean isSuccessful() { return successful; @@ -280,8 +301,17 @@ public interface TransferHandler extends Comparable { } @Override - public IntList getIntegers() { - return integers; + @Environment(EnvType.CLIENT) + public TransferHandlerErrorRenderer getErrorRenderer(TransferHandler handler, Context context) { + if (errorRenderer == null) return null; + return handler.provideErrorRenderer(context, errorRenderer); + } + + @Override + public void fillTooltip(List components) { + if (!isSuccessful() && isApplicable()) { + components.add(getError()); + } } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java new file mode 100644 index 000000000..1d683ba41 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java @@ -0,0 +1,31 @@ +package me.shedaniel.rei.api.client.registry.transfer; + +import com.mojang.blaze3d.vertex.PoseStack; +import it.unimi.dsi.fastutil.ints.IntList; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.registry.display.TransferDisplayCategory; +import me.shedaniel.rei.api.common.display.Display; +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; +import java.util.Objects; + +@ApiStatus.Experimental +@FunctionalInterface +public interface TransferHandlerErrorRenderer { + void render(PoseStack matrices, int mouseX, int mouseY, float delta, List widgets, Rectangle bounds, Display display); + + @ApiStatus.Internal + static TransferHandlerErrorRenderer forRedSlots(IntList redSlots) { + return (matrices, mouseX, mouseY, delta, widgets, bounds, display) -> { + DisplayCategory category = Objects.requireNonNull(CategoryRegistry.getInstance().get(display.getCategoryIdentifier())) + .getCategory(); + if (category instanceof TransferDisplayCategory) { + ((TransferDisplayCategory) category).renderRedSlots(matrices, widgets, bounds, display, redSlots); + } + }; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java index 1ee2515e3..8b2b2ee22 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/display/Display.java @@ -25,6 +25,8 @@ package me.shedaniel.rei.api.common.display; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.transfer.info.MenuInfo; +import me.shedaniel.rei.api.common.transfer.info.MenuSerializationContext; import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; @@ -47,6 +49,10 @@ public interface Display extends DisplaySpec { */ List getInputEntries(); + default List getInputEntries(MenuSerializationContext context, MenuInfo info, boolean fill) { + return getInputEntries(); + } + /** * @return a list of outputs */ 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 b5ed1de67..4fa19f4b2 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 @@ -23,6 +23,11 @@ package me.shedaniel.rei.api.common.transfer.info; +import com.mojang.blaze3d.vertex.PoseStack; +import it.unimi.dsi.fastutil.ints.IntList; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.widgets.Slot; +import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; @@ -36,10 +41,12 @@ import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import me.shedaniel.rei.api.common.util.CollectionUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; import java.util.Collections; import java.util.List; @@ -119,15 +126,29 @@ public interface MenuInfo ex * Returns the inputs of the {@link Display}. The nested lists are possible stacks for that specific slot. * * @param context the context of the transfer + * @param fill whether this call is for a fill or not, if it is for a fill, the returned list should be aligned for the menu, + * otherwise it should be aligned for the display category * @return the list of lists of items */ - default List> getInputs(MenuInfoContext context) { + default List> getInputs(MenuInfoContext context, boolean fill) { if (context.getDisplay() == null) return Collections.emptyList(); - return CollectionUtils.map(context.getDisplay().getInputEntries(), inputEntry -> + return CollectionUtils.map(context.getDisplay().getInputEntries(context, this, fill), inputEntry -> CollectionUtils., ItemStack>filterAndMap(inputEntry, stack -> stack.getType() == VanillaEntryTypes.ITEM, EntryStack::castValue)); } + /** + * Returns the inputs of the {@link Display}. The nested lists are possible stacks for that specific slot. + * + * @param context the context of the transfer + * @return the list of lists of items + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default List> getInputs(MenuInfoContext context) { + return getInputs(context, false); + } + /** * Serializes the {@link Display} as {@link CompoundTag}, sent to the server for further info for the transfer. * @@ -150,4 +171,35 @@ public interface MenuInfo ex default D read(MenuSerializationContext context, CompoundTag tag) { return DisplaySerializerRegistry.getInstance().read(context.getCategoryIdentifier(), tag); } + + /** + * Renders the missing ingredients of the transfer. + * The indices of the missing stacks are provided, this aligns with the list returned by {@link #getInputs(MenuInfoContext, boolean)}. + * + * @param context the context of the transfer + * @param inputs the list of inputs + * @param missingIndices the indices of the missing stacks + * @param matrices the rendering transforming matrices + * @param mouseX the mouse x position + * @param mouseY the mouse y position + * @param delta the delta frame time + * @param widgets the widgets set-up by the category + * @param bounds the bounds of the display + */ + @Environment(EnvType.CLIENT) + default void renderMissingInput(MenuInfoContext context, List> inputs, IntList missingIndices, PoseStack matrices, int mouseX, int mouseY, + float delta, List widgets, Rectangle bounds) { + int i = 0; + for (Widget widget : widgets) { + if (widget instanceof Slot && ((Slot) widget).getNoticeMark() == Slot.INPUT) { + if (missingIndices.contains(i++)) { + matrices.pushPose(); + matrices.translate(0, 0, 400); + Rectangle innerBounds = ((Slot) widget).getInnerBounds(); + GuiComponent.fill(matrices, innerBounds.x, innerBounds.y, innerBounds.getMaxX(), innerBounds.getMaxY(), 0x40ff0000); + matrices.popPose(); + } + } + } + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index aa4ac5037..0d20cf7f9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -323,6 +323,29 @@ public class CollectionUtils { public int size() { return realSize; } + + @Override + public Iterator iterator() { + Iterator iterator = super.iterator(); + return new Iterator() { + boolean endReached = false; + + @Override + public boolean hasNext() { + return iterator.hasNext() && !endReached; + } + + @Override + public T next() { + try { + return iterator.next(); + } catch (NoSuchElementException e) { + endReached = true; + return null; + } + } + }; + } }; } }; -- cgit From 67f20e0233abc67f7743554deb486049e8a88e1c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 18:24:52 +0800 Subject: Fix duplicate items with CC Tweaked --- .../me/shedaniel/rei/api/common/util/CollectionUtils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 0d20cf7f9..946d9336f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -265,6 +265,19 @@ public class CollectionUtils { return l == null ? Collections.emptyList() : l; } + public static List mapAndFilter(Iterable list, Predicate predicate, Function function) { + List l = null; + for (T t : list) { + R r = function.apply(t); + if (predicate.test(r)) { + if (l == null) + l = Lists.newArrayList(); + l.add(r); + } + } + return l == null ? Collections.emptyList() : l; + } + public static int sumInt(Iterable list, Function function) { int sum = 0; for (T t : list) { -- cgit From 1aa8f3c5a2bc55135c3bef0e56c88bdd569dc00e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 18:26:23 +0800 Subject: Fix license --- .../transfer/TransferHandlerErrorRenderer.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java index 1d683ba41..d9669d753 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java @@ -1,3 +1,26 @@ +/* + * 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.api.client.registry.transfer; import com.mojang.blaze3d.vertex.PoseStack; -- cgit From 0dd97db996b084fc8e0533e093e8116786308747 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 20:51:17 +0800 Subject: Fix merge conflicts --- api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index d44731cc9..5f459dac9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -23,7 +23,7 @@ package me.shedaniel.rei.api.client.gui.widgets; -import me.shedaniel.architectury.utils.Env; +import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; -- cgit From 92778560fb4e9b0f37446bb4858b0dcad23bdde6 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 21 Nov 2021 17:21:28 +0800 Subject: Add wildcard matching --- .../shedaniel/rei/api/common/entry/EntryStack.java | 41 +++++++++++++ .../rei/api/common/entry/type/EntryDefinition.java | 70 ++++++++++++++++++++++ 2 files changed, 111 insertions(+) (limited to 'api/src') 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 74529de5c..da37a0432 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 @@ -52,6 +52,7 @@ import java.util.function.Function; /** * @see me.shedaniel.rei.api.common.util.EntryStacks */ +@ApiStatus.NonExtendable public interface EntryStack extends TextRepresentable, Renderer { static EntryStack empty() { return Internals.getEntryStackProvider().empty(); @@ -122,14 +123,54 @@ public interface EntryStack extends TextRepresentable, Renderer { boolean isEmpty(); + /** + * Returns a copy of this stack. + * The copied stack will retain the same settings applied, with a copied value. + * + * @return a copy for an entry + */ EntryStack copy(); + /** + * Returns a copy of this stack. + * The copied stack will retain the value object, with no settings applied. + * + * @return a copy for an entry + */ default EntryStack rewrap() { return copy(); } + /** + * Returns a copy of this stack. + * The copied stack will have no settings applied. + *

+ * The new value should be functionally equivalent to the original value, + * but should have a normalized state. + *

+ * For example, an {@link net.minecraft.world.item.ItemStack} should have its + * amount removed, but its tags kept. + * + * @return a copy for an entry + */ EntryStack normalize(); + /** + * Returns a copy of this stack. + * The copied stack will have no settings applied. + *

+ * The new value should be the bare minimum to match the original value. + *

+ * For example, an {@link net.minecraft.world.item.ItemStack} should have its + * amount and tags removed. + * + * @return a copy for an entry + * @since 6.2 + */ + default EntryStack wildcard() { + return normalize(); + } + Collection getTagsFor(); @Deprecated 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 81e2a93dd..343a3491c 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 @@ -46,22 +46,92 @@ import java.util.Collection; * @see EntryTypeRegistry */ public interface EntryDefinition { + /** + * Returns the type of the entry. + * + * @return the type of the entry + */ Class getValueType(); + /** + * Returns the type of this definition. The type is also used for comparing the type of two definitions, + * as the definition does not guarantee object and reference equality. + * + * @return the type of this definition + */ EntryType getType(); + /** + * Returns the renderer for this entry, this is used to render the entry, and provide tooltip. + * External plugins can extend this method using {@link me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry} + * to provide custom renderers. + * + * @return the renderer for this entry + */ @Environment(EnvType.CLIENT) EntryRenderer getRenderer(); + /** + * Returns the identifier for an entry, used in identifier search argument type, + * and appending the mod name to the tooltip. + * + * @param entry the entry + * @param value the value of the entry + * @return the identifier for an entry + */ @Nullable ResourceLocation getIdentifier(EntryStack entry, T value); + /** + * Returns whether the entry is empty, empty entries are not displayed, + * and are considered invalid. + * Empty entries will be treated equally to {@link EntryStack#empty()}. + * + * @param entry the entry + * @param value the value of the entry + * @return whether the entry is empty + */ boolean isEmpty(EntryStack entry, T value); + /** + * Returns a copy for an entry. + * + * @param entry the entry + * @param value the value of the entry + * @return a copy for an entry + */ T copy(EntryStack entry, T value); + /** + * Returns a normalized copy for an entry. + * The returned stack should be functionally equivalent to the original stack, + * but should have a normalized state. + *

+ * For example, an {@link net.minecraft.world.item.ItemStack} should have its + * amount removed, but its tags kept. + * + * @param entry the entry + * @param value the value of the entry + * @return a normalized copy for an entry + */ T normalize(EntryStack entry, T value); + /** + * Returns a wildcard copy for an entry. + * The returned stack should be the bare minimum to match the original stack. + *

+ * For example, an {@link net.minecraft.world.item.ItemStack} should have its + * amount and tags removed. + * + * @param entry the entry + * @param value the value of the entry + * @return a wildcard copy for an entry + * @since 6.2 + */ + default T wildcard(EntryStack entry, T value) { + return normalize(entry, value); + } + long hash(EntryStack entry, T value, ComparisonContext context); boolean equals(T o1, T o2, ComparisonContext context); -- cgit