Minecraft Blogs

Minecraft Modding Tutorial - Basic Block

  • 4
  • 2
  • 3
avatar aSmartMiner
Level 32 : Artisan Modder
17
Psst, does the standard Minecraft blocks getting boring? Well, maybe you can

make your own mods!
Sounds pretty good, uh?

Made by aSmartMiner.

Hi guys,
In this tutorial you will learn how to make a whole new block for Minecraft 1.3.2.

It isn't that hard you know. And if you dont understand it, feel free to copy the codes and stuff.

What you need:
  • Minecraft
  • MCP - Minecraft Coders Pack http://www.minecraftwiki.net/wiki/Mcp (Installation insturctions on this site too)
  • Notepad++ or Eclipse (I use Notepad++, highly recomment and free!)
  • A unzip program like 7-zip or WinRAR
  • Modloader (Installing tutorial also on that site above)



Okay, time to get started now!

We going to make a simple block like stone, wool, wood etc. My block will be Poisoned Stone.
First, after you installed everything in the What you need list, get to the Minecraft Coders Pack folder.
If you've installed everything correctly, you see 11 folders. Go to src>minecraft>net>minecraft>src. Now you see a lot .java files. This is the heart of Minecraft, many lines of code are stored here.

To make a block, we have to make a .java file. Create a new text file and call it BlockPoisonedStone.java (Whats red marked is the name of the block I make, you can change it to a block you want to make.)
Then open that file with Notepad++.

Now its time to type!

First type in:


package net.minecraft.src;

import java.util.Random;



Thats the base of every block you will make.
Then add this to it:

public class BlockPoisonedStone extends Block

{
protected BlockPoisonedStone(int par1, int par2)
{
super(par1, par2, Material.rock);
}


To be honest, I dont know exactly what Protected BlockPoisonedStone(int par1, int par2) means, but you have to type it in ;)

Material.rock sais what kind of material your block is made. If you want that it acts like wood (So that it can burn) you have to change rock to wood. You can also choose glass, if you dont want that you can place rails, redstone and stuff on it.

Okay, lets go on:

public int quantityDropped(int par1, int par2)

{
return 1;
}


This sais howmany of the block will drop if you break it in Survival mode. If you change the 1 after Return, you will get that many you putted in there.

After that you type in:


public int idDropped(int par1, Random random, int par2)
{
return
}

}



Okay, idDropped sais what it dropped if you break it, BUT we havent made the block yet, so we dont put something after return yet.
We'll get to that later.

So, thats all for that file. Now we gonna create an other file, called mod_PStone.java (You MUST to put mod_ in front of the name in this file. To put after that I choosed PStone, shorter then PoisonedStone.)

Now we gonna edit that file. Type in:


package net.minecraft.src;

import java.util.Random;

public class mod_PStone extends BaseMod


Just the base of every mod_ file.
Going on:


{

public static final block PStone = (new BlockPoisonedStone(200, ModLoader.addOverride("/terrain.png","/MODFOLDER/PoisonedStone.png"))


Okay, so the number 200 is the block ID. I know you can use 200, and futher on to 256, or it will conflict with other mods.

Then we have a ModLoader function calles addOverride. That means setting a new texture to the block. I made this texture, you can copy it for yourself if you want. pstonepng
If you want to make your own, you can with a program called Paint.net, its totally free and very useful! The image dimensions should be 16x16 and saved as a .png file.

The /MODFOLDER is just an example of a folder you have to make, where you put in your textures. The name after that is the name of the file, you have to type in .png after that as well.

You have to put the /MODFOLDER with the texture in the minecraft.jar. You can find them to go the jars>bin folders.

Lets move on, now comes the customisation part: (Put it right after the previous line)


.setHardness(5.0F).setResistance(1.0F).setBlockName("PStone"));


The number in setHardness means how long it takes to break it, 5.0F is good for a stone kind.
The number in setResistance is the TNT explosion resistance, If you make it like 10.0F TNT cant explode it. 1.0F is a good number for this.
And setBlockName is the block name in the java files NOT IN THE GAME!

Okay, going on:


public void load()
{

ModLoader.registerBlock(PStone);

ModLoader.addName(PStone,"Poisoned Stone");


RegisterBlock meand that ModLoader and Minecraft knows that the block is real and here :)
AddName is to add a in-game name to it. Whats in the "" 's is the IN GAME MINECRAFT NAME.

Almost done, now adding a crafting recipe:


ModLoader.addShapelessRecipe(new ItemStack(mod_PStone.PStone, 1), new Object[]
{Block.stone, Item.slimeBall});

}


Tada, there is your (shapeless) recipe. For a poisoned stone block, you will need one stone block and a slimeball, and put them in a crafting table in every shape possible.

The new ItemStack is what you will get from that recipe, and the number in there is how much. (Dont make that number more than 64!)
{Block.stone, Item.slimeBall}); is the stuf that has to be added in the crafting table to make the block.

Adding the last things:


public String getVersion()
{
return "Poisoned Block Mod For 1.3.2";
}

}


DONE!
Oh, those last lines of code? Well, that sais which version your mod is, but you can put any text in the "" 's, it doesnt really matter, but those lines had to be there.

Now we have to add the last line to the BlockPoisonedStone.java, remember?
Put this after the last return of the file:


mod_PStone.PStone.blockID;


Easy right?

Here all the lines of code if you get an error or something, you can check your files:

BlockPoisonedStone.java


mod_PStone.java


Now you have made your own mod!
Coding isnt THAT hard, if you can copy it ;)

Good Luck making more mods!

Please leave a rating, diamond, comment and please subscribe to my PMC for more future tutorials.

Getting ERROR's? Ask it in the comments below.

When 5 diamonds OR 500 views: Pastebins for final codes to copy and paste.
When 10 comments: More tutorials will come.

By aSmartMiner.
CreditAll programs used in the tutorial.
Tags

1 Update Logs

Update #1 : 08/26/2012 11:02:30 amAug 26th, 2012

Added some sentences at the end of the post...

1
11/13/2012 6:16 pm
Level 52 : Grandmaster Baconator
Cybug
Awesome! Thanks!
1
08/27/2012 7:15 am
Level 15 : Journeyman Archer
zakky123
great tutorial. I shall try it now
1
08/26/2012 2:08 pm
Level 1 : New Architect
chocofudge2011
Please do more even if you don't get more comments.Great tutorial.
Planet Minecraft Logo

Website

© 2010 - 2020
www.planetminecraft.com

Welcome