Custom Red Diamond Tool Material

Next it will be necessary to create a new tool material to be able to create our custom tools and weapons.  The tool material is used only to create new tools and the default set is defined in net.minecraft.item.EnumToolMaterial enumeration.  However, Forge provides the ability to dynamically add to the EnumToolMaterial by using the net.minecraftforge.common.EnumHelper.addToolMaterial() static method. 

However, before explaining how to add the custom material, it is important to explain the difference between tool materials and block materials.  Tool materials are kept in the EnumToolMaterial enumeration, are a very small set of enumeration entries, and are only used for tools.  Whereas the block materials are a completely separate Java class used to model things like: grass, rock, water, etc…, and there are a lot of these block material objects available.  The material objects are then associated with Block objects.  It is very important to not confuse the two different types of materials. 

The insertion of the new tool material into the enumeration is only only line of code.  However, there is a long list of parameters which are used to configure the tool material, and it is the parameters that make it seem daunting.  However, with a little explanation, they really are not that difficult to understand.  The parameters are as follows:

  1. Name – name of your material, needs to be uppercase, continuous characters with no spaces
  2. Harvest Level – level of material that can harvest it (defined as 0 = WOOD/GOLD, 1 = STONE, 2 = IRON, 3 = DIAMOND)
  3. Max Uses – number of uses this material allows(e.g.: WOOD = 59, STONE = 131, IRON = 250, DIAMOND = 1561, GOLD = 32)
  4. Efficiency – strength when used on blocks (e.g.: WOOD = 2.0F, STONE = 4.0F, IRON = 4.0F, DIAMOND = 8.0F, GOLD = 12.0F). 
  5. Damage – additional damage factor done to entities (e.g.: WOOD = 0.0F, STONE = 1.0F, IRON = 2.0F, DIAMOND = 3.0F, GOLD = 0.0F).  This will be added to default damage done by whatever weapon, e.g.: sword = 4.0F.  Remember, this needs to be double the number of hearts of damage, so to do 10 hearts of damage would need at least 20. 
  6. Enchantability – natural enchantability factor of the material (e.g.: WOOD = 15, STONE = 5, IRON = 14, DIAMOND = 10, GOLD = 22).  A higher value means it is more enchantable. 

In the RedDiamondMod class, it will be necessary to include the proper imports and then define the new material in the class. 

import net.minecraft.item.EnumToolMaterial;
import net.minecraftforge.common.EnumHelper;

public static EnumToolMaterial materialRedDiamond = 
        EnumHelper.addToolMaterial(
             "REDDIAMOND", 3, 2000, 15.0F, 40.0F, 50);

 

This will create a new REDDIAMOND tool material, that can only be harvested with a diamond pick, will have 2000 possible uses, will an efficiency of 15.0 (which is really good), will cause 20 hearts of damage (which can kill an Enderman in one strike), and has enchantability starting at 50.