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:
parent
ad3fb8be7a
commit
5df5199098
|
@ -1,10 +1,17 @@
|
||||||
package fr.username404.snowygui.config
|
package fr.username404.snowygui.config
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.gui.Element
|
import fr.username404.snowygui.gui.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
|
||||||
open class SnowyConfigScreen: SnowyScreen("screen.snowygui.config") { // TODO Actual config screen
|
open class SnowyConfigScreen: SnowyScreen("screen.snowygui.config") { // TODO Actual config screen
|
||||||
override val components: MutableSet<Element>? = mutableSetOf(
|
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
|
// TODO Add components to the config gui
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.BufferBuilder
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import com.mojang.blaze3d.vertex.Tesselator
|
import com.mojang.blaze3d.vertex.Tesselator
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer
|
import com.mojang.blaze3d.vertex.VertexConsumer
|
||||||
|
import fr.username404.snowygui.Snowy
|
||||||
|
|
||||||
fun interface Renderable { fun render(poseStack: PoseStack?) }
|
fun interface Renderable { fun render(poseStack: PoseStack?) }
|
||||||
abstract class Element(
|
abstract class Element(
|
||||||
|
@ -14,7 +15,16 @@ abstract class Element(
|
||||||
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()
|
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()
|
||||||
@JvmStatic protected val buffer: BufferBuilder = tessellator.builder
|
@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
|
var hidden: Boolean = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue