package baubles.common.items;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemRing extends Item implements IBauble
{
public ItemRing()
{
super();
this.setMaxStackSize(1);
this.setHasSubtypes(true);
this.setMaxDamage(0);
setCreativeTab(CreativeTabs.tabTools);
}
public IIcon icon;
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister ir) {
icon = ir.registerIcon("baubles:ring");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIconFromDamage(int meta) {
return icon;
}
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs,List par3List) {
par3List.add(new ItemStack(this,1,0));
}
@Override
public BaubleType getBaubleType(ItemStack itemstack) {
return BaubleType.RING;
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
if(!par2World.isRemote) {
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(par3EntityPlayer);
for(int i = 0; i < baubles.getSizeInventory(); i++)
if(baubles.getStackInSlot(i) == null && baubles.isItemValidForSlot(i, par1ItemStack)) {
baubles.setInventorySlotContents(i, par1ItemStack.copy());
if(!par3EntityPlayer.capabilities.isCreativeMode){
par3EntityPlayer.inventory.setInventorySlotContents(par3EntityPlayer.inventory.currentItem, null);
}
onEquipped(par1ItemStack, par3EntityPlayer);
break;
}
}
return par1ItemStack;
}
@Override
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
if (itemstack.getItemDamage()==0 && !player.isPotionActive(Potion.digSpeed)) {
player.addPotionEffect(new PotionEffect(Potion.digSpeed.id,40,0,true));
}
}
@Override
public boolean hasEffect(ItemStack par1ItemStack, int a) {
return true;
}
@Override
public EnumRarity getRarity(ItemStack par1ItemStack) {
return EnumRarity.rare;
}
@Override
public String getUnlocalizedName(ItemStack par1ItemStack)
{
return super.getUnlocalizedName() + "." + par1ItemStack.getItemDamage();
}
@Override
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
if (!player.worldObj.isRemote) {
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 1.3f);
}
}
@Override
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
}
@Override
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
@Override
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
}