Skip to content

Commit

Permalink
add optional output quantity to recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 24, 2019
1 parent a5decb8 commit 63fc7b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Expand Up @@ -82,7 +82,9 @@ public class ItemScriptContainer extends ScriptContainer {
// # You can optional add a group as well. If unspecified, the item will have no group.
// # Groups are used to merge together similar recipes (in particular, multiple recipes for one item).
// group: my_custom_group
// # You need to specify the input for the recipe. The below is a sample of a 3x3 shaped recipe. Other recipe types have a different format.
// # You can optionally specify the quantity to output. The default is 1 (or whatever the item script's quantity is).
// output_quantity: 4
// # You must specify the input for the recipe. The below is a sample of a 3x3 shaped recipe. Other recipe types have a different format.
// # You are allowed to have non-3x3 shapes (can be any value 1-3 x 1-3, so for example 1x3, 2x1, and 2x2 are fine).
// # For an empty slot, use "air".
// input:
Expand Down
Expand Up @@ -71,7 +71,7 @@ public String getIdFor(ItemScriptContainer container, String type, int id) {
return newId;
}

public void registerShapedRecipe(ItemScriptContainer container, List<String> recipeList, String internalId, String group) {
public void registerShapedRecipe(ItemScriptContainer container, ItemStack item, List<String> recipeList, String internalId, String group) {
for (int n = 0; n < recipeList.size(); n++) {
recipeList.set(n, TagManager.tag(ScriptBuilder.stripLinePrefix(recipeList.get(n)), new BukkitTagContext(container.player, container.npc, new ScriptTag(container))));
}
Expand All @@ -98,7 +98,7 @@ public void registerShapedRecipe(ItemScriptContainer container, List<String> rec
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
NamespacedKey key = new NamespacedKey("denizen", internalId);
ShapedRecipe recipe = new ShapedRecipe(key, container.getCleanReference().getItemStack());
ShapedRecipe recipe = new ShapedRecipe(key, item);
recipe.setGroup(group);
String shape1 = "ABC".substring(0, width);
String shape2 = "DEF".substring(0, width);
Expand All @@ -123,7 +123,7 @@ else if (recipeList.size() == 2) {
}
}

public void registerShapelessRecipe(ItemScriptContainer container, String shapelessString, String internalId, String group) {
public void registerShapelessRecipe(ItemScriptContainer container, ItemStack item, String shapelessString, String internalId, String group) {
String list = TagManager.tag(shapelessString, new BukkitTagContext(container.player, container.npc, new ScriptTag(container)));
List<ItemTag> ingredients = new ArrayList<>();
for (String element : ListTag.valueOf(list)) {
Expand All @@ -136,37 +136,35 @@ public void registerShapelessRecipe(ItemScriptContainer container, String shapel
ingredients.add(ingredient);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack[] input = new ItemStack[ingredients.size()];
for (int i = 0; i < input.length; i++) {
input[i] = ingredients.get(i).getItemStack().clone();
}
NMSHandler.getItemHelper().registerShapelessRecipe(internalId, group, result, input);
NMSHandler.getItemHelper().registerShapelessRecipe(internalId, group, item, input);
}
else {
shapelessRecipesMap.put(container, ingredients);
}
}

public void registerFurnaceRecipe(ItemScriptContainer container, String furnaceItemString, float exp, int time, String type, String internalId, String group) {
public void registerFurnaceRecipe(ItemScriptContainer container, ItemStack item, String furnaceItemString, float exp, int time, String type, String internalId, String group) {
ItemTag furnace_item = ItemTag.valueOf(furnaceItemString, container);
if (furnace_item == null) {
Debug.echoError("Invalid item '" + furnaceItemString + "', furnace recipe will not be registered for item script '" + container.getName() + "'.");
return;
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
NMSHandler.getItemHelper().registerFurnaceRecipe(internalId, group, result, input, exp, time, type);
NMSHandler.getItemHelper().registerFurnaceRecipe(internalId, group, item, input, exp, time, type);
}
else {
FurnaceRecipe recipe = new FurnaceRecipe(container.getCleanReference().getItemStack(), furnace_item.getMaterial().getMaterial(), furnace_item.getItemStack().getDurability());
FurnaceRecipe recipe = new FurnaceRecipe(item, furnace_item.getMaterial().getMaterial(), furnace_item.getItemStack().getDurability());
Bukkit.addRecipe(recipe);
currentFurnaceRecipes.put(container, furnace_item);
}
}

public void registerStonecuttingRecipe(ItemScriptContainer container, String inputItemString, String internalId, String group) {
public void registerStonecuttingRecipe(ItemScriptContainer container, ItemStack item, String inputItemString, String internalId, String group) {
if (!NMSHandler.getVersion().isAtLeast(NMSVersion.v1_14)) {

}
Expand All @@ -175,9 +173,8 @@ public void registerStonecuttingRecipe(ItemScriptContainer container, String inp
Debug.echoError("Invalid item '" + inputItemString + "', stonecutting recipe will not be registered for item script '" + container.getName() + "'.");
return;
}
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
NMSHandler.getItemHelper().registerStonecuttingRecipe(internalId, group, result, input);
NMSHandler.getItemHelper().registerStonecuttingRecipe(internalId, group, item, input);
}

public void rebuildRecipes() {
Expand All @@ -192,37 +189,44 @@ public void rebuildRecipes() {
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, subSection.getStringList("input"), internalId, group);
registerShapedRecipe(container, item, subSection.getStringList("input"), internalId, group);
}
else if (type.equals("shapeless")) {
registerShapelessRecipe(container, subSection.getString("input"), internalId, group);
registerShapelessRecipe(container, item, subSection.getString("input"), internalId, group);
}
else if (type.equals("stonecutting")) {
registerStonecuttingRecipe(container, subSection.getString("input"), internalId, group);
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.valueOf(subSection.getString("experience"));
exp = Float.parseFloat(subSection.getString("experience"));
}
if (subSection.contains("cook_time")) {
cookTime = DurationTag.valueOf(subSection.getString("cook_time")).getTicksAsInt();
}
registerFurnaceRecipe(container, 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")) {
registerShapedRecipe(container, container.getStringList("RECIPE"), getIdFor(container, "old_recipe", 0), "custom");
// Deprecations.oldRecipeScript.warn();
registerShapedRecipe(container, container.getCleanReference().getItemStack().clone(), container.getStringList("RECIPE"), getIdFor(container, "old_recipe", 0), "custom");
}
if (container.contains("SHAPELESS_RECIPE")) {
registerShapelessRecipe(container, container.getString("SHAPELESS_RECIPE"), getIdFor(container, "old_shapeless", 0), "custom");
// Deprecations.oldRecipeScript.warn();
registerShapelessRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("SHAPELESS_RECIPE"), getIdFor(container, "old_shapeless", 0), "custom");
}
if (container.contains("FURNACE_RECIPE")) {
registerFurnaceRecipe(container, container.getString("FURNACE_RECIPE"), 0, 40, "furnace", getIdFor(container, "old_furnace", 0), "custom");
// Deprecations.oldRecipeScript.warn();
registerFurnaceRecipe(container, container.getCleanReference().getItemStack().clone(), container.getString("FURNACE_RECIPE"), 0, 40, "furnace", getIdFor(container, "old_furnace", 0), "custom");
}
}
}
Expand Down

0 comments on commit 63fc7b7

Please sign in to comment.