User Tools

Site Tools


tutorial:datagen_loot

This is an old revision of the document!


Before reading this, make sure you have a class that implements DataGenerationEntrypoint

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:

Setting Up

private static class MyBlockLootTables extends SimpleFabricLootTableProvider {
    public MyBlockLootTables(FabricDataGenerator dataGenerator) {
         super(dataGenerator, LootContextTypes.BLOCK);
    }
 
    @Override
    public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {
        // ...
    }
}
 
// ...
 
 
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
    fabricDataGenerator.addProvider(MyBlockLootTables::new);
}

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.

public static final Block TEST_ORE = Registry.register(Registry.BLOCK, new Identifier("tutorial", "test_ore"), new Block(...));
 
public static final Item TEST_ITEM = Registry.register(Registry.ITEM, new Identifier("tutorial", "test_item", new Item(...));
// Let's just ignore the fact that there isn't a block item ๐Ÿ˜…

ADDING BLOCK LOOT

private static class MyBlockLootTables extends SimpleFabricLootTableProvider {
    public MyBlockLootTables(FabricDataGenerator dataGenerator) {
         super(dataGenerator, LootContextTypes.BLOCK);
    }
 
    @Override
    public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {
    // The BlockLootTableGenerator class contains a behemoth of utility methods. Just take some time and go through the methods available to override.
        biConsumer.accept(new Identifier("tutorial", "test_block"), BlockLootTableGenerator.drops(Tutorial.TEST_BLOCK, Tutorial.TEST_ITEM, ConstantLootNumberProvider.create(9.0F)));
    }
}

Now that we successfully adding a block. Now let's add chest loot.

Firstly, we need an identifier.

// In Tutorial class
public static final Identifier TEST_CHEST = new Identifier("tutorial", "chests/test_loot");

TODO

tutorial/datagen_loot.1663186993.txt.gz ยท Last modified: 2022/09/14 20:23 by nexus-dino