diff --git a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts index 1a84a95388..f433f67ed0 100644 --- a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts @@ -10,6 +10,12 @@ group = rootProject.group version = rootProject.version repositories { + mavenLocal { + mavenContent { + snapshotsOnly() + includeGroup("org.enginehub.worldeditcui") + } + } mavenCentral() maven { name = "EngineHub" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df54bea33f..d8bf6296a8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,13 +3,14 @@ codecov = "org.enginehub.codecov:0.2.0" neogradle-userdev = "net.neoforged.gradle.userdev:7.0.107" fabric-loom = "fabric-loom:1.6.9" sponge-spongegradle = "org.spongepowered.gradle.plugin:2.2.0" -sponge-vanillagradle = "org.spongepowered.gradle.vanilla:0.2.1-20240507.024226-82" +sponge-vanillagradle = "org.spongepowered.gradle.vanilla:0.2.1-20240617.053350-83" [versions] kyoriText = "3.0.4" piston = "0.5.10" autoValue = "1.10.4" antlr = "4.13.1" +cuiProtocol = "1.20.6+01-SNAPSHOT" fabric-api = "0.97.8+1.20.6" @@ -29,7 +30,7 @@ lang-version = "1309" [libraries] neogradle-userdev = "net.neoforged.gradle:neoform:7.0.107" -sponge-vanillagradle = "org.spongepowered:vanillagradle:0.2.1-20240507.024226-82" +sponge-vanillagradle = "org.spongepowered:vanillagradle:0.2.1-20240617.053350-83" licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1" grgit = "org.ajoberstar.grgit:grgit-gradle:5.2.2" @@ -149,3 +150,11 @@ version.ref = "antlr" [libraries.antlr4-runtime] module = "org.antlr:antlr4-runtime" + +[libraries.cuiProtocol-fabric] +module = "org.enginehub.worldeditcui:worldeditcui-protocol-fabric" +version.ref = "cuiProtocol" + +[libraries.cuiProtocol-neoforge] +module = "org.enginehub.worldeditcui:worldeditcui-protocol-neoforge" +version.ref = "cuiProtocol" diff --git a/worldedit-fabric/build.gradle.kts b/worldedit-fabric/build.gradle.kts index 273b6d5693..ccf235c0a0 100644 --- a/worldedit-fabric/build.gradle.kts +++ b/worldedit-fabric/build.gradle.kts @@ -38,6 +38,7 @@ repositories { getByName("Mojang") { content { includeGroupAndSubgroups("com.mojang") + includeGroupAndSubgroups("org.lwjgl") } } } @@ -48,6 +49,8 @@ dependencies { "minecraft"(libs.fabric.minecraft) "mappings"(project.the().officialMojangMappings()) "modImplementation"(libs.fabric.loader) + "modImplementation"(libs.cuiProtocol.fabric) + "include"(libs.cuiProtocol.fabric) // [1] Load the API dependencies from the fabric mod json... diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java index 8820c5ad31..ee3935e1b6 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java @@ -19,13 +19,11 @@ package com.sk89q.worldedit.fabric; -import com.sk89q.util.StringUtil; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.fabric.internal.NBTConverter; -import com.sk89q.worldedit.fabric.net.handler.WECUIPacketHandler; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -52,6 +50,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntityType; import org.enginehub.linbus.tree.LinCompoundTag; +import org.enginehub.worldeditcui.protocol.CUIPacket; import java.util.Locale; import java.util.UUID; @@ -123,14 +122,9 @@ public void giveItem(BaseItemStack itemStack) { @Override public void dispatchCUIEvent(CUIEvent event) { - String[] params = event.getParameters(); - String send = event.getTypeId(); - if (params.length > 0) { - send = send + "|" + StringUtil.joinString(params, "|"); - } ServerPlayNetworking.send( this.player, - new WECUIPacketHandler.CuiPacket(send) + new CUIPacket(event.getTypeId(), event.getParameters()) ); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java index fb4c48277d..760ee6587b 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java @@ -30,7 +30,6 @@ import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.PlatformManager; -import com.sk89q.worldedit.fabric.net.handler.WECUIPacketHandler; import com.sk89q.worldedit.internal.anvil.ChunkDeleter; import com.sk89q.worldedit.internal.event.InteractionDebouncer; import com.sk89q.worldedit.internal.util.LogManagerCompat; @@ -82,6 +81,8 @@ import net.minecraft.world.phys.BlockHitResult; import org.apache.logging.log4j.Logger; import org.enginehub.piston.Command; +import org.enginehub.worldeditcui.protocol.CUIPacket; +import org.enginehub.worldeditcui.protocol.CUIPacketHandler; import java.io.IOException; import java.io.UncheckedIOException; @@ -169,7 +170,7 @@ public void onInitialize() { config = new FabricConfiguration(this); this.provider = getInitialPermissionsProvider(); - WECUIPacketHandler.init(); + CUIPacketHandler.instance().registerServerboundHandler(this::onCuiPacket); ServerTickEvents.END_SERVER_TICK.register(ThreadSafeCache.getInstance()); CommandRegistrationCallback.EVENT.register(this::registerCommands); @@ -395,6 +396,12 @@ private void onPlayerDisconnect(ServerGamePacketListenerImpl handler, MinecraftS .post(new SessionIdleEvent(new FabricPlayer.SessionKeyImpl(handler.player))); } + private void onCuiPacket(CUIPacket payload, CUIPacketHandler.PacketContext context) { + LocalSession session = FabricWorldEdit.inst.getSession((ServerPlayer) context.player()); + FabricPlayer actor = FabricAdapter.adaptPlayer((ServerPlayer) context.player()); + session.handleCUIInitializationMessage(payload.eventType() + "|" + String.join("|", payload.args()), actor); + } + /** * Get the configuration. * diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/net/handler/WECUIPacketHandler.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/net/handler/WECUIPacketHandler.java deleted file mode 100644 index a28ee5fa9b..0000000000 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/net/handler/WECUIPacketHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.fabric.net.handler; - -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.fabric.FabricAdapter; -import com.sk89q.worldedit.fabric.FabricPlayer; -import com.sk89q.worldedit.fabric.FabricWorldEdit; -import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; - -import java.nio.charset.StandardCharsets; - -public final class WECUIPacketHandler { - private WECUIPacketHandler() { - } - - public static final ResourceLocation CUI_IDENTIFIER = new ResourceLocation(FabricWorldEdit.MOD_ID, FabricWorldEdit.CUI_PLUGIN_CHANNEL); - - public record CuiPacket(String text) implements CustomPacketPayload { - public static final Type TYPE = new Type<>(CUI_IDENTIFIER); - - @Override - public Type type() { - return TYPE; - } - } - - public static void init() { - StreamCodec codec = CustomPacketPayload.codec( - (packet, buffer) -> buffer.writeCharSequence(packet.text(), StandardCharsets.UTF_8), - buffer -> new CuiPacket(buffer.readCharSequence(buffer.readableBytes(), StandardCharsets.UTF_8).toString()) - ); - PayloadTypeRegistry.playC2S().register(CuiPacket.TYPE, codec); - PayloadTypeRegistry.playS2C().register(CuiPacket.TYPE, codec); - ServerPlayNetworking.registerGlobalReceiver(CuiPacket.TYPE, (payload, context) -> { - LocalSession session = FabricWorldEdit.inst.getSession(context.player()); - FabricPlayer actor = FabricAdapter.adaptPlayer(context.player()); - session.handleCUIInitializationMessage(payload.text(), actor); - }); - } -} diff --git a/worldedit-mod/build.gradle.kts b/worldedit-mod/build.gradle.kts index e1c39837f2..aaf5c855a0 100644 --- a/worldedit-mod/build.gradle.kts +++ b/worldedit-mod/build.gradle.kts @@ -64,13 +64,13 @@ val fabricZipTree = zipTree( project(":worldedit-fabric").tasks.named("remapShadowJar").flatMap { it.archiveFile } ) val forgeZipTree = zipTree( - project(":worldedit-neoforge").tasks.named("shadowJar").map { it.outputs.files.singleFile } + project(":worldedit-neoforge").tasks.named("jarJar").map { it.outputs.files.singleFile } ) val mergeManifests = tasks.register("mergeManifests") { dependsOn( project(":worldedit-fabric").tasks.named("remapShadowJar"), - project(":worldedit-neoforge").tasks.named("shadowJar") + project(":worldedit-neoforge").tasks.named("jarJar") ) inputManifests.from( fabricZipTree.matching { include("META-INF/MANIFEST.MF") }, @@ -82,7 +82,7 @@ val mergeManifests = tasks.register("mergeManifests") { tasks.register("jar") { dependsOn( project(":worldedit-fabric").tasks.named("remapShadowJar"), - project(":worldedit-neoforge").tasks.named("shadowJar"), + project(":worldedit-neoforge").tasks.named("jarJar"), mergeManifests ) from(fabricZipTree) { diff --git a/worldedit-neoforge/build.gradle.kts b/worldedit-neoforge/build.gradle.kts index 3fc0bdbec1..59692d88a1 100644 --- a/worldedit-neoforge/build.gradle.kts +++ b/worldedit-neoforge/build.gradle.kts @@ -25,12 +25,19 @@ val apiClasspath = configurations.create("apiClasspath") { isCanBeResolved = true extendsFrom(configurations.api.get()) } +jarJar.disableDefaultSources() repositories { val toRemove = mutableListOf() for (repo in project.repositories) { if (repo is MavenArtifactRepository && repo.url.toString() == "https://maven.neoforged.net/releases/") { toRemove.add(repo) + } else if (repo is MavenArtifactRepository && repo.url.toString() == "https://libraries.minecraft.net/") { + exclusiveContent { + forRepositories(repo).filter { + includeGroupAndSubgroups("org.lwjgl") + } + } } } toRemove.forEach { remove(it) } @@ -44,6 +51,8 @@ dependencies { "api"(project(":worldedit-core")) "implementation"(libs.neoforge) + "implementation"(libs.cuiProtocol.neoforge) + jarJar(libs.cuiProtocol.neoforge) } minecraft { @@ -110,6 +119,7 @@ tasks.named("processResources") { } tasks.named("shadowJar") { + archiveClassifier = "dist-slim" dependencies { relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4") relocate("net.royawesome.jlibnoise", "com.sk89q.worldedit.jlibnoise") @@ -122,3 +132,13 @@ tasks.named("shadowJar") { exclude(dependency("org.mozilla:rhino-runtime")) } } + +tasks.jarJar { + archiveClassifier = "dist" + val shadowJar = tasks.shadowJar.get() + dependsOn(shadowJar) + manifest.inheritFrom(shadowJar.manifest) + from(project.zipTree(shadowJar.archiveFile).matching { + exclude("META-INF/MANIFEST.MF") + }) +} diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java index fddd8bc453..2291ea11c0 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgePlayer.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.neoforge; -import com.sk89q.util.StringUtil; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; @@ -28,7 +27,6 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.neoforge.internal.NBTConverter; -import com.sk89q.worldedit.neoforge.net.handler.WECUIPacketHandler; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -55,6 +53,7 @@ import java.util.Locale; import java.util.UUID; import javax.annotation.Nullable; +import org.enginehub.worldeditcui.protocol.CUIPacket; public class NeoForgePlayer extends AbstractPlayerActor { @@ -124,12 +123,7 @@ public void giveItem(BaseItemStack itemStack) { @Override public void dispatchCUIEvent(CUIEvent event) { - String[] params = event.getParameters(); - String send = event.getTypeId(); - if (params.length > 0) { - send = send + "|" + StringUtil.joinString(params, "|"); - } - PacketDistributor.sendToPlayer(this.player, new WECUIPacketHandler.CuiPacket(send)); + PacketDistributor.sendToPlayer(this.player, new CUIPacket(event.getTypeId(), event.getParameters())); } private void sendMessage(net.minecraft.network.chat.Component textComponent) { diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java index 9f3d0beb77..99c8dbba3e 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java @@ -34,7 +34,6 @@ import com.sk89q.worldedit.internal.anvil.ChunkDeleter; import com.sk89q.worldedit.internal.event.InteractionDebouncer; import com.sk89q.worldedit.internal.util.LogManagerCompat; -import com.sk89q.worldedit.neoforge.net.handler.WECUIPacketHandler; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeCategory; @@ -88,6 +87,8 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.enginehub.worldeditcui.protocol.CUIPacket; +import org.enginehub.worldeditcui.protocol.CUIPacketHandler; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME; @@ -119,7 +120,6 @@ public NeoForgeWorldEdit(IEventBus modBus) { inst = this; modBus.addListener(this::init); - modBus.register(WECUIPacketHandler.class); NeoForge.EVENT_BUS.register(ThreadSafeCache.getInstance()); NeoForge.EVENT_BUS.register(this); @@ -138,6 +138,8 @@ private void init(FMLCommonSetupEvent event) { } } + CUIPacketHandler.instance().registerServerboundHandler(this::onCuiPacket); + setupPlatform(); LOGGER.info("WorldEdit for NeoForge (version {}) is loaded", getInternalVersion()); @@ -389,6 +391,15 @@ public void onPlayerLogOut(PlayerEvent.PlayerLoggedOutEvent event) { .post(new SessionIdleEvent(new NeoForgePlayer.SessionKeyImpl(player))); } } + private void onCuiPacket(CUIPacket payload, CUIPacketHandler.PacketContext context) { + if (!(context.player() instanceof ServerPlayer player)) { + // Client-side packet, ignore (this is for WECUI to handle) + return; + } + LocalSession session = NeoForgeWorldEdit.inst.getSession(player); + NeoForgePlayer actor = NeoForgeAdapter.adaptPlayer(player); + session.handleCUIInitializationMessage(payload.eventType() + "|" + String.join("|", payload.args()), actor); + } /** * Get the configuration. diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/net/handler/WECUIPacketHandler.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/net/handler/WECUIPacketHandler.java deleted file mode 100644 index 6ea3adffd9..0000000000 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/net/handler/WECUIPacketHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.neoforge.net.handler; - -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.neoforge.NeoForgeAdapter; -import com.sk89q.worldedit.neoforge.NeoForgePlayer; -import com.sk89q.worldedit.neoforge.NeoForgeWorldEdit; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; - -import java.nio.charset.StandardCharsets; - -public final class WECUIPacketHandler { - private WECUIPacketHandler() { - } - - private static final String PROTOCOL_VERSION = "1"; - - public static final ResourceLocation CUI_IDENTIFIER = new ResourceLocation(NeoForgeWorldEdit.MOD_ID, NeoForgeWorldEdit.CUI_PLUGIN_CHANNEL); - - public record CuiPacket(String text) implements CustomPacketPayload { - public static final Type TYPE = new Type<>(CUI_IDENTIFIER); - - @Override - public Type type() { - return TYPE; - } - } - - @SubscribeEvent - public static void register(RegisterPayloadHandlersEvent event) { - event.registrar(PROTOCOL_VERSION) - .optional() - .playBidirectional( - CuiPacket.TYPE, - CustomPacketPayload.codec( - (packet, buffer) -> buffer.writeCharSequence(packet.text(), StandardCharsets.UTF_8), - buffer -> new CuiPacket(buffer.readCharSequence(buffer.readableBytes(), StandardCharsets.UTF_8).toString()) - ), - (payload, context) -> { - if (!(context.player() instanceof ServerPlayer player)) { - // Client-side packet, ignore (this is for WECUI to handle) - return; - } - LocalSession session = NeoForgeWorldEdit.inst.getSession(player); - NeoForgePlayer actor = NeoForgeAdapter.adaptPlayer(player); - session.handleCUIInitializationMessage(payload.text(), actor); - } - ); - } - -}