From 99773d6a593c444151503de315f127bea6f74d49 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 7 Jul 2022 00:31:50 +0200 Subject: init lorenz mod --- .../java/at/lorenz/mod/events/GuiContainerEvent.kt | 54 ++++++++++++++++++++++ .../java/at/lorenz/mod/events/LorenzChatEvent.kt | 5 ++ src/main/java/at/lorenz/mod/events/LorenzEvent.kt | 20 ++++++++ .../at/lorenz/mod/events/PlayerSendChatEvent.kt | 11 +++++ 4 files changed, 90 insertions(+) create mode 100644 src/main/java/at/lorenz/mod/events/GuiContainerEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/LorenzChatEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/LorenzEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/PlayerSendChatEvent.kt (limited to 'src/main/java/at/lorenz/mod/events') diff --git a/src/main/java/at/lorenz/mod/events/GuiContainerEvent.kt b/src/main/java/at/lorenz/mod/events/GuiContainerEvent.kt new file mode 100644 index 000000000..4f43ab505 --- /dev/null +++ b/src/main/java/at/lorenz/mod/events/GuiContainerEvent.kt @@ -0,0 +1,54 @@ +package at.lorenz.mod.events + +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.inventory.Container +import net.minecraft.inventory.ContainerChest +import net.minecraft.inventory.Slot +import net.minecraftforge.fml.common.eventhandler.Cancelable + +abstract class GuiContainerEvent(open val gui: GuiContainer, open val container: Container) : LorenzEvent() { + val chestName: String by lazy { + if (container !is ContainerChest) error("Container is not a chest") + return@lazy (container as ContainerChest).lowerChestInventory.displayName.unformattedText.trim() + } + + data class BackgroundDrawnEvent( + override val gui: GuiContainer, + override val container: Container, + val mouseX: Int, + val mouseY: Int, + val partialTicks: Float + ) : GuiContainerEvent(gui, container) + + @Cancelable + data class CloseWindowEvent(override val gui: GuiContainer, override val container: Container) : + GuiContainerEvent(gui, container) + + abstract class DrawSlotEvent(gui: GuiContainer, container: Container, open val slot: Slot) : + GuiContainerEvent(gui, container) { + @Cancelable + data class Pre(override val gui: GuiContainer, override val container: Container, override val slot: Slot) : + DrawSlotEvent(gui, container, slot) + + data class Post(override val gui: GuiContainer, override val container: Container, override val slot: Slot) : + DrawSlotEvent(gui, container, slot) + } + + data class ForegroundDrawnEvent( + override val gui: GuiContainer, + override val container: Container, + val mouseX: Int, + val mouseY: Int, + val partialTicks: Float + ) : GuiContainerEvent(gui, container) + + @Cancelable + data class SlotClickEvent( + override val gui: GuiContainer, + override val container: Container, + val slot: Slot?, + val slotId: Int, + val clickedButton: Int, + val clickType: Int + ) : GuiContainerEvent(gui, container) +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/events/LorenzChatEvent.kt b/src/main/java/at/lorenz/mod/events/LorenzChatEvent.kt new file mode 100644 index 000000000..3b0350918 --- /dev/null +++ b/src/main/java/at/lorenz/mod/events/LorenzChatEvent.kt @@ -0,0 +1,5 @@ +package at.lorenz.mod.events + +import net.minecraft.util.IChatComponent + +class LorenzChatEvent(val message: String, val chatComponent: IChatComponent, var blockedReason: String = "") : LorenzEvent() \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/events/LorenzEvent.kt b/src/main/java/at/lorenz/mod/events/LorenzEvent.kt new file mode 100644 index 000000000..facb18e2a --- /dev/null +++ b/src/main/java/at/lorenz/mod/events/LorenzEvent.kt @@ -0,0 +1,20 @@ +package at.lorenz.mod.events + +import at.lorenz.mod.utils.LorenzUtils +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.Event + +abstract class LorenzEvent: Event() { + val eventName by lazy { + this::class.simpleName + } + + fun postAndCatch(): Boolean { + return runCatching { + MinecraftForge.EVENT_BUS.post(this) + }.onFailure { + it.printStackTrace() + LorenzUtils.chat("§cLorenz Mod caught and logged an ${it::class.simpleName ?: "error"} at ${eventName}.") + }.getOrDefault(isCanceled) + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/events/PlayerSendChatEvent.kt b/src/main/java/at/lorenz/mod/events/PlayerSendChatEvent.kt new file mode 100644 index 000000000..dd015e1cb --- /dev/null +++ b/src/main/java/at/lorenz/mod/events/PlayerSendChatEvent.kt @@ -0,0 +1,11 @@ +package at.lorenz.mod.events + +import at.lorenz.mod.chat.PlayerMessageChannel + + +class PlayerSendChatEvent( + val channel: PlayerMessageChannel, + val playerName: String, + var message: String, + var cancelledReason: String = "" +) : LorenzEvent() \ No newline at end of file -- cgit