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
tutorial:datagen_loot [2022/09/16 16:37] nexus-dinotutorial:datagen_loot [2023/06/16 17:29] (current) – 1.20+ addProvider change slainlight
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 ====
 +To get started with block loot, create a block loot table generator
 +
 <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 21: Line 25:
 @Override @Override
 public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
-    fabricDataGenerator.addProvider(MyBlockLootTables::new);+    // ... 
 +    FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack(); 
 +    myPack.addProvider(MyBlockLootTables::new); 
 +    // ...
 } }
 </code> </code>
 +
 +If you're using versions pre-1.20, please replace ''myPack.addProvider(MyBlockLootTables::new);'' with ''fabricDataGenerator.addProvider(MyBlockLootTables::new);''。You can also remove ''FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack();''
  
 Let's just create a simple ore block and an item to drop from it for a block loot table. Add this to your block init or ''Tutorial'' class in this case. Let's just create a simple ore block and an item to drop from it for a block loot table. Add this to your block init or ''Tutorial'' class in this case.
Line 34: Line 43:
 </code> </code>
  
-==== 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)));+
     }     }
 } }
Line 51: Line 59:
 Now that we successfully adding a block. Now let's add chest loot. Now that we successfully adding a block. Now let's add chest loot.
  
-==== ADDING CHEST LOOT ====+==== Adding Chest Loot ====
  
 Firstly, we need an identifier. This identifier points to a json file that contains your chest loot. Firstly, we need an identifier. This identifier points to a json file that contains your chest loot.
Line 65: Line 73:
  
 private static class MyChestLootTables extends SimpleFabricLootTableProvider { private static class MyChestLootTables extends SimpleFabricLootTableProvider {
-    public MyChestLootGenerator(FabricDataGenerator dataGenerator) {+    public MyChestLootGenerator(FabricDataOutput dataGenerator) {
  super(dataGenerator, LootContextTypes.CHEST);  super(dataGenerator, LootContextTypes.CHEST);
     }     }
Line 84: Line 92:
 @Override @Override
 public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
-    fabricDataGenerator.addProvider(MyChestLootTables::new);+    FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack(); 
 +    myPack.addProvider(MyChestLootTables::new);
 } }
 </code> </code>
 +
 +If you're using versions pre-1.20, please replace ''myPack.addProvider(MyBlockLootTables::new);'' with ''fabricDataGenerator.addProvider(MyBlockLootTables::new);''。You can also remove ''FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack();''
tutorial/datagen_loot.1663346273.txt.gz · Last modified: 2022/09/16 16:37 by nexus-dino