Basic Block-1.9

From McJty Modding
Jump to: navigation, search

In this document you learn how to do your first basic block. i.e. the simplest kind of block you can have: just a block that looks the same on all sides and does not have any other information. Note that this tutorial requires at least version 11.15.0.1673 of Forge to be able to use the new registry name feature.

In the constructor of our block we have to register it and in many cases you also have to register the corresponding item (ItemBlock) so that you can actually have the object in your inventory.

public class FirstBlock extends Block {
    public FirstBlock() {
        super(Material.ROCK);
        setUnlocalizedName(ModTut.MODID + ".firstblock");     // Used for localization (en_US.lang)
        setRegistryName("firstblock");        // The unique name (within your mod) that identifies this block
        GameRegistry.register(this);
        GameRegistry.register(new ItemBlock(this), getRegistryName());
    }
}

Then it is recommended you have some centralized place where you initialize all your blocks. It is common to call this ModBlocks. The static init in this class should be called from within CommonProxy.preInit:

public class ModBlocks {

    public static FirstBlock firstBlock;

    public static void init() {
        firstBlock = new FirstBlock();
    }
}

This block will look very ugly (default checkerboard model) and do nothing but it is the minimal example.