Skip to content

Commit

Permalink
Open gui callback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Sep 30, 2024
1 parent 66b7830 commit 9b9a9e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ audience_version=2.11.1
sgui_version=1.6.1+1.21.1

# Mod Properties
mod_version=1.4.0
mod_version=1.5.0
maven_group=net.mcbrawls
mod_id=brawls-sgui

Expand Down
12 changes: 2 additions & 10 deletions src/main/kotlin/net/mcbrawls/sgui/callback/OpenGuiClickCallback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import eu.pb4.sgui.api.ClickType
import eu.pb4.sgui.api.elements.GuiElementInterface.ClickCallback
import eu.pb4.sgui.api.gui.GuiInterface
import eu.pb4.sgui.api.gui.SlotGuiInterface
import net.mcbrawls.sgui.openGui
import net.mcbrawls.sgui.openParentedGui
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.server.network.ServerPlayerEntity
Expand All @@ -16,17 +15,10 @@ data class OpenGuiClickCallback(
/**
* The factory to create the new GUI.
*/
val factory: (ServerPlayerEntity) -> GuiInterface,

val parent: GuiInterface? = null
val factory: (ServerPlayerEntity) -> GuiInterface
) : ClickCallback {
override fun click(index: Int, type: ClickType, action: SlotActionType, gui: SlotGuiInterface) {
val player = gui.player
val parent = parent
if (parent != null) {
player.openParentedGui(parent, factory)
} else {
player.openGui(factory)
}
player.openParentedGui(gui, factory)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.mcbrawls.sgui.callback

import eu.pb4.sgui.api.ClickType
import eu.pb4.sgui.api.elements.GuiElementInterface.ClickCallback
import eu.pb4.sgui.api.gui.GuiInterface
import eu.pb4.sgui.api.gui.SlotGuiInterface
import net.mcbrawls.sgui.openGui
import net.mcbrawls.sgui.openParentedGui
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.server.network.ServerPlayerEntity

/**
* A click callback to open a GUI.
*/
data class ParentedOpenGuiClickCallback(
/**
* The factory to create the new GUI.
*/
val factory: (ServerPlayerEntity) -> GuiInterface,

/**
* The parent of the opened GUI.
*/
val parent: GuiInterface? = null
) : ClickCallback {
override fun click(index: Int, type: ClickType, action: SlotActionType, gui: SlotGuiInterface) {
val player = gui.player
val parent = parent
if (parent != null) {
player.openParentedGui(parent, factory)
} else {
player.openGui(factory)
}
}
}

0 comments on commit 9b9a9e8

Please sign in to comment.