-
Notifications
You must be signed in to change notification settings - Fork 0
Enchantment Data Generation
Maksym Uimanov edited this page Feb 10, 2026
·
1 revision
The @GenerateEnchantment annotation is a data generation annotation that automatically creates enchantment definitions for Minecraft mods using the Temporal API. It provides a structured approach to defining enchantments without manual JSON configuration by using description classes.
- Automatic data generation: Creates enchantment definitions without manual JSON files
-
Description-based configuration: Uses
EnchantmentDescriptionclasses to define enchantment properties - Type safety: Ensures compile-time validation of enchantment configurations
- Integration with data providers: Seamlessly integrates with NeoForge's enchantment data generation system
-
Annotation processing: The annotation is processed by
GenerateEnchantmentStrategyduring the data generation phase -
Field extraction: The strategy extracts the
ResourceKey<Enchantment>from the annotated field -
Description instantiation: Creates an instance of the specified
EnchantmentDescriptionclass -
Builder registration: Registers the enchantment description with
ApiEnchantmentProviderfor data generation
public class CustomEnchantmentDescription implements EnchantmentDescription {
@Override
public Enchantment.Builder build(HolderGetter<Enchantment> enchantments, HolderGetter<Item> items) {
return Enchantment.enchantment(Enchantment.definition(
items.getOrThrow(ItemTags.SWORD_ENCHANTABLE),
5, // max level
2, // anvil cost
Enchantment.dynamicCost(5, 20), // min cost
Enchantment.dynamicCost(55, 20), // max cost
2, // min level for treasure
EquipmentSlotGroup.MAINHAND))
.withEffect(
EnchantmentEffectComponents.POST_ATTACK,
EnchantmentTarget.ATTACKER,
EnchantmentTarget.VICTIM,
new CustomEnchantmentEffect()
);
}
}public final class ModEnchantments {
@GenerateEnchantment(CustomEnchantmentDescription.class)
public static final ResourceKey<Enchantment> CUSTOM_ENCHANTMENT =
ResourceUtils.createKey(Registries.ENCHANTMENT, "custom_enchantment");
}- value (Class<? extends EnchantmentDescription>): The description class that defines the enchantment's properties and effects
The annotation integrates with the Temporal API's strategy system:
-
Strategy implementation:
GenerateEnchantmentStrategyhandles the processing logic -
Provider system: Uses
ApiEnchantmentProviderfor data generation -
Description interface:
EnchantmentDescriptionprovides a flexible way to define enchantment properties
Use @GenerateEnchantment when:
- Creating custom enchantments for your mod
- Defining enchantments with complex effects and properties
- Automating data generation for enchantment content
- Ensuring consistent enchantment configuration across your mod
The annotation is particularly useful for mods with multiple enchantments, as it centralizes enchantment logic and eliminates manual JSON file management while providing full access to Minecraft's enchantment builder API.
🚀 Getting Started
🧩 Core Concepts
⚙️ Data Generation
- ⚙️ Advancement
- ⚙️ Damage Type
- ⚙️ Chest Loot Modifier
- ⚙️ Recipe
- ⚙️ Sound
- ⚙️ Jukebox Song
- ⚙️ Enchantment
- ⚙️ Trim Material
- ⚙️ Trim Pattern
- ⚙️ Banner Pattern
- ⚙️ Painting Variant
- ⚙️ Particle Sprite Set
- ⚙️ Wolf Variant
- ⚙️ Item Model
- ⚙️ Block Model
- ⚙️ Block Loot Table
- ⚙️ Tag
- ⚙️ Language Translation
- ⚙️ World Feature
- ⚙️ Custom Properties
🚨 Events
🛠 Engine Layers
🧪 Resources
- 🧪 Examples