Skip to content

Commit

Permalink
chore: update to from api-13
Browse files Browse the repository at this point in the history
  • Loading branch information
gabizou committed Dec 26, 2024
2 parents cd1052a + 707b3f1 commit 770056c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SpongeAPI
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -190,11 +191,10 @@ public Optional<TabListEntry> removeEntry(final UUID uniqueId) {
@SuppressWarnings("ConstantConditions")
void sendUpdate(final TabListEntry entry, final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ 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");
this.displayName = displayName;
this.latency = latency;
this.gameMode = Objects.requireNonNull(gameMode, "game mode");
this.listed = listed;
this.weight = weight;
this.profilePublicKey = profilePublicKey;
}

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

Expand All @@ -107,6 +115,7 @@ public TabListEntry.Builder reset() {
this.displayName = null;
this.latency = 0;
this.gameMode = null;
this.weight = 0;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ minecraft {
// jvmArgs("-Dbsl.debug=true") // Uncomment to debug bootstrap classpath
mainClass("net.minecraftforge.bootstrap.ForgeBootstrap")

// Configure resources
jvmArgs("-Dsponge.dev.root=" + project.rootDir)
jvmArgs("-Dsponge.dev.boot=$bootFileNames")
jvmArgs("-Dsponge.dev.gameShaded=$gameShadedFileNames")
Expand Down

0 comments on commit 770056c

Please sign in to comment.