package rewbot.minecraft.tutorial.items.armor;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import rewbot.minecraft.tutorial.MmaGlobal;
import rewbot.minecraft.tutorial.items.AdventureItems;

/**
 * Created by ashepherd on 5/26/2016.
 */
public class MmaVanadiumArmor extends ItemArmor {

    public MmaVanadiumArmor(String unlocalizedName, ArmorMaterial material, int renderIndex, int armorType) {
        super(material, renderIndex, armorType);

        setUnlocalizedName(unlocalizedName);
        setCreativeTab(MmaGlobal.mmaCreativeTab);
    }

    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
        if (itemStack.getItem() == AdventureItems.vanadiumHelmet) {
            effectPlayer(player, Potion.nightVision, 0);
        }
        if (itemStack.getItem() == AdventureItems.vanadiumChestplate) {
            effectPlayer(player, Potion.absorption, 1);
        }
        if (itemStack.getItem() == AdventureItems.vanadiumLeggings) {
            effectPlayer(player, Potion.moveSpeed, 1);
        }
        if (itemStack.getItem() == AdventureItems.vanadiumBoots) {
            effectPlayer(player, Potion.jump, 2);
        }

        if (isWearingFullSet(player, AdventureItems.vanadiumHelmet, AdventureItems.vanadiumChestplate, AdventureItems.vanadiumLeggings, AdventureItems.vanadiumBoots)) {
            effectPlayer(player, Potion.regeneration, 1);
        }

        //TODO: How can I add the custom items directly to survival inventory?
        //player.inventory.addItemStackToInventory(new ItemStack(AdventureItems.copperIngot));
    }

    private boolean isWearingFullSet(EntityPlayer player, Item helmet, Item chestplate, Item leggings, Item boots) {
        return (player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(3).getItem() == helmet)
                && (player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(2).getItem() == chestplate)
                && (player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(1).getItem() == leggings)
                && (player.inventory.armorItemInSlot(3) != null && player.inventory.armorItemInSlot(0).getItem() == boots);
    }

    private void effectPlayer(EntityPlayer player, Potion potion, int amplifier) {
        if (player.getActivePotionEffect(potion) == null || player.getActivePotionEffect(potion).getDuration() <= 1) {
            player.addPotionEffect(new PotionEffect(potion.id, 159, amplifier, true, true));
        }
    }
}

@@ -2035,17 +2035,17 @@
 mInSlot(
-0
+3
 ) != nul
@@ -2160,17 +2160,17 @@
 mInSlot(
-1
+2
 ) != nul
@@ -2281,33 +2281,33 @@
 armorItemInSlot(
-2
+1
 ) != null && pla
@@ -2408,33 +2408,33 @@
 armorItemInSlot(
-3
+0
 ) != null && pla

Fix NullPointerException on armorItemSlot mismatch