summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-24 18:16:37 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-24 18:16:37 +0200
commit5b68a5f3f716c8d12117b39efba8c4b8d09fcb98 (patch)
tree77fbd5503748073a4cf4968bda4d592d2aebd977 /src
parentb681f11ea5a72d4ec6a34c2807f6ed781bbd19bc (diff)
downloadultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.gz
ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.tar.bz2
ultra-notifier-5b68a5f3f716c8d12117b39efba8c4b8d09fcb98.zip
Add basic chat commands
Diffstat (limited to 'src')
-rw-r--r--src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java4
-rw-r--r--src/main/kotlin/UltraNotifier.kt2
-rw-r--r--src/main/kotlin/UltraNotifierEntryPoint.kt2
-rw-r--r--src/main/kotlin/commands/Commands.kt50
-rw-r--r--src/main/kotlin/event/ChatGuiLineEvent.kt10
-rw-r--r--src/main/kotlin/event/ChatLineAddedEvent.kt7
-rw-r--r--src/main/kotlin/event/PacketChatLineEvent.kt5
-rw-r--r--src/main/kotlin/event/UltraNotifierEvents.kt8
-rw-r--r--src/main/resources/fabric.mod.json14
-rw-r--r--src/main/resources/mcmod.info18
-rw-r--r--src/main/resources/mixins.ultranotifier.json2
11 files changed, 111 insertions, 11 deletions
diff --git a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
index b6c013f..2b65282 100644
--- a/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
+++ b/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
@@ -1,6 +1,6 @@
package moe.nea.ultranotifier.mixin;
-import moe.nea.ultranotifier.event.ChatLineAddedEvent;
+import moe.nea.ultranotifier.event.ChatGuiLineEvent;
import moe.nea.ultranotifier.event.UltraNotifierEvents;
import net.minecraft.client.gui.hud.ChatHud;
//#if MC > 11404
@@ -37,7 +37,7 @@ public class ChatHudMessageAdded {
//#endif
CallbackInfo ci
) {
- if (UltraNotifierEvents.post(new ChatLineAddedEvent(message)).isCancelled()) {
+ if (UltraNotifierEvents.post(new ChatGuiLineEvent(message)).isCancelled()) {
ci.cancel();
}
}
diff --git a/src/main/kotlin/UltraNotifier.kt b/src/main/kotlin/UltraNotifier.kt
index 17798cc..dce1fda 100644
--- a/src/main/kotlin/UltraNotifier.kt
+++ b/src/main/kotlin/UltraNotifier.kt
@@ -1,5 +1,6 @@
package moe.nea.ultranotifier
+import moe.nea.ultranotifier.commands.Commands
import moe.nea.ultranotifier.init.NeaMixinConfig
import java.io.File
@@ -16,6 +17,7 @@ object UltraNotifier {
for (mixinPlugin in NeaMixinConfig.getMixinPlugins()) {
logger.info("Loaded ${mixinPlugin.mixins.size} mixins for ${mixinPlugin.mixinPackage}.")
}
+ Commands.init()
}
val configFolder = File("config/ultra-notifier").also {
diff --git a/src/main/kotlin/UltraNotifierEntryPoint.kt b/src/main/kotlin/UltraNotifierEntryPoint.kt
index 67dd566..42ae064 100644
--- a/src/main/kotlin/UltraNotifierEntryPoint.kt
+++ b/src/main/kotlin/UltraNotifierEntryPoint.kt
@@ -21,7 +21,7 @@ package moe.nea.ultranotifier
//$$}
//#else
import net.fabricmc.api.ModInitializer
-object UltraNotifierEntryPoint : ModInitializer {
+class UltraNotifierEntryPoint : ModInitializer {
override fun onInitialize() {
UltraNotifier.onStartup()
}
diff --git a/src/main/kotlin/commands/Commands.kt b/src/main/kotlin/commands/Commands.kt
new file mode 100644
index 0000000..75047cd
--- /dev/null
+++ b/src/main/kotlin/commands/Commands.kt
@@ -0,0 +1,50 @@
+package moe.nea.ultranotifier.commands
+
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import moe.nea.ultranotifier.UltraNotifier
+import moe.nea.ultranotifier.event.UltraNotifierEvents
+import net.minecraft.text.Text
+
+interface CustomSource {
+ fun sendFeedback(text: Text)
+}
+
+
+typealias UltraCommandSource =
+//#if FORGE
+//$$ CustomSource
+//#else
+ net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+
+//#endif
+
+
+fun literalText(string: String): Text =
+//#if MC >= 11400
+ Text.literal(string)
+//#else
+//$$ net.minecraft.util.ChatComponentText(string)
+//#endif
+
+object Commands {
+ fun registerAll(dispatcher: CommandDispatcher<UltraCommandSource>) {
+ dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource>("hello")
+ .executes {
+ it.source.sendFeedback(literalText("Hello World"))
+ 0
+ })
+ }
+
+ fun init() {
+ UltraNotifierEvents.register(this)
+//#if FORGE
+//$$
+//#else
+ net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT.register { dispatcher, registryAccess ->
+ registerAll(dispatcher)
+ }
+//#endif
+ UltraNotifier.logger.info("Initialized command subsystem")
+ }
+}
diff --git a/src/main/kotlin/event/ChatGuiLineEvent.kt b/src/main/kotlin/event/ChatGuiLineEvent.kt
new file mode 100644
index 0000000..e37d31f
--- /dev/null
+++ b/src/main/kotlin/event/ChatGuiLineEvent.kt
@@ -0,0 +1,10 @@
+package moe.nea.ultranotifier.event
+
+import net.minecraft.text.Text
+
+class ChatGuiLineEvent(val component: Text) : UltraEvent() {
+ val string = component.string
+ override fun toString(): String {
+ return "ChatLineAddedEvent($string)"
+ }
+}
diff --git a/src/main/kotlin/event/ChatLineAddedEvent.kt b/src/main/kotlin/event/ChatLineAddedEvent.kt
deleted file mode 100644
index 0460f83..0000000
--- a/src/main/kotlin/event/ChatLineAddedEvent.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package moe.nea.ultranotifier.event
-
-import net.minecraft.text.Text
-
-class ChatLineAddedEvent(val component: Text) : UltraEvent() {
- val string = component.string
-}
diff --git a/src/main/kotlin/event/PacketChatLineEvent.kt b/src/main/kotlin/event/PacketChatLineEvent.kt
new file mode 100644
index 0000000..2d5887c
--- /dev/null
+++ b/src/main/kotlin/event/PacketChatLineEvent.kt
@@ -0,0 +1,5 @@
+package moe.nea.ultranotifier.event
+
+import net.minecraft.text.Text
+
+class PacketChatLineEvent(val component: Text) : UltraEvent()
diff --git a/src/main/kotlin/event/UltraNotifierEvents.kt b/src/main/kotlin/event/UltraNotifierEvents.kt
index 8c8fb13..34d1769 100644
--- a/src/main/kotlin/event/UltraNotifierEvents.kt
+++ b/src/main/kotlin/event/UltraNotifierEvents.kt
@@ -15,6 +15,14 @@ object UltraNotifierEvents {
eventBus.post(event)
return event
}
+
+ fun register(obj: Any) {
+//#if FORGE
+//$$ eventBus.register(obj)
+//#else
+ eventBus.subscribe(obj)
+//#endif
+ }
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
new file mode 100644
index 0000000..df30b70
--- /dev/null
+++ b/src/main/resources/fabric.mod.json
@@ -0,0 +1,14 @@
+{
+ "schemaVersion": 1,
+ "id": "ultranotifier",
+ "name": "${modName}",
+ "description": "${description}",
+ "version": "${version}",
+ "entrypoints": {
+ "main": ["moe.nea.ultranotifier.UltraNotifierEntryPoint"]
+ },
+ "depends": {
+ "minecraft": "~${mcVersion}",
+ "java": ">=${java}"
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info
new file mode 100644
index 0000000..733fa56
--- /dev/null
+++ b/src/main/resources/mcmod.info
@@ -0,0 +1,18 @@
+[
+ {
+ "modid": "ultranotifier",
+ "name": "${modName}",
+ "description": "${description}",
+ "version": "${version}",
+ "mcversion": "${mcVersion}",
+ "url": "https://github.com/nea89/ultra-notifier/",
+ "updateUrl": "",
+ "authorList": [
+ "nea89"
+ ],
+ "credits": "",
+ "logoFile": "",
+ "screenshots": [],
+ "dependencies": []
+ }
+] \ No newline at end of file
diff --git a/src/main/resources/mixins.ultranotifier.json b/src/main/resources/mixins.ultranotifier.json
index 03c353c..cf12435 100644
--- a/src/main/resources/mixins.ultranotifier.json
+++ b/src/main/resources/mixins.ultranotifier.json
@@ -1,5 +1,5 @@
{
- "compatibilityLevel": "JAVA_8",
+ "compatibilityLevel": "JAVA_${java}",
"package": "moe.nea.ultranotifier.mixin",
"plugin": "moe.nea.ultranotifier.init.NeaMixinConfig",
"refmap": "mixins.ultranotifier.refmap.json",