diff options
-rw-r--r-- | build.gradle.kts | 41 | ||||
-rw-r--r-- | sharedVariables/src/Versions.kt | 6 | ||||
-rw-r--r-- | src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java | 4 | ||||
-rw-r--r-- | src/main/kotlin/UltraNotifier.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/UltraNotifierEntryPoint.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/commands/Commands.kt | 50 | ||||
-rw-r--r-- | src/main/kotlin/event/ChatGuiLineEvent.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/event/ChatLineAddedEvent.kt | 7 | ||||
-rw-r--r-- | src/main/kotlin/event/PacketChatLineEvent.kt | 5 | ||||
-rw-r--r-- | src/main/kotlin/event/UltraNotifierEvents.kt | 8 | ||||
-rw-r--r-- | src/main/resources/fabric.mod.json (renamed from versions/1.20.6/src/main/resources/fabric.mod.json) | 7 | ||||
-rw-r--r-- | src/main/resources/mcmod.info (renamed from versions/1.8.9/src/main/resources/mcmod.info) | 6 | ||||
-rw-r--r-- | src/main/resources/mixins.ultranotifier.json | 2 | ||||
-rw-r--r-- | versions/1.14.4-forge/src/main/resources/META-INF/mods.toml | 2 |
14 files changed, 131 insertions, 21 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 78efa65..5feb95d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,7 @@ java.toolchain.languageVersion.set(mcJavaVersion) preprocess.run { vars.put("MC", version.numericMinecraftVersion) vars.put("FORGE", if ((version.forgeDep != null)) 1 else 0) + vars.put("JAVA", mcJavaVersion.asInt()) } repositories { @@ -92,9 +93,13 @@ dependencies { runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:$devauthVersion") } else { modImplementation("net.fabricmc:fabric-loader:0.15.10") + modImplementation("net.fabricmc.fabric-api:fabric-api:${version.fabricVersion!!}") runtimeOnly("me.djtheredstoner:DevAuth-fabric:$devauthVersion") } shadowImpl("com.github.therealbush:eventbus:1.0.2") + if (version.numericMinecraftVersion < 11300) { + shadowImpl("com.mojang:brigadier:1.0.18") + } if (version <= Versions.MC11404F) { shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false @@ -120,15 +125,44 @@ tasks.withType<Jar> { tasks.jar { archiveClassifier.set("without-dep") } - +sourceSets.main { + val resourceFile = project.file("src/main/resources") + println("All resources: ${resources.srcDirs}") + if (!resources.srcDirs.contains(resourceFile)) { + println("Added resource dir") + resources.srcDir(resourceFile) + } +} tasks.shadowJar { archiveClassifier.set("all-dev") configurations = listOf(shadowImpl, shadowModImpl) } +tasks.processResources { + inputs.property("java", mcJavaVersion.asInt().toString()) + inputs.property("mcVersion", version.minecraftVersion) + inputs.property("version", project.version.toString()) + inputs.property("modName", "Ultra Notifier") + inputs.property("description", "Ultra Notifications") + filesMatching(listOf("fabric.mod.json", "mixins.*.json", "mcmod.info", "META-INF/mods.toml")) { + expand(inputs.properties) + } + if (version.forgeDep != null) { + exclude("fabric.mod.json") + if (version.numericMinecraftVersion < 11400) { + exclude("META-INF/mods.toml") + } else { + exclude("mcmod.info") + } + } else { + exclude("mcmod.info") + exclude("META-INF/mods.toml") + } +} + tasks.named("remapJar", RemapJarTask::class) { this.destinationDirectory.set(layout.buildDirectory.dir("libs")) - from(tasks.shadowJar) + dependsOn(tasks.shadowJar) archiveClassifier.set("") inputFile.set(tasks.shadowJar.flatMap { it.archiveFile }) } @@ -137,7 +171,8 @@ tasks.named("runClient", RunGameTask::class) { this.languageVersion.set(mcJavaVersion) }) } -if (version.isBridge && false) { + +if (version.isBridge) { tasks.withType<JavaCompile> { onlyIf { false } } diff --git a/sharedVariables/src/Versions.kt b/sharedVariables/src/Versions.kt index f559d03..bfccd3a 100644 --- a/sharedVariables/src/Versions.kt +++ b/sharedVariables/src/Versions.kt @@ -12,11 +12,13 @@ enum class Versions( val forgeDep: String?, val needsPack200: Boolean, val isBridge: Boolean, + + val fabricVersion: String? = null, ) { MC189("1.8.9", "srg", "1.8.9", "de.oceanlabs.mcp:mcp_stable:22-1.8.9@zip", "MC11404F", "net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9", true, false), MC11404F("1.14.4-forge", "srg", "1.14.4", "de.oceanlabs.mcp:mcp_stable:58-1.14.4@zip", "MC11404", "net.minecraftforge:forge:1.14.4-28.1.113", false, true), - MC11404("1.14.4", "yarn", "1.14.4", yarn("1.14.4+build.1"), "MC12006", null, false, true), - MC12006("1.20.6", "yarn", "1.20.6", yarn("1.20.6+build.1"), null, null, false, false), + MC11404("1.14.4", "yarn", "1.14.4", yarn("1.14.4+build.1"), "MC12006", null, false, true, fabricVersion = "0.23.2+1.14"), + MC12006("1.20.6", "yarn", "1.20.6", yarn("1.20.6+build.1"), null, null, false, false, fabricVersion = "0.99.0+1.20.6"), ; val parent: Versions? by lazy { 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/versions/1.20.6/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index bd24129..df30b70 100644 --- a/versions/1.20.6/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,9 +1,14 @@ { "schemaVersion": 1, "id": "ultranotifier", - "name": "Ultra Notifier", + "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/versions/1.8.9/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 2d38802..733fa56 100644 --- a/versions/1.8.9/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,10 +1,10 @@ [ { "modid": "ultranotifier", - "name": "nea89s Ultra Notifier", - "description": "Ultratastic chat notifications and similar", + "name": "${modName}", + "description": "${description}", "version": "${version}", - "mcversion": "1.8.9", + "mcversion": "${mcVersion}", "url": "https://github.com/nea89/ultra-notifier/", "updateUrl": "", "authorList": [ 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", diff --git a/versions/1.14.4-forge/src/main/resources/META-INF/mods.toml b/versions/1.14.4-forge/src/main/resources/META-INF/mods.toml index faf1456..41b3d45 100644 --- a/versions/1.14.4-forge/src/main/resources/META-INF/mods.toml +++ b/versions/1.14.4-forge/src/main/resources/META-INF/mods.toml @@ -16,6 +16,6 @@ side="BOTH" [[dependencies.ultranotifier]] modId="minecraft" mandatory=true -versionRange="[1.14.4]" +versionRange="[${mcVersion}]" ordering="NONE" side="BOTH"
\ No newline at end of file |