    001    package net.minecraft.src;
    002
    003    public class ItemBed extends Item
    004    {
    005        public ItemBed(int par1)
    006        {
    007            super(par1);
    008            this.setCreativeTab(CreativeTabs.tabDecorations);
    009        }
    010
    011        /**
    012         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    013         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    014         */
    015        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    016        {
    017            if (par3World.isRemote)
    018            {
    019                return true;
    020            }
    021            else if (par7 != 1)
    022            {
    023                return false;
    024            }
    025            else
    026            {
    027                ++par5;
    028                BlockBed var11 = (BlockBed)Block.bed;
    029                int var12 = MathHelper.floor_double((double)(par2EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    030                byte var13 = 0;
    031                byte var14 = 0;
    032
    033                if (var12 == 0)
    034                {
    035                    var14 = 1;
    036                }
    037
    038                if (var12 == 1)
    039                {
    040                    var13 = -1;
    041                }
    042
    043                if (var12 == 2)
    044                {
    045                    var14 = -1;
    046                }
    047
    048                if (var12 == 3)
    049                {
    050                    var13 = 1;
    051                }
    052
    053                if (par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.func_82247_a(par4 + var13, par5, par6 + var14, par7, par1ItemStack))
    054                {
    055                    if (par3World.isAirBlock(par4, par5, par6) && par3World.isAirBlock(par4 + var13, par5, par6 + var14) && par3World.doesBlockHaveSolidTopSurface(par4, par5 - 1, par6) && par3World.doesBlockHaveSolidTopSurface(par4 + var13, par5 - 1, par6 + var14))
    056                    {
    057                        par3World.setBlockAndMetadataWithNotify(par4, par5, par6, var11.blockID, var12);
    058
    059                        if (par3World.getBlockId(par4, par5, par6) == var11.blockID)
    060                        {
    061                            par3World.setBlockAndMetadataWithNotify(par4 + var13, par5, par6 + var14, var11.blockID, var12 + 8);
    062                        }
    063
    064                        --par1ItemStack.stackSize;
    065                        return true;
    066                    }
    067                    else
    068                    {
    069                        return false;
    070                    }
    071                }
    072                else
    073                {
    074                    return false;
    075                }
    076            }
    077        }
    078    }