Working sample code for the basic concepts in Minecraft and Forge.
Working sample code for the basic concepts in Minecraft and Forge.
The purpose of MinecraftByExample is to give simple working examples of the important concepts in Minecraft and Forge. If you're anything like me, a good code example is worth several screens of waffling explanation, and can very quickly explain the key concepts. I also find it much easier to adapt and debug something that already works, than to have to synthesize something from scratch and spend hours trying to discover the missing bit of information I didn't know about.
I've tried to keep the code simple and obvious and to resist the urge to be clever. The examples might not be the most efficient or succinct implementation, I've deliberately left the optimization to you.
Each example is split up to be totally independent of all the others. The only part of the code which is common to more than one example is the MinecraftByExample class.
If you want more information and explanatory text about the concepts, the following links might be useful:
If you are updating from previous forge versions, you will probably find this link and this link very helpful. For better or for worse, MCP decided to rename a very large number of classes (eg all Blocks Blockxxx --> xxxxBlock, etc) so this might save you a stack of time. If you use IntelliJ, you might find these xml mapping files useful too
See here for pictures of what each example looks like in-game.
MBE01 - a simple cube
MBE02 - a block with a more complicated shape
MBE03 - two types of blocks which vary their appearance / shape:
a block (coloured signpost) with multiple variants- four colours, can be placed facing in four directions
a block (3D Web) with multiple parts (multipart) similar to a vanilla fence.
MBE04 - dynamically created block models
a camouflage ("secret door") block which dynamically changes its appearance to match adjacent blocks - uses IBlockModel.getQuads(), ModelBakeEvent, IForgeBakedModel and IModelData
an "altimeter" block which shows the block altitude (y coordinate) on the side in digital display - as camouflage block but uses programmatic generation of quads
MBE05 - multilayer block (lantern block with transparent glass) with animated flame texture
MBE06 - several different types of block which use redstone
MBE08 - how to add a creative tab for organising your custom blocks / items
You can browse directly in GitHub, or alternatively, download it as a zip and browse it locally.
If you want to install it and compile it, the basic steps for beginners are:
Head over here if this didn't make sense to you (check comments for differences with latest versions of IDEA).
No open issues yet, or sync has not completed.