Minecraft Addons Enchantments API Documentation
This documentation provides an overview of the main APIs and data structures available for working with enchantments in Minecraft addons, focusing on Bedrock Edition scripting and JSON, as well as Java modding APIs (Spigot/Bukkit and Fabric). It covers how to define, apply, and manage enchantments programmatically and via data files.
Bedrock Edition: Script API & JSON
Enchantments in Bedrock can be managed via scripting and item JSON components.
Enchantment Interface
Represents a specific leveled enchantment applied to an item.
- Properties:
level: number — The level of this enchantment.
type: EnchantmentType — The type of enchantment (e.g., sharpness, protection)[1].
ItemEnchantableComponent
Allows manipulation of enchantments on an item stack.
Key Methods:
| Method | Description |
|---|
addEnchantment(e) | Adds a single enchantment to the item stack. |
addEnchantments([e1, e2]) | Adds multiple enchantments at once. |
canAddEnchantment(e) | Checks if an enchantment can be added to the item stack. |
getEnchantment(type) | Retrieves a specific enchantment by type. |
getEnchantments() | Returns all enchantments on the item stack. |
hasEnchantment(type) | Checks if the item stack has a specific enchantment. |
removeAllEnchantments() | Removes all enchantments from the item stack. |
removeEnchantment(type) | Removes a specific enchantment by type. |
- Component ID:
minecraft:enchantable[6].
JSON Item Component: minecraft:enchantable
Defines what enchantments can be applied to an item via JSON.
| Property | Type | Description | Example Value |
|---|
| slot | String | Enchantment slot type (e.g., sword, bow, armor_head, etc.) | "armor_torso" |
| value | Integer | Enchantability value (minimum 0) | 10 |
Example:
"minecraft:enchantable": {
"slot": "armor_torso",
"value": 10
}
[4][15]
Java Edition: Bukkit/Spigot API
The Bukkit/Spigot API provides a robust system for managing enchantments, including custom ones.
Enchantment Class
Represents a type of enchantment.
- Key Methods:
getName(): Returns the unique name of the enchantment.
getMaxLevel(): Maximum level of the enchantment.
getStartLevel(): Starting level.
canEnchantItem(ItemStack item): Checks if the enchantment can be applied to the item.
conflictsWith(Enchantment other): Checks for conflicts with another enchantment.
isCursed(), isTreasure(): Flags for special enchantments.
getKey(): Namespaced identifier[3].
Common Enchantments: (partial list)
PROTECTION, FIRE_PROTECTION, SHARPNESS, EFFICIENCY, UNBREAKING, MENDING, etc.[3]
Creating Custom Enchantments
Use plugins like CustomEnchantment API or AdvancedEnchantments for easier custom enchantment creation.
CustomEnchantment API Example:
public class MyEnchant extends CustomEnchantment {
public MyEnchant(int id, String name, int lvl, EnchantmentTarget target, int start, boolean cursed, boolean treasure, List<enchantment> conf, EventTrigger eventtrigger, boolean visible) {
super(id, name, lvl, target, start, cursed, treasure, conf, eventtrigger, visible);
}
@Override
public void enchantmentEffect(Event event, int lvl) {
// Custom effect logic here
}
}
- Register with:
EnchAPI.loadEnchantment(CustomEnchantment)
- Apply to item:
YourEnchantment.enchant(ItemStack item, int level)[5][14][16]
Java Edition: Fabric API
Fabric supports both data-driven and code-driven enchantments.
Data-Driven Enchantments (1.21+)
- Define enchantments in datapacks (JSON files).
- Reference via
RegistryKey<enchantment> in code[7].
Code-Driven Enchantments
- Extend the
Enchantment class.
- Override methods like
getMinPower, getMaxLevel, onTargetDamaged, etc.
Example:
public class FrostEnchantment extends Enchantment {
public FrostEnchantment() {
super(Rarity.UNCOMMON, EnchantmentTarget.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND});
}
@Override
public int getMinPower(int level) { return 1; }
@Override
public int getMaxLevel() { return 3; }
@Override
public void onTargetDamaged(LivingEntity user, Entity target, int level) {
if (target instanceof LivingEntity livingEntity) {
livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 40 * level, level - 1));
}
super.onTargetDamaged(user, target, level);
}
}
- Register with:
Registry.register(Registries.ENCHANTMENT, new Identifier("modid", "frost"), FROST);[7][18]
Key Concepts Across APIs
| Concept | Bedrock (Script/JSON) | Bukkit/Spigot API | Fabric API |
|---|
| Enchantment Instance | Enchantment interface | Enchantment class | Enchantment class |
| Apply to Item | addEnchantment, JSON component | ItemStack.addEnchantment() | Custom logic or data-driven |
| Custom Enchantments | Script logic, lore, or JSON | Extend CustomEnchantment | Extend Enchantment or datapack |
| Enchantability | value in JSON | N/A (handled by enchantment logic) | N/A (handled by enchantment logic) |
| Enchantment Slots | slot in JSON | EnchantmentTarget | EnchantmentTarget |
| Conflict Checking | N/A (script logic) | conflictsWith() | canAccept()/canCombine() |
Additional Resources
- Bedrock Script API Reference: Official Microsoft Docs[1][6]
- Bukkit/Spigot Javadocs: SpigotMC Developer Hub[3]
- Fabric Enchantments: Fabric Wiki & Documentation[7][18]
- Custom Enchantment Plugins: CustomEnchantment API, AdvancedEnchantments[5][8][14]
Summary
- Bedrock: Use scripting and JSON to define, apply, and manage enchantments on items.
- Bukkit/Spigot: Use the Enchantment class and plugins/APIs to create and manage both vanilla and custom enchantments.
- Fabric: Supports both data-driven (JSON/datapack) and code-driven (Java class) enchantments, with full control over effects and registration.
For implementation details, always refer to the latest official documentation and community guides for your specific Minecraft version and platform.