Fixed the same thing for 1.21.5

This commit is contained in:
2026-03-21 20:46:10 +01:00
parent 39dc0963ce
commit 2bbabff979
2 changed files with 32 additions and 52 deletions
@@ -127,4 +127,36 @@ public abstract class MinecraftClientMixin implements MinecraftClientRef {
public void executeOnThread(Runnable runnable) {
((java.util.concurrent.Executor) (Object) this).execute(runnable);
}
@Override
@SuppressWarnings("resource")
public String getPlayerListEntry(UUID uuid) {
var client = (MinecraftClient) (Object) this;
var handler = client.getNetworkHandler();
if (handler == null)
return null;
var entry = handler.getPlayerListEntry(uuid);
if (entry == null)
return null;
return entry.getProfile().getName();
}
@Override
@SuppressWarnings("resource")
public UUID getPlayerListEntryUUID(String name) {
var client = (MinecraftClient) (Object) this;
var handler = client.getNetworkHandler();
if (handler == null)
return null;
var entry = handler.getPlayerListEntry(name);
if (entry == null)
return null;
return entry.getProfile().getId();
}
}
@@ -1,52 +0,0 @@
package org.saturnclient.saturnclient;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import org.saturnclient.client.ServiceClient;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.MinecraftClient;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
public class PlayerTracker {
private static Set<UUID> trackedPlayers = new HashSet<>();
public static void initialize() {
// When client joins a server, reset tracked players
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
trackedPlayers.clear();
client.execute(() -> {
checkForNewPlayers(SaturnClient.client);
});
});
// Check for new players every tick
ClientTickEvents.END_CLIENT_TICK.register(client -> checkForNewPlayers(client));
}
private static void checkForNewPlayers(MinecraftClient client) {
if (client.getNetworkHandler() == null)
return;
for (PlayerListEntry player : client.getNetworkHandler().getPlayerList()) {
UUID playerUUID = player.getProfile().getId();
if (!trackedPlayers.contains(playerUUID)) {
// A new player has joined
onPlayerJoin(client, player);
trackedPlayers.add(playerUUID);
}
}
}
private static void onPlayerJoin(MinecraftClient client, PlayerListEntry player) {
GameProfile profile = player.getProfile();
ServiceClient.player(profile.getId(), profile.getName());
}
}