aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-06-09 18:38:24 -0500
committeringlettronald <inglettronald@gmail.com>2023-06-09 18:38:24 -0500
commit480f3cc93b3b77aa53225b3d65a5eb30de81bc30 (patch)
tree143020f565a3d28fac9d8f766aa8b59f032fa14c /src
parentc0eb625a9b937bcb9256e98afb80d32443daa795 (diff)
downloadDulkirMod-Fabric-480f3cc93b3b77aa53225b3d65a5eb30de81bc30.tar.gz
DulkirMod-Fabric-480f3cc93b3b77aa53225b3d65a5eb30de81bc30.tar.bz2
DulkirMod-Fabric-480f3cc93b3b77aa53225b3d65a5eb30de81bc30.zip
Some event stuff
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/GameMenuScreenMixin.java13
-rw-r--r--src/main/java/com/dulkirfabric/mixin/render/KeyboardMixin.java16
-rw-r--r--src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt15
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt3
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/WorldKeyPressEvent.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt2
-rw-r--r--src/main/resources/dulkirmod-fabric.mixins.json3
7 files changed, 27 insertions, 31 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/render/GameMenuScreenMixin.java b/src/main/java/com/dulkirfabric/mixin/render/GameMenuScreenMixin.java
index b644595..6f09e51 100644
--- a/src/main/java/com/dulkirfabric/mixin/render/GameMenuScreenMixin.java
+++ b/src/main/java/com/dulkirfabric/mixin/render/GameMenuScreenMixin.java
@@ -14,7 +14,6 @@
package com.dulkirfabric.mixin.render;
import com.dulkirfabric.config.DulkirConfig;
-import com.dulkirfabric.events.WidgetInitEvent;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
@@ -30,8 +29,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.Supplier;
-import static com.dulkirfabric.DulkirModFabric.EVENT_BUS;
-
@Mixin(GameMenuScreen.class)
public abstract class GameMenuScreenMixin extends ScreenMixin {
@@ -48,14 +45,4 @@ public abstract class GameMenuScreenMixin extends ScreenMixin {
adder.add(this.createButton(buttonText, new DulkirConfig()::getScreen));
}
- @Inject(method = "initWidgets", at = @At(value = "HEAD"))
- private void initWidgetPre(CallbackInfo ci) {
- EVENT_BUS.post(WidgetInitEvent.get(false));
- }
-
- @Inject(method = "initWidgets", at = @At(value = "TAIL"))
- private void initWidgetPost(CallbackInfo ci) {
- EVENT_BUS.post(WidgetInitEvent.get(true));
- }
-
} \ No newline at end of file
diff --git a/src/main/java/com/dulkirfabric/mixin/render/KeyboardMixin.java b/src/main/java/com/dulkirfabric/mixin/render/KeyboardMixin.java
new file mode 100644
index 0000000..c2c5a45
--- /dev/null
+++ b/src/main/java/com/dulkirfabric/mixin/render/KeyboardMixin.java
@@ -0,0 +1,16 @@
+package com.dulkirfabric.mixin.render;
+
+import com.dulkirfabric.events.WorldKeyPressEvent;
+import net.minecraft.client.Keyboard;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(Keyboard.class)
+public class KeyboardMixin {
+ @Inject(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;onKeyPressed(Lnet/minecraft/client/util/InputUtil$Key;)V"))
+ public void onKeyBoardInWorld(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
+ new WorldKeyPressEvent(key, scancode, modifiers).post();
+ }
+}
diff --git a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt
index e32e50a..112bf2a 100644
--- a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt
+++ b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt
@@ -15,7 +15,6 @@ package com.dulkirfabric
import com.dulkirfabric.config.DulkirConfig
import meteordevelopment.orbit.EventBus
-import meteordevelopment.orbit.EventHandler
import net.fabricmc.api.ModInitializer
import net.minecraft.client.MinecraftClient
import org.slf4j.LoggerFactory
@@ -28,7 +27,6 @@ object DulkirModFabric : ModInitializer {
val EVENT_BUS = EventBus()
@JvmField
val mc: MinecraftClient = MinecraftClient.getInstance()
- var widgetLoadTime = 0L
override fun onInitialize() {
logger.info("Initializing DulkirMod...")
@@ -46,19 +44,6 @@ object DulkirModFabric : ModInitializer {
DulkirConfig.loadConfig()
}
-
- @EventHandler
- fun onPreInit(event: WidgetInitEvent) {
- if (!event.initialized) println("have not initialized widgets yet!!!!")
- widgetLoadTime = System.nanoTime()
- }
-
- @EventHandler
- fun onPostInit(event: WidgetInitEvent) {
- val time = System.nanoTime() - widgetLoadTime
- if (event.initialized) println("widgets initialized!!!!!, took: $time ns")
- }
-
//!this.client.options.getPerspective().isFirstPerson(), this.client.options.getPerspective().isFrontView()
} \ 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
index f4f9e13..6ba0667 100644
--- a/src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt
+++ b/src/main/kotlin/com/dulkirfabric/events/InventoryKeyPressEvent.kt
@@ -2,4 +2,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
+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/WorldKeyPressEvent.kt b/src/main/kotlin/com/dulkirfabric/events/WorldKeyPressEvent.kt
new file mode 100644
index 0000000..2e6545b
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/events/WorldKeyPressEvent.kt
@@ -0,0 +1,6 @@
+package com.dulkirfabric.events
+
+import com.dulkirfabric.events.base.Event
+
+data class
+WorldKeyPressEvent(val key: Int, val scancode: Int, val modifiers: Int): Event() \ 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
index 1c1ddcd..09027ed 100644
--- a/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt
+++ b/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt
@@ -4,7 +4,7 @@ import com.dulkirfabric.DulkirModFabric
import meteordevelopment.orbit.ICancellable
abstract class CancellableEvent: ICancellable {
-
+ @JvmField
var cancelled: Boolean = false
override fun isCancelled(): Boolean {
diff --git a/src/main/resources/dulkirmod-fabric.mixins.json b/src/main/resources/dulkirmod-fabric.mixins.json
index dc450d3..808b58f 100644
--- a/src/main/resources/dulkirmod-fabric.mixins.json
+++ b/src/main/resources/dulkirmod-fabric.mixins.json
@@ -6,9 +6,10 @@
"defaultRequire": 1
},
"client": [
+ "io.HandledScreenMixin",
"render.GameMenuScreenMixin",
"render.GameRendererMixin",
- "io.HandledScreenMixin",
+ "render.KeyboardMixin",
"render.ScreenMixin"
]
} \ No newline at end of file