Minecraft enchantments offer a powerful way to enhance gameplay by adding special abilities to items. This documentation covers the various approaches to working with enchantments across different Minecraft platforms and versions.
Enchantment Systems Overview
Minecraft offers different approaches to enchantments depending on which version and platform you're developing for:
Bedrock Edition: Uses component-based system with Script API
Java Edition: Uses class-based systems through Bukkit/Spigot or Fabric/Forge
Modern Java (1.21+): Shifted to data-driven enchantments through datapacks
Bedrock Edition Enchantment API
Enchantment Interface
The Enchantment interface in Bedrock represents a specific leveled enchantment applied to an item[1].
javascript
// Properties of an Enchantment
interface Enchantment {
level: number; // The level of this enchantment instance
type: EnchantmentType; // The enchantment type of this instance
}
ItemEnchantableComponent
This component allows items to receive enchantments[6].
javascript
// Accessing enchantments on an item
const enchantableComponent = item.getComponent("minecraft:enchantable");
// Methods
enchantableComponent.addEnchantment(enchantment); // Add single enchantment
enchantableComponent.addEnchantments(enchantments); // Add multiple enchantments
enchantableComponent.canAddEnchantment(enchantment); // Check if enchantment can be added
enchantableComponent.getEnchantment(enchantmentType); // Get specific enchantment
enchantableComponent.getEnchantments(); // Get all enchantments
enchantableComponent.hasEnchantment(enchantmentType); // Check for specific enchantment
enchantableComponent.removeAllEnchantments(); // Remove all enchantments
enchantableComponent.removeEnchantment(enchantmentType); // Remove specific enchantment
JSON Component Definition
The minecraft:enchantable component in Bedrock item definitions determines what enchantments can be applied to an item[4][15].
json
"minecraft:enchantable": {
"slot": "sword", // Enchantment slot type
"value": 10 // Enchantment value (minimum of 0)
}
Bukkit/Spigot provides an abstract Enchantment class that represents enchantments in Minecraft[3].
java
public abstract class Enchantment extends Object implements Keyed, Translatable, RegistryAware {
// Key methods
public abstract int getMaxLevel();
public abstract int getStartLevel();
public abstract boolean conflictsWith(Enchantment other);
public abstract boolean canEnchantItem(ItemStack item);
}
Built-in Enchantment Types
The Bukkit API provides constants for all vanilla enchantments[3][18]:
java
Enchantment.PROTECTION // Environmental protection
Enchantment.FIRE_PROTECTION // Fire protection
Enchantment.SHARPNESS // Increases damage against all targets
Enchantment.EFFICIENCY // Increases mining/digging speed
Enchantment.MENDING // Repairs items with experience
Enchantment.DENSITY // Increases fall damage of maces (newer versions)
Enchantment.BREACH // Reduces armor effectiveness against maces
Enchantment.WIND_BURST // Emits wind burst upon hitting enemy
Creating Custom Enchantments (Bukkit)
For pre-1.20 versions, custom enchantments required reflection to modify internal field values. Since 1.20, Bukkit has added a method to register custom enchantments directly[12].
Using CustomEnchantment API plugin:
java
// Constructor example
new CustomEnchantment(
int id, // Enchantment ID (use values > 100)
String name, // Enchantment display name
int lvl, // Max level
EnchantmentTarget target, // What items can have this enchantment
int start, // Minimum enchantment level
boolean cursed, // Is this a curse?
boolean treasure, // Is this a treasure enchantment?
List<enchantment> conf, // Conflicting enchantments
EventTrigger eventtrigger, // Event that triggers this enchantment
boolean visible // Show in item lore?
)
// Register enchantment
EnchAPI.loadEnchantment(myCustomEnchantment);
Fabric/Forge Enchantment API
Modern Enchantments (1.21+)
Since Minecraft 1.21, enchantments have become data-driven, meaning they are defined in datapacks rather than directly in code[7][17]:
java
// Store registry keys for your enchantments
public final class TutorialEnchantments {
public static final RegistryKey<enchantment> FROST = of("frost");
private static RegistryKey<enchantment> of(String name) {
return RegistryKey.of(RegistryKeys.ENCHANTMENT, Identifier.of("tutorial", name));
}
public static void initialize() { }
}
Pre-1.21 Implementation
For older versions, custom enchantments were created by extending the Enchantment class[7][17]:
java
public class FrostEnchantment extends Enchantment {
public FrostEnchantment() {
super(Enchantment.Rarity.UNCOMMON, EnchantmentTarget.WEAPON,
new EquipmentSlot[] {EquipmentSlot.MAINHAND});
}
@Override
public int getMinPower(int level) {
return 1;
}
@Override
public int getMaxLevel() {
return 3;
}
public void onTargetDamaged(LivingEntity user, Entity target, int level) {
if(target instanceof LivingEntity) {
((LivingEntity) target).addStatusEffect(
new StatusEffectInstance(StatusEffects.SLOWNESS, 20 * 2 * level, level - 1)
);
}
super.onTargetDamaged(user, target, level);
}
}
Creating Custom Enchantment Effects (1.21+)
For modern Fabric implementations, custom enchantment effects are created through a dedicated class[13]:
java
public record LightningEnchantmentEffect(EnchantmentLevelBasedValue amount)
implements EnchantmentEntityEffect {
public static final MapCodec<lightningenchantmenteffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
EnchantmentLevelBasedValue.CODEC.fieldOf("amount").forGetter(LightningEnchantmentEffect::amount)
).apply(instance, LightningEnchantmentEffect::new)
);
@Override
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
if (target instanceof LivingEntity victim && context.owner() instanceof PlayerEntity player) {
float numStrikes = this.amount.getValue(level);
for (float i = 0; i < numStrikes; i++) {
BlockPos position = victim.getBlockPos();
EntityType.LIGHTNING_BOLT.spawn(world, position, SpawnReason.TRIGGERED);
}
}
}
@Override
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
return CODEC;
}
}
Custom Enchantment Categories
MCreator Approach
For MCreator users, custom enchantment categories can be created[10][16]:
java
public class AECategory {
public static final EnchantmentCategory HOE = EnchantmentCategory.create(
"hoe",
item -> item instanceof HoeItem
);
// For multiple items
public static final EnchantmentCategory TOOLS = EnchantmentCategory.create(
"tools",
item -> item instanceof AxeItem ||
item instanceof ShovelItem ||
item instanceof PickaxeItem
);
}
Defining Enchantment Compatibility
Control which enchantments can be combined[10][16]:
java
@Override
protected boolean checkCompatibility(Enchantment ench) {
if (ench == Enchantments.THORNS)
return false;
if (ench == Enchantments.BANE_OF_ARTHROPODS)
return false;
if (ench == Enchantments.SHARPNESS)
return false;
if (ench == Enchantments.SMITE)
return false;
return true;
}
Bedrock Script API Custom Enchantments
For Bedrock Edition, custom enchantments can be implemented via the Script API[11]:
javascript
// Basic system using lore as storage
world.beforeEvents.entityHurt.subscribe(event => {
const player = event.damageSource.damagingEntity;
if (player?.id !== "minecraft:player") return;
// Get player's held item
const inventory = player.getComponent("inventory");
const container = inventory.container;
const weapon = container.getItem(player.selectedSlot);
if (weapon && weapon.getLore()?.includes("explode")) {
// Create explosion when entity is hit
world.createExplosion(player.headLocation, 1);
}
});
// Apply enchantment example
world.beforeEvents.chatSend.subscribe(event => {
const player = event.sender;
const inventory = player.getComponent("inventory");
const container = inventory.container;
const heldItem = container.getItem(player.selectedSlot);
if (heldItem) {
heldItem.setLore(["explode"]);
container.setItem(player.selectedSlot, heldItem);
}
});
Summary of Key Concepts
Enchantment Properties: Level, type, and compatibility with other enchantments.
Item Compatibility: Determines which items can receive which enchantments.
Enchantment Effects: Custom logic that executes when conditions are met.
Registration: Process for making custom enchantments available in the game.
Events: Triggers for when enchantment effects should activate.
This documentation provides a foundation for working with enchantments across different Minecraft platforms and versions. For implementation details specific to your platform, consult the relevant API documentation for the most up-to-date information.