123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package me.km.items;
- import me.km.blocks.ModBlocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockBed;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumActionResult;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- public class ItemBed extends ItemBase
- {
- public ItemBed(String name, String local)
- {
- super(name, local);
- super.setCreativeTab(CreativeTabs.DECORATIONS);
- }
- @Override
- public EnumActionResult onItemUse(EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
- {
- if(w.isRemote)
- {
- return EnumActionResult.SUCCESS;
- }
- else if(facing != EnumFacing.UP)
- {
- return EnumActionResult.FAIL;
- }
- else
- {
- IBlockState iblockstate = w.getBlockState(pos);
- Block block = iblockstate.getBlock();
- boolean flag = block.isReplaceable(w, pos);
- if (!flag)
- {
- pos = pos.up();
- }
- int i = MathHelper.floor((double)(p.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- EnumFacing enumfacing = EnumFacing.getHorizontal(i);
- BlockPos blockpos = pos.offset(enumfacing);
- ItemStack itemstack = p.getHeldItem(hand);
- if (p.canPlayerEdit(pos, facing, itemstack) && p.canPlayerEdit(blockpos, facing, itemstack))
- {
- IBlockState iblockstate1 = w.getBlockState(blockpos);
- boolean flag1 = iblockstate1.getBlock().isReplaceable(w, blockpos);
- boolean flag2 = flag || w.isAirBlock(pos);
- boolean flag3 = flag1 || w.isAirBlock(blockpos);
- if (flag2 && flag3 && w.getBlockState(pos.down()).isTopSolid() && w.getBlockState(blockpos.down()).isTopSolid())
- {
- IBlockState iblockstate2 = ModBlocks.realHayBed.getDefaultState().withProperty(BlockBed.OCCUPIED, false).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
- w.setBlockState(pos, iblockstate2, 10);
- w.setBlockState(blockpos, iblockstate2.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD), 10);
- w.notifyNeighborsRespectDebug(pos, block, false);
- w.notifyNeighborsRespectDebug(blockpos, iblockstate1.getBlock(), false);
- SoundType soundtype = iblockstate2.getBlock().getSoundType(iblockstate2, w, pos, p);
- w.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
- itemstack.shrink(1);
- return EnumActionResult.SUCCESS;
- }
- else
- {
- return EnumActionResult.FAIL;
- }
- }
- else
- {
- return EnumActionResult.FAIL;
- }
- }
- }
- }
|