diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt index 129b21805..c6859c5ca 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt @@ -10,6 +10,7 @@ import net.minecraft.core.Vec3i import net.minecraft.network.chat.Component import net.minecraft.util.FormattedCharSequence import ru.dbotthepony.mc.otm.core.* +import kotlin.math.roundToInt val tesselator: Tesselator get() = Tesselator.getInstance() @@ -66,48 +67,48 @@ enum class TextAlign { fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: Int): Int { return when (align) { TextAlign.TOP_LEFT -> draw(poseStack, text, x, y, color) - TextAlign.TOP_CENTER -> draw(poseStack, text, x - width(text) / 2f, y, color) - TextAlign.TOP_RIGHT -> draw(poseStack, text, x - width(text), y, color) + TextAlign.TOP_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), y, color) + TextAlign.TOP_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), y, color) - TextAlign.CENTER_LEFT -> draw(poseStack, text, x, y - lineHeight / 2f, color) - TextAlign.CENTER_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight / 2f, color) - TextAlign.CENTER_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight / 2f, color) + TextAlign.CENTER_LEFT -> draw(poseStack, text, x, (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) - TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, y - lineHeight, color) - TextAlign.BOTTOM_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight, color) - TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight, color) + TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) } } fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: Int): Int { return when (align) { TextAlign.TOP_LEFT -> draw(poseStack, text, x, y, color) - TextAlign.TOP_CENTER -> draw(poseStack, text, x - width(text) / 2f, y, color) - TextAlign.TOP_RIGHT -> draw(poseStack, text, x - width(text), y, color) + TextAlign.TOP_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), y, color) + TextAlign.TOP_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), y, color) - TextAlign.CENTER_LEFT -> draw(poseStack, text, x, y - lineHeight / 2f, color) - TextAlign.CENTER_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight / 2f, color) - TextAlign.CENTER_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight / 2f, color) + TextAlign.CENTER_LEFT -> draw(poseStack, text, x, (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) - TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, y - lineHeight, color) - TextAlign.BOTTOM_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight, color) - TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight, color) + TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) } } fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int): Int { return when (align) { TextAlign.TOP_LEFT -> draw(poseStack, text, x, y, color) - TextAlign.TOP_CENTER -> draw(poseStack, text, x - width(text) / 2f, y, color) - TextAlign.TOP_RIGHT -> draw(poseStack, text, x - width(text), y, color) + TextAlign.TOP_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), y, color) + TextAlign.TOP_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), y, color) - TextAlign.CENTER_LEFT -> draw(poseStack, text, x, y - lineHeight / 2f, color) - TextAlign.CENTER_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight / 2f, color) - TextAlign.CENTER_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight / 2f, color) + TextAlign.CENTER_LEFT -> draw(poseStack, text, x, (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) + TextAlign.CENTER_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color) - TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, y - lineHeight, color) - TextAlign.BOTTOM_CENTER -> draw(poseStack, text, x - width(text) / 2f, y - lineHeight, color) - TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, x - width(text), y - lineHeight, color) + TextAlign.BOTTOM_LEFT -> draw(poseStack, text, x, (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_CENTER -> draw(poseStack, text, (x - width(text) / 2f).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) + TextAlign.BOTTOM_RIGHT -> draw(poseStack, text, (x - width(text)).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color) } }