Fix and improve UI rendering

Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404-59 2025-04-16 04:41:17 +02:00
parent 6eed08aa53
commit 5d98234d39
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 18 additions and 20 deletions

View File

@ -81,26 +81,25 @@ class ClickBox(
val currentHeight = y + (height + clickboxHeightOffset)
prepareDraw()
renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_TRIANGLE_FAN) {
with(it) {
// Render the header:
addVertex(x, y + height, 0.0F).colorEnd()
addVertex(x + width + inclination, y + height, 0.0F).colorEnd()
addVertex(x + width, y, 0.0F).colorEnd()
addVertex(x + inclination, y, 0.0F).colorEnd()
// Render the header:
addVertex(x, y + height, 0.0F).colorEnd()
addVertex(x + width + inclination, y + height, 0.0F).colorEnd()
addVertex(x + width, y, 0.0F).colorEnd()
addVertex(x + inclination, y, 0.0F).colorEnd()
}
// Render the box:
addVertex(x, currentHeight, 0.0F).colorEnd()
addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd()
addVertex(x + width + inclination, y + height, 0.0F).colorEnd()
}
renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_TRIANGLE_FAN) {
// Render the box:
addVertex(x, currentHeight, 0.0F).colorEnd()
addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd()
addVertex(x + width + inclination, y + height, 0.0F).colorEnd()
addVertex(x, y + height, 0.0F).colorEnd()
}
renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) {
with(it) {
colorShader()
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
}
colorShader()
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
}
endDraw()

View File

@ -18,7 +18,6 @@ import java.util.OptionalInt
import java.util.OptionalDouble
object RenderingUtil {
@JvmField val tessellator: Tesselator = Tesselator.getInstance()
@JvmStatic
fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer = hextoRGB(color).run {
setColor(get(0), get(1), get(2), opacity)
@ -36,21 +35,21 @@ object RenderingUtil {
fun drawRectangle(
x: Double, y: Double, height: Int, width: Int,
color: Int = Colors.TRANSPARENT(), opacity: Float = 1F
): Unit = renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_QUADS) { buffer -> buffer.run {
): Unit = renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_QUADS) {
fun VertexConsumer.colorIt() = colorIt(color, opacity)
val x = x.toFloat() ; val y = y.toFloat()
addVertex(x, y + height, 0.0F).colorIt()
addVertex(x + width, y + height, 0.0F).colorIt()
addVertex(x + width, y, 0.0F).colorIt()
addVertex(x, y, 0.0F).colorIt()
} }
}
fun renderBufferWithPipeline(
name: String? = "Dynamic vertex buffer",
renderPipeline: RenderPipeline,
renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget,
uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null,
bufferBuilderConsumer: (BufferBuilder) -> Unit,
bufferBuilderConsumer: BufferBuilder.() -> Unit,
) {
val mode = renderPipeline.vertexFormatMode
val builder = Tesselator.getInstance().begin(mode, renderPipeline.vertexFormat)