use of net.minecraft.client.renderer.block.model.ItemTransforms in project MinecraftForge by MinecraftForge.
the class DataGeneratorTest method testModelResults.
private static <T extends ModelBuilder<T>> List<String> testModelResults(Map<ResourceLocation, T> models, ExistingFileHelper existingFileHelper, Set<ResourceLocation> toIgnore) {
List<String> ret = new ArrayList<>();
models.forEach((loc, model) -> {
if (toIgnore.contains(loc))
return;
JsonObject generated = model.toJson();
if (generated.has("parent")) {
generated.addProperty("parent", toVanillaModel(generated.get("parent").getAsString()));
}
try {
Resource vanillaResource = existingFileHelper.getResource(new ResourceLocation(loc.getPath()), PackType.CLIENT_RESOURCES, ".json", "models");
JsonObject existing = GSON.fromJson(new InputStreamReader(vanillaResource.getInputStream()), JsonObject.class);
JsonElement generatedDisplay = generated.remove("display");
JsonElement vanillaDisplay = existing.remove("display");
if (generatedDisplay == null && vanillaDisplay != null) {
ret.add("Model " + loc + " is missing transforms");
return;
} else if (generatedDisplay != null && vanillaDisplay == null) {
ret.add("Model " + loc + " has transforms when vanilla equivalent does not");
return;
} else if (generatedDisplay != null) {
// Both must be non-null
ItemTransforms generatedTransforms = GSON.fromJson(generatedDisplay, ItemTransforms.class);
ItemTransforms vanillaTransforms = GSON.fromJson(vanillaDisplay, ItemTransforms.class);
for (Perspective type : Perspective.values()) {
if (!generatedTransforms.getTransform(type.vanillaType).equals(vanillaTransforms.getTransform(type.vanillaType))) {
ret.add("Model " + loc + " has transforms that differ from vanilla equivalent for perspective " + type.name());
return;
}
}
}
JsonElement generatedTextures = generated.remove("textures");
JsonElement vanillaTextures = existing.remove("textures");
if (generatedTextures == null && vanillaTextures != null) {
ret.add("Model " + loc + " is missing textures");
} else if (generatedTextures != null && vanillaTextures == null) {
ret.add("Model " + loc + " has textures when vanilla equivalent does not");
} else if (generatedTextures != null) {
// Both must be non-null
for (Map.Entry<String, JsonElement> e : generatedTextures.getAsJsonObject().entrySet()) {
String vanillaTexture = vanillaTextures.getAsJsonObject().get(e.getKey()).getAsString();
if (!e.getValue().getAsString().equals(vanillaTexture)) {
ret.add("Texture for variable '" + e.getKey() + "' for model " + loc + " does not match vanilla equivalent");
}
}
if (generatedTextures.getAsJsonObject().size() != vanillaTextures.getAsJsonObject().size()) {
ret.add("Model " + loc + " is missing textures from vanilla equivalent");
}
}
if (!existing.equals(generated)) {
ret.add("Model " + loc + " does not match vanilla equivalent");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return ret;
}
Aggregations