Difference between revisions of "Tutorial:Advanced Recipes"

From MineTweaker 3
Jump to: navigation, search
Line 1: Line 1:
 
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?
 
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?
 +
 +
## NBT Tag in output ##
  
 
It is possible to define both damage or an NBT tag as output. Let's take a pickaxe as our toy for this tutorial:
 
It is possible to define both damage or an NBT tag as output. Let's take a pickaxe as our toy for this tutorial:
Line 12: Line 14:
  
 
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.
 
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.
 +
 +
## Input conditions ##
  
 
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:
 
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 = <minecraft:stick>;
 
  val stick = <minecraft:stick>;
 
  val pick = <minecraft:stone_pickaxe>;
 
  val pick = <minecraft:stone_pickaxe>;
Line 27: Line 28:
 
   
 
   
 
  val stonedPick = pick.withTag({display: {Name: "Stoned pick", Lore: ["This pick", "Has been experimenting too much"]}});
 
  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 onlyStickedPick = pick.onlyWithTag({display: {Name: "Sticked pick"}});
 
  val cobble = <minecraft:cobblestone>;
 
  val cobble = <minecraft:cobblestone>;
 
  recipes.addShaped(stonedPick, [[onlyStickedPick, cobble], [cobble, cobble]]);
 
  recipes.addShaped(stonedPick, [[onlyStickedPick, cobble], [cobble, cobble]]);
Line 33: Line 34:
 
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.
 
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.
+
Other conditions exist too:
 +
 
 +
myItem.onlyDamaged(); // only accepts damaged items
 +
myItem.onlyDamageAtLeast(15); // only accepts items with a damage of at least 15
 +
myItem.onlyDamageAtMost(100); // only accepts items with a damage of at most 100
 +
myItem.onlyDamageBetween(15, 100); // only accepts items with a damage between 15 and 100
 +
 
 +
Multiple conditions can be added to a single ingredient, too:
 +
 
 +
myItem.onlyDamaged().onlyWithTag({display: {Name: "Sticked pick"}});
 +
 
 +
## Output reuse and transformations ##
 +
 
 +
Since MineTweaker 3.0.2, it is now possible to reuse items, return empty buckets to the crafting grid (or whatever item you want) or damage items upon crafting.
 +
 
 +
We could for instance make a recipe to get more sticks out of wood by using an axe:
 +
 
 +
recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>, <ore:woodPlanks>]);
 +
 
 +
Nice. But the stone axe gets consumed, and that is sort of annoying. We can fix this with the reuse modifier:
 +
 
 +
recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.reuse(), <ore:plankWood>]);
 +
 
 +
Great! We can reuse the axe. Now what if we also wanted the axe to be damaged when you use it?
 +
 
 +
recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.transformDamage(), <ore:plankWood>]);
 +
 
 +
We can also deal more than 1 damage upon crafting:
 +
 
 +
recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.transformDamage(4), <ore:plankWood>]);
 +
 
 +
Imagine we'd want to make a recipe to turn dirt into grass by combining dirt, a water bucket and wheat. We could make this recipe:
 +
 
 +
recipes.addShapeless(<minecraft:grass>, [<minecraft:dirt>, <minecraft:water_bucket>, <minecraft:wheat>]);
 +
 
 +
However, crafting this will consume the bucket. We can tell MineTweaker to return the empty bucket afterwards:
 +
 
 +
recipes.addShaped(<minecraft:grass>, [[
 +
<minecraft:dirt>,
 +
<minecraft:water_bucket>.transform(Transform.replaceWith(<minecraft:bucket>)),
 +
<minecraft:wheat>
 +
]]);
  
''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''
+
Now, crafting a grass block will return the empty crafting bucket in the crafting grid.

Revision as of 20:32, 4 July 2014

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?

    1. NBT Tag in output ##

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 = <minecraft:stick>;
val pick = <minecraft:stone_pickaxe>;
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.

    1. Input conditions ##

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:

val stick = <minecraft:stick>;
val pick = <minecraft:stone_pickaxe>;
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.onlyWithTag({display: {Name: "Sticked pick"}});
val cobble = <minecraft: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.

Other conditions exist too:

myItem.onlyDamaged(); // only accepts damaged items
myItem.onlyDamageAtLeast(15); // only accepts items with a damage of at least 15
myItem.onlyDamageAtMost(100); // only accepts items with a damage of at most 100
myItem.onlyDamageBetween(15, 100); // only accepts items with a damage between 15 and 100

Multiple conditions can be added to a single ingredient, too:

myItem.onlyDamaged().onlyWithTag({display: {Name: "Sticked pick"}});
    1. Output reuse and transformations ##

Since MineTweaker 3.0.2, it is now possible to reuse items, return empty buckets to the crafting grid (or whatever item you want) or damage items upon crafting.

We could for instance make a recipe to get more sticks out of wood by using an axe:

recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>, <ore:woodPlanks>]);

Nice. But the stone axe gets consumed, and that is sort of annoying. We can fix this with the reuse modifier:

recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.reuse(), <ore:plankWood>]);

Great! We can reuse the axe. Now what if we also wanted the axe to be damaged when you use it?

recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.transformDamage(), <ore:plankWood>]);

We can also deal more than 1 damage upon crafting:

recipes.addShapeless(<minecraft:stick> * 3, [<minecraft:stone_axe>.transformDamage(4), <ore:plankWood>]);

Imagine we'd want to make a recipe to turn dirt into grass by combining dirt, a water bucket and wheat. We could make this recipe:

recipes.addShapeless(<minecraft:grass>, [<minecraft:dirt>, <minecraft:water_bucket>, <minecraft:wheat>]);

However, crafting this will consume the bucket. We can tell MineTweaker to return the empty bucket afterwards:

recipes.addShaped(<minecraft:grass>, [[
	<minecraft:dirt>,
	<minecraft:water_bucket>.transform(Transform.replaceWith(<minecraft:bucket>)),
	<minecraft:wheat>
]]);

Now, crafting a grass block will return the empty crafting bucket in the crafting grid.