How to replace custom drops

Discussion in 'Spigot Plugin Development' started by AsssassinJianer, Apr 14, 2017.

  1. Hey, im coding this and im wondering if is possible beacause it will make all my work easier. Basiclly this is what should happend, when i mine a iron ingot one piece of the code will change the drops to 4 iron ores, but i want another part of the code to change it to iron ingot only when enabled, i know that i can change all together but this method, if possible, will make the code simpler than it will.
     
  2. BTW THIS IS MY CURRENT CODE
    Code (Text):


        @EventHandler
        public void onBreakLimitations(BlockBreakEvent e)
        {
            Block Block = e.getBlock();
            Location loc = new Location(Block.getWorld(),
                    Block.getLocation().getBlockX() + 0.00D,
                    Block.getLocation().getBlockY() + 0.00D,
                    Block.getLocation().getBlockZ() + 0.00D);
            if(!e.getPlayer().getGameMode().equals(GameMode.CREATIVE))
            {
                if (Block.getType() == Material.IRON_ORE)
                {
                    Block.getWorld().dropItemNaturally(loc, new ItemStack(Material.IRON_ORE, 3));
                }


               
                new BukkitRunnable()
                {
                    int time = 2;

                    public void run()
                    {
                        this.time -= 1;
                        if (this.time == 0)
                        {
                           
                            if (Block.getType() == Material.IRON_ORE)
                            {
                                for (ItemStack drops : Block.getDrops()) {
                                    if (drops.getTypeId() == 15) {
                                        int dropint = drops.getAmount();
                                        Block.getLocation().getBlock().setType(Material.AIR);
                                        Block.getWorld().dropItemNaturally(loc, new ItemStack(Material.IRON_INGOT, dropint));
                                       
                                    }
                                }

                            }



                            cancel();
                            return;
                        }
                    }
                }.runTaskTimer(this.plugin, 0L, 10L);


            }

        }

     
    Waiting your response, thanks.
     
  3. This should be your answer :)
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/block/BlockDispenseEvent.html

    Just modify ( event.setItem(); ) then.