#Enchant Remover

1 messages · Page 1 of 1 (latest)

crude sinew
#
/**
 * Removes an enchant from an ItemStack
 * @param item 
 * @param enchantId 
 * @returns the ItemStack if the enchant was successfully removed
 */
export function removeEnchant(item: ItemStack, enchantId: string): ItemStack|null{
    const enchantable = item.getComponent('enchantable')
    if (!enchantable) return null;

    const enchants = enchantable.getEnchantments()

    const enchant = enchants.find(ench => ench.type.id === enchantId)
    if (!enchant) return null;

    enchantable.removeEnchantment(enchant.type)
    return item
}
#

If you want to remove the enchantment from all the inventory just loop through the inventory and pass the item to this function and set the ItemStack returned to the slot.