diff --git a/build.gradle b/build.gradle index a406796..4834215 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false id "com.github.johnrengelman.shadow" version "8.+" apply false id "com.hypherionmc.modutils.modpublisher" version "2.+" apply false } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/background/DirtTexturedBackground.java b/common/src/main/java/org/thinkingstudio/obsidianui/background/DirtTexturedBackground.java index 87be095..b849c72 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/background/DirtTexturedBackground.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/background/DirtTexturedBackground.java @@ -21,7 +21,7 @@ public record DirtTexturedBackground(int red, int green, int blue, int alpha) im @Override public void render(DrawContext drawContext, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) { - RenderUtil.renderDirtBackgroundTexture(widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(), + RenderUtil.renderDirtBackgroundTexture(drawContext, widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(), vOffset / 32.f, this.red, this.green, this.blue, this.alpha); } diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/background/TransparentBackground.java b/common/src/main/java/org/thinkingstudio/obsidianui/background/TransparentBackground.java index 2f8ab0a..d0b4941 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/background/TransparentBackground.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/background/TransparentBackground.java @@ -20,7 +20,7 @@ public record TransparentBackground(int red, int green, int blue, int alpha) imp @Override public void render(DrawContext drawContext, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) { - RenderUtil.renderTransparentBackgroundTexture(widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(), + RenderUtil.renderTransparentBackgroundTexture(drawContext, widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(), vOffset / 32.f, this.red, this.green, this.blue, this.alpha); } 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 6330c94..e314d9a 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/border/SimpleBorder.java @@ -13,6 +13,8 @@ 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; @@ -54,41 +56,40 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int @Override public void render(DrawContext drawContext, SpruceWidget widget, int mouseX, int mouseY, float delta) { - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); + RenderLayer renderLayer = RenderLayer.getGui(); + VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); int x = widget.getX(); int y = widget.getY(); int right = x + widget.getWidth(); int bottom = y + widget.getHeight(); boolean focused = widget.isFocused(); // Top border - this.vertex(buffer, x, y + this.thickness, focused); - this.vertex(buffer, right, y + this.thickness, focused); - this.vertex(buffer, right, y, focused); - this.vertex(buffer, x, y, focused); + 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); // Right border - this.vertex(buffer, right - this.thickness, bottom, focused); - this.vertex(buffer, right, bottom, focused); - this.vertex(buffer, right, y, focused); - this.vertex(buffer, right - this.thickness, y, focused); + 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); // Bottom - this.vertex(buffer, x, bottom, focused); - this.vertex(buffer, right, bottom, focused); - this.vertex(buffer, right, bottom - this.thickness, focused); - this.vertex(buffer, x, bottom - this.thickness, focused); + 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); // Left border - this.vertex(buffer, x, bottom, focused); - this.vertex(buffer, x + this.thickness, bottom, focused); - this.vertex(buffer, x + this.thickness, y, focused); - this.vertex(buffer, x, y, focused); - BufferRenderer.drawWithGlobalProgram(buffer.end()); + 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(BufferBuilder buffer, int x, int y, boolean focused) { + private void vertex(VertexConsumer consumer, int x, int y, boolean focused) { int[] color = focused ? this.focusedColor : this.color; - buffer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]); + consumer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]); } @Override diff --git a/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java b/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java new file mode 100644 index 0000000..e0ae50f --- /dev/null +++ b/common/src/main/java/org/thinkingstudio/obsidianui/mixin/DrawContextAccessor.java @@ -0,0 +1,12 @@ +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/util/RenderUtil.java b/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java index 16f6229..0a8ef6b 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/util/RenderUtil.java @@ -12,8 +12,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; +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 { /** @@ -31,20 +34,22 @@ private RenderUtil() { /** * Renders the vanilla's transparent background texture. * + * @param drawContext the current draw context * @param x the X coordinate * @param y the Y coordinate * @param width the width * @param height the height * @param vOffset the v offset - * @see #renderTransparentBackgroundTexture(int, int, int, int, float, int, int, int, int) + * @see #renderTransparentBackgroundTexture(DrawContext, int, int, int, int, float, int, int, int, int) */ - public static void renderTransparentBackgroundTexture(int x, int y, int width, int height, float vOffset) { - renderTransparentBackgroundTexture(x, y, width, height, vOffset, 64, 64, 64, 255); + public static void renderTransparentBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset) { + renderTransparentBackgroundTexture(drawContext, x, y, width, height, vOffset, 64, 64, 64, 255); } /** * Renders the vanilla's transparent background texture. * + * @param drawContext the current draw context * @param x the X-coordinate * @param y the Y-coordinate * @param width the width @@ -55,31 +60,28 @@ public static void renderTransparentBackgroundTexture(int x, int y, int width, i * @param blue the blue-component color value * @param alpha the alpha-component alpha value */ - public static void renderTransparentBackgroundTexture(int x, int y, int width, int height, float vOffset, - int red, int green, int blue, int alpha) { - var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); - RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); - RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); - RenderSystem.setShaderTexture(0, getListBackgroundTexture()); + public static void renderTransparentBackgroundTexture(DrawContext drawContext, 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; RenderSystem.enableBlend(); - bufferBuilder.vertex(x, bottom, 0) + vertexConsumer.vertex(x, bottom, 0) .texture(0, bottom / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(right, bottom, 0) + vertexConsumer.vertex(right, bottom, 0) .texture(right / 32.f, bottom / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(right, y, 0) + vertexConsumer.vertex(right, y, 0) .texture(right / 32.f, y / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(x, y, 0) + vertexConsumer.vertex(x, y, 0) .texture(0, y / 32.f + vOffset) .color(red, green, blue, alpha); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + drawContext.draw(); RenderSystem.disableBlend(); } public static Identifier getListBackgroundTexture() { @@ -89,21 +91,23 @@ public static Identifier getListBackgroundTexture() { /** * Renders the dirt background texture. * + * @param drawContext the current draw context * @param x the X coordinate * @param y the Y coordinate * @param width the width * @param height the height * @param vOffset the v offset - * @see #renderDirtBackgroundTexture(int, int, int, int, float, int, int, int, int) + * @see #renderDirtBackgroundTexture(DrawContext, int, int, int, int, float, int, int, int, int) */ @Deprecated(since = "1.20.5") - public static void renderDirtBackgroundTexture(int x, int y, int width, int height, float vOffset) { - renderDirtBackgroundTexture(x, y, width, height, vOffset, 64, 64, 64, 255); + public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset) { + renderDirtBackgroundTexture(drawContext, x, y, width, height, vOffset, 64, 64, 64, 255); } /** * Renders the dirt background texture. * + * @param drawContext the current draw context * @param x the X-coordinate * @param y the Y-coordinate * @param width the width @@ -115,35 +119,33 @@ public static void renderDirtBackgroundTexture(int x, int y, int width, int heig * @param alpha the alpha-component alpha value */ @Deprecated(since = "1.20.5") - public static void renderDirtBackgroundTexture(int x, int y, int width, int height, float vOffset, + public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset, int red, int green, int blue, int alpha) { - var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); - RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); - RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); - RenderSystem.setShaderTexture(0, DIRT_BACKGROUND_TEXTURE); + RenderLayer renderLayer = RenderLayer.getGuiTextured(DIRT_BACKGROUND_TEXTURE); + VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer); int right = x + width; int bottom = y + height; - bufferBuilder.vertex(x, bottom, 0) + vertexConsumer.vertex(x, bottom, 0) .texture(0, bottom / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(right, bottom, 0) + vertexConsumer.vertex(right, bottom, 0) .texture(right / 32.f, bottom / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(right, y, 0) + vertexConsumer.vertex(right, y, 0) .texture(right / 32.f, y / 32.f + vOffset) .color(red, green, blue, alpha); - bufferBuilder.vertex(x, y, 0) + vertexConsumer.vertex(x, y, 0) .texture(0, y / 32.f + vOffset) .color(red, green, blue, alpha); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + drawContext.draw(); } /** * Renders a selection box as background. * + * @param drawContext 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 @@ -153,25 +155,22 @@ public static void renderDirtBackgroundTexture(int x, int y, int width, int heig * @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(int x, int y, int width, int height, int red, int green, int blue, int alpha) { - var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - + public static void renderSelectionBox(DrawContext drawContext, int x, int y, int width, int height, int red, int green, int blue, int alpha) { int top = y + height; int right = x + width; - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - RenderSystem.setShaderColor(red / 255.f, green / 255.f, blue / 255.f, alpha / 255.f); - bufferBuilder.vertex(x, top, 0); - bufferBuilder.vertex(right, top, 0); - bufferBuilder.vertex(right, y, 0); - bufferBuilder.vertex(x, y, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderSystem.setShaderColor(0, 0, 0, 1.f); - bufferBuilder.vertex(x + 1, top - 1, 0); - bufferBuilder.vertex(right - 1, top - 1, 0); - bufferBuilder.vertex(right - 1, y + 1, 0); - bufferBuilder.vertex(x + 1, y + 1, 0); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + 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); + 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(); } } 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 43f0e97..79092c1 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/AbstractSpruceButtonWidget.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.screen.ButtonTextures; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -165,7 +166,7 @@ protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); - drawContext.drawGuiTexture(this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight()); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight()); } /* 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 e5756cd..9922087 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceCheckboxWidget.java @@ -14,12 +14,16 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; import net.minecraft.text.OrderedText; 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.thinkingstudio.obsidianui.Position; +import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor; /** * Represents a checkbox widget. @@ -99,11 +103,11 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo if (this.getValue()) { if (this.colored) RenderSystem.setShaderColor(0.f, 1.f, 0.f, this.alpha); - drawContext.drawTexture(TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64); + drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64); } else if (this.showCross) { if (this.colored) RenderSystem.setShaderColor(1.f, 0.f, 0.f, this.alpha); - drawContext.drawTexture(TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64); + drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64); } if (this.colored) { @@ -120,12 +124,11 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo @Override protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) { RenderSystem.enableDepthTest(); - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.alpha); - RenderSystem.setShaderTexture(0, TEXTURE); + int color = ColorHelper.fromFloats(this.alpha, 1.f, 1.f, 1.f); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawContext.drawTexture(TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64); + drawContext.drawTexture(RenderLayer::getGuiTextured, 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/SpruceSliderWidget.java b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java index 0a3cdaf..b518f43 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceSliderWidget.java @@ -12,6 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem; 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.MathHelper; @@ -174,7 +175,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); final Identifier texture = this.isFocusedOrHovered() ? SLIDER_HANDLE_HIGHLIGHTED : SLIDER_HANDLE; - drawContext.drawGuiTexture(texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20); + drawContext.drawGuiTexture(RenderLayer::getGuiTextured, 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 33d8083..cff8abc 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceTexturedButtonWidget.java @@ -12,6 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.thinkingstudio.obsidianui.Position; @@ -77,7 +78,7 @@ protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha()); RenderSystem.setShaderTexture(0, this.texture); RenderSystem.enableDepthTest(); - drawContext.drawTexture(this.texture, + drawContext.drawTexture(RenderLayer::getGuiTextured, this.texture, this.getX(), this.getY(), this.u, v, this.getWidth(), this.getHeight(), 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 229c046..ec30055 100644 --- a/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java +++ b/common/src/main/java/org/thinkingstudio/obsidianui/widget/SpruceToggleSwitch.java @@ -13,6 +13,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; 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; @@ -58,7 +59,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawContext.drawTexture(TEXTURE, this.getX() + (this.getValue() ? 14 : 0), this.getY() + (this.getHeight() / 2 - 9), + drawContext.drawTexture(RenderLayer::getGuiTextured, 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); @@ -79,7 +80,7 @@ protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawContext.drawTexture(TEXTURE, this.getX(), this.getY() + (this.getHeight() / 2 - 9), + 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); } 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 f52e68a..a835435 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 @@ -28,6 +28,7 @@ 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.ScissorManager; import org.thinkingstudio.obsidianui.widget.AbstractSpruceWidget; @@ -354,18 +355,17 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo Identifier topTexture = getSeparatorTexture(true); Identifier bottomTexture = getSeparatorTexture(false); - drawContext.drawTexture(topTexture, left, top - 2, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); - drawContext.drawTexture(bottomTexture, left, bottom, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); + 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); // The following code is absolutely cursed, but works surprisingly well to create side borders int screenWidth = client.getWindow().getScaledWidth(); - if (left > 0) drawContext.drawTexture(topTexture, left-1, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); - if (right < screenWidth) drawContext.drawTexture(topTexture, right, top - 1, 0.0F, 0.0F, 1, this.getHeight() + 2, 1, (this.getHeight() + 2) * 2); + 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); } // Scrollbar int maxScroll = this.getMaxScroll(); if (maxScroll > 0) { - var tessellator = Tessellator.getInstance(); int scrollbarHeight = (int) ((float) ((this.getHeight()) * (this.getHeight())) / (float) this.getMaxPosition()); scrollbarHeight = MathHelper.clamp(scrollbarHeight, 32, this.getHeight() - 8); int scrollbarY = (int) this.getScrollAmount() * (this.getHeight() - scrollbarHeight) / maxScroll + this.getY(); @@ -373,7 +373,7 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo scrollbarY = this.getY(); } - this.renderScrollbar(tessellator, scrollbarPositionX, scrollBarEnd, scrollbarY, scrollbarHeight); + this.renderScrollbar(drawContext, scrollbarPositionX, scrollBarEnd, scrollbarY, scrollbarHeight); } this.getBorder().render(drawContext, this, mouseX, mouseY, delta); @@ -381,23 +381,23 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo RenderSystem.disableBlend(); } - protected void renderScrollbar(Tessellator tessellator, int scrollbarX, int scrollbarEndX, int scrollbarY, int scrollbarHeight) { - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - - BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); - buffer.vertex(scrollbarX, this.getY() + this.getHeight(), 0).color(0, 0, 0, 255); - buffer.vertex(scrollbarEndX, this.getY() + this.getHeight(), 0).color(0, 0, 0, 255); - buffer.vertex(scrollbarEndX, this.getY(), 0).color(0, 0, 0, 255); - buffer.vertex(scrollbarX, this.getY(), 0).color(0, 0, 0, 255); - buffer.vertex(scrollbarX, scrollbarY + scrollbarHeight, 0).color(128, 128, 128, 255); - buffer.vertex(scrollbarEndX, scrollbarY + scrollbarHeight, 0).color(128, 128, 128, 255); - buffer.vertex(scrollbarEndX, scrollbarY, 0).color(128, 128, 128, 255); - buffer.vertex(scrollbarX, scrollbarY, 0).color(128, 128, 128, 255); - buffer.vertex(scrollbarX, scrollbarY + scrollbarHeight - 1, 0).color(192, 192, 192, 255); - buffer.vertex(scrollbarEndX - 1, scrollbarY + scrollbarHeight - 1, 0).color(192, 192, 192, 255); - buffer.vertex(scrollbarEndX - 1, scrollbarY, 0).color(192, 192, 192, 255); - buffer.vertex(scrollbarX, scrollbarY, 0).color(192, 192, 192, 255); - BufferRenderer.drawWithGlobalProgram(buffer.end()); + 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(); } /* Narration */ 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 070b956..cbb88a5 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 @@ -19,11 +19,13 @@ import net.minecraft.client.render.*; import net.minecraft.text.Text; import net.minecraft.util.StringHelper; +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.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; @@ -509,18 +511,16 @@ protected void drawSelection(DrawContext drawContext, String line, int lineY, in int x2 = x + this.textRenderer.getWidth(selected); int y2 = lineY + this.textRenderer.fontHeight; - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - RenderSystem.setShader(GameRenderer::getPositionProgram); - RenderSystem.setShaderColor(0.0f, 0.0f, 1.0f, 1.0f); - buffer.vertex(x, y2, 0); - buffer.vertex(x2, y2, 0); - buffer.vertex(x2, lineY, 0); - buffer.vertex(x, lineY, 0); - BufferRenderer.drawWithGlobalProgram(buffer.end()); - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); + 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(); RenderSystem.disableColorLogicOp(); } 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 51346aa..78e4df4 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 @@ -23,12 +23,14 @@ import net.minecraft.text.Text; import net.minecraft.util.StringHelper; import net.minecraft.util.Util; +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.mixin.DrawContextAccessor; import org.thinkingstudio.obsidianui.navigation.NavigationDirection; import org.thinkingstudio.obsidianui.util.ColorUtil; @@ -440,16 +442,17 @@ protected void drawText(DrawContext drawContext) { drawContext.drawTextWithShadow(this.client.textRenderer, this.renderTextProvider.apply(displayedText, this.firstCharacterIndex), x, y, textColor); - this.drawSelection(displayedText, y); + this.drawSelection(drawContext, displayedText, y); } /** * Draws the selection over the text. * + * @param drawContext the current draw context * @param line the current line * @param lineY the line Y-coordinates */ - protected void drawSelection(String line, int lineY) { + protected void drawSelection(DrawContext drawContext, String line, int lineY) { if (!this.isFocused() || !this.selection.active) return; @@ -465,17 +468,16 @@ protected void drawSelection(String line, int lineY) { int x2 = x + this.client.textRenderer.getWidth(selected); int y2 = lineY + this.client.textRenderer.fontHeight; - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - RenderSystem.setShader(GameRenderer::getPositionProgram); - RenderSystem.setShaderColor(0.f, 0.f, 255.f, 255.f); - buffer.vertex(x, y2, 0); - buffer.vertex(x2, y2, 0); - buffer.vertex(x2, lineY, 0); - buffer.vertex(x, lineY, 0); - BufferRenderer.drawWithGlobalProgram(buffer.end()); + 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(); RenderSystem.disableColorLogicOp(); } diff --git a/common/src/main/resources/obsidianui.mixins.json b/common/src/main/resources/obsidianui.mixins.json new file mode 100644 index 0000000..2d881c5 --- /dev/null +++ b/common/src/main/resources/obsidianui.mixins.json @@ -0,0 +1,11 @@ +{ + "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 3703405..d6944f1 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -20,6 +20,7 @@ ] }, "mixins": [ + "obsidianui.mixins.json", "obsidianui.fabric.mixins.json" ], "depends": { diff --git a/gradle.properties b/gradle.properties index 806a12b..bccd099 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.jvmargs=-Xmx2G -minecraft_version=1.21.1 +minecraft_version=1.21.3 enabled_platforms=fabric,neoforge -yarn_mappings=1.21.1+build.3 +yarn_mappings=1.21.3+build.2 mappings_patch=1.21+build.4 archives_base_name=ObsidianUI -mod_version=0.2.8 +mod_version=0.2.9 maven_group=org.thinkingstudio.obsidianui -fabric_loader_version=0.16.2 -fabric_api_version=0.102.1+1.21.1 +fabric_loader_version=0.16.9 +fabric_api_version=0.107.3+1.21.3 -neoforge_version=21.1.18 +neoforge_version=21.3.33-beta modrinth_id=E0L8mfJZ curseforge_id=684718 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 5109e4b..c97df83 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -16,6 +16,9 @@ Just a GUI library. ''' logoFile = "icon.png" +[[mixins]] +config = "obsidianui.mixins.json" + [[mixins]] config = "obsidianui.neoforge.mixins.json"