From 1167c00c645376481560afd838038251174860ec Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sun, 4 Jun 2023 00:07:28 +0300 Subject: Update to 1.20 RC 1 --- .../cottonmc/cotton/gui/SyncedGuiDescription.java | 4 +- .../cotton/gui/client/BackgroundPainter.java | 40 ++-- .../cotton/gui/client/CottonClientScreen.java | 26 +-- .../cottonmc/cotton/gui/client/CottonHud.java | 4 +- .../cotton/gui/client/CottonInventoryScreen.java | 32 ++- .../gui/client/NinePatchBackgroundPainter.java | 7 +- .../cottonmc/cotton/gui/client/ScreenDrawing.java | 214 ++++++++++----------- .../cottonmc/cotton/gui/impl/VisualLogger.java | 8 +- .../cotton/gui/impl/client/CottonScreenImpl.java | 4 - .../impl/client/NinePatchTextureRendererImpl.java | 12 +- .../cotton/gui/impl/modmenu/WKirbSprite.java | 6 +- .../io/github/cottonmc/cotton/gui/widget/WBar.java | 24 +-- .../github/cottonmc/cotton/gui/widget/WButton.java | 12 +- .../cottonmc/cotton/gui/widget/WClippedPanel.java | 8 +- .../cottonmc/cotton/gui/widget/WDynamicLabel.java | 6 +- .../github/cottonmc/cotton/gui/widget/WItem.java | 11 +- .../cottonmc/cotton/gui/widget/WItemSlot.java | 8 +- .../github/cottonmc/cotton/gui/widget/WLabel.java | 8 +- .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 19 +- .../cottonmc/cotton/gui/widget/WListPanel.java | 6 +- .../github/cottonmc/cotton/gui/widget/WPanel.java | 8 +- .../cottonmc/cotton/gui/widget/WScrollBar.java | 26 +-- .../cottonmc/cotton/gui/widget/WScrollPanel.java | 6 +- .../github/cottonmc/cotton/gui/widget/WSlider.java | 22 +-- .../github/cottonmc/cotton/gui/widget/WSprite.java | 20 +- .../cottonmc/cotton/gui/widget/WTabPanel.java | 12 +- .../github/cottonmc/cotton/gui/widget/WText.java | 8 +- .../cottonmc/cotton/gui/widget/WTextField.java | 44 ++--- .../cottonmc/cotton/gui/widget/WTiledSprite.java | 6 +- .../cottonmc/cotton/gui/widget/WToggleButton.java | 10 +- .../github/cottonmc/cotton/gui/widget/WWidget.java | 33 ++-- .../cottonmc/cotton/gui/widget/icon/Icon.java | 12 +- .../cottonmc/cotton/gui/widget/icon/ItemIcon.java | 11 +- .../cotton/gui/widget/icon/TextureIcon.java | 6 +- 34 files changed, 332 insertions(+), 351 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index 2abc643..64d905e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -71,7 +71,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio super(type, syncId); this.blockInventory = null; this.playerInventory = playerInventory; - this.world = playerInventory.player.world; + this.world = playerInventory.player.getWorld(); this.propertyDelegate = null;//new ArrayPropertyDelegate(1); } @@ -88,7 +88,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio super(type, syncId); this.blockInventory = blockInventory; this.playerInventory = playerInventory; - this.world = playerInventory.player.world; + this.world = playerInventory.player.getWorld(); this.propertyDelegate = propertyDelegate; if (propertyDelegate!=null && propertyDelegate.size()>0) this.addProperties(propertyDelegate); if (blockInventory != null) blockInventory.onOpen(playerInventory.player); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index 77b7268..f3df523 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -1,6 +1,6 @@ package io.github.cottonmc.cotton.gui.client; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; @@ -20,11 +20,13 @@ import java.util.function.Consumer; public interface BackgroundPainter { /** * Paint the specified panel to the screen. - * @param left The absolute position of the left of the panel, in gui-screen coordinates - * @param top The absolute position of the top of the panel, in gui-screen coordinates - * @param panel The panel being painted + * + * @param context The draw context + * @param left The absolute position of the left of the panel, in gui-screen coordinates + * @param top The absolute position of the top of the panel, in gui-screen coordinates + * @param panel The panel being painted */ - public void paintBackground(MatrixStack matrices, int left, int top, WWidget panel); + public void paintBackground(DrawContext context, int left, int top, WWidget panel); /** * The {@code VANILLA} background painter draws a vanilla-like GUI panel using nine-patch textures. @@ -47,9 +49,9 @@ public interface BackgroundPainter { * *

For {@linkplain WItemSlot item slots}, this painter uses {@link WItemSlot#SLOT_TEXTURE libgui:textures/widget/item_slot.png}. */ - public static BackgroundPainter SLOT = (matrices, left, top, panel) -> { + public static BackgroundPainter SLOT = (context, left, top, panel) -> { if (!(panel instanceof WItemSlot)) { - ScreenDrawing.drawBeveledPanel(matrices, left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); + ScreenDrawing.drawBeveledPanel(context, left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); } else { WItemSlot slot = (WItemSlot)panel; for(int x = 0; x < slot.getWidth()/18; ++x) { @@ -59,19 +61,19 @@ public interface BackgroundPainter { if (slot.isBigSlot()) { int sx = (x * 18) + left - 4; int sy = (y * 18) + top - 4; - ScreenDrawing.texturedRect(matrices, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, + ScreenDrawing.texturedRect(context, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, 18 * px, 0, 44 * px, 26 * px, 0xFF_FFFFFF); if (slot.getFocusedSlot() == index) { - ScreenDrawing.texturedRect(matrices, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, + ScreenDrawing.texturedRect(context, sx, sy, 26, 26, WItemSlot.SLOT_TEXTURE, 18 * px, 26 * px, 44 * px, 52 * px, 0xFF_FFFFFF); } } else { int sx = (x * 18) + left; int sy = (y * 18) + top; - ScreenDrawing.texturedRect(matrices, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, + ScreenDrawing.texturedRect(context, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, 0, 0, 18 * px, 18 * px, 0xFF_FFFFFF); if (slot.getFocusedSlot() == index) { - ScreenDrawing.texturedRect(matrices, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, + ScreenDrawing.texturedRect(context, sx, sy, 18, 18, WItemSlot.SLOT_TEXTURE, 0, 26 * px, 18 * px, 44 * px, 0xFF_FFFFFF); } } @@ -85,11 +87,11 @@ public interface BackgroundPainter { * * @param panelColor the panel background color * @return a colorful gui panel painter - * @see ScreenDrawing#drawGuiPanel(MatrixStack, int, int, int, int, int) + * @see ScreenDrawing#drawGuiPanel(DrawContext, int, int, int, int, int) */ public static BackgroundPainter createColorful(int panelColor) { - return (matrices, left, top, panel) -> { - ScreenDrawing.drawGuiPanel(matrices, left, top, panel.getWidth(), panel.getHeight(), panelColor); + return (context, left, top, panel) -> { + ScreenDrawing.drawGuiPanel(context, left, top, panel.getWidth(), panel.getHeight(), panelColor); }; } @@ -101,11 +103,11 @@ public interface BackgroundPainter { * @return a colorful gui panel painter */ public static BackgroundPainter createColorful(int panelColor, float contrast) { - return (matrices, left, top, panel) -> { + return (context, left, top, panel) -> { int shadowColor = ScreenDrawing.multiplyColor(panelColor, 1.0f - contrast); int hilightColor = ScreenDrawing.multiplyColor(panelColor, 1.0f + contrast); - ScreenDrawing.drawGuiPanel(matrices, left, top, panel.getWidth(), panel.getHeight(), shadowColor, panelColor, hilightColor, 0xFF000000); + ScreenDrawing.drawGuiPanel(context, left, top, panel.getWidth(), panel.getHeight(), shadowColor, panelColor, hilightColor, 0xFF000000); }; } @@ -151,9 +153,9 @@ public interface BackgroundPainter { * @since 1.5.0 */ public static BackgroundPainter createLightDarkVariants(BackgroundPainter light, BackgroundPainter dark) { - return (matrices, left, top, panel) -> { - if (panel.shouldRenderInDarkMode()) dark.paintBackground(matrices, left, top, panel); - else light.paintBackground(matrices, left, top, panel); + return (context, left, top, panel) -> { + if (panel.shouldRenderInDarkMode()) dark.paintBackground(context, left, top, panel); + else light.paintBackground(context, left, top, panel); }; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index 81d7646..310b9aa 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -1,11 +1,10 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Style; import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.GuiDescription; @@ -124,41 +123,41 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { } } - private void paint(MatrixStack matrices, int mouseX, int mouseY) { - renderBackground(matrices); + private void paint(DrawContext context, int mouseX, int mouseY) { + renderBackground(context); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { GL11.glEnable(GL11.GL_SCISSOR_TEST); Scissors.refreshScissors(); - root.paint(matrices, left, top, mouseX-left, mouseY-top); + root.paint(context, left, top, mouseX-left, mouseY-top); GL11.glDisable(GL11.GL_SCISSOR_TEST); Scissors.checkStackIsEmpty(); } if (getTitle() != null && description.isTitleVisible()) { int width = description.getRootPanel().getWidth(); - ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - titleX, description.getTitleColor()); } } } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { - paint(matrices, mouseX, mouseY); + public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { + paint(context, mouseX, mouseY); - super.render(matrices, mouseX, mouseY, partialTicks); + super.render(context, mouseX, mouseY, partialTicks); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { WWidget hitChild = root.hit(mouseX-left, mouseY-top); - if (hitChild!=null) hitChild.renderTooltip(matrices, left, top, mouseX-left, mouseY-top); + if (hitChild!=null) hitChild.renderTooltip(context, left, top, mouseX-left, mouseY-top); } } - VisualLogger.render(matrices); + VisualLogger.render(context); } @Override @@ -257,11 +256,6 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { return super.keyReleased(ch, keyCode, modifiers); } - @Override - public void renderTextHover(MatrixStack matrices, @Nullable Style textStyle, int x, int y) { - renderTextHoverEffect(matrices, textStyle, x, y); - } - @Override protected void addElementNarrations(NarrationMessageBuilder builder) { if (description != null) NarrationHelper.addNarrations(description.getRootPanel(), builder); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java index 05141a7..5dde548 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java @@ -23,7 +23,7 @@ public final class CottonHud { private static final Map positioners = new HashMap<>(); static { - HudRenderCallback.EVENT.register((matrices, tickDelta) -> { + HudRenderCallback.EVENT.register((drawContext, tickDelta) -> { Window window = MinecraftClient.getInstance().getWindow(); int hudWidth = window.getScaledWidth(); int hudHeight = window.getScaledHeight(); @@ -33,7 +33,7 @@ public final class CottonHud { positioner.reposition(widget, hudWidth, hudHeight); } - widget.paint(matrices, widget.getX(), widget.getY(), -1, -1); + widget.paint(drawContext, widget.getX(), widget.getY(), -1, -1); } }); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index 61fc287..04025a6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -1,14 +1,13 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.render.DiffuseLighting; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Style; import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.GuiDescription; @@ -274,17 +273,17 @@ public class CottonInventoryScreen extends Handl } @Override - protected void drawBackground(MatrixStack matrices, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. + protected void drawBackground(DrawContext context, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. - private void paint(MatrixStack matrices, int mouseX, int mouseY) { - renderBackground(matrices); + private void paint(DrawContext context, int mouseX, int mouseY) { + renderBackground(context); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { GL11.glEnable(GL11.GL_SCISSOR_TEST); Scissors.refreshScissors(); - root.paint(matrices, x, y, mouseX-x, mouseY-y); + root.paint(context, x, y, mouseX-x, mouseY-y); GL11.glDisable(GL11.GL_SCISSOR_TEST); Scissors.checkStackIsEmpty(); } @@ -292,29 +291,29 @@ public class CottonInventoryScreen extends Handl } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { - paint(matrices, mouseX, mouseY); + public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { + paint(context, mouseX, mouseY); - super.render(matrices, mouseX, mouseY, partialTicks); + super.render(context, mouseX, mouseY, partialTicks); DiffuseLighting.disableGuiDepthLighting(); //Needed because super.render leaves dirty state if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { WWidget hitChild = root.hit(mouseX-x, mouseY-y); - if (hitChild!=null) hitChild.renderTooltip(matrices, x, y, mouseX-x, mouseY-y); + if (hitChild!=null) hitChild.renderTooltip(context, x, y, mouseX-x, mouseY-y); } } - drawMouseoverTooltip(matrices, mouseX, mouseY); //Draws the itemstack tooltips - VisualLogger.render(matrices); + drawMouseoverTooltip(context, mouseX, mouseY); //Draws the itemstack tooltips + VisualLogger.render(context); } @Override - protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { if (description != null && description.isTitleVisible()) { int width = description.getRootPanel().getWidth(); - ScreenDrawing.drawString(matrices, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - titleX, description.getTitleColor()); } // Don't draw the player inventory label as it's drawn by the widget itself @@ -331,11 +330,6 @@ public class CottonInventoryScreen extends Handl } } - @Override - public void renderTextHover(MatrixStack matrices, @Nullable Style textStyle, int x, int y) { - renderTextHoverEffect(matrices, textStyle, x, y); - } - @Override protected void addElementNarrations(NarrationMessageBuilder builder) { if (description != null) NarrationHelper.addNarrations(description.getRootPanel(), builder); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatchBackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatchBackgroundPainter.java index 04e7a04..37fa1bf 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatchBackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatchBackgroundPainter.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.impl.client.NinePatchTextureRendererImpl; @@ -96,10 +96,11 @@ public final class NinePatchBackgroundPainter implements BackgroundPainter { } @Override - public void paintBackground(MatrixStack matrices, int left, int top, WWidget panel) { + public void paintBackground(DrawContext context, int left, int top, WWidget panel) { + var matrices = context.getMatrices(); matrices.push(); matrices.translate(left - leftPadding, top - topPadding, 0); - ninePatch.draw(NinePatchTextureRendererImpl.INSTANCE, matrices, panel.getWidth() + leftPadding + rightPadding, panel.getHeight() + topPadding + bottomPadding); + ninePatch.draw(NinePatchTextureRendererImpl.INSTANCE, context, panel.getWidth() + leftPadding + rightPadding, panel.getHeight() + topPadding + bottomPadding); matrices.pop(); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 7af67f1..64e9096 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -2,19 +2,17 @@ package io.github.cottonmc.cotton.gui.client; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.text.Style; import net.minecraft.util.Identifier; -import io.github.cottonmc.cotton.gui.impl.client.CottonScreenImpl; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; import io.github.cottonmc.cotton.gui.widget.data.Texture; import org.jetbrains.annotations.Nullable; @@ -29,7 +27,7 @@ public class ScreenDrawing { /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -37,14 +35,14 @@ public class ScreenDrawing { * @param texture the Identifier for the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int color) { - texturedRect(matrices, x, y, width, height, texture, 0, 0, 1, 1, color, 1.0f); + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Identifier texture, int color) { + texturedRect(context, x, y, width, height, texture, 0, 0, 1, 1, color, 1.0f); } /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -54,14 +52,14 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 2.0.0 */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int color, float opacity) { - texturedRect(matrices, x, y, width, height, texture, 0, 0, 1, 1, color, opacity); + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Identifier texture, int color, float opacity) { + texturedRect(context, x, y, width, height, texture, 0, 0, 1, 1, color, opacity); } /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -73,14 +71,14 @@ public class ScreenDrawing { * @param v2 the bottom edge of the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { - texturedRect(matrices, x, y, width, height, texture, u1, v1, u2, v2, color, 1.0f); + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { + texturedRect(context, x, y, width, height, texture, u1, v1, u2, v2, color, 1.0f); } /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -89,14 +87,14 @@ public class ScreenDrawing { * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint * @since 3.0.0 */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Texture texture, int color) { - texturedRect(matrices, x, y, width, height, texture, color, 1.0f); + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Texture texture, int color) { + texturedRect(context, x, y, width, height, texture, color, 1.0f); } /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -106,14 +104,14 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 3.0.0 */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Texture texture, int color, float opacity) { - texturedRect(matrices, x, y, width, height, texture.image(), texture.u1(), texture.v1(), texture.u2(), texture.v2(), color, opacity); + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Texture texture, int color, float opacity) { + texturedRect(context, x, y, width, height, texture.image(), texture.u1(), texture.v1(), texture.u2(), texture.v2(), color, opacity); } /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -127,7 +125,7 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 2.0.0 */ - public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) { + public static void texturedRect(DrawContext context, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) { if (width <= 0) width = 1; if (height <= 0) height = 1; @@ -136,7 +134,7 @@ public class ScreenDrawing { float b = (color & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); - Matrix4f model = matrices.peek().getPositionMatrix(); + Matrix4f model = context.getMatrices().peek().getPositionMatrix(); RenderSystem.enableBlend(); RenderSystem.setShaderTexture(0, texture); RenderSystem.setShaderColor(r, g, b, opacity); @@ -155,7 +153,7 @@ public class ScreenDrawing { * *

If the texture is 256x256, this draws the texture at one pixel per texel. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -165,9 +163,9 @@ public class ScreenDrawing { * @param textureY the y offset into the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedGuiRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int textureX, int textureY, int color) { + public static void texturedGuiRect(DrawContext context, int x, int y, int width, int height, Identifier texture, int textureX, int textureY, int color) { float px = 1/256f; - texturedRect(matrices, x, y, width, height, texture, textureX*px, textureY*px, (textureX+width)*px, (textureY+height)*px, color); + texturedRect(context, x, y, width, height, texture, textureX*px, textureY*px, (textureX+width)*px, (textureY+height)*px, color); } /** @@ -175,7 +173,7 @@ public class ScreenDrawing { * *

If the texture is 256x256, this draws the texture at one pixel per texel. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param left the x coordinate of the box on-screen * @param top the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -183,55 +181,55 @@ public class ScreenDrawing { * @param texture the Identifier for the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedGuiRect(MatrixStack matrices, int left, int top, int width, int height, Identifier texture, int color) { - texturedGuiRect(matrices, left, top, width, height, texture, 0, 0, color); + public static void texturedGuiRect(DrawContext context, int left, int top, int width, int height, Identifier texture, int color) { + texturedGuiRect(context, left, top, width, height, texture, 0, 0, color); } /** * Draws an untextured rectangle of the specified RGB color. */ - public static void coloredRect(MatrixStack matrices, int left, int top, int width, int height, int color) { + public static void coloredRect(DrawContext context, int left, int top, int width, int height, int color) { if (width <= 0) width = 1; if (height <= 0) height = 1; - DrawableHelper.fill(matrices, left, top, left + width, top + height, color); + context.fill(left, top, left + width, top + height, color); } /** * Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the X position of the panel * @param y the Y position of the panel * @param width the width of the panel * @param height the height of the panel */ - public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height) { - if (LibGui.isDarkMode()) drawGuiPanel(matrices, x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); - else drawGuiPanel(matrices, x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); + public static void drawGuiPanel(DrawContext context, int x, int y, int width, int height) { + if (LibGui.isDarkMode()) drawGuiPanel(context, x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); + else drawGuiPanel(context, x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); } /** * Draws a beveled, round, and colored rectangle that is substantially similar to default Minecraft UI panels. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the X position of the panel * @param y the Y position of the panel * @param width the width of the panel * @param height the height of the panel * @param panelColor the panel ARGB color */ - public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height, int panelColor) { + public static void drawGuiPanel(DrawContext context, int x, int y, int width, int height, int panelColor) { int shadowColor = multiplyColor(panelColor, 0.50f); int hilightColor = multiplyColor(panelColor, 1.25f); - drawGuiPanel(matrices, x, y, width, height, shadowColor, panelColor, hilightColor, 0xFF000000); + drawGuiPanel(context, x, y, width, height, shadowColor, panelColor, hilightColor, 0xFF000000); } /** * Draws a beveled, round rectangle with custom edge colors that is substantially similar to default Minecraft UI panels. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x the X position of the panel * @param y the Y position of the panel * @param width the width of the panel @@ -241,46 +239,46 @@ public class ScreenDrawing { * @param hilight the top/left hilight ARGB color * @param outline the outline ARGB color */ - public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { - coloredRect(matrices, x + 3, y + 3, width - 6, height - 6, panel); //Main panel area - - coloredRect(matrices, x + 2, y + 1, width - 4, 2, hilight); //Top hilight - coloredRect(matrices, x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow - coloredRect(matrices, x + 1, y + 2, 2, height - 4, hilight); //Left hilight - coloredRect(matrices, x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow - coloredRect(matrices, x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel - coloredRect(matrices, x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel - coloredRect(matrices, x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel - coloredRect(matrices, x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel - - coloredRect(matrices, x + 2, y, width - 4, 1, outline); //Top outline - coloredRect(matrices, x, y + 2, 1, height - 4, outline); //Left outline - coloredRect(matrices, x + width - 1, y + 2, 1, height - 4, outline); //Right outline - coloredRect(matrices, x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline - coloredRect(matrices, x + 1, y + 1, 1, 1, outline); //Topleft round pixel - coloredRect(matrices, x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel - coloredRect(matrices, x + width - 2, y + 1, 1, 1, outline); //Topright round pixel - coloredRect(matrices, x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel + public static void drawGuiPanel(DrawContext context, int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { + coloredRect(context, x + 3, y + 3, width - 6, height - 6, panel); //Main panel area + + coloredRect(context, x + 2, y + 1, width - 4, 2, hilight); //Top hilight + coloredRect(context, x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow + coloredRect(context, x + 1, y + 2, 2, height - 4, hilight); //Left hilight + coloredRect(context, x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow + coloredRect(context, x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel + coloredRect(context, x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel + coloredRect(context, x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel + coloredRect(context, x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel + + coloredRect(context, x + 2, y, width - 4, 1, outline); //Top outline + coloredRect(context, x, y + 2, 1, height - 4, outline); //Left outline + coloredRect(context, x + width - 1, y + 2, 1, height - 4, outline); //Right outline + coloredRect(context, x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline + coloredRect(context, x + 1, y + 1, 1, 1, outline); //Topleft round pixel + coloredRect(context, x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel + coloredRect(context, x + width - 2, y + 1, 1, 1, outline); //Topright round pixel + coloredRect(context, x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel } /** * Draws a default-sized recessed itemslot panel */ - public static void drawBeveledPanel(MatrixStack matrices, int x, int y) { - drawBeveledPanel(matrices, x, y, 18, 18, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); + public static void drawBeveledPanel(DrawContext context, int x, int y) { + drawBeveledPanel(context, x, y, 18, 18, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } /** * Draws a default-color recessed itemslot panel of variable size */ - public static void drawBeveledPanel(MatrixStack matrices, int x, int y, int width, int height) { - drawBeveledPanel(matrices, x, y, width, height, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); + public static void drawBeveledPanel(DrawContext context, int x, int y, int width, int height) { + drawBeveledPanel(context, x, y, width, height, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } /** * Draws a generalized-case beveled panel. Can be inset or outset depending on arguments. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param x x coordinate of the topleft corner * @param y y coordinate of the topleft corner * @param width width of the panel @@ -289,18 +287,18 @@ public class ScreenDrawing { * @param panel color of the panel area * @param bottomright color of the bottom/right bevel */ - public static void drawBeveledPanel(MatrixStack matrices, int x, int y, int width, int height, int topleft, int panel, int bottomright) { - coloredRect(matrices, x, y, width, height, panel); //Center panel - coloredRect(matrices, x, y, width - 1, 1, topleft); //Top shadow - coloredRect(matrices, x, y + 1, 1, height - 2, topleft); //Left shadow - coloredRect(matrices, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - coloredRect(matrices, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight + public static void drawBeveledPanel(DrawContext context, int x, int y, int width, int height, int topleft, int panel, int bottomright) { + coloredRect(context, x, y, width, height, panel); //Center panel + coloredRect(context, x, y, width - 1, 1, topleft); //Top shadow + coloredRect(context, x, y + 1, 1, height - 2, topleft); //Left shadow + coloredRect(context, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight + coloredRect(context, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } /** * Draws a string with a custom alignment. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param s the string * @param align the alignment of the string * @param x the X position @@ -308,22 +306,23 @@ public class ScreenDrawing { * @param width the width of the string, used for aligning * @param color the text color */ - public static void drawString(MatrixStack matrices, String s, HorizontalAlignment align, int x, int y, int width, int color) { + public static void drawString(DrawContext context, String s, HorizontalAlignment align, int x, int y, int width, int color) { + var textRenderer = MinecraftClient.getInstance().textRenderer; switch (align) { case LEFT -> { - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color); + context.drawText(textRenderer, s, x, y, color, false); } case CENTER -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); + int wid = textRenderer.getWidth(s); int l = (width / 2) - (wid / 2); - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x + l, y, color); + context.drawText(textRenderer, s, x + l, y, color, false); } case RIGHT -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); + int wid = textRenderer.getWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x + l, y, color); + context.drawText(textRenderer, s, x + l, y, color, false); } } } @@ -331,7 +330,7 @@ public class ScreenDrawing { /** * Draws a text component with a custom alignment. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param text the text * @param align the alignment of the string * @param x the X position @@ -340,22 +339,23 @@ public class ScreenDrawing { * @param color the text color * @since 1.9.0 */ - public static void drawString(MatrixStack matrices, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { + public static void drawString(DrawContext context, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { + var textRenderer = MinecraftClient.getInstance().textRenderer; switch (align) { case LEFT -> { - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); + context.drawText(textRenderer, text, x, y, color, false); } case CENTER -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); + int wid = textRenderer.getWidth(text); int l = (width / 2) - (wid / 2); - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x + l, y, color); + context.drawText(textRenderer, text, x + l, y, color, false); } case RIGHT -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); + int wid = textRenderer.getWidth(text); int l = width - wid; - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x + l, y, color); + context.drawText(textRenderer, text, x + l, y, color, false); } } } @@ -363,7 +363,7 @@ public class ScreenDrawing { /** * Draws a shadowed string. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param s the string * @param align the alignment of the string * @param x the X position @@ -371,22 +371,23 @@ public class ScreenDrawing { * @param width the width of the string, used for aligning * @param color the text color */ - public static void drawStringWithShadow(MatrixStack matrices, String s, HorizontalAlignment align, int x, int y, int width, int color) { + public static void drawStringWithShadow(DrawContext context, String s, HorizontalAlignment align, int x, int y, int width, int color) { + var textRenderer = MinecraftClient.getInstance().textRenderer; switch (align) { case LEFT -> { - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x, y, color); + context.drawText(textRenderer, s, x, y, color, true); } case CENTER -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); + int wid = textRenderer.getWidth(s); int l = (width / 2) - (wid / 2); - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x + l, y, color); + context.drawText(textRenderer, s, x + l, y, color, true); } case RIGHT -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(s); + int wid = textRenderer.getWidth(s); int l = width - wid; - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x + l, y, color); + context.drawText(textRenderer, s, x + l, y, color, true); } } } @@ -394,7 +395,7 @@ public class ScreenDrawing { /** * Draws a shadowed text component. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param text the text component * @param align the alignment of the string * @param x the X position @@ -402,22 +403,23 @@ public class ScreenDrawing { * @param width the width of the string, used for aligning * @param color the text color */ - public static void drawStringWithShadow(MatrixStack matrices, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { + public static void drawStringWithShadow(DrawContext context, OrderedText text, HorizontalAlignment align, int x, int y, int width, int color) { + var textRenderer = MinecraftClient.getInstance().textRenderer; switch (align) { case LEFT -> { - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x, y, color); + context.drawText(textRenderer, text, x, y, color, true); } case CENTER -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); + int wid = textRenderer.getWidth(text); int l = (width / 2) - (wid / 2); - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + l, y, color); + context.drawText(textRenderer, text, x + l, y, color, true); } case RIGHT -> { - int wid = MinecraftClient.getInstance().textRenderer.getWidth(text); + int wid = textRenderer.getWidth(text); int l = width - wid; - MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + l, y, color); + context.drawText(textRenderer, text, x + l, y, color, true); } } } @@ -425,27 +427,27 @@ public class ScreenDrawing { /** * Draws a left-aligned string. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param s the string * @param x the X position * @param y the Y position * @param color the text color */ - public static void drawString(MatrixStack matrices, String s, int x, int y, int color) { - MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color); + public static void drawString(DrawContext context, String s, int x, int y, int color) { + context.drawText(MinecraftClient.getInstance().textRenderer, s, x, y, color, false); } /** * Draws a left-aligned text component. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param text the text component * @param x the X position * @param y the Y position * @param color the text color */ - public static void drawString(MatrixStack matrices, OrderedText text, int x, int y, int color) { - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); + public static void drawString(DrawContext context, OrderedText text, int x, int y, int color) { + context.drawText(MinecraftClient.getInstance().textRenderer, text, x, y, color, false); } /** @@ -454,16 +456,14 @@ public class ScreenDrawing { *

This method has no effect when the caller is not in a LibGui screen. * For example, there will be nothing drawn in HUDs. * - * @param matrices the rendering matrix stack + * @param context the draw context * @param textStyle the text style * @param x the X position * @param y the Y position * @since 4.0.0 */ - public static void drawTextHover(MatrixStack matrices, @Nullable Style textStyle, int x, int y) { - if (MinecraftClient.getInstance().currentScreen instanceof CottonScreenImpl screen) { - screen.renderTextHover(matrices, textStyle, x, y); - } + public static void drawTextHover(DrawContext context, @Nullable Style textStyle, int x, int y) { + context.drawHoverEvent(MinecraftClient.getInstance().textRenderer, textStyle, x, y); } public static int colorAtOpacity(int opaque, float opacity) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/VisualLogger.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/VisualLogger.java index f54e9fa..490833f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/VisualLogger.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/VisualLogger.java @@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -53,7 +53,7 @@ public final class VisualLogger { } @Environment(EnvType.CLIENT) - public static void render(MatrixStack matrices) { + public static void render(DrawContext context) { var client = MinecraftClient.getInstance(); var textRenderer = client.textRenderer; int width = client.getWindow().getScaledWidth(); @@ -67,8 +67,8 @@ public final class VisualLogger { int y = 0; for (var line : lines) { - ScreenDrawing.coloredRect(matrices, 2, 2 + y, textRenderer.getWidth(line), fontHeight, 0x88_000000); - ScreenDrawing.drawString(matrices, line, 2, 2 + y, 0xFF_FFFFFF); + ScreenDrawing.coloredRect(context, 2, 2 + y, textRenderer.getWidth(line), fontHeight, 0x88_000000); + ScreenDrawing.drawString(context, line, 2, 2 + y, 0xFF_FFFFFF); y += fontHeight; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonScreenImpl.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonScreenImpl.java index cd215b3..4050c64 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonScreenImpl.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonScreenImpl.java @@ -2,8 +2,6 @@ package io.github.cottonmc.cotton.gui.impl.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Style; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.widget.WWidget; @@ -17,6 +15,4 @@ public interface CottonScreenImpl { WWidget getLastResponder(); void setLastResponder(@Nullable WWidget lastResponder); - - void renderTextHover(MatrixStack matrices, @Nullable Style textStyle, int x, int y); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java index 9227f94..d044dce 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/NinePatchTextureRendererImpl.java @@ -3,12 +3,12 @@ package io.github.cottonmc.cotton.gui.impl.client; import com.mojang.blaze3d.systems.RenderCall; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gl.ShaderProgram; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -19,20 +19,20 @@ import org.joml.Matrix4f; /** * An implementation of LibNinePatch's {@link ContextualTextureRenderer} for identifiers. */ -public enum NinePatchTextureRendererImpl implements ContextualTextureRenderer { +public enum NinePatchTextureRendererImpl implements ContextualTextureRenderer { INSTANCE; @Override - public void draw(Identifier texture, MatrixStack matrices, int x, int y, int width, int height, float u1, float v1, float u2, float v2) { - ScreenDrawing.texturedRect(matrices, x, y, width, height, texture, u1, v1, u2, v2, 0xFF_FFFFFF); + public void draw(Identifier texture, DrawContext context, int x, int y, int width, int height, float u1, float v1, float u2, float v2) { + ScreenDrawing.texturedRect(context, x, y, width, height, texture, u1, v1, u2, v2, 0xFF_FFFFFF); } @Override - public void drawTiled(Identifier texture, MatrixStack matrices, int x, int y, int regionWidth, int regionHeight, int tileWidth, int tileHeight, float u1, float v1, float u2, float v2) { + public void drawTiled(Identifier texture, DrawContext context, int x, int y, int regionWidth, int regionHeight, int tileWidth, int tileHeight, float u1, float v1, float u2, float v2) { RenderSystem.setShader(LibGuiShaders::getTiledRectangle); RenderSystem.setShaderTexture(0, texture); RenderSystem.setShaderColor(1, 1, 1, 1); - Matrix4f positionMatrix = matrices.peek().getPositionMatrix(); + Matrix4f positionMatrix = context.getMatrices().peek().getPositionMatrix(); onRenderThread(() -> { @Nullable ShaderProgram program = RenderSystem.getShader(); if (program != null) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/modmenu/WKirbSprite.java index 5d9473f..20c6ac0 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/modmenu/WKirbSprite.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.impl.modmenu; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -54,7 +54,7 @@ public class WKirbSprite extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { long now = System.nanoTime() / 1_000_000L; if (pendingFrames.isEmpty()) { @@ -81,7 +81,7 @@ public class WKirbSprite extends WWidget { } float offset = KIRB_WIDTH * currentFrame; - ScreenDrawing.texturedRect(matrices, x, y + 8, 32, 32, KIRB, offset, 0, offset + KIRB_WIDTH, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y + 8, 32, 32, KIRB, offset, 0, offset + KIRB_WIDTH, 1, 0xFFFFFFFF); long elapsed = now - lastFrame; currentFrameTime += elapsed; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index b6a6dd8..0a4f51b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.screen.PropertyDelegate; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -137,11 +137,11 @@ public class WBar extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { if (bg != null) { - ScreenDrawing.texturedRect(matrices, x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(matrices, x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); + ScreenDrawing.coloredRect(context, x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); } int maxVal = max >= 0 ? properties.get(max) : maxValue; @@ -162,25 +162,25 @@ public class WBar extends WWidget { int top = y + getHeight(); top -= barSize; if (bar != null) { - ScreenDrawing.texturedRect(matrices, left, top, getWidth(), barSize, bar.image(), bar.u1(), MathHelper.lerp(percent, bar.v2(), bar.v1()), bar.u2(), bar.v2(), 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, left, top, getWidth(), barSize, bar.image(), bar.u1(), MathHelper.lerp(percent, bar.v2(), bar.v1()), bar.u2(), bar.v2(), 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(matrices, left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(context, left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } } case RIGHT -> { if (bar != null) { - ScreenDrawing.texturedRect(matrices, x, y, barSize, getHeight(), bar.image(), bar.u1(), bar.v1(), MathHelper.lerp(percent, bar.u1(), bar.u2()), bar.v2(), 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, barSize, getHeight(), bar.image(), bar.u1(), bar.v1(), MathHelper.lerp(percent, bar.u1(), bar.u2()), bar.v2(), 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(matrices, x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(context, x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } } case DOWN -> { if (bar != null) { - ScreenDrawing.texturedRect(matrices, x, y, getWidth(), barSize, bar.image(), bar.u1(), bar.v1(), bar.u2(), MathHelper.lerp(percent, bar.v1(), bar.v2()), 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, getWidth(), barSize, bar.image(), bar.u1(), bar.v1(), bar.u2(), MathHelper.lerp(percent, bar.v1(), bar.v2()), 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(matrices, x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(context, x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } } @@ -189,9 +189,9 @@ public class WBar extends WWidget { int top = y; left -= barSize; if (bar != null) { - ScreenDrawing.texturedRect(matrices, left, top, barSize, getHeight(), bar.image(), MathHelper.lerp(percent, bar.u2(), bar.u1()), bar.v1(), bar.u2(), bar.v2(), 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, left, top, barSize, getHeight(), bar.image(), MathHelper.lerp(percent, bar.u2(), bar.u1()), bar.v1(), bar.u2(), bar.v2(), 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(matrices, left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(context, left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index d865452..1230905 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -3,11 +3,11 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -88,7 +88,7 @@ public class WButton extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX