From c0eb625a9b937bcb9256e98afb80d32443daa795 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Fri, 9 Jun 2023 16:55:24 -0500 Subject: 1.20 refactor --- .../com/dulkirfabric/events/ClientTickEvent.kt | 9 +++---- .../dulkirfabric/events/InventoryKeyPressEvent.kt | 5 ++++ .../com/dulkirfabric/events/SlotRenderEvent.kt | 29 ++++++++++++++++++++++ .../com/dulkirfabric/events/WidgetInitEvent.kt | 24 ------------------ .../com/dulkirfabric/events/WorldLoadEvent.kt | 8 ------ .../dulkirfabric/events/base/CancellableEvent.kt | 25 +++++++++++++++++++ .../kotlin/com/dulkirfabric/events/base/Event.kt | 9 +++++++ 7 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt create mode 100644 src/main/kotlin/com/dulkirfabric/events/SlotRenderEvent.kt delete mode 100644 src/main/kotlin/com/dulkirfabric/events/WidgetInitEvent.kt delete mode 100644 src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt create mode 100644 src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt create mode 100644 src/main/kotlin/com/dulkirfabric/events/base/Event.kt (limited to 'src/main/kotlin/com/dulkirfabric/events') diff --git a/src/main/kotlin/com/dulkirfabric/events/ClientTickEvent.kt b/src/main/kotlin/com/dulkirfabric/events/ClientTickEvent.kt index f24fdf7..d8184f1 100644 --- a/src/main/kotlin/com/dulkirfabric/events/ClientTickEvent.kt +++ b/src/main/kotlin/com/dulkirfabric/events/ClientTickEvent.kt @@ -1,8 +1,5 @@ package com.dulkirfabric.events -object ClientTickEvent { - @JvmStatic - fun get(): ClientTickEvent { - return this - } -} \ No newline at end of file +import com.dulkirfabric.events.base.Event + +object ClientTickEvent: Event() \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt b/src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt new file mode 100644 index 0000000..f4f9e13 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt @@ -0,0 +1,5 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.CancellableEvent + +data class InventoryKeyPressEvent(val keyCode: Int, val scanCode: Int, val modifiers: Int): CancellableEvent() \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/SlotRenderEvent.kt b/src/main/kotlin/com/dulkirfabric/events/SlotRenderEvent.kt new file mode 100644 index 0000000..3670998 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/SlotRenderEvent.kt @@ -0,0 +1,29 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.CancellableEvent +import net.minecraft.client.gui.DrawContext +import net.minecraft.screen.slot.Slot + +interface SlotRenderEvent { + val context: DrawContext + val slot: Slot + val mouseX: Int + val mouseY: Int + val delta: Float + + data class Before( + override val context: DrawContext, override val slot: Slot, + override val mouseX: Int, + override val mouseY: Int, + override val delta: Float + ) : CancellableEvent(), + SlotRenderEvent + + data class After( + override val context: DrawContext, override val slot: Slot, + override val mouseX: Int, + override val mouseY: Int, + override val delta: Float + ) : CancellableEvent(), + SlotRenderEvent +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/WidgetInitEvent.kt b/src/main/kotlin/com/dulkirfabric/events/WidgetInitEvent.kt deleted file mode 100644 index 9a6eebb..0000000 --- a/src/main/kotlin/com/dulkirfabric/events/WidgetInitEvent.kt +++ /dev/null @@ -1,24 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * If it is not possible or desirable to put the notice in a particular - * file, then You may include the notice in a location (such as a LICENSE - * file in a relevant directory) where a recipient would be likely to look - * for such a notice. - * - * You may add additional accurate notices of copyright ownership. - */ - -package com.dulkirfabric.events - -object WidgetInitEvent { - var initialized = false - - @JvmStatic - fun get(initialized: Boolean): WidgetInitEvent { - this.initialized = initialized - return this - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt b/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt deleted file mode 100644 index 99039a8..0000000 --- a/src/main/kotlin/com/dulkirfabric/events/WorldLoadEvent.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.dulkirfabric.events - -object WorldLoadEvent { - @JvmStatic - fun get(): WorldLoadEvent { - return this - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt b/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt new file mode 100644 index 0000000..1c1ddcd --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt @@ -0,0 +1,25 @@ +package com.dulkirfabric.events.base + +import com.dulkirfabric.DulkirModFabric +import meteordevelopment.orbit.ICancellable + +abstract class CancellableEvent: ICancellable { + + var cancelled: Boolean = false + + override fun isCancelled(): Boolean { + return cancelled + } + + override fun setCancelled(cancelled: Boolean) { + this.cancelled = cancelled + } + + /** + * Posts a given event to the bus and returns whether the user wishes to cancel it + */ + fun post(): Boolean { + DulkirModFabric.EVENT_BUS.post(this) + return cancelled + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/events/base/Event.kt b/src/main/kotlin/com/dulkirfabric/events/base/Event.kt new file mode 100644 index 0000000..7671199 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/base/Event.kt @@ -0,0 +1,9 @@ +package com.dulkirfabric.events.base + +import com.dulkirfabric.DulkirModFabric + +abstract class Event { + fun post() { + DulkirModFabric.EVENT_BUS.post(this) + } +} \ No newline at end of file -- cgit