Solved Set Mob Drop as Random Item From Loot Table

Discussion in 'Spigot Plugin Development' started by gecko10000, Aug 3, 2020.

  1. So I'm trying to set a mob drop as an item from the fishing loot table, and so far I've got the following in EntityDeathEvent:
    Code (Text):
                Random random = new Random();
                LootTable fishingLoot = LootTables.FISHING.getLootTable();
                Builder fishingContextBuilder = new LootContext.Builder(evt.getEntity().getLocation());
                LootContext fishingContext =;
                List<ItemStack> fishingDrops = (List<ItemStack>) fishingLoot.populateLoot(random, fishingContext);
                for (ItemStack drop : fishingDrops) {
                    getLogger().info("" + drop.getType().toString());
    but fishingDrops appears to be empty.

    Alternatively, is there a way to set an ItemStack as a random item from a loot table?

    Thank you.
  2. Just use in your forloop

    Code (Text):
    evt.getLocation.getWorld().dropItemNaturally(evt.getLocation, drop);
  3. The list of fishingDrops is still empty, however, and nothing drops.
  4. Basically, how would I get a random ItemStack from the fishing loot table?
  5. I have used this but whenever I do
    no items are added to the list of drops. Whenever it happens, it gives me the exception:
    Code (Text):
    Caused by: java.lang.IllegalArgumentException: Missing required parameters: [<parameter minecraft:position>, <parameter minecraft:tool>]
    I'm probably just not understanding how to generate loot correctly.
  6. Just create your own List with items
    • Agree Agree x 1
  7. If not adding to a mob's drops, is there a way to generate a chest's loot with the fishing loot table? I've got the following code, which generates an empty chest:
    Code (Java):
                Chest chest = (Chest) evt.getLocation().getBlock().getState();
                LootTable fishingLoot = LootTables.FISHING.getLootTable();
                LootContext fishingContext = new LootContext.Builder(evt.getLocation()).build();
                List<ItemStack> loot = new ArrayList<>();
                loot.add(new ItemStack(Material.DIAMOND));
                LootGenerateEvent lootEvent = new LootGenerateEvent(evt.getLocation().getWorld(), null, chest.getInventory().getHolder(), fishingLoot, fishingContext, loot, true);
    Also, what is loot (the second-to-last argument for LootGenerateEvent) for?
  8. Welp, I've found a solution:
    Code (Java):
    getServer().dispatchCommand(getServer().getConsoleSender() , "loot spawn " + x + " " + y + " " + z + " loot minecraft:gameplay/fishing");
  9. Not the smartest solution but when it works this should be fine too ;D
    But i still would recommend to create your own Loot table.
  10. And if your question is answered, don't forget to change the title to solved :)