addShapelessRecipe takes an ItemStack argument; this is the item that will be crafted. The following arguments are all of the blocks / items needed to craft it, in any order. In the example, a block of dirt and a stick will craft yourItemName.
addRecipe takes the same first argument, followed by 3 strings.
Each string represents a horizontal line in the crafting grid, using different characters to represent the different items needed. Here we've used "x", "#" and "z", but you can use whatever you want. Use as many different characters as you need.
Following this representation of the crafting grid, we define our variables like so: 'x', Object1, '#', Object2, etc.,
where each Object is a Block, Item or ItemStack. You can use your custom items in the recipe simply by referring to the instance you created in your class, i.e. using its name.
Here's a concrete example of a very basic item, a ThrowingRock:
public static final Item throwingRock = new ItemThrowingRock(5030).setUnlocalizedName("throwingRock");
GameRegistry.addShapelessRecipe(new ItemStack(MyMod.throwingRock, 9), Block.cobblestone);
GameRegistry.addRecipe(new ItemStack(Block.cobblestone), "xxx", "xxx", "xxx", 'x', throwingRock);
First we declare our Item, throwingRock, then add the recipes.
The first recipe is shapeless and turns one cobblestone block into 9 throwingRocks.
The second recipe has a shape (all 9 squares of the crafting grid) and turns 9 throwing rocks back into a cobblestone block.
Note that the recipe can return an ItemStack containing more than one Item of the same type; this is the second argument in ItemStack.
Note: Be sure to import Block, Item, ItemStack and GameRegistry or you will get errors.
Ok, now we're ready to tackle using potions in our recipes. It's actually quite simple.
We need to use the 3rd argument in ItemStack - itemDamage. While most items use this to keep track of wear and tear, potions use it as a secondary ID.
For example, we can craft a damaged wooden sword from a stick like so:
We need to make a stack of Item.potion with an itemDamage value that matches the 'id' of the potion we want. But what are the potion ID values? The easiest course of action is to check the minecraft wiki here: http://www.minecraft...et/wiki/Potions
Halfway down the page is a Data Value Table that shows the itemDamage values for every potion currently in game, as well as those in the code. Let's look at an example:
Let's say I want to use a Potion of Poison in my recipe. Looking at the wiki table above, I see a Regular Potion of Poison has an iD of 8196. So my recipe looks like this:
GameRegistry.addShapelessRecipe(new ItemStack(YourMod.yourModItem), new ItemStack(Item.potion,1,8196));
GameRegistry.addShapelessRecipe(new ItemStack(Item.potion,1,8196), new ItemStack(YourMod.yourModItem));
The first recipe crafts yourModItem from a Potion of Poison.
The second crafts a Potion of Poison from yourModItem.
Obviously, you can make your recipes as simple or complex as you like - if you need help, see the spoiler above for more on how crafting recipes work.
Well, that's pretty easy to do, but not very intuitive. It's not obvious just from looking at the code what (Item.potion,1,8196) is, which I personally don't like.
If you're up for something a little more advanced that will allow you to replace 8196 with a readable name, read on. Otherwise, you should be good to go - just check the wiki for data values of potions!
For this, we're going to take advantage of the type 'enum.' This allows us to define constant values in the format of CONSTANT_NAME(value1, value2,...). So we'll set up a new class called EnumPotionID like so:
public enum EnumPotionID
{
POTION_POISON(8196),
private final int potionID;
private EnumPotionID(int par1) {
this.potionID = par1;
}
public int potionID()
{
return this.potionID;
}
}
This allows us to call EnumPotionID.POTION_POISON.potionID(), which will return the value 8196, much like calling Item.swordWood returns the correct Item, which we can then call functions for with the same syntax.
So now our recipe will look like this:
GameRegistry.addShapelessRecipe(new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(YourMod.yourModItem));
Much more readable, although a bit long. If you want to make it shorter, remove the "POTION_" prefix and change the "potionID()" function to "ID()". You could even rename the class to "EnumPID".
There is also the advantage that if the developers ever change the potion iDs, you will only need to update your EnumPotionID class values and everywhere else in your code will automatically be updated.
Well that's all fine and dandy, but what if you want to make an item craftable from ANY version of a potion? Say, for example, you want a Potato + any version of a Poison potion to make a Poisoned Potato. You could code all the recipes by hand. But that wouldn't be very interesting. See below for an implementation.
First, you will need to implement the EnumPotionID class as above, or simply input all the values by hand. Here's my full version of EnumPotionID; if you want to use it, go ahead:
public enum EnumPotionID
{
/* POTION DATA VALUES from http://www.minecraftwiki.net/wiki/Potions
* EXT means "Extended" version of potion
* REV means "Reverted" version of potion
*/
POTION_AWKWARD(16),
POTION_THICK(32),
POTION_MUNDANE(128),
POTION_MUNDANE_EXT(64),
/*
* HELPFUL POTIONS
*/
POTION_REGEN(8193),
POTION_REGEN_II(8225),
POTION_REGEN_EXT(8257),
POTION_REGEN_II_EXT(8289),
POTION_REGEN_SPLASH(16385),
POTION_REGEN_SPLASH_II(16417),
POTION_REGEN_SPLASH_EXT(16449),
POTION_SWIFTNESS(8194),
POTION_SWIFTNESS_II(8226),
POTION_SWIFTNESS_EXT(8258),
POTION_SWIFTNESS_II_EXT(8290),
POTION_SWIFTNESS_SPLASH(16386),
POTION_SWIFTNESS_SPLASH_II(16418),
POTION_SWIFTNESS_SPLASH_EXT(16450),
POTION_FIRERESIST(8195),
POTION_FIRERESIST_REV(8227),
POTION_FIRERESIST_EXT(8259),
POTION_FIRERESIST_SPLASH(16387),
POTION_FIRERESIST_SPLASH_REV(16419),
POTION_FIRERESIST_SPLASH_EXT(16451),
POTION_HEALING(8197),
POTION_HEALING_II(8229),
POTION_HEALING_REV(8261),
POTION_HEALING_SPLASH(16389),
POTION_HEALING_SPLASH_II(16421),
POTION_HEALING_SPLASH_REV(16453),
POTION_NIGHTVISION(8198),
POTION_NIGHTVISION_REV(8230),
POTION_NIGHTVISION_EXT(8262),
POTION_NIGHTVISION_SPLASH(16390),
POTION_NIGHTVISION_SPLASH_REV(16422),
POTION_NIGHTVISION_SPLASH_EXT(16454),
POTION_STRENGTH(8201),
POTION_STRENGTH_II(8233),
POTION_STRENGTH_EXT(8265),
POTION_STRENGTH_II_EXT(8292),
POTION_STRENGTH_SPLASH(16393),
POTION_STRENGTH_SPLASH_II(16425),
POTION_STRENGTH_SPLASH_EXT(16457),
POTION_INVISIBILITY(8206),
POTION_INVISIBILITY_REV(8238),
POTION_INVISIBILITY_EXT(8270),
POTION_INVISIBILITY_SPLASH(16398),
POTION_INVISIBILITY_SPLASH_REV(16430),
POTION_INVISIBILITY_SPLASH_EXT(16462),
/*
* HARMFUL POTIONS
*/
POTION_POISON(8196),
POTION_POISON_II(8228),
POTION_POISON_EXT(8260),
POTION_POISON_SPLASH(16388),
POTION_POISON_SPLASH_II(16420),
POTION_POISON_SPLASH_EXT(16452),
POTION_WEAKNESS(8200),
POTION_WEAKNESS_REV(8232),
POTION_WEAKNESS_EXT(8264),
POTION_WEAKNESS_SPLASH(16392),
POTION_WEAKNESS_SPLASH_REV(16424),
POTION_WEAKNESS_SPLASH_EXT(16456),
POTION_SLOWNESS(8202),
POTION_SLOWNESS_REV(8234),
POTION_SLOWNESS_EXT(8266),
POTION_SLOWNESS_SPLASH(16394),
POTION_SLOWNESS_SPLASH_REV(16426),
POTION_SLOWNESS_SPLASH_EXT(16458),
POTION_HARM(8204),
POTION_HARM_II(8236),
POTION_HARM_REV(8268),
POTION_HARM_SPLASH(16396),
POTION_HARM_SPLASH_II(16428),
POTION_HARM_SPLASH_REV(16460);
private final int potionID;
private EnumPotionID(int par1) {
this.potionID = par1;
}
public int potionID()
{
return this.potionID;
}
}
Next, we're going to make an array "poisonPotions" like so:
Object[] poisonPotions = {new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_EXT.potionID())};
Implement it like so:
for (int i = 0; i < poisonPotions.length; ++i)
{
GameRegistry.addShapelessRecipe(new ItemStack(Item.poisonousPotato), Item.potato, poisonPotions[i]);
}
If you don't know about arrays, here's a brief explanation:
An array is basically an ordered list of objects of any type. The array is accessed using brackets and the place of the object you want in the array, such that arrayName[0] returns the first object in the array, and arrayName[arrayName.length-1] returns the last object in the array.
Arrays are very powerful tools, but if you're new to them, you're likely crash to your game by throwing null pointer exceptions and not know why, as they won't show up as errors in your code. Array errors can be difficult to pinpoint, and a solid understanding of their functionality will go a long way in helping you.
Learn more here: http://docs.oracle.c...lts/arrays.html
Ok, so we've used an array to auto-generate our crafting recipes for us. Great. But say for some reason you want every potion type craftable into your new item? For example, you want to make a new FoodItems that confers potion effects based on the potion it was crafted with. Assuming you have your newFoodItem class set up and only need to generate recipes, here's what you could do:
/*
* Object[][] potionMatrix is set up so that the first
* bracket identifies the potion type (e.g. POISON) and
* the second bracket the specific instance of that potion
* (e.g. POTION_POISON_EXT)
*/
Object[][] potionMatrix =
{{new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_EXT.potionID())},
{new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_REV.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH_REV.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH_EXT.potionID())},
{etc.}};
/*
* Object[] yourModItems contains the corresponding new food items for
* each potion effect. There MUST be the same number of new items as
* there are Potion types in potionMatrix[][] or you WILL throw null
* pointer exceptions and crash your game.
*/
Object[] yourModItems = {YourMod.breadPoison, YourMod.breadWeakness, etc.};
// Iterates through the base potion types
for (int j = 0; j < potionMatrix.length; ++j)
{
// Iterates through the specific potions of a single type
for (int k = 0; k < potionMatrix[j].length; ++k)
{
Object potioninrecipe = potionMatrix[j][k];
GameRegistry.addShapelessRecipe(new ItemStack(yourModItems[j]), new Object[] {Item.bread, potioninrecipe});
}
}
This would generate all the recipes you need to make your Weak Bread, Poisoned Bread, etc., as you define in your own class. If you're like me and don't like to have lots of code mucking up your main mod class, just create a new class RegisterCraftingRecipes with an addRecipe() function and call it like so:
(new RegisterCraftingRecipes()).addRecipes();
Then you can put all that stuff there and your main mod will look nice and tidy!
Well, there it is. Hope that's helpful to somebody.
Be sure to check out my other tutorials - they are all on github here or follow the forum links below:
addShapelessRecipe takes an ItemStack argument; this is the item that will be crafted. The following arguments are all of the blocks / items needed to craft it, in any order. In the example, a block of dirt and a stick will craft yourItemName.
addRecipe takes the same first argument, followed by 3 strings.
Each string represents a horizontal line in the crafting grid, using different characters to represent the different items needed. Here we've used "x", "#" and "z", but you can use whatever you want. Use as many different characters as you need.
Following this representation of the crafting grid, we define our variables like so: 'x', Object1, '#', Object2, etc.,
where each Object is a Block, Item or ItemStack. You can use your custom items in the recipe simply by referring to the instance you created in your class, i.e. using its name.
Here's a concrete example of a very basic item, a ThrowingRock:
public static final Item throwingRock = new ItemThrowingRock(5030).setUnlocalizedName("throwingRock");
GameRegistry.addShapelessRecipe(new ItemStack(MyMod.throwingRock, 9), Block.cobblestone);
GameRegistry.addRecipe(new ItemStack(Block.cobblestone), "xxx", "xxx", "xxx", 'x', throwingRock);
First we declare our Item, throwingRock, then add the recipes.
The first recipe is shapeless and turns one cobblestone block into 9 throwingRocks.
The second recipe has a shape (all 9 squares of the crafting grid) and turns 9 throwing rocks back into a cobblestone block.
Note that the recipe can return an ItemStack containing more than one Item of the same type; this is the second argument in ItemStack.
Note: Be sure to import Block, Item, ItemStack and GameRegistry or you will get errors.
Ok, now we're ready to tackle using potions in our recipes. It's actually quite simple.
We need to use the 3rd argument in ItemStack - itemDamage. While most items use this to keep track of wear and tear, potions use it as a secondary ID.
For example, we can craft a damaged wooden sword from a stick like so:
So we need to make a stack of Item.potion with the correct itemDamage value (the 'id' of the potion we want). But what ID value do we use? The easiest course of action is to check the minecraft wiki here: http://www.minecraft...et/wiki/Potions
Halfway down the page is a Data Value Table that shows the itemDamage values for every potion currently in game, as well as those in the code. Let's look at an example:
Let's say I want to use a Potion of Poison in my recipe. Looking at the wiki table above, I see a Regular Potion of Poison has an iD of 8196. So my recipe looks like this:
GameRegistry.addShapelessRecipe(new ItemStack(YourMod.yourModItem), new ItemStack(Item.potion,1,8196));
GameRegistry.addShapelessRecipe(new ItemStack(Item.potion,1,8196), new ItemStack(YourMod.yourModItem));
The first recipe crafts yourModItem from a Potion of Poison.
The second crafts a Potion of Poison from yourModItem.
Obviously, you can make your recipes as simple or complex as you like - if you need help, see above for more on how crafting recipes work.
Well, that's pretty easy to do, but not very intuitive. What is (Item.potion,1,8196)? It's not very obvious just from looking at the code, and if you come back at a later date and want to change something, it may take you a while to figure out what the hell 8196 is.
If you're up for something a little more advanced that will allow you to replace 8196 with a readable name, read on.
For this, we're going to take advantage of the type 'enum.' This allows us to define constant values in the format of CONSTANT_NAME(value1, value2,...). So we'll set up a new class called EnumPotionID like so:
public enum EnumPotionID
{
POTION_POISON(8196),
private final int potionID;
private EnumPotionID(int par1) {
this.potionID = par1;
}
public int potionID()
{
return this.potionID;
}
}
This allows us to call EnumPotionID.POTION_POISON.potionID(), which will return the value 8196, much like calling Item.swordWood returns the correct Item, which we can then call functions for with the same syntax.
So now our recipe will look like this:
GameRegistry.addShapelessRecipe(new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(YourMod.yourModItem));
Much more readable, although a bit long. It has the added advantage that if the developers ever change the potion iDs, you will only need to update your EnumPotionID class values and everywhere else in your code will automatically be updated.
Well that's all fine and dandy, but what if you want to make an item craftable from ANY version of a potion? Say, for example, you want a Potato + any version of a Poison potion to make a Poisoned Potato. You could code all the recipes by hand. But that would just be silly. See below for an implementation.
First, you will need to implement the EnumPotionID class as above, or simply input all the values by hand. Here's my full version of EnumPotionID; if you want to use it, go ahead:
public enum EnumPotionID
{
/* POTION DATA VALUES from http://www.minecraftwiki.net/wiki/Potions
* EXT means "Extended" version of potion
* REV means "Reverted" version of potion
*/
POTION_AWKWARD(16),
POTION_THICK(32),
POTION_MUNDANE(128),
POTION_MUNDANE_EXT(64),
/*
* HELPFUL POTIONS
*/
POTION_REGEN(8193),
POTION_REGEN_II(8225),
POTION_REGEN_EXT(8257),
POTION_REGEN_II_EXT(8289),
POTION_REGEN_SPLASH(16385),
POTION_REGEN_SPLASH_II(16417),
POTION_REGEN_SPLASH_EXT(16449),
POTION_SWIFTNESS(8194),
POTION_SWIFTNESS_II(8226),
POTION_SWIFTNESS_EXT(8258),
POTION_SWIFTNESS_II_EXT(8290),
POTION_SWIFTNESS_SPLASH(16386),
POTION_SWIFTNESS_SPLASH_II(16418),
POTION_SWIFTNESS_SPLASH_EXT(16450),
POTION_FIRERESIST(8195),
POTION_FIRERESIST_REV(8227),
POTION_FIRERESIST_EXT(8259),
POTION_FIRERESIST_SPLASH(16387),
POTION_FIRERESIST_SPLASH_REV(16419),
POTION_FIRERESIST_SPLASH_EXT(16451),
POTION_HEALING(8197),
POTION_HEALING_II(8229),
POTION_HEALING_REV(8261),
POTION_HEALING_SPLASH(16389),
POTION_HEALING_SPLASH_II(16421),
POTION_HEALING_SPLASH_REV(16453),
POTION_NIGHTVISION(8198),
POTION_NIGHTVISION_REV(8230),
POTION_NIGHTVISION_EXT(8262),
POTION_NIGHTVISION_SPLASH(16390),
POTION_NIGHTVISION_SPLASH_REV(16422),
POTION_NIGHTVISION_SPLASH_EXT(16454),
POTION_STRENGTH(8201),
POTION_STRENGTH_II(8233),
POTION_STRENGTH_EXT(8265),
POTION_STRENGTH_II_EXT(8292),
POTION_STRENGTH_SPLASH(16393),
POTION_STRENGTH_SPLASH_II(16425),
POTION_STRENGTH_SPLASH_EXT(16457),
POTION_INVISIBILITY(8206),
POTION_INVISIBILITY_REV(8238),
POTION_INVISIBILITY_EXT(8270),
POTION_INVISIBILITY_SPLASH(16398),
POTION_INVISIBILITY_SPLASH_REV(16430),
POTION_INVISIBILITY_SPLASH_EXT(16462),
/*
* HARMFUL POTIONS
*/
POTION_POISON(8196),
POTION_POISON_II(8228),
POTION_POISON_EXT(8260),
POTION_POISON_SPLASH(16388),
POTION_POISON_SPLASH_II(16420),
POTION_POISON_SPLASH_EXT(16452),
POTION_WEAKNESS(8200),
POTION_WEAKNESS_REV(8232),
POTION_WEAKNESS_EXT(8264),
POTION_WEAKNESS_SPLASH(16392),
POTION_WEAKNESS_SPLASH_REV(16424),
POTION_WEAKNESS_SPLASH_EXT(16456),
POTION_SLOWNESS(8202),
POTION_SLOWNESS_REV(8234),
POTION_SLOWNESS_EXT(8266),
POTION_SLOWNESS_SPLASH(16394),
POTION_SLOWNESS_SPLASH_REV(16426),
POTION_SLOWNESS_SPLASH_EXT(16458),
POTION_HARM(8204),
POTION_HARM_II(8236),
POTION_HARM_REV(8268),
POTION_HARM_SPLASH(16396),
POTION_HARM_SPLASH_II(16428),
POTION_HARM_SPLASH_REV(16460);
private final int potionID;
private EnumPotionID(int par1) {
this.potionID = par1;
}
public int potionID()
{
return this.potionID;
}
}
Next, we're going to make an array "poisonPotions" like so:
Object[] poisonPotions = {new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_EXT.potionID())};
Implement it like so:
for (int i = 0; i < poisonPotions.length; ++i)
{
GameRegistry.addShapelessRecipe(new ItemStack(Item.poisonousPotato), Item.potato, poisonPotions[i]);
}
If you don't know about arrays, here's a brief explanation:
An array is basically an ordered list of objects of any type. The array is accessed using brackets and the place of the object you want in the array, such that arrayName[0] returns the first object in the array, and arrayName[arrayName.length-1] returns the last object in the array.
Arrays are very powerful tools, but if you're new to them, you're likely crash to your game by throwing null pointer exceptions and not know why, as they won't show up as errors in your code. Array errors can be difficult to pinpoint, and a solid understanding of their functionality will go a long way in helping you.
Learn more here: http://docs.oracle.c...lts/arrays.html
Ok, so we've used an array to auto-generate our crafting recipes for us. Great. But say for some reason you want every potion type craftable into your new item? For example, you want to make a new FoodItems that confers potion effects based on the potion it was crafted with. Assuming you have your newFoodItem class set up and only need to generate recipes, here's what you could do:
/*
* Object[][] potionMatrix is set up so that the first
* bracket identifies the potion type (e.g. POISON) and
* the second bracket the specific instance of that potion
* (e.g. POTION_POISON_EXT)
*/
Object[][] potionMatrix =
{{new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_II.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_POISON_SPLASH_EXT.potionID())},
{new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_REV.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_EXT.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH_REV.potionID()), new ItemStack(Item.potion,1,EnumPotionID.POTION_WEAKNESS_SPLASH_EXT.potionID())},
{etc.}};
/*
* Object[] yourModItems contains the corresponding new food items for
* each potion effect. There MUST be the same number of new items as
* there are Potion types in potionMatrix[][] or you WILL throw null
* pointer exceptions and crash your game.
*/
Object[] yourModItems = {YourMod.breadPoison, YourMod.breadWeakness, etc.};
// Iterates through the base potion types
for (int j = 0; j < potionMatrix.length; ++j)
{
// Iterates through the specific potions of a single type
for (int k = 0; k < potionMatrix[j].length; ++k)
{
Object potioninrecipe = potionMatrix[j][k];
GameRegistry.addShapelessRecipe(new ItemStack(yourModItems[j]), new Object[] {Item.bread, potioninrecipe});
}
}
This would generate all the recipes you need to make your Weak Bread, Poisoned Bread, etc., as you define in your own class. If you're like me and don't like to have lots of code mucking up your main mod class, just create a new class RegisterCraftingRecipes with an addRecipe() function and call it like so:
(new RegisterCraftingRecipes()).addRecipes();
Then you can put all that stuff there and your main mod will look nice and tidy!
Whew! That was way longer than I expected. Hope that's helpful to somebody.
You my friend, deserve a lot more respect than you are currently getting
Thanks! Heh, I didn't think anyone was even interested in this tutorial, so I'm glad you did. I just wrote it as a way for me to learn about potion recipes when I started modding a few months back, as I was toying with using this as part of a mod.
Is there a way to craft unimplemented potions like the splash potion of blindness? I have a mod that has a craftable splash potion of blindness as one of its intended features, and would like to find out if it is possible.
Rollback Post to RevisionRollBack
I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
Is there a way to craft unimplemented potions like the splash potion of blindness? I have a mod that has a craftable splash potion of blindness as one of its intended features, and would like to find out if it is possible.
I don't see why you couldn't - try and let us know!
For any recipe, you will need the following in your main mod class:
addShapelessRecipe takes an ItemStack argument; this is the item that will be crafted. The following arguments are all of the blocks / items needed to craft it, in any order. In the example, a block of dirt and a stick will craft yourItemName.
addRecipe takes the same first argument, followed by 3 strings.
Each string represents a horizontal line in the crafting grid, using different characters to represent the different items needed. Here we've used "x", "#" and "z", but you can use whatever you want. Use as many different characters as you need.
Following this representation of the crafting grid, we define our variables like so: 'x', Object1, '#', Object2, etc.,
where each Object is a Block, Item or ItemStack. You can use your custom items in the recipe simply by referring to the instance you created in your class, i.e. using its name.
Here's a concrete example of a very basic item, a ThrowingRock:
First we declare our Item, throwingRock, then add the recipes.
The first recipe is shapeless and turns one cobblestone block into 9 throwingRocks.
The second recipe has a shape (all 9 squares of the crafting grid) and turns 9 throwing rocks back into a cobblestone block.
Note that the recipe can return an ItemStack containing more than one Item of the same type; this is the second argument in ItemStack.
Ok, now we're ready to tackle using potions in our recipes. It's actually quite simple.
We need to use the 3rd argument in ItemStack - itemDamage. While most items use this to keep track of wear and tear, potions use it as a secondary ID.
For example, we can craft a damaged wooden sword from a stick like so:
The sword will have 25 damage to its durability.
We need to make a stack of Item.potion with an itemDamage value that matches the 'id' of the potion we want. But what are the potion ID values? The easiest course of action is to check the minecraft wiki here: http://www.minecraft...et/wiki/Potions
Halfway down the page is a Data Value Table that shows the itemDamage values for every potion currently in game, as well as those in the code. Let's look at an example:
Let's say I want to use a Potion of Poison in my recipe. Looking at the wiki table above, I see a Regular Potion of Poison has an iD of 8196. So my recipe looks like this:
The first recipe crafts yourModItem from a Potion of Poison.
The second crafts a Potion of Poison from yourModItem.
Obviously, you can make your recipes as simple or complex as you like - if you need help, see the spoiler above for more on how crafting recipes work.
Well, that's pretty easy to do, but not very intuitive. It's not obvious just from looking at the code what (Item.potion,1,8196) is, which I personally don't like.
If you're up for something a little more advanced that will allow you to replace 8196 with a readable name, read on. Otherwise, you should be good to go - just check the wiki for data values of potions!
For this, we're going to take advantage of the type 'enum.' This allows us to define constant values in the format of CONSTANT_NAME(value1, value2,...). So we'll set up a new class called EnumPotionID like so:
For more information about the enum type, see: http://docs.oracle.c...avaOO/enum.html
So now our recipe will look like this:
Much more readable, although a bit long. If you want to make it shorter, remove the "POTION_" prefix and change the "potionID()" function to "ID()". You could even rename the class to "EnumPID".
There is also the advantage that if the developers ever change the potion iDs, you will only need to update your EnumPotionID class values and everywhere else in your code will automatically be updated.
Well that's all fine and dandy, but what if you want to make an item craftable from ANY version of a potion? Say, for example, you want a Potato + any version of a Poison potion to make a Poisoned Potato. You could code all the recipes by hand. But that wouldn't be very interesting. See below for an implementation.
First, you will need to implement the EnumPotionID class as above, or simply input all the values by hand. Here's my full version of EnumPotionID; if you want to use it, go ahead:
Implement it like so:
If you don't know about arrays, here's a brief explanation:
An array is basically an ordered list of objects of any type. The array is accessed using brackets and the place of the object you want in the array, such that arrayName[0] returns the first object in the array, and arrayName[arrayName.length-1] returns the last object in the array.
Arrays are very powerful tools, but if you're new to them, you're likely crash to your game by throwing null pointer exceptions and not know why, as they won't show up as errors in your code. Array errors can be difficult to pinpoint, and a solid understanding of their functionality will go a long way in helping you.
Learn more here: http://docs.oracle.c...lts/arrays.html
Then you can put all that stuff there and your main mod will look nice and tidy!
Be sure to check out my other tutorials - they are all on github here or follow the forum links below:
- EventHandler and IExtendedEntityProperties: http://www.minecraft...e-explanations/
- Custom Inventories in Items and Players: http://www.minecraft...s-an-inventory/
- Rendering a custom item texture: http://www.minecraft...m-item-texture/
- How to properly override shift-clicking: http://www.minecraft...shift-clicking/
- Enchanted Book Crafting Recipes: http://www.minecraft...-tag-compounds/
- See Mazetar's List for the best Minecraft tutorials from around the web!
Lastly, don't forget to up the green arrow on any posts that help you!
Great tutorial :).
Mapping and Modding rules | Global rules
Thanks!
Thanks! Heh, I didn't think anyone was even interested in this tutorial, so I'm glad you did. I just wrote it as a way for me to learn about potion recipes when I started modding a few months back, as I was toying with using this as part of a mod.
Then I thought heck, why not share it?
Is there a way to craft unimplemented potions like the splash potion of blindness? I have a mod that has a craftable splash potion of blindness as one of its intended features, and would like to find out if it is possible.
I just took the Minecraft Noob test! Check out what I scored. Think you can beat me?!
To take the test, check out
https://minecraftnoobtest.com/test.php
Don't click this link, HE is haunting it...
I don't see why you couldn't - try and let us know!