Script API - v26.60
    Preparing search index...

    Class EnchantmentTypes

    Contains a catalog of Minecraft Enchantment Types that are available in this world.

    export class EnchantmentTypes {
    private constructor();
    static get(enchantmentId: string): EnchantmentType | undefined;
    static getAll(): EnchantmentType[];
    }
    Index
    • Parameters

      • enchantmentId: string

        Identifier of the enchantment. For example, "minecraft:flame".

      Returns EnchantmentType | undefined

      If available, returns an EnchantmentType object that represents the specified enchantment.

      Retrieves an enchantment with the specified identifier.

      This function can't be called in early-execution mode.

      import { EnchantmentTypes, Player, system } from "@minecraft/server";

      // Run `/scriptevent example:getsharpnessenchantment` in chat to inspect the sharpness enchantment.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:getsharpnessenchantment" || !(sourceEntity instanceof Player)) return;

      const enchantmentType = EnchantmentTypes.get("minecraft:sharpness");
      if (!enchantmentType) return;

      sourceEntity.sendMessage(`Found enchantment: ${enchantmentType.id} (max level ${enchantmentType.maxLevel})`);
      });
    • Returns EnchantmentType[]

      Returns a collection of all available enchantment types.

      This function can't be called in early-execution mode.

      import { EnchantmentTypes, Player, system } from "@minecraft/server";

      // Run `/scriptevent example:listenchantments` in chat to list registered enchantment IDs.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:listenchantments" || !(sourceEntity instanceof Player)) return;

      const enchantmentIds = EnchantmentTypes.getAll().map((enchantmentType) => enchantmentType.id);
      sourceEntity.sendMessage(`Enchantments (${enchantmentIds.length}): ${enchantmentIds.slice(0, 10).join(", ")}`);
      });