[SOLVED] Help with: Armor with Infinite Durability and Diamond Level Protection

Discussion in 'Mod Development' started by Type1Ninja, Jun 13, 2015.

  1. Type1Ninja

    Type1Ninja New Member

    [SOLVED]
    Solution at bottom

    I'm just learning to code mods. It's hard. :p
    Don't question my design principles in this particular thread; there IS a way to balance Infinite Durability and Diamond protection. I promise. :)
    So, I'm trying to do this, and so far I'm using ISpecialArmor from Forge. I've managed to make "unblockable" damage unblockable, and I've managed to get Infinite Durability working, but while testing the armor stuff like mob attacks has no effect, ignoring the stuff I've (tried to) set with an ArmorMaterial. I *think* this is due to using ISpecialArmor, but I can't figure out what to do to make the damage reduction behave like regular armor.

    Here's my code so far, if it helps:
    package com.type1ninja.extrafeatures.item;

    import com.type1ninja.extrafeatures.reference.Reference;

    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemArmor;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.ItemArmor.ArmorMaterial;
    import net.minecraft.util.DamageSource;
    import net.minecraftforge.common.ISpecialArmor;
    import net.minecraftforge.common.util.EnumHelper;

    public class ItemBedrockiumArmor extends ItemArmor implements ISpecialArmor {

    //Armor Material
    //Bedrockium - never breaks, has protection just under diamond, slows player
    public static ArmorMaterial BEDROCKIUMARMOR = EnumHelper.addArmorMaterial("BEDROCKIUMARMOR", 1, new int[] {3, 8, 6, 3}, 9);
    public static float damagePercentReduction = 0.75f;

    //armorSetNumber is the nth armor set from this mod
    //armorPiece is which armor piece it is.
    public ItemBedrockiumArmor(String unlocalizedName, ArmorMaterial material, int armorSetNumber, int armorPiece) {
    super(BEDROCKIUMARMOR, armorSetNumber, armorPiece);
    this.setUnlocalizedName(unlocalizedName);
    }

    //So far, nothing here. Maybe increase fall damage? TODO
    @Override
    public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
    if(!source.isUnblockable()) {
    return new ArmorProperties(1, damagePercentReduction, Integer.MAX_VALUE);
    } else {
    return new ArmorProperties(0, 0, 0);
    }
    }

    //Make armor never break
    @Override
    public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
    //The first parameter is the damage. Passing zero makes the armor not take damage
    stack.damageItem(0, entity);
    }

    //Number of shields to display. Depends on armor piece. These are currently hardcoded...
    @Override
    public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
    return BEDROCKIUMARMOR.getDamageReductionAmount(slot);
    }

    @Override
    public String getUnlocalizedName() {
    return String.format("item.%s%s", Reference.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    //No difference, but we have to override all permutations (I think). This one is for
    //having an ItemStack as a parameter
    @Override
    public String getUnlocalizedName(ItemStack itemStack) {
    return String.format("item.%s%s", Reference.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    protected String getUnwrappedUnlocalizedName(String unlocalizedName) {
    return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
    }
    }

    Thanks in Advance,
    Type1Ninja

    (I've got another thread in this forum section about hiding recipes from NEI. Information there would be welcome as well. :))

    EDIT: It would seem that whatever the last value in the constructor of the ArmorProperties object returned in the getProperties method is affects the damage taken. Setting it to Integer.MAX_VALUE, as I have it here, results in invincibility, while setting it to, say, 2, results in 2 or 3 damage being taken from zombie hits.
     
    Last edited: Jun 14, 2015
  2. goldenapple

    goldenapple Well-Known Member Mod Developer

    I'm pretty sure that if you aren't doing anything with damage calculation you don't need ISpecialArmor. Just a regular ItemArmor should do just fine. If you want to make it unbreakable, though, you probably want to override the setDamage method instead.

    You can also override isDamageable, but I'm pretty sure it will be impossible to enchant it this way.
     
  3. Type1Ninja

    Type1Ninja New Member

    I managed to set it so that the armor attempts to damage itself for -10 points of damage each tick, which actually repairs it. :)
    This is fast enough that you never see the durability bar appear or go down, so it's effectively infinitely durable. :D
    Thanks for the suggestion, though. :)
     
    goldenapple likes this.

Share This Page