diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-07-28 19:52:18 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-07-28 19:52:18 +0200 |
| commit | 80d97bb0de46b1b0cefd8a5bd1ba22105ee08a50 (patch) | |
| tree | f4f361e7397d0f743429bff824664b09ab4a0748 /src/main/kotlin/util | |
| parent | 32e1b1176b4230e3e76145c1fec7f13f705cb6a7 (diff) | |
| download | Firmament-80d97bb0de46b1b0cefd8a5bd1ba22105ee08a50.tar.gz Firmament-80d97bb0de46b1b0cefd8a5bd1ba22105ee08a50.tar.bz2 Firmament-80d97bb0de46b1b0cefd8a5bd1ba22105ee08a50.zip | |
feat: update to new moulconfig version
Diffstat (limited to 'src/main/kotlin/util')
| -rw-r--r-- | src/main/kotlin/util/FragmentGuiScreen.kt | 2 | ||||
| -rw-r--r-- | src/main/kotlin/util/MC.kt | 4 | ||||
| -rw-r--r-- | src/main/kotlin/util/MoulConfigFragment.kt | 69 | ||||
| -rw-r--r-- | src/main/kotlin/util/MoulConfigUtils.kt | 16 | ||||
| -rw-r--r-- | src/main/kotlin/util/render/FacingThePlayerContext.kt | 17 | ||||
| -rw-r--r-- | src/main/kotlin/util/render/RenderCircleProgress.kt | 35 | ||||
| -rw-r--r-- | src/main/kotlin/util/render/RenderInWorldContext.kt | 9 |
7 files changed, 74 insertions, 78 deletions
diff --git a/src/main/kotlin/util/FragmentGuiScreen.kt b/src/main/kotlin/util/FragmentGuiScreen.kt index c4d9ac0..de53ac0 100644 --- a/src/main/kotlin/util/FragmentGuiScreen.kt +++ b/src/main/kotlin/util/FragmentGuiScreen.kt @@ -61,7 +61,7 @@ abstract class FragmentGuiScreen( return ifPopup { if (!Rectangle( it.position, - Dimension(it.context.root.width, it.context.root.height) + Dimension(it.guiContext.root.width, it.guiContext.root.height) ).contains(Point(mouseX, mouseY)) && dismissOnOutOfBounds ) { diff --git a/src/main/kotlin/util/MC.kt b/src/main/kotlin/util/MC.kt index d597beb..7ab0cbb 100644 --- a/src/main/kotlin/util/MC.kt +++ b/src/main/kotlin/util/MC.kt @@ -1,7 +1,7 @@ package moe.nea.firmament.util import io.github.moulberry.repo.data.Coordinate -import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper +import io.github.notenoughupdates.moulconfig.platform.MoulConfigScreenComponent import java.util.concurrent.ConcurrentLinkedQueue import kotlin.jvm.optionals.getOrNull import net.minecraft.client.MinecraftClient @@ -131,7 +131,7 @@ object MC { private set val currentMoulConfigContext - get() = (screen as? GuiComponentWrapper)?.context + get() = (screen as? MoulConfigScreenComponent)?.guiContext fun openUrl(uri: String) { Util.getOperatingSystem().open(uri) diff --git a/src/main/kotlin/util/MoulConfigFragment.kt b/src/main/kotlin/util/MoulConfigFragment.kt index 1aaea0a..7e7f5db 100644 --- a/src/main/kotlin/util/MoulConfigFragment.kt +++ b/src/main/kotlin/util/MoulConfigFragment.kt @@ -1,44 +1,43 @@ - - package moe.nea.firmament.util -import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper import io.github.notenoughupdates.moulconfig.gui.GuiContext import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext +import io.github.notenoughupdates.moulconfig.platform.MoulConfigScreenComponent import me.shedaniel.math.Point import net.minecraft.client.gui.DrawContext +import net.minecraft.text.Text class MoulConfigFragment( - context: GuiContext, - val position: Point, - val dismiss: () -> Unit -) : GuiComponentWrapper(context) { - init { - this.init(MC.instance, MC.screen!!.width, MC.screen!!.height) - } - - override fun createContext(drawContext: DrawContext?): GuiImmediateContext { - val oldContext = super.createContext(drawContext) - return oldContext.translated( - position.x, - position.y, - context.root.width, - context.root.height, - ) - } - - - override fun render(drawContext: DrawContext?, i: Int, j: Int, f: Float) { - val ctx = createContext(drawContext) - val m = drawContext!!.matrices - m.pushMatrix() - m.translate(position.x.toFloat(), position.y.toFloat()) - context.root.render(ctx) - m.popMatrix() - ctx.renderContext.renderExtraLayers() - } - - override fun close() { - dismiss() - } + context: GuiContext, + val position: Point, + val dismiss: () -> Unit +) : MoulConfigScreenComponent(Text.empty(), context, null) { + init { + this.init(MC.instance, MC.screen!!.width, MC.screen!!.height) + } + + override fun createContext(drawContext: DrawContext?): GuiImmediateContext { + val oldContext = super.createContext(drawContext) + return oldContext.translated( + position.x, + position.y, + guiContext.root.width, + guiContext.root.height, + ) + } + + + override fun render(drawContext: DrawContext, i: Int, j: Int, f: Float) { + val ctx = createContext(drawContext) + val m = drawContext.matrices + m.pushMatrix() + m.translate(position.x.toFloat(), position.y.toFloat()) + guiContext.root.render(ctx) + m.popMatrix() + ctx.renderContext.renderExtraLayers() + } + + override fun close() { + dismiss() + } } diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt index 90cfb3a..2f2fd5c 100644 --- a/src/main/kotlin/util/MoulConfigUtils.kt +++ b/src/main/kotlin/util/MoulConfigUtils.kt @@ -4,13 +4,14 @@ import io.github.notenoughupdates.moulconfig.common.IMinecraft import io.github.notenoughupdates.moulconfig.common.MyResourceLocation import io.github.notenoughupdates.moulconfig.gui.CloseEventListener import io.github.notenoughupdates.moulconfig.gui.GuiComponent -import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper import io.github.notenoughupdates.moulconfig.gui.GuiContext import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent import io.github.notenoughupdates.moulconfig.gui.MouseEvent import io.github.notenoughupdates.moulconfig.observer.GetSetter -import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext +import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform +import io.github.notenoughupdates.moulconfig.platform.MoulConfigRenderContext +import io.github.notenoughupdates.moulconfig.platform.MoulConfigScreenComponent import io.github.notenoughupdates.moulconfig.xml.ChildCount import io.github.notenoughupdates.moulconfig.xml.XMLContext import io.github.notenoughupdates.moulconfig.xml.XMLGuiLoader @@ -26,6 +27,7 @@ import kotlin.time.Duration.Companion.seconds import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.screen.Screen import net.minecraft.client.util.InputUtil +import net.minecraft.text.Text import moe.nea.firmament.gui.BarComponent import moe.nea.firmament.gui.FirmButtonComponent import moe.nea.firmament.gui.FirmHoverComponent @@ -226,9 +228,9 @@ object MoulConfigUtils { } fun wrapScreen(guiContext: GuiContext, parent: Screen?, onClose: () -> Unit = {}): Screen { - return object : GuiComponentWrapper(guiContext) { + return object : MoulConfigScreenComponent(Text.empty(), guiContext, null) { override fun close() { - if (context.onBeforeClose() == CloseEventListener.CloseAction.NO_OBJECTIONS_TO_CLOSE) { + if (guiContext.onBeforeClose() == CloseEventListener.CloseAction.NO_OBJECTIONS_TO_CLOSE) { client!!.setScreen(parent) onClose() } @@ -264,7 +266,7 @@ object MoulConfigUtils { h: Int, keyboardEvent: KeyboardEvent ): Boolean { - val immContext = createInPlaceFullContext(null, IMinecraft.instance.mouseX, IMinecraft.instance.mouseY) + val immContext = createInPlaceFullContext(null, IMinecraft.INSTANCE.mouseX, IMinecraft.INSTANCE.mouseY) if (component.keyboardEvent(keyboardEvent, immContext.translated(x, y, w, h))) return true if (component.context.getFocusedElement() != null) { @@ -296,8 +298,8 @@ object MoulConfigUtils { "created moulconfig context with pre-existing translations.", drawContext?.isUntranslatedGuiDrawContext() != false ) - val context = drawContext?.let(::ModernRenderContext) - ?: IMinecraft.instance.provideTopLevelRenderContext() + val context = drawContext?.let(::MoulConfigRenderContext) + ?: IMinecraft.INSTANCE.provideTopLevelRenderContext() val immContext = GuiImmediateContext( context, 0, 0, 0, 0, diff --git a/src/main/kotlin/util/render/FacingThePlayerContext.kt b/src/main/kotlin/util/render/FacingThePlayerContext.kt index 0e5788a..76270c5 100644 --- a/src/main/kotlin/util/render/FacingThePlayerContext.kt +++ b/src/main/kotlin/util/render/FacingThePlayerContext.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.util.render -import io.github.notenoughupdates.moulconfig.platform.next import org.joml.Matrix4f import util.render.CustomRenderLayers import net.minecraft.client.font.TextRenderer @@ -41,14 +40,14 @@ class FacingThePlayerContext(val worldContext: RenderInWorldContext) { worldContext.vertexConsumers.getBuffer(RenderLayer.getTextBackgroundSeeThrough()) val matrix4f = worldContext.matrixStack.peek().positionMatrix vertexConsumer.vertex(matrix4f, -1.0f, -1.0f, 0.0f).color(background) - .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next() + .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE) vertexConsumer.vertex(matrix4f, -1.0f, MC.font.fontHeight.toFloat(), 0.0f).color(background) - .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next() + .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE) vertexConsumer.vertex(matrix4f, width.toFloat(), MC.font.fontHeight.toFloat(), 0.0f) .color(background) - .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next() + .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE) vertexConsumer.vertex(matrix4f, width.toFloat(), -1.0f, 0.0f).color(background) - .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE).next() + .light(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE) worldContext.matrixStack.translate(0F, 0F, 0.01F) MC.font.draw( @@ -79,16 +78,16 @@ class FacingThePlayerContext(val worldContext: RenderInWorldContext) { val matrix4f: Matrix4f = worldContext.matrixStack.peek().positionMatrix buf.vertex(matrix4f, -hw, -hh, 0F) .color(-1) - .texture(u1, v1).next() + .texture(u1, v1) buf.vertex(matrix4f, -hw, +hh, 0F) .color(-1) - .texture(u1, v2).next() + .texture(u1, v2) buf.vertex(matrix4f, +hw, +hh, 0F) .color(-1) - .texture(u2, v2).next() + .texture(u2, v2) buf.vertex(matrix4f, +hw, -hh, 0F) .color(-1) - .texture(u2, v1).next() + .texture(u2, v1) worldContext.vertexConsumers.draw() } diff --git a/src/main/kotlin/util/render/RenderCircleProgress.kt b/src/main/kotlin/util/render/RenderCircleProgress.kt index 2c875f8..efd99fe 100644 --- a/src/main/kotlin/util/render/RenderCircleProgress.kt +++ b/src/main/kotlin/util/render/RenderCircleProgress.kt @@ -1,9 +1,6 @@ package moe.nea.firmament.util.render -import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.VertexFormat -import io.github.notenoughupdates.moulconfig.platform.next -import java.util.OptionalInt import org.joml.Matrix3x2f import util.render.CustomRenderLayers import net.minecraft.client.gui.DrawContext @@ -14,6 +11,7 @@ import net.minecraft.util.Identifier import moe.nea.firmament.util.MC import moe.nea.firmament.util.collections.nonNegligibleSubSectionsAlignedWith import moe.nea.firmament.util.math.Projections +import moe.nea.firmament.util.mc.CustomRenderPassHelper object RenderCircleProgress { @@ -27,7 +25,7 @@ object RenderCircleProgress { angleRadians: ClosedFloatingPointRange<Float>, color: Int = -1, innerCutoutRadius: Float = 0F - ) { + ) { // TODO: this is fixed by adding a special gui element renderer val sections = angleRadians.nonNegligibleSubSectionsAlignedWith((τ / 8f).toFloat()) .zipWithNext().toList() BufferAllocator(layer.vertexFormat.vertexSize * sections.size * 3).use { allocator -> @@ -45,38 +43,37 @@ object RenderCircleProgress { .vertex(matrix, secondPoint.x, secondPoint.y, 0F) .texture(lerp(u1, u2, ilerp(secondPoint.x)), lerp(v1, v2, ilerp(secondPoint.y))) .color(color) - .next() + bufferBuilder .vertex(matrix, firstPoint.x, firstPoint.y, 0F) .texture(lerp(u1, u2, ilerp(firstPoint.x)), lerp(v1, v2, ilerp(firstPoint.y))) .color(color) - .next() + bufferBuilder .vertex(matrix, 0F, 0F, 0F) .texture(lerp(u1, u2, ilerp(0F)), lerp(v1, v2, ilerp(0F))) .color(color) - .next() + } bufferBuilder.end().use { buffer -> - // TODO: write a better utility to pass uniforms :sob: ill even take a mixin at this point if (innerCutoutRadius <= 0) { layer.draw(buffer) return } - val vertexBuffer = layer.vertexFormat.uploadImmediateVertexBuffer(buffer.buffer) - val indexBufferConstructor = RenderSystem.getSequentialBuffer(VertexFormat.DrawMode.TRIANGLES) - val indexBuffer = indexBufferConstructor.getIndexBuffer(buffer.drawParameters.indexCount) - RenderSystem.getDevice().createCommandEncoder().createRenderPass( - { "Firmament Circle Renderer" }, - MC.instance.framebuffer.colorAttachmentView, - OptionalInt.empty(), + CustomRenderPassHelper( + { "RenderCircleProgress" }, + VertexFormat.DrawMode.TRIANGLES, + layer.vertexFormat, + MC.instance.framebuffer, + false, ).use { renderPass -> + renderPass.uploadVertices(buffer) renderPass.setPipeline(layer.pipeline) -// renderPass.setUniform("InnerCutoutRadius", innerCutoutRadius) - renderPass.setIndexBuffer(indexBuffer, indexBufferConstructor.indexType) - renderPass.setVertexBuffer(0, vertexBuffer) - renderPass.drawIndexed(0, 0, buffer.drawParameters.indexCount, 1) + renderPass.setUniform("InnerCutoutRadius", 4) { + it.putFloat(innerCutoutRadius) + } + renderPass.draw() } } } diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt index 29a387b..1077060 100644 --- a/src/main/kotlin/util/render/RenderInWorldContext.kt +++ b/src/main/kotlin/util/render/RenderInWorldContext.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem -import io.github.notenoughupdates.moulconfig.platform.next import java.lang.Math.pow import org.joml.Matrix4f import org.joml.Vector3f @@ -146,11 +145,11 @@ class RenderInWorldContext private constructor( buffer.vertex(matrix.positionMatrix, a.x.toFloat(), a.y.toFloat(), a.z.toFloat()) .color(-1) .normal(matrix, lastNormal0.x, lastNormal0.y, lastNormal0.z) - .next() + buffer.vertex(matrix.positionMatrix, b.x.toFloat(), b.y.toFloat(), b.z.toFloat()) .color(-1) .normal(matrix, normal.x, normal.y, normal.z) - .next() + } } @@ -173,11 +172,11 @@ class RenderInWorldContext private constructor( buf.vertex(matrix.positionMatrix, i, j, k) .normal(matrix, normal.x, normal.y, normal.z) .color(-1) - .next() + buf.vertex(matrix.positionMatrix, x, y, z) .normal(matrix, normal.x, normal.y, normal.z) .color(-1) - .next() + } |
