From 513347f841a401391f59b4c9fe3cbcb4f554f86d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 12 Apr 2021 00:36:08 +0800 Subject: Prepare for true sided REI Signed-off-by: shedaniel --- api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java | 1 - .../java/me/shedaniel/rei/api/common/util/TextRepresentable.java | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'api') 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 3b0f6b454..99dbf1014 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 @@ -49,7 +49,6 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; -@Environment(EnvType.CLIENT) public interface EntryStack extends TextRepresentable, Renderer { static EntryStack empty() { return Internals.getEntryStackProvider().empty(); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java b/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java index b4b0c9c0c..0cf9bc535 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java @@ -23,11 +23,11 @@ package me.shedaniel.rei.api.common.util; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.network.chat.Component; -@Environment(EnvType.CLIENT) +/** + * A component that can be represented in {@link Component}. + */ public interface TextRepresentable { default Component asFormattedText() { return ImmutableTextComponent.EMPTY; -- cgit From 5467c2f08da6f3c6dae7ae603e3708d4f6eb1638 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 12 Apr 2021 21:30:18 +0800 Subject: Fix #502 and Fix #499 Signed-off-by: shedaniel --- .../client/registry/category/CategoryRegistry.java | 14 ++++++------- .../client/registry/display/DisplayRegistry.java | 8 ++++---- .../shedaniel/rei/api/common/entry/EntryStack.java | 3 +++ .../shedaniel/rei/api/common/util/EntryStacks.java | 23 +++++++++++++++------- 4 files changed, 30 insertions(+), 18 deletions(-) (limited to 'api') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java index 90abba478..254d0b5fd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java @@ -58,8 +58,8 @@ public interface CategoryRegistry extends Reloadable, Iterable< * * @param category the category to register */ - default void register(DisplayCategory category) { - register(category, config -> {}); + default void add(DisplayCategory category) { + add(category, config -> {}); } /** @@ -68,16 +68,16 @@ public interface CategoryRegistry extends Reloadable, Iterable< * @param category the category to register * @param configurator the consumer for configuring the attributes of the category */ - void register(DisplayCategory category, Consumer> configurator); + void add(DisplayCategory category, Consumer> configurator); /** * Registers the categories supplied. * * @param categories the categories to register */ - default void register(Iterable> categories) { + default void add(Iterable> categories) { for (DisplayCategory category : categories) { - register(category); + add(category); } } @@ -86,9 +86,9 @@ public interface CategoryRegistry extends Reloadable, Iterable< * * @param categories the categories to register */ - default void register(DisplayCategory... categories) { + default void add(DisplayCategory... categories) { for (DisplayCategory category : categories) { - register(category); + add(category); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index 65bdb9460..7535645a5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -62,22 +62,22 @@ public interface DisplayRegistry extends RecipeManagerContext { * * @param display the recipe display */ - void registerDisplay(Display display); + void add(Display display); /** * Returns an unmodifiable map of displays visible to the player * * @return an unmodifiable map of displays */ - Map, List> getAllDisplays(); + Map, List> getAll(); /** * Returns the list of displays visible to the player for a category * * @return the list of displays */ - default List getDisplays(CategoryIdentifier categoryId) { - return (List) getAllDisplays().getOrDefault(categoryId, Collections.emptyList()); + default List get(CategoryIdentifier categoryId) { + return (List) getAll().getOrDefault(categoryId, Collections.emptyList()); } /** 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 99dbf1014..7288ca97a 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 @@ -49,6 +49,9 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +/** + * @see me.shedaniel.rei.api.common.util.EntryStacks + */ public interface EntryStack extends TextRepresentable, Renderer { static EntryStack empty() { return Internals.getEntryStackProvider().empty(); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java index c8b1b86e9..46e601f37 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java @@ -147,6 +147,18 @@ public final class EntryStacks { return equals(left, right, ComparisonContext.FUZZY); } + /** + * Hash Code of the {@code context} context. + * + * @param stack the stack to hash code + * @param context the context to use + * @param the type of the stack + * @return the hash code of the {@code context} context + */ + public static long hash(EntryStack stack, ComparisonContext context) { + return stack.getDefinition().hash(stack, stack.getValue(), context); + } + /** * Hash Code of the {@link ComparisonContext#EXACT} context, stacks with the same hash code should share the same normalized stack. *

@@ -156,9 +168,10 @@ public final class EntryStacks { * @param stack the stack to hash code * @param the type of the stack * @return the hash code of the {@link ComparisonContext#EXACT} context + * @see #hash(EntryStack, ComparisonContext) */ public static long hashExact(EntryStack stack) { - return stack.getDefinition().hash(stack, stack.getValue(), ComparisonContext.EXACT); + return hash(stack, ComparisonContext.EXACT); } /** @@ -170,13 +183,9 @@ public final class EntryStacks { * @param stack the stack to hash code * @param the type of the stack * @return the hash code of the {@link ComparisonContext#FUZZY} context + * @see #hash(EntryStack, ComparisonContext) */ public static long hashFuzzy(EntryStack stack) { - return stack.getDefinition().hash(stack, stack.getValue(), ComparisonContext.FUZZY); - } - - public static EntryStack simplifyAmount(EntryStack stack) { - stack.getValue().setAmount(stack.getValue().getAmount().simplify()); - return stack; + return hash(stack, ComparisonContext.FUZZY); } } -- cgit From d892547a9b8a8ae85655900c08b6cc97c6aa2050 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 14 Apr 2021 17:33:29 +0800 Subject: Pass the BakedModel as an extra data Signed-off-by: shedaniel --- .../entry/renderer/BatchedEntryRenderer.java | 58 +++++++++++++++------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'api') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java index 400ef727c..f5aa5e579 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java @@ -29,16 +29,35 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; -public interface BatchedEntryRenderer extends EntryRenderer { +/** + * A batched renderer for rendering a lot of {@link EntryStack} at once with better performance. + * + * @param the entry type + * @param the type of extra data returned in {@link #getExtraData(EntryStack)} + */ +public interface BatchedEntryRenderer extends EntryRenderer { + default boolean isBatched(EntryStack entry) { + return true; + } + + /** + * Returns extra data to be passed to various rendering methods. + * + * @param entry the stack + * @return the extra data + */ + E getExtraData(EntryStack entry); + /** * Returns a batch identifier, stacks with the same batch identifier will be grouped together * into a batch. * - * @param entry the stack - * @param bounds the bounds of the entry + * @param entry the stack + * @param bounds the bounds of the entry + * @param extraData the extra data returned from {@link #getExtraData(EntryStack)} * @return the batch identifier */ - default int getBatchIdentifier(EntryStack entry, Rectangle bounds) { + default int getBatchIdentifier(EntryStack entry, Rectangle bounds, E extraData) { return getClass().hashCode(); } @@ -55,34 +74,37 @@ public interface BatchedEntryRenderer extends EntryRenderer { /** * Starts the batch rendering, used to setup states, only called once with every batch. * - * @param entry the first entry in the batch - * @param matrices the matrix stack - * @param delta the tick delta + * @param entry the first entry in the batch + * @param extraData the extra data returned from {@link #getExtraData(EntryStack)} + * @param matrices the matrix stack + * @param delta the tick delta */ - void startBatch(EntryStack entry, PoseStack matrices, float delta); + void startBatch(EntryStack entry, E extraData, PoseStack matrices, float delta); - void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); + void renderBase(EntryStack entry, E extraData, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); - void renderOverlay(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); + void renderOverlay(EntryStack entry, E extraData, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); /** * Ends the batch rendering, used to setup states, only called once with every batch. * - * @param entry the first entry in the batch - * @param matrices the matrix stack - * @param delta the tick delta + * @param entry the first entry in the batch + * @param extraData the extra data returned from {@link #getExtraData(EntryStack)} + * @param matrices the matrix stack + * @param delta the tick delta */ - void endBatch(EntryStack entry, PoseStack matrices, float delta); + void endBatch(EntryStack entry, E extraData, PoseStack matrices, float delta); @Override default void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { matrices = batchModifyMatrices(matrices); - startBatch(entry, matrices, delta); + E data = getExtraData(entry); + startBatch(entry, data, matrices, delta); MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); - renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + renderBase(entry, data, matrices, immediate, bounds, mouseX, mouseY, delta); immediate.endBatch(); - renderOverlay(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + renderOverlay(entry, data, matrices, immediate, bounds, mouseX, mouseY, delta); immediate.endBatch(); - endBatch(entry, matrices, delta); + endBatch(entry, data, matrices, delta); } } \ No newline at end of file -- cgit