Migrate player integration coverage to server-thread hosting

Co-Authored-By: OpenAI Codex GPT-6.1 <noreply@openai.com>
This commit is contained in:
rdbtCVS
2026-10-25 19:36:11 +00:00
parent 8177a6f450
commit bd09f8b03e
29 changed files with 932 additions and 100 deletions
@@ -10,6 +10,8 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GlyphSource;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
@@ -31,9 +33,13 @@ import net.minecraft.util.RandomSource;
*/
public final class ParityFont {
public static ResourceManager resources() throws Exception {
return resources(Path.of("/nonexistent-horizon-assets"));
}
public static ResourceManager resources(Path assets) throws Exception {
var method = net.minecraft.client.resources.ClientPackSource.class.getDeclaredMethod("createVanillaPackSource", Path.class);
method.setAccessible(true);
var pack = (net.minecraft.server.packs.VanillaPackResources) method.invoke(null, Path.of("/nonexistent-horizon-assets"));
var pack = (net.minecraft.server.packs.VanillaPackResources) method.invoke(null, assets);
return pack.asResourceManager();
}
@@ -50,6 +56,38 @@ public final class ParityFont {
}
}
}
return create(providers);
}
/** The full default font, including references and the external Unihex fallback. */
public static Font createDefault(ResourceManager resources) throws Exception {
List<GlyphProvider> providers = new ArrayList<>();
loadProviders(resources, Identifier.withDefaultNamespace("default"), providers, new HashSet<>());
return create(providers);
}
private static void loadProviders(ResourceManager resources, Identifier font, List<GlyphProvider> providers,
Set<Identifier> visiting) throws Exception {
if (!visiting.add(font)) throw new IllegalArgumentException("Cyclic font reference: " + font);
var file = font.withPath("font/" + font.getPath() + ".json");
try (var reader = new InputStreamReader(resources.open(file), StandardCharsets.UTF_8)) {
var json = JsonParser.parseReader(reader).getAsJsonObject();
for (var element : json.getAsJsonArray("providers")) {
var conditional = GlyphProviderDefinition.Conditional.CODEC.parse(JsonOps.INSTANCE, element).getOrThrow();
if (!conditional.filter().apply(Set.of())) continue;
var definition = conditional.definition().unpack();
if (definition.left().isPresent()) {
providers.add(definition.left().orElseThrow().load(resources));
} else {
loadProviders(resources, definition.right().orElseThrow().id(), providers, visiting);
}
}
} finally {
visiting.remove(font);
}
}
private static Font create(List<GlyphProvider> providers) {
GlyphSource source = new GlyphSource() {
@Override
public BakedGlyph getGlyph(int codepoint) {
@@ -370,7 +370,7 @@ public final class VanillaPackScreenOracle {
unsafeField.setAccessible(true);
unsafe = unsafeField.get(null);
allocate = unsafe.getClass().getMethod("allocateInstance", Class.class);
font = ParityFont.create(ParityFont.resources());
font = ParityFont.createDefault(ParityFont.resources(Path.of(args[2])));
Minecraft mc = alloc(Minecraft.class);
put(mc, Minecraft.class, "font", font);
put(mc, Minecraft.class, "lastInputType", InputType.MOUSE);
@@ -230,7 +230,7 @@ public final class VanillaTabListOracle {
unsafeField.setAccessible(true);
unsafe = unsafeField.get(null);
allocate = unsafe.getClass().getMethod("allocateInstance", Class.class);
Font font = ParityFont.create(ParityFont.resources());
Font font = ParityFont.createDefault(ParityFont.resources(Path.of(args[2])));
var gson = new Gson();
var out = new StringBuilder();
for (String line : Files.readAllLines(Path.of(args[0]))) {
@@ -284,6 +284,8 @@ public final class VanillaTabListOracle {
put(mc, Minecraft.class, "user", user);
var skins = skinManager(c);
put(mc, Minecraft.class, "skinManager", skins);
var profiles = new ArrayList<GameProfile>();
var lookups = new ArrayList<CompletableFuture<?>>();
for (var p : c.getAsJsonArray("players")) {
var o = p.getAsJsonObject();
var uuid = UUID.fromString(o.get("uuid").getAsString());
@@ -296,12 +298,22 @@ public final class VanillaTabListOracle {
: new Property("textures", t.get("value").getAsString(), sig.getAsString()));
}
var profile = new GameProfile(uuid, o.get("name").getAsString(), new PropertyMap(properties));
// Let the lookup's unpacking and downloads run before the first frame,
// as they would have by the time a player list shows.
try {
skins.get(profile).get(1, java.util.concurrent.TimeUnit.SECONDS);
} catch (java.util.concurrent.TimeoutException pending) {
}
profiles.add(profile);
lookups.add(skins.get(profile));
}
// Start every lookup before waiting: intentionally pending fake
// downloads must not add a second for each player in the list.
// Keep the same observation window and leave those futures pending.
try {
CompletableFuture.allOf(lookups.toArray(CompletableFuture[]::new))
.get(1, java.util.concurrent.TimeUnit.SECONDS);
} catch (java.util.concurrent.TimeoutException pending) {
}
int profileIndex = 0;
for (var p : c.getAsJsonArray("players")) {
var o = p.getAsJsonObject();
var profile = profiles.get(profileIndex++);
var uuid = profile.id();
var info = new PlayerInfo(profile, false);
put(info, PlayerInfo.class, "gameMode", GameType.byId(o.get("gameMode").getAsInt()));
put(info, PlayerInfo.class, "latency", o.get("latency").getAsInt());