Advertisement
Guest User

Untitled

a guest
Jul 30th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /**
  2. * Called when the player uses this ItemStack on a Block (right-click). Places blocks, etc. (Legacy name:
  3. * tryPlaceItemIntoWorld)
  4. */
  5. public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
  6. {
  7. if (!worldIn.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, playerIn, worldIn, pos, side, hitX, hitY, hitZ, hand);
  8.  
  9. Item i = this.getItem();
  10. BlockSnapshot blockSnapshot = null;
  11.  
  12. if(i instanceof ItemBlock)
  13. {
  14. BlockPos pos2 = pos;
  15. ItemBlock item = (ItemBlock)this.getItem();
  16. if(!item.getBlock().isReplaceable(worldIn, pos))
  17. {
  18. pos2 = pos2.offset(side);
  19. }
  20. blockSnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, pos2, 11);
  21. }
  22.  
  23. EnumActionResult resault = this.getItem().onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);
  24.  
  25. if(i instanceof ItemBlock && resault == EnumActionResult.SUCCESS)
  26. {
  27. IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(side.getOpposite()));
  28. ClientBlockPlaceEvent e = new ClientBlockPlaceEvent(blockSnapshot, placedAgainst, playerIn, hand);
  29. MinecraftForge.EVENT_BUS.post(e);
  30. }
  31. else if (resault == EnumActionResult.SUCCESS)
  32. {
  33. playerIn.addStat(StatList.getObjectUseStats(this.item));
  34. }
  35.  
  36. return resault;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement