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 1a08bf0..0007033 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -6,7 +6,14 @@ import com.mojang.blaze3d.vertex.Tesselator import com.mojang.blaze3d.vertex.VertexConsumer import fr.username404.snowygui.Snowy -fun interface Renderable { fun render(poseStack: PoseStack?) } +fun interface Renderable { + companion object Rendering { + @JvmStatic val tessellator: Tesselator = Tesselator.getInstance() + @JvmStatic val buffer: BufferBuilder = tessellator.builder + } + fun render(poseStack: PoseStack?) +} + abstract class Element( @JvmField val xOrigin: Double, @JvmField val yOrigin: Double, val width: Int, val height: Int @@ -14,10 +21,13 @@ abstract class Element( var x = xOrigin; var y = yOrigin internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean = ((coordinateX >= this.x) && (coordinateX <= (this.x + this.width))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height))) - companion object Rendering { + companion object { private var caughtError: Boolean = false - @JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance() - @JvmStatic protected val buffer: BufferBuilder = tessellator.builder + fun fromRenderable(r: Renderable, x: Int, y: Int, width: Int, height: Int): Element { + return object: Element(x.toDouble(), y.toDouble(), width, height) { + override fun render(poseStack: PoseStack?) = r.render(poseStack) + } + } } fun display(stack: PoseStack? = null) { if (!hidden && !caughtError) try { 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 6ca59d8..923724d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt @@ -6,13 +6,6 @@ import net.minecraft.network.chat.TranslatableComponent import kotlin.properties.Delegates abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) { - companion object { - fun fromRenderable(r: Renderable, x: Int, y: Int, width: Int, height: Int): Element { - return object: Element(x.toDouble(), y.toDouble(), width, height) { - override fun render(poseStack: PoseStack?) = r.render(poseStack) - } - } - } open val components: MutableSet by Delegates.notNull() override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) { if (poseStack != null) { 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 93372bb..11fff17 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 @@ -4,6 +4,8 @@ import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.gui.ColoredElement +import fr.username404.snowygui.gui.Renderable.Rendering.buffer +import fr.username404.snowygui.gui.Renderable.Rendering.tessellator import net.minecraft.client.Minecraft import net.minecraft.network.chat.TranslatableComponent import org.lwjgl.opengl.GL20