Skip to content

Commit

Permalink
fix(serializer-minecraft): do not write 'textures' section if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Dec 15, 2023
1 parent ddfd4d0 commit 1c7c306
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void serializeToJson(Model model, JsonWriter writer) throws IOException {
writer.name("ambientocclusion").value(ambientOcclusion);
}

writer.name("textures");
writeTextures(writer, model.textures());

Model.GuiLight guiLight = model.guiLight();
Expand Down Expand Up @@ -449,18 +448,26 @@ private static ItemTransform readItemTransform(JsonElement node) {
}

private static void writeTextures(JsonWriter writer, ModelTextures texture) throws IOException {
final ModelTexture particle = texture.particle();
final List<ModelTexture> layers = texture.layers();
final Map<String, ModelTexture> variables = texture.variables();

if (particle == null && layers.isEmpty() && variables.isEmpty()) {
// do not write if completely empty
return;
}

writer.name("textures");
writer.beginObject();
ModelTexture particle = texture.particle();
if (particle != null) {
writer.name("particle");
writeModelTexture(writer, particle);
}
List<ModelTexture> layers = texture.layers();
for (int i = 0; i < layers.size(); i++) {
writer.name("layer" + i);
writeModelTexture(writer, layers.get(i));
}
for (Map.Entry<String, ModelTexture> variable : texture.variables().entrySet()) {
for (Map.Entry<String, ModelTexture> variable : variables.entrySet()) {
writer.name(variable.getKey());
writeModelTexture(writer, variable.getValue());
}
Expand Down

0 comments on commit 1c7c306

Please sign in to comment.