How-to: Add Monster Loot

Library of Exile provides two hooks for adding drops to mobs: one for mob kills and one for block-break farming drops.


Add drops when a mob is killed

Use ExileEvents.MOB_KILLED_BY_PLAYER to react when a player kills a mob:

ExileEvents.MOB_KILLED_BY_PLAYER.register(new EventConsumer<ExileEvents.OnMobKilledByPlayer>() {
    @Override
    public void accept(ExileEvents.OnMobKilledByPlayer e) {
        LivingEntity mob    = e.mob;
        ServerPlayer player = e.player;

        // Drop an item at the mob's position
        if (mob instanceof Zombie) {
            mob.spawnAtLocation(new ItemStack(Items.ROTTEN_FLESH, 2));
        }
    }
});

mob.spawnAtLocation drops the item into the world at the mob's position. It is collected like any normal drop.


Read and modify loot chance

ExileEvents.SETUP_LOOT_CHANCE fires before loot is determined. The lootChance field is a mutable float you can read or change:

ExileEvents.SETUP_LOOT_CHANCE.register(new EventConsumer<ExileEvents.OnSetupLootChance>() {
    @Override
    public void accept(ExileEvents.OnSetupLootChance e) {
        LivingEntity mob    = e.mobKilled;
        ServerPlayer player = e.player;
        // e.lootChance is the current chance value; modify it here
        if (player.hasEffect(MobEffects.LUCK)) {
            e.lootChance += 0.1f;
        }
    }
});

Add drops from ore mining

ExileEvents.PLAYER_MINE_ORE fires when a player mines a block that is not a farmable block. Add items to itemsToAddToDrop to include them in the block's drops:

ExileEvents.PLAYER_MINE_ORE.register(new EventConsumer<ExileEvents.PlayerMineOreEvent>() {
    @Override
    public void accept(ExileEvents.PlayerMineOreEvent e) {
        BlockState state    = e.state;
        ServerPlayer player = e.player;
        BlockPos pos        = e.pos;

        if (state.is(Blocks.IRON_ORE)) {
            e.itemsToAddToDrop.add(new ItemStack(MyItems.IRON_SHARD.get()));
        }
    }
});

Add drops from farm block harvesting

ExileEvents.PLAYER_MINE_FARMABLE fires specifically for farmable blocks (crops, etc.):

ExileEvents.PLAYER_MINE_FARMABLE.register(new EventConsumer<ExileEvents.PlayerMineFarmableBlockEvent>() {
    @Override
    public void accept(ExileEvents.PlayerMineFarmableBlockEvent e) {
        // e.droppedItems contains the items already determined to drop.
        // Add to it or replace entries as needed.
        e.droppedItems.add(new ItemStack(Items.WHEAT_SEEDS));
    }
});

Use vanilla loot tables for mob drops

Standard Minecraft loot tables for mobs are not replaced by Library of Exile — they continue to fire normally. You can override or extend them using Forge's LootTableLoadEvent, or by placing loot table JSON files in your datapack at:

src/main/resources/data/<namespace>/loot_tables/entities/<entity_type>.json

Notes

  • MOB_KILLED_BY_PLAYER does not fire for mob-on-mob kills. Use ExileEvents.MOB_DEATH if you need to react to all deaths regardless of killer.
  • All event listeners registered via ExileEvents use an ordered priority system. If your listener depends on another mod's output, use callOrder() to set relative ordering.