User Tools

Site Tools


tutorial:datagen_loot

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:datagen_loot [2022/11/14 19:32] nexus-dinotutorial:datagen_loot [2023/06/05 17:30] – Add comments inside onInitializeDataGenerator to be consistent with other data generation tutorials on the wiki mcrafterzz
Line 1: Line 1:
-Before reading this, make sure you have a class that implements ''DataGenerationEntrypoint''+====== Loot Table Generation ======
  
-To get started, make a class (or a few, you need one for blocks, chests and entities) that extends ''SimpleFabricLootTableProvider'' and register it like so:+Before reading this, make sure you've read [[datagen_setup|Getting started with Data Generation]], and have a class that implements ''DataGenerationEntrypoint'' 
 + 
 +To begin, make a class (or a few, you need one for blocks, chests and entities) that extends ''SimpleFabricLootTableProvider'' and register it like so:
  
 ==== Setting Up ==== ==== Setting Up ====
Line 7: Line 9:
  
 <code java> <code java>
-private static class MyBlockLootTables extends SimpleFabricLootTableProvider +private static class MyBlockLootTables extends FabricBlockLootTableProvider 
-    public MyBlockLootTables(FabricDataGenerator dataGenerator) { +    public MyBlockLootTables(FabricDataOutput dataOutput) { 
-         super(dataGenerator, LootContextTypes.BLOCK);+         super(dataOutput);
     }     }
          
     @Override     @Override
-    public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {+    public void generate() {
         // ...         // ...
     }     }
Line 23: Line 25:
 @Override @Override
 public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
 +    // ...
     fabricDataGenerator.addProvider(MyBlockLootTables::new);     fabricDataGenerator.addProvider(MyBlockLootTables::new);
 +    // ...
 } }
 </code> </code>
Line 38: Line 42:
 ==== Adding Block Loot ==== ==== Adding Block Loot ====
 <code java> <code java>
-private static class MyBlockLootTables extends SimpleFabricLootTableProvider +private static class MyBlockLootTables extends FabricBlockLootTableProvider 
-    public MyBlockLootTables(FabricDataGenerator dataGenerator) { +    public MyBlockLootTables(FabricDataOutput dataOutput) { 
-         super(dataGenerator, LootContextTypes.BLOCK);+         super(dataOutput);
     }     }
- +    
     @Override     @Override
-    public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) { +    public void generate() { 
-    // The BlockLootTableGenerator class contains a behemoth of utility methods. Just take some time and go through the methods available to override. +        addDrop(Tutorial.TEST_BLOCK, drops(Tutorial.TEST_ITEM));
-        biConsumer.accept(new Identifier("tutorial", "test_block"), BlockLootTableGenerator.drops(Tutorial.TEST_BLOCK, Tutorial.TEST_ITEM, ConstantLootNumberProvider.create(9.0F)));+
     }     }
 } }
tutorial/datagen_loot.txt · Last modified: 2023/06/16 17:29 by slainlight