diff options
author | Linnea Gräf <nea@nea.moe> | 2025-01-30 20:11:37 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-01-30 20:11:37 +0100 |
commit | 8e386bcf8d10784fc7784333be9e4470598c71d4 (patch) | |
tree | f0bd83c41bd083b6708703d420fe466b5f66111a /mod/src/main/kotlin/moe/nea/ledger/events | |
parent | e51a59636129c35b58dbdda83b141b539a87e6fe (diff) | |
download | LocalTransactionLedger-nightly.tar.gz LocalTransactionLedger-nightly.tar.bz2 LocalTransactionLedger-nightly.zip |
Diffstat (limited to 'mod/src/main/kotlin/moe/nea/ledger/events')
-rw-r--r-- | mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt | 12 | ||||
-rw-r--r-- | mod/src/main/kotlin/moe/nea/ledger/events/LedgerEvent.kt | 22 |
2 files changed, 33 insertions, 1 deletions
diff --git a/mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt b/mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt index 098912a..7f6eae9 100644 --- a/mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt +++ b/mod/src/main/kotlin/moe/nea/ledger/events/BeforeGuiAction.kt @@ -1,11 +1,21 @@ package moe.nea.ledger.events +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import moe.nea.ledger.telemetry.GuiContextValue +import moe.nea.ledger.utils.telemetry.ContextValue import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.Event -data class BeforeGuiAction(val gui: GuiScreen) : Event() { +data class BeforeGuiAction(val gui: GuiScreen) : LedgerEvent() { val chest = gui as? GuiChest val chestSlots = chest?.inventorySlots as ContainerChest? + override fun serialize(): JsonElement { + return JsonObject().apply { + add("gui", GuiContextValue(gui).serialize()) + } + } } diff --git a/mod/src/main/kotlin/moe/nea/ledger/events/LedgerEvent.kt b/mod/src/main/kotlin/moe/nea/ledger/events/LedgerEvent.kt new file mode 100644 index 0000000..cbb3f81 --- /dev/null +++ b/mod/src/main/kotlin/moe/nea/ledger/events/LedgerEvent.kt @@ -0,0 +1,22 @@ +package moe.nea.ledger.events + +import moe.nea.ledger.Ledger +import moe.nea.ledger.utils.ErrorUtil +import moe.nea.ledger.utils.telemetry.CommonKeys +import moe.nea.ledger.utils.telemetry.ContextValue +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.Event + +abstract class LedgerEvent : Event(), ContextValue { + fun post() { + Ledger.leakDI() + .provide<ErrorUtil>() + .catch( + CommonKeys.EVENT_MESSAGE to ContextValue.string("Error during event execution"), + "event_instance" to this, + "event_type" to ContextValue.string(javaClass.name) + ) { + MinecraftForge.EVENT_BUS.post(this) + } + } +}
\ No newline at end of file |