Can't Pick drops

Discussion in 'Plugin Development' started by bronzzze, Mar 14, 2015.

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

    bronzzze

    I made AutoSmelt plugin. Sometimes when I mine gold ore I cannot pickup goldingots and I have no idea why. Ususuly when I am mining without fortune.
    [​IMG]

    My Code:
    Code:
        public void onMine(BlockBreakEvent e) {
             Block block = e.getBlock();
                Location centerOfBlock = block.getLocation().add(0.5, 0.5, 0.5);
            Player p = e.getPlayer();
            ItemStack item = p.getItemInHand();
            int fortuneLevel =  item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
              int bonus = (int) (Math.random() * ((fortuneLevel + 2)) - 1);
                if (bonus < 0) {
                    bonus = 0;
                }
       
       
            if (p.getItemInHand() != null
                    && p.getItemInHand().hasItemMeta()
                    && p.getItemInHand().getItemMeta().hasLore()
                    && p.getItemInHand().getItemMeta().getLore().contains
                            (ChatColor.GRAY + "Smelting I")) {
               
                if(e.getBlock().getType().equals(Material.GOLD_ORE)){
                    p.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.GOLD_INGOT, bonus));
                    centerOfBlock.getWorld().playEffect(centerOfBlock, Effect.MOBSPAWNER_FLAMES, 2);
                    centerOfBlock.getWorld().playSound(centerOfBlock, Sound.FIZZ, 2,2);
                    e.setCancelled(true);
                    e.getBlock().setType(Material.AIR);
                    e.getBlock().getDrops().remove(e.getBlock().getDrops());
                }else if(e.getBlock().getType().equals(Material.IRON_ORE)){
                        p.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.IRON_INGOT, bonus));
                        centerOfBlock.getWorld().playEffect(centerOfBlock, Effect.MOBSPAWNER_FLAMES, 4);
                        centerOfBlock.getWorld().playSound(centerOfBlock, Sound.FIZZ, 2,2);
                        e.setCancelled(true);
                        e.getBlock().setType(Material.AIR);
                        e.getBlock().getDrops().remove(e.getBlock().getDrops());
                       
       
                           
    
    
                       
                       
                    }
               
    
            }
           
    
       
        }
       
    }
    Ok Now I know when I can't pick it up. Its when it drops only 1 ingot but I have no idea why.

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

    bronzzze

  3. Offline

    Kilorbine

    hum...
    Have you try something like :
    Code:
    if (bonus == 1)
    p.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.IRON_INGOT));
    else
    p.getWorld().dropItemNaturally(centerOfBlock, new ItemStack(Material.IRON_INGOT, bonus));
    
     
  4. Offline

    bronzzze

  5. Offline

    bronzzze

Thread Status:
Not open for further replies.

Share This Page