001 package net.minecraft.item; 002 003 import net.minecraft.block.Block; 004 import net.minecraft.block.BlockBed; 005 import net.minecraft.creativetab.CreativeTabs; 006 import net.minecraft.entity.player.EntityPlayer; 007 import net.minecraft.util.MathHelper; 008 import net.minecraft.world.World; 009 010 public 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 var11 = (BlockBed)Block.bed; 036 int var12 = MathHelper.floor_double((double)(par2EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; 037 byte var13 = 0; 038 byte var14 = 0; 039 040 if (var12 == 0) 041 { 042 var14 = 1; 043 } 044 045 if (var12 == 1) 046 { 047 var13 = -1; 048 } 049 050 if (var12 == 2) 051 { 052 var14 = -1; 053 } 054 055 if (var12 == 3) 056 { 057 var13 = 1; 058 } 059 060 if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4 + var13, par5, par6 + var14, par7, par1ItemStack)) 061 { 062 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)) 063 { 064 par3World.setBlockAndMetadataWithNotify(par4, par5, par6, var11.blockID, var12); 065 066 if (par3World.getBlockId(par4, par5, par6) == var11.blockID) 067 { 068 par3World.setBlockAndMetadataWithNotify(par4 + var13, par5, par6 + var14, var11.blockID, var12 + 8); 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 }