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