fix crash in chunk border renderer, rename "mouse catch" to "cursor mode"

This commit is contained in:
Bixilon 2021-12-03 21:16:58 +01:00
parent 17ee5ad834
commit de6e1b8ff6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 19 additions and 11 deletions

View File

@ -0,0 +1,7 @@
package de.bixilon.minosoft.config.profile.profiles.connection
import de.bixilon.minosoft.modding.event.events.Event
class ConnectionProfileSelectEvent(
val profile: ConnectionProfile,
) : Event

View File

@ -50,7 +50,7 @@ class RenderWindowInputHandler(
val interactionManager = InteractionManager(renderWindow)
init {
registerKeyCallback("minosoft:debug_mouse_catch".toResourceLocation(),
registerKeyCallback("minosoft:debug_change_cursor_mode".toResourceLocation(),
KeyBinding(
mutableMapOf(
KeyAction.MODIFIER to mutableSetOf(KeyCodes.KEY_F4),
@ -64,7 +64,7 @@ class RenderWindowInputHandler(
CursorModes.HIDDEN -> CursorModes.NORMAL
}
renderWindow.window.cursorMode = nextMode
renderWindow.sendDebugMessage("Mouse catch: ${nextMode.format()}")
renderWindow.sendDebugMessage("Cursor mode: ${nextMode.format()}")
}
}

View File

@ -38,11 +38,11 @@ class ChunkBorderRenderer(
) : Renderer, OpaqueDrawable {
private val profile = connection.profiles.rendering
override val renderSystem: RenderSystem = renderWindow.renderSystem
private var lastChunkPosition: Vec2i? = null
private var lastMesh: LineMesh? = null
private var chunkPosition: Vec2i? = null
private var mesh: LineMesh? = null
override val skipOpaque: Boolean
get() = !profile.chunkBorder.enabled
get() = mesh == null || !profile.chunkBorder.enabled
override fun init() {
renderWindow.inputHandler.registerKeyCallback(CHUNK_BORDER_TOGGLE_KEY_COMBINATION,
@ -59,14 +59,15 @@ class ChunkBorderRenderer(
override fun prepareDraw() {
if (!profile.chunkBorder.enabled) {
lastMesh?.unload()
mesh?.unload()
this.mesh = null
return
}
val chunkPosition = renderWindow.connection.player.positionInfo.chunkPosition
if (chunkPosition == lastChunkPosition && lastMesh != null) {
if (chunkPosition == this.chunkPosition && mesh != null) {
return
}
lastMesh?.unload()
mesh?.unload()
val mesh = LineMesh(renderWindow)
val dimension = renderWindow.connection.world.dimension ?: return
@ -133,8 +134,8 @@ class ChunkBorderRenderer(
}
mesh.load()
this.lastMesh = mesh
this.lastChunkPosition = chunkPosition
this.mesh = mesh
this.chunkPosition = chunkPosition
}
override fun setupOpaque() {
@ -143,7 +144,7 @@ class ChunkBorderRenderer(
}
override fun drawOpaque() {
lastMesh?.draw()
mesh?.draw()
}