package com.vanamod.mod.armor;

import com.vanamod.mod.VanaMod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
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;

public class ItemVoidiumArmor extends ItemArmor {

    private String textureName;

    public ItemVoidiumArmor(ArmorMaterial material, int armorType, String name) {
        super(material, 0, armorType);
        this.textureName = name;
        this.setUnlocalizedName(name);
        this.setCreativeTab(VanaMod.vanaTab);
    }

    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
        // Effets selon la pièce portée
        if (this.armorType == 3) { // Boots
            player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 20, 1, true)); // Speed I (0 = niveau 1)
        }

        if (this.armorType == 1) { // Chestplate
            player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 20, 0, true)); // Strength I
        }

        // Vérifier si le set complet est porté
        if (hasFullSet(player)) {
            player.addPotionEffect(new PotionEffect(Potion.invisibility.id, 20, 0, true)); // Invisibilité I
        }
    }

    private boolean hasFullSet(EntityPlayer player) {
        ItemStack helmet = player.getCurrentArmor(3);
        ItemStack chestplate = player.getCurrentArmor(2);
        ItemStack leggings = player.getCurrentArmor(1);
        ItemStack boots = player.getCurrentArmor(0);

        return helmet != null && helmet.getItem() instanceof ItemVoidiumArmor &&
                chestplate != null && chestplate.getItem() instanceof ItemVoidiumArmor &&
                leggings != null && leggings.getItem() instanceof ItemVoidiumArmor &&
                boots != null && boots.getItem() instanceof ItemVoidiumArmor;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister iconRegister) {
        this.itemIcon = iconRegister.registerIcon("vanamod:" + this.textureName);
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
        if (slot == 2) { // Legs
            return "vanamod:textures/models/armor/voidium_layer_2.png";
        }
        return "vanamod:textures/models/armor/voidium_layer_1.png";
    }
}