Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WECUI protocol library #2554

Draft
wants to merge 2 commits into
base: version/7.3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build-logic/src/main/kotlin/buildlogic.common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ group = rootProject.group
version = rootProject.version

repositories {
mavenLocal {
mavenContent {
snapshotsOnly()
includeGroup("org.enginehub.worldeditcui")
}
}
mavenCentral()
maven {
name = "EngineHub"
Expand Down
13 changes: 11 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down Expand Up @@ -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"
3 changes: 3 additions & 0 deletions worldedit-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ repositories {
getByName("Mojang") {
content {
includeGroupAndSubgroups("com.mojang")
includeGroupAndSubgroups("org.lwjgl")
}
}
}
Expand All @@ -48,6 +49,8 @@ dependencies {
"minecraft"(libs.fabric.minecraft)
"mappings"(project.the<LoomGradleExtensionAPI>().officialMojangMappings())
"modImplementation"(libs.fabric.loader)
"modImplementation"(libs.cuiProtocol.fabric)
"include"(libs.cuiProtocol.fabric)


// [1] Load the API dependencies from the fabric mod json...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions worldedit-mod/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ val fabricZipTree = zipTree(
project(":worldedit-fabric").tasks.named<RemapJarTask>("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>("mergeManifests") {
dependsOn(
project(":worldedit-fabric").tasks.named<RemapJarTask>("remapShadowJar"),
project(":worldedit-neoforge").tasks.named("shadowJar")
project(":worldedit-neoforge").tasks.named("jarJar")
)
inputManifests.from(
fabricZipTree.matching { include("META-INF/MANIFEST.MF") },
Expand All @@ -82,7 +82,7 @@ val mergeManifests = tasks.register<MergeManifests>("mergeManifests") {
tasks.register<Jar>("jar") {
dependsOn(
project(":worldedit-fabric").tasks.named<RemapJarTask>("remapShadowJar"),
project(":worldedit-neoforge").tasks.named("shadowJar"),
project(":worldedit-neoforge").tasks.named("jarJar"),
mergeManifests
)
from(fabricZipTree) {
Expand Down
20 changes: 20 additions & 0 deletions worldedit-neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ val apiClasspath = configurations.create("apiClasspath") {
isCanBeResolved = true
extendsFrom(configurations.api.get())
}
jarJar.disableDefaultSources()

repositories {
val toRemove = mutableListOf<MavenArtifactRepository>()
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) }
Expand All @@ -44,6 +51,8 @@ dependencies {
"api"(project(":worldedit-core"))

"implementation"(libs.neoforge)
"implementation"(libs.cuiProtocol.neoforge)
jarJar(libs.cuiProtocol.neoforge)
}

minecraft {
Expand Down Expand Up @@ -110,6 +119,7 @@ tasks.named<Copy>("processResources") {
}

tasks.named<ShadowJar>("shadowJar") {
archiveClassifier = "dist-slim"
dependencies {
relocate("org.antlr.v4", "com.sk89q.worldedit.antlr4")
relocate("net.royawesome.jlibnoise", "com.sk89q.worldedit.jlibnoise")
Expand All @@ -122,3 +132,13 @@ tasks.named<ShadowJar>("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")
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -138,6 +138,8 @@ private void init(FMLCommonSetupEvent event) {
}
}

CUIPacketHandler.instance().registerServerboundHandler(this::onCuiPacket);

setupPlatform();

LOGGER.info("WorldEdit for NeoForge (version {}) is loaded", getInternalVersion());
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading