Skip to content

Commit 7059a01

Browse files
author
The Grey Ghost
committed
All examples working except 40 HUD and 70 Config screen
1 parent be7bd01 commit 7059a01

19 files changed

+1114
-1036
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This update is a work in progress. It will compile and run many of the examples
5555
- [MBE35][35] - some typical example crafting recipes and furnace (smelting) recipes
5656

5757
### Heads Up Display/Overlays
58-
- [MBE40][40] - simple customisations of the heads up display (hotbar, health meter)
58+
- [MBE40][40] - NOT WORKING YET - simple customisations of the heads up display (hotbar, health meter)
5959

6060
### Particles - particle effects
6161
- [MBE50][50] - shows how to use vanilla Particles; also how to generate your own custom Particles
@@ -64,7 +64,7 @@ This update is a work in progress. It will compile and run many of the examples
6464
- [MBE60][60] - send network messages between client and server
6565

6666
### Configuration GUI
67-
- [MBE70][70] - configuration file linked to the "mod options" button GUI on the mods list screen
67+
- [MBE70][70] - NOT WORKING YET - configuration file linked to the "mod options" button GUI on the mods list screen
6868

6969
### Testing tools
7070
- [MBE75][75] - a tool to help you automate testing of your classes in-game.

Diff for: changes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ForgeRegistries.ITEMS.register, ForgeRegistries.BLOCKS.register etc instead of G
33
Item.getSubItems() signature change, and vanilla Items no longer add subitems unless the tab parameter equals CreativeTabs.SEARCH
44
Particle.shouldDisableDepth() instead of .isTransparent()
55
IPerspectiveAwareModel has been integrated into IBakedModel
6+
Items in recipes now default to using WILDCARD, i.e. damaged items will still match the recipe.
67

78
Changes from 1.10.2 to 1.11
89
A major change is that itemStacks can't be null anymore, the EMPTY item is used instead. i.e.

Diff for: src/main/java/minecraftbyexample/ClientOnlyProxy.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void preInit()
4141
// minecraftbyexample.mbe40_hud_overlay.StartupClientOnly.preInitClientOnly();
4242
minecraftbyexample.mbe50_particle.StartupClientOnly.preInitClientOnly();
4343
minecraftbyexample.mbe60_network_messages.StartupClientOnly.preInitClientOnly();
44-
// minecraftbyexample.mbe75_testing_framework.StartupClientOnly.preInitClientOnly();
44+
minecraftbyexample.mbe75_testing_framework.StartupClientOnly.preInitClientOnly();
4545
minecraftbyexample.testingarea.StartupClientOnly.preInitClientOnly();
4646
}
4747

@@ -74,7 +74,7 @@ public void init()
7474
// minecraftbyexample.mbe40_hud_overlay.StartupClientOnly.initClientOnly();
7575
minecraftbyexample.mbe50_particle.StartupClientOnly.initClientOnly();
7676
minecraftbyexample.mbe60_network_messages.StartupClientOnly.initClientOnly();
77-
// minecraftbyexample.mbe75_testing_framework.StartupClientOnly.initClientOnly();
77+
minecraftbyexample.mbe75_testing_framework.StartupClientOnly.initClientOnly();
7878
minecraftbyexample.testingarea.StartupClientOnly.initClientOnly();
7979
}
8080

@@ -106,7 +106,7 @@ public void postInit()
106106
// minecraftbyexample.mbe40_hud_overlay.StartupClientOnly.postInitClientOnly();
107107
minecraftbyexample.mbe50_particle.StartupClientOnly.postInitClientOnly();
108108
minecraftbyexample.mbe60_network_messages.StartupClientOnly.postInitClientOnly();
109-
// minecraftbyexample.mbe75_testing_framework.StartupClientOnly.postInitClientOnly();
109+
minecraftbyexample.mbe75_testing_framework.StartupClientOnly.postInitClientOnly();
110110
minecraftbyexample.testingarea.StartupClientOnly.postInitClientOnly();
111111
}
112112

Diff for: src/main/java/minecraftbyexample/CommonProxy.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void preInit()
3737
// minecraftbyexample.mbe40_hud_overlay.StartupCommon.preInitCommon();
3838
minecraftbyexample.mbe50_particle.StartupCommon.preInitCommon();
3939
minecraftbyexample.mbe60_network_messages.StartupCommon.preInitCommon();
40-
// minecraftbyexample.mbe75_testing_framework.StartupCommon.preInitCommon();
40+
minecraftbyexample.mbe75_testing_framework.StartupCommon.preInitCommon();
4141
minecraftbyexample.testingarea.StartupCommon.preInitCommon();
4242
}
4343

@@ -69,7 +69,7 @@ public void init()
6969
// minecraftbyexample.mbe40_hud_overlay.StartupCommon.initCommon();
7070
minecraftbyexample.mbe50_particle.StartupCommon.initCommon();
7171
minecraftbyexample.mbe60_network_messages.StartupCommon.initCommon();
72-
// minecraftbyexample.mbe75_testing_framework.StartupCommon.initCommon();
72+
minecraftbyexample.mbe75_testing_framework.StartupCommon.initCommon();
7373
// minecraftbyexample.testingarea.StartupCommon.initCommon();
7474
}
7575

@@ -100,7 +100,7 @@ public void postInit()
100100
// minecraftbyexample.mbe40_hud_overlay.StartupCommon.postInitCommon();
101101
minecraftbyexample.mbe50_particle.StartupCommon.postInitCommon();
102102
minecraftbyexample.mbe60_network_messages.StartupCommon.postInitCommon();
103-
// minecraftbyexample.mbe75_testing_framework.StartupCommon.postInitCommon();
103+
minecraftbyexample.mbe75_testing_framework.StartupCommon.postInitCommon();
104104
minecraftbyexample.testingarea.StartupCommon.postInitCommon();
105105
}
106106

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package minecraftbyexample.mbe35_recipes;
2+
3+
import net.minecraft.client.renderer.block.model.IBakedModel;
4+
import net.minecraft.init.Items;
5+
import net.minecraft.item.ItemStack;
6+
import net.minecraftforge.client.event.ModelBakeEvent;
7+
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
8+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
9+
10+
/**
11+
* Created by TheGreyGhost on 13/11/2017.
12+
* Turns vanilla item (wheat) into a fuel. Can also be used for more-complicated calculations on whether the
13+
* item is a fuel or not, for example depending on the time of day, or whether it's raining or not, or similar.
14+
* For your own items, override Item.getItemBurnTime(ItemStack)
15+
*/
16+
public class FurnaceFuelBurnTimeEventHandler {
17+
public static final FurnaceFuelBurnTimeEventHandler instance = new FurnaceFuelBurnTimeEventHandler();
18+
19+
private FurnaceFuelBurnTimeEventHandler() {};
20+
21+
// Called whenever fuel is added into a furnace
22+
// Allows us to check whether the item added into the fuel slot is burnable. If it is Wheat, burn it.
23+
@SubscribeEvent
24+
public void onFurnaceFuelBurnTimeEvent(FurnaceFuelBurnTimeEvent event)
25+
{
26+
ItemStack fuel = event.getItemStack();
27+
final int BURN_TIME_SECONDS = 5;
28+
final int TICKS_PER_SECOND = 20;
29+
if (fuel.getItem() == Items.WHEAT) {
30+
event.setBurnTime(BURN_TIME_SECONDS * TICKS_PER_SECOND);
31+
}
32+
}
33+
}

Diff for: src/main/java/minecraftbyexample/mbe35_recipes/Notes.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ It will show you
99
5) how to add your own IRecipe class for complicated crafting logic
1010

1111
In earlier versions, recipes had to be added by code. now they can be added by json as well.
12-
This example shows both.
12+
This example shows both. For pictures of the recipes being added, see http://greyminecraftcoder.blogspot.com/2015/02/recipes.html
1313

14-
The pieces you need to understand are located in:
14+
15+
The pieces you need to understand for adding recipes by code are located in:
1516
StartupCommon
1617

17-
For json recipes:
18+
For json recipes, all you need is the json file in the right location:
1819
resources.assets.minecraftbyexample.recipes.mbe35_recipe_painting.json
19-
TODO **** NOT CURRENTLY WORKING ****
2020

21-
For pictures of the recipes being added, see http://greyminecraftcoder.blogspot.com/2015/02/recipes.html
21+
The parsing of recipes is done mostly in CraftingHelper - getIngredient, getItemStack
2222

2323
Useful discussion about recipes, especially the new json :
2424
http://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2810250-1-12-custom-recipes

Diff for: src/main/java/minecraftbyexample/mbe35_recipes/StartupCommon.java

+75-66
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
import net.minecraft.item.EnumDyeColor;
66
import net.minecraft.item.ItemStack;
77
import net.minecraft.item.crafting.IRecipe;
8+
import net.minecraft.item.crafting.Ingredient;
89
import net.minecraft.util.ResourceLocation;
10+
import net.minecraftforge.common.MinecraftForge;
11+
import net.minecraftforge.common.crafting.CraftingHelper;
912
import net.minecraftforge.fml.common.IFuelHandler;
1013
import net.minecraftforge.fml.common.registry.GameRegistry;
1114
import net.minecraftforge.oredict.OreDictionary;
1215
import net.minecraftforge.oredict.ShapedOreRecipe;
16+
import net.minecraftforge.registries.GameData;
17+
18+
import javax.annotation.Nonnull;
1319

1420
/**
1521
* User: The Grey Ghost
@@ -50,7 +56,7 @@ public static void initCommon()
5056
ResourceLocation optionalGroup = new ResourceLocation("");
5157

5258
// 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[]{
5460
" D ",
5561
"DED",
5662
" D ",
@@ -62,72 +68,85 @@ public static void initCommon()
6268

6369
// b) shaped recipe with metadata - cobblestone surrounded by red dye makes redstone
6470
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[]{
6672
"RRR",
6773
"RCR",
6874
"RRR",
6975
'C', Blocks.COBBLESTONE,
7076
'R', new ItemStack(Items.DYE, 1, RED_DYE_DAMAGE_VALUE)
7177
});
7278

79+
80+
ResourceLocation woodSwordGroup = new ResourceLocation("mbe35_woodswordgroup");
81+
7382
// c) shaped recipe for items which are damaged, or which have a metadata you want to ignore
7483
// 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[]{
7685
"CIC",
7786
"CWC",
7887
"CCC",
7988
'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
8191
'I', Items.IRON_INGOT
8292
});
8393

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.
131150

132151
//---------------- FURNACE RECIPES (smelting)
133152

@@ -140,25 +159,15 @@ public static void initCommon()
140159
GameRegistry.addSmelting(Items.CAKE, new ItemStack(Items.COAL, NUMBER_OF_ITEMS, CHARCOAL_METADATA_VALUE), CAKE_SMELT_XP);
141160

142161
// 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);
157166

158167
// ------------- Custom recipes
159168

160169
// 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);
162171
}
163172

164173
public static void postInitCommon()

0 commit comments

Comments
 (0)