    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 (par7 != 1)
    018            {
    019                return false;
    020            }
    021            else
    022            {
    023                ++par5;
    024                BlockBed var11 = (BlockBed)Block.bed;
    025                int var12 = MathHelper.floor_double((double)(par2EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    026                byte var13 = 0;
    027                byte var14 = 0;
    028
    029                if (var12 == 0)
    030                {
    031                    var14 = 1;
    032                }
    033
    034                if (var12 == 1)
    035                {
    036                    var13 = -1;
    037                }
    038
    039                if (var12 == 2)
    040                {
    041                    var14 = -1;
    042                }
    043
    044                if (var12 == 3)
    045                {
    046                    var13 = 1;
    047                }
    048
    049                if (par2EntityPlayer.canPlayerEdit(par4, par5, par6) && par2EntityPlayer.canPlayerEdit(par4 + var13, par5, par6 + var14))
    050                {
    051                    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))
    052                    {
    053                        par3World.setBlockAndMetadataWithNotify(par4, par5, par6, var11.blockID, var12);
    054
    055                        if (par3World.getBlockId(par4, par5, par6) == var11.blockID)
    056                        {
    057                            par3World.setBlockAndMetadataWithNotify(par4 + var13, par5, par6 + var14, var11.blockID, var12 + 8);
    058                        }
    059
    060                        --par1ItemStack.stackSize;
    061                        return true;
    062                    }
    063                    else
    064                    {
    065                        return false;
    066                    }
    067                }
    068                else
    069                {
    070                    return false;
    071                }
    072            }
    073        }
    074    }