diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt index dfa97516c..43a8d851e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/MGUIGraphics.kt @@ -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()