From 5df5199098e1ca493d9550bfb023140be5266a93 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Tue, 13 Apr 2021 10:48:33 +0200 Subject: [PATCH] Add a try and catch in the Element.display() method, and add an element to render a background in the config screen --- .../fr/username404/snowygui/config/ConfigScreen.kt | 7 +++++++ .../kotlin/fr/username404/snowygui/gui/Element.kt | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 b9882e0..4e505ed 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -1,10 +1,17 @@ package fr.username404.snowygui.config +import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.SnowyScreen +import net.minecraft.client.Minecraft open class SnowyConfigScreen: SnowyScreen("screen.snowygui.config") { // TODO Actual config screen override val components: MutableSet? = mutableSetOf( + object: Element(0.0, 0.0, Minecraft.getInstance().window.width, Minecraft.getInstance().window.height) { + override fun render(poseStack: PoseStack?) { + renderBackground(poseStack) + } + } // TODO Add components to the config gui ) } \ No newline at end of file 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 213d3e8..bfb3399 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.Tesselator import com.mojang.blaze3d.vertex.VertexConsumer +import fr.username404.snowygui.Snowy fun interface Renderable { fun render(poseStack: PoseStack?) } abstract class Element( @@ -14,7 +15,16 @@ abstract class Element( @JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance() @JvmStatic protected val buffer: BufferBuilder = tessellator.builder } - fun display(stack: PoseStack? = null) { if (!hidden) render(stack) } + fun display(stack: PoseStack? = null) { + if (!hidden) try { + render(stack) + } catch (t: Throwable) { + with(Snowy.logs) { + error("Caught an error when rendering an Element from SnowyGUI:") + catching(t) + } + } + } var hidden: Boolean = false }