If game suffers "Wayland" illness, don't crash, but instead just disable functionality

This commit is contained in:
DBotThePony 2025-02-12 19:07:18 +07:00
parent d1a2f24d5a
commit 124af53131
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent
import net.neoforged.neoforge.client.event.ClientTickEvent
import net.neoforged.neoforge.client.event.RenderFrameEvent
import org.apache.logging.log4j.LogManager
import org.lwjgl.glfw.GLFW
import ru.dbotthepony.mc.otm.core.util.IConditionalTickable
import ru.dbotthepony.mc.otm.core.util.ITickable
@ -11,6 +12,7 @@ import ru.dbotthepony.mc.otm.core.util.WriteOnce
import ru.dbotthepony.mc.otm.isClient
import java.util.function.LongSupplier
private val LOGGER = LogManager.getLogger()
private val preTickList = TickList()
private val postTickList = TickList()
@ -25,6 +27,12 @@ private var HAND_CURSOR by WriteOnce<Long>()
private var NOT_ALLOWED_CURSOR by WriteOnce<Long>()
private var CROSSHAIR_CURSOR by WriteOnce<Long>()
private inline fun check(cond: Boolean, error: () -> String) {
if (!cond) {
LOGGER.error(error.invoke(), RuntimeException(error.invoke()))
}
}
fun createCursors() {
ARROW_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR)
BEAM_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_IBEAM_CURSOR)
@ -43,6 +51,9 @@ enum class CursorType(val pointer: LongSupplier) {
ARROW(::ARROW_CURSOR), BEAM(::BEAM_CURSOR), HAND(::HAND_CURSOR), NOT_ALLOWED(::NOT_ALLOWED_CURSOR), CROSSHAIR(::CROSSHAIR_CURSOR);
fun setTo() {
if (pointer.asLong == 0L)
return
GLFW.glfwSetCursor(minecraft.window.window, pointer.asLong)
MODIFIED_CURSOR = true
MODIFIED_CURSOR_FRAMES = 2