Tutorial:Advanced Recipes 164
So far we have learned about how to add or remove simple recipes. But what if the inputs and outputs also involve damage values or NBT tags?
It is possible to define both damage or an NBT tag as output. Let's take a pickaxe as our toy for this tutorial:
val stick = <item.stick>; val pick = <item.pickaxeStone>; val damagedPick = pick.withDamage(10); val stickedPick = pick.withTag({display: {Name: "Sticked pick", Lore: ["This pick", "Has been sticked"]}}); recipes.addShaped(damagedPick, pick, stick); recipes.addShaped(stickedPick, [[pick, stick], [stick, stick]]);
Crafting the pick with 1 or 3 sticks as in the recipe will give you an item with the appropriate damage and name/lore on it, respectively.
You can also require the input to contain certain NBT tags. Say, you make a recipe that requires our sticked pick. Let's modify our file:
// import must always be on top of the file import minetweaker.item.Condition; val stick = <item.stick>; val pick = <item.pickaxeStone>; val damagedPick = pick.withDamage(10); val stickedPick = pick.withTag({display: {Name: "Sticked pick", Lore: ["This pick", "Has been sticked"]}}); recipes.addShaped(damagedPick, pick, stick); recipes.addShaped(stickedPick, [[pick, stick], [stick, stick]]); val stonedPick = pick.withTag({display: {Name: "Stoned pick", Lore: ["This pick", "Has been experimenting too much"]}}); val onlyStickedPick = pick.only(Condition.data({display: {Name: "Sticked pick"}})); val cobble = <tile.stonebrick>; // cobblestone recipes.addShaped(stonedPick, [[onlyStickedPick, cobble], [cobble, cobble]]);
What about the lore part in our sticked pick? Since your condition only contains the name, the lore part is ignored - when setting a condition on the data tag, MineTweaker only cares about the contents that you specified and ignores everything else.
You may also have noticed the new element in this script - an import. The imported class, Condition, contains a set of standard crafting conditions - such as requiring a specific damage or tag, or having a damage value between certain bounds.
More functionality will soon become available in the form of transformers, making it possible to reuse items and have items damaged upon used or to have custom functions define crafting output. However, it's not yet fully implemented