Skip to content

Commit

Permalink
protocol: fixes and polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Jun 17, 2024
1 parent 5d6af9a commit ab5386c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -101,4 +102,12 @@ subprojects {
shouldResolveConsistentlyWith(configurations.getByName("modImplementation"))
}
}

extensions.configure(PublishingExtension::class) {
publications {
register("maven", MavenPublication::class) {
from(components.getByName("java"))
}
}
}
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
2 changes: 1 addition & 1 deletion worldeditcui-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 18 additions & 7 deletions worldeditcui-protocol-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.architecturyPlugin)
alias(libs.plugins.loom)
alias(libs.plugins.shadow)
}

architectury {
Expand All @@ -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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<CUIPacket, PacketContext> handler : SERVERBOUND_HANDLERS) {
for (BiConsumer<CUIPacket, PacketContext> handler : CLIENTBOUND_HANDLERS) {
handler.accept(pkt, cuiCtx);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -17,7 +17,7 @@
},
"custom": {
"modmenu": {
"library": true,
"badges": [ "library" ],
"links": {
"modmenu.discord": "https://discord.gg/enginehub"
}
Expand Down
23 changes: 17 additions & 6 deletions worldeditcui-protocol-neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
plugins {
alias(libs.plugins.architecturyPlugin)
alias(libs.plugins.loom)
alias(libs.plugins.shadow)
}

architectury {
neoForge()
platformSetupLoomIde()
}

configurations {
val common = dependencyScope("common")
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 {
Expand All @@ -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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ 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"
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,)"
Expand Down

0 comments on commit ab5386c

Please sign in to comment.