Dropping change

Discussion in 'Plugin Development' started by 1928i, Aug 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    1928i

    How do I make it so that when a player breaks one blocks, a different one is dropped. Like if you broke a diamond block it would drop a dirt block.

    I need help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    ZodiacTheories

    1928i

    13 minute bump? Patience, please. Back on tropic, just listen to the blockbreakevent, and you should be able to get the right methods from that.
     
  3. Offline

    kmecpp

    1928i untested, but it should work

    Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent e){
        if(e.getBlock().getType() == Material.DIAMOND_BLOCK){
                e.setCancelled(true);
                e.getBlock().setType(Material.DIRT);
                e.getBlock().breakNaturally();
            }
        }
    }
     
  4. Offline

    1928i

    kmecpp What about if someone mined it with their fist? It would still drop the dirt. How could you prevent that?
     
  5. Offline

    kmecpp

    1928i The simplest way would probably to just check if the player is holding a pickaxe:

    Code:
    if(e.getBlock().getType() == Material.DIAMOND_BLOCK){
                if(e.getPlayer().getItemInHand().getTypeId() == 257 || e.getPlayer().getItemInHand().getTypeId() == 278){
                    e.setCancelled(true);
                    e.getBlock().setType(Material.DIRT);
                    e.getBlock().breakNaturally();
                }
            }
    The item ID 257 is an iron pick and 278 is a diamond pick. I don't think anything else can break diamond blocks...
     
  6. Offline

    Iroh

Thread Status:
Not open for further replies.

Share This Page