Skip to content

Commit

Permalink
huh??
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Aug 29, 2024
1 parent 58d29b9 commit 29e87b8
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main/kotlin/breadmod/client/render/SoundBlockRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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
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
Expand All @@ -24,34 +23,39 @@ internal class SoundBlockRenderer : BlockEntityRenderer<SoundBlockEntity> {
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
Expand Down

0 comments on commit 29e87b8

Please sign in to comment.