tigres810

Untitled

Mar 1st, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. package net.minecraft.item;
  2.  
  3. import net.minecraft.advancements.CriteriaTriggers;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.BlockBed;
  6. import net.minecraft.block.SoundType;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.entity.player.EntityPlayerMP;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.tileentity.TileEntityBed;
  14. import net.minecraft.util.EnumActionResult;
  15. import net.minecraft.util.EnumFacing;
  16. import net.minecraft.util.EnumHand;
  17. import net.minecraft.util.NonNullList;
  18. import net.minecraft.util.SoundCategory;
  19. import net.minecraft.util.math.BlockPos;
  20. import net.minecraft.util.math.MathHelper;
  21. import net.minecraft.world.World;
  22.  
  23. public class ItemBed extends Item
  24. {
  25. public ItemBed()
  26. {
  27. this.setCreativeTab(CreativeTabs.DECORATIONS);
  28. this.setMaxDamage(0);
  29. this.setHasSubtypes(true);
  30. }
  31.  
  32. /**
  33. * Called when a Block is right-clicked with this Item
  34. */
  35. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  36. {
  37. if (worldIn.isRemote)
  38. {
  39. return EnumActionResult.SUCCESS;
  40. }
  41. else if (facing != EnumFacing.UP)
  42. {
  43. return EnumActionResult.FAIL;
  44. }
  45. else
  46. {
  47. IBlockState iblockstate = worldIn.getBlockState(pos);
  48. Block block = iblockstate.getBlock();
  49. boolean flag = block.isReplaceable(worldIn, pos);
  50.  
  51. if (!flag)
  52. {
  53. pos = pos.up();
  54. }
  55.  
  56. int i = MathHelper.floor((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  57. EnumFacing enumfacing = EnumFacing.getHorizontal(i);
  58. BlockPos blockpos = pos.offset(enumfacing);
  59. ItemStack itemstack = player.getHeldItem(hand);
  60.  
  61. if (player.canPlayerEdit(pos, facing, itemstack) && player.canPlayerEdit(blockpos, facing, itemstack))
  62. {
  63. IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
  64. boolean flag1 = iblockstate1.getBlock().isReplaceable(worldIn, blockpos);
  65. boolean flag2 = flag || worldIn.isAirBlock(pos);
  66. boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);
  67.  
  68. if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid() && worldIn.getBlockState(blockpos.down()).isTopSolid())
  69. {
  70. IBlockState iblockstate2 = Blocks.BED.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
  71. worldIn.setBlockState(pos, iblockstate2, 10);
  72. worldIn.setBlockState(blockpos, iblockstate2.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD), 10);
  73. SoundType soundtype = iblockstate2.getBlock().getSoundType(iblockstate2, worldIn, pos, player);
  74. worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  75. TileEntity tileentity = worldIn.getTileEntity(blockpos);
  76.  
  77. if (tileentity instanceof TileEntityBed)
  78. {
  79. ((TileEntityBed)tileentity).setItemValues(itemstack);
  80. }
  81.  
  82. TileEntity tileentity1 = worldIn.getTileEntity(pos);
  83.  
  84. if (tileentity1 instanceof TileEntityBed)
  85. {
  86. ((TileEntityBed)tileentity1).setItemValues(itemstack);
  87. }
  88.  
  89. worldIn.notifyNeighborsRespectDebug(pos, block, false);
  90. worldIn.notifyNeighborsRespectDebug(blockpos, iblockstate1.getBlock(), false);
  91.  
  92. if (player instanceof EntityPlayerMP)
  93. {
  94. CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
  95. }
  96.  
  97. itemstack.shrink(1);
  98. return EnumActionResult.SUCCESS;
  99. }
  100. else
  101. {
  102. return EnumActionResult.FAIL;
  103. }
  104. }
  105. else
  106. {
  107. return EnumActionResult.FAIL;
  108. }
  109. }
  110. }
  111.  
  112. /**
  113. * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
  114. * different names based on their damage or NBT.
  115. */
  116. public String getUnlocalizedName(ItemStack stack)
  117. {
  118. return super.getUnlocalizedName() + "." + EnumDyeColor.byMetadata(stack.getMetadata()).getUnlocalizedName();
  119. }
  120.  
  121. /**
  122. * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
  123. */
  124. public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
  125. {
  126. if (this.isInCreativeTab(tab))
  127. {
  128. for (int i = 0; i < 16; ++i)
  129. {
  130. items.add(new ItemStack(this, 1, i));
  131. }
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment