Skip to content

Commit

Permalink
better item script recipe load error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 10, 2019
1 parent 979588b commit d5bbe35
Showing 1 changed file with 48 additions and 42 deletions.
Expand Up @@ -212,53 +212,59 @@ public void registerStonecuttingRecipe(ItemScriptContainer container, ItemStack
public void rebuildRecipes() {
currentFurnaceRecipes.clear();
for (ItemScriptContainer container : item_scripts.values()) {
if (container.contains("recipes")) {
YamlConfiguration section = container.getConfigurationSection("recipes");
int id = 0;
for (StringHolder key : section.getKeys(false)) {
id++;
YamlConfiguration subSection = section.getConfigurationSection(key.str);
String type = CoreUtilities.toLowerCase(subSection.getString("type"));
String internalId = subSection.contains("recipe_id") ? subSection.getString("recipe_id") : getIdFor(container, type + "_recipe", id);
String group = subSection.contains("group") ? subSection.getString("group") : "";
ItemStack item = container.getCleanReference().getItemStack().clone();
if (subSection.contains("output_quantity")) {
item.setAmount(Integer.parseInt(subSection.getString("output_quantity")));
}
if (type.equals("shaped")) {
registerShapedRecipe(container, item, subSection.getStringList("input"), internalId, group);
}
else if (type.equals("shapeless")) {
registerShapelessRecipe(container, item, subSection.getString("input"), internalId, group);
}
else if (type.equals("stonecutting")) {
registerStonecuttingRecipe(container, item, subSection.getString("input"), internalId, group);
}
else if (type.equals("furnace") || type.equals("blast") || type.equals("smoker") || type.equals("campfire")) {
float exp = 0;
int cookTime = 40;
if (subSection.contains("experience")) {
exp = Float.parseFloat(subSection.getString("experience"));
try {
if (container.contains("recipes")) {
YamlConfiguration section = container.getConfigurationSection("recipes");
int id = 0;
for (StringHolder key : section.getKeys(false)) {
id++;
YamlConfiguration subSection = section.getConfigurationSection(key.str);
String type = CoreUtilities.toLowerCase(subSection.getString("type"));
String internalId = subSection.contains("recipe_id") ? subSection.getString("recipe_id") : getIdFor(container, type + "_recipe", id);
String group = subSection.contains("group") ? subSection.getString("group") : "";
ItemStack item = container.getCleanReference().getItemStack().clone();
if (subSection.contains("output_quantity")) {
item.setAmount(Integer.parseInt(subSection.getString("output_quantity")));
}
if (type.equals("shaped")) {
registerShapedRecipe(container, item, subSection.getStringList("input"), internalId, group);
}
else if (type.equals("shapeless")) {
registerShapelessRecipe(container, item, subSection.getString("input"), internalId, group);
}
else if (type.equals("stonecutting")) {
registerStonecuttingRecipe(container, item, subSection.getString("input"), internalId, group);
}
if (subSection.contains("cook_time")) {
cookTime = DurationTag.valueOf(subSection.getString("cook_time")).getTicksAsInt();
else if (type.equals("furnace") || type.equals("blast") || type.equals("smoker") || type.equals("campfire")) {
float exp = 0;
int cookTime = 40;
if (subSection.contains("experience")) {
exp = Float.parseFloat(subSection.getString("experience"));
}
if (subSection.contains("cook_time")) {
cookTime = DurationTag.valueOf(subSection.getString("cook_time")).getTicksAsInt();
}
registerFurnaceRecipe(container, item, subSection.getString("input"), exp, cookTime, type, internalId, group);
}
registerFurnaceRecipe(container, item, subSection.getString("input"), exp, cookTime, type, internalId, group);
}
}
// Old script style
if (container.contains("RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerShapedRecipe(container, container.getCleanReference().getItemStack().clone(), container.getStringList("RECIPE"), getIdFor(container, "old_recipe", 0), "custom");
}
if (container.contains("SHAPELESS_RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerShapelessRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("SHAPELESS_RECIPE"), getIdFor(container, "old_shapeless", 0), "custom");
}
if (container.contains("FURNACE_RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerFurnaceRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("FURNACE_RECIPE"), 0, 40, "furnace", getIdFor(container, "old_furnace", 0), "custom");
}
}
// Old script style
if (container.contains("RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerShapedRecipe(container, container.getCleanReference().getItemStack().clone(), container.getStringList("RECIPE"), getIdFor(container, "old_recipe", 0), "custom");
}
if (container.contains("SHAPELESS_RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerShapelessRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("SHAPELESS_RECIPE"), getIdFor(container, "old_shapeless", 0), "custom");
}
if (container.contains("FURNACE_RECIPE")) {
Deprecations.oldRecipeScript.warn(container);
registerFurnaceRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("FURNACE_RECIPE"), 0, 40, "furnace", getIdFor(container, "old_furnace", 0), "custom");
catch (Exception ex) {
Debug.echoError("Error while rebuilding item script recipes for '" + container.getName() + "'...");
Debug.echoError(ex);
}
}
}
Expand Down

0 comments on commit d5bbe35

Please sign in to comment.