Hey guys, Dan here! Welcome to my modloader modding tutorials! Before you go and talk about how there's a ton out there already, I want to stop you right there. Here's some problems with a LOT of existing tutorials: They don't explain the code, just tell you to copy, paste, and change. They also often do unnecessary things, leading you to develop bad Java habits. I want to show you guys the quickest and easiest way to get on to making mods!
Things that I'll be doing differently are I'll be explaining some of the code, so you start to grasp Java faster. How do you think I figured out some of these methods? You have to look around the rest of the modloader and Minecraft class files to figure some things out!
I'll also be providing the quickest and easiest way to do things, and making sure that I don't leave anything out. For example, in some tutorials, the person says "These swords can't be enchanted." Why not? They are swords in Minecraft! They need to be enchanted! So I went and figured out how to make my swords enchantable. I did that with some other tutorials too, so you'll probably be seeing some new stuff here that isn't exactly identical to anything you've seen before.
To-do List
Here's my to-do list of tutorials. Feel free to suggest things, and I'll throw them up here.
- Armor - Trees - Mobs (Currently broken in 1.3.2 modloader)
Tutorials
Let me just start off by saying that I'm assuming that you have used MCP to decompile Minecraft, and have eclipse up and running. I won't restate that, because that tutorial is the exact same everywhere. You can ask questions about it, but I'm not writing a huge thing about it right now.
Weapons
In this example we will be making a quick mod for a dirt sword. It will be crafted like a traditional sword, and have a custom strength and durability.
mod_dirtsword.java:
package net.minecraft.src;
public class mod_dirtsword extends BaseMod{
public static final Item dirtsword = new dirtsword(2000).setItemName("dirtsword");
public void load(){
ModLoader.addName(dirtsword,"Dirt Sword");
dirtsword.iconIndex = ModLoader.addOverride("/gui/items.png", "/dirtswordmod/dirtsword.png");
ModLoader.addRecipe(new ItemStack(dirtsword, 1), new Object[]{ "#", "#", "|", Character.valueOf('#'), Block.dirt, Character.valueOf('|'), Item.stick});
}
public String getVersion(){
return "1.3";
}
}
The first 2 lines are nothing to worry about, they are standard for any modloader mod.
public static final Item dirtsword . . . defines the sword initially. This is standard for adding any item. the (2000) after new dirtsword is the Item ID. Make sure that you don't use the same one for multiple items. Not any number is available, but around 2000 is fine.
ModLoader.addName is adding the actual in game name that you see when you move your mouse over the item. This should be a something like "Dirt Sword" and not "dirtsword".
dirtsword.iconIndex is overriding the texture. The texture will go in your minecraft.jar, and you can specify a path. Start with a /, and go from there. For example, mine is in a folder called dirtswordmod and it is a .png file called dirtsword. You must use png files.
Adding the recipe is the next part, and it's fairly simple. The first set of quotes represent the top 3 spaces in the crafting table, and the next quotes the middle, and the last the bottom. So something like this; "XXX", "X X", "XXX", with the character value of X being planks, would create a chest.
That's basically it for your mod_dirtsword class!
dirtsword.java:
package net.minecraft.src;
public class dirtsword extends ItemSword
{
protected int damage;
protected int enchantability;
public dirtsword(int par1){
super(par1, EnumToolMaterial.WOOD);
setMaxDamage(8);
damage = 12;
enchantability = 25;
}
public int getDamageVsEntity(Entity par1Entity)
{
return damage;
}
public int getItemEnchantability()
{
return enchantability;
}
}
Now, let me explain that, starting at the top.
public class dirtsword extends ItemSword
This bit classifies this class file as a sword, saying that it extends ItemSword, which is Minecraft's overall sword class. Change dirtsword to the name of your class file.
The protected ints you don't really need to worry about, there's nothing you should be changing about them.
This little bit actually defines the new sword. the EnumtoolMaterial would normally be changed to your material class, but using this way, we don't need one of those, instead, we define it's attributes in this class. So you can keep it as wood.
SetMaxDamage is the durability. With this sword, we could swing it at mobs or break blocks 8 times. Not a whole lot, considering diamond has around 1500 and even wood has around 60 (Use those as reference points).
Damage is the amount of... well... damage your sword does! This is counted in half hearts, so this dirt sword will do 6 hearts of damage on a non armoured player or mob. It's fairly strong for a basic sword. Diamond has 7 and wood & gold both have 4. So 3.5 and 2 hearts damage, respectively. Change the value to whatever you want.
Enchantability is a fairly complicated one, because the formula for calculating possible enchantments is quite complex itself. Basically though, higher values will make it possible to get better enchantments at lower levels. It won't change the minimum or maximum values for enchantments, but it will essentially make it easier to get better enchantments, or more enchantments. For example, diamond is 10, gold is 22, wood is 5, stone is 15, and iron is 14. So it's easiest to get good enchantments on gold tools and weapons, and hardest on wood. Choose this value wisely.
Those last two public ints you also don't have to worry about, it's just closing off everything and making sure it will work properly. The above things are the customizable options.
Biomes
Soon!
How To Ask Questions (READ):
Please use the below submission outline for questions about errors you have. If you don't, I might ignore you.
What is supposed to happen:
What actually happens:
Your mod_*** file (In spoilers):
Your other class file(s) that are likely causing the problem (In spoilers):
The error log (Once again, spoilers):
Anything else:
Terms
Use these tutorials, release the mods, and do whatever you want from there (staying within Minecraft's terms of course) but just don't, I repeat, DON'T, copy my tutorials, or release my example mods. Go make a sand sword, ok. Don't release a ****ing dirt sword mod the exact same as this one. Maybe it spawns dirt where you look, ok, cool. But NEVER copy my examples and release them, OR post them anywhere else. Feel free to make video versions of these tutorials however, that's fine with me.
Things that I'll be doing differently are I'll be explaining some of the code, so you start to grasp Java faster. How do you think I figured out some of these methods? You have to look around the rest of the modloader and Minecraft class files to figure some things out!
I'll also be providing the quickest and easiest way to do things, and making sure that I don't leave anything out. For example, in some tutorials, the person says "These swords can't be enchanted." Why not? They are swords in Minecraft! They need to be enchanted! So I went and figured out how to make my swords enchantable. I did that with some other tutorials too, so you'll probably be seeing some new stuff here that isn't exactly identical to anything you've seen before.
Here's my to-do list of tutorials. Feel free to suggest things, and I'll throw them up here.
- Armor
- Trees
- Mobs (Currently broken in 1.3.2 modloader)
Let me just start off by saying that I'm assuming that you have used MCP to decompile Minecraft, and have eclipse up and running. I won't restate that, because that tutorial is the exact same everywhere. You can ask questions about it, but I'm not writing a huge thing about it right now.
The first 2 lines are nothing to worry about, they are standard for any modloader mod.
public static final Item dirtsword . . . defines the sword initially. This is standard for adding any item. the (2000) after new dirtsword is the Item ID. Make sure that you don't use the same one for multiple items. Not any number is available, but around 2000 is fine.
ModLoader.addName is adding the actual in game name that you see when you move your mouse over the item. This should be a something like "Dirt Sword" and not "dirtsword".
dirtsword.iconIndex is overriding the texture. The texture will go in your minecraft.jar, and you can specify a path. Start with a /, and go from there. For example, mine is in a folder called dirtswordmod and it is a .png file called dirtsword. You must use png files.
Adding the recipe is the next part, and it's fairly simple. The first set of quotes represent the top 3 spaces in the crafting table, and the next quotes the middle, and the last the bottom. So something like this; "XXX", "X X", "XXX", with the character value of X being planks, would create a chest.
That's basically it for your mod_dirtsword class!
The protected ints you don't really need to worry about, there's nothing you should be changing about them.
This little bit actually defines the new sword. the EnumtoolMaterial would normally be changed to your material class, but using this way, we don't need one of those, instead, we define it's attributes in this class. So you can keep it as wood.
SetMaxDamage is the durability. With this sword, we could swing it at mobs or break blocks 8 times. Not a whole lot, considering diamond has around 1500 and even wood has around 60 (Use those as reference points).
Damage is the amount of... well... damage your sword does! This is counted in half hearts, so this dirt sword will do 6 hearts of damage on a non armoured player or mob. It's fairly strong for a basic sword. Diamond has 7 and wood & gold both have 4. So 3.5 and 2 hearts damage, respectively. Change the value to whatever you want.
Enchantability is a fairly complicated one, because the formula for calculating possible enchantments is quite complex itself. Basically though, higher values will make it possible to get better enchantments at lower levels. It won't change the minimum or maximum values for enchantments, but it will essentially make it easier to get better enchantments, or more enchantments. For example, diamond is 10, gold is 22, wood is 5, stone is 15, and iron is 14. So it's easiest to get good enchantments on gold tools and weapons, and hardest on wood. Choose this value wisely.
Those last two public ints you also don't have to worry about, it's just closing off everything and making sure it will work properly. The above things are the customizable options.
How To Ask Questions (READ):
Please use the below submission outline for questions about errors you have. If you don't, I might ignore you.