    001package net.minecraft.item;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.block.material.Material;
    006import net.minecraft.client.renderer.texture.IconRegister;
    007import net.minecraft.creativetab.CreativeTabs;
    008import net.minecraft.entity.player.EntityPlayer;
    009import net.minecraft.util.EnumMovingObjectType;
    010import net.minecraft.util.Icon;
    011import net.minecraft.util.MovingObjectPosition;
    012import net.minecraft.world.World;
    013
    014public class ItemGlassBottle extends Item
    015{
    016    public ItemGlassBottle(int par1)
    017    {
    018        super(par1);
    019        this.setCreativeTab(CreativeTabs.tabBrewing);
    020    }
    021
    022    @SideOnly(Side.CLIENT)
    023
    024    /**
    025     * Gets an icon index based on an item's damage value
    026     */
    027    public Icon getIconFromDamage(int par1)
    028    {
    029        return Item.potion.getIconFromDamage(0);
    030    }
    031
    032    /**
    033     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    034     */
    035    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    036    {
    037        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);
    038
    039        if (movingobjectposition == null)
    040        {
    041            return par1ItemStack;
    042        }
    043        else
    044        {
    045            if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
    046            {
    047                int i = movingobjectposition.blockX;
    048                int j = movingobjectposition.blockY;
    049                int k = movingobjectposition.blockZ;
    050
    051                if (!par2World.canMineBlock(par3EntityPlayer, i, j, k))
    052                {
    053                    return par1ItemStack;
    054                }
    055
    056                if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
    057                {
    058                    return par1ItemStack;
    059                }
    060
    061                if (par2World.getBlockMaterial(i, j, k) == Material.water)
    062                {
    063                    --par1ItemStack.stackSize;
    064
    065                    if (par1ItemStack.stackSize <= 0)
    066                    {
    067                        return new ItemStack(Item.potion);
    068                    }
    069
    070                    if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.potion)))
    071                    {
    072                        par3EntityPlayer.dropPlayerItem(new ItemStack(Item.potion.itemID, 1, 0));
    073                    }
    074                }
    075            }
    076
    077            return par1ItemStack;
    078        }
    079    }
    080
    081    @SideOnly(Side.CLIENT)
    082    public void registerIcons(IconRegister par1IconRegister) {}
    083}