Fix tooltips being wrongly positioned
This commit is contained in:
parent
7258e1e4d3
commit
ad76b4cabc
@ -92,15 +92,26 @@ class MGUIGraphics(val pose: PoseStack) {
|
|||||||
val preEvent = ForgeHooksClient.onRenderTooltipPre(itemStack, pose, x, y, width, height, mapped, font, font)
|
val preEvent = ForgeHooksClient.onRenderTooltipPre(itemStack, pose, x, y, width, height, mapped, font, font)
|
||||||
|
|
||||||
if (preEvent.isCanceled) return
|
if (preEvent.isCanceled) return
|
||||||
var i = 0
|
var totalWidth = 0
|
||||||
var j = if (lines.size == 1) -2 else 0
|
var totalHeight = if (lines.size == 1) -2 else 0
|
||||||
|
|
||||||
for (line in mapped) {
|
for (line in mapped) {
|
||||||
val k = line.getWidth(preEvent.font)
|
val k = line.getWidth(preEvent.font)
|
||||||
if (k > i) i = k
|
if (k > totalWidth) totalWidth = k
|
||||||
j += line.height
|
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()
|
pose.pushPose()
|
||||||
val tesselator = Tesselator.getInstance()
|
val tesselator = Tesselator.getInstance()
|
||||||
val bufferbuilder = tesselator.builder
|
val bufferbuilder = tesselator.builder
|
||||||
@ -109,7 +120,7 @@ class MGUIGraphics(val pose: PoseStack) {
|
|||||||
val matrix4f = pose.last().pose()
|
val matrix4f = pose.last().pose()
|
||||||
val colorEvent = ForgeHooksClient.onRenderTooltipColor(itemStack, pose, x, y, preEvent.font, mapped)
|
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.enableDepthTest()
|
||||||
RenderSystem.enableBlend()
|
RenderSystem.enableBlend()
|
||||||
RenderSystem.defaultBlendFunc()
|
RenderSystem.defaultBlendFunc()
|
||||||
|
Loading…
Reference in New Issue
Block a user