Search in sources :

Example 1 with ItemCameraTransforms

use of net.minecraft.client.renderer.model.ItemCameraTransforms in project tetra by mickelus.

the class ModularModelLoader method read.

@Override
public ModularItemModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
    ItemCameraTransforms cameraTransforms = deserializationContext.deserialize(modelContents.get("display"), ItemCameraTransforms.class);
    if (modelContents.has("variants")) {
        Map<String, ItemCameraTransforms> transformVariants = deserializationContext.deserialize(modelContents.get("variants"), new TypeToken<Map<String, ItemCameraTransforms>>() {
        }.getType());
        ModularItemModel model = new ModularItemModel(cameraTransforms, transformVariants);
        models.add(model);
        return model;
    }
    ModularItemModel model = new ModularItemModel(cameraTransforms);
    models.add(model);
    return model;
}
Also used : TypeToken(com.google.common.reflect.TypeToken) ItemCameraTransforms(net.minecraft.client.renderer.model.ItemCameraTransforms)

Example 2 with ItemCameraTransforms

use of net.minecraft.client.renderer.model.ItemCameraTransforms in project Magma-1.16.x by magmafoundation.

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 {
            IResource vanillaResource = existingFileHelper.getResource(new ResourceLocation(loc.getPath()), ResourcePackType.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
                ItemCameraTransforms generatedTransforms = GSON.fromJson(generatedDisplay, ItemCameraTransforms.class);
                ItemCameraTransforms vanillaTransforms = GSON.fromJson(vanillaDisplay, ItemCameraTransforms.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) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ItemCameraTransforms(net.minecraft.client.renderer.model.ItemCameraTransforms) Perspective(net.minecraftforge.client.model.generators.ModelBuilder.Perspective) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) Map(java.util.Map) IResource(net.minecraft.resources.IResource)

Aggregations

ItemCameraTransforms (net.minecraft.client.renderer.model.ItemCameraTransforms)2 TypeToken (com.google.common.reflect.TypeToken)1 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 IResource (net.minecraft.resources.IResource)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Perspective (net.minecraftforge.client.model.generators.ModelBuilder.Perspective)1 InputStreamReader (org.jline.utils.InputStreamReader)1