From d21a84ac2e07fe30685f1d703481425b0f01c93d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 19 Mar 2021 19:16:12 +0800 Subject: Implement ItemComparatorRegistry as a replacement for previous check tags and check amount flags Signed-off-by: shedaniel --- .../rei/api/gui/SimpleDisplayRenderer.java | 5 +- .../shedaniel/rei/api/ingredient/EntryStack.java | 30 ++----- .../ingredient/entry/AbstractEntryRenderer.java | 29 ------- .../api/ingredient/entry/BatchEntryRenderer.java | 61 -------------- .../api/ingredient/entry/BuiltinEntryTypes.java | 38 --------- .../api/ingredient/entry/ComparisonContext.java | 59 ------------- .../rei/api/ingredient/entry/EntryDefinition.java | 66 --------------- .../rei/api/ingredient/entry/EntryRenderer.java | 38 --------- .../rei/api/ingredient/entry/EntryType.java | 48 ----------- .../rei/api/ingredient/entry/EntryTypeBridge.java | 36 -------- .../api/ingredient/entry/EntryTypeRegistry.java | 98 ---------------------- .../api/ingredient/entry/VanillaEntryTypes.java | 35 -------- .../entry/comparison/ComparisonContext.java | 49 +++++++++++ .../entry/comparison/ItemComparator.java | 67 +++++++++++++++ .../entry/comparison/ItemComparatorRegistry.java | 62 ++++++++++++++ .../entry/renderer/AbstractEntryRenderer.java | 29 +++++++ .../entry/renderer/BatchEntryRenderer.java | 61 ++++++++++++++ .../ingredient/entry/renderer/EntryRenderer.java | 49 +++++++++++ .../ingredient/entry/type/BuiltinEntryTypes.java | 39 +++++++++ .../api/ingredient/entry/type/EntryDefinition.java | 69 +++++++++++++++ .../rei/api/ingredient/entry/type/EntryType.java | 48 +++++++++++ .../api/ingredient/entry/type/EntryTypeBridge.java | 36 ++++++++ .../ingredient/entry/type/EntryTypeRegistry.java | 98 ++++++++++++++++++++++ .../ingredient/entry/type/VanillaEntryTypes.java | 35 ++++++++ .../rei/api/ingredient/util/EntryIngredients.java | 4 +- .../rei/api/ingredient/util/EntryStacks.java | 39 +++++---- .../me/shedaniel/rei/api/plugins/REIPlugin.java | 12 ++- .../me/shedaniel/rei/api/util/CollectionUtils.java | 21 +---- .../main/java/me/shedaniel/rei/impl/Internals.java | 21 ++++- 29 files changed, 708 insertions(+), 574 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java index 50d44339e..404fab43a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java @@ -81,12 +81,12 @@ public class SimpleDisplayRenderer extends DisplayRenderer { public static boolean equalsList(EntryIngredient left, EntryIngredient right) { IntSet leftBytes = new IntOpenHashSet(left.size()); for (EntryStack entryStack : left) { - leftBytes.add(EntryStacks.hashIgnoreCount(entryStack)); + leftBytes.add(EntryStacks.hashExact(entryStack)); } if (leftBytes.size() > right.size()) return false; IntSet rightBytes = new IntOpenHashSet(right.size()); for (EntryStack entryStack : right) { - rightBytes.add(EntryStacks.hashIgnoreCount(entryStack)); + rightBytes.add(EntryStacks.hashExact(entryStack)); if (rightBytes.size() > leftBytes.size()) return false; } @@ -149,5 +149,4 @@ public class SimpleDisplayRenderer extends DisplayRenderer { public int getItemsPerLine() { return Mth.floor((getWidth() - 4f) / 18f); } - } diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java index d39bd4dde..d083b425b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java @@ -27,15 +27,16 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.serialization.Dynamic; import com.mojang.serialization.JsonOps; -import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.api.gui.Renderer; -import me.shedaniel.rei.api.ingredient.entry.*; -import me.shedaniel.rei.api.ingredient.util.EntryStacks; +import me.shedaniel.rei.api.ingredient.entry.EntrySerializer; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import me.shedaniel.rei.api.util.TextRepresentable; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.resources.language.I18n; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.TagParser; import net.minecraft.network.chat.Component; @@ -109,7 +110,8 @@ public interface EntryStack extends TextRepresentable, Renderer { } default EntryRenderer getRenderer() { - return getDefinition().getRenderer(); + EntryRenderer renderer = get(Settings.RENDER).apply(this); + return renderer == null ? EntryRenderer.empty() : renderer.cast(); } Optional getIdentifier(); @@ -151,16 +153,12 @@ public interface EntryStack extends TextRepresentable, Renderer { public static final Supplier TRUE = () -> true; public static final Supplier FALSE = () -> false; - public static final Settings> RENDER = new Settings<>(TRUE); - @Deprecated - public static final Settings> CHECK_TAGS = new Settings<>(FALSE); - @Deprecated - public static final Settings> CHECK_AMOUNT = new Settings<>(FALSE); + public static final Function, EntryRenderer> DEFAULT_RENDERER = stack -> stack.getDefinition().getRenderer(); + public static final Settings, EntryRenderer>> RENDER = new Settings<>(DEFAULT_RENDERER); @Deprecated public static final Settings> TOOLTIP_ENABLED = new Settings<>(TRUE); @Deprecated public static final Settings> TOOLTIP_APPEND_MOD = new Settings<>(TRUE); - public static final Settings> RENDER_COUNTS = new Settings<>(TRUE); @Deprecated public static final Settings, List>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList()); @Deprecated @@ -190,16 +188,6 @@ public interface EntryStack extends TextRepresentable, Renderer { public short getId() { return id; } - - public static class Fluid { - private static final String FLUID_AMOUNT = Platform.isForge() ? "tooltip.rei.fluid_amount.forge" : "tooltip.rei.fluid_amount"; - // Return null to disable - public static final Settings, String>> AMOUNT_TOOLTIP = new Settings<>(stack -> I18n.get(FLUID_AMOUNT, EntryStacks.simplifyAmount(stack.cast()).getValue().getAmount())); - - private Fluid() { - } - } - } @ApiStatus.NonExtendable diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java deleted file mode 100644 index bbc52436b..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import net.minecraft.client.gui.GuiComponent; - -public abstract class AbstractEntryRenderer extends GuiComponent implements EntryRenderer { -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java deleted file mode 100644 index 16660f336..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.ingredient.EntryStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.MultiBufferSource; - -public interface BatchEntryRenderer extends EntryRenderer { - static int getBatchIdFrom(EntryStack entry) { - EntryRenderer renderer = entry.getRenderer(); - if (renderer instanceof BatchEntryRenderer) return ((BatchEntryRenderer) renderer).getBatchId(entry); - return renderer.getClass().hashCode(); - } - - default int getBatchId(EntryStack entry) { - return getClass().hashCode(); - } - - void startBatch(EntryStack entry, PoseStack matrices, float delta); - - void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); - - void renderOverlay(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta); - - void endBatch(EntryStack entry, PoseStack matrices, float delta); - - @Deprecated - @Override - default void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - startBatch(entry, matrices, delta); - MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); - renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - renderOverlay(entry, matrices, bounds, mouseX, mouseY, delta); - endBatch(entry, matrices, delta); - } -} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java deleted file mode 100644 index 935418904..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.rei.api.gui.Renderer; -import me.shedaniel.rei.impl.Internals; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Unit; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.NonExtendable -public interface BuiltinEntryTypes { - ResourceLocation EMPTY_ID = new ResourceLocation("empty"); - ResourceLocation RENDERING_ID = new ResourceLocation("rendering"); - EntryType EMPTY = Internals.getEntryStackProvider().emptyType(EMPTY_ID); - EntryType RENDERING = Internals.getEntryStackProvider().renderingType(RENDERING_ID); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java deleted file mode 100644 index 4b30e44c1..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -public enum ComparisonContext { - /** - * Should only compare the type of the object - */ - FUZZY(true, true), - /** - * Should compare the nbt and the type of the object - */ - IGNORE_COUNT(true, false), - /** - * Should compare the amount and the type of the object - */ - IGNORE_NBT(true, false), - /** - * Should compare the amount, the nbt and the type of the object - */ - EXACT(false, false); - - boolean ignoresCount; - boolean ignoresNbt; - - ComparisonContext(boolean ignoresCount, boolean ignoresNbt) { - this.ignoresCount = ignoresCount; - this.ignoresNbt = ignoresNbt; - } - - public boolean isIgnoresCount() { - return ignoresCount; - } - - public boolean isIgnoresNbt() { - return ignoresNbt; - } -} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java deleted file mode 100644 index faa35334a..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.rei.api.ingredient.EntryStack; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.Optional; - -public interface EntryDefinition { - Class getValueType(); - - EntryType getType(); - - EntryRenderer getRenderer(); - - Optional getIdentifier(EntryStack entry, T value); - - boolean isEmpty(EntryStack entry, T value); - - T copy(EntryStack entry, T value); - - T normalize(EntryStack entry, T value); - - int hash(EntryStack entry, T value, ComparisonContext context); - - boolean equals(T o1, T o2, ComparisonContext context); - - @Nullable - EntrySerializer getSerializer(); - - Component asFormattedText(EntryStack entry, T value); - - Collection getTagsFor(EntryStack entry, T value); - - @ApiStatus.NonExtendable - default EntryDefinition cast() { - return (EntryDefinition) this; - } -} - diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java deleted file mode 100644 index 3ff850bb3..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.gui.widgets.Tooltip; -import me.shedaniel.rei.api.ingredient.EntryStack; -import org.jetbrains.annotations.Nullable; - -public interface EntryRenderer { - void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta); - - @Nullable - Tooltip getTooltip(EntryStack entry, Point mouse); -} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java deleted file mode 100644 index cc47fa116..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.rei.impl.Internals; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -@ApiStatus.NonExtendable -public interface EntryType { - static EntryType deferred(ResourceLocation id) { - return Internals.deferEntryType(id).cast(); - } - - @NotNull - ResourceLocation getId(); - - @NotNull - EntryDefinition getDefinition(); - - @ApiStatus.NonExtendable - @NotNull - default EntryType cast() { - return (EntryType) this; - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java deleted file mode 100644 index bd87a90ec..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.rei.api.ingredient.EntryStack; -import net.minecraft.world.InteractionResultHolder; -import org.jetbrains.annotations.NotNull; - -import java.util.stream.Stream; - -@FunctionalInterface -public interface EntryTypeBridge { - @NotNull - InteractionResultHolder>> bridge(EntryStack object); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java deleted file mode 100644 index eb11722dc..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.rei.api.plugins.PluginManager; -import me.shedaniel.rei.api.registry.Reloadable; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; - -import java.util.Set; - -public interface EntryTypeRegistry extends Reloadable { - static EntryTypeRegistry getInstance() { - return PluginManager.getInstance().get(EntryTypeRegistry.class); - } - - /** - * Registers a entry type, with its entry definition. - * - * @param type the entry type - * @param definition the definition of the entry - * @param the type of the entry - */ - default void register(EntryType type, EntryDefinition definition) { - register(type.getId(), definition); - } - - /** - * Registers a entry type, with its entry definition. - * - * @param id the identifier of the entry type - * @param definition the definition of the entry - * @param the type of the entry - */ - void register(ResourceLocation id, EntryDefinition definition); - - /** - * Returns the entry definition from the entry type. - * - * @param type the entry type - * @return the definition of the entry, may be {@code null} if {@code type} was not registered - */ - @Nullable - default EntryDefinition get(EntryType type) { - return type.getDefinition(); - } - - /** - * Returns the entry definition from an identifier of the entry type. - * - * @param id the identifier of the entry type - * @return the definition of the entry, may be {@code null} if {@code id} is an unknown type - */ - @Nullable - EntryDefinition get(ResourceLocation id); - - Set keySet(); - - Set> values(); - - /** - * Register a bridge between two entry types, for example, item to fluid, this is used, to - * approximately match two entry stacks,. - *

- * For bridging two entry types, only 1 one way bridge is required, two way bridges are discouraged - * for performance issues. - * - * @param original the original entry type - * @param destination the destination entry type - * @param bridge the bridge to bridge between the original and the destination types - * @param the type of the original entry type - * @param the type of the destination entry type - */ - void registerBridge(EntryType original, EntryType destination, EntryTypeBridge bridge); - - Iterable> getBridgesFor(EntryType original, EntryType destination); -} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java deleted file mode 100644 index 3737a2d7d..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.ingredient.entry; - -import me.shedaniel.architectury.fluid.FluidStack; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.NonExtendable -public interface VanillaEntryTypes { - EntryType ITEM = EntryType.deferred(new ResourceLocation("item")); - EntryType FLUID = EntryType.deferred(new ResourceLocation("fluid")); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java new file mode 100644 index 000000000..3a958adb5 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java @@ -0,0 +1,49 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.comparison; + +public enum ComparisonContext { + /** + * Should only compare the type of the object, normalized stacks may still not be the same. + */ + FUZZY(false), + /** + * Should compare the nbt and the type of the object, normalized stacks should be exactly the same. + */ + EXACT(true); + + boolean exact; + + ComparisonContext(boolean exact) { + this.exact = exact; + } + + public boolean isExact() { + return exact; + } + + public boolean isFuzzy() { + return !exact; + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java new file mode 100644 index 000000000..03f9511c4 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java @@ -0,0 +1,67 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.comparison; + +import me.shedaniel.rei.impl.Internals; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; + +import java.util.Objects; +import java.util.function.ToLongFunction; + +/** + * Hasher implementation for {@link ItemStack}. + */ +@FunctionalInterface +public interface ItemComparator { + static ItemComparator noop() { + return stack -> 1; + } + + static ItemComparator itemNbt() { + ToLongFunction nbtHasher = nbtHasher("Count"); + return stack -> { + CompoundTag tag = stack.getTag(); + return tag == null ? 0L : nbtHasher.applyAsLong(tag); + }; + } + + static ToLongFunction nbtHasher(String... ignoredKeys) { + return Internals.getNbtHasher(ignoredKeys); + } + + long hash(ItemStack stack); + + default ItemComparator then(ItemComparator other) { + Objects.requireNonNull(other); + + return stack -> { + long hash = 1L; + hash = hash * 31 + hash(stack); + hash = hash * 31 + other.hash(stack); + return hash; + }; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java new file mode 100644 index 000000000..ea97a57ac --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java @@ -0,0 +1,62 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.comparison; + +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +/** + * Registry for registering custom methods for identifying variants of {@link net.minecraft.world.item.ItemStack}. + * The default comparator is {@link ItemComparator#noop()}, which does not compare the NBT of the items. + *

+ * This comparator is used when the comparison context is {@link ComparisonContext#EXACT}. + */ +public interface ItemComparatorRegistry extends Reloadable { + /** + * @return the instance of {@link ItemComparatorRegistry} + */ + static ItemComparatorRegistry getInstance() { + return PluginManager.getInstance().get(ItemComparatorRegistry.class); + } + + void register(ItemComparator comparator, Item item); + + default void register(ItemComparator comparator, Item... items) { + for (Item item : items) { + register(comparator, item); + } + } + + default void registerNbt(Item item) { + register(ItemComparator.itemNbt(), item); + } + + default void registerNbt(Item... items) { + register(ItemComparator.itemNbt(), items); + } + + long hashOf(ItemStack stack); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java new file mode 100644 index 000000000..c868b44dc --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java @@ -0,0 +1,29 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.renderer; + +import net.minecraft.client.gui.GuiComponent; + +public abstract class AbstractEntryRenderer extends GuiComponent implements EntryRenderer { +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java new file mode 100644 index 000000000..343a2d4ac --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java @@ -0,0 +1,61 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.ingredient.EntryStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; + +public interface BatchEntryRenderer extends EntryRenderer { + static int getBatchIdFrom(EntryStack entry) { + EntryRenderer renderer = entry.getRenderer(); + if (renderer instanceof BatchEntryRenderer) return ((BatchEntryRenderer) renderer).getBatchId(entry); + return renderer.getClass().hashCode(); + } + + default int getBatchId(EntryStack entry) { + return getClass().hashCode(); + } + + void startBatch(EntryStack entry, PoseStack matrices, float delta); + + void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); + + void renderOverlay(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta); + + void endBatch(EntryStack entry, PoseStack matrices, float delta); + + @Deprecated + @Override + default void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + startBatch(entry, matrices, delta); + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + immediate.endBatch(); + renderOverlay(entry, matrices, bounds, mouseX, mouseY, delta); + endBatch(entry, matrices, delta); + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java new file mode 100644 index 000000000..0ab20098d --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java @@ -0,0 +1,49 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.gui.widgets.Tooltip; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.impl.Internals; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +public interface EntryRenderer { + static EntryRenderer empty() { + return Internals.getEmptyEntryRenderer(); + } + + void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta); + + @Nullable + Tooltip getTooltip(EntryStack entry, Point mouse); + + @ApiStatus.NonExtendable + default EntryRenderer cast() { + return (EntryRenderer) this; + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java new file mode 100644 index 000000000..72d535846 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java @@ -0,0 +1,39 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.type; + +import me.shedaniel.rei.api.gui.Renderer; +import me.shedaniel.rei.impl.Internals; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Unit; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.NonExtendable +public interface BuiltinEntryTypes { + ResourceLocation EMPTY_ID = new ResourceLocation("empty"); + ResourceLocation RENDERING_ID = new ResourceLocation("rendering"); + + EntryType EMPTY = Internals.getEntryStackProvider().emptyType(EMPTY_ID); + EntryType RENDERING = Internals.getEntryStackProvider().renderingType(RENDERING_ID); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java new file mode 100644 index 000000000..a4ba8f2bd --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java @@ -0,0 +1,69 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.type; + +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.EntrySerializer; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Optional; + +public interface EntryDefinition { + Class getValueType(); + + EntryType getType(); + + EntryRenderer getRenderer(); + + Optional getIdentifier(EntryStack entry, T value); + + boolean isEmpty(EntryStack entry, T value); + + T copy(EntryStack entry, T value); + + T normalize(EntryStack entry, T value); + + int hash(EntryStack entry, T value, ComparisonContext context); + + boolean equals(T o1, T o2, ComparisonContext context); + + @Nullable + EntrySerializer getSerializer(); + + Component asFormattedText(EntryStack entry, T value); + + Collection getTagsFor(EntryStack entry, T value); + + @ApiStatus.NonExtendable + default EntryDefinition cast() { + return (EntryDefinition) this; + } +} + diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java new file mode 100644 index 000000000..89479588f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java @@ -0,0 +1,48 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.type; + +import me.shedaniel.rei.impl.Internals; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +@ApiStatus.NonExtendable +public interface EntryType { + static EntryType deferred(ResourceLocation id) { + return Internals.deferEntryType(id).cast(); + } + + @NotNull + ResourceLocation getId(); + + @NotNull + EntryDefinition getDefinition(); + + @ApiStatus.NonExtendable + @NotNull + default EntryType cast() { + return (EntryType) this; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java new file mode 100644 index 000000000..de13eacda --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java @@ -0,0 +1,36 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.type; + +import me.shedaniel.rei.api.ingredient.EntryStack; +import net.minecraft.world.InteractionResultHolder; +import org.jetbrains.annotations.NotNull; + +import java.util.stream.Stream; + +@FunctionalInterface +public interface EntryTypeBridge { + @NotNull + InteractionResultHolder>> bridge(EntryStack object); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java new file mode 100644 index 000000000..3d836047a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java @@ -0,0 +1,98 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.type; + +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public interface EntryTypeRegistry extends Reloadable { + static EntryTypeRegistry getInstance() { + return PluginManager.getInstance().get(EntryTypeRegistry.class); + } + + /** + * Registers a entry type, with its entry definition. + * + * @param type the entry type + * @param definition the definition of the entry + * @param the type of the entry + */ + default void register(EntryType type, EntryDefinition definition) { + register(type.getId(), definition); + } + + /** + * Registers a entry type, with its entry definition. + * + * @param id the identifier of the entry type + * @param definition the definition of the entry + * @param the type of the entry + */ + void register(ResourceLocation id, EntryDefinition definition); + + /** + * Returns the entry definition from the entry type. + * + * @param type the entry type + * @return the definition of the entry, may be {@code null} if {@code type} was not registered + */ + @Nullable + default EntryDefinition get(EntryType type) { + return type.getDefinition(); + } + + /** + * Returns the entry definition from an identifier of the entry type. + * + * @param id the identifier of the entry type + * @return the definition of the entry, may be {@code null} if {@code id} is an unknown type + */ + @Nullable + EntryDefinition get(ResourceLocation id); + + Set keySet(); + + Set> values(); + + /** + * Register a bridge between two entry types, for example, item to fluid, this is used, to + * approximately match two entry stacks,. + *

+ * For bridging two entry types, only 1 one way bridge is required, two way bridges are discouraged + * for performance issues. + * + * @param original the original entry type + * @param destination the destination entry type + * @param bridge the bridge to bridge between the original and the destination types + * @param the type of the original entry type + * @param the type of the destination entry type + */ + void registerBridge(EntryType original, EntryType destination, EntryTypeBridge bridge); + + Iterable> getBridgesFor(EntryType original, EntryType destination); +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java new file mode 100644 index 000000000..2bc2bdb99 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java @@ -0,0 +1,35 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyrig