Hello, I am going to show you how to make a set of tools with ModLoader. The tools should be enchantable (with a few exceptions) and do not edit any base classes.
I am going to assume you have already set up MCP and get right to the coding.
#1 Swords
First you make your mod_ file (I will be using Redstone for the example
package net.minecraft.src;
public class mod_RedstoneTools extends BaseMod{
public static final Item swordRedstone = new ItemRedstoneSword(2100).setItemName("swordRedstone");
public void load(){
ModLoader.addName(swordRedstone,"Redstone Sword");
swordRedstone.iconIndex = ModLoader.addOverride("/gui/items.png", "/RedstoneTools/RedstoneSword.png");
ModLoader.addRecipe(new ItemStack(swordRedstone, 1), new Object[]{
"#",
"#",
"|",
Character.valueOf('#'), Item.redstone, Character.valueOf('|'), Item.stick});
}
public String getVersion(){
return "1";
}
}
And now for ItemRedstoneSword.java. The tools material (Which is normally used to calculate the stats) doesnt matter because we will be replacing them with our own values. I have added a list of the values used by all of the other tools for reference. With the durability (setMaxDamage), you add 1 for the actual durability as a tool breaks when its health falls below 0, not at it.
package net.minecraft.src;
public class ItemRedstoneSword extends ItemSword
{
protected int damage;
protected int enchantability;
public ItemRedstoneSword(int par1){
super(par1, EnumToolMaterial.WOOD);
setMaxDamage(119); //Wood = 59, Stone = 131, Iron = 250, Diamond = 1561, Gold = 32 (+1 for effective efficiency, 0 for unbreakable)
damage = 5; //Wood/Gold = 4, Stone = 5, Iron = 6, Diamond = 7 (How much damage versus mobs)
enchantability = 20; //Wood = 15, Stone = 5, Iron = 14, Diamond = 10, Gold = 22 (How enchantable it is)
}
public int getDamageVsEntity(Entity par1Entity)
{
return damage;
}
public int getItemEnchantability()
{
return enchantability;
}
}
The EnumToolMaterial does not matter as it only handles the durability, damage, efficiency, harvest level and enchantability, all of which are either only used by tools or are set by you.
More Advanced
Rarity
Rarity is the coloring of the items name. It is very easy to add to any item (although I dont know how to add it to blocks)
You can add this code to any item to make the items name more noticable
NOTE: I am unsure of the effects on enchanting using this may have
Enchanting issues
As I mentioned before, there are some exceptions with enchanting. Namely, setting an items max durability to 0 or less renders the item unenchantable.
To fix, make the items durability any number (even 1) and put this code in the tools file.
public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
{
par1ItemStack.damageItem(0, par3EntityLiving);
return true;
}
public boolean onBlockDestroyed(ItemStack par1ItemStack, int par2, int par3, int par4, int par5, EntityLiving par6EntityLiving)
{
par1ItemStack.damageItem(0, par6EntityLiving);
return true;
}
Pre-Enchanted Items
This is where players always get a certain enchantment when they make the tool. This only applies to the crafting bench, so players in Creative mode will get an unenchanted item if they get it from the creative window.
Put this in your mod_(whatever) file, not in load() or getVersion()
public void takenFromCrafting(EntityPlayer entityPlayer, ItemStack itemStack, IInventory iinventory){
if(itemStack.itemID == YourItemHere.shiftedIndex){
itemStack.addEnchantment(Enchantment.EnchantmentHere, 3); //Enchantments can be found in Enchantment.java
}
}
NOTE: Using this makes items unable to be enchanted at a table
Bonus damage against certain mobs
In this part of the tutorial I will show you how to make a sword or tool deal more/less damage against mobs
First, open your sword/tools file and go to the line 'getDamageVsEntity' and change it to this:
public int getDamageVsEntity(Entity par1Entity)
{
if(par1Entity instanceof EntityCreeper)
return 20;
return 1;
}
This makes the item do 20 damage - 10 hearts - to creepers and 1 to everything else.
The line
if(par1Entity instanceof EntityCreeper)
checks if the Entity you hit is an EntityCreeper.
NOTE: You can use any mob (passive or neutral, even players count) and even have different damages for different mobs by repeating lines 3 and 4 (Be sure to place them before what is currently line 5)
Thats all for now, I will await feedback and experiment with the rest of the tools!
Really really good tutorials, you should add other tools such as, bow, enchanting tools, and effects. You should also add MCP because some people just jump to here, that's what I did.
****ing phenomenal! I can't find anywhere else that includes enchanting, or even the rarity OR enchantment upon crafting! I never even thought of that! That's ****ing awesoem!
I am going to assume you have already set up MCP and get right to the coding.
#1 Swords
And now for ItemRedstoneSword.java. The tools material (Which is normally used to calculate the stats) doesnt matter because we will be replacing them with our own values. I have added a list of the values used by all of the other tools for reference. With the durability (setMaxDamage), you add 1 for the actual durability as a tool breaks when its health falls below 0, not at it.
The EnumToolMaterial does not matter as it only handles the durability, damage, efficiency, harvest level and enchantability, all of which are either only used by tools or are set by you.
More Advanced
You can add this code to any item to make the items name more noticable
NOTE: I am unsure of the effects on enchanting using this may have
Enchanting issues
To fix, make the items durability any number (even 1) and put this code in the tools file.
Pre-Enchanted Items
Put this in your mod_(whatever) file, not in load() or getVersion()
NOTE: Using this makes items unable to be enchanted at a table
Bonus damage against certain mobs
First, open your sword/tools file and go to the line 'getDamageVsEntity' and change it to this:
This makes the item do 20 damage - 10 hearts - to creepers and 1 to everything else.
The line checks if the Entity you hit is an EntityCreeper.
NOTE: You can use any mob (passive or neutral, even players count) and even have different damages for different mobs by repeating lines 3 and 4 (Be sure to place them before what is currently line 5)
Thats all for now, I will await feedback and experiment with the rest of the tools!
Enchanting added!
System.out.err("Nope");
at the moment im making this mod and i made my own enum material files like suggested in a load of other tutorials
Farewell everyone o/
Pie is delicious. That is all.