From 9b9a9e831ef36782c67d19a8721016857b66f8c2 Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Mon, 30 Sep 2024 19:39:30 +0100 Subject: [PATCH] Open gui callback changes --- gradle.properties | 2 +- .../sgui/callback/OpenGuiClickCallback.kt | 12 ++----- .../callback/ParentedOpenGuiClickCallback.kt | 35 +++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/net/mcbrawls/sgui/callback/ParentedOpenGuiClickCallback.kt diff --git a/gradle.properties b/gradle.properties index 79c6ee6..d48ef70 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/net/mcbrawls/sgui/callback/OpenGuiClickCallback.kt b/src/main/kotlin/net/mcbrawls/sgui/callback/OpenGuiClickCallback.kt index 6f01010..d8b0586 100644 --- a/src/main/kotlin/net/mcbrawls/sgui/callback/OpenGuiClickCallback.kt +++ b/src/main/kotlin/net/mcbrawls/sgui/callback/OpenGuiClickCallback.kt @@ -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 @@ -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) } } diff --git a/src/main/kotlin/net/mcbrawls/sgui/callback/ParentedOpenGuiClickCallback.kt b/src/main/kotlin/net/mcbrawls/sgui/callback/ParentedOpenGuiClickCallback.kt new file mode 100644 index 0000000..2981c03 --- /dev/null +++ b/src/main/kotlin/net/mcbrawls/sgui/callback/ParentedOpenGuiClickCallback.kt @@ -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) + } + } +}