nageyqma·git
HTTPS https://git.nageyqma.icu/nageyqma/odin_next.git SSH git@git.nageyqma.icu:nageyqma/odin_next.git

HTTPS 链接可直接 git clone;推送代码请使用 SSH。

2.0 KB · 60 行raw
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
package com.odtheking.odin.utils.render

import com.odtheking.odin.OdinMod.mc
import com.odtheking.odin.utils.Color
import com.odtheking.odin.utils.Colors
import net.minecraft.client.gui.GuiGraphicsExtractor
import net.minecraft.util.FormattedCharSequence
import org.joml.Matrix3x2f
import kotlin.math.atan2
import kotlin.math.ceil
import kotlin.math.hypot

fun GuiGraphicsExtractor.text(text: String, x: Int, y: Int, color: Color = Colors.WHITE, shadow: Boolean = true) {
    text(mc.font, text, x, y, color.rgba, shadow)
}

fun GuiGraphicsExtractor.text(text: FormattedCharSequence, x: Int, y: Int, color: Color = Colors.WHITE, shadow: Boolean = true) {
    text(mc.font, text, x, y, color.rgba, shadow)
}

fun GuiGraphicsExtractor.textDim(text: String, x: Int, y: Int, color: Color = Colors.WHITE, shadow: Boolean = true): Pair<Int, Int> {
    text(text, x, y, color, shadow)
    return mc.font.width(text) to mc.font.lineHeight
}

fun GuiGraphicsExtractor.textDim(text: FormattedCharSequence, x: Int, y: Int, color: Color = Colors.WHITE, shadow: Boolean = true): Pair<Int, Int> {
    text(text, x, y, color, shadow)
    return mc.font.width(text) to mc.font.lineHeight
}

fun getStringWidth(text: String): Int = mc.font.width(text)

fun GuiGraphicsExtractor.hollowFill(x: Int, y: Int, width: Int, height: Int, thickness: Int, color: Color) {
    fill(x, y, x + width, y + thickness, color.rgba)
    fill(x, y + height - thickness, x + width, y + height, color.rgba)
    fill(x, y + thickness, x + thickness, y + height - thickness, color.rgba)
    fill(x + width - thickness, y + thickness, x + width, y + height - thickness, color.rgba)
}

fun GuiGraphicsExtractor.drawLine(
    x1: Float,
    y1: Float,
    x2: Float,
    y2: Float,
    color: Color,
    lineWidth: Float = 1f
) {
    val dx = x2 - x1
    val dy = y2 - y1
    val length = hypot(dx, dy)

    pose().pushMatrix()
    pose().translate(x1, y1)
    pose().mul(Matrix3x2f().identity().rotate(atan2(dy, dx)))
    pose().scale(1f, lineWidth)

    fill(0, -1, ceil(length).toInt(), 1, color.rgba)

    pose().popMatrix()
}