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
tutorial:datagen_loot [2025/04/01 13:34] solidblocktutorial:datagen_loot [2025/04/01 13:47] (current) solidblock
Line 4: Line 4:
  
 ===== Block loot tables ===== ===== Block loot tables =====
-To create add a data generation for block loot tables, just create a class which extends ''FabricBlockLootTableProvider''.+To add a data generation for block loot tables, just create a class which extends ''FabricBlockLootTableProvider''.
  
 <code java TutorialBlockLootTableProvider.java> <code java TutorialBlockLootTableProvider.java>
Line 34: Line 34:
  
 In the previous [[blocks]] tutorial, we created an //example block//. Now let's use the data generator to generate its loot table. It's as simple as: In the previous [[blocks]] tutorial, we created an //example block//. Now let's use the data generator to generate its loot table. It's as simple as:
-<code java TutorialBlockLootTableProvider>+<code java TutorialBlockLootTableProvider.java>
   @Override   @Override
   public void generate() {   public void generate() {
Line 48: Line 48:
     addDrop(TutorialBlocks.EXAMPLE_BLOCK, dropsNothing());     addDrop(TutorialBlocks.EXAMPLE_BLOCK, dropsNothing());
          
-    // drops a dirt when mined+    // drops a dirt block
     addDrop(TutorialBlocks.EXAMPLE_BLOCK, Blocks.DIRT);     addDrop(TutorialBlocks.EXAMPLE_BLOCK, Blocks.DIRT);
          
Line 60: Line 60:
     addDrop(TutorialBlocks.EXAMPLE_BLOCK, dropsWithSilkTouchOrShears(TutorialBlocks.EXAMPLE_BLOCK));     addDrop(TutorialBlocks.EXAMPLE_BLOCK, dropsWithSilkTouchOrShears(TutorialBlocks.EXAMPLE_BLOCK));
          
-    // drops three blocks+    // drops five blocks
     addDrop(TutorialBlocks.EXAMPLE_BLOCK, drops(TutorialBlocks.EXAMPLE_BLOCK)     addDrop(TutorialBlocks.EXAMPLE_BLOCK, drops(TutorialBlocks.EXAMPLE_BLOCK)
         .apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(5))));         .apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(5))));
 </code> </code>
  
-You can also generate data for the [[crops]] we introduced before:+You can also generate loot tables for the [[crops]] we introduced before:
 <code java> <code java>
     addDrop(TutorialBlocks.CUSTOM_CROP, cropDrops(TutorialBlocks.CUSTOM_CROP, TutorialItems.CUSTOM_ITEM, TutorialItems.CUSTOM_SEEDS, BlockStatePropertyLootCondition.builder(TutorialBlocks.CUSTOM_CROP).properties(StatePredicate.Builder.create().exactMatch(CropBlock.AGE, 7))));     addDrop(TutorialBlocks.CUSTOM_CROP, cropDrops(TutorialBlocks.CUSTOM_CROP, TutorialItems.CUSTOM_ITEM, TutorialItems.CUSTOM_SEEDS, BlockStatePropertyLootCondition.builder(TutorialBlocks.CUSTOM_CROP).properties(StatePredicate.Builder.create().exactMatch(CropBlock.AGE, 7))));
Line 105: Line 105:
 </code> </code>
  
-If you're using versions pre-1.20, please replace ''pack.addProvider(TutorialChestLootTableProvider::new);'' with ''fabricDataGenerator.addProvider(TutorialChestLootTableProvider::new);'', and remove ''FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack();''.+If you're using versions pre-1.20, please replace ''pack.addProvider(TutorialChestLootTableProvider::new);'' with ''fabricDataGenerator.addProvider(TutorialChestLootTableProvider::new);'', and remove ''FabricDataGenerator.Pack myPack = fabricDataGenerator.createPack();''.
  
-Now run the data generator, then start Minecraft and run the command ''/loot give @s loot tutorial:test_chest'' multiple times. See what happens!+Now run the data generator, then start Minecraft and run the command ''/loot give @s loot tutorial:test_chest'' multiple times. See what happens! You can also try running the command ''/setblock ~ ~ ~ chest{LootTable:"tutorial:test_chest"}'' and open the chest.
tutorial/datagen_loot.txt · Last modified: 2025/04/01 13:47 by solidblock