diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-06-11 13:48:58 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-06-11 13:48:58 +0300 |
commit | 50de295b5c106f4a50c82b4446240f0dcbb3f526 (patch) | |
tree | eab45da6bbf52ce1c03a11cbb465d1e2f165506d /src | |
parent | 6f41969c6c85be5d0f7ad0cf2537071f3befde66 (diff) | |
parent | 6b14e2b3afa122744d3ae209703fc44b041b4e80 (diff) | |
download | LibGui-50de295b5c106f4a50c82b4446240f0dcbb3f526.tar.gz LibGui-50de295b5c106f4a50c82b4446240f0dcbb3f526.tar.bz2 LibGui-50de295b5c106f4a50c82b4446240f0dcbb3f526.zip |
Merge branch 'unstable/8.0'
# Conflicts:
# gradle.properties
# src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
# src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
Diffstat (limited to 'src')
38 files changed, 456 insertions, 475 deletions
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 { * * <p>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 0df0597..877528c 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 - 2 * titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - 2 * 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 @@ -258,11 +257,6 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { } @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<WWidget, Positioner> 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 013856d..b1ed4ce 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<T extends SyncedGuiDescription> 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<T extends SyncedGuiDescription> 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 - 2 * titleX, description.getTitleColor()); + ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), titleX, titleY, width - 2 * titleX, description.getTitleColor()); } // Don't draw the player inventory label as it's drawn by the widget itself @@ -332,11 +331,6 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> 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..4064a04 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,105 +27,105 @@ public class ScreenDrawing { /** * Draws a textured rectangle. * - * @param matrices the rendering matrix stack - * @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 - * @param height the height of the box on-screen - * @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 + * @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 + * @param height the height of the box on-screen + * @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 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 - * @param height the height of the box on-screen - * @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 - * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) + * @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 + * @param height the height of the box on-screen + * @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 + * @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 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 - * @param height the height of the box on-screen - * @param texture the Identifier for the texture - * @param u1 the left edge of the texture - * @param v1 the top edge of the texture - * @param u2 the right edge of the texture - * @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 + * @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 + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param u1 the left edge of the texture + * @param v1 the top edge of the texture + * @param u2 the right edge of the texture + * @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 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 - * @param height the height of the box on-screen - * @param texture 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 + * @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 + * @param height the height of the box on-screen + * @param texture 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 * @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 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 - * @param height the height of the box on-screen - * @param texture 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 - * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) + * @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 + * @param height the height of the box on-screen + * @param texture 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 + * @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 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 - * @param height the height of the box on-screen - * @param texture the Identifier for the texture - * @param u1 the left edge of the texture - * @param v1 the top edge of the texture - * @param u2 the right edge of the texture - * @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 - * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) + * @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 + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param u1 the left edge of the texture + * @param v1 the top edge of the texture + * @param u2 the right edge of the texture + * @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 + * @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,19 +153,19 @@ public class ScreenDrawing { * * <p>If the texture is 256x256, this draws the texture at one pixel per texel. * - * @param matrices the rendering matrix stack - * @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 - * @param height the height of the box on-screen - * @param texture the Identifier for the texture - * @param textureX the x offset into the texture - * @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 + * @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 + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param textureX the x offset into the texture + * @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,155 +173,156 @@ public class ScreenDrawing { * * <p>If the texture is 256x256, this draws the texture at one pixel per texel. * - * @param matrices the rendering matrix stack - * @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 - * @param height the height of the box on-screen - * @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 + * @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 + * @param height the height of the box on-screen + * @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 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 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 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 shadow the bottom/right shadow ARGB color - * @param panel the center ARGB color - * @param hilight the top/left hilight ARGB color - * @param outline the outline ARGB color + * @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 shadow the bottom/right shadow ARGB color + * @param panel the center ARGB color + * @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 x x coordinate of the topleft corner - * @param y y coordinate of the topleft corner - * @param width width of the panel - * @param height height of the panel - * @param topleft color of the top/left bevel - * @param panel color of the panel area - * @param bottomright color of the bottom/right bevel + * @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 + * @param height height of the panel + * @param topleft color of the top/left bevel + * @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 s the string - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param context the draw context + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @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,31 +330,32 @@ public class ScreenDrawing { /** * Draws a text component with a custom alignment. * - * @param matrices the rendering matrix stack - * @param text the text - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param context the draw context + * @param text the text + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @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,30 +363,31 @@ public class ScreenDrawing { /** * Draws a shadowed string. * - * @param matrices the rendering matrix stack - * @param s the string - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param context the draw context + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @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,30 +395,31 @@ public class ScreenDrawing { /** * Draws a shadowed text component. * - * @param matrices the rendering matrix stack - * @param text the text component - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param context the draw context + * @param text the text component + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @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 s the string - * @param x the X position - * @param y the Y position - * @param color the text color + * @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 text the text component - * @param x the X position - * @param y the Y position - * @param color the text color + * @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 { * <p>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<Identifier, MatrixStack> { +public enum NinePatchTextureRendererImpl implements ContextualTextureRenderer<Identifier, DrawContext> { 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<getWidth() && mouseY<getHeight()); int state = 1; //1=regular. 2=hovered. 0=disabled. if (!enabled) { @@ -108,11 +108,11 @@ public class WButton extends WWidget { float buttonEndLeft = (200-(getWidth()/2)) * px; Identifier texture = getTexture(this); - ScreenDrawing.texturedRect(matrices, x, y, getWidth()/2, 20, texture, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, x+(getWidth()/2), y, getWidth()/2, 20, texture, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, getWidth()/2, 20, texture, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x+(getWidth()/2), y, getWidth()/2, 20, texture, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); if (icon != null) { - icon.paint(matrices, x+ICON_SPACING, y+(BUTTON_HEIGHT-iconSize)/2, iconSize); + icon.paint(context, x+ICON_SPACING, y+(BUTTON_HEIGHT-iconSize)/2, iconSize); } if (label!=null) { @@ -124,7 +124,7 @@ public class WButton extends WWidget { }*/ int xOffset = (icon != null && alignment == HorizontalAlignment.LEFT) ? ICON_SPACING+iconSize+ICON_SPACING : 0; - ScreenDrawing.drawStringWithShadow(matrices, label.asOrderedText(), alignment, x + xOffset, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawStringWithShadow(context, label.asOrderedText(), alignment, x + xOffset, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java index a594fc2..9b08074 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.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 io.github.cottonmc.cotton.gui.client.Scissors; @@ -12,12 +12,12 @@ import io.github.cottonmc.cotton.gui.client.Scissors; public class WClippedPanel extends WPanel { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(matrices, x, y, this); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(context, x, y, this); Scissors.push(x, y, width, height); for(WWidget child : children) { - child.paint(matrices, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); + child.paint(context, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); } Scissors.pop(); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java index 0b81a59..7f0aa7e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.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 io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; @@ -37,9 +37,9 @@ public class WDynamicLabel 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) { String tr = text.get(); - ScreenDrawing.drawString(matrices, tr, alignment, x, y, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color); + ScreenDrawing.drawString(context, tr, alignment, x, y, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java index 32770c3..11d2c86 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java @@ -3,9 +3,7 @@ package io.github.cottonmc.cotton.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; @@ -59,12 +57,9 @@ public class WItem 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) { RenderSystem.enableDepthTest(); - - MinecraftClient mc = MinecraftClient.getInstance(); - ItemRenderer renderer = mc.getItemRenderer(); - renderer.renderInGui(matrices, items.get(current), x + getWidth() / 2 - 8, y + getHeight() / 2 - 8); + context.drawItemWithoutEntity(items.get(current), x + getWidth() / 2 - 8, y + getHeight() / 2 - 8); } /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index 972dbd0..3ef3684 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -3,9 +3,9 @@ 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.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; @@ -427,13 +427,13 @@ public class WItemSlot 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 (backgroundPainter != null) { - backgroundPainter.paintBackground(matrices, x, y, this); + backgroundPainter.paintBackground(context, x, y, this); } if (icon != null) { - icon.paint(matrices, x + 1, y + 1, 16); + icon.paint(context, x + 1, y + 1, 16); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index f340717..be0b1e4 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -4,10 +4,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Style; import net.minecraft.text.Text; @@ -62,7 +62,7 @@ public class WLabel 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) { MinecraftClient mc = MinecraftClient.getInstance(); TextRenderer renderer = mc.textRenderer; int yOffset = switch (verticalAlignment) { @@ -71,10 +71,10 @@ public class WLabel extends WWidget { case TOP -> 0; }; - ScreenDrawing.drawString(matrices, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color); + ScreenDrawing.drawString(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color); Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY); - ScreenDrawing.drawTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY); + ScreenDrawing.drawTextHover(context, hoveredTextStyle, x + mouseX, y + mouseY); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index 59adde7..d8cca29 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java @@ -2,9 +2,9 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +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.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.RotationAxis; @@ -160,7 +160,7 @@ public class WLabeledSlider extends WAbstractSlider { @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) { int aWidth = axis == Axis.HORIZONTAL ? width : height; int aHeight = axis == Axis.HORIZONTAL ? height : width; int rotMouseX = axis == Axis.HORIZONTAL @@ -168,13 +168,14 @@ public class WLabeledSlider extends WAbstractSlider { : (direction == Direction.UP ? height - mouseY : mouseY); int rotMouseY = axis == Axis.HORIZONTAL ? mouseY : mouseX; + var matrices = context.getMatrices(); matrices.push(); matrices.translate(x, y, 0); if (axis == Axis.VERTICAL) { matrices.translate(0, height, 0); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(270)); } - drawButton(matrices, 0, 0, 0, aWidth); + drawButton(context, 0, 0, 0, aWidth); // 1: regular, 2: hovered, 0: disabled/dragging int thumbX = Math.round(coordToValueRatio * (value - min)); @@ -184,23 +185,23 @@ public class WLabeledSlider extends WAbstractSlider { boolean hovering = rotMouseX >= thumbX && rotMouseX <= thumbX + thumbWidth && rotMouseY >= thumbY && rotMouseY <= thumbY + thumbHeight; int thumbState = dragging || hovering ? 2 : 1; - drawButton(matrices, thumbX, thumbY, thumbState, thumbWidth); + drawButton(context, thumbX, thumbY, thumbState, thumbWidth); if (thumbState == 1 && isFocused()) { float px = 1 / 32f; - ScreenDrawing.texturedRect(matrices, thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); } if (label != null) { int color = isMouseInsideBounds(mouseX, mouseY) ? 0xFFFFA0 : 0xE0E0E0; - ScreenDrawing.drawStringWithShadow(matrices, label.asOrderedText(), labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); + ScreenDrawing.drawStringWithShadow(context, label.asOrderedText(), labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); } matrices.pop(); } // state = 1: regular, 2: hovered, 0: disabled/dragging @Environment(EnvType.CLIENT) - private void drawButton(MatrixStack matrices, int x, int y, int state, int width) { + private void drawButton(DrawContext context, int x, int y, int state, int width) { float px = 1 / 256f; float buttonLeft = 0 * px; float buttonTop = (46 + (state * 20)) * px; @@ -211,8 +212,8 @@ public class WLabeledSlider extends WAbstractSlider { float buttonEndLeft = (200 - halfWidth) * px; Identifier texture = WButton.getTexture(this); - ScreenDrawing.texturedRect(matrices, x, y, halfWidth, 20, texture, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, x + halfWidth, y, halfWidth, 20, texture, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, halfWidth, 20, texture, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x + halfWidth, y, halfWidth, 20, texture, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 9cd83fd..06db362 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.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 io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.widget.data.Axis; @@ -81,13 +81,13 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { @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 (scrollBar.getValue()!=lastScroll) { layout(); lastScroll = scrollBar.getValue(); } - super.paint(matrices, x, y, mouseX, mouseY); + super.paint(context, x, y, mouseX, mouseY); /* if (getBackgroundPainter()!=null) { getBackgroundPainter().paintBackground(x, y, this); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 433ea61..5503f73 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.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 io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; @@ -138,11 +138,11 @@ public abstract class WPanel extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (backgroundPainter!=null) backgroundPainter.paintBackground(matrices, x, y, this); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + if (backgroundPainter!=null) backgroundPainter.paintBackground(context, x, y, this); for(WWidget child : children) { - child.paint(matrices, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); + child.paint(context, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index aab0db8..0846d68 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -2,9 +2,9 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +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.util.math.MatrixStack; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.impl.client.NarrationMessages; @@ -40,13 +40,13 @@ public class WScrollBar 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 darkMode = shouldRenderInDarkMode(); if (darkMode) { - ScreenDrawing.drawBeveledPanel(matrices, x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); + ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); } else { - ScreenDrawing.drawBeveledPanel(matrices, x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); + ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); } if (maxValue<=0) return; @@ -86,16 +86,16 @@ public class WScrollBar extends WWidget { } if (axis==Axis.HORIZONTAL) { - ScreenDrawing.drawBeveledPanel(matrices, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom); + ScreenDrawing.drawBeveledPanel(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom); if (isFocused()) { - drawBeveledOutline(matrices, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39); + drawBeveledOutline(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39); } } else { - ScreenDrawing.drawBeveledPanel(matrices, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom); + ScreenDrawing.drawBeveledPanel(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom); if (isFocused()) { - drawBeveledOutline(matrices, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39); + drawBeveledOutline(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39); } } } @@ -110,11 +110,11 @@ public class WScrollBar extends WWidget { return true; } - private static void drawBeveledOutline(MatrixStack matrices, int x, int y, int width, int height, int topleft, int bottomright) { - ScreenDrawing.coloredRect(matrices, x, y, width, 1, topleft); //Top shadow - ScreenDrawing.coloredRect(matrices, x, y + 1, 1, height - 1, topleft); //Left shadow - ScreenDrawing.coloredRect(matrices, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - ScreenDrawing.coloredRect(matrices, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight + private static void drawBeveledOutline(DrawContext context, int x, int y, int width, int height, int topleft, int bottomright) { + ScreenDrawing.coloredRect(context, x, y, width, 1, topleft); //Top shadow + ScreenDrawing.coloredRect(context, x, y + 1, 1, height - 1, topleft); //Left shadow + ScreenDrawing.coloredRect(context, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight + ScreenDrawing.coloredRect(context, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java index 4b33caa..facac1b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollPanel.java @@ -3,7 +3,7 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.util.TriState; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.widget.data.Axis; @@ -92,14 +92,14 @@ public class WScrollPanel extends WClippedPanel { @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 (verticalScrollBar.getValue() != lastVerticalScroll || horizontalScrollBar.getValue() != lastHorizontalScroll) { layout(); lastHorizontalScroll = horizontalScrollBar.getValue(); lastVerticalScroll = verticalScrollBar.getValue(); } - super.paint(matrices, x, y, mouseX, mouseY); + super.paint(context, x, y, mouseX, mouseY); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index f0ad49d..c4c3877 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.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.util.Identifier; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; @@ -48,9 +48,9 @@ public class WSlider extends WAbstractSlider { @SuppressWarnings("SuspiciousNameCombination") @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 (backgroundPainter != null) { - backgroundPainter.paintBackground(matrices, x, y, this); + backgroundPainter.paintBackground(context, x, y, this); } else { float px = 1 / 32f; // thumbX/Y: thumb position in widget-space @@ -67,9 +67,9 @@ public class WSlider extends WAbstractSlider { : Math.round(coordToValueRatio * (value - min)); thumbXOffset = 0; - ScreenDrawing.texturedRect(matrices, trackX, y + 1, TRACK_WIDTH, 1, texture, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, trackX, y + 2, TRACK_WIDTH, height - 2, texture, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, trackX, y + height, TRACK_WIDTH, 1, texture, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, trackX, y + 1, TRACK_WIDTH, 1, texture, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, trackX, y + 2, TRACK_WIDTH, height - 2, texture, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, trackX, y + height, TRACK_WIDTH, 1, texture, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); } else { int trackY = y + height / 2 - TRACK_WIDTH / 2; thumbX = direction == Direction.LEFT @@ -78,18 +78,18 @@ public class WSlider extends WAbstractSlider { thumbY = height / 2 - THUMB_SIZE / 2; thumbXOffset = 8; - ScreenDrawing.texturedRect(matrices, x, trackY, 1, TRACK_WIDTH, texture, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, x + 1, trackY, width - 2, TRACK_WIDTH, texture, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(matrices, x + width - 1, trackY, 1, TRACK_WIDTH, texture, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, trackY, 1, TRACK_WIDTH, texture, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x + 1, trackY, width - 2, TRACK_WIDTH, texture, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x + width - 1, trackY, 1, TRACK_WIDTH, texture, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); } // thumbState values: // 0: default, 1: dragging, 2: hovered int thumbState = dragging ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0); - ScreenDrawing.texturedRect(matrices, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); if (thumbState == 0 && isFocused()) { - ScreenDrawing.texturedRect(matrices, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java index a17ed42..97a1ab8 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.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.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -182,9 +182,9 @@ public class WSprite 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 (singleImage) { - paintFrame(matrices, x, y, frames[0]); + paintFrame(context, x, y, frames[0]); } else { //grab the system time at the very start of the frame. long now = System.nanoTime() / 1_000_000L; @@ -194,7 +194,7 @@ public class WSprite extends WWidget { if (!inBounds) currentFrame = 0; //assemble and draw the frame calculated last iteration. Texture currentFrameTex = frames[currentFrame]; - paintFrame(matrices, x, y, currentFrameTex); + paintFrame(context, x, y, currentFrameTex); //calculate how much time has elapsed since the last animation change, and change the frame if necessary. long elapsed = now - lastFrame; @@ -216,13 +216,13 @@ public class WSprite extends WWidget { /** * Paints a single frame for this sprite. * - * @param matrices the rendering matrix stack - * @param x the X coordinate to draw it at - * @param y the Y coordinate to draw it at - * @param texture the texture to draw + * @param context the draw context + * @param x the X coordinate to draw it at + * @param y the Y coordinate to draw it at + * @param texture the texture to draw */ @Environment(EnvType.CLIENT) - protected void paintFrame(MatrixStack matrices, int x, int y, Texture texture) { - ScreenDrawing.texturedRect(matrices, x, y, getWidth(), getHeight(), texture, tint); + protected void paintFrame(DrawContext context, int x, int y, Texture texture) { + ScreenDrawing.texturedRect(context, x, y, getWidth(), getHeight(), texture, tint); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java index 729c6dd..766804e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java @@ -4,10 +4,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +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.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -374,7 +374,7 @@ public class WTabPanel extends WPanel { @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) { TextRenderer renderer = MinecraftClient.getInstance().textRenderer; Text title = data.getTitle(); Icon icon = data.getIcon(); @@ -389,9 +389,9 @@ public class WTabPanel extends WPanel { } } - (selected ? Painters.SELECTED_TAB : Painters.UNSELECTED_TAB).paintBackground(matrices, x, y, this); + (selected ? Painters.SELECTED_TAB : Painters.UNSELECTED_TAB).paintBackground(context, x, y, this); if (isFocused()) { - (selected ? Painters.SELECTED_TAB_FOCUS_BORDER : Painters.UNSELECTED_TAB_FOCUS_BORDER).paintBackground(matrices, x, y, this); + (selected ? Painters.SELECTED_TAB_FOCUS_BORDER : Painters.UNSELECTED_TAB_FOCUS_BORDER).paintBackground(context, x, y, this); } int iconX = 6; @@ -409,11 +409,11 @@ public class WTabPanel extends WPanel { color = selected ? WLabel.DEFAULT_TEXT_COLOR : 0xEEEEEE; } - ScreenDrawing.drawString(matrices, title.asOrderedText(), align, x + titleX, y + titleY, width, color); + ScreenDrawing.drawString(context, title.asOrderedText(), align, x + titleX, y + titleY, width, color); } if (icon != null) { - icon.paint(matrices, x + iconX, y + (height - TAB_PADDING - ICON_SIZE) / 2, ICON_SIZE); + icon.paint(context, x + iconX, y + (height - TAB_PADDING - ICON_SIZE) / 2, ICON_SIZE); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java index a38ce74..2b4ad31 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java @@ -4,9 +4,9 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +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.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.text.Style; import net.minecraft.text.Text; @@ -85,7 +85,7 @@ public class WText 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 (wrappedLines == null || wrappingScheduled) { wrapLines(); wrappingScheduled = false; @@ -103,11 +103,11 @@ public class WText extends WWidget { OrderedText line = wrappedLines.get(i); int c = shouldRenderInDarkMode() ? darkmodeColor : color; - ScreenDrawing.drawString(matrices, line, horizontalAlignment, x, y + yOffset + i * font.fontHeight, width, c); + ScreenDrawing.drawString(context, line, horizontalAlignment, x, y + yOffset + i * font.fontHeight, width, c); } Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY); - ScreenDrawing.drawTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY); + ScreenDrawing.drawTextHover(context, hoveredTextStyle, x + mouseX, y + mouseY); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index a26fb35..94069c3 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; @@ -15,7 +16,6 @@ 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.Text; import net.minecraft.util.math.MathHelper; @@ -185,35 +185,35 @@ public class WTextField extends WWidget { } @Environment(EnvType.CLIENT) - protected void renderBox(MatrixStack matrices, int x, int y) { + protected void renderBox(DrawContext context, int x, int y) { int borderColor = this.isFocused() ? BORDER_COLOR_SELECTED : BORDER_COLOR_UNSELECTED; - ScreenDrawing.coloredRect(matrices, x - 1, y - 1, width + 2, height + 2, borderColor); - ScreenDrawing.coloredRect(matrices, x, y, width, height, BACKGROUND_COLOR); + ScreenDrawing.coloredRect(context, x - 1, y - 1, width + 2, height + 2, borderColor); + ScreenDrawing.coloredRect(context, x, y, width, height, BACKGROUND_COLOR); } @Environment(EnvType.CLIENT) - protected void renderText(MatrixStack matrices, int x, int y, String visibleText) { + protected void renderText(DrawContext context, int x, int y, String visibleText) { int textColor = this.editable ? this.enabledColor : this.disabledColor; - this.font.drawWithShadow(matrices, visibleText, x + TEXT_PADDING_X, y + TEXT_PADDING_Y, textColor); + context.drawText(font, visibleText, x + TEXT_PADDING_X, y + TEXT_PADDING_Y, textColor, true); } @Environment(EnvType.CLIENT) - protected void renderCursor(MatrixStack matrices, int x, int y, String visibleText) { + protected void renderCursor(DrawContext context, int x, int y, String visibleText) { if (this.tickCount / 6 % 2 == 0) return; if (this.cursor < this.scrollOffset) return; if (this.cursor > this.scrollOffset + visibleText.length()) return; int cursorOffset = this.font.getWidth(visibleText.substring(0, this.cursor - this.scrollOffset)); - ScreenDrawing.coloredRect(matrices, x + TEXT_PADDING_X + cursorOffset, y + CURSOR_PADDING_Y, 1, CURSOR_HEIGHT, CURSOR_COLOR); + ScreenDrawing.coloredRect(context, x + TEXT_PADDING_X + cursorOffset, y + CURSOR_PADDING_Y, 1, CURSOR_HEIGHT, CURSOR_COLOR); } @Environment(EnvType.CLIENT) - protected void renderSuggestion(MatrixStack matrices, int x, int y) { + protected void renderSuggestion(DrawContext context, int x, int y) { if (this.suggestion == null) return; - this.font.drawWithShadow(matrices, this.suggestion, x + TEXT_PADDING_X, y + TEXT_PADDING_Y, this.suggestionColor); + context.drawText(font, suggestion, x + TEXT_PADDING_X, y + TEXT_PADDING_Y, this.suggestionColor, true); } @Environment(EnvType.CLIENT) - protected void renderSelection(MatrixStack matrices, int x, int y, String visibleText) { + protected void renderSelection(DrawContext context, int x, int y, String visibleText) { if (select == cursor || select == -1) return; int textLength = visibleText.length(); @@ -229,31 +229,31 @@ public class WTextField extends WWidget { int leftCaret = font.getWidth(visibleText.substring(0, normalizedLeft)); int selectionWidth = font.getWidth(visibleText.substring(normalizedLeft, normalizedRight)); - invertedRect(matrices, x + TEXT_PADDING_X + leftCaret, y + CURSOR_PADDING_Y, selectionWidth, CURSOR_HEIGHT); + invertedRect(context, x + TEXT_PADDING_X + leftCaret, y + CURSOR_PADDING_Y, selectionWidth, CURSOR_HEIGHT); } @Environment(EnvType.CLIENT) - protected void renderTextField(MatrixStack matrices, int x, int y) { + protected void renderTextField(DrawContext context, int x, int y) { if (this.font == null) this.font = MinecraftClient.getInstance().textRenderer; checkScrollOffset(); String visibleText = font.trimToWidth(this.text.substring(this.scrollOffset), this.width - 2 * TEXT_PADDING_X); - renderBox(matrices, x, y); - renderText(matrices, x, y, visibleText); + renderBox(context, x, y); + renderText(context, x, y, visibleText); if (this.text.isEmpty() && !this.isFocused()) { - renderSuggestion(matrices, x, y); + renderSuggestion(context, x, y); } if (this.isFocused()) { - renderCursor(matrices, x, y, visibleText); + renderCursor(context, x, y, visibleText); } - renderSelection(matrices, x, y, visibleText); + renderSelection(context, x, y, visibleText); } @Environment(EnvType.CLIENT) - private void invertedRect(MatrixStack matrices, int x, int y, int width, int height) { + private void invertedRect(DrawContext context, int x, int y, int width, int height) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); - Matrix4f model = matrices.peek().getPositionMatrix(); + Matrix4f model = context.getMatrices().peek().getPositionMatrix(); RenderSystem.setShaderColor(0.0F, 0.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionProgram); RenderSystem.enableColorLogicOp(); @@ -332,8 +332,8 @@ public class WTextField extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - renderTextField(matrices, x, y); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + renderTextField(context, x, y); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java index 0ab9d7c..76e7295 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.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.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -130,14 +130,14 @@ public class WTiledSprite extends WSprite { @Environment(EnvType.CLIENT) @Override - public void paintFrame(MatrixStack matrices, int x, int y, Texture texture) { + public void paintFrame(DrawContext context, int x, int y, Texture texture) { // Y Direction (down) for (int tileYOffset = 0; tileYOffset < height; tileYOffset += tileHeight) { // X Direction (right) for (int tileXOffset = 0; tileXOffset < width; tileXOffset += tileWidth) { // draw the texture ScreenDrawing.texturedRect( - matrices, + context, // at the correct position using tileXOffset and tileYOffset x + tileXOffset, y + tileYOffset, // but using the set tileWidth and tileHeight instead of the full height and diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index 3ad8cd6..c996219 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -3,10 +3,10 @@ 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.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -104,14 +104,14 @@ public class WToggleButton extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.texturedRect(matrices, x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + ScreenDrawing.texturedRect(context, x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); if (isFocused()) { - ScreenDrawing.texturedRect(matrices, x, y, 18, 18, focusImage, 0xFFFFFFFF); + ScreenDrawing.texturedRect(context, x, y, 18, 18, focusImage, 0xFFFFFFFF); } if (label!=null) { - ScreenDrawing.drawString(matrices, label.asOrderedText(), x + 22, y+6, shouldRenderInDarkMode() ? darkmodeColor : color); + ScreenDrawing.drawString(context, label.asOrderedText(), x + 22, y+6, shouldRenderInDarkMode() ? darkmodeColor : color); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index f008310..1486928 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -3,9 +3,9 @@ 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.screen.Screen; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.tooltip.HoveredTooltipPositioner; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.client.LibGui; @@ -319,15 +319,15 @@ public class WWidget { /** * Paints this widget. * - * @param matrices the rendering matrix stack - * @param x this widget's X coordinate on the screen - * @param y this widget's Y coordinate on the screen - * @param mouseX the X coordinate of the cursor - * @param mouseY the X coordinate of the cursor + * @param context the draw context + * @param x this widget's X coordinate on the screen + * @param y this widget's Y coordinate on the screen + * @param mouseX the X coordinate of the cursor + * @param mouseY the X coordinate of the cursor * @since 2.0.0 */ @Environment(EnvType.CLIENT) - 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) { } /** @@ -347,20 +347,21 @@ public class WWidget { * Internal method to render tooltip data. This requires an overridden {@link #addTooltip(TooltipBuilder) * addTooltip} method to insert data into the tooltip - without this, the method returns early because of no work. * - * @param x the X coordinate of this widget on screen - * @param y the Y coordinate of this widget on screen - * @param tX the X coordinate of the tooltip - * @param tY the Y coordinate of the tooltip + * @param context the draw context + * @param x the X coordinate of this widget on screen + * @param y the Y coordinate of this widget on screen + * @param tX the X coordinate of the tooltip + * @param tY the Y coordinate of the tooltip */ @Environment(EnvType.CLIENT) - public void renderTooltip(MatrixStack matrices, int x, int y, int tX, int tY) { + public void renderTooltip(DrawContext context, int x, int y, int tX, int tY) { TooltipBuilder builder = new TooltipBuilder(); addTooltip(builder); if (builder.size() == 0) return; - Screen screen = MinecraftClient.getInstance().currentScreen; - screen.renderOrderedTooltip(matrices, builder.lines, tX+x, tY+y); + var client = MinecraftClient.getInstance(); + context.drawTooltip(client.textRenderer, builder.lines, HoveredTooltipPositioner.INSTANCE, tX + x, tY + y); } /** @@ -498,7 +499,7 @@ public class WWidget { * * <p>Hovering is used by LibGui itself mostly for narration support. * For rendering, it might be preferable that you check the mouse coordinates in - * {@link #paint(MatrixStack, int, int, int, int) paint()} directly. + * {@link #paint(DrawContext, int, int, int, int) paint()} directly. * That lets you react to different parts of the widget being hovered over. * * @return the {@code hovered} property diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/Icon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/Icon.java index ccf1bcc..3075814 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/Icon.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/Icon.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.widget.icon; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; /** * A square icon for a widget such as a button. @@ -15,11 +15,11 @@ public interface Icon { /** * Paints this icon. * - * @param matrices the GUI matrix stack - * @param x the X coordinate - * @param y the Y coordinate - * @param size the size of this icon in pixels (size N means a N*N square) + * @param context the draw context + * @param x the X coordinate + * @param y the Y coordinate + * @param size the size of this icon in pixels (size N means a N*N square) */ @Environment(EnvType.CLIENT) - void paint(MatrixStack matrices, int x, int y, int size); + void paint(DrawContext context, int x, int y, int size); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java index f979b44..9da86ee 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java @@ -2,8 +2,7 @@ package io.github.cottonmc.cotton.gui.widget.icon; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -41,15 +40,13 @@ public class ItemIcon implements Icon { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int size) { - MinecraftClient client = MinecraftClient.getInstance(); - ItemRenderer renderer = client.getItemRenderer(); + public void paint(DrawContext context, int x, int y, int size) { float scale = size != 16 ? ((float) size / 16f) : 1f; - + MatrixStack matrices = context.getMatrices(); matrices.push(); matrices.translate(x, y, 0); matrices.scale(scale, scale, 1); - renderer.renderInGui(matrices, stack, 0, 0); + context.drawItemWithoutEntity(stack, 0, 0); matrices.pop(); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java index acc3ce5..c822d88 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java @@ -2,7 +2,7 @@ package io.github.cottonmc.cotton.gui.widget.icon; 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; @@ -79,7 +79,7 @@ public class TextureIcon implements Icon { @Environment(EnvType.CLIENT) @Override - public void paint(MatrixStack matrices, int x, int y, int size) { - ScreenDrawing.texturedRect(matrices, x, y, size, size, texture, color, opacity); + public void paint(DrawContext context, int x, int y, int size) { + ScreenDrawing.texturedRect(context, x, y, size, size, texture, color, opacity); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f127656..646abd4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,12 +25,12 @@ "mixins": ["mixins.libgui.json"], "depends": { "java": ">=17", - "fabricloader": ">=0.14.17", + "fabricloader": ">=0.14.21", "fabric-api-base": ">=0.4.4", "fabric-lifecycle-events-v1": "^2.0.2", "fabric-networking-api-v1": "^1.0.21", - "fabric-rendering-v1": "^2.1.0", - "minecraft": ">=1.19.4", + "fabric-rendering-v1": "^3.0.6", + "minecraft": ">=1.20-rc.1", "jankson": "^5.0.1", "libninepatch": "^1.2.0" }, diff --git a/src/testMod/java/io/github/cottonmc/test/TestItemDescription.java b/src/testMod/java/io/github/cottonmc/test/TestItemDescription.java index 4c9c1f0..45be514 100644 --- a/src/testMod/java/io/github/cottonmc/test/TestItemDescription.java +++ b/src/testMod/java/io/github/cottonmc/test/TestItemDescription.java @@ -2,7 +2,7 @@ package io.github.cottonmc.test; 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.entity.player.PlayerInventory; import net.minecraft.inventory.StackReference; import net.minecraft.text.Text; @@ -149,8 +149,8 @@ public class TestItemDescription extends ItemSyncedGuiDescription { } @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(matrices, x, y, this.getWidth(), this.getHeight(), color); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + ScreenDrawing.coloredRect(context, x, y, this.getWidth(), this.getHeight(), color); } } } diff --git a/src/testMod/java/io/github/cottonmc/test/client/TestClientGui.java b/src/testMod/java/io/github/cottonmc/test/client/TestClientGui.java index 839072e..7bc7ffb 100644 --- a/src/testMod/java/io/github/cottonmc/test/client/TestClientGui.java +++ b/src/testMod/java/io/github/cottonmc/test/client/TestClientGui.java @@ -2,7 +2,7 @@ package io.github.cottonmc.test.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.text.Text; import net.minecraft.util.Identifier; @@ -149,8 +149,8 @@ public class TestClientGui extends LightweightGuiDescription { } @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(matrices, x, y, this.getWidth(), this.getHeight(), color); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + ScreenDrawing.coloredRect(context, x, y, this.getWidth(), this.getHeight(), color); } } } diff --git a/src/testMod/java/io/github/cottonmc/test/client/WHudTest.java b/src/testMod/java/io/github/cottonmc/test/client/WHudTest.java index 98f4d0f..2f07c3a 100644 --- a/src/testMod/java/io/github/cottonmc/test/client/WHudTest.java +++ b/src/testMod/java/io/github/cottonmc/test/client/WHudTest.java @@ -2,7 +2,7 @@ package io.github.cottonmc.test.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 io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.WWidget; @@ -14,8 +14,8 @@ public class WHudTest extends WWidget { private static final Logger LOGGER = LogManager.getLogger(); @Override - public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF_00FF00); + public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { + ScreenDrawing.coloredRect(context, x, y, width, height, 0xFF_00FF00); } @Override |