Skip to content

Commit

Permalink
Merge pull request #14 from ThinkingStudios/revert-13-revert-12-1.21.…
Browse files Browse the repository at this point in the history
…3-architectury

Revert "Revert "Port to 1.21.3""
  • Loading branch information
TexBlock authored Nov 23, 2024
2 parents d98143b + 2331124 commit bb18529
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 132 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit bb18529

Please sign in to comment.