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
Last revisionBoth sides next revision
tutorial:adding_to_loot_tables [2022/03/27 07:20] stormyfabrictutorial:adding_to_loot_tables [2022/06/21 22:54] – use loot v2 api instead of v1 juuz
Line 9: Line 9:
 ===== Listening to loot table loading ===== ===== Listening to loot table loading =====
  
-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, ''%%LootTableEvents.MODIFY%%''. 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.
  
 <yarncode java> <yarncode java>
Line 17: Line 17:
 // Actual code // Actual code
  
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, tablesetter) -> { +LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuildersource) -> { 
-    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {+    // Let's only modify built-in loot tables and leave data pack loot tables untouched by checking the source. 
 +    // We also check that the loot table ID is equal to the ID we want. 
 +    if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         // Our code will go here         // Our code will go here
     }     }
Line 26: Line 28:
 ===== Adding items to the table ===== ===== 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 pool 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.
  
-We can make a pool with ''%%FabricLootPoolBuilder%%'', and add it to the loot table:+We can make a pool with ''<yarn class_55$class_56>'', and add it to the loot table:
  
 <yarncode java> <yarncode java>
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, tablesetter) -> { +LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuildersource) -> { 
-    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { +    if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) { 
-        FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder(+        class_55.Builder poolBuilder = class_55.method_347();
-                .method_352(class_44.method_32448(1)); // Same as "rolls": 1 in the loot table json+
  
-        table.method_336(poolBuilder);+        tableBuilder.method_336(poolBuilder);
     }     }
 }); });
Line 43: Line 44:
  
 <yarncode java> <yarncode java>
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, tablesetter) -> { +LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuildersource) -> { 
-    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) { +    if (source.isBuiltin() && COAL_ORE_LOOT_TABLE_ID.equals(id)) { 
-        FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() +        class_55.Builder poolBuilder = class_55.method_347()
-                .method_352(class_44.method_32448(1));+
                 .method_351(class_77.method_411(class_1802.field_8803));                 .method_351(class_77.method_411(class_1802.field_8803));
  
-        table.method_336(poolBuilder);+        tableBuilder.method_336(poolBuilder);
     }     }
 }); });
tutorial/adding_to_loot_tables.txt · Last modified: 2024/02/05 16:08 by mschae23