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 revisionBoth sides next revision
tutorial:adding_to_loot_tables [2019/08/13 06:46] – No magic constants man! liachtutorial:adding_to_loot_tables [2021/06/10 13:00] – update to current yarn naming 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 ''%%minecraft:blocks/coal_ore%%''.+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> <code java>
 // No magic constants! // No magic constants!
-private static final Identifier COAL_ORE_LOOT_TABLE_ID = new Identifier("minecraft", "blocks/coal_ore");+private static final Identifier COAL_ORE_LOOT_TABLE_ID = Blocks.COAL_ORE.getLootTableId();
  
 // Actual code // Actual code
  
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, 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)) {
         // Our code will go here         // Our code will go here
Line 31: Line 31:
  
 <code java> <code java>
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, 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()
-                .withRolls(ConstantLootTableRange.create(1)); // Same as "rolls": 1 in the loot table json+                .rolls(ConstantLootTableRange.create(1)); // Same as "rolls": 1 in the loot table json
  
-        supplier.withPool(poolBuilder);+        table.pool(poolBuilder);
     }     }
 }); });
Line 43: Line 43:
  
 <code java> <code java>
-LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, 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()
-                .withRolls(ConstantLootTableRange.create(1)) +                .rolls(ConstantLootTableRange.create(1)) 
-                .withEntry(ItemEntry.builder(Items.EGG));+                .with(ItemEntry.builder(Items.EGG));
  
-        supplier.withPool(poolBuilder);+        table.pool(poolBuilder);
     }     }
 }); });
tutorial/adding_to_loot_tables.txt · Last modified: 2024/02/05 16:08 by mschae23