drop item naturally with a chance %

Discussion in 'Plugin Development' started by XbannisherX, Jun 17, 2012.

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

    XbannisherX

    hi, im making a plugin that when a player destroy's IRON_ORE it haves X% chance that something else drops, i came this far but now im stuck :( becaus its throwing quite a bit of errors...



    Code:
    public void onBlockBreakEvent(BlockBreakEvent event){
        (BlockBreakEvent() == Material.IRON_ORE, 1);{
     
     
         
            double rand = Math.random();
            for (Entry<ItemStack, Float> e : map) {
                rand -= e.getValue();
                if (rand <= 0) {
                    block.getWorld().dropItemNaturally(centerOfBlock, e.getKey());
                    break;
                }
         
         
         
         
         
         
         
            Block block = event.getBlock();
            Location centerOfBlock = block.getLocation().add(0.5, 0.5, 0.5);
            block.getWorld().dropItemNaturally(centerOfBlock, block.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.COBBLESTONE, 2)));
            if (Math.random() < 0.1)
                block.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.BONE, 1));
            if (Math.random() < 0.4)
                    block.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.IRON_ORE, 1));
            if (Math.random() < 0.4)
                    block.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.STONE, 1));
            if (Math.random() < 0.1)
                    block.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.DIRT, 1));
            
     
  2. Offline

    Jnorr44

    Stack-trace please!
     
  3. Offline

    Njol

    It seems like you just merged my code with yours without understanding what it does, thus either remove my code or your's.
    Moreover you should learn a bit more about Java's syntax as this line is completely invalid:
    Code:
    (BlockBreakEvent() == Material.IRON_ORE, 1);{
    I guess you meant to write the following:
    Code:
    if (event.getBlock().getType() == Material.IRON_ORE) {
     
  4. Offline

    XbannisherX

    Sorry ill remove your code and try it myself a bit more :)
     
  5. Offline

    Jnorr44

    before you can call a material name you need to put getType(), otherwise, java doesnt recognize the type of material you are talking about.
     
Thread Status:
Not open for further replies.

Share This Page