User Tools

Site Tools


tutorial:datagen_advancements

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
Next revisionBoth sides next revision
tutorial:datagen_advancements [2022/12/22 11:52] – [One More Simple Example] jmanc3tutorial:datagen_advancements [2023/09/24 18:52] – Use new minecraft wiki mattidragon
Line 13: Line 13:
 Unfortunately there's like three layers of indirection before we can actually start adding some advancements, but we'll go one layer at a time. First things first, in the ''DataGeneration'' file we created earlier, add the following: Unfortunately there's like three layers of indirection before we can actually start adding some advancements, but we'll go one layer at a time. First things first, in the ''DataGeneration'' file we created earlier, add the following:
  
-<code java [highlight_lines_extra="11"]>+<code java [highlight_lines_extra="13"]>
 import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
 import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
Line 21: Line 21:
     @Override     @Override
     public void onInitializeDataGenerator(FabricDataGenerator generator) {     public void onInitializeDataGenerator(FabricDataGenerator generator) {
 +        FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
 +        
         /**          /** 
         /* Add our advancements generator         /* Add our advancements generator
          **/          **/
-        generator.createPack().addProvider(AdvancementsProvider::new);+        pack.addProvider(AdvancementsProvider::new);
  
         // .. (Your other generators)         // .. (Your other generators)
Line 214: Line 216:
   * This name is only ever used by ''requirements'' (another property we can add to advancements) which make it so that before an advancement activates, the ''requirements'' (other advancements) need to be fulfilled first. In other words, it mostly doesn't matter what name you give the criterion.   * This name is only ever used by ''requirements'' (another property we can add to advancements) which make it so that before an advancement activates, the ''requirements'' (other advancements) need to be fulfilled first. In other words, it mostly doesn't matter what name you give the criterion.
  
-The second argument is the criterion. In our example we use the ''InventoryChangedCriterion'' and we pass it the item we want it to trigger for ''Items.DIRT''. But there are many criterions. The Minecraft Wiki has them listed as "[[https://minecraft.fandom.com/wiki/Advancement/JSON_format|List of triggers]]". But the better reference to use is the Minecraft source itself. (If you haven't generated the source yet, read [[tutorial:setup#generating_minecraft_sources|here]].) You can take a look at the ''net.minecraft.advancement.criterion'' folder where they are all located and see what's already available.+The second argument is the criterion. In our example we use the ''InventoryChangedCriterion'' and we pass it the item we want it to trigger for ''Items.DIRT''. But there are many criterions. The Minecraft Wiki has them listed as "[[https://minecraft.wiki/w/Advancement/JSON_format#List_of_triggers|List of triggers]]". But the better reference to use is the Minecraft source itself. (If you haven't generated the source yet, read [[tutorial:setup#generating_minecraft_sources|here]].) You can take a look at the ''net.minecraft.advancement.criterion'' folder where they are all located and see what's already available.
  
 | PlayerHurtEntityCriterion.class | ImpossibleCriterion.class | Criterion.class | AbstractCriterion.class | VillagerTradeCriterion.class | PlayerHurtEntityCriterion.class | ImpossibleCriterion.class | Criterion.class | AbstractCriterion.class | VillagerTradeCriterion.class
Line 457: Line 459:
  
   * Because we aren't implementing a full blown mod we pretend a function ''checkedPlayerStateAndHesJumpedOneHundredTimes'' exists and returns true when the player has done more than one-hundred jumping jacks.   * Because we aren't implementing a full blown mod we pretend a function ''checkedPlayerStateAndHesJumpedOneHundredTimes'' exists and returns true when the player has done more than one-hundred jumping jacks.
 +
 +  * **NOTE:** You must call ''Criteria.register'' with your custom made criterion, or your game won't award the advancements. (And it MUST be done server side, which is why we do this in the ''ModInitializer'' class).
  
 If you run your game now (changing that fake function to a simple ''true'' so it compiles), when you log into a world, you should be granted the jumping jack advancement, but because we are using the server join event here to do this, it gives it to you before you load in, which is why you don't get a toast message. If you open up the advancements page in the escape menu, you'll see it was in fact granted. If you run your game now (changing that fake function to a simple ''true'' so it compiles), when you log into a world, you should be granted the jumping jack advancement, but because we are using the server join event here to do this, it gives it to you before you load in, which is why you don't get a toast message. If you open up the advancements page in the escape menu, you'll see it was in fact granted.
tutorial/datagen_advancements.txt · Last modified: 2023/10/02 23:11 by jmanc3