Class LootTableEvents

java.lang.Object
net.fabricmc.fabric.api.loot.v2.LootTableEvents

public final class LootTableEvents extends Object
Events for manipulating loot tables.
  • Field Details

    • REPLACE

      public static final Event<LootTableEvents.Replace> REPLACE
      This event can be used to replace loot tables. If a loot table is replaced, the iteration will stop for that loot table.
    • MODIFY

      public static final Event<LootTableEvents.Modify> MODIFY
      This event can be used to modify loot tables. The main use case is to add items to vanilla or mod loot tables (e.g. modded seeds to grass).

      You can also modify loot tables that are created by REPLACE. They have the loot table source LootTableSource.REPLACED.

      Example: adding diamonds to the cobblestone loot table

      We'll add a new diamond loot pool to the cobblestone loot table that will be dropped alongside the original cobblestone loot pool.

      If you want only one of the items to drop, you can use FabricLootTableBuilder.modifyPools(java.util.function.Consumer) to add the new item to the original loot pool instead.

       
       LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
           // If the loot table is for the cobblestone block and it is not overridden by a user:
           if (Blocks.COBBLESTONE.getLootTableId().equals(id) && source.isBuiltin()) {
               // Create a new loot pool that will hold the diamonds.
               LootPool.Builder pool = LootPool.builder()
                   // Add diamonds...
                   .with(ItemEntry.builder(Items.DIAMOND))
                   // ...only if the block would survive a potential explosion.
                   .conditionally(SurvivesExplosionLootCondition.builder());
      
               // Add the loot pool to the loot table
               tableBuilder.pool(pool);
           }
       });
       
       
    • ALL_LOADED

      public static final Event<LootTableEvents.Loaded> ALL_LOADED
      This event can be used for post-processing after all loot tables have been loaded and modified by Fabric.