Search in sources :

Example 1 with InputStreamReader

use of org.jline.utils.InputStreamReader 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;
}
Also used : InputStreamReader(org.jline.utils.InputStreamReader) ArrayList(java.util.ArrayList) Resource(net.minecraft.server.packs.resources.Resource) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms) Perspective(net.minecraftforge.client.model.generators.ModelBuilder.Perspective) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) Map(java.util.Map)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ItemTransforms (net.minecraft.client.renderer.block.model.ItemTransforms)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Resource (net.minecraft.server.packs.resources.Resource)1 Perspective (net.minecraftforge.client.model.generators.ModelBuilder.Perspective)1 InputStreamReader (org.jline.utils.InputStreamReader)1