API reference Obsidian.API.Loot
EnchantmentHelper class
Vanilla's enchanting logic (EnchantmentHelper) for item stacks: picking enchantments for an enchanting power and adding them to a stack.
public static class EnchantmentHelper
In Obsidian.API.
Methods
Enchant(ItemStack, EnchantmentDefinition, int)
public static void Enchant(ItemStack stack, EnchantmentDefinition enchantment, int level);Adds enchantment at level to the stack's enchantments (stored enchantments for an enchanted book), keeping the higher level if the stack already has it.
EnchantItem(IRandomSource, ItemStack, int, IReadOnlyList<EnchantmentDefinition>)
public static ItemStack EnchantItem(IRandomSource random, ItemStack stack, int level, IReadOnlyList<EnchantmentDefinition> options);Enchants stack like an enchanting table would at level levels, picking from options. A book becomes a new single enchanted book; other stacks are enchanted in place.
GetEnchantments(ItemStack)
public static Enchantment[] GetEnchantments(ItemStack stack);The stack's enchantments, or the stored enchantments of an enchanted book. The array is a copy.
SelectEnchantments(IRandomSource, ItemStack, int, IReadOnlyList<EnchantmentDefinition>)
public static List<(EnchantmentDefinition, int)> SelectEnchantments(IRandomSource random, ItemStack stack, int level, IReadOnlyList<EnchantmentDefinition> options);Picks the enchantments (and levels) an enchanting table would give stack at level levels. Draws nothing for items that can't be enchanted.
SetEnchantments(ItemStack, Enchantment[])
public static void SetEnchantments(ItemStack stack, Enchantment[] enchantments);Replaces the stack's enchantments, or the stored enchantments of an enchanted book.