From 3f33928c8fefe4816af9d538fa3fce48d5e76f7c Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Mon, 24 Nov 2025 21:49:16 +0100 Subject: feat(recipe viewer): moulconfig widget --- src/main/kotlin/util/MoulConfigUtils.kt | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/util') diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt index c0c7ef5..0c65e69 100644 --- a/src/main/kotlin/util/MoulConfigUtils.kt +++ b/src/main/kotlin/util/MoulConfigUtils.kt @@ -26,6 +26,7 @@ import kotlin.time.Duration.Companion.seconds import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.screens.Screen import com.mojang.blaze3d.platform.InputConstants +import me.shedaniel.math.Rectangle import net.minecraft.network.chat.Component import moe.nea.firmament.gui.BarComponent import moe.nea.firmament.gui.FirmButtonComponent @@ -292,7 +293,22 @@ object MoulConfigUtils { return component.mouseEvent(mouseEvent, immContext.translated(x, y, w, h)) } - fun createInPlaceFullContext(drawContext: GuiGraphics?, mouseX: Int, mouseY: Int): GuiImmediateContext { + fun createAndTranslateFullContext( + drawContext: GuiGraphics?, + mouseX: Number, mouseY: Number, + rectangle: Rectangle, + block: (GuiImmediateContext) -> T + ): T { + val ctx = createInPlaceFullContext(drawContext, mouseX, mouseY) + val pose = drawContext?.pose() + pose?.pushMatrix() + pose?.translate(rectangle.x.toFloat(), rectangle.y.toFloat()) + val result = block(ctx.translated(rectangle.x, rectangle.y, rectangle.width, rectangle.height)) + pose?.popMatrix() + return result + } + + fun createInPlaceFullContext(drawContext: GuiGraphics?, mouseX: Number, mouseY: Number): GuiImmediateContext { ErrorUtil.softCheck( "created moulconfig context with pre-existing translations.", drawContext?.isUntranslatedGuiDrawContext() != false @@ -302,8 +318,8 @@ object MoulConfigUtils { val immContext = GuiImmediateContext( context, 0, 0, 0, 0, - mouseX, mouseY, - mouseX, mouseY, + mouseX.toInt(), mouseY.toInt(), + mouseX.toInt(), mouseY.toInt(), mouseX.toFloat(), mouseY.toFloat() ) -- cgit