package common.item;

import common.entity.npc.EntityNPC;
import common.init.Items;
import common.material.Material;
import common.model.Model;
import common.model.ModelProvider;
import common.util.BlockPos;
import common.util.HitPosition;
import common.world.World;

public class ItemGlassBottle extends Item
{
    public ItemGlassBottle()
    {
        this.setTab(CheatTab.tabTools);
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
    {
        HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

        if (movingobjectposition == null)
        {
            return itemStackIn;
        }
        else
        {
            if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
            {
                BlockPos blockpos = movingobjectposition.block;

                if (!World.isValidXZ(blockpos))
                {
                    return itemStackIn;
                }

                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.side), movingobjectposition.side, itemStackIn))
                {
                    return itemStackIn;
                }

                if (worldIn.getState(blockpos).getBlock().getMaterial() == Material.water)
                {
                    --itemStackIn.stackSize;
//                    playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);

                    if (itemStackIn.stackSize <= 0)
                    {
                        return new ItemStack(Items.potion);
                    }

                    if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potion)))
                    {
                        playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potion, 1, 0), false);
                    }
                }
            }

            return itemStackIn;
        }
    }

    public Model getModel(ModelProvider provider, String name, int meta) {
    	return provider.getModel(this.getTransform(), "potion_bottle_empty");
    }
}
