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];
}
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);
}
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;
}
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);
}
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];
}
Aggregations