From 06ebd1d3479b9edda29d7de58c036b49db3d0928 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sun, 22 Dec 2024 22:33:02 +0100 Subject: [PATCH 1/3] Fix dev classpath when root directory is not "Sponge" --- vanilla/build.gradle.kts | 1 + .../vanilla/devlaunch/SourceSet.java | 30 ++++--- .../devlaunch/SpongeDevClasspathFixer.java | 85 +++++++++++-------- 3 files changed, 65 insertions(+), 51 deletions(-) diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index b936a70281c..3595ab06aab 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -329,6 +329,7 @@ minecraft { mainClass("net.minecraftforge.bootstrap.ForgeBootstrap") // Configure resources + jvmArgs("-Dsponge.dev.root=" + project.rootDir) jvmArgs("-Dsponge.dev.boot=" + bootLayerConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) jvmArgs("-Dsponge.dev.gameShaded=" + gameShadedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name }) } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java index a4fa3b1b537..6bc2ef07a88 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SourceSet.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.List; -public record SourceSet(String project, String name, String format) { +public record SourceSet(Path project, String name, String format) { @Override public String toString() { @@ -57,32 +57,34 @@ public static SourceSet identify(Path path) { } // from right to left - final List parts = new ArrayList<>(); + final List names = new ArrayList<>(); + final List paths = new ArrayList<>(); while (path != null) { - parts.add(path.getFileName().toString()); - if (parts.size() >= 5) { + names.add(path.getFileName().toString()); + paths.add(path); + if (names.size() >= 5) { break; } path = path.getParent(); } - if (parts.size() >= 4 && (parts.get(0).equals("classes") || parts.get(0).equals("resources"))) { - final String name = parts.get(1); - return new SourceSet(parts.get(3), name.equals("production") ? "main" : name, "IntelliJ"); + if (names.size() >= 4 && (names.get(0).equals("classes") || names.get(0).equals("resources"))) { + final String name = names.get(1); + return new SourceSet(paths.get(3), name.equals("production") ? "main" : name, "IntelliJ"); } - if (parts.size() >= 4 && (parts.get(1).equals("resources") || parts.get(1).equals("generated"))) { - return new SourceSet(parts.get(3), parts.get(0), "Gradle"); + if (names.size() >= 4 && (names.get(1).equals("resources") || names.get(1).equals("generated"))) { + return new SourceSet(paths.get(3), names.get(0), "Gradle"); } - if (parts.size() >= 5 && parts.get(2).equals("classes")) { - return new SourceSet(parts.get(4), parts.get(0), "Gradle"); + if (names.size() >= 5 && names.get(2).equals("classes")) { + return new SourceSet(paths.get(4), names.get(0), "Gradle"); } - if (parts.size() >= 3 && parts.get(1).equals("bin")) { - return new SourceSet(parts.get(2), parts.get(0), "Eclipse"); + if (names.size() >= 3 && names.get(1).equals("bin")) { + return new SourceSet(paths.get(2), names.get(0), "Eclipse"); } - return new SourceSet("", parts.get(0), "Unknown"); + return new SourceSet(paths.get(0), "?", "Unknown"); } } diff --git a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java index 47c8f979594..ba527b23e6b 100644 --- a/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java +++ b/vanilla/src/devlaunch/java/org/spongepowered/vanilla/devlaunch/SpongeDevClasspathFixer.java @@ -28,6 +28,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -51,6 +52,7 @@ public String name() { */ @Override public boolean process(final List classpath) { + final Path spongeRoot = Paths.get(System.getProperty("sponge.dev.root")).toAbsolutePath(); final Set bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(";")); final Set gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(";")); @@ -67,46 +69,55 @@ public boolean process(final List classpath) { return false; } - final Path path = paths[0]; + final Path path = paths[0].toAbsolutePath(); final SourceSet sourceSet = SourceSet.identify(path); if (sourceSet != null) { - if (DEBUG) { - System.out.println("SourceSet (" + sourceSet + "): " + path); - } + if (sourceSet.project().startsWith(spongeRoot)) { + if (DEBUG) { + System.out.println("Sponge SourceSet (" + sourceSet + "): " + path); + } - switch (sourceSet.project()) { - case "modlauncher-transformers": - bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path); - break; - case "SpongeAPI": - switch (sourceSet.name()) { - case "ap": - // ignore - break; - case "main": - hasAPISourceSet.set(true); - // no break - default: - spongeImplUnion.add(path); - break; - } - break; - case "Sponge", "vanilla": - switch (sourceSet.name()) { - case "devlaunch": - // ignore - break; - case "applaunch": - bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path); - break; - default: - spongeImplUnion.add(path); - break; - } - break; - default: - unknownProjects.computeIfAbsent(sourceSet.project(), k -> new LinkedList<>()).add(path); - break; + final String projectName = spongeRoot.relativize(sourceSet.project()).toString(); + switch (projectName) { + case "modlauncher-transformers": + bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path); + break; + case "SpongeAPI": + switch (sourceSet.name()) { + case "ap": + // ignore + break; + case "main": + hasAPISourceSet.set(true); + // no break + default: + spongeImplUnion.add(path); + break; + } + break; + case "", "vanilla": + switch (sourceSet.name()) { + case "devlaunch": + // ignore + break; + case "applaunch": + bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path); + break; + default: + spongeImplUnion.add(path); + break; + } + break; + default: + unknownProjects.computeIfAbsent(projectName, k -> new LinkedList<>()).add(path); + break; + } + } else { + if (DEBUG) { + System.out.println("External SourceSet (" + sourceSet + "): " + path); + } + + unknownProjects.computeIfAbsent(sourceSet.project().toString(), k -> new LinkedList<>()).add(path); } return true; } From e5e0121efd81dd8d9921262a9e53800d91a7ca1a Mon Sep 17 00:00:00 2001 From: aromaa Date: Mon, 23 Dec 2024 00:45:33 +0200 Subject: [PATCH 2/3] Fix ExplosionEvent.Pre cancelling --- .../tracker/server/level/ServerLevelMixin_Tracker.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java index e1766cb999a..990a2389412 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java @@ -373,6 +373,14 @@ public abstract class ServerLevelMixin_Tracker extends LevelMixin_Tracker implem this.tracker$apiExplosion = apiExplosion; } + @Inject(method = "explode", cancellable = true, at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/ServerExplosion;explode()V", shift = At.Shift.AFTER)) + private void tracker$onCancelled(final CallbackInfo ci) { + if (this.tracker$apiExplosion == null) { + ci.cancel(); + } + } + /** * See {@link net.minecraft.client.multiplayer.ClientPacketListener#handleExplosion} for client side handling */ From 707b3f1ac6fd309338d6affd9b60bd4a4938b45d Mon Sep 17 00:00:00 2001 From: aromaa Date: Mon, 23 Dec 2024 00:46:14 +0200 Subject: [PATCH 3/3] Implement tab list entry order --- SpongeAPI | 2 +- .../common/entity/player/tab/SpongeTabList.java | 4 ++-- .../entity/player/tab/SpongeTabListEntry.java | 16 +++++++++++++++- .../entity/player/tab/TabListEntryBuilder.java | 11 ++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index c0f65a12e41..f4245597d6d 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit c0f65a12e41afb4a6891efd0c6c00a7b0f2ddea4 +Subproject commit f4245597d6dc09becafbcff46a1afbc365ee2eca diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java index 8d49e1212f2..072decba587 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabList.java @@ -151,6 +151,7 @@ private void addEntry(final ClientboundPlayerInfoUpdatePacket.Entry entry) { entry.latency(), (GameMode) (Object) entry.gameMode(), entry.listed(), + entry.listOrder(), entry.chatSession() == null ? null : entry.chatSession().profilePublicKey() ), false); } @@ -190,11 +191,10 @@ public Optional removeEntry(final UUID uniqueId) { @SuppressWarnings("ConstantConditions") void sendUpdate(final TabListEntry entry, final EnumSet actions) { final ClientboundPlayerInfoUpdatePacket packet = new ClientboundPlayerInfoUpdatePacket(actions, List.of()); - int listOrder = 0; // TODO expose to API final RemoteChatSession.Data chatSessionData = ((SpongeTabListEntry) entry).profilePublicKey() == null ? null : new RemoteChatSession.Data(entry.profile().uuid(), ((SpongeTabListEntry) entry).profilePublicKey()); final net.minecraft.network.chat.Component displayName = entry.displayName().isPresent() ? SpongeAdventure.asVanilla(entry.displayName().get()) : null; final ClientboundPlayerInfoUpdatePacket.Entry data = new ClientboundPlayerInfoUpdatePacket.Entry(entry.profile().uniqueId(), SpongeGameProfile.toMcProfile(entry.profile()), - entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, listOrder, chatSessionData); + entry.listed(), entry.latency(), (GameType) (Object) entry.gameMode(), displayName, entry.weight(), chatSessionData); ((ClientboundPlayerInfoUpdatePacketAccessor) packet).accessor$entries(List.of(data)); this.player.connection.send(packet); } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java index 355ada3d91b..566f25f008e 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/SpongeTabListEntry.java @@ -52,12 +52,13 @@ public final class SpongeTabListEntry implements TabListEntry { private int latency; private GameMode gameMode; private boolean listed; + private int weight; private boolean updateWithoutSend; private final ProfilePublicKey.Data profilePublicKey; public SpongeTabListEntry( final TabList list, final GameProfile profile, @Nullable final Component displayName, final int latency, final GameMode gameMode, - final boolean listed, final ProfilePublicKey.Data profilePublicKey) { + final boolean listed, final int weight, final ProfilePublicKey.Data profilePublicKey) { Preconditions.checkState(list instanceof SpongeTabList, "list is not a SpongeTabList"); this.list = (SpongeTabList) list; this.profile = Objects.requireNonNull(profile, "profile"); @@ -65,6 +66,7 @@ public SpongeTabListEntry( this.latency = latency; this.gameMode = Objects.requireNonNull(gameMode, "game mode"); this.listed = listed; + this.weight = weight; this.profilePublicKey = profilePublicKey; } @@ -126,6 +128,18 @@ public SpongeTabListEntry setListed(boolean listed) { return this; } + @Override + public int weight() { + return this.weight; + } + + @Override + public SpongeTabListEntry setWeight(int weight) { + this.weight = weight; + this.sendUpdate(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LIST_ORDER); + return this; + } + public ProfilePublicKey.Data profilePublicKey() { return this.profilePublicKey; } diff --git a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java index cb974eb6caf..3c1e136d1cd 100644 --- a/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java +++ b/src/main/java/org/spongepowered/common/entity/player/tab/TabListEntryBuilder.java @@ -44,6 +44,7 @@ public final class TabListEntryBuilder implements TabListEntry.Builder { private int latency; private boolean listed = true; private @Nullable GameMode gameMode; + private int weight; @Override public TabListEntry.Builder list(TabList list) { @@ -81,13 +82,19 @@ public TabListEntry.Builder listed(boolean listed) { return this; } + @Override + public TabListEntry.Builder weight(int weight) { + this.weight = weight; + return this; + } + @Override public TabListEntry build() { Preconditions.checkState(this.list != null, "list must be set"); Preconditions.checkState(this.profile != null, "profile must be set"); Preconditions.checkState(this.gameMode != null, "game mode must be set"); - return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, null); + return new SpongeTabListEntry(this.list, this.profile, this.displayName, this.latency, this.gameMode, this.listed, this.weight, null); } @Override @@ -97,6 +104,7 @@ public TabListEntry.Builder from(TabListEntry value) { this.displayName = value.displayName().orElse(null); this.latency = value.latency(); this.gameMode = Objects.requireNonNull(value.gameMode(), "game mode"); + this.weight = value.weight(); return this; } @@ -107,6 +115,7 @@ public TabListEntry.Builder reset() { this.displayName = null; this.latency = 0; this.gameMode = null; + this.weight = 0; return this; }