tutorial:datagen_loot
This is an old revision of the document!
Table of Contents
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.
ADDING CHEST LOOT
Firstly, we need an identifier.
// In Tutorial class public static final Identifier TEST_CHEST = new Identifier("tutorial", "chests/test_loot");
Let's create a chest loot table generator and register it like so.
public class MyChestLootTables extends SimpleFabricLootTableProvider { public MyChestLootGenerator(FabricDataGenerator dataGenerator) { super(dataGenerator, LootContextTypes.CHEST); } @Override public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) { biConsumer.accept(Tutorial.TEST_CHEST, LootTable.builder() .pool(LootPool.builder().rolls(ConstantLootNumberProvider.create(1.0F)) .with(ItemEntry.builder(Items.DIAMOND) .apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(1.0F))) .with(ItemEntry.builder(Items.DIAMOND_SWORD)).apply(EnchantWithLevelsLootFunction.create(UniformLootNumberProvider.create(20.0F, 39.0F)))) ); } }
tutorial/datagen_loot.1663345807.txt.gz · Last modified: 2022/09/16 16:30 by nexus-dino