Add a try and catch in the Element.display() method, and add an element to render a background in the config screen

This commit is contained in:
Username404-59 2021-04-13 10:48:33 +02:00
parent ad3fb8be7a
commit 5df5199098
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 18 additions and 1 deletions

View File

@ -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<Element>? = 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
)
}

View File

@ -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
}