Guest User

Untitled

a guest
Oct 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. @Override
  2. public void onPlayerInteract(PlayerInteractEvent event){
  3. Block tobreak = event.getClickedBlock(); //get the block the player interacted with
  4. if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
  5. boolean breakblock = false; //sets whether or not to break the block
  6. if (tobreak != null) {
  7. //Place the block types as the format below
  8. if (tobreak.getType() == Material.BEDROCK) breakblock = true;
  9.  
  10. }
  11. if (breakblock) {
  12. ItemStack item = event.getItem();
  13. if (item != null) {
  14. item.setDurability((short) (item.getDurability() - 10));
  15. }
  16. Player p = event.getPlayer();
  17. World w = p.getWorld();
  18.  
  19. //Generate the itemstack to drop
  20. ItemStack tospawn = new ItemStack(tobreak.getType(), 1);
  21.  
  22. //Set the clicked block to air (0)
  23. tobreak.setTypeId(0);
  24.  
  25. //Drop the item
  26. w.dropItemNaturally(tobreak.getLocation(), tospawn);
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment