Skip to content

Commit

Permalink
Revert "Port to 1.21.3"
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock authored Nov 23, 2024
1 parent 9ad775c commit 6e14239
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 168 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.7-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-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(drawContext, widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(),
RenderUtil.renderDirtBackgroundTexture(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(drawContext, widget.getX(), widget.getY(), widget.getWidth(), widget.getHeight(),
RenderUtil.renderTransparentBackgroundTexture(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,8 +13,6 @@
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 @@ -56,40 +54,41 @@ 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) {
RenderLayer renderLayer = RenderLayer.getGui();
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);
var tessellator = Tessellator.getInstance();
var buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
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(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);
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);
// 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);
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);
// 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);
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);
// 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();
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());

}

private void vertex(VertexConsumer consumer, int x, int y, boolean focused) {
private void vertex(BufferBuilder buffer, 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]);
buffer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

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 @@ -34,22 +31,20 @@ 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(DrawContext, int, int, int, int, float, int, int, int, int)
* @see #renderTransparentBackgroundTexture(int, int, int, int, float, int, int, int, int)
*/
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);
public static void renderTransparentBackgroundTexture(int x, int y, int width, int height, float vOffset) {
renderTransparentBackgroundTexture(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 @@ -60,28 +55,31 @@ 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,
int red, int green, int blue, int alpha) {
RenderLayer renderLayer = RenderLayer.getGuiTextured(getListBackgroundTexture());
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);
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());

int right = x + width;
int bottom = y + height;

RenderSystem.enableBlend();
vertexConsumer.vertex(x, bottom, 0)
bufferBuilder.vertex(x, bottom, 0)
.texture(0, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, bottom, 0)
bufferBuilder.vertex(right, bottom, 0)
.texture(right / 32.f, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, y, 0)
bufferBuilder.vertex(right, y, 0)
.texture(right / 32.f, y / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(x, y, 0)
bufferBuilder.vertex(x, y, 0)
.texture(0, y / 32.f + vOffset)
.color(red, green, blue, alpha);
drawContext.draw();
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
RenderSystem.disableBlend();
}
public static Identifier getListBackgroundTexture() {
Expand All @@ -91,23 +89,21 @@ 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(DrawContext, int, int, int, int, float, int, int, int, int)
* @see #renderDirtBackgroundTexture(int, int, int, int, float, int, int, int, int)
*/
@Deprecated(since = "1.20.5")
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);
public static void renderDirtBackgroundTexture(int x, int y, int width, int height, float vOffset) {
renderDirtBackgroundTexture(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 @@ -119,33 +115,35 @@ 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(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);
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);

int right = x + width;
int bottom = y + height;

vertexConsumer.vertex(x, bottom, 0)
bufferBuilder.vertex(x, bottom, 0)
.texture(0, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, bottom, 0)
bufferBuilder.vertex(right, bottom, 0)
.texture(right / 32.f, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, y, 0)
bufferBuilder.vertex(right, y, 0)
.texture(right / 32.f, y / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(x, y, 0)
bufferBuilder.vertex(x, y, 0)
.texture(0, y / 32.f + vOffset)
.color(red, green, blue, alpha);
drawContext.draw();
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
}

/**
* 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 @@ -155,22 +153,25 @@ 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(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);

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);
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();
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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 @@ -166,7 +165,7 @@ protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY,
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
drawContext.drawGuiTexture(RenderLayer::getGuiTextured, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight());
drawContext.drawGuiTexture(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,16 +14,12 @@
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 @@ -103,11 +99,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(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64);
drawContext.drawTexture(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(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64);
drawContext.drawTexture(TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64);
}

if (this.colored) {
Expand All @@ -124,11 +120,12 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo
@Override
protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
RenderSystem.enableDepthTest();
int color = ColorHelper.fromFloats(this.alpha, 1.f, 1.f, 1.f);
RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.alpha);
RenderSystem.setShaderTexture(0, TEXTURE);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
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(TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64);
}

/* Narration */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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 @@ -175,7 +174,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(RenderLayer::getGuiTextured, texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20);
drawContext.drawGuiTexture(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,7 +12,6 @@

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 @@ -78,7 +77,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(RenderLayer::getGuiTextured, this.texture,
drawContext.drawTexture(this.texture,
this.getX(), this.getY(),
this.u, v,
this.getWidth(), this.getHeight(),
Expand Down
Loading

0 comments on commit 6e14239

Please sign in to comment.