Skip to content

Commit

Permalink
Use json directly instead of a formatted string to ensure formatting …
Browse files Browse the repository at this point in the history
…is correct
  • Loading branch information
Bawnorton committed Jun 26, 2023
1 parent 488fe40 commit c5c04e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.8
loader_version=0.14.21

# Mod Properties
mod_version=2.1.0
mod_version=2.1.2
maven_group=com.bawnorton.allthetrims
archives_base_name=allthetrims

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.bawnorton.allthetrims.mixin;

import com.bawnorton.allthetrims.AllTheTrims;
import com.bawnorton.allthetrims.json.JsonHelper;
import com.bawnorton.allthetrims.util.DebugHelper;
import com.bawnorton.allthetrims.util.TrimMaterialHelper;
import com.google.gson.JsonObject;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryLoader;
import net.minecraft.resource.Resource;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.apache.commons.io.IOUtils;
import org.spongepowered.asm.mixin.Debug;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

Expand All @@ -29,28 +31,26 @@ private static Map<Identifier, Resource> addAllTrimMaterialJsonFiles(Map<Identif

TrimMaterialHelper.loopTrimMaterials((item) -> {
Identifier itemId = Registries.ITEM.getId(item);
String resourceString =
"""
{
"asset_name": "att-blank",
"description": {
"color": "%s",
"translate": "%s %s"
},
"ingredient": "%s",
"item_model_index": %f
}
""".formatted(
"#FFFFFF",
escape(item.getName().getString()), escape(Text.translatable("text.allthetrims.material").getString()),
itemId,
0.099f
);
Resource resource = new Resource(first.getValue().getPack(), () -> IOUtils.toInputStream(resourceString, "UTF-8"));

JsonObject resourceJson = new JsonObject();
try {
resourceJson.addProperty("asset_name", "att-blank");
JsonObject description = new JsonObject();
description.addProperty("color", "#FFFFFF");
description.addProperty("translate", escape(item.getName().getString()) + " " + escape(Text.translatable("text.allthetrims.material").getString()));
resourceJson.add("description", description);
resourceJson.addProperty("ingredient", itemId.toString());
resourceJson.addProperty("item_model_index", 0.099);
} catch (RuntimeException e) {
AllTheTrims.LOGGER.error("Failed to generate trim material JSON for " + itemId, e);
return;
}

Resource resource = new Resource(first.getValue().getPack(), () -> IOUtils.toInputStream(resourceJson.toString(), "UTF-8"));
Identifier resourceId = new Identifier(itemId.getNamespace(), "trim_material/" + itemId.getPath() + ".json");
original.put(resourceId, resource);

DebugHelper.createDebugFile("trim_materials", itemId + ".json", resourceString);
DebugHelper.createDebugFile("trim_materials", itemId + ".json", resourceJson.toString());
});
return original;
}
Expand Down

0 comments on commit c5c04e6

Please sign in to comment.