Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos blockpos, EnumHand hand,
  2. EnumFacing facing, float hitX, float hitY, float hitZ) {
  3. ItemStack itemstack = player.getHeldItem(hand);
  4. IBlockState iblockstate = worldIn.getBlockState(blockpos);
  5. Block block = iblockstate.getBlock();
  6.  
  7. if (!(block instanceof BlockLayer) && !block.isReplaceable(worldIn, blockpos)) {
  8. blockpos = blockpos.offset(facing);
  9. iblockstate = worldIn.getBlockState(blockpos);
  10. block = iblockstate.getBlock();
  11. }
  12.  
  13. if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemBlockLayer
  14. && player.canPlayerEdit(blockpos, facing, itemstack)) {
  15. int amount = 1;
  16.  
  17. // Build upon already placed block
  18. if (block instanceof BlockLayer) {
  19. int i = ((Integer) iblockstate.getValue(BlockSnow.LAYERS)).intValue();
  20. if (i < 8) {
  21. if (Minecraft.getMinecraft().gameSettings
  22. .isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) {
  23. amount = Math.min(4, 8 - i);
  24. if (player.isCreative() == false) {
  25. amount = Math.min(amount, itemstack.getCount());
  26. }
  27. amount += i;
  28. } else {
  29. amount = i + 1;
  30. }
  31. } else {
  32. blockpos = blockpos.up();
  33. iblockstate = worldIn.getBlockState(blockpos);
  34. block = iblockstate.getBlock();
  35. }
  36. } else {
  37. // New block
  38. if (Minecraft.getMinecraft().gameSettings
  39. .isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) {
  40. amount = 4;
  41. if (player.isCreative() == false) {
  42. amount = Math.min(4, itemstack.getCount());
  43. }
  44. }
  45. }
  46.  
  47. IBlockState iblockstate1 = ((ItemBlock) itemstack.getItem()).getBlock().getDefaultState()
  48. .withProperty(BlockSnow.LAYERS, Integer.valueOf(amount));
  49.  
  50. // Change/Place block
  51. AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);
  52. if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos))
  53. && worldIn.setBlockState(blockpos, iblockstate1, 10)) {
  54. Main.logger.warn("PLACED");
  55. SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, blockpos, player);
  56. worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS,
  57. (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
  58.  
  59. if (player instanceof EntityPlayerMP) {
  60. CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, blockpos, itemstack);
  61. }
  62.  
  63. itemstack.shrink(amount);
  64. return EnumActionResult.SUCCESS;
  65. }
  66. }
  67. return EnumActionResult.FAIL;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement