User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:datagen_advancements

To get started with this, create a class that extends FabricAdvancementProvider and register it in your datagen entrypoint like so:

private static class MyAdvancementGenerators extends FabricAdvancementProvider {
 
     protected MyAdvancementGenerators(FabricDataGenerator dataGenerator) {
         super(dataGenerator);
     }
 
     @Override
     public void generateAdvancement(Consumer<Advancement> consumer) {
         // ...
     }
}
 
// ...
 
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
    // ...
    fabricDataGenerator.addProvider(MyAdvancementGenerators::new);
    // ...
}

Advancements

A quick summary, to create an advancement, you need a parent advancement. A parent advancement is an advancement tab, that's all.

The recommended way to make advancements by the type of advancements you are making followed by 'AdvancementGenerator'.

CAUTION: Before reading more of this, we recommend to read the Block tutorial first.

For this example, we are going to trigger our custom advancement when the user mines our example block.

ADVANCEMENT GENERATOR

first, create a generator class like so:

private static class CustomAdvancementsGenerator implements Consumer<Consumer<Advancement>> {
 
    @Override
    public void accept(Consumer<Advancement> consumer) {
	// This is our advancement
	// The difference: 
 
	Advancement parentAdvancement = Advancement.Builder.create()
		.display(Tutorial.EXAMPLE_BLOCK, Text.translatable("advancements.custom.title"),
			Text.translatable("advancements.custom.description"),
			new Identifier("textures/gui/advancements/backgrounds/husbandry.png"),
			AdvancementFrame.TASK,
			// whether to show a toast that appears on the top-right corner
			false,
			// whether to announce to chat
			false,
			// whether its hidden in the advancement tab
			false)
		.build(consumer, "custom/root");
 
	Advancement exampleBlockAdvancement = Advancement.Builder.create()
		.parent(parentAdvancement)
		.criterion("inventory_changed", InventoryChangedCriterion.Conditions.items(Items.ACACIA_BOAT))
		.build(consumer, "custom/example_block_in_inventory");
    }
}

Now that we created our advancement in our generator, we register it in our advancements:

private static class MyAdvancementGenerators extends FabricAdvancementProvider {
     private final List<Consumer<Consumer<Advancement>>> generators = Util.make(Lists.newArrayList(), list -> {
          list.add(new CustomAdvancementsGenerator());
     });
 
     protected MyAdvancementGenerators(FabricDataGenerator dataGenerator) {
         super(dataGenerator);
     }
 
     @Override
     public void generateAdvancement(Consumer<Advancement> consumer) {
         list.forEach(i -> i.accept(consumer));
     }
}

Let's run our datagen run config and the advancements jsons are waiting for us!

tutorial/datagen_advancements.txt · Last modified: 2022/09/14 19:39 by nexus-dino