Skip to content

Commit

Permalink
Catch json parsing errors from constants/factories files (MinecraftFo…
Browse files Browse the repository at this point in the history
  • Loading branch information
bs2609 authored and tterrag1098 committed Apr 11, 2019
1 parent 208ed99 commit 24f7be2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static ItemStack getItemStack(JsonObject json, JsonContext context)
if(element.isJsonObject())
nbt = JsonToNBT.getTagFromJson(GSON.toJson(element));
else
nbt = JsonToNBT.getTagFromJson(element.getAsString());
nbt = JsonToNBT.getTagFromJson(JsonUtils.getString(element, "nbt"));

NBTTagCompound tmp = new NBTTagCompound();
if (nbt.hasKey("ForgeCaps"))
Expand Down Expand Up @@ -368,6 +368,11 @@ public static ShapedPrimer parseShaped(Object... recipe)
return ret;
}

public static boolean processConditions(JsonObject json, String memberName, JsonContext context)
{
return !json.has(memberName) || processConditions(JsonUtils.getJsonArray(json, memberName), context);
}

public static boolean processConditions(JsonArray conditions, JsonContext context)
{
for (int x = 0; x < conditions.size(); x++)
Expand Down Expand Up @@ -654,9 +659,9 @@ else if (mod.getSource().isDirectory())
}
}
}
catch (IOException e)
catch (JsonParseException | IOException e)
{
e.printStackTrace();
FMLLog.log.error("Error loading _factories.json: ", e);
}
finally
{
Expand All @@ -679,7 +684,7 @@ private static boolean loadRecipes(ModContainer mod)
JsonObject[] json = JsonUtils.fromJson(GSON, reader, JsonObject[].class);
ctx.loadConstants(json);
}
catch (IOException e)
catch (JsonParseException | IOException e)
{
FMLLog.log.error("Error loading _constants.json: ", e);
return false;
Expand All @@ -701,7 +706,7 @@ private static boolean loadRecipes(ModContainer mod)
try(BufferedReader reader = Files.newBufferedReader(file))
{
JsonObject json = JsonUtils.fromJson(GSON, reader, JsonObject.class);
if (json.has("conditions") && !CraftingHelper.processConditions(JsonUtils.getJsonArray(json, "conditions"), ctx))
if (!processConditions(json, "conditions", ctx))
return true;
IRecipe recipe = CraftingHelper.getRecipe(json, ctx);
ForgeRegistries.RECIPES.register(recipe.setRegistryName(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void loadConstants(JsonObject... jsons)
{
for (JsonObject json : jsons)
{
if (json.has("conditions") && !CraftingHelper.processConditions(json.getAsJsonArray("conditions"), this))
if (!CraftingHelper.processConditions(json, "conditions", this))
continue;
if (!json.has("ingredient"))
throw new JsonSyntaxException("Constant entry must contain 'ingredient' value");
Expand Down

0 comments on commit 24f7be2

Please sign in to comment.