Add a try and catch in the render function of ClickBox.kt.

This commit is contained in:
Username404-59 2021-04-12 23:44:15 +02:00
parent 25a37898ad
commit ad3fb8be7a
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 21 additions and 16 deletions

View File

@ -3,6 +3,7 @@ package fr.username404.snowygui.gui
import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.DefaultVertexFormat
import com.mojang.blaze3d.vertex.PoseStack
import fr.username404.snowygui.Snowy
import net.minecraft.client.Minecraft
import net.minecraft.network.chat.TranslatableComponent
import org.lwjgl.opengl.GL20
@ -16,24 +17,28 @@ class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? =
RenderSystem.enableBlend()
RenderSystem.defaultBlendFunc()
with(buffer) {
begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR)
// Render the header:
vertex(x, y + height, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
vertex(x + width, y, 0.0).colorEnd()
vertex(x + inclination, y, 0.0).colorEnd()
try {
begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR)
// Render the header:
vertex(x, y + height, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
vertex(x + width, y, 0.0).colorEnd()
vertex(x + inclination, y, 0.0).colorEnd()
// Render the box:
val fullHeight = (y + height) + 80
vertex(x, fullHeight, 0.0).colorEnd()
vertex(x + width + inclination, fullHeight, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
tessellator.end()
// Render the box:
val fullHeight = (y + height) + 80
vertex(x, fullHeight, 0.0).colorEnd()
vertex(x + width + inclination, fullHeight, 0.0).colorEnd()
vertex(x + width + inclination, y + height, 0.0).colorEnd()
tessellator.end()
begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR)
vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex()
vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex()
tessellator.end()
begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR)
vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex()
vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex()
tessellator.end()
} catch (e: Error) {
Snowy.logs.error("Error caught when rendering a ClickBox: $e")
}
}
RenderSystem.enableTexture()
RenderSystem.disableBlend()