From 8341de88a57ffe7c6be6634314ce7f18bccaf28e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 10 Apr 2021 02:29:48 +0800 Subject: Primitive port to 21w14a Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/client/REIHelper.java | 1 + .../client/entry/renderer/BatchEntryRenderer.java | 62 --------------- .../entry/renderer/BatchedEntryRenderer.java | 88 ++++++++++++++++++++++ .../api/client/entry/renderer/EntryRenderer.java | 7 ++ .../rei/api/client/gui/SimpleDisplayRenderer.java | 4 +- .../rei/api/client/util/SpriteRenderer.java | 4 +- .../shedaniel/rei/api/common/entry/EntryStack.java | 4 +- .../rei/api/common/transfer/info/MenuInfo.java | 5 +- .../info/simple/SimplePlayerInventoryMenuInfo.java | 2 +- .../rei/api/common/util/EntryIngredients.java | 11 +-- .../shedaniel/rei/api/common/util/EntryStacks.java | 16 +--- 11 files changed, 106 insertions(+), 98 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java (limited to 'api/src') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIHelper.java b/api/src/main/java/me/shedaniel/rei/api/client/REIHelper.java index 9cc776a55..ff5a3b762 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/REIHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/REIHelper.java @@ -35,6 +35,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.Optional; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java deleted file mode 100644 index ba7e5d150..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchEntryRenderer.java +++ /dev/null @@ -1,62 +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.client.entry.renderer; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.common.entry.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, MultiBufferSource.BufferSource immediate, 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, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - endBatch(entry, matrices, delta); - } -} \ No newline at end of file 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 new file mode 100644 index 000000000..400ef727c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java @@ -0,0 +1,88 @@ +/* + * 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.client.entry.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.common.entry.EntryStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; + +public interface BatchedEntryRenderer extends EntryRenderer { + /** + * 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 + * @return the batch identifier + */ + default int getBatchIdentifier(EntryStack entry, Rectangle bounds) { + return getClass().hashCode(); + } + + /** + * Modifies the {@link PoseStack} passed tp various batch rendering methods. + * + * @param matrices the matrix stack + * @return the modified matrix stack, could be an entirely different stack + */ + default PoseStack batchModifyMatrices(PoseStack matrices) { + return matrices; + } + + /** + * 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 + */ + 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, 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 + */ + void endBatch(EntryStack entry, 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); + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + renderBase(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + immediate.endBatch(); + renderOverlay(entry, matrices, immediate, bounds, mouseX, mouseY, delta); + immediate.endBatch(); + endBatch(entry, matrices, delta); + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java index 9ee60c5f8..caabdbabd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java @@ -34,6 +34,13 @@ import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +/** + * A renderer to render a {@link EntryStack}. + * Use {@link EntryStack.Settings#RENDERER} to change the {@link EntryRenderer} for a {@link EntryStack}. + * + * @param the entry type + * @see BatchedEntryRenderer + */ public interface EntryRenderer { static EntryRenderer empty() { return ClientInternals.getEmptyEntryRenderer(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java index 917a88b75..3ec24c511 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.api.client.gui; import com.google.common.base.Predicates; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; @@ -37,7 +38,6 @@ import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -121,7 +121,7 @@ public class SimpleDisplayRenderer extends DisplayRenderer implements WidgetHold } xx = bounds.x + 4 + 18 * (getItemsPerLine() - 2); yy = bounds.y + getHeight() / 2 - 8; - Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); + RenderSystem.setShaderTexture(0, CHEST_GUI_TEXTURE); blit(matrices, xx, yy, 0, 28, 18, 18); xx += 18; yy += outputWidgets.size() * -9 + 9; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java index 10de31d6d..1ff551825 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java @@ -23,11 +23,11 @@ package me.shedaniel.rei.api.client.util; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -212,7 +212,7 @@ public class SpriteRenderer { float sX = sprite.getWidth(); float sY = sprite.getHeight(); - Minecraft.getInstance().getTextureManager().bind(texture); + RenderSystem.setShaderTexture(0, texture); for (float y = y1; y < y2; y += Math.min(y2 - y, sY)) { for (float x = x1; x < x2; x += Math.min(x2 - x, sX)) { 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 660605f32..d6f73a7cf 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 @@ -103,7 +103,7 @@ public interface EntryStack extends TextRepresentable, Renderer { @Environment(EnvType.CLIENT) default EntryRenderer getRenderer() { - EntryRenderer renderer = get(Settings.RENDER).apply(this); + EntryRenderer renderer = get(Settings.RENDERER).apply(this); return renderer == null ? EntryRenderer.empty() : renderer.cast(); } @@ -162,7 +162,7 @@ public interface EntryStack extends TextRepresentable, Renderer { public static final Function, EntryRenderer> EMPTY_RENDERER = stack -> EntryRenderer.empty(); public static final BiFunction, Tooltip, Tooltip> DEFAULT_TOOLTIP_PROCESSOR = (stack, tooltip) -> tooltip; @Environment(EnvType.CLIENT) - public static final Settings, EntryRenderer>> RENDER = new Settings<>(DEFAULT_RENDERER); + public static final Settings, EntryRenderer>> RENDERER = new Settings<>(DEFAULT_RENDERER); @Deprecated public static final Settings, Tooltip, Tooltip>> TOOLTIP_PROCESSOR = new Settings<>(DEFAULT_TOOLTIP_PROCESSOR); @Deprecated 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 bdb54adbb..11c307def 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 @@ -65,11 +65,8 @@ public interface MenuInfo { Iterable getInventoryStacks(MenuInfoContext context); default void markDirty(MenuInfoContext context) { - context.getPlayerEntity().inventory.setChanged(); + context.getPlayerEntity().getInventory().setChanged(); context.getMenu().broadcastChanges(); - - AbstractContainerMenu containerMenu = context.getPlayerEntity().containerMenu; - context.getPlayerEntity().refreshContainer(containerMenu, containerMenu.getItems()); } default void populateRecipeFinder(T container, RecipeFinder finder) {} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimplePlayerInventoryMenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimplePlayerInventoryMenuInfo.java index 67f5d2bb1..e94630d46 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimplePlayerInventoryMenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimplePlayerInventoryMenuInfo.java @@ -77,7 +77,7 @@ public interface SimplePlayerInventoryMenuInfo getInventoryStacks(MenuInfoContext context) { - Inventory inventory = context.getPlayerEntity().inventory; + Inventory inventory = context.getPlayerEntity().getInventory(); return IntStream.range(0, inventory.items.size()) .mapToObj(index -> StackAccessor.fromContainer(inventory, index)) .collect(Collectors.toList()); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java index 786a212fc..d2488f4fa 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java @@ -25,7 +25,6 @@ package me.shedaniel.rei.api.common.util; import com.google.common.collect.ImmutableList; import me.shedaniel.architectury.fluid.FluidStack; -import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; @@ -58,15 +57,7 @@ public final class EntryIngredients { return EntryIngredient.of(EntryStacks.of(fluid)); } - public static EntryIngredient of(Fluid fluid, int amount) { - return EntryIngredient.of(EntryStacks.of(fluid, amount)); - } - - public static EntryIngredient of(Fluid fluid, double amount) { - return EntryIngredient.of(EntryStacks.of(fluid, amount)); - } - - public static EntryIngredient of(Fluid fluid, Fraction amount) { + public static EntryIngredient of(Fluid fluid, long amount) { return EntryIngredient.of(EntryStacks.of(fluid, amount)); } 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..3cd5fbd50 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 @@ -24,7 +24,6 @@ package me.shedaniel.rei.api.common.util; import me.shedaniel.architectury.fluid.FluidStack; -import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; import me.shedaniel.rei.api.common.entry.type.EntryType; @@ -47,15 +46,7 @@ public final class EntryStacks { return of(fluid, FluidStack.bucketAmount()); } - public static EntryStack of(Fluid fluid, int amount) { - return of(fluid, Fraction.ofWhole(amount)); - } - - public static EntryStack of(Fluid fluid, double amount) { - return of(fluid, Fraction.from(amount)); - } - - public static EntryStack of(Fluid fluid, Fraction amount) { + public static EntryStack of(Fluid fluid, long amount) { return EntryStack.of(VanillaEntryTypes.FLUID, FluidStack.create(fluid, amount)); } @@ -174,9 +165,4 @@ public final class EntryStacks { 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; - } } -- cgit