From ab5386cc32d5452bf3f96c55444af12e14367300 Mon Sep 17 00:00:00 2001 From: zml Date: Sun, 16 Jun 2024 21:41:53 -0700 Subject: [PATCH] protocol: fixes and polishing --- build.gradle.kts | 9 +++++++ gradle/libs.versions.toml | 3 +++ worldeditcui-fabric/build.gradle.kts | 2 +- worldeditcui-protocol-fabric/build.gradle.kts | 25 +++++++++++++------ .../network/FabricCUIPacketHandler.java | 3 ++- .../network/FabricCUIPacketRegistration.java | 2 +- .../src/main/resources/fabric.mod.json | 4 +-- .../build.gradle.kts | 23 ++++++++++++----- .../protocol/NeoForgeProtocolMod.java | 12 ++++++--- .../resources/META-INF/neoforge.mods.toml | 6 ++--- 10 files changed, 65 insertions(+), 24 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 111d7a37..e366760e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,6 +38,7 @@ subprojects { apply(plugin = "java") apply(plugin = "com.diffplug.spotless") apply(plugin = "net.kyori.indra.licenser.spotless") + apply(plugin = "maven-publish") val targetJavaVersion: String by project val targetVersion = targetJavaVersion.toInt() @@ -101,4 +102,12 @@ subprojects { shouldResolveConsistentlyWith(configurations.getByName("modImplementation")) } } + + extensions.configure(PublishingExtension::class) { + publications { + register("maven", MavenPublication::class) { + from(components.getByName("java")) + } + } + } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 32c16214..ce44ab35 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,8 @@ minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } parchment = { module = "org.parchmentmc.data:parchment-1.20.6", version = "2024.05.01" } fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabricLoader" } fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabricApi" } +fabric-api-bom = { module = "net.fabricmc.fabric-api:fabric-api-bom", version.ref = "fabricApi" } +fabric-api-networking = { module = "net.fabricmc.fabric-api:fabric-networking-api-v1" } modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" } neoforge = { module = "net.neoforged:neoforge", version = "20.6.119"} viafabricplus-api = { module = "de.florianmichael:ViaFabricPlus", version.ref = "viafabricplus" } @@ -31,5 +33,6 @@ javaEcosystemCapabilities = { id = "org.gradlex.java-ecosystem-capabilities", ve loom = { id = "dev.architectury.loom", version = "1.6.397" } minotaur = { id = "com.modrinth.minotaur", version = "2.8.7" } publishGithubRelease = { id = "ca.stellardrift.publish-github-release", version = "0.1.0" } +shadow = { id = "io.github.goooler.shadow", version = "8.1.7" } spotless = { id = "com.diffplug.spotless", version = "6.25.0" } versions = { id = "com.github.ben-manes.versions", version = "0.51.0" } diff --git a/worldeditcui-fabric/build.gradle.kts b/worldeditcui-fabric/build.gradle.kts index 20387a11..7462d01c 100644 --- a/worldeditcui-fabric/build.gradle.kts +++ b/worldeditcui-fabric/build.gradle.kts @@ -37,7 +37,7 @@ val fabricApi by configurations.creating dependencies { implementation(project(":worldeditcui-protocol-fabric", configuration = "namedElements")) { isTransitive = false } implementation(project(":worldeditcui-protocol-common", configuration = "namedElements")) { isTransitive = false } - include(project(":worldeditcui-protocol-fabric")) // todo shadow? + include(project(":worldeditcui-protocol-fabric")) modImplementation(libs.fabric.loader) modImplementation(libs.modmenu) modCompileOnly(libs.viafabricplus.api) { diff --git a/worldeditcui-protocol-fabric/build.gradle.kts b/worldeditcui-protocol-fabric/build.gradle.kts index 4fa0946e..f0988693 100644 --- a/worldeditcui-protocol-fabric/build.gradle.kts +++ b/worldeditcui-protocol-fabric/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.architecturyPlugin) alias(libs.plugins.loom) + alias(libs.plugins.shadow) } architectury { @@ -16,18 +17,28 @@ configurations { compileClasspath { extendsFrom(common.get()) } runtimeClasspath { extendsFrom(common.get()) } "developmentFabric" { extendsFrom(common.get()) } +} -// Files in this configuration will be bundled into your mod using the Shadow plugin. -// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding - val shadowBundle = dependencyScope("shadowBundle") - val shadowBundleClasspath = resolvable("shadowBundleClasspath") { - extendsFrom(shadowBundle.get()) - } +val shadowBundle = configurations.dependencyScope("shadowBundle") +val shadowBundleClasspath = configurations.resolvable("shadowBundleClasspath") { + extendsFrom(shadowBundle.get()) } dependencies { "common"(project(":worldeditcui-protocol-common", configuration = "namedElements")) { isTransitive = false } "shadowBundle"(project(":worldeditcui-protocol-common", configuration = "transformProductionFabric")) modImplementation(libs.fabric.loader) - modImplementation(libs.fabric.api) + modImplementation(platform(libs.fabric.api.bom)) + modImplementation(libs.fabric.api.networking) +} + +tasks { + shadowJar { + configurations = listOf(shadowBundleClasspath.get()) + archiveClassifier = "dev-shadow" + } + + remapJar { + inputFile = shadowJar.flatMap { it.archiveFile } + } } diff --git a/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketHandler.java b/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketHandler.java index f40fab74..86fc76c1 100644 --- a/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketHandler.java +++ b/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketHandler.java @@ -16,6 +16,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import org.apache.commons.compress.archivers.sevenz.CLI; import org.enginehub.worldeditcui.protocol.CUIPacket; import org.enginehub.worldeditcui.protocol.CUIPacketHandler; @@ -41,7 +42,7 @@ static void register() { static void registerClient() { ClientPlayNetworking.registerGlobalReceiver(CUIPacket.TYPE, (pkt, ctx) -> { final PacketContext cuiCtx = new PacketContext(ctx.player(), ctx.client()); - for (BiConsumer handler : SERVERBOUND_HANDLERS) { + for (BiConsumer handler : CLIENTBOUND_HANDLERS) { handler.accept(pkt, cuiCtx); } }); diff --git a/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketRegistration.java b/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketRegistration.java index 77b971b7..eace301f 100644 --- a/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketRegistration.java +++ b/worldeditcui-protocol-fabric/src/main/java/org/enginehub/worldeditcui/fabric/network/FabricCUIPacketRegistration.java @@ -21,8 +21,8 @@ public class FabricCUIPacketRegistration implements ModInitializer { @Override public void onInitialize() { - FabricCUIPacketHandler.register(); PayloadTypeRegistry.playS2C().register(CUIPacket.TYPE, CUIPacket.CODEC); PayloadTypeRegistry.playC2S().register(CUIPacket.TYPE, CUIPacket.CODEC); + FabricCUIPacketHandler.register(); } } diff --git a/worldeditcui-protocol-fabric/src/main/resources/fabric.mod.json b/worldeditcui-protocol-fabric/src/main/resources/fabric.mod.json index 492ae581..2b70e80f 100644 --- a/worldeditcui-protocol-fabric/src/main/resources/fabric.mod.json +++ b/worldeditcui-protocol-fabric/src/main/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "worldeditcui-protocol", + "id": "worldeditcui_protocol", "version": "${version}", "name": "WorldEditCUI Protocol (Fabric)", "description": "Protocol implementation for the client-side user interface for WorldEdit", @@ -17,7 +17,7 @@ }, "custom": { "modmenu": { - "library": true, + "badges": [ "library" ], "links": { "modmenu.discord": "https://discord.gg/enginehub" } diff --git a/worldeditcui-protocol-neoforge/build.gradle.kts b/worldeditcui-protocol-neoforge/build.gradle.kts index 3f5d741d..77b32db6 100644 --- a/worldeditcui-protocol-neoforge/build.gradle.kts +++ b/worldeditcui-protocol-neoforge/build.gradle.kts @@ -1,10 +1,12 @@ plugins { alias(libs.plugins.architecturyPlugin) alias(libs.plugins.loom) + alias(libs.plugins.shadow) } architectury { neoForge() + platformSetupLoomIde() } configurations { @@ -12,13 +14,11 @@ configurations { compileClasspath { extendsFrom(common.get()) } runtimeClasspath { extendsFrom(common.get()) } "developmentNeoForge" { extendsFrom(common.get()) } +} - // Files in this configuration will be bundled into your mod using the Shadow plugin. - // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding - val shadowBundle = dependencyScope("shadowBundle") - val shadowBundleClasspath = resolvable("shadowBundleClasspath") { - extendsFrom(shadowBundle.get()) - } +val shadowBundle = configurations.dependencyScope("shadowBundle") +val shadowBundleClasspath = configurations.resolvable("shadowBundleClasspath") { + extendsFrom(shadowBundle.get()) } dependencies { @@ -31,3 +31,14 @@ dependencies { indraSpotlessLicenser { licenseHeaderFile(rootProject.file("HEADER-PROTOCOL")) } + +tasks { + shadowJar { + configurations = listOf(shadowBundleClasspath.get()) + archiveClassifier = "dev-shadow" + } + + remapJar { + inputFile = shadowJar.flatMap { it.archiveFile } + } +} diff --git a/worldeditcui-protocol-neoforge/src/main/java/org/enginehub/worldeditcui/neoforge/protocol/NeoForgeProtocolMod.java b/worldeditcui-protocol-neoforge/src/main/java/org/enginehub/worldeditcui/neoforge/protocol/NeoForgeProtocolMod.java index 8c2ef65a..3be62b20 100644 --- a/worldeditcui-protocol-neoforge/src/main/java/org/enginehub/worldeditcui/neoforge/protocol/NeoForgeProtocolMod.java +++ b/worldeditcui-protocol-neoforge/src/main/java/org/enginehub/worldeditcui/neoforge/protocol/NeoForgeProtocolMod.java @@ -14,17 +14,23 @@ */ package org.enginehub.worldeditcui.neoforge.protocol; +import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.enginehub.worldeditcui.protocol.CUIPacket; -@Mod("worldeditcui-protocol") +@Mod("worldeditcui_protocol") public class NeoForgeProtocolMod { + + public NeoForgeProtocolMod(final IEventBus modBus) { + modBus.register(this); + } + @SubscribeEvent - public static void registerPacket(final RegisterPayloadHandlersEvent event) { - final PayloadRegistrar registrar = event.registrar(CUIPacket.protocolVersion()); + public void registerPacket(final RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar(CUIPacket.protocolVersion()).optional(); registrar.playBidirectional(CUIPacket.TYPE, CUIPacket.CODEC, NeoForgeCUIPacketHandler.asHandler()); } } diff --git a/worldeditcui-protocol-neoforge/src/main/resources/META-INF/neoforge.mods.toml b/worldeditcui-protocol-neoforge/src/main/resources/META-INF/neoforge.mods.toml index 57855a07..06eb65ff 100644 --- a/worldeditcui-protocol-neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/worldeditcui-protocol-neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -4,7 +4,7 @@ issueTrackerURL = "https://github.com/EngineHub/WorldEditCUI/issues" license = "EPL-2.0" [[mods]] -modId = "worldeditcui-protocol" +modId = "worldeditcui_protocol" version = "${version}" displayName = "WorldEditCUI Protocol (NeoForge)" authors = "lahwran, yetanotherx, Mumfrey, TomyLobo, mikroskeem" @@ -12,14 +12,14 @@ description = ''' Protocol implementation for the client-side user interface for WorldEdit ''' -[[dependencies.worldeditcui-protocol]] +[[dependencies.worldeditcui_protocol]] modId = "neoforge" type = "required" versionRange = "[20.6,)" ordering = "NONE" side = "BOTH" -[[dependencies.worldeditcui-protocol]] +[[dependencies.worldeditcui_protocol]] modId = "minecraft" type = "required" versionRange = "[1.20.6,)"