5
5
import net .minecraft .item .EnumDyeColor ;
6
6
import net .minecraft .item .ItemStack ;
7
7
import net .minecraft .item .crafting .IRecipe ;
8
+ import net .minecraft .item .crafting .Ingredient ;
8
9
import net .minecraft .util .ResourceLocation ;
10
+ import net .minecraftforge .common .MinecraftForge ;
11
+ import net .minecraftforge .common .crafting .CraftingHelper ;
9
12
import net .minecraftforge .fml .common .IFuelHandler ;
10
13
import net .minecraftforge .fml .common .registry .GameRegistry ;
11
14
import net .minecraftforge .oredict .OreDictionary ;
12
15
import net .minecraftforge .oredict .ShapedOreRecipe ;
16
+ import net .minecraftforge .registries .GameData ;
17
+
18
+ import javax .annotation .Nonnull ;
13
19
14
20
/**
15
21
* User: The Grey Ghost
@@ -50,7 +56,7 @@ public static void initCommon()
50
56
ResourceLocation optionalGroup = new ResourceLocation ("" );
51
57
52
58
// a) Shaped recipe without metadata - emerald surrounded by diamond makes ender eye
53
- GameRegistry .addShapedRecipe (new ResourceLocation ("minecraftbyexample:ender_eye " ), optionalGroup , new ItemStack (Items .ENDER_EYE ), new Object []{
59
+ GameRegistry .addShapedRecipe (new ResourceLocation ("minecraftbyexample:mbe35_recipe_ender_eye " ), optionalGroup , new ItemStack (Items .ENDER_EYE ), new Object []{
54
60
" D " ,
55
61
"DED" ,
56
62
" D " ,
@@ -62,72 +68,85 @@ public static void initCommon()
62
68
63
69
// b) shaped recipe with metadata - cobblestone surrounded by red dye makes redstone
64
70
final int RED_DYE_DAMAGE_VALUE = EnumDyeColor .RED .getDyeDamage ();
65
- GameRegistry .addShapedRecipe (new ResourceLocation ("minecraftbyexample:redstone " ), optionalGroup , new ItemStack (Items .REDSTONE ), new Object []{
71
+ GameRegistry .addShapedRecipe (new ResourceLocation ("minecraftbyexample:mbe35_recipe_redstone " ), optionalGroup , new ItemStack (Items .REDSTONE ), new Object []{
66
72
"RRR" ,
67
73
"RCR" ,
68
74
"RRR" ,
69
75
'C' , Blocks .COBBLESTONE ,
70
76
'R' , new ItemStack (Items .DYE , 1 , RED_DYE_DAMAGE_VALUE )
71
77
});
72
78
79
+
80
+ ResourceLocation woodSwordGroup = new ResourceLocation ("mbe35_woodswordgroup" );
81
+
73
82
// c) shaped recipe for items which are damaged, or which have a metadata you want to ignore
74
83
// wooden sword (any damage value) in a cobblestone shell plus iron ingot makes iron sword
75
- GameRegistry .addShapedRecipe (new ItemStack (Items .IRON_SWORD ), new Object []{
84
+ GameRegistry .addShapedRecipe (new ResourceLocation ( "minecraftbyexample:mbe35_recipe_wood_to_iron_sword" ), woodSwordGroup , new ItemStack (Items .IRON_SWORD ), new Object []{
76
85
"CIC" ,
77
86
"CWC" ,
78
87
"CCC" ,
79
88
'C' , Blocks .COBBLESTONE ,
80
- 'W' , new ItemStack (Items .WOODEN_SWORD , 1 , OreDictionary .WILDCARD_VALUE ),
89
+ 'W' , new ItemStack (Items .WOODEN_SWORD , 1 , OreDictionary .WILDCARD_VALUE ), // as of 1.12.2, you can also write simply Items.WOODEN_SWORD instead of new ItemStack,
90
+ // i.e. same as Items.IRON_INGOT on the next line
81
91
'I' , Items .IRON_INGOT
82
92
});
83
93
84
- // // for comparison - this recipe only works with an undamaged wooden sword
85
- // // wooden sword (undamaged) in a cobblestone shell plus gold ingot makes gold sword
86
- // GameRegistry.addRecipe(new ItemStack(Items.GOLDEN_SWORD), new Object[]{
87
- // "CIC",
88
- // "CWC",
89
- // "CCC",
90
- // 'C', Blocks.COBBLESTONE,
91
- // 'W', Items.WOODEN_SWORD,
92
- // 'I', Items.GOLD_INGOT
93
- // });
94
- //
95
- // // d) Shapeless recipe - blue dye plus yellow dye makes two green dye
96
- // final int BLUE_DYE_DAMAGE_VALUE = EnumDyeColor.BLUE.getDyeDamage();
97
- // final int YELLOW_DYE_DAMAGE_VALUE = EnumDyeColor.YELLOW.getDyeDamage();
98
- // final int GREEN_DYE_DAMAGE_VALUE = EnumDyeColor.GREEN.getDyeDamage();
99
- // final int NUMBER_OF_GREEN_DYE_PRODUCED = 2;
100
- // GameRegistry.addShapelessRecipe(new ItemStack(Items.DYE, NUMBER_OF_GREEN_DYE_PRODUCED, GREEN_DYE_DAMAGE_VALUE),
101
- // new Object[] {
102
- // new ItemStack(Items.DYE, 1, YELLOW_DYE_DAMAGE_VALUE),
103
- // new ItemStack(Items.DYE, 1, BLUE_DYE_DAMAGE_VALUE)
104
- // });
105
- //
106
- // // g) Shaped Ore recipe - any type of tree leaves arranged around sticks makes a sapling
107
- // // Ores are a way for mods to add blocks & items which are equivalent to vanilla blocks for crafting
108
- // // For example - an ore recipe which uses "logWood" will accept a log of spruce, oak, birch, pine, etc.
109
- // // If your mod registers its balsawood log using OreDictionary.registerOre("logWood", BalsaWood), then your
110
- // // BalsaWood log will also be accepted in the recipe.
111
- // IRecipe saplingRecipe = new ShapedOreRecipe(new ItemStack(Blocks.SAPLING), new Object[] {
112
- // "LLL",
113
- // "LSL",
114
- // " S ",
115
- // 'S', Items.STICK, // can use ordinary items, blocks, itemstacks in ShapedOreRecipe
116
- // 'L', "treeLeaves", // look in OreDictionary for vanilla definitions
117
- // });
118
- // GameRegistry.addRecipe(saplingRecipe);
119
- //
120
- // // h) by default, recipes are automatically mirror-imaged, i.e. you can flip the recipe left<--> right and it will
121
- // // produce the same output. This one isn't. Only works for OreRecipes, but you can make ShapedOreRecipe from vanilla
122
- // // Items or Blocks too (see (g) above)
123
- // IRecipe unmirroredRecipe = new ShapedOreRecipe(new ItemStack(Items.CAULDRON), new Object[] {
124
- // false,
125
- // "III",
126
- // "I ",
127
- // "III",
128
- // 'I', Items.IRON_INGOT
129
- // });
130
- // GameRegistry.addRecipe(unmirroredRecipe);
94
+ // for comparison - this recipe only works with an undamaged wooden sword
95
+ // wooden sword (undamaged) in a cobblestone shell plus gold ingot makes gold sword
96
+ // NOTE - this has changed since 1.11.2
97
+ GameRegistry .addShapedRecipe (new ResourceLocation ("minecraftbyexample:mbe35_recipe_wood_to_gold_sword" ), woodSwordGroup , new ItemStack (Items .GOLDEN_SWORD ), new Object []{
98
+ "CIC" ,
99
+ "CWC" ,
100
+ "CCC" ,
101
+ 'C' , Blocks .COBBLESTONE ,
102
+ 'W' , new ItemStack (Items .WOODEN_SWORD ),
103
+ 'I' , Items .GOLD_INGOT
104
+ });
105
+
106
+ // d) Shapeless recipe - blue dye plus yellow dye makes two green dye
107
+ final int BLUE_DYE_DAMAGE_VALUE = EnumDyeColor .BLUE .getDyeDamage ();
108
+ final int YELLOW_DYE_DAMAGE_VALUE = EnumDyeColor .YELLOW .getDyeDamage ();
109
+ final int GREEN_DYE_DAMAGE_VALUE = EnumDyeColor .GREEN .getDyeDamage ();
110
+ final int NUMBER_OF_GREEN_DYE_PRODUCED = 2 ;
111
+
112
+ GameRegistry .addShapelessRecipe (new ResourceLocation ("minecraftbyexample:mbe35_recipe_greendye" ), optionalGroup ,
113
+ new ItemStack (Items .DYE , NUMBER_OF_GREEN_DYE_PRODUCED , GREEN_DYE_DAMAGE_VALUE ),
114
+ new Ingredient [] {Ingredient .fromStacks (new ItemStack (Items .DYE , 1 , YELLOW_DYE_DAMAGE_VALUE )),
115
+ Ingredient .fromStacks (new ItemStack (Items .DYE , 1 , BLUE_DYE_DAMAGE_VALUE ))
116
+ }
117
+ );
118
+
119
+ // g) Shaped Ore recipe - any type of tree leaves arranged around sticks makes a sapling
120
+ // Ores are a way for mods to add blocks & items which are equivalent to vanilla blocks for crafting
121
+ // For example - an ore recipe which uses "logWood" will accept a log of spruce, oak, birch, pine, etc.
122
+ // If your mod registers its balsawood log using OreDictionary.registerOre("logWood", BalsaWood), then your
123
+ // BalsaWood log will also be accepted in the recipe.
124
+ IRecipe saplingRecipe = new ShapedOreRecipe (optionalGroup ,
125
+ new ItemStack (Blocks .SAPLING ), new Object [] {
126
+ "LLL" ,
127
+ "LSL" ,
128
+ " S " ,
129
+ 'S' , Items .STICK , // can use ordinary items, blocks, itemstacks in ShapedOreRecipe
130
+ 'L' , "treeLeaves" , // look in OreDictionary for vanilla definitions
131
+ });
132
+ saplingRecipe .setRegistryName (new ResourceLocation ("minecraftbyexample:mbe35_recipe_sapling" ));
133
+ // GameRegistry.register(saplingRecipe);
134
+ GameData .register_impl (saplingRecipe ); // looks clumsy. Not sure why GameRegistry doesn't have an appropriate register method.
135
+
136
+ // h) by default, recipes are automatically mirror-imaged, i.e. you can flip the recipe left<--> right and it will
137
+ // produce the same output. This one isn't. Only works for OreRecipes, but you can make ShapedOreRecipe from vanilla
138
+ // Items or Blocks too (see (g) above)
139
+ CraftingHelper .ShapedPrimer primer = CraftingHelper .parseShaped (new Object []{
140
+ false ,
141
+ "III" ,
142
+ "I " ,
143
+ "III" ,
144
+ 'I' , Items .IRON_INGOT
145
+ });
146
+ primer .mirrored = false ;
147
+ IRecipe unmirroredRecipe = new ShapedOreRecipe (optionalGroup , new ItemStack (Items .CAULDRON ), primer );
148
+ unmirroredRecipe .setRegistryName (new ResourceLocation ("minecraftbyexample:mbe35_recipe_cauldron" ));
149
+ GameData .register_impl (unmirroredRecipe ); // looks clumsy. Not sure why GameRegistry doesn't have an appropriate register method.
131
150
132
151
//---------------- FURNACE RECIPES (smelting)
133
152
@@ -140,25 +159,15 @@ public static void initCommon()
140
159
GameRegistry .addSmelting (Items .CAKE , new ItemStack (Items .COAL , NUMBER_OF_ITEMS , CHARCOAL_METADATA_VALUE ), CAKE_SMELT_XP );
141
160
142
161
// e) fuel - use wheat as fuel in a furnace
143
- // We use an anonymous class... you can use an ordinary class instead if you prefer.
144
- IFuelHandler wheatFuelHandler = new IFuelHandler () {
145
- @ Override
146
- public int getBurnTime (ItemStack fuel ) {
147
- final int BURN_TIME_SECONDS = 5 ;
148
- final int TICKS_PER_SECOND = 20 ;
149
- if (fuel .getItem () == Items .WHEAT ) {
150
- return BURN_TIME_SECONDS * TICKS_PER_SECOND ;
151
- } else {
152
- return 0 ;
153
- }
154
- }
155
- };
156
- GameRegistry .registerFuelHandler (wheatFuelHandler );
162
+ // For your own item, override getItemBurnTime()
163
+ // For vanilla, need to register for the FurnaceFuelBurnTimeEvent, which is called whenever fuel is placed into a furnace
164
+ // Look in the FurnaceFuelBurnTimeEventHandler class for the details.
165
+ MinecraftForge .EVENT_BUS .register (FurnaceFuelBurnTimeEventHandler .instance );
157
166
158
167
// ------------- Custom recipes
159
168
160
169
// you can even register your own custom IRecipe class to match complicated inputs - see for example RecipeFireworks
161
- // GameRegister.addRecipe (myRecipe implements IRecipe);
170
+ // GameData.register_impl (myRecipe implements IRecipe);
162
171
}
163
172
164
173
public static void postInitCommon ()
0 commit comments