Iv been asking a lot of questions on here lately. So Iv decided to give back a little by posting a tutorial on how to do fast simple blocks. This is my first tutorial so if I dont explain things clearly enough or if you have any questions please let me know
First lets start with the Proxy
//In your common/iproxy class you will need to add the addRenderRegister method this is the method we will be using to register our resource location. //The others are optional however they make things easier because you can just initialize these methods in your main mod class. Then any other //methods you need you can just put inside of these and they will already be initialize in your main class
public interface iproxy {
public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant);
public void preInit(FMLPreInitializationEvent event);
public void Init(FMLInitializationEvent event);
public void postInit(FMLPostInitializationEvent event);
}
////////////////////////////////////
//Now in your client proxy we need to call the addRenderRegister method but first we need to map our resource location by adding a map to the top of //our client proxy and watch out when you import make sure you import java.util.HashMap; and java.util.Map;. now we can add our method inside our //preInit.
public class ClientProxy implements iproxy {
private static final Map<itemstack, modelresourcelocation=""> MODEL_LOCATIONS = new HashMap<itemstack, modelresourcelocation="">();
@Override
public void preInit(FMLPreInitializationEvent event) {
// Custom Resource Location
for (Map.Entry<itemstack, modelresourcelocation=""> entry : MODEL_LOCATIONS.entrySet()) {
public void postInit(FMLPostInitializationEvent event) {
}
@Override
public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant) {
MODEL_LOCATIONS.put(stack, new ModelResourceLocation(location, variant));
}
}
Next we will need to create a itemblock class so we will have an item version of our blocks
//This is a very simple class that doesnt really need any explaining
public class itemblocks extends ItemBlock {
public itemblocks(Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(false);
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public S{tring getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName();
}
}
Now onto the only block you will need to make for basic blocks because this will work for as many blocks as you want
public class blockbase extends Block
//Just like any block we will start with the constructor however we are going to add a few things such as the unlocalizedname, registeryname, harvest //level, hardness, resistance, and your creative tab. For 99% of your blocks you will need to have these constructors. But what about this.register well //that composes the rest of the class.
public blockbase(Material material, String name, String Regname, float hardness, float resistance, String tool, int level) {
super(material);
setUnlocalizedName(name);
setRegistryName(Regname);
setHarvestLevel(tool, level);
setHardness(hardness);
setResistance(resistance);
this.setCreativeTab(DeadlyWorld.block);
this.register();
}
//This is where the itemblocks class comes in and all we are doing is telling this block to go to itemblocks and create a item based off of this block.
protected itemblocks getItemBlocks() {
return new itemblocks(this);
}
//Next we need to register our block, itemblock and give our item a registry name.
public static void registerBlock(Block block, itemblocks itemblock) {
//Now we nee to register our resource location using the method we created in our proxy. Note that we are using our registry name so when we create //our blockstates we will need to use the registry name as our blockstate name
//Final we get to our register this is where we take all of our registries and put them into one method this is very important because most of the others //call on other things which we cant have in our constructor.
private void register() {
registerBlock(this, this.getItemBlocks());
this.registerRendering();
}
}
//////////////////////////////////
//But what if we want our block to have more constructors well for that you will need to create more block classes but they are very easy to do just give //them your block name then inside we will extend our blockbase which will bring in every thing we did in that class and then all we need do is add our //constructors.
public class block_lamp extends blockbase{
public block_lamp(Material material, String name, String Regname, float hardness, float resistance, String tool, int level) {
Now we get to the fun part this is where we make all the blocks we want
////Make sure you initialize this class in your main mod class.
public class ModBlocks {
// First off we need to set our reference names this way when we add recipes or call on a certain block such as adding a block icon to our creative tabs. //These names are very important and you must have them for this method of creating blocks to work properly. It will always be
//public static Block yourblocknamehere; .
// Blocks
public static Block Plywood;
public static Block Basalt_Rough;
public static Block Basalt_Smooth;
public static Block Basalt_Brick;
public static Block Basalt_Carved;
public static Block Cracked_Dirt;
//Ores
public static Block OreTin;
/////////////////////////////
//And finally this is where we initialize our blocks for our basic blocks it will always be
//yourreferencename = new blockbase followed buy the constructors material, unlocalizedname, registeryname, hardness(must be a float), //resistance(must be a float), tool needed, and the harvest level(must be an int)
//and for your special blocks it will be
//yourreferencename = new specialblockname followed buy the constructors. Also if you dont want to specify a tool just enter null
public static void init() {
// Blocks
Plywood = new blockbase(Material.WOOD, "plywood", "block_plywood", 3.0f, 10.0f, "axe", 0);
Cracked_Dirt = new blockbase(Material.GROUND, "cracked_dirt", "block_cracked_dirt", 1.5f, 5.0f, "shovel", 0);
Basalt_Rough = new blockbase(Material.ROCK, "basalt_rough", "block_basalt_rough", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Smooth = new blockbase(Material.ROCK, "basalt_smooth", "block_basalt_smooth", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Brick = new blockbase(Material.ROCK, "basalt_brick", "block_basalt_brick", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Carved = new blockbase(Material.ROCK, "basalt_carved", "block_basalt_carved", 5.0f, 20.0f, "pickaxe", 1);
Lamp = new block_lamp(Material.GLASS, "lamp", "block_lamp", 1.0f, 3.0f, null, 0);
//Ores
OreTin = new blockbase(Material.ROCK, "tin", "ore_tin", 5.0f, 20.0f, "pickaxe", 2);
}
}
Other than your blockstates and textures thats all there is to creating blocks just give it a name then initialize it and you can have as many blocks as you want. But now that we have a way to create blocks so fast, we now have another problem we need a blockstate, a block model, a item model, and a texture. Well i cant help with the textures but i can help with the others. By using forge_marker we can get rid of the block model and the item model.
//This is a very simple method all you need to change is the texture location the method already takes in your textures folder so if you are just putting //all your textures in there it would be
//yourmodid:texturename,
//however if your like the rest of us you like to organize your textures it will be
//yourmodid:foldername/texturename, and yes this works with nested folders just make sure to separate your foldernames with a /
{
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"model": "minecraft:cube_all",
"textures": {"all": "deadlyworld:blocks/plywood"}
},
"variants": {
"normal": [{}],
"inventory": [{}]
}
}
And thats it I hope you like this method and if you think you can improve on it let me know.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIv been asking a lot of questions on here lately. So Iv decided to give back a little by posting a tutorial on how to do fast simple blocks. This is my first tutorial so if I dont explain things clearly enough or if you have any questions please let me know
First lets start with the Proxy
//In your common/iproxy class you will need to add the addRenderRegister method this is the method we will be using to register our resource location. //The others are optional however they make things easier because you can just initialize these methods in your main mod class. Then any other //methods you need you can just put inside of these and they will already be initialize in your main class
public interface iproxy {
public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant);
public void preInit(FMLPreInitializationEvent event);
public void Init(FMLInitializationEvent event);
public void postInit(FMLPostInitializationEvent event);
}
////////////////////////////////////
//Now in your client proxy we need to call the addRenderRegister method but first we need to map our resource location by adding a map to the top of //our client proxy and watch out when you import make sure you import java.util.HashMap; and java.util.Map;. now we can add our method inside our //preInit.
public class ClientProxy implements iproxy {
private static final Map<itemstack, modelresourcelocation=""> MODEL_LOCATIONS = new HashMap<itemstack, modelresourcelocation="">();
@Override
public void preInit(FMLPreInitializationEvent event) {
// Custom Resource Location
for (Map.Entry<itemstack, modelresourcelocation=""> entry : MODEL_LOCATIONS.entrySet()) {
ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(),
entry.getValue());
}
}
@Override
public void Init(FMLInitializationEvent event) {
}
@Override
public void postInit(FMLPostInitializationEvent event) {
}
@Override
public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant) {
MODEL_LOCATIONS.put(stack, new ModelResourceLocation(location, variant));
}
}
Next we will need to create a itemblock class so we will have an item version of our blocks
//This is a very simple class that doesnt really need any explaining
public class itemblocks extends ItemBlock {
public itemblocks(Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(false);
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public S{tring getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName();
}
}
Now onto the only block you will need to make for basic blocks because this will work for as many blocks as you want
//Just like any block we will start with the constructor however we are going to add a few things such as the unlocalizedname, registeryname, harvest //level, hardness, resistance, and your creative tab. For 99% of your blocks you will need to have these constructors. But what about this.register well //that composes the rest of the class.
public blockbase(Material material, String name, String Regname, float hardness, float resistance, String tool, int level) {
super(material);
setUnlocalizedName(name);
setRegistryName(Regname);
setHarvestLevel(tool, level);
setHardness(hardness);
setResistance(resistance);
this.setCreativeTab(DeadlyWorld.block);
this.register();
}
//This is where the itemblocks class comes in and all we are doing is telling this block to go to itemblocks and create a item based off of this block.
protected itemblocks getItemBlocks() {
return new itemblocks(this);
}
//Next we need to register our block, itemblock and give our item a registry name.
public static void registerBlock(Block block, itemblocks itemblock) {
GameRegistry.register(block);
GameRegistry.register(itemBlock);
itemblock.setRegistryName(block.getRegistryName());
}
//Now we nee to register our resource location using the method we created in our proxy. Note that we are using our registry name so when we create //our blockstates we will need to use the registry name as our blockstate name
protected void registerRendering() {
DeadlyWorld.proxy.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
}
//Final we get to our register this is where we take all of our registries and put them into one method this is very important because most of the others //call on other things which we cant have in our constructor.
private void register() {
registerBlock(this, this.getItemBlocks());
this.registerRendering();
}
}
//////////////////////////////////
//But what if we want our block to have more constructors well for that you will need to create more block classes but they are very easy to do just give //them your block name then inside we will extend our blockbase which will bring in every thing we did in that class and then all we need do is add our //constructors.
public class block_lamp extends blockbase{
public block_lamp(Material material, String name, String Regname, float hardness, float resistance, String tool, int level) {
super(material, name, Regname, hardness, resistance, tool, level);
setLightLevel(5);
setSoundType(SoundType.GLASS);
}
}
Now we get to the fun part this is where we make all the blocks we want
////Make sure you initialize this class in your main mod class.
public class ModBlocks {
// First off we need to set our reference names this way when we add recipes or call on a certain block such as adding a block icon to our creative tabs. //These names are very important and you must have them for this method of creating blocks to work properly. It will always be
//public static Block yourblocknamehere; .
// Blocks
public static Block Plywood;
public static Block Basalt_Rough;
public static Block Basalt_Smooth;
public static Block Basalt_Brick;
public static Block Basalt_Carved;
public static Block Cracked_Dirt;
//Ores
public static Block OreTin;
/////////////////////////////
//And finally this is where we initialize our blocks for our basic blocks it will always be
//yourreferencename = new blockbase followed buy the constructors material, unlocalizedname, registeryname, hardness(must be a float), //resistance(must be a float), tool needed, and the harvest level(must be an int)
//and for your special blocks it will be
//yourreferencename = new specialblockname followed buy the constructors. Also if you dont want to specify a tool just enter null
public static void init() {
// Blocks
Plywood = new blockbase(Material.WOOD, "plywood", "block_plywood", 3.0f, 10.0f, "axe", 0);
Cracked_Dirt = new blockbase(Material.GROUND, "cracked_dirt", "block_cracked_dirt", 1.5f, 5.0f, "shovel", 0);
Basalt_Rough = new blockbase(Material.ROCK, "basalt_rough", "block_basalt_rough", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Smooth = new blockbase(Material.ROCK, "basalt_smooth", "block_basalt_smooth", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Brick = new blockbase(Material.ROCK, "basalt_brick", "block_basalt_brick", 5.0f, 20.0f, "pickaxe", 1);
Basalt_Carved = new blockbase(Material.ROCK, "basalt_carved", "block_basalt_carved", 5.0f, 20.0f, "pickaxe", 1);
Lamp = new block_lamp(Material.GLASS, "lamp", "block_lamp", 1.0f, 3.0f, null, 0);
//Ores
OreTin = new blockbase(Material.ROCK, "tin", "ore_tin", 5.0f, 20.0f, "pickaxe", 2);
}
}
Other than your blockstates and textures thats all there is to creating blocks just give it a name then initialize it and you can have as many blocks as you want. But now that we have a way to create blocks so fast, we now have another problem we need a blockstate, a block model, a item model, and a texture. Well i cant help with the textures but i can help with the others. By using forge_marker we can get rid of the block model and the item model.
//This is a very simple method all you need to change is the texture location the method already takes in your textures folder so if you are just putting //all your textures in there it would be
//yourmodid:texturename,
//however if your like the rest of us you like to organize your textures it will be
//yourmodid:foldername/texturename, and yes this works with nested folders just make sure to separate your foldernames with a /
{
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"model": "minecraft:cube_all",
"textures": {"all": "deadlyworld:blocks/plywood"}
},
"variants": {
"normal": [{}],
"inventory": [{}]
}
}
And thats it I hope you like this method and if you think you can improve on it let me know.