Minecraft Forge: Tips On Modding Armor

Introduction


Armor is basically just items that can be placed in reserved inventory slots. So most of the tips related to items applies to armor. I'll assume you're familiar with how to make items generally, including registering them, creating models and textures, etc.

I recommend the following: BedrockMiner's Custom Armor Tutorial

Key Point: Many of the armor properties such as maxDamage ("durability"), damageReduceAmount, enchantability and toughness are actually set by the armor material. So you will generally want to create a custom material for any custom armor.

Making Armor Better Than Diamond


Thanks to Draco18s for this tip.

In versions prior to 1.10.2 you could not really make armor that was better than diamond without serious re-coding of the attack system. However, 1.10.2 introduced an "armor toughness" property which allow you to make superior armor. For toughness, diamond armor has a rating of 2 and all other types are 0. The toughness is used in the damage taken calculation like this:

damageTaken = damageDealt*(1-min(20, max(defensePoints/5, defensePoints-damageDealt/(2+toughness/4)))/25)

The toughness is technically a property of a material, which is accessed by the Material.setToughness() and getToughness() methods. So to create a tougher armor you should create a custom armor material and then assign that to your armor when you construct it.

Use The ISpecialArmor Interface For Custom Armor


When creating custom armor, it is advised to make your armor class also implement the ISpecialArmor interface. This interface gives more control over how damage and durability work on the armor. There are three methods provided by the interface: damageArmor()getArmorDisplay(), and getProperties(). There is Javadoc comments that help explain the use of each method.

How To Detect If Armor Or Armor Set Is Being Worn By Player


To have continuous checking you can @Override your custom ItemArmor's onArmorTick() method. That method passes the EntityPlayer as a parameter, so you can use that and use the EntityPlayer methods for checking the armor slots.

Prior to 1.10.2, you could check armor with the EntityPlayer#getCurrentArmor() method. With the getCurrentArmor() method you pass in an int parameter that represents the armor slot (0 for boots, 1 for leggings, 2 for chestplate, and 3 for helmet).

In 1.10.2, it changes so you could use the EntityPlayer#getItemStackFromSlot() method and pass the EntityEquipmentSlot enum as parameter. So for example you could check the boots by getItemStackFromSlot(EntityEquipmentSlot.feet).

So with that, you can check if your custom armor is in a given slot. To check if a complete armor set is worn, you'd just logically AND the tests for your armor in each slot.

Adding NBT Data To Armor

NBT data allows you to make an ItemStack unique. For example, it could be used store a special name for the armor, or it could store how much energy the armor has left, etc. Since, armor is just an item, then you can use NBT just like I describe in my tips on items.

Setting Up Armor Models And Textures


This topic is already well covered by other tutorials. Check out TheGreyGhost's Item Rendering Tutorial.

Making A Custom Armor Effect


Thanks to coolAlias for this tip.

For a continuous effect, there is a built-in method called onArmorTickUpdate() which runs every tick for every armor slot, passing the armor in as an Item.  You can just check for your item then do desired code.

Sometimes you'll want armor to do a more "one time" effect.  For example, I've made Boots of Safe Falling that eliminate fall damage. In that case I did not use the armor tick method, but instead just checked for them in a LivingFallEvent handler.

If you need to check whether armor is equipped you can use the EntityPlayer's getCurrentArmor(slotNum).getItem() method.  For this method, the slot numbering is 0 for boots, 1 for leggings, 2 for chestplate, 3 for helmet.

2 comments:

  1. Do you know how I could change the armor model AFTER it's already been initialized and registered and such? I want to have an initial armor model, and then have that be changed upon execution of a command. I want it to be changed by something like /changeArmor "armorName", like diamond or emerald. I have like 100 different armor textures that I want to useable, and I don't want to have to add 100 different sets of armor Items.

    ReplyDelete
    Replies
    1. I actually figured it but. This is a great tutorial and really helpful by the way.

      Delete