Auto Smelting

Discussion in 'Plugin Development' started by Trill, Jan 12, 2015.

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

    Trill

    @nverdier
    Sorry, I didn't say that very well. I mean if a player had Fortune 10 and he mined a block. How could I give him 5,6,7, or 8 ingots. Like how fortune works in Minecraft.
     
  2. Offline

    teej107

    Using the Random class.
     
  3. Invisible

    nverdier

  4. Offline

    Trill

    @teej107 @nverdier
    I can't seem to find something that will create me random number between 5 and 8. I know it probably says somewhere in there the way to do it but after looking at all the code pasted there, I have no clue.
     
  5. Offline

    teej107

    @Trill Where did you look exactly?
     
  6. Offline

    Trill

  7. Offline

    teej107

    @Trill Do you know how to read Java Documentation? Is there a certain method that is similar to what you want?
     
  8. Invisible

    nverdier

  9. Offline

    Trill

    @nverdier
    I should of thought of that...
    Well thanks! I got how to do it now.

    Ok, I exported the plugin and put it on my server(checking for any imcompatible plugins) and after restarting my server it still gives me iron or gold ore when I break iron or gold. I checked my console but it doesn't say anything bad about it.

    My plugin.yml is setup correctly

    Here is my code:
    Code:
    @EventHandler
            public void onBlockBreak(BlockBreakEvent event)
            {
                Material block = event.getBlock().getType();
                Player player = event.getPlayer();
                event.getBlock().getLocation();  
                World world = Bukkit.getWorld("world");
                player.getItemInHand();
                player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
                if (block == Material.GOLD_ORE)
                {
                    event.setExpToDrop(1);
                    if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 0)
                    {
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, 1);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 1)
                    {
                        Random ran = new Random();
                        int gold1 = ran.nextInt(2) + 1;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold1);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 2)
                    {
                        Random ran = new Random();
                        int gold2 = ran.nextInt(3) + 1;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold2);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 3)
                    {
                        Random ran = new Random();
                        int gold3 = ran.nextInt(4) + 1;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold3);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 4)
                    {
                        Random ran = new Random();
                        int gold4 = ran.nextInt(3) + 2;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold4);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 5)
                    {
                        Random ran = new Random();
                        int gold5 = ran.nextInt(5) + 1;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold5);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 6)
                    {
                        Random ran = new Random();
                        int gold6 = ran.nextInt(5) + 2;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold6);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 7)
                    {
                        Random ran = new Random();
                        int gold7 = ran.nextInt(7) + 2;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold7);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 8)
                    {
                        Random ran = new Random();
                        int gold8 = ran.nextInt(8) + 2;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold8);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 9)
                    {
                        Random ran = new Random();
                        int gold9 = ran.nextInt(8) + 3;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold9);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 10)
                    {
                        Random ran = new Random();
                        int gold10 = ran.nextInt(8) + 4;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold10);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 11)
                    {
                        Random ran = new Random();
                        int gold11 = ran.nextInt(8) + 5;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold11);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 12)
                    {
                        Random ran = new Random();
                        int gold12 = ran.nextInt(9) + 5;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold12);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 13)
                    {
                        Random ran = new Random();
                        int gold13 = ran.nextInt(8) + 6;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold13);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 14)
                    {
                        Random ran = new Random();
                        int gold14 = ran.nextInt(8) + 7;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold14);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 15)
                    {
                        Random ran = new Random();
                        int gold15 = ran.nextInt(12) + 7;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold15);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 16)
                    {
                        Random ran = new Random();
                        int gold16 = ran.nextInt(11) + 8;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold16);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 17)
                    {
                        Random ran = new Random();
                        int gold17 = ran.nextInt(10) + 9;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold17);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 18)
                    {
                        Random ran = new Random();
                        int gold18 = ran.nextInt(10) + 9;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold18);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 19)
                    {
                        Random ran = new Random();
                        int gold19 = ran.nextInt(10) + 10;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold19);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 20)
                    {
                        Random ran = new Random();
                        int gold20 = ran.nextInt(11) + 10;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold20);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 21)
                    {
                        Random ran = new Random();
                        int gold21 = ran.nextInt(11) + 10;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold21);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 22)
                    {
                        Random ran = new Random();
                        int gold22 = ran.nextInt(11) + 11;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold22);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 23)
                    {
                        Random ran = new Random();
                        int gold23 = ran.nextInt(13) + 11;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold23);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 24)
                    {
                        Random ran = new Random();
                        int gold24 = ran.nextInt(11) + 13;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold24);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 25)
                    {
                        Random ran = new Random();
                        int gold25 = ran.nextInt(10) + 14;
                        ItemStack gold = new ItemStack(Material.GOLD_INGOT, gold25);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    }
                  
                }
              
              
              
                else if (block == Material.IRON_ORE)
                {
                    event.setExpToDrop((int) 0.7);
                    if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 0)
                    {
                        ItemStack iron = new ItemStack(Material.IRON_INGOT, 1);
                        world.dropItemNaturally(event.getBlock().getLocation(), iron);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 1)
                    {
                        Random ran = new Random();
                        int iron1 = ran.nextInt(2) + 1;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron1);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 2)
                    {
                        Random ran = new Random();
                        int iron2 = ran.nextInt(3) + 1;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron2);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 3)
                    {
                        Random ran = new Random();
                        int iron3 = ran.nextInt(4) + 1;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron3);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 4)
                    {
                        Random ran = new Random();
                        int iron4 = ran.nextInt(3) + 2;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron4);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 5)
                    {
                        Random ran = new Random();
                        int iron5 = ran.nextInt(5) + 1;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron5);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 6)
                    {
                        Random ran = new Random();
                        int iron6 = ran.nextInt(5) + 2;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron6);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 7)
                    {
                        Random ran = new Random();
                        int iron7 = ran.nextInt(7) + 2;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron7);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 8)
                    {
                        Random ran = new Random();
                        int iron8 = ran.nextInt(8) + 2;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron8);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 9)
                    {
                        Random ran = new Random();
                        int iron9 = ran.nextInt(8) + 3;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron9);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 10)
                    {
                        Random ran = new Random();
                        int iron10 = ran.nextInt(8) + 4;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron10);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 11)
                    {
                        Random ran = new Random();
                        int iron11 = ran.nextInt(8) + 5;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron11);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 12)
                    {
                        Random ran = new Random();
                        int iron12 = ran.nextInt(9) + 5;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron12);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 13)
                    {
                        Random ran = new Random();
                        int iron13 = ran.nextInt(8) + 6;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron13);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 14)
                    {
                        Random ran = new Random();
                        int iron14 = ran.nextInt(8) + 7;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron14);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 15)
                    {
                        Random ran = new Random();
                        int iron15 = ran.nextInt(12) + 7;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron15);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 16)
                    {
                        Random ran = new Random();
                        int iron16 = ran.nextInt(11) + 8;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron16);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 17)
                    {
                        Random ran = new Random();
                        int iron17 = ran.nextInt(10) + 9;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron17);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 18)
                    {
                        Random ran = new Random();
                        int iron18 = ran.nextInt(10) + 9;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron18);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 19)
                    {
                        Random ran = new Random();
                        int iron19 = ran.nextInt(10) + 10;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron19);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 20)
                    {
                        Random ran = new Random();
                        int iron20 = ran.nextInt(11) + 10;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron20);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 21)
                    {
                        Random ran = new Random();
                        int iron21 = ran.nextInt(11) + 10;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron21);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 22)
                    {
                        Random ran = new Random();
                        int iron22 = ran.nextInt(11) + 11;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron22);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 23)
                    {
                        Random ran = new Random();
                        int iron23 = ran.nextInt(13) + 11;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron23);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 24)
                    {
                        Random ran = new Random();
                        int iron24 = ran.nextInt(11) + 13;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron24);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else if (player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) == 25)
                    {
                        Random ran = new Random();
                        int iron25 = ran.nextInt(10) + 14;
                        ItemStack gold = new ItemStack(Material.IRON_INGOT, iron25);
                        world.dropItemNaturally(event.getBlock().getLocation(), gold);
                    } else return;
                }
                return;
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  10. Offline

    teej107

    @Trill Did you register your events?
     
  11. Offline

    Trill

    @teej107
    Thanks! I registered my events now but it is dropping ingots and the ore now. I still need to cancel the default ore drop. Then it will only drop the specified ingots.

    Basically I am getting the ingots(which I added) and the ore (which is what normally drops when you break iron or gold ore).

    EDIT: Got it, just have to cancel the event and replace the block with air!
    EDIT: Couldn't find a way to naturally drop xp. So I made it give the player xp automatically.
     
    Last edited: Jan 18, 2015
Thread Status:
Not open for further replies.

Share This Page