diff options
Diffstat (limited to 'src/main/kotlin')
3 files changed, 67 insertions, 4 deletions
diff --git a/src/main/kotlin/features/items/recipes/MoulConfigWidget.kt b/src/main/kotlin/features/items/recipes/MoulConfigWidget.kt new file mode 100644 index 0000000..aad3bda --- /dev/null +++ b/src/main/kotlin/features/items/recipes/MoulConfigWidget.kt @@ -0,0 +1,46 @@ +package moe.nea.firmament.features.items.recipes + +import io.github.notenoughupdates.moulconfig.gui.GuiComponent +import io.github.notenoughupdates.moulconfig.gui.MouseEvent +import me.shedaniel.math.Dimension +import me.shedaniel.math.Point +import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.input.MouseButtonEvent +import moe.nea.firmament.util.MoulConfigUtils.createAndTranslateFullContext + +class MoulConfigWidget( + val component: GuiComponent, + override var position: Point, + override val size: Dimension, +) : RecipeWidget() { + override fun render( + guiGraphics: GuiGraphics, + mouseX: Int, + mouseY: Int, + partialTick: Float + ) { + createAndTranslateFullContext( + guiGraphics, mouseX, mouseY, rect, + component::render + ) + } + + override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean { + return createAndTranslateFullContext(null, event.x.toInt(), event.y.toInt(), rect) { + component.mouseEvent(MouseEvent.Click(event.button(), true), it) + } + } + + override fun mouseMoved(mouseX: Double, mouseY: Double) { + createAndTranslateFullContext(null, mouseX, mouseY, rect) { + component.mouseEvent(MouseEvent.Move(0F, 0F), it) + } + } + + override fun mouseReleased(event: MouseButtonEvent): Boolean { + return createAndTranslateFullContext(null, event.x, event.y, rect) { + component.mouseEvent(MouseEvent.Click(event.button(), false), it) + } + } + +} diff --git a/src/main/kotlin/features/items/recipes/StandaloneRecipeRenderer.kt b/src/main/kotlin/features/items/recipes/StandaloneRecipeRenderer.kt index fb11592..5a834eb 100644 --- a/src/main/kotlin/features/items/recipes/StandaloneRecipeRenderer.kt +++ b/src/main/kotlin/features/items/recipes/StandaloneRecipeRenderer.kt @@ -1,6 +1,7 @@ package moe.nea.firmament.features.items.recipes import io.github.notenoughupdates.moulconfig.gui.GuiComponent +import me.shedaniel.math.Dimension import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import net.minecraft.client.gui.components.events.AbstractContainerEventHandler @@ -58,7 +59,7 @@ class StandaloneRecipeRenderer(val bounds: Rectangle) : AbstractContainerEventHa h: Int, component: GuiComponent ) { - TODO("Not yet implemented") + addWidget(MoulConfigWidget(component, Point(x, y), Dimension(w, h))) } override fun createFire(point: Point, animationTicks: Int) { 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 <T> 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() ) |
