mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Sort entity extractor output for better diffing
This commit is contained in:
parent
55cb595740
commit
02fe0bae3b
|
@ -0,0 +1,21 @@
|
||||||
|
package dev._00a.valence_extractor;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare Class objects by their simple names lexicographically.
|
||||||
|
*/
|
||||||
|
public class ClassComparator implements Comparator<Class<?>> {
|
||||||
|
public ClassComparator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Class<?> c1, Class<?> c2) {
|
||||||
|
return c1.getSimpleName().compareTo(c2.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object comp) {
|
||||||
|
return comp instanceof ClassComparator;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package dev._00a.valence_extractor.extractors;
|
package dev._00a.valence_extractor.extractors;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import dev._00a.valence_extractor.ClassComparator;
|
||||||
import dev._00a.valence_extractor.DummyPlayerEntity;
|
import dev._00a.valence_extractor.DummyPlayerEntity;
|
||||||
import dev._00a.valence_extractor.DummyWorld;
|
import dev._00a.valence_extractor.DummyWorld;
|
||||||
import dev._00a.valence_extractor.Main;
|
import dev._00a.valence_extractor.Main;
|
||||||
|
@ -272,7 +273,7 @@ public class Entities implements Main.Extractor {
|
||||||
final var dataTrackerField = Entity.class.getDeclaredField("dataTracker");
|
final var dataTrackerField = Entity.class.getDeclaredField("dataTracker");
|
||||||
dataTrackerField.setAccessible(true);
|
dataTrackerField.setAccessible(true);
|
||||||
|
|
||||||
var entitiesJson = new JsonObject();
|
var entitiesMap = new TreeMap<Class<? extends Entity>, JsonElement>(new ClassComparator());
|
||||||
|
|
||||||
for (var entry : entityClassToType.entrySet()) {
|
for (var entry : entityClassToType.entrySet()) {
|
||||||
var entityClass = entry.getKey();
|
var entityClass = entry.getKey();
|
||||||
|
@ -285,7 +286,7 @@ public class Entities implements Main.Extractor {
|
||||||
final var entityInstance = entityType.equals(EntityType.PLAYER) ? DummyPlayerEntity.INSTANCE : entityType.create(DummyWorld.INSTANCE);
|
final var entityInstance = entityType.equals(EntityType.PLAYER) ? DummyPlayerEntity.INSTANCE : entityType.create(DummyWorld.INSTANCE);
|
||||||
final var dataTracker = (DataTracker) dataTrackerField.get(entityInstance);
|
final var dataTracker = (DataTracker) dataTrackerField.get(entityInstance);
|
||||||
|
|
||||||
while (entitiesJson.get(entityClass.getSimpleName()) == null) {
|
while (entitiesMap.get(entityClass) == null) {
|
||||||
var entityJson = new JsonObject();
|
var entityJson = new JsonObject();
|
||||||
|
|
||||||
var parent = entityClass.getSuperclass();
|
var parent = entityClass.getSuperclass();
|
||||||
|
@ -331,7 +332,7 @@ public class Entities implements Main.Extractor {
|
||||||
}
|
}
|
||||||
entityJson.add("fields", fieldsJson);
|
entityJson.add("fields", fieldsJson);
|
||||||
|
|
||||||
entitiesJson.add(entityClass.getSimpleName(), entityJson);
|
entitiesMap.put(entityClass, entityJson);
|
||||||
|
|
||||||
if (!hasParent) {
|
if (!hasParent) {
|
||||||
break;
|
break;
|
||||||
|
@ -342,6 +343,11 @@ public class Entities implements Main.Extractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var entitiesJson = new JsonObject();
|
||||||
|
for (var entry : entitiesMap.entrySet()) {
|
||||||
|
entitiesJson.add(entry.getKey().getSimpleName(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
return entitiesJson;
|
return entitiesJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue