Extract entity animation codes

This commit is contained in:
Ryan 2022-07-26 23:50:19 -07:00
parent 37f5789202
commit f97c67d42a

View file

@ -4,9 +4,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import dev._00a.valence_extractor.Main; import dev._00a.valence_extractor.Main;
import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.network.packet.s2c.play.EntityAnimationS2CPacket;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import java.lang.reflect.Modifier;
import java.util.Locale; import java.util.Locale;
public class EntityData implements Main.Extractor { public class EntityData implements Main.Extractor {
@ -20,7 +23,7 @@ public class EntityData implements Main.Extractor {
var dataJson = new JsonObject(); var dataJson = new JsonObject();
var statusesJson = new JsonObject(); var statusesJson = new JsonObject();
for (var field : net.minecraft.entity.EntityStatuses.class.getDeclaredFields()) { for (var field : EntityStatuses.class.getDeclaredFields()) {
if (field.canAccess(null) && field.get(null) instanceof Byte code) { if (field.canAccess(null) && field.get(null) instanceof Byte code) {
if (field.getName().equals("field_30030")) { if (field.getName().equals("field_30030")) {
statusesJson.addProperty("stop_attack", code); statusesJson.addProperty("stop_attack", code);
@ -31,6 +34,15 @@ public class EntityData implements Main.Extractor {
} }
dataJson.add("statuses", statusesJson); dataJson.add("statuses", statusesJson);
var animationsJson = new JsonObject();
for (var field : EntityAnimationS2CPacket.class.getDeclaredFields()) {
field.setAccessible(true);
if (Modifier.isStatic(field.getModifiers()) && field.canAccess(null) && field.get(null) instanceof Integer i) {
animationsJson.addProperty(field.getName().toLowerCase(Locale.ROOT), i);
}
}
dataJson.add("animations", animationsJson);
var villagerTypesJson = new JsonObject(); var villagerTypesJson = new JsonObject();
for (var type : Registry.VILLAGER_TYPE) { for (var type : Registry.VILLAGER_TYPE) {
villagerTypesJson.addProperty(Registry.VILLAGER_TYPE.getId(type).getPath(), Registry.VILLAGER_TYPE.getRawId(type)); villagerTypesJson.addProperty(Registry.VILLAGER_TYPE.getId(type).getPath(), Registry.VILLAGER_TYPE.getRawId(type));