User Tools

Site Tools


tutorial:datagen_tags

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorial:datagen_tags [2022/08/08 20:05] – created mineblock11tutorial:datagen_tags [2023/06/05 18:22] (current) – [Adding stuff to the builder] mcrafterzz
Line 1: Line 1:
 ====== Tag Generation ====== ====== Tag Generation ======
  
-The ''FabricTagProvider<T>'' class allows you to generate tag json files.+The ''[[https://github.com/FabricMC/fabric/blob/1.19.2/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricTagProvider.java|FabricTagProvider<T>]]'' class allows you to generate tag json files.
  
 This page will follow you through all aspects of this provider. This page will follow you through all aspects of this provider.
  
-To create a ''FabricTagProvider<T>'' create a class that extends it and register it at your entrypoint like so:+To create a tag generator, create a class that extends ''FabricTagProvider<T>'', where ''T'' is the type of tag you want to generate, and register it at your datagen entrypoint like so:
  
 <code java> <code java>
-private static class MyTagGenerator extends FabricTagProvider<Item> +private static class MyTagGenerator extends ItemTagProvider 
-   public MyTagGenerator(FabricDataGenerator dataGenerator) { +   public MyTagGenerator(FabricDataOutput output, CompletableFuture<WrapperLookup> completableFuture) { 
-       super(dataGeneratorRegistry.ITEM);+        super(outputcompletableFuture);
    }    }
  
    @Override    @Override
-   protected void generateTags() { +   protected void configure(WrapperLookup arg) { 
 +   
    }    }
 } }
Line 33: Line 33:
 ===== Adding a tag ===== ===== Adding a tag =====
  
-To add a tag, simply call the ''getOrCreateTagBuilder'' method with your supplied ''TagKey<T>'' in the ''generateTags()'' method like so:+To add a tag, simply call the ''getOrCreateTagBuilder'' method with your supplied ''TagKey<T>'' in the ''configure(WrapperLookup arg)'' method like so:
  
 <code java> <code java>
-private static final TagKey<Item> SMELLY_ITEMS = TagKey.of(Registry.ITEM_KEY, new Identifier("mymod:smelly_items"));+private static final TagKey<Item> SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM_KEY, new Identifier("mymod:smelly_items"));
    
 @Override @Override
-protected void generateTags() {+protected void configure(WrapperLookup arg) {
      // This creates a tag builder, where we add slime balls, rotten flesh and everything in the minecraft:dirt item tag.      // This creates a tag builder, where we add slime balls, rotten flesh and everything in the minecraft:dirt item tag.
      getOrCreateTagBuilder(SMELLY_ITEMS)      getOrCreateTagBuilder(SMELLY_ITEMS)
Line 48: Line 48:
 } }
 </code> </code>
 +
 +Output from the example above:
 +
 +<file javascript smelly_items.json>
 +{
 +  "replace": false,
 +  "values": [
 +    "minecraft:slime_ball",
 +    "minecraft:rotten_flesh",
 +    {
 +      "id": "#minecraft:dirt",
 +      "required": false
 +    }
 +  ]
 +}
 +</file>
  
 ===== Adding stuff to the builder ===== ===== Adding stuff to the builder =====
Line 64: Line 80:
  
 <code java> <code java>
-private static final TagKey<Item> SMELLY_ITEMS = TagKey.of(Registry.ITEM_KEY, new Identifier("mymod:smelly_items"));+private static final TagKey<Item> SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM_KEY, new Identifier("mymod:smelly_items"));
  
 @Override @Override
-protected void generateTags() {+protected void configure(WrapperLookup arg) {
      getOrCreateTagBuilder(SMELLY_ITEMS)      getOrCreateTagBuilder(SMELLY_ITEMS)
                     .add(Items.SLIME_BALL)                     .add(Items.SLIME_BALL)
tutorial/datagen_tags.1659989141.txt.gz · Last modified: 2022/08/08 20:05 by mineblock11