From 29e87b8633fed89d0ef8e425fd6bfde6b4772eb4 Mon Sep 17 00:00:00 2001 From: ttttdoy Date: Thu, 29 Aug 2024 17:31:44 -0400 Subject: [PATCH] huh?? --- .../client/render/SoundBlockRenderer.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/breadmod/client/render/SoundBlockRenderer.kt b/src/main/kotlin/breadmod/client/render/SoundBlockRenderer.kt index 91a839c3..f4771dd4 100644 --- a/src/main/kotlin/breadmod/client/render/SoundBlockRenderer.kt +++ b/src/main/kotlin/breadmod/client/render/SoundBlockRenderer.kt @@ -1,7 +1,6 @@ package breadmod.client.render import breadmod.block.entity.SoundBlockEntity -import breadmod.util.render.drawCenteredTextOnSide import breadmod.util.render.drawTextOnSide import breadmod.util.render.rgMinecraft import com.mojang.blaze3d.vertex.PoseStack @@ -9,7 +8,7 @@ import net.minecraft.Util import net.minecraft.client.renderer.MultiBufferSource import net.minecraft.client.renderer.blockentity.BlockEntityRenderer import net.minecraft.network.chat.Component -import net.minecraft.util.Mth +import net.minecraft.util.Mth.lerp import kotlin.math.cos import kotlin.math.max import kotlin.math.sin @@ -24,34 +23,39 @@ internal class SoundBlockRenderer : BlockEntityRenderer { pPackedOverlay: Int ) { // TODO split into render general - val pText = Component.literal("dummy") + val pText = Component.literal("dummydummydummydummy") val pMinX = 0 - val pMaxX = 100 + val pMaxX = 12 + + // is line height needed here? val pMinY = 0 val pMaxY = rgMinecraft.font.lineHeight - val i: Int = rgMinecraft.font.width(pText) - val j: Int = (pMinY + pMaxY - 9) / 2 + 1 - val k: Int = pMaxX - pMinX - if (i > k) { - val l = i - k - val d0 = Util.getMillis().toDouble() / 1000.0 - val d1 = max(l.toDouble() * 0.5, 3.0) - val d2 = sin((Math.PI / 2.0) * cos((Math.PI * 2.0) * d0 / d1)) / 2.0 + 0.5 - val d3 = Mth.lerp(d2, 0.0, l.toDouble()) + val textWidth: Int = pText.string.length + val yPos: Int = (pMinY + pMaxY - 9) / 2 + val maxWidth: Int = pMaxX - pMinX + if (textWidth > maxWidth) { + val scrollAmount = pText.string.length.toDouble() / 20.0 + val scrollSpeed = Util.getMillis().toDouble() / 1000.0 + // scroll delta? the math that smooths out the scrolling? + val d1 = max(scrollAmount * 0.5, 3.0) + // the thing that smoothly scrolls it forward and back + val d2 = sin((Math.PI / 2.0) * cos((Math.PI * 2.0) * scrollSpeed / d1)) / 2.0 + 0.5 + // does this even do anything? I replaced it with d2 in posX, yet it didn't change the scrolling + val d3 = lerp(d2, 0.0, scrollAmount) // pGuiGraphics.enableScissor(pMinX, pMinY, pMaxX, pMaxY) drawTextOnSide( rgMinecraft.font, pText, - pMinX - d3, j.toDouble(), + pMinX - d2, yPos.toDouble(), pPoseStack = pPoseStack, pBuffer = pBuffer, pBlockState = pBlockEntity.blockState, pScale = 0.0105f ) // pGuiGraphics.disableScissor() } else { - drawCenteredTextOnSide( + drawTextOnSide( rgMinecraft.font, pText, - (pMinX + pMaxX) / 2.0, j.toDouble(), + 0.0, yPos.toDouble(), pPoseStack = pPoseStack, pBuffer = pBuffer, pBlockState = pBlockEntity.blockState, pScale = 0.0105f