diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/Tooltip.java b/common/src/main/java/org/thinkingstudio/obsidianui/Tooltip.java index f716e692..b3fb75eb 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/Tooltip.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/Tooltip.java @@ -89,7 +89,7 @@ public boolean shouldRender() { * @param drawContext The GuiGraphics instance used to render. */ public void render(DrawContext drawContext) { - drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.tooltip, HoveredTooltipPositioner.INSTANCE, this.x, this.y); + drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.tooltip, HoveredTooltipPositioner.INSTANCE, this.x, this.y, true); } /** diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java b/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java index e314d9a0..38938f96 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java @@ -10,11 +10,7 @@ package org.thinkingstudio.obsidianui.border; -import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.*; -import net.minecraft.util.math.ColorHelper; -import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; import org.thinkingstudio.obsidianui.util.ColorUtil; import org.thinkingstudio.obsidianui.widget.SpruceWidget; @@ -31,8 +27,8 @@ public final class SimpleBorder implements Border { public static final SimpleBorder SIMPLE_BORDER = new SimpleBorder(1, 192, 192, 192, 255); private final int thickness; - private final int[] color; - private final int[] focusedColor; + private final int color; + private final int focusedColor; public SimpleBorder(int thickness, int color) { this(thickness, color, color); @@ -40,8 +36,8 @@ public SimpleBorder(int thickness, int color) { public SimpleBorder(int thickness, int color, int focusedColor) { this.thickness = thickness; - this.color = ColorUtil.unpackARGBColor(color); - this.focusedColor = ColorUtil.unpackARGBColor(focusedColor); + this.color = color; + this.focusedColor = focusedColor; } public SimpleBorder(int thickness, int red, int green, int blue, int alpha) { @@ -50,46 +46,26 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha) { public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int focusedRed, int focusedGreen, int focusedBlue, int focusedAlpha) { this.thickness = thickness; - this.color = new int[]{red, green, blue, alpha}; - this.focusedColor = new int[]{focusedRed, focusedGreen, focusedBlue, focusedAlpha}; + this.color = ColorUtil.packARGBColor(red, green, blue, alpha); + this.focusedColor = ColorUtil.packARGBColor(focusedRed, focusedGreen, focusedBlue, focusedAlpha); } @Override - public void render(DrawContext drawContext, SpruceWidget widget, int mouseX, int mouseY, float delta) { - RenderLayer renderLayer = RenderLayer.getGui(); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); + public void render(DrawContext context, SpruceWidget widget, int mouseX, int mouseY, float delta) { int x = widget.getX(); int y = widget.getY(); int right = x + widget.getWidth(); int bottom = y + widget.getHeight(); boolean focused = widget.isFocused(); + int color = focused ? this.focusedColor : this.color; // Top border - this.vertex(vertexConsumer, x, y + this.thickness, focused); - this.vertex(vertexConsumer, right, y + this.thickness, focused); - this.vertex(vertexConsumer, right, y, focused); - this.vertex(vertexConsumer, x, y, focused); + context.fill(x, y, right, y + thickness, color); // Right border - this.vertex(vertexConsumer, right - this.thickness, bottom, focused); - this.vertex(vertexConsumer, right, bottom, focused); - this.vertex(vertexConsumer, right, y, focused); - this.vertex(vertexConsumer, right - this.thickness, y, focused); + context.fill(right - thickness, y, right, bottom, color); // Bottom - this.vertex(vertexConsumer, x, bottom, focused); - this.vertex(vertexConsumer, right, bottom, focused); - this.vertex(vertexConsumer, right, bottom - this.thickness, focused); - this.vertex(vertexConsumer, x, bottom - this.thickness, focused); + context.fill(x, bottom - thickness, right, bottom, color); // Left border - this.vertex(vertexConsumer, x, bottom, focused); - this.vertex(vertexConsumer, x + this.thickness, bottom, focused); - this.vertex(vertexConsumer, x + this.thickness, y, focused); - this.vertex(vertexConsumer, x, y, focused); - drawContext.draw(); - - } - - private void vertex(VertexConsumer consumer, int x, int y, boolean focused) { - int[] color = focused ? this.focusedColor : this.color; - consumer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]); + context.fill(x, y, x + thickness, bottom, color); } @Override @@ -101,8 +77,8 @@ public int getThickness() { public String toString() { return "SimpleBorder{" + "thickness=" + this.thickness + - ", color=" + Arrays.toString(this.color) + - ", focusedColor=" + Arrays.toString(this.focusedColor) + + ", color=" + Arrays.toString(ColorUtil.unpackARGBColor(this.color)) + + ", focusedColor=" + Arrays.toString(ColorUtil.unpackARGBColor(this.focusedColor)) + '}'; } } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java b/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java deleted file mode 100644 index e0ae50f0..00000000 --- a/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.thinkingstudio.obsidianui.mixin; - -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.VertexConsumerProvider; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(DrawContext.class) -public interface DrawContextAccessor { - @Accessor("vertexConsumers") - VertexConsumerProvider.Immediate getVertexConsumers(); -} diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/screen/SpruceScreen.java b/common/src/main/java/org/thinkingstudio/obsidianui/screen/SpruceScreen.java index df8dcb9a..957b025a 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/screen/SpruceScreen.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/screen/SpruceScreen.java @@ -109,7 +109,6 @@ private boolean tryNavigating(Element element, NavigationDirection direction, bo @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - this.renderBackground(drawContext, mouseX, mouseY, delta); this.renderWidgets(drawContext, mouseX, mouseY, delta); this.renderTitle(drawContext, mouseX, mouseY, delta); Tooltip.renderAll(drawContext); diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java b/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java index df70bbc9..2a1539b5 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java @@ -10,14 +10,11 @@ package org.thinkingstudio.obsidianui.util; -import com.mojang.blaze3d.opengl.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.*; import net.minecraft.util.Identifier; import net.minecraft.util.math.ColorHelper; -import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; public final class RenderUtil { /** @@ -50,7 +47,7 @@ public static void renderTransparentBackgroundTexture(DrawContext drawContext, i /** * Renders the vanilla's transparent background texture. * - * @param drawContext the current draw context + * @param context the current draw context * @param x the X-coordinate * @param y the Y-coordinate * @param width the width @@ -61,29 +58,12 @@ public static void renderTransparentBackgroundTexture(DrawContext drawContext, i * @param blue the blue-component color value * @param alpha the alpha-component alpha value */ - public static void renderTransparentBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset, + public static void renderTransparentBackgroundTexture(DrawContext context, int x, int y, int width, int height, float vOffset, int red, int green, int blue, int alpha) { - RenderLayer renderLayer = RenderLayer.getGuiTextured(getListBackgroundTexture()); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); - int right = x + width; int bottom = y + height; - GlStateManager._enableBlend(); - vertexConsumer.vertex(x, bottom, 0) - .texture(0, bottom / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(right, bottom, 0) - .texture(right / 32.f, bottom / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(right, y, 0) - .texture(right / 32.f, y / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(x, y, 0) - .texture(0, y / 32.f + vOffset) - .color(red, green, blue, alpha); - drawContext.draw(); - GlStateManager._disableBlend(); + context.drawTexture(RenderPipelines.GUI_TEXTURED, getListBackgroundTexture(), x, y, x, y, width, height, (int) (right / 32.f), (int) (bottom / 32.f + vOffset), ColorUtil.packARGBColor(red, green, blue, alpha)); } public static Identifier getListBackgroundTexture() { return client.world == null ? MENU_LIST_BACKGROUND_TEXTURE : INWORLD_MENU_LIST_BACKGROUND_TEXTURE; @@ -108,7 +88,7 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i /** * Renders the dirt background texture. * - * @param drawContext the current draw context + * @param context the current draw context * @param x the X-coordinate * @param y the Y-coordinate * @param width the width @@ -120,33 +100,18 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i * @param alpha the alpha-component alpha value */ @Deprecated(since = "1.20.5") - public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset, + public static void renderDirtBackgroundTexture(DrawContext context, int x, int y, int width, int height, float vOffset, int red, int green, int blue, int alpha) { - RenderLayer renderLayer = RenderLayer.getGuiTextured(DIRT_BACKGROUND_TEXTURE); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); - int right = x + width; int bottom = y + height; - vertexConsumer.vertex(x, bottom, 0) - .texture(0, bottom / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(right, bottom, 0) - .texture(right / 32.f, bottom / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(right, y, 0) - .texture(right / 32.f, y / 32.f + vOffset) - .color(red, green, blue, alpha); - vertexConsumer.vertex(x, y, 0) - .texture(0, y / 32.f + vOffset) - .color(red, green, blue, alpha); - drawContext.draw(); + context.drawTexture(RenderPipelines.GUI_TEXTURED, DIRT_BACKGROUND_TEXTURE, x, y, x, y, width, height, (int) (right / 32.f), (int) (bottom / 32.f + vOffset), ColorUtil.packARGBColor(red, green, blue, alpha)); } /** * Renders a selection box as background. * - * @param drawContext the current draw context + * @param context the current draw context * @param x the X-coordinate of the selection box * @param y the Y-coordinate of the selection box * @param width the width of the selection box @@ -156,22 +121,13 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i * @param blue the blue-component color value of the outer border * @param alpha the alpha-component color value of the outer border */ - public static void renderSelectionBox(DrawContext drawContext, int x, int y, int width, int height, int red, int green, int blue, int alpha) { + public static void renderSelectionBox(DrawContext context, int x, int y, int width, int height, int red, int green, int blue, int alpha) { int top = y + height; int right = x + width; - RenderLayer renderLayer = RenderLayer.getGui(); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); int argb = ColorHelper.getArgb(alpha, red, green, blue); - vertexConsumer.vertex(x, top, 0).color(argb); - vertexConsumer.vertex(right, top, 0).color(argb); - vertexConsumer.vertex(right, y, 0).color(argb); - vertexConsumer.vertex(x, y, 0).color(argb); + context.fill(x, top, right, y, argb); int dark = ColorHelper.getArgb(0, 0, 0); - vertexConsumer.vertex(x + 1, top - 1, 0).color(dark); - vertexConsumer.vertex(right - 1, top - 1, 0).color(dark); - vertexConsumer.vertex(right - 1, y + 1, 0).color(dark); - vertexConsumer.vertex(x + 1, y + 1, 0).color(dark); - drawContext.draw(); + context.fill(x, top, right, y, dark); } } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java index 53a51c2d..7f5dd70d 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java @@ -11,6 +11,7 @@ package org.thinkingstudio.obsidianui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ButtonTextures; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; @@ -18,12 +19,14 @@ import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; import org.thinkingstudio.obsidianui.Position; import org.thinkingstudio.obsidianui.Tooltip; import org.thinkingstudio.obsidianui.Tooltipable; +import org.thinkingstudio.obsidianui.util.ColorUtil; import org.thinkingstudio.obsidianui.wrapper.VanillaButtonWrapper; import java.util.Optional; @@ -162,8 +165,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo @Override protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha()); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight()); + drawContext.drawGuiTexture(RenderPipelines.GUI_TEXTURED, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight(), ColorHelper.fromFloats(this.getAlpha(), 1.f, 1.f, 1.f)); } /* Narration */ diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java index edac5b11..2e76b20c 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java @@ -12,6 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.text.OrderedText; @@ -21,6 +22,7 @@ import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.MathHelper; import org.thinkingstudio.obsidianui.Position; +import org.thinkingstudio.obsidianui.util.ColorUtil; /** * Represents a checkbox widget. @@ -90,21 +92,16 @@ public void setColored(boolean colored) { @Override protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) { - float[] oldColor = RenderSystem.getShaderColor(); - float oldRed = oldColor[0], oldGreen = oldColor[1], oldBlue = oldColor[2], oldAlpha = oldColor[3]; - if (this.getValue()) { + int color = ColorUtil.WHITE; if (this.colored) - RenderSystem.setShaderColor(0.f, 1.f, 0.f, this.alpha); - drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64); + color = ColorHelper.fromFloats(this.alpha, 0.f, 1.f, 0.f); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64, color); } else if (this.showCross) { + int color = ColorUtil.WHITE; if (this.colored) - RenderSystem.setShaderColor(1.f, 0.f, 0.f, this.alpha); - drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64); - } - - if (this.colored) { - RenderSystem.setShaderColor(oldRed, oldGreen, oldBlue, oldAlpha); + color = ColorHelper.fromFloats(this.alpha, 1.f, 0.f, 0.f); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64, color); } if (this.showMessage) { @@ -117,7 +114,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo @Override protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) { int color = ColorHelper.fromFloats(this.alpha, 1.f, 1.f, 1.f); - drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64, color); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64, color); } /* Narration */ diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceLabelWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceLabelWidget.java index 96af9af1..372196f0 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceLabelWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceLabelWidget.java @@ -176,7 +176,7 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo var line = it.next(); int x = this.centered ? (this.getInnerX() + this.maxWidth / 2) - this.client.textRenderer.getWidth(line) / 2 : this.getInnerX(); - drawContext.drawText(this.client.textRenderer, line, x, y, 10526880, true); + drawContext.drawText(this.client.textRenderer, line, x, y, 0xffffffff, true); } this.getBorder().render(drawContext, this, mouseX, mouseY, delta); diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java index b518f431..54741188 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java @@ -11,10 +11,12 @@ package org.thinkingstudio.obsidianui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.MathHelper; import org.thinkingstudio.obsidianui.Position; import org.thinkingstudio.obsidianui.Tooltipable; @@ -172,10 +174,8 @@ protected Identifier getTexture() { @Override protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); - final Identifier texture = this.isFocusedOrHovered() ? SLIDER_HANDLE_HIGHLIGHTED : SLIDER_HANDLE; - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20); + drawContext.drawGuiTexture(RenderPipelines.GUI_TEXTURED, texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20); if (!this.isMouseHovered() && this.inUse) { this.inUse = false; diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java index b7deb3d0..95350b17 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java @@ -11,10 +11,12 @@ package org.thinkingstudio.obsidianui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.math.ColorHelper; import org.thinkingstudio.obsidianui.Position; /** @@ -75,12 +77,12 @@ protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, v += this.hoveredVOffset; } - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha()); - drawContext.drawTexture(RenderLayer::getGuiTextured, this.texture, + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, this.texture, this.getX(), this.getY(), this.u, v, this.getWidth(), this.getHeight(), - this.textureWidth, this.textureHeight + this.textureWidth, this.textureHeight, + ColorHelper.fromFloats(this.getAlpha(), 1.f, 1.f, 1.f) ); } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java index 8efea734..e2d96472 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java @@ -11,11 +11,13 @@ package org.thinkingstudio.obsidianui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.Language; +import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.thinkingstudio.obsidianui.Position; @@ -54,7 +56,7 @@ public SpruceToggleSwitch(Position position, int width, int height, Text message @Override protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) { - drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX() + (this.getValue() ? 14 : 0), this.getY() + (this.getHeight() / 2 - 9), + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX() + (this.getValue() ? 14 : 0), this.getY() + (this.getHeight() / 2 - 9), this.getValue() ? 50.f : 32.f, this.isFocusedOrHovered() ? 18.f : 0.f, 18, 18, 68, 36); @@ -69,9 +71,8 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo @Override protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.alpha); - drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY() + (this.getHeight() / 2 - 9), - 0.f, this.isFocusedOrHovered() ? 18.f : 0.f, 32, 18, 68, 36); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY() + (this.getHeight() / 2 - 9), + 0.f, this.isFocusedOrHovered() ? 18.f : 0.f, 32, 18, 68, 36, ColorHelper.fromFloats(this.getAlpha(), 1.f, 1.f, 1.f)); } /* Narration */ diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/SpruceEntryListWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/SpruceEntryListWidget.java index 527c24f2..add78577 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/SpruceEntryListWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/SpruceEntryListWidget.java @@ -13,10 +13,10 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.gl.RenderPipelines; 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.render.*; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -27,8 +27,8 @@ import org.thinkingstudio.obsidianui.background.TransparentBackground; import org.thinkingstudio.obsidianui.border.Border; import org.thinkingstudio.obsidianui.border.EmptyBorder; -import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; import org.thinkingstudio.obsidianui.navigation.NavigationDirection; +import org.thinkingstudio.obsidianui.util.ColorUtil; import org.thinkingstudio.obsidianui.widget.AbstractSpruceWidget; import org.thinkingstudio.obsidianui.widget.WithBackground; import org.thinkingstudio.obsidianui.widget.WithBorder; @@ -352,12 +352,12 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo Identifier topTexture = getSeparatorTexture(true); Identifier bottomTexture = getSeparatorTexture(false); - drawContext.drawTexture(RenderLayer::getGuiTextured, topTexture, left, top - 2, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); - drawContext.drawTexture(RenderLayer::getGuiTextured, bottomTexture, left, bottom, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, topTexture, left, top - 2, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); + drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, bottomTexture, left, bottom, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); // The following code is absolutely cursed, but works surprisingly well to create side borders int screenWidth = client.getWindow().getScaledWidth(); - if (left > 0) drawContext.drawTexture(RenderLayer::getGuiTextured, topTexture, left-1, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); - if (right < screenWidth) drawContext.drawTexture(RenderLayer::getGuiTextured, topTexture, right, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); + if (left > 0) drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, topTexture, left-1, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); + if (right < screenWidth) drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, topTexture, right, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); } // Scrollbar @@ -376,23 +376,10 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo this.getBorder().render(drawContext, this, mouseX, mouseY, delta); } - protected void renderScrollbar(DrawContext drawContext, int scrollbarX, int scrollbarEndX, int scrollbarY, int scrollbarHeight) { - RenderLayer renderLayer = RenderLayer.getGui(); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); - - vertexConsumer.vertex(scrollbarX, this.getY() + this.getHeight(), 0).color(0, 0, 0, 255); - vertexConsumer.vertex(scrollbarEndX, this.getY() + this.getHeight(), 0).color(0, 0, 0, 255); - vertexConsumer.vertex(scrollbarEndX, this.getY(), 0).color(0, 0, 0, 255); - vertexConsumer.vertex(scrollbarX, this.getY(), 0).color(0, 0, 0, 255); - vertexConsumer.vertex(scrollbarX, scrollbarY + scrollbarHeight, 0).color(128, 128, 128, 255); - vertexConsumer.vertex(scrollbarEndX, scrollbarY + scrollbarHeight, 0).color(128, 128, 128, 255); - vertexConsumer.vertex(scrollbarEndX, scrollbarY, 0).color(128, 128, 128, 255); - vertexConsumer.vertex(scrollbarX, scrollbarY, 0).color(128, 128, 128, 255); - vertexConsumer.vertex(scrollbarX, scrollbarY + scrollbarHeight - 1, 0).color(192, 192, 192, 255); - vertexConsumer.vertex(scrollbarEndX - 1, scrollbarY + scrollbarHeight - 1, 0).color(192, 192, 192, 255); - vertexConsumer.vertex(scrollbarEndX - 1, scrollbarY, 0).color(192, 192, 192, 255); - vertexConsumer.vertex(scrollbarX, scrollbarY, 0).color(192, 192, 192, 255); - drawContext.draw(); + protected void renderScrollbar(DrawContext context, int scrollbarX, int scrollbarEndX, int scrollbarY, int scrollbarHeight) { + context.fill(scrollbarX, this.getY(), scrollbarEndX, this.getY() + this.getHeight(), ColorUtil.packARGBColor(0, 0, 0, 255)); + context.fill(scrollbarX, this.getY(), scrollbarEndX, scrollbarY + scrollbarHeight, ColorUtil.packARGBColor(128, 128, 128, 255)); + context.fill(scrollbarX, this.getY(), scrollbarEndX - 1, scrollbarY + scrollbarHeight - 1, ColorUtil.packARGBColor(192, 192, 192, 255)); } /* Narration */ diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/tabbed/SpruceTabbedWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/tabbed/SpruceTabbedWidget.java index bb4d9b1b..748dae53 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/tabbed/SpruceTabbedWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/container/tabbed/SpruceTabbedWidget.java @@ -257,13 +257,13 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo int y = this.getY() + 4; for (var it = this.title.iterator(); it.hasNext(); y += 9) { var line = it.next(); - drawContext.drawText(this.client.textRenderer, line, this.getX() + 4, y, 0xffffff, false); + drawContext.drawText(this.client.textRenderer, line, this.getX() + 4, y, 0xffffffff, true); } if (this.description != null) { y += 4; for (var it = this.description.iterator(); it.hasNext(); y += 9) { var line = it.next(); - drawContext.drawText(this.client.textRenderer, line, this.getX() + 8, y, 0xffffff, false); + drawContext.drawText(this.client.textRenderer, line, this.getX() + 8, y, 0xffffffff, false); } } } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextAreaWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextAreaWidget.java index 98289661..f1e3f622 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextAreaWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextAreaWidget.java @@ -14,7 +14,6 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.*; import net.minecraft.text.Text; import net.minecraft.util.StringHelper; import net.minecraft.util.math.ColorHelper; @@ -23,7 +22,6 @@ import org.lwjgl.glfw.GLFW; import org.thinkingstudio.obsidianui.Position; import org.thinkingstudio.obsidianui.border.Border; -import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; import org.thinkingstudio.obsidianui.navigation.NavigationDirection; import org.thinkingstudio.obsidianui.util.ColorUtil; import org.thinkingstudio.obsidianui.util.MultilineText; @@ -468,8 +466,8 @@ protected void drawText(DrawContext drawContext) { continue; if (line.endsWith("\n")) line = line.substring(0, line.length() - 1); - drawContext.drawTextWithShadow(this.textRenderer, Text.literal(line), textX, lineY, textColor); this.drawSelection(drawContext, line, lineY, row); + drawContext.drawTextWithShadow(this.textRenderer, Text.literal(line), textX, lineY, textColor); lineY += this.textRenderer.fontHeight; } @@ -478,12 +476,12 @@ protected void drawText(DrawContext drawContext) { /** * Draws the selection over the text. * - * @param drawContext the GUI graphics instance to render with + * @param context the GUI graphics instance to render with * @param line the current line * @param lineY the line Y-coordinates * @param row the row number */ - protected void drawSelection(DrawContext drawContext, String line, int lineY, int row) { + protected void drawSelection(DrawContext context, String line, int lineY, int row) { if (!this.isFocused()) return; if (!this.selection.isRowSelected(row)) @@ -509,14 +507,8 @@ protected void drawSelection(DrawContext drawContext, String line, int lineY, in int x2 = x + this.textRenderer.getWidth(selected); int y2 = lineY + this.textRenderer.fontHeight; - RenderLayer renderLayer = RenderLayer.getGui(); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); int color = ColorHelper.fromFloats(1.f, 0.f, 0.f, 1.f); - vertexConsumer.vertex(x, y2, 0).color(color); - vertexConsumer.vertex(x2, y2, 0).color(color); - vertexConsumer.vertex(x2, lineY, 0).color(color); - vertexConsumer.vertex(x, lineY, 0).color(color); - drawContext.draw(); + context.fill(x, lineY, x2, y2, color); } /** diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextFieldWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextFieldWidget.java index 7ab327e6..f932464f 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextFieldWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/text/SpruceTextFieldWidget.java @@ -15,7 +15,6 @@ 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.render.*; import net.minecraft.text.OrderedText; import net.minecraft.text.Style; import net.minecraft.text.Text; @@ -28,7 +27,6 @@ import org.thinkingstudio.obsidianui.Position; import org.thinkingstudio.obsidianui.Tooltip; import org.thinkingstudio.obsidianui.Tooltipable; -import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; import org.thinkingstudio.obsidianui.navigation.NavigationDirection; import org.thinkingstudio.obsidianui.util.ColorUtil; @@ -438,19 +436,19 @@ protected void drawText(DrawContext drawContext) { var displayedText = this.client.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); + this.drawSelection(drawContext, displayedText, y); drawContext.drawTextWithShadow(this.client.textRenderer, this.renderTextProvider.apply(displayedText, this.firstCharacterIndex), x, y, textColor); - this.drawSelection(drawContext, displayedText, y); } /** * Draws the selection over the text. * - * @param drawContext the current draw context + * @param context the current draw context * @param line the current line * @param lineY the line Y-coordinates */ - protected void drawSelection(DrawContext drawContext, String line, int lineY) { + protected void drawSelection(DrawContext context, String line, int lineY) { if (!this.isFocused() || !this.selection.active) return; @@ -466,14 +464,8 @@ protected void drawSelection(DrawContext drawContext, String line, int lineY) { int x2 = x + this.client.textRenderer.getWidth(selected); int y2 = lineY + this.client.textRenderer.fontHeight; - RenderLayer renderLayer = RenderLayer.getGui(); - VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); int color = ColorHelper.fromFloats(255.f, 0.f, 0.f, 255.f); - vertexConsumer.vertex(x, y2, 0).color(color); - vertexConsumer.vertex(x2, y2, 0).color(color); - vertexConsumer.vertex(x2, lineY, 0).color(color); - vertexConsumer.vertex(x, lineY, 0).color(color); - drawContext.draw(); + context.fill(x, lineY, x2, y2, color); } /** diff --git a/common/src/main/resources/obsidianui.mixins.json b/common/src/main/resources/obsidianui.mixins.json deleted file mode 100644 index 2d881c54..00000000 --- a/common/src/main/resources/obsidianui.mixins.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required": true, - "package": "org.thinkingstudio.obsidianui.mixin", - "compatibilityLevel": "JAVA_21", - "client": [ - "DrawContextAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 71817604..911124c4 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -20,7 +20,6 @@ ] }, "mixins": [ - "obsidianui.mixins.json", "obsidianui.fabric.mixins.json" ], "depends": { diff --git a/gradle.properties b/gradle.properties index c5d759b9..8adf0c01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.jvmargs=-Xmx2G -minecraft_version=1.21.5 +minecraft_version=1.21.6 enabled_platforms=fabric,neoforge -yarn_mappings=1.21.5+build.1 +yarn_mappings=1.21.6+build.1 mappings_patch=1.21+build.4 archives_base_name=ObsidianUI mod_version=0.2.12 maven_group=org.thinkingstudio.obsidianui -fabric_loader_version=0.16.10 -fabric_api_version=0.119.5+1.21.5 +fabric_loader_version=0.16.14 +fabric_api_version=0.127.0+1.21.6 -neoforge_version=21.5.2-beta +neoforge_version=21.6.0-beta modrinth_id=E0L8mfJZ curseforge_id=684718 diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 83886ea4..d39f7e90 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -16,9 +16,6 @@ Just a GUI library. ''' logoFile = "icon.png" -[[mixins]] -config = "obsidianui.mixins.json" - [[mixins]] config = "obsidianui.neoforge.mixins.json"