diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index e33fbac..f764e13 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -1,8 +1,6 @@ package fr.username404.snowygui.config -import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.ClickGui -import fr.username404.snowygui.utils.FontUtil import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickBox.Companion.buttonsMax import fr.username404.snowygui.gui.elements.ClickBox.Companion.sortAlphabetically @@ -11,6 +9,8 @@ import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.gui.feature.Macro import fr.username404.snowygui.gui.feature.Keystrokes import fr.username404.snowygui.gui.feature.Zoom +import fr.username404.snowygui.utils.FontUtil +import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component.translatable @@ -27,9 +27,9 @@ private fun supplyComponent(string: String?): Optional = string?.run val SnowyConfigScreen: Screen = object: Screen(translationComponent) { override fun isPauseScreen(): Boolean = false - override fun render(poseStack: PoseStack, i: Int, j: Int, f: Float) { - super.renderBackground(poseStack) - FontUtil.drawScaled(poseStack, + override fun render(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) { + super.renderBackground(guiGraphics) + FontUtil.drawScaled(guiGraphics, text = "An appropriate version of the Cloth Config mod is required for the configuration of snowygui.", 16.0, 16.0, color = Colors.WHITE, scaleFactor = 0.85F ) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 79c3980..0b40cb8 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -5,10 +5,11 @@ import fr.username404.snowygui.Snowy import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.utils.RenderingUtil import fr.username404.snowygui.utils.RenderingUtil.colorEnd +import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.components.events.GuiEventListener fun interface Renderable { - fun render(poseStack: PoseStack?) + fun render(guiGraphics: GuiGraphics?) } abstract class Element( @@ -28,13 +29,13 @@ abstract class Element( private var caughtError: Boolean = false fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element { return object: Element(x, y, width, height) { - override fun render(poseStack: PoseStack?) = r.render(poseStack) + override fun render(guiGraphics: GuiGraphics?) = r.render(guiGraphics) } } } - open fun display(stack: PoseStack? = null) { + open fun display(guiGraphics: GuiGraphics? = null) { if (!hidden && !caughtError) try { - render(stack) + render(guiGraphics) } catch (t: Throwable) { with(Snowy.logs) { error("An element from snowy threw an error: \n\t$t") diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt index d2e1d62..50d1670 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt @@ -1,14 +1,14 @@ package fr.username404.snowygui.gui -import com.mojang.blaze3d.vertex.PoseStack +import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component.translatable abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(translatable(translatableString)) { abstract val components: MutableCollection - override fun render(poseStack: PoseStack, i: Int, j: Int, f: Float) { + override fun render(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) { components.forEach { - it.display(poseStack) + it.display(guiGraphics) } } override fun isPauseScreen(): Boolean = willPauseScreen diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index df95d17..6d8b449 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -1,7 +1,6 @@ package fr.username404.snowygui.gui.elements import com.mojang.blaze3d.vertex.DefaultVertexFormat -import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.Snowy.Companion.MissingComponent import fr.username404.snowygui.config.Configuration import com.mojang.blaze3d.vertex.VertexFormat @@ -16,6 +15,7 @@ import fr.username404.snowygui.utils.RenderingUtil.prepareDraw import fr.username404.snowygui.utils.RenderingUtil.tessellator import io.github.config4k.extract import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiGraphics import net.minecraft.network.chat.Component import org.jetbrains.annotations.ApiStatus import java.util.TreeSet @@ -32,9 +32,9 @@ class ClickBox( if (sortAlphabetically) TreeSet(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title }) else LinkedHashSet() - override fun display(stack: PoseStack?) { + override fun display(guiGraphics: GuiGraphics?) { hidden = buttons.isEmpty() || hidden - super.display(stack) + super.display(guiGraphics) } @JvmField @@ -44,7 +44,7 @@ class ClickBox( opacity = 0.75F ) { override val color: Int get() = this@ClickBox.color - override fun render(poseStack: PoseStack?) { + override fun render(guiGraphics: GuiGraphics?) { prepareDraw() colorShader(); defaultRectFunc() endDraw() @@ -76,7 +76,7 @@ class ClickBox( const val clickboxHeightOffset: Int = 80 private const val inclination: Double = 2.5 } - override fun render(poseStack: PoseStack?) { + override fun render(guiGraphics: GuiGraphics?) { val currentHeight = y + (height + clickboxHeightOffset) prepareDraw() with(buffer) { @@ -105,18 +105,16 @@ class ClickBox( buttonsProgressBar.apply { x = this@ClickBox.x + this@ClickBox.width - 3 y = this@ClickBox.y + this@ClickBox.height + 3 - }.display(poseStack) + }.display(guiGraphics) buttons.forEachIndexed { num, button -> val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset) button.also { it.x = x + 3 it.y = y + 3 + height + (((num + 1) - barStage) * 9) it.hidden = if ((num + 1) <= 8) ((it.y) !in fullHeight) else ((it.y + it.height) !in fullHeight) - }.display(poseStack) + }.display(guiGraphics) } } - if (poseStack != null) { - Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, Colors.TRANSPARENT.hexValue) - } + guiGraphics?.drawString(Minecraft.getInstance().font, name.string, (x + 5).toInt(), (y + 2).toInt(), Colors.TRANSPARENT.hexValue, false) } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 818ce2f..558c601 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -1,15 +1,15 @@ package fr.username404.snowygui.gui.feature -import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.ClickGui import fr.username404.snowygui.Snowy import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.ColoredElement -import fr.username404.snowygui.utils.FontUtil import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type +import fr.username404.snowygui.utils.FontUtil +import fr.username404.snowygui.utils.RenderingUtil.colorShader import fr.username404.snowygui.utils.RenderingUtil.endDraw import fr.username404.snowygui.utils.RenderingUtil.prepareDraw -import fr.username404.snowygui.utils.RenderingUtil.colorShader +import net.minecraft.client.gui.GuiGraphics import kotlin.reflect.full.findAnnotation sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { @@ -90,12 +90,12 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { lightDown() }; return false } - final override fun render(poseStack: PoseStack?) { + final override fun render(guiGraphics: GuiGraphics?) { prepareDraw() colorShader(); defaultRectFunc() endDraw() - if (poseStack != null) { - FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F) + if (guiGraphics != null) { + FontUtil.drawScaled(guiGraphics, title, x + 1, y + 1, 0.75F) } } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt index 3346a94..6387776 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImplWithHud.kt @@ -1,13 +1,13 @@ package fr.username404.snowygui.gui.feature -import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.argsLambda import fr.username404.snowygui.gui.Renderable +import net.minecraft.client.gui.GuiGraphics sealed class ButtonImplWithHud: ButtonImpl() { protected abstract val hudRenderLambda: Renderable - private val generatedLambda: argsLambda = { hudRenderLambda.render(it.first() as PoseStack?) } + private val generatedLambda: argsLambda = { hudRenderLambda.render(it.first() as GuiGraphics?) } final override fun execAction() { EventSnowy["HudRender"].run { if (toggled) add(generatedLambda) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Keystrokes.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Keystrokes.kt index 56b9762..644d887 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Keystrokes.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Keystrokes.kt @@ -7,6 +7,7 @@ import fr.username404.snowygui.gui.Renderable import fr.username404.snowygui.utils.FontUtil import fr.username404.snowygui.utils.RenderingUtil import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiGraphics @ButtonInfo(Category.HUD) object Keystrokes: ButtonImplWithHud() { @@ -41,14 +42,14 @@ object Keystrokes: ButtonImplWithHud() { return dynamicOpacity[i] } - private fun drawKey(x: Double, y: Double, key: Int, poseStack: PoseStack? = null) { + private fun drawKey(x: Double, y: Double, key: Int, guiGraphics: GuiGraphics?) { RenderingUtil.prepareDraw() RenderingUtil.drawRectangle( x, y, height / 2, height / 2, color = color, opacity = getDynamicOpacity(key).toFloat() ) RenderingUtil.endDraw() - poseStack?.let { + guiGraphics?.let { FontUtil.drawScaled( it, keysArray.first[key].translatedKeyMessage.string.uppercase(), x + height.toDouble() / 5.5, y + height.toDouble() / 6.5, @@ -57,11 +58,11 @@ object Keystrokes: ButtonImplWithHud() { } } private fun getNewPos(i: Int) = x + (i * (2 + (height / 2))) - override fun render(poseStack: PoseStack?) = with(RenderingUtil) { + override fun render(guiGraphics: GuiGraphics?) = with(RenderingUtil) { for (i in 0 until 3) { - drawKey(getNewPos(i), y, i, poseStack) + drawKey(getNewPos(i), y, i, guiGraphics) } - drawKey(getNewPos(1), y - (height / 2) - 2, 3, poseStack) + drawKey(getNewPos(1), y - (height / 2) - 2, 3, guiGraphics) } } override val hudRenderLambda = Renderable { diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt index f74e683..8e275f4 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt @@ -1,13 +1,14 @@ package fr.username404.snowygui.utils -import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.Minecraft import fr.username404.snowygui.gui.feature.Colors +import net.minecraft.client.gui.GuiGraphics object FontUtil { - fun drawScaled(stack: PoseStack, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) { + fun drawScaled(guiGraphics: GuiGraphics, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) { + val stack = guiGraphics.pose() stack.scale(scaleFactor, scaleFactor, scaleFactor) - Minecraft.getInstance().font.draw(stack, text, (x / scaleFactor).toFloat(), (y / scaleFactor).toFloat(), color.hexValue) + guiGraphics.drawString(Minecraft.getInstance().font, text, (x / scaleFactor).toInt(), (y / scaleFactor).toInt(), color.hexValue, false) val factorToOriginal = 1F / scaleFactor stack.scale(factorToOriginal, factorToOriginal, factorToOriginal) } diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index 3fed76b..7b08c35 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -8,6 +8,7 @@ import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT import net.fabricmc.loader.api.FabricLoader +import net.minecraft.client.gui.GuiGraphics import kotlin.io.path.exists import kotlin.io.path.isDirectory import kotlin.io.path.listDirectoryEntries @@ -20,7 +21,7 @@ class FabricInit: Snowy(), ClientModInitializer { EVENT.register( object: HudRenderCallback, EventSnowy { override val type: String = "HudRender" - override fun onHudRender(matrixStack: PoseStack?, tickDelta: Float) = fire(matrixStack) + override fun onHudRender(guiGraphics: GuiGraphics?, tickDelta: Float) = fire(guiGraphics) } ) } diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt index 3ad498e..079bcbe 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt @@ -8,6 +8,6 @@ object HudHandler: EventSnowy { override val type: String = "HudRender" @SubscribeEvent fun handleRendering(event: RenderGuiEvent.Post) { - fire(event.poseStack) + fire(event.guiGraphics) } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1f3f56d..86ce927 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,16 +7,16 @@ org.gradle.parallel=true org.gradle.unsafe.configuration-cache=on org.gradle.vfs.watch=true -minecraft=1.19.4 -forge_version=45.0 -kotlinforforge=4.1.0 -kotlinVer=1.8.20 -kotlin_coroutines_version=1.7.0-RC -serializationVer=1.5.0 +minecraft=1.20 +forge_version=46.0 +kotlinforforge=4.3.0 +kotlinVer=1.8.22 +kotlin_coroutines_version=1.7.1 +serializationVer=1.5.1 fabric_loader_version=0.14.19 -fabric_language_kotlin=1.9.3+kotlin.1.8.20 -fabric_resource_loader_version=0.11.4+bd913b0d4e -fabric_rendering_api_version=2.1.1+8f878217f4 -fabric_api_base_version=0.4.5+ec94c6f6e0 -clothconfig_version=10.0.96 -modmenu_version=6.2.1 +fabric_language_kotlin=1.9.5+kotlin.1.8.22 +fabric_resource_loader_version=0.11.7+f7923f6d27 +fabric_rendering_api_version=3.0.6+b3afc78b27 +fabric_api_base_version=0.4.29+b04edc7a27 +clothconfig_version=11.0.99 +modmenu_version=7.0.0