    001package net.minecraft.item;
    002
    003import net.minecraft.block.Block;
    004import net.minecraft.entity.Entity;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.world.World;
    007
    008public class ItemReed extends Item
    009{
    010    /** The ID of the block the reed will spawn when used from inventory bar. */
    011    private int spawnID;
    012
    013    public ItemReed(int par1, Block par2Block)
    014    {
    015        super(par1);
    016        this.spawnID = par2Block.blockID;
    017    }
    018
    019    /**
    020     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    021     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    022     */
    023    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    024    {
    025        int i1 = par3World.getBlockId(par4, par5, par6);
    026
    027        if (i1 == Block.snow.blockID && (par3World.getBlockMetadata(par4, par5, par6) & 7) < 1)
    028        {
    029            par7 = 1;
    030        }
    031        else if (i1 != Block.vine.blockID && i1 != Block.tallGrass.blockID && i1 != Block.deadBush.blockID)
    032        {
    033            if (par7 == 0)
    034            {
    035                --par5;
    036            }
    037
    038            if (par7 == 1)
    039            {
    040                ++par5;
    041            }
    042
    043            if (par7 == 2)
    044            {
    045                --par6;
    046            }
    047
    048            if (par7 == 3)
    049            {
    050                ++par6;
    051            }
    052
    053            if (par7 == 4)
    054            {
    055                --par4;
    056            }
    057
    058            if (par7 == 5)
    059            {
    060                ++par4;
    061            }
    062        }
    063
    064        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
    065        {
    066            return false;
    067        }
    068        else if (par1ItemStack.stackSize == 0)
    069        {
    070            return false;
    071        }
    072        else
    073        {
    074            if (par3World.canPlaceEntityOnSide(this.spawnID, par4, par5, par6, false, par7, (Entity)null, par1ItemStack))
    075            {
    076                Block block = Block.blocksList[this.spawnID];
    077                int j1 = block.onBlockPlaced(par3World, par4, par5, par6, par7, par8, par9, par10, 0);
    078
    079                if (par3World.setBlock(par4, par5, par6, this.spawnID, j1, 3))
    080                {
    081                    if (par3World.getBlockId(par4, par5, par6) == this.spawnID)
    082                    {
    083                        Block.blocksList[this.spawnID].onBlockPlacedBy(par3World, par4, par5, par6, par2EntityPlayer, par1ItemStack);
    084                        Block.blocksList[this.spawnID].onPostBlockPlaced(par3World, par4, par5, par6, j1);
    085                    }
    086
    087                    par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
    088                    --par1ItemStack.stackSize;
    089                }
    090            }
    091
    092            return true;
    093        }
    094    }
    095}