aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java')
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
index 48f2cc3..111ccdb 100644
--- a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
+++ b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
@@ -2,6 +2,7 @@ package dev.isxander.yacl3.gui;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.isxander.yacl3.api.utils.Dimension;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import dev.isxander.yacl3.gui.utils.YACLRenderHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
@@ -88,23 +89,22 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
graphics.fill(x1, y1, x1 + width, y2, color);
}
- protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int startColor, int endColor) {
+ protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int startColor, int endColor, VertexConsumer consumer) {
//Fills a gradient, left to right
//Uses practically the same method as the GuiGraphics class, but with the x/y moved
//Has a custom "z" value in case needed for later
- VertexConsumer vertex = graphics.bufferSource().getBuffer(RenderType.gui());
Matrix4f matrix4f = graphics.pose().last().pose();
/*? if >1.20.6 {*/
- vertex.addVertex(matrix4f, x1, y1, 0).setColor(startColor);
- vertex.addVertex(matrix4f, x1, y2, 0).setColor(startColor);
- vertex.addVertex(matrix4f, x2, y2, 0).setColor(endColor);
- vertex.addVertex(matrix4f, x2, y1, 0).setColor(endColor);
+ consumer.addVertex(matrix4f, x1, y1, 0).setColor(startColor);
+ consumer.addVertex(matrix4f, x1, y2, 0).setColor(startColor);
+ consumer.addVertex(matrix4f, x2, y2, 0).setColor(endColor);
+ consumer.addVertex(matrix4f, x2, y1, 0).setColor(endColor);
/*?} else {*/
- /*vertex.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex();
- vertex.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex();
- vertex.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex();
- vertex.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex();
+ /*consumer.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex();
+ consumer.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex();
+ consumer.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex();
+ consumer.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex();
*//*?}*/
}
@@ -115,16 +115,25 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
Color.cyan.getRGB(), Color.blue.getRGB(), Color.magenta.getRGB(), Color.red.getRGB()}; //all the colors in the gradient
int width = x2 - x1;
int maxColors = colors.length - 1;
- for (int color = 0; color < maxColors; color++) {
- //First checks if the final color is being rendered, if true -> uses x2 int instead of x1
- //if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
- //the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
- //The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
- fillSidewaysGradient(graphics,
- x1 + (width / maxColors * color), y1,
- color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
- colors[color], colors[color + 1]);
- }
+
+ GuiUtils.drawSpecial(graphics, bufferSource -> {
+ VertexConsumer consumer = bufferSource.getBuffer(RenderType.gui());
+
+ for (int color = 0; color < maxColors; color++) {
+ //First checks if the final color is being rendered, if true -> uses x2 int instead of x1
+ //if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
+ //the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
+ //The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
+ fillSidewaysGradient(
+ graphics,
+ x1 + (width / maxColors * color), y1,
+ color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
+ colors[color], colors[color + 1],
+ consumer
+ );
+ }
+ });
+
}
protected int multiplyColor(int hex, float amount) {