Fix tooltips being wrongly positioned

This commit is contained in:
DBotThePony 2024-01-01 22:41:58 +07:00
parent 7258e1e4d3
commit ad76b4cabc
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -92,15 +92,26 @@ class MGUIGraphics(val pose: PoseStack) {
val preEvent = ForgeHooksClient.onRenderTooltipPre(itemStack, pose, x, y, width, height, mapped, font, font)
if (preEvent.isCanceled) return
var i = 0
var j = if (lines.size == 1) -2 else 0
var totalWidth = 0
var totalHeight = if (lines.size == 1) -2 else 0
for (line in mapped) {
val k = line.getWidth(preEvent.font)
if (k > i) i = k
j += line.height
if (k > totalWidth) totalWidth = k
totalHeight += line.height
}
@Suppress("NAME_SHADOWING")
var x = x + 12
@Suppress("NAME_SHADOWING")
var y = y - 12
if (x + totalWidth >= minecraft.window.guiScaledWidth)
x = (x - 24 - totalWidth).coerceAtLeast(4)
if (y + totalHeight + 3 >= minecraft.window.guiScaledHeight)
y = minecraft.window.guiScaledHeight - totalHeight - 3
pose.pushPose()
val tesselator = Tesselator.getInstance()
val bufferbuilder = tesselator.builder
@ -109,7 +120,7 @@ class MGUIGraphics(val pose: PoseStack) {
val matrix4f = pose.last().pose()
val colorEvent = ForgeHooksClient.onRenderTooltipColor(itemStack, pose, x, y, preEvent.font, mapped)
TooltipRenderUtil.renderTooltipBackground(GuiComponent::fillGradient, matrix4f, bufferbuilder, x, y, i, j, 400, colorEvent.backgroundStart, colorEvent.backgroundEnd, colorEvent.borderStart, colorEvent.borderEnd)
TooltipRenderUtil.renderTooltipBackground(GuiComponent::fillGradient, matrix4f, bufferbuilder, x, y, totalWidth, totalHeight, 400, colorEvent.backgroundStart, colorEvent.backgroundEnd, colorEvent.borderStart, colorEvent.borderEnd)
RenderSystem.enableDepthTest()
RenderSystem.enableBlend()
RenderSystem.defaultBlendFunc()