User Tools

Site Tools


tutorial:adding_to_loot_tables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:adding_to_loot_tables [2022/03/27 06:01] – Added syntax clarification for 1.17.1+ support. stormyfabrictutorial:adding_to_loot_tables [2022/03/27 07:20] stormyfabric
Line 11: Line 11:
 Fabric API has an event that’s fired when loot tables are loaded, ''%%LootTableLoadingCallback%%''. You can register an event listener for it in your initializer. Let’s also check that the current loot table is the coal ore loot table. Fabric API has an event that’s fired when loot tables are loaded, ''%%LootTableLoadingCallback%%''. You can register an event listener for it in your initializer. Let’s also check that the current loot table is the coal ore loot table.
  
-<code java>+<yarncode java>
 // No magic constants! // No magic constants!
-private static final Identifier COAL_ORE_LOOT_TABLE_ID = Blocks.COAL_ORE.getLootTableId();+private static final class_2960 COAL_ORE_LOOT_TABLE_ID = class_2246.COAL_ORE.getLootTableId();
  
 // Actual code // Actual code
Line 22: Line 22:
     }     }
 }); });
-</code>+</yarncode>
  
-===== Adding items to the table 1.16.5 and Below =====+===== Adding items to the table =====
  
 In loot tables, items are stored in //loot entries,// and entries are stored in //loot pools//. To add an item, we’ll need to add a pool with an item entry to the loot table. In loot tables, items are stored in //loot entries,// and entries are stored in //loot pools//. To add an item, we’ll need to add a pool with an item entry to the loot table.
Line 30: Line 30:
 We can make a pool with ''%%FabricLootPoolBuilder%%'', and add it to the loot table: We can make a pool with ''%%FabricLootPoolBuilder%%'', and add it to the loot table:
  
-<code java>+<yarncode java>
 LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> {
     if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {     if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
-                .rolls(ConstantLootTableRange.create(1)); // Same as "rolls": 1 in the loot table json+                .method_352(class_44.method_32448(1)); // Same as "rolls": 1 in the loot table json
  
-        table.pool(poolBuilder);+        table.method_336(poolBuilder);
     }     }
 }); });
-</code>+</yarncode>
 Our pool doesn’t have any items yet, so we’ll make an item entry and add it to the pool, and we're done: Our pool doesn’t have any items yet, so we’ll make an item entry and add it to the pool, and we're done:
  
-<code java>+<yarncode java>
 LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> {
     if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {     if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
-                .rolls(ConstantLootTableRange.create(1)) +                .method_352(class_44.method_32448(1)); 
-                .with(ItemEntry.builder(Items.EGG));+                .method_351(class_77.method_411(class_1802.field_8803));
  
-        table.pool(poolBuilder);+        table.method_336(poolBuilder);
     }     }
 }); });
-</code> +</yarncode>
- +
-===== Adding items to the table 1.17.1 and Above===== +
- +
-The process is the same, the only change is in Syntax for 1.17.1+ you will need to replace ''%%ConstantLootTableRange%%'' with ''%%ConstantLootNumberProvider%%'' as shown below in the final code. +
- +
-<code java> +
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, table, setter) -> { +
-    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { +
-        FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() +
-                .rolls(ConstantLootNumberProvider.create(1)) +
-                .with(ItemEntry.builder(Items.EGG)); +
- +
-        table.pool(poolBuilder); +
-    } +
-}); +
-</code> +
- +
  
 {{:tutorial:coal_ore_egg.png?400|}} {{:tutorial:coal_ore_egg.png?400|}}
  
tutorial/adding_to_loot_tables.txt · Last modified: 2024/02/05 16:08 by mschae23