mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 22:41:30 +11:00
Extract more data from entities
This commit is contained in:
parent
d95c51b492
commit
37f5789202
|
@ -4,7 +4,7 @@ import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import dev._00a.valence_extractor.extractors.Blocks;
|
import dev._00a.valence_extractor.extractors.Blocks;
|
||||||
import dev._00a.valence_extractor.extractors.Entities;
|
import dev._00a.valence_extractor.extractors.Entities;
|
||||||
import dev._00a.valence_extractor.extractors.EntityStatuses;
|
import dev._00a.valence_extractor.extractors.EntityData;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -39,7 +39,7 @@ public class Main implements ModInitializer {
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
LOGGER.info("Starting extractors...");
|
LOGGER.info("Starting extractors...");
|
||||||
|
|
||||||
var extractors = new Extractor[]{new Blocks(), new Entities(), new EntityStatuses(),};
|
var extractors = new Extractor[]{new Blocks(), new Entities(), new EntityData(),};
|
||||||
|
|
||||||
Path outputDirectory;
|
Path outputDirectory;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import dev._00a.valence_extractor.DummyWorld;
|
||||||
import dev._00a.valence_extractor.Main;
|
import dev._00a.valence_extractor.Main;
|
||||||
import dev._00a.valence_extractor.Main.Pair;
|
import dev._00a.valence_extractor.Main.Pair;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityPose;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.data.DataTracker;
|
import net.minecraft.entity.data.DataTracker;
|
||||||
import net.minecraft.entity.data.TrackedData;
|
import net.minecraft.entity.data.TrackedData;
|
||||||
|
@ -199,19 +200,22 @@ public class Entities implements Main.Extractor {
|
||||||
// TODO: base64 binary representation or SNBT?
|
// TODO: base64 binary representation or SNBT?
|
||||||
return new Pair<>("nbt_compound", new JsonPrimitive(val.toString()));
|
return new Pair<>("nbt_compound", new JsonPrimitive(val.toString()));
|
||||||
} else if (handler == TrackedDataHandlerRegistry.PARTICLE) {
|
} else if (handler == TrackedDataHandlerRegistry.PARTICLE) {
|
||||||
return new Pair<>("particle", new JsonPrimitive(((ParticleEffect) val).asString()));
|
var id = Registry.PARTICLE_TYPE.getId(((ParticleEffect) val).getType());
|
||||||
|
return new Pair<>("particle", new JsonPrimitive(id.getPath()));
|
||||||
} else if (handler == TrackedDataHandlerRegistry.VILLAGER_DATA) {
|
} else if (handler == TrackedDataHandlerRegistry.VILLAGER_DATA) {
|
||||||
var vd = (VillagerData) val;
|
var vd = (VillagerData) val;
|
||||||
var json = new JsonObject();
|
var json = new JsonObject();
|
||||||
json.addProperty("type", vd.getType().toString());
|
var type = Registry.VILLAGER_TYPE.getId(vd.getType()).getPath();
|
||||||
json.addProperty("profession", vd.getProfession().toString());
|
var profession = Registry.VILLAGER_PROFESSION.getId(vd.getProfession()).getPath();
|
||||||
|
json.addProperty("type", type);
|
||||||
|
json.addProperty("profession", profession);
|
||||||
json.addProperty("level", vd.getLevel());
|
json.addProperty("level", vd.getLevel());
|
||||||
return new Pair<>("villager_data", json);
|
return new Pair<>("villager_data", json);
|
||||||
} else if (handler == TrackedDataHandlerRegistry.OPTIONAL_INT) {
|
} else if (handler == TrackedDataHandlerRegistry.OPTIONAL_INT) {
|
||||||
var opt = (OptionalInt) val;
|
var opt = (OptionalInt) val;
|
||||||
return new Pair<>("optional_int", opt.isPresent() ? new JsonPrimitive(opt.getAsInt()) : JsonNull.INSTANCE);
|
return new Pair<>("optional_int", opt.isPresent() ? new JsonPrimitive(opt.getAsInt()) : JsonNull.INSTANCE);
|
||||||
} else if (handler == TrackedDataHandlerRegistry.ENTITY_POSE) {
|
} else if (handler == TrackedDataHandlerRegistry.ENTITY_POSE) {
|
||||||
return new Pair<>("entity_pose", new JsonPrimitive(val.toString()));
|
return new Pair<>("entity_pose", new JsonPrimitive(((EntityPose) val).name().toLowerCase(Locale.ROOT)));
|
||||||
} else if (handler == TrackedDataHandlerRegistry.CAT_VARIANT) {
|
} else if (handler == TrackedDataHandlerRegistry.CAT_VARIANT) {
|
||||||
return new Pair<>("cat_variant", new JsonPrimitive(Registry.CAT_VARIANT.getId((CatVariant) val).getPath()));
|
return new Pair<>("cat_variant", new JsonPrimitive(Registry.CAT_VARIANT.getId((CatVariant) val).getPath()));
|
||||||
} else if (handler == TrackedDataHandlerRegistry.FROG_VARIANT) {
|
} else if (handler == TrackedDataHandlerRegistry.FROG_VARIANT) {
|
||||||
|
@ -322,7 +326,9 @@ public class Entities implements Main.Extractor {
|
||||||
|
|
||||||
entitiesJson.add(entityClass.getSimpleName(), entityJson);
|
entitiesJson.add(entityClass.getSimpleName(), entityJson);
|
||||||
|
|
||||||
if (!hasParent) break;
|
if (!hasParent) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
entityClass = (Class<? extends Entity>) parent;
|
entityClass = (Class<? extends Entity>) parent;
|
||||||
entityType = entityClassToType.get(entityClass);
|
entityType = entityClassToType.get(entityClass);
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
package dev._00a.valence_extractor.extractors;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import dev._00a.valence_extractor.Main;
|
||||||
|
import net.minecraft.entity.EntityPose;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class EntityData implements Main.Extractor {
|
||||||
|
@Override
|
||||||
|
public String fileName() {
|
||||||
|
return "entity_data.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement extract() throws Exception {
|
||||||
|
var dataJson = new JsonObject();
|
||||||
|
|
||||||
|
var statusesJson = new JsonObject();
|
||||||
|
for (var field : net.minecraft.entity.EntityStatuses.class.getDeclaredFields()) {
|
||||||
|
if (field.canAccess(null) && field.get(null) instanceof Byte code) {
|
||||||
|
if (field.getName().equals("field_30030")) {
|
||||||
|
statusesJson.addProperty("stop_attack", code);
|
||||||
|
} else {
|
||||||
|
statusesJson.addProperty(field.getName().toLowerCase(Locale.ROOT), code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataJson.add("statuses", statusesJson);
|
||||||
|
|
||||||
|
var villagerTypesJson = new JsonObject();
|
||||||
|
for (var type : Registry.VILLAGER_TYPE) {
|
||||||
|
villagerTypesJson.addProperty(Registry.VILLAGER_TYPE.getId(type).getPath(), Registry.VILLAGER_TYPE.getRawId(type));
|
||||||
|
}
|
||||||
|
dataJson.add("villager_types", villagerTypesJson);
|
||||||
|
|
||||||
|
var villagerProfessionsJson = new JsonObject();
|
||||||
|
for (var profession : Registry.VILLAGER_PROFESSION) {
|
||||||
|
villagerProfessionsJson.addProperty(profession.id(), Registry.VILLAGER_PROFESSION.getRawId(profession));
|
||||||
|
}
|
||||||
|
dataJson.add("villager_professions", villagerProfessionsJson);
|
||||||
|
|
||||||
|
var catVariantsJson = new JsonObject();
|
||||||
|
for (var variant : Registry.CAT_VARIANT) {
|
||||||
|
catVariantsJson.addProperty(Registry.CAT_VARIANT.getId(variant).getPath(), Registry.CAT_VARIANT.getRawId(variant));
|
||||||
|
}
|
||||||
|
dataJson.add("cat_variants", catVariantsJson);
|
||||||
|
|
||||||
|
var frogVariantsJson = new JsonObject();
|
||||||
|
for (var variant : Registry.FROG_VARIANT) {
|
||||||
|
frogVariantsJson.addProperty(Registry.FROG_VARIANT.getId(variant).getPath(), Registry.FROG_VARIANT.getRawId(variant));
|
||||||
|
}
|
||||||
|
dataJson.add("frog_variants", frogVariantsJson);
|
||||||
|
|
||||||
|
var paintingVariantsJson = new JsonObject();
|
||||||
|
for (var variant : Registry.PAINTING_VARIANT) {
|
||||||
|
var variantJson = new JsonObject();
|
||||||
|
variantJson.addProperty("id", Registry.PAINTING_VARIANT.getRawId(variant));
|
||||||
|
variantJson.addProperty("width", variant.getWidth());
|
||||||
|
variantJson.addProperty("height", variant.getHeight());
|
||||||
|
paintingVariantsJson.add(Registry.PAINTING_VARIANT.getId(variant).getPath(), variantJson);
|
||||||
|
}
|
||||||
|
dataJson.add("painting_variants", paintingVariantsJson);
|
||||||
|
|
||||||
|
var facingJson = new JsonObject();
|
||||||
|
for (var dir : Direction.values()) {
|
||||||
|
facingJson.addProperty(dir.getName(), dir.getId());
|
||||||
|
}
|
||||||
|
dataJson.add("facing", facingJson);
|
||||||
|
|
||||||
|
var posesJson = new JsonObject();
|
||||||
|
var poses = EntityPose.values();
|
||||||
|
for (int i = 0; i < poses.length; i++) {
|
||||||
|
posesJson.addProperty(poses[i].name().toLowerCase(Locale.ROOT), i);
|
||||||
|
}
|
||||||
|
dataJson.add("poses", posesJson);
|
||||||
|
|
||||||
|
var particleTypesJson = new JsonObject();
|
||||||
|
for (var type : Registry.PARTICLE_TYPE) {
|
||||||
|
particleTypesJson.addProperty(Registry.PARTICLE_TYPE.getId(type).getPath(), Registry.PARTICLE_TYPE.getRawId(type));
|
||||||
|
}
|
||||||
|
dataJson.add("particle_types", particleTypesJson);
|
||||||
|
|
||||||
|
return dataJson;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +0,0 @@
|
||||||
package dev._00a.valence_extractor.extractors;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import dev._00a.valence_extractor.Main;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class EntityStatuses implements Main.Extractor {
|
|
||||||
@Override
|
|
||||||
public String fileName() {
|
|
||||||
return "entity_statuses.json";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonElement extract() throws Exception {
|
|
||||||
var statusesJson = new JsonObject();
|
|
||||||
|
|
||||||
for (var field : net.minecraft.entity.EntityStatuses.class.getDeclaredFields()) {
|
|
||||||
if (field.canAccess(null) && field.get(null) instanceof Byte code) {
|
|
||||||
if (field.getName().equals("field_30030")) {
|
|
||||||
// TODO: temp
|
|
||||||
statusesJson.addProperty("stop_attack", code);
|
|
||||||
} else {
|
|
||||||
statusesJson.addProperty(field.getName().toLowerCase(Locale.ROOT), code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return statusesJson;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue