Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recipes How to craft items from others Copyright © 2015 Curt Hill.

Similar presentations


Presentation on theme: "Recipes How to craft items from others Copyright © 2015 Curt Hill."— Presentation transcript:

1 Recipes How to craft items from others Copyright © 2015 Curt Hill

2 Introduction The craft of Minecraft refers to the fact that we can build things This could be using things we have gathered and rearranged It also involves crafting new items out of other items The 2 by 2 craft square in out inventory is used as can be the 3 by 3 craft table We will now look at some of the ways this is done Copyright © 2015 Curt Hill

3 GameRegistry The first method we will consider is addRecipe It and most others are static methods of GameRegistry We will need to execute these after we have created our mod items and blocks –Before game play starts I will typically put these in CommonProxie Copyright © 2015 Curt Hill

4 addRecipe The signature is this: public static void addRecipe( ItemStack output, Object... parms) The first is an ItemStack which is a container of Item handles The second is an array of objects –Recall that any object may be in this array This is the simplest of the recipes Copyright © 2015 Curt Hill

5 Explanation The first parameter of addRecipe is what you want to receive back –Could be an Item or Block The second parameter is rather more complicated It describes how these items are on the crafting squares Copyright © 2015 Curt Hill

6 Array of Object The first contents of the array are two or three strings –Two for the 2 by 2 crafting square –Three for the crafting table The strings have two characters for the square and three for the table A character(in the example an octothorp) represents that the source item –A blank represents the empty square This is followed by the results Copyright © 2015 Curt Hill

7 Results One more character is required –Recall string in “ and character in ‘ The character identifies the type that has been used Let’s consider some examples Copyright © 2015 Curt Hill

8 Example Copyright © 2015 Curt Hill Item result = GameRegistry.findItem( CurtMod.MODID, "yellowplus"); Item source_item = GameRegistry.findItem( CurtMod.MODID, "redplus"); Object [] source = new Object[] {"# ", " #", '#', source_item}; GameRegistry.addRecipe( new ItemStack(result), source);

9 The Picture Copyright © 2015 Curt Hill

10 Commentary This is asking for 2 redplus items to be transformed into yellowplus item –This registers this recipe When the two items are properly placed the yellowplus appears –In this case either set of opposite corners Using a string to identify the input object aborts the server Copyright © 2015 Curt Hill

11 What was the …? Who remembers what the … does in C++/Java? It means a variable number of parameters Thus we can put all the result parameters into an array or they may be separate parameters Copyright © 2015 Curt Hill

12 Example Revisited Copyright © 2015 Curt Hill result = GameRegistry.findItem( CurtMod.MODID, "blueplus"); source_item2 = GameRegistry.findItem( CurtMod.MODID, "redplus"); GameRegistry.addRecipe(new ItemStack(result), "# ", " #", '#', source_item2);

13 Commentary The Object array is preferred It is also typical to not set the parameters into separate variable Merely create find the item as the first parameter and create the object array as the second Copyright © 2015 Curt Hill

14 ItemStack Again There are several ItemStack constructor One takes a Block One takes an Item One takes a Block and integer One takes an Item and integer The latter two allow us to create multiple items in one recipe Copyright © 2015 Curt Hill

15 Another Picture Copyright © 2015 Curt Hill Using: ItemStack(result,3) as source Notice pattern symmetry

16 The Array The first part of the array is two or three strings that show position of objects The last so many are pairs An identifying character The input object Now lets consider two input objects Copyright © 2015 Curt Hill

17 Another Example Copyright © 2015 Curt Hill source_item = GameRegistry.findItem( CurtMod.MODID, "redplus"); source_item2 = GameRegistry.findItem( "minecraft", "emerald"); source = new Object[] {"R ", " E", 'R', source_item, 'E', source_item2}; GameRegistry.addRecipe( new ItemStack(result,2), source);

18 Picture Two different items Copyright © 2015 Curt Hill

19 No Shapes The method is: addShapelessRecipe Similar signature to addRecipe The pattern strings and identifying characters are missing Copyright © 2015 Curt Hill

20 Shapeless Example Copyright © 2015 Curt Hill GameRegistry.addShapelessRecipe( new ItemStack(result), new Object[] {source_item, source_item2, source_item, source_item2});

21 Shapeless Picture Copyright © 2015 Curt Hill

22 Smelting The smelting is done with addSmelting Takes three parameters First –A Block, Item or ItemStack for the input Second –An ItemStack for output Third –A float that determines experience points earned Copyright © 2015 Curt Hill

23 Finally This should be enough to get us crafting We may now do: –Shaped recipes –Shapeless recipes –Smelting recipes The adds for these are usually in a class that executes after the initialization but before game play –I put mine in CommonProxy, but other places will work Copyright © 2015 Curt Hill


Download ppt "Recipes How to craft items from others Copyright © 2015 Curt Hill."

Similar presentations


Ads by Google