aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-05-03 12:15:45 +0200
committerGitHub <noreply@github.com>2024-05-03 12:15:45 +0200
commit4a2ac4ca162d846dcc9a2a3227f963321fa4e22a (patch)
tree3bd7a448f61e58e02f1e81778a40aa3b964fd8b7 /src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
parent8d338540f3293b03acdd74f40a6c84a3cbedbded (diff)
downloadskyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.tar.gz
skyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.tar.bz2
skyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.zip
Backend: GuiContainerEvent.BeforeDraw (#1510)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/GuiData.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiData.kt72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
new file mode 100644
index 000000000..c0cd46365
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
@@ -0,0 +1,72 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.NEURenderEvent
+import at.hannibal2.skyhanni.utils.DelayedRun
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
+import io.github.moulberry.notenoughupdates.NEUApi
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraftforge.client.event.GuiOpenEvent
+import net.minecraftforge.client.event.GuiScreenEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.network.FMLNetworkEvent
+import org.lwjgl.input.Keyboard
+
+object GuiData {
+
+ var preDrawEventCanceled = false
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onNeuRenderEvent(event: NEURenderEvent) {
+ if (preDrawEventCanceled) event.cancel()
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (preDrawEventCanceled) event.cancel()
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onGuiClick(event: GuiScreenEvent.MouseInputEvent.Pre) {
+ if (preDrawEventCanceled) event.isCanceled = true
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onGuiKeyPress(event: GuiScreenEvent.KeyboardInputEvent.Pre) {
+ val (escKey, invKey) = Minecraft.getMinecraft().gameSettings.let {
+ Keyboard.KEY_ESCAPE to it.keyBindInventory.keyCode
+ }
+ if (escKey.isKeyHeld() || invKey.isKeyHeld()) return
+ if (preDrawEventCanceled) event.isCanceled = true
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ DelayedRun.runNextTick {
+ if (Minecraft.getMinecraft().currentScreen !is GuiChest) {
+ preDrawEventCanceled = false
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ preDrawEventCanceled = false
+ }
+
+ @SubscribeEvent
+ fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) {
+ preDrawEventCanceled = false
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOW)
+ fun onGuiOpen(event: GuiOpenEvent) {
+ if (preDrawEventCanceled) {
+ NEUApi.setInventoryButtonsToDisabled()
+ }
+ }
+}