Search in sources :

Example 1 with GeometryModelData

use of gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData in project pollen by MoonflowerTeam.

the class Geometry180Parser method parseModel.

public static GeometryModelData[] parseModel(JsonElement json) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    GeometryModelData data = null;
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        if (!entry.getKey().startsWith("geometry."))
            continue;
        if (data != null)
            throw new JsonSyntaxException("1.8.0 does not allow multiple geometry definitions per file.");
        JsonObject object = GsonHelper.convertToJsonObject(entry.getValue(), entry.getKey());
        // Description
        GeometryModelData.Description description = parseDescription(entry.getKey().substring(9), object);
        // Bones
        GeometryModelData.Bone[] bones;
        if (object.has("bones")) {
            Set<String> usedNames = new HashSet<>();
            JsonArray bonesJson = GsonHelper.getAsJsonArray(object, "bones");
            bones = new GeometryModelData.Bone[bonesJson.size()];
            for (int j = 0; j < bones.length; j++) {
                bones[j] = parseBone(GsonHelper.convertToJsonObject(bonesJson.get(j), "bones[" + j + "]"));
                if (!usedNames.add(bones[j].getName()))
                    throw new JsonSyntaxException("Duplicate bone: " + bones[j].getName());
            }
        } else {
            bones = new GeometryModelData.Bone[0];
        }
        data = new GeometryModelData(description, bones);
    }
    return data != null ? new GeometryModelData[] { data } : new GeometryModelData[0];
}
Also used : GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with GeometryModelData

use of gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData in project pollen by MoonflowerTeam.

the class LocalGeometryModelLoader method reload.

@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
    return CompletableFuture.supplyAsync(() -> {
        Map<ResourceLocation, GeometryModel> modelLocations = new HashMap<>();
        for (ResourceLocation modelLocation : resourceManager.listResources(FOLDER, name -> name.endsWith(".json"))) {
            try (Resource resource = resourceManager.getResource(modelLocation)) {
                GeometryModelData[] models = GeometryModelParser.parseModel(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
                for (GeometryModelData model : models) {
                    ResourceLocation id = new ResourceLocation(modelLocation.getNamespace(), model.getDescription().getIdentifier());
                    if (modelLocations.put(id, model.create()) != null)
                        LOGGER.warn("Duplicate geometry model with id '" + id + "'");
                }
            } catch (Exception e) {
                LOGGER.error("Failed to load geometry file '" + modelLocation.getNamespace() + ":" + modelLocation.getPath().substring(FOLDER.length(), modelLocation.getPath().length() - 5) + "'", e);
            }
        }
        LOGGER.info("Loaded " + modelLocations.size() + " geometry models.");
        return modelLocations;
    }, backgroundExecutor);
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData)

Example 3 with GeometryModelData

use of gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData in project pollen by MoonflowerTeam.

the class Geometry1120Parser method parseModel.

public static GeometryModelData[] parseModel(JsonElement json) throws JsonParseException {
    JsonArray jsonArray = GsonHelper.getAsJsonArray(json.getAsJsonObject(), "minecraft:geometry");
    GeometryModelData[] data = new GeometryModelData[jsonArray.size()];
    for (int i = 0; i < data.length; i++) {
        JsonObject object = GsonHelper.convertToJsonObject(jsonArray.get(i), "minecraft:geometry[" + i + "]");
        // Description
        GeometryModelData.Description description = parseDescription(GsonHelper.getAsJsonObject(object, "description"));
        // Bones
        GeometryModelData.Bone[] bones;
        if (object.has("bones")) {
            Set<String> usedNames = new HashSet<>();
            JsonArray bonesJson = GsonHelper.getAsJsonArray(object, "bones");
            bones = new GeometryModelData.Bone[bonesJson.size()];
            for (int j = 0; j < bones.length; j++) {
                bones[j] = parseBone(GsonHelper.convertToJsonObject(bonesJson.get(j), "bones[" + j + "]"));
                if (!usedNames.add(bones[j].getName()))
                    throw new JsonSyntaxException("Duplicate bone: " + bones[j].getName());
            }
        } else {
            bones = new GeometryModelData.Bone[0];
        }
        data[i] = new GeometryModelData(description, bones);
    }
    return data;
}
Also used : GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) HashSet(java.util.HashSet)

Example 4 with GeometryModelData

use of gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData in project pollen by MoonflowerTeam.

the class DeprecatedLocalGeometryModelLoader method reload.

@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
    return CompletableFuture.supplyAsync(() -> {
        Set<ResourceLocation> deprecatedFiles = new HashSet<>();
        Map<ResourceLocation, GeometryModel> modelLocations = new HashMap<>();
        for (ResourceLocation modelLocation : resourceManager.listResources(FOLDER, name -> name.endsWith(".json"))) {
            try (Resource resource = resourceManager.getResource(modelLocation)) {
                GeometryModelData[] models = GeometryModelParser.parseModel(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
                for (GeometryModelData model : models) {
                    ResourceLocation id = new ResourceLocation(modelLocation.getNamespace(), model.getDescription().getIdentifier());
                    if (modelLocations.put(id, model.create()) != null)
                        LOGGER.warn("Duplicate geometry model with id '" + id + "'");
                }
                deprecatedFiles.add(modelLocation);
            } catch (Exception ignored) {
            }
        }
        deprecatedFiles.stream().map(ResourceLocation::getNamespace).forEach(namespace -> LOGGER.error("Mod: " + namespace + " is using deprecated Pollen models. Geometry models should be relocated to 'assets/" + namespace + "/" + LocalGeometryModelLoader.FOLDER.substring(0, LocalGeometryModelLoader.FOLDER.length() - 1) + "'"));
        LOGGER.info("Loaded " + modelLocations.size() + " geometry models.");
        return modelLocations;
    }, backgroundExecutor);
}
Also used : GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) HashSet(java.util.HashSet)

Example 5 with GeometryModelData

use of gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData in project pollen by MoonflowerTeam.

the class Geometry110Parser method parseModel.

public static GeometryModelData[] parseModel(JsonElement json) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    GeometryModelData data = null;
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        if (!entry.getKey().startsWith("geometry."))
            continue;
        if (data != null)
            throw new JsonSyntaxException("1.8.0 does not allow multiple geometry definitions per file.");
        JsonObject object = GsonHelper.convertToJsonObject(entry.getValue(), entry.getKey());
        // Description
        GeometryModelData.Description description = parseDescription(entry.getKey().substring(9), object);
        // Bones
        GeometryModelData.Bone[] bones;
        if (object.has("bones")) {
            Set<String> usedNames = new HashSet<>();
            JsonArray bonesJson = GsonHelper.getAsJsonArray(object, "bones");
            bones = new GeometryModelData.Bone[bonesJson.size()];
            for (int j = 0; j < bones.length; j++) {
                bones[j] = parseBone(GsonHelper.convertToJsonObject(bonesJson.get(j), "bones[" + j + "]"));
                if (!usedNames.add(bones[j].getName()))
                    throw new JsonSyntaxException("Duplicate bone: " + bones[j].getName());
            }
        } else {
            bones = new GeometryModelData.Bone[0];
        }
        data = new GeometryModelData(description, bones);
    }
    return data != null ? new GeometryModelData[] { data } : new GeometryModelData[0];
}
Also used : GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

GeometryModelData (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData)6 HashSet (java.util.HashSet)4 GeometryModel (gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel)3 Map (java.util.Map)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 HashMap (java.util.HashMap)2 Resource (net.minecraft.server.packs.resources.Resource)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Platform (gg.moonflower.pollen.api.platform.Platform)1 Pollen (gg.moonflower.pollen.core.Pollen)1 EntitlementManager (gg.moonflower.pollen.core.client.entitlement.EntitlementManager)1 ModelEntitlement (gg.moonflower.pollen.core.client.entitlement.ModelEntitlement)1 FileCache (gg.moonflower.pollen.pinwheel.api.client.FileCache)1 GeometryModelParser (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser)1 BackgroundLoader (gg.moonflower.pollen.pinwheel.api.common.util.BackgroundLoader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Arrays (java.util.Arrays)1 java.util.concurrent (java.util.concurrent)1