diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
commit | 99773d6a593c444151503de315f127bea6f74d49 (patch) | |
tree | 9ee1ae505e5f82aba62f10c882af85a3acd6e483 /src/main/java/at/lorenz/mod/events | |
download | skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.gz skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.bz2 skyhanni-99773d6a593c444151503de315f127bea6f74d49.zip |
init lorenz mod
Diffstat (limited to 'src/main/java/at/lorenz/mod/events')
4 files changed, 90 insertions, 0 deletions
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 |