Increasing Apple Drop Rate

Discussion in 'Plugin Development' started by edragy, Aug 10, 2012.

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

    edragy

    How do you increase the apple drop rate?
     
  2. Offline

    WarmakerT

    Once you break a leaf block without using shears, cancel the event. Remove the leaf block, drop some apples based on an algorithm.
     
  3. Offline

    edragy

    example please?
     
  4. Offline

    Cirno

    Pseudo-code, it doesn't work. Meant to be readable by the normal human eye :)
    Code:
    When player breaks a block:
     if Block is a leaf Block and Player's held item is not a shear then:
      Cancel this event. Meaning, don't let the block break.
      Remove the blocks, or effectively just set it to air.
      Do some fancy doo-dad algorithm, probably just using Random
      if the random is equal/less then/more then/whatever then you want:
       drop Apple
    
     
  5. Offline

    WarmakerT

    Code:
    @EventHandler
    //When player breaks a block:
    public void onBlockBreak(BlockBreakEvent event){
    //if Block is a leaf Block and Player's held item
    if(event.getBlock().getType().equals(Material.LEAF) && event.getPlayer().getItemInHand().equals(Material.SHEARS)) {
      /*Cancel this event. Meaning, don't let the block break.*/
    event.setCancelled(true);
    //Remove the blocks, or effectively just set it to air.
    event.getBlock().setType(Material.AIR);
    //Do some fancy doo-dad algorithm, probably just using Random
    Random rand = new Random();
    int randomNumber = rand.nextInt(3);
    switch(randomNumber){
    default:
    break;
    case 1:
    event.getPlayer().getLocation().dropItemNaturally(new Itemstack(Material.APPLE, 1));
    break;
    case 2:
    event.getPlayer().getLocation().dropItemNaturally(new Itemstack(Material.APPLE, 1));
    break;
    }
    }
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page