diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 760c4b946..57dfd0dc0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.utils.renderables.Renderable import io.github.moulberry.moulconfig.internal.TextRenderUtils +import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.Gui @@ -354,6 +355,15 @@ object RenderUtils { return lastValue + (currentValue - lastValue) * multiplier } + + fun Position.transform(): Pair<Int, Int> { + GlStateManager.translate(getAbsX().toFloat(), getAbsY().toFloat(), 0F) + GlStateManager.scale(effectiveScale, effectiveScale, 1F) + val x = ((Utils.getMouseX() - getAbsX()) / effectiveScale).toInt() + val y = ((Utils.getMouseY() - getAbsY()) / effectiveScale).toInt() + return x to y + } + fun Position.renderString(string: String?, offsetX: Int = 0, offsetY: Int = 0, posLabel: String) { if (string == null) return if (string == "") return @@ -364,12 +374,12 @@ object RenderUtils { private fun Position.renderString0(string: String?, offsetX: Int = 0, offsetY: Int = 0): Int { val display = "§f$string" GlStateManager.pushMatrix() - + transform() val minecraft = Minecraft.getMinecraft() val renderer = minecraft.renderManager.fontRenderer - val x = getAbsX() + offsetX - val y = getAbsY() + offsetY + val x = offsetX + val y = offsetY GlStateManager.translate(x + 1.0, y + 1.0, 0.0) renderer.drawStringWithShadow(display, 0f, 0f, 0) @@ -443,15 +453,17 @@ object RenderUtils { private fun Position.renderLine(line: List<Any?>, offsetY: Int, itemScale: Double = 1.0): Int { GlStateManager.pushMatrix() - GlStateManager.translate(getAbsX().toFloat(), (getAbsY() + offsetY).toFloat(), 0F) + val mp = transform() + GlStateManager.translate(0f, offsetY.toFloat(), 0F) var offsetX = 0 - for (any in line) { - val renderable = Renderable.fromAny(any, itemScale = itemScale) - ?: throw RuntimeException("Unknown render object: $any") - - renderable.render(getAbsX() + offsetX, getAbsY() + offsetY) - offsetX += renderable.width - GlStateManager.translate(renderable.width.toFloat(), 0F, 0F) + Renderable.withMousePosition(mp.first, mp.second) { + for (any in line) { + val renderable = Renderable.fromAny(any, itemScale = itemScale) + ?: throw RuntimeException("Unknown render object: $any") + renderable.render(offsetX, offsetY) + offsetX += renderable.width + GlStateManager.translate(renderable.width.toFloat(), 0F, 0F) + } } GlStateManager.popMatrix() return offsetX @@ -972,7 +984,12 @@ object RenderUtils { ) } - fun GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost.drawSlotText(xPos: Int, yPos: Int, text: String, scale: Float) { + fun GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost.drawSlotText( + xPos: Int, + yPos: Int, + text: String, + scale: Float + ) { val fontRenderer = Minecraft.getMinecraft().fontRendererObj GlStateManager.disableLighting() |