Skip to content

Commit

Permalink
Fix back stack open invalid gui
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Aug 17, 2024
1 parent 21d4d9c commit c5540c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/one/oktw/galaxy/gui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class GUI private constructor(

override fun getDisplayName() = title

override fun createMenu(syncId: Int, playerInventory: PlayerInventory, player: PlayerEntity): ScreenHandler {
override fun createMenu(syncId: Int, playerInventory: PlayerInventory, player: PlayerEntity): ScreenHandler? {
if (blockEntity?.isRemoved == true) return null
return GuiContainer(syncId, playerInventory)
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/one/oktw/galaxy/gui/GUISBackStackManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class GUISBackStackManager(private val player: ServerPlayerEntity) : CoroutineSc
stack.pollLast() // Remove closed

// Delay 1 tick to workaround open GUI on close callback
launch { stack.lastOrNull()?.let(player::openHandledScreen) } // Open previous
launch {
while (stack.isNotEmpty()) {
if (stack.last().let(player::openHandledScreen).isPresent) break // Try open previous
stack.pollLast() // Open fail, remove it
}
}
}
}
}

0 comments on commit c5540c4

Please sign in to comment.