diff options
Diffstat (limited to 'api')
10 files changed, 66 insertions, 184 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 11fbe4a37..a0d429db1 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -116,14 +116,6 @@ public interface ConfigObject { boolean isGrabbingItems(); /** - * Returns whether favorites motions are animated. - * - * @return whether favorites motions are animated - */ - @Deprecated(forRemoval = true) - boolean isFavoritesAnimated(); - - /** * Returns whether motions are reduced. * * @return whether motions are reduced @@ -281,8 +273,6 @@ public interface ConfigObject { @ApiStatus.Experimental boolean doDisplayIMEHints(); - boolean doesFastEntryRendering(); - boolean doesCacheEntryRendering(); @ApiStatus.Experimental 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 deleted file mode 100644 index 2aba4ba67..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/BatchedEntryRenderer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.MultiBufferSource; - -/** - * A batched renderer for rendering a lot of {@link EntryStack} at once with better performance. - * - * @param <T> the entry type - * @param <E> the type of extra data returned in {@link #getExtraData(EntryStack)} - */ -@Environment(EnvType.CLIENT) -public interface BatchedEntryRenderer<T, E> extends EntryRenderer<T> { - default boolean isBatched(EntryStack<T> entry) { - return true; - } - - /** - * Returns extra data to be passed to various rendering methods. - * - * @param entry the stack - * @return the extra data - */ - E getExtraData(EntryStack<T> 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 extraData the extra data returned from {@link #getExtraData(EntryStack)} - * @return the batch identifier - */ - int getBatchIdentifier(EntryStack<T> entry, Rectangle bounds, E extraData); - - /** - * 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 extraData the extra data returned from {@link #getExtraData(EntryStack)} - * @param graphics the graphics context - * @param delta the tick delta - */ - void startBatch(EntryStack<T> entry, E extraData, GuiGraphics graphics, float delta); - - void renderBase(EntryStack<T> entry, E extraData, GuiGraphics graphics, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta); - - void afterBase(EntryStack<T> entry, E extraData, GuiGraphics graphics, float delta); - - void renderOverlay(EntryStack<T> entry, E extraData, GuiGraphics graphics, 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 extraData the extra data returned from {@link #getExtraData(EntryStack)} - * @param graphics the graphics context - * @param delta the tick delta - */ - void endBatch(EntryStack<T> entry, E extraData, GuiGraphics graphics, float delta); - - @Override - default void render(EntryStack<T> entry, GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { - PoseStack newStack = batchModifyMatrices(graphics.pose()); - graphics.pose().pushPose(); - graphics.pose().last().pose().set(newStack.last().pose()); - graphics.pose().last().normal().set(newStack.last().normal()); - E data = getExtraData(entry); - startBatch(entry, data, graphics, delta); - MultiBufferSource.BufferSource immediate = graphics.bufferSource; - renderBase(entry, data, graphics, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - renderOverlay(entry, data, graphics, immediate, bounds, mouseX, mouseY, delta); - immediate.endBatch(); - endBatch(entry, data, graphics, delta); - graphics.pose().popPose(); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java index b00381a07..6dda97e5b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java @@ -90,13 +90,13 @@ public class CompoundFavoriteRenderer implements Renderer { public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { updateAnimator(delta); graphics.enableScissor(bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY()); - graphics.pose().pushPose(); - graphics.pose().translate(0, this.offset.floatValue() * -bounds.getHeight(), 0); + graphics.pose().pushMatrix(); + graphics.pose().translate(0, this.offset.floatValue() * -bounds.getHeight()); for (int i = 0; i < count; i++) { renderers.apply(i).render(graphics, bounds, mouseX, mouseY, delta); - graphics.pose().translate(0, bounds.height, 0); + graphics.pose().translate(0, bounds.height); } - graphics.pose().popPose(); + graphics.pose().popMatrix(); graphics.disableScissor(); } 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 f7863abcc..aced40fa1 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 @@ -36,7 +36,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; @@ -120,8 +120,6 @@ public class SimpleDisplayRenderer extends DisplayRenderer implements WidgetHold int xx = bounds.x + 4, yy = bounds.y + 2; int j = 0; int itemsPerLine = getItemsPerLine(); - graphics.pose().pushPose(); - graphics.pose().translate(0, 0, 50); for (Slot entryWidget : inputWidgets) { entryWidget.getBounds().setLocation(xx, yy); entryWidget.render(graphics, mouseX, mouseY, delta); @@ -133,20 +131,16 @@ public class SimpleDisplayRenderer extends DisplayRenderer implements WidgetHold j = 0; } } - graphics.pose().popPose(); xx = bounds.x + 4 + 18 * (getItemsPerLine() - 2); yy = bounds.y + getHeight() / 2 - 8; - graphics.blit(RenderType::guiTextured, CHEST_GUI_TEXTURE, xx, yy, 0, 28, 18, 18, 256, 256); + graphics.blit(RenderPipelines.GUI_TEXTURED, CHEST_GUI_TEXTURE, xx, yy, 0, 28, 18, 18, 256, 256); xx += 18; yy += outputWidgets.size() * -9 + 9; - graphics.pose().pushPose(); - graphics.pose().translate(0, 0, 50); for (Slot outputWidget : outputWidgets) { outputWidget.getBounds().setLocation(xx, yy); outputWidget.render(graphics, mouseX, mouseY, delta); yy += 18; } - graphics.pose().popPose(); } @Nullable diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java index 499383833..8a3c01f77 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.client.gui.widgets; -import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -36,8 +35,8 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Renderable; import org.jetbrains.annotations.ApiStatus; -import org.joml.Matrix4f; -import org.joml.Vector4f; +import org.joml.Matrix3x2f; +import org.joml.Vector3f; import java.util.Stack; @@ -71,17 +70,13 @@ public abstract class Widget extends AbstractContainerEventHandler implements Re return mouseStack.pop(); } - public static Point translateMouse(PoseStack poses) { - return translateMouse(poses.last().pose()); + public static Point translateMouse(double x, double y) { + return translateMouse(new Matrix3x2f().translate((float) x, (float) y)); } - public static Point translateMouse(double x, double y, double z) { - return translateMouse(new Matrix4f().translate((float) x, (float) y, (float) z)); - } - - public static Point translateMouse(Matrix4f pose) { + public static Point translateMouse(Matrix3x2f pose) { Point mouse = mouse(); - Vector4f mouseVec = new Vector4f(mouse.x, mouse.y, 0, 1); + Vector3f mouseVec = new Vector3f(mouse.x, mouse.y, 1); pose.transform(mouseVec); return pushMouse(new Point(mouseVec.x(), mouseVec.y())); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index 6b4567038..79068b463 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -44,7 +44,7 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.item.Item; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; +import org.joml.Matrix3x2f; import java.util.*; import java.util.function.Consumer; @@ -110,19 +110,19 @@ public final class Widgets { return ClientInternals.getWidgetsProvider().wrapVanillaWidget(element); } - public static WidgetWithBounds withTranslate(Widget widget, double x, double y, double z) { - return withTranslate(widget, new Matrix4f().translate((float) x, (float) y, (float) z)); + public static WidgetWithBounds withTranslate(Widget widget, double x, double y) { + return withTranslate(widget, new Matrix3x2f().translate((float) x, (float) y)); } - public static WidgetWithBounds withTranslate(Widget widget, Matrix4f translate) { + public static WidgetWithBounds withTranslate(Widget widget, Matrix3x2f translate) { return withTranslate(widget, () -> translate); } - public static <T extends Widget> WidgetWithBounds withTranslate(T widget, Function<T, Matrix4f> translate) { + public static <T extends Widget> WidgetWithBounds withTranslate(T widget, Function<T, Matrix3x2f> translate) { return withTranslate(widget, () -> translate.apply(widget)); } - public static WidgetWithBounds withTranslate(Widget widget, Supplier<Matrix4f> translate) { + public static WidgetWithBounds withTranslate(Widget widget, Supplier<Matrix3x2f> translate) { WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); return ClientInternals.getWidgetsProvider().withTranslate(widgetWithBounds, translate); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java index f5c8981f8..e88791644 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/simple/SimpleTransferHandler.java @@ -174,11 +174,8 @@ public interface SimpleTransferHandler extends TransferHandler, TransferHandlerM for (Widget widget : widgets) { if (widget instanceof Slot && ((Slot) widget).getNoticeMark() == Slot.INPUT) { if (missingIndices.contains(i++)) { - graphics.pose().pushPose(); - graphics.pose().translate(0, 0, 50); Rectangle innerBounds = ((Slot) widget).getInnerBounds(); graphics.fill(innerBounds.x, innerBounds.y, innerBounds.getMaxX(), innerBounds.getMaxY(), 0x40ff0000); - graphics.pose().popPose(); } } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java b/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java index 6ca6595ff..6884b0776 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/MatrixUtils.java @@ -23,26 +23,53 @@ package me.shedaniel.rei.api.client.util; -import com.mojang.math.Transformation; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import org.jetbrains.annotations.ApiStatus; -import org.joml.Matrix4f; -import org.joml.Vector4f; +import org.joml.Matrix3x2f; +import org.joml.Vector3f; @ApiStatus.Experimental public class MatrixUtils { - public static Matrix4f inverse(Matrix4f matrix) { - Transformation transformation = new Transformation(matrix); - Transformation inverse = transformation.inverse(); - if (inverse != null) inverse.getScale(); // This has a side effect - return inverse == null ? Transformation.identity().getMatrixCopy() : inverse.getMatrixCopy(); + public static Matrix3x2f inverse(Matrix3x2f matrix) { + float m00 = matrix.m00; + float m01 = matrix.m01; + float m10 = matrix.m10; + float m11 = matrix.m11; + float m20 = matrix.m20; // Translation X + float m21 = matrix.m21; // Translation Y + + // Calculate determinant of the 2x2 rotation/scale part + float det = m00 * m11 - m10 * m01; + + if (Math.abs(det) < 0.00001f) { // Check for singularity (e.g., zero scale) + System.err.println("Warning: Matrix is singular (determinant near zero), cannot be accurately inverted."); + return null; + } + + float invDet = 1.0f / det; + float invM00 = m11 * invDet; + float invM01 = -m01 * invDet; + float invM10 = -m10 * invDet; + float invM11 = m00 * invDet; + + // Apply inverse 2x2 part to translation + // T_inv = -M_inv * T + float invM20 = -(invM00 * m20 + invM10 * m21); + float invM21 = -(invM01 * m20 + invM11 * m21); + + // Create the inverse matrix + return new Matrix3x2f( + invM00, invM01, // First column (x-axis transformation) + invM10, invM11, // Second column (y-axis transformation) + invM20, invM21 // Third column (translation) + ); } - public static Rectangle transform(Matrix4f matrix, Rectangle rectangle) { - Vector4f vec1 = new Vector4f((float) rectangle.x, (float) rectangle.y, 0, 1); + public static Rectangle transform(Matrix3x2f matrix, Rectangle rectangle) { + Vector3f vec1 = new Vector3f((float) rectangle.x, (float) rectangle.y, 1); matrix.transform(vec1); - Vector4f vec2 = new Vector4f((float) rectangle.getMaxX(), (float) rectangle.getMaxY(), 0, 1); + Vector3f vec2 = new Vector3f((float) rectangle.getMaxX(), (float) rectangle.getMaxY(), 1); matrix.transform(vec2); int x1 = Math.round(vec1.x()); int x2 = Math.round(vec2.x()); @@ -51,8 +78,8 @@ public class MatrixUtils { return new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2 - x1), Math.abs(y2 - y1)); } - public static Point transform(Matrix4f matrix, Point point) { - Vector4f mouse = new Vector4f((float) point.x, (float) point.y, 0, 1); + public static Point transform(Matrix3x2f matrix, Point point) { + Vector3f mouse = new Vector3f((float) point.x, (float) point.y, 1); matrix.transform(mouse); return new Point(mouse.x(), mouse.y()); } 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 f7005374f..ace052989 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 @@ -38,6 +38,7 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.TriState; import org.joml.Matrix3f; +import org.joml.Matrix3x2fStack; import org.joml.Matrix4f; import org.joml.Vector3f; @@ -70,7 +71,7 @@ public class SpriteRenderer { private TextureAtlasSprite sprite; private VertexConsumer consumer; private MultiBufferSource consumers; - private PoseStack matrices; + private Matrix3x2fStack matrices; private Matrix4f model; private Matrix3f normal; private RenderType layer; @@ -87,7 +88,7 @@ public class SpriteRenderer { public RenderPass setup(VertexConsumer consumer, RenderType type) { this.consumer = consumer; - this.matrices = new PoseStack(); + this.matrices = new Matrix3x2fStack(); this.layer = type; return this; @@ -207,7 +208,7 @@ public class SpriteRenderer { } public void next(ResourceLocation texture) { - if (this.consumer == null) { + /*if (this.consumer == null) { throw new RuntimeException("Invalid VertexConsumer!"); } if (this.matrices == null) { @@ -229,7 +230,7 @@ public class SpriteRenderer { TextureManager textureManager = Minecraft.getInstance().getTextureManager(); AbstractTexture abstractTexture = textureManager.getTexture(texture); - abstractTexture.setFilter(TriState.FALSE, false); + abstractTexture.setFilter(false, false); RenderSystem.setShaderTexture(0, abstractTexture.getTexture()); for (float y = y1; y < y2; y += Math.min(y2 - y, sY)) { @@ -274,7 +275,7 @@ public class SpriteRenderer { .setUv2(this.u, this.v) .setOverlay(this.l), this.normal, this.nX, this.nY, this.nZ); } - } + }*/ } } diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java index 0eb1c9b49..2545f0cfc 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -57,7 +57,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; +import org.joml.Matrix3x2f; import java.lang.reflect.Field; import java.util.Collection; @@ -81,7 +81,6 @@ public final class ClientInternals { private static BiFunction<Component, BooleanValue, FavoriteMenuEntry> toggleEntry = (supplier, toJson) -> throwNotSetup(); private static Function<CompoundTag, DataResult<FavoriteEntry>> favoriteEntryFromJson = (object) -> throwNotSetup(); private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); - private static BiConsumer<List<ClientTooltipComponent>, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static QuadFunction<Point, @Nullable TooltipFlag, Boolean, Item.TooltipContext, TooltipContext> tooltipContextProvider = (point, texts, search, context) -> throwNotSetup(); private static Function<Object, Tooltip.Entry> tooltipEntryProvider = (component) -> throwNotSetup(); @@ -138,10 +137,6 @@ public final class ClientInternals { return clickAreaHandlerResult.apply(applicable); } - public static void getClientTooltipComponent(List<ClientTooltipComponent> tooltip, TooltipComponent component) { - clientTooltipComponentProvider.accept(tooltip, component); - } - public static Tooltip createTooltip(@Nullable Point point, Collection<Tooltip.Entry> texts) { return tooltipProvider.apply(point, texts); } @@ -200,7 +195,7 @@ public final class ClientInternals { WidgetWithBounds wrapRenderer(Supplier<Rectangle> bounds, Renderer renderer); - WidgetWithBounds withTranslate(WidgetWithBounds widget, Supplier<Matrix4f> translate); + WidgetWithBounds withTranslate(WidgetWithBounds widget, Supplier<Matrix3x2f> translate); Widget createDrawableWidget(DrawableConsumer drawable); |
