Draw in-world text in batches

This commit is contained in:
DBotThePony 2022-10-08 16:41:56 +07:00
parent 13d5aae33b
commit 7f6f25e616
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 148 additions and 59 deletions

View File

@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer
import com.mojang.math.Matrix4f import com.mojang.math.Matrix4f
import com.mojang.math.Vector3f import com.mojang.math.Vector3f
import net.minecraft.client.gui.Font import net.minecraft.client.gui.Font
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.core.Vec3i import net.minecraft.core.Vec3i
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.util.FormattedCharSequence import net.minecraft.util.FormattedCharSequence
@ -78,6 +79,20 @@ private fun Font.drawScaledDuckTyped(poseStack: PoseStack, text: Any, scale: Flo
return size return size
} }
private fun Font.drawScaledDuckTyped(poseStack: PoseStack, buffer: MultiBufferSource, text: Any, scale: Float, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0): Int {
val translation = poseStack.translation()
poseStack.pushPose()
poseStack.translate(-translation)
poseStack.scale(scale, scale, scale)
val inv = 1f / scale
poseStack.translate(-translation * inv)
val size = drawDuckTyped(poseStack, buffer, text, x * inv, y * inv, color, drawShadow, seeThrough, packedLightCoords, effectColor)
poseStack.popPose()
return size
}
private fun Font.drawDuckTyped(poseStack: PoseStack, text: Any, x: Float, y: Float, color: Int): Int { private fun Font.drawDuckTyped(poseStack: PoseStack, text: Any, x: Float, y: Float, color: Int): Int {
return when (text) { return when (text) {
is Component -> draw(poseStack, text, x, y, color) is Component -> draw(poseStack, text, x, y, color)
@ -87,6 +102,36 @@ private fun Font.drawDuckTyped(poseStack: PoseStack, text: Any, x: Float, y: Flo
} }
} }
private fun Font.drawDuckTyped(
poseStack: PoseStack,
buffer: MultiBufferSource,
text: Any,
x: Float,
y: Float,
color: Int,
drawShadow: Boolean = false,
seeThrough: Boolean = false,
packedLightCoords: Int = 15728880,
effectColor: Int = 0
): Int {
if (drawShadow) {
poseStack.pushPose()
}
val result = when (text) {
is Component -> drawInBatch(text, x, y, color, drawShadow, poseStack.last().pose(), buffer, seeThrough, effectColor, packedLightCoords)
is String -> drawInBatch(text, x, y, color, drawShadow, poseStack.last().pose(), buffer, seeThrough, effectColor, packedLightCoords)
is FormattedCharSequence -> drawInBatch(text, x, y, color, drawShadow, poseStack.last().pose(), buffer, seeThrough, effectColor, packedLightCoords)
else -> throw ClassCastException(text::class.qualifiedName)
}
if (drawShadow) {
poseStack.popPose()
}
return result
}
private fun Font.widthDuckTyped(text: Any): Int { private fun Font.widthDuckTyped(text: Any): Int {
return when (text) { return when (text) {
is Component -> width(text) is Component -> width(text)
@ -112,6 +157,34 @@ private fun Font.drawAlignedDuckTyped(poseStack: PoseStack, text: Any, align: Te
} }
} }
private fun Font.drawAlignedDuckTyped(
poseStack: PoseStack,
buffer: MultiBufferSource,
text: Any,
align: TextAlign,
x: Float,
y: Float,
color: Int,
drawShadow: Boolean = false,
seeThrough: Boolean = false,
packedLightCoords: Int = 15728880,
effectColor: Int = 0
): Int {
return when (align) {
TextAlign.TOP_LEFT -> drawDuckTyped(poseStack, buffer, text, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.TOP_CENTER -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text) / 2f).roundToInt().toFloat(), y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.TOP_RIGHT -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text)).roundToInt().toFloat(), y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_LEFT -> drawDuckTyped(poseStack, buffer, text, x, (y - lineHeight / 2f).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_CENTER -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text) / 2f).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_RIGHT -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text)).roundToInt().toFloat(), (y - lineHeight / 2f).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_LEFT -> drawDuckTyped(poseStack, buffer, text, x, (y - lineHeight).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_CENTER -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text) / 2f).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_RIGHT -> drawDuckTyped(poseStack, buffer, text, (x - widthDuckTyped(text)).roundToInt().toFloat(), (y - lineHeight).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
}
}
private fun Font.drawScaledAlignedDuckTyped(poseStack: PoseStack, text: Any, scale: Float, align: TextAlign, x: Float, y: Float, color: Int): Int { private fun Font.drawScaledAlignedDuckTyped(poseStack: PoseStack, text: Any, scale: Float, align: TextAlign, x: Float, y: Float, color: Int): Int {
return when (align) { return when (align) {
TextAlign.TOP_LEFT -> drawScaledDuckTyped(poseStack, text, scale, x, y, color) TextAlign.TOP_LEFT -> drawScaledDuckTyped(poseStack, text, scale, x, y, color)
@ -128,50 +201,63 @@ private fun Font.drawScaledAlignedDuckTyped(poseStack: PoseStack, text: Any, sca
} }
} }
fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: Int): Int { private fun Font.drawScaledAlignedDuckTyped(
return drawAlignedDuckTyped(poseStack, text, align, x, y, color) poseStack: PoseStack,
buffer: MultiBufferSource,
text: Any,
scale: Float,
align: TextAlign,
x: Float,
y: Float,
color: Int,
drawShadow: Boolean = false,
seeThrough: Boolean = false,
packedLightCoords: Int = 15728880,
effectColor: Int = 0
): Int {
return when (align) {
TextAlign.TOP_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.TOP_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f).roundToInt().toFloat(), y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.TOP_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale).roundToInt().toFloat(), y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, (y - lineHeight / 2f * scale).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f).roundToInt().toFloat(), (y - lineHeight * scale / 2f).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.CENTER_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale).roundToInt().toFloat(), (y - lineHeight * scale / 2f).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_LEFT -> drawScaledDuckTyped(poseStack, buffer, text, scale, x, (y - lineHeight * scale).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_CENTER -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale / 2f).roundToInt().toFloat(), (y - lineHeight * scale).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
TextAlign.BOTTOM_RIGHT -> drawScaledDuckTyped(poseStack, buffer, text, scale, (x - widthDuckTyped(text) * scale).roundToInt().toFloat(), (y - lineHeight * scale).roundToInt().toFloat(), color, drawShadow, seeThrough, packedLightCoords, effectColor)
}
} }
fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: Int): Int { fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
return drawAlignedDuckTyped(poseStack, text, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
} fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int) = drawAlignedDuckTyped(poseStack, text, align, x, y, color)
fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int): Int { fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
return drawAlignedDuckTyped(poseStack, text, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
} fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawAligned(poseStack, text, align, x, y, color.toInt())
fun Font.drawAligned(poseStack: PoseStack, text: String, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int { fun Font.drawScaledAligned(poseStack: PoseStack, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
return drawAligned(poseStack, text, align, x, y, color.toInt()) fun Font.drawScaledAligned(poseStack: PoseStack, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
} fun Font.drawScaledAligned(poseStack: PoseStack, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: Int) = drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color)
fun Font.drawAligned(poseStack: PoseStack, text: Component, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int { fun Font.drawScaledAligned(poseStack: PoseStack, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
return drawAligned(poseStack, text, align, x, y, color.toInt()) fun Font.drawScaledAligned(poseStack: PoseStack, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
} fun Font.drawScaledAligned(poseStack: PoseStack, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor) = drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
fun Font.drawAligned(poseStack: PoseStack, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int { fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAlignedDuckTyped(poseStack, buffer, text, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
return drawAligned(poseStack, text, align, x, y, color.toInt()) fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAlignedDuckTyped(poseStack, buffer, text, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
} fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAlignedDuckTyped(poseStack, buffer, text, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: Int): Int { fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, align: TextAlign, x: Float, y: Float, color: RGBAColor, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAligned(poseStack, buffer, text, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
return drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color) fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, align: TextAlign, x: Float, y: Float, color: RGBAColor, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAligned(poseStack, buffer, text, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
} fun Font.drawAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, align: TextAlign, x: Float, y: Float, color: RGBAColor, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0) = drawAligned(poseStack, buffer, text, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: Int): Int { fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0,) = drawScaledAlignedDuckTyped(poseStack, buffer, text, scale, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
return drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color) fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0,) = drawScaledAlignedDuckTyped(poseStack, buffer, text, scale, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
} fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: Int, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0,) = drawScaledAlignedDuckTyped(poseStack, buffer, text, scale, align, x, y, color, drawShadow, seeThrough, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: Int): Int { fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: String, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
return drawScaledAlignedDuckTyped(poseStack, text, scale, align, x, y, color) fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
} fun Font.drawScaledAligned(poseStack: PoseStack, buffer: MultiBufferSource, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, drawShadow: Boolean = false, seeThrough: Boolean = false, packedLightCoords: Int = 15728880, effectColor: Int = 0, color: RGBAColor) = drawScaledAligned(poseStack, buffer, text, scale, align, x, y, color.toInt(), drawShadow, seeThrough, packedLightCoords, effectColor)
fun Font.drawScaledAligned(poseStack: PoseStack, text: String, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int {
return drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
}
fun Font.drawScaledAligned(poseStack: PoseStack, text: Component, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int {
return drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
}
fun Font.drawScaledAligned(poseStack: PoseStack, text: FormattedCharSequence, scale: Float, align: TextAlign, x: Float, y: Float, color: RGBAColor): Int {
return drawScaledAligned(poseStack, text, scale, align, x, y, color.toInt())
}

View File

@ -172,11 +172,13 @@ class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context
val text1 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", tile.mass.formatMatter()) val text1 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", tile.mass.formatMatter())
val text2 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(tile.gravitationStrength)) val text2 = TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(tile.gravitationStrength))
font.drawAligned(poseStack, text1, TextAlign.TOP_LEFT, 0.8f, 0.8f - font.lineHeight.toFloat() / 2f, 0x0) val sorse = DynamicBufferSource.WORLD
font.drawAligned(poseStack, text2, TextAlign.TOP_LEFT, 0.8f, 0.8f + font.lineHeight.toFloat() / 2f, 0x0)
font.drawAligned(poseStack, sorse, text1, TextAlign.TOP_LEFT, 0.8f, 0.8f - font.lineHeight.toFloat() / 2f, 0x0)
font.drawAligned(poseStack, sorse, text2, TextAlign.TOP_LEFT, 0.8f, 0.8f + font.lineHeight.toFloat() / 2f, 0x0)
poseStack.translate(0.0, 0.0, -1.0) poseStack.translate(0.0, 0.0, -1.0)
font.drawAligned(poseStack, text1, TextAlign.TOP_LEFT, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF) font.drawAligned(poseStack, sorse, text1, TextAlign.TOP_LEFT, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF)
font.drawAligned(poseStack, text2, TextAlign.TOP_LEFT, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF) font.drawAligned(poseStack, sorse, text2, TextAlign.TOP_LEFT, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF)
poseStack.popPose() poseStack.popPose()
} }

View File

@ -9,6 +9,7 @@ import net.minecraft.core.Direction
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.block.EnergyCounterBlock import ru.dbotthepony.mc.otm.block.EnergyCounterBlock
import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.RGBAColor import ru.dbotthepony.mc.otm.core.RGBAColor
import ru.dbotthepony.mc.otm.core.asAngle import ru.dbotthepony.mc.otm.core.asAngle
@ -32,10 +33,12 @@ class EnergyCounterRenderer(private val context: BlockEntityRendererProvider.Con
poseStack.translate(0.5, 0.5, 0.5) poseStack.translate(0.5, 0.5, 0.5)
poseStack.translate(screenDir.normal * 0.44) poseStack.translate(screenDir.normal * 0.44)
val font = Minecraft.getInstance().font val font = minecraft.font
poseStack.scale(0.01f, 0.01f, 0.01f) poseStack.scale(0.01f, 0.01f, 0.01f)
val sorse = DynamicBufferSource.WORLD
if (screenDir === Direction.DOWN) { if (screenDir === Direction.DOWN) {
poseStack.rotateAroundPoint(poseStack.translation(), inputDir.asAngle().copy(pitch = PI, roll = PI / 2)) poseStack.rotateAroundPoint(poseStack.translation(), inputDir.asAngle().copy(pitch = PI, roll = PI / 2))
} else if (screenDir === Direction.UP) { } else if (screenDir === Direction.UP) {
@ -46,23 +49,21 @@ class EnergyCounterRenderer(private val context: BlockEntityRendererProvider.Con
var y = -16f var y = -16f
val finalX = font.drawAligned(poseStack, "00000000", TextAlign.CENTER_CENTER, -4f, y, RGBAColor.GRAY) val finalX = font.drawAligned(poseStack, sorse, "00000000", TextAlign.CENTER_CENTER, -4f, y, RGBAColor.GRAY)
font.drawAligned(poseStack, "00000000", TextAlign.CENTER_CENTER, -4f, y + font.lineHeight, RGBAColor.GRAY) font.drawAligned(poseStack, sorse, "00000000", TextAlign.CENTER_CENTER, -4f, y + font.lineHeight, RGBAColor.GRAY)
font.drawAligned(poseStack, "/t", TextAlign.CENTER_LEFT, finalX.toFloat(), y, RGBAColor.GRAY) font.drawAligned(poseStack, sorse, "/t", TextAlign.CENTER_LEFT, finalX.toFloat(), y, RGBAColor.GRAY)
font.drawAligned(poseStack, "/s", TextAlign.CENTER_LEFT, finalX.toFloat(), y + font.lineHeight, RGBAColor.GRAY) font.drawAligned(poseStack, sorse, "/s", TextAlign.CENTER_LEFT, finalX.toFloat(), y + font.lineHeight, RGBAColor.GRAY)
poseStack.pushPose() poseStack.pushPose()
poseStack.translate(-0.1, -0.1, -0.1) poseStack.translate(-0.1, -0.1, -0.1)
font.drawAligned(poseStack, tile.lastTick.toString(0), TextAlign.CENTER_RIGHT, finalX.toFloat(), y, RGBAColor.WHITE) font.drawAligned(poseStack, sorse, tile.lastTick.toString(0), TextAlign.CENTER_RIGHT, finalX.toFloat(), y, RGBAColor.WHITE)
font.drawAligned(poseStack, tile.sumHistory(20).toString(0), font.drawAligned(poseStack, sorse, tile.sumHistory(20).toString(0), TextAlign.CENTER_RIGHT, finalX.toFloat(), y + font.lineHeight, RGBAColor.WHITE)
TextAlign.CENTER_RIGHT, finalX.toFloat(), y + font.lineHeight, RGBAColor.WHITE)
poseStack.popPose() poseStack.popPose()
y += font.lineHeight * 3 y += font.lineHeight * 3
font.drawAligned(poseStack, TOTAL, TextAlign.CENTER_CENTER, 0f, y, RGBAColor.WHITE) font.drawAligned(poseStack, sorse, TOTAL, TextAlign.CENTER_CENTER, 0f, y, RGBAColor.WHITE)
font.drawAligned(poseStack, tile.passed.formatPower(), font.drawAligned(poseStack, sorse, tile.passed.formatPower(), TextAlign.CENTER_CENTER, 0f, y + font.lineHeight, RGBAColor.WHITE)
TextAlign.CENTER_CENTER, 0f, y + font.lineHeight, RGBAColor.WHITE)
poseStack.popPose() poseStack.popPose()
} }

View File

@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.GravitationStabilizerBlockEntity import ru.dbotthepony.mc.otm.block.entity.GravitationStabilizerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.core.*
import kotlin.math.PI import kotlin.math.PI
@ -142,11 +143,10 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv
poseStack.scale(0.01f, 0.01f, 0.01f) poseStack.scale(0.01f, 0.01f, 0.01f)
val font = Minecraft.getInstance().font val sorse = DynamicBufferSource.WORLD
font.drawAligned(poseStack, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter()), val font = minecraft.font
TextAlign.TOP_CENTER, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF) font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.mass", bhTile.mass.formatMatter()), TextAlign.TOP_CENTER, 0f, -font.lineHeight.toFloat() / 2f, 0xFFFFFF)
font.drawAligned(poseStack, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), font.drawAligned(poseStack, sorse, TranslatableComponent("otm.3d2d.gravitation_stabilizer.strength", "%.2f".format(bhTile.gravitationStrength)), TextAlign.TOP_CENTER, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF)
TextAlign.TOP_CENTER, 0f, font.lineHeight.toFloat() / 2f, 0xFFFFFF)
poseStack.popPose() poseStack.popPose()
} }