====== cEnchantments class ======
This class  is the storage for enchantments for a single [[API:cItem|cItem]] object, through its m_Enchantments member variable. Although it is possible to create a standalone object of this class, it is not yet used in any API directly. 

Enchantments can be initialized either programmatically by calling the individual functions (SetLevel()), or by using a string description of the enchantment combination. This string description is in the form "id=lvl;id=lvl;...;id=lvl;", where id is either a numerical ID of the enchantment, or its textual representation from the table below, and lvl is the desired enchantment level. The class can also create its string description from its current contents; however that string description will only have the numerical IDs.

===== Enchantments =====
Each enchantment has a textual ID (used in the string description) and is represented by a named constant equal to a numerical value. The table below lists the available enchantments:
^ Enchantment ^ Textual ID ^ Constant name ^ Numeric ID ^
| Protection | Protection | enchProtection | 0 |
| Fire Protection | FireProtection | enchFireProtection | 1 |
| Feather Falling | FeatherFalling | enchFeatherFalling | 2 |
| Blast Protection | BlastProtection | enchBlastProtection | 3 |
| Projectile Protection  | ProjectileProtection | enchProjectileProtection | 4 |
| Respiration | Respiration | enchRespiration | 5 |
| Aqua Affinity | AquaAffinity | enchAquaAffinity | 6 |
| Thorns | Thorns | enchThorns | 7 |
| Sharpness | Sharpness | enchSharpness | 16 |
| Smite | Smite | enchSmite | 17 |
| Bane of Arthropods | BaneOfArthropods | enchBaneOfArthropods | 18 |
| Knockback | Knockback | enchKnockback | 19 |
| Fire Aspect | FireAspect | enchFireAspect | 20 |
| Looting | Looting | enchLooting | 21 |
| Efficiency | Efficiency | enchEfficiency | 32 |
| Silk Touch | SilkTouch | enchSilkTouch | 33 |
| Unbreaking | Unbreaking | enchUnbreaking | 34 |
| Fortune | Fortune | enchFortune | 35 |
| Power | Power | enchPower | 48 |
| Punch | Punch | enchPunch | 49 |
| Flame | Flame | enchFlame | 50 |
| Infinity | Infinity | enchInfinity | 51 |

===== Functions =====
^ Function ^ Parameters ^ Return value ^ Notes ^
| ( ) | | cEnchantments | Creates a new empty cEnchantments object |
| ( ) | StringSpec | cEnchantments | Creates a new cEnchantments object filled with enchantments based on the string description |
| AddFromString | StringSpec | | Adds the enchantments in the string description into the object. If a specified enchantment already existed, it is overwritten. |
| Clear | | | Removes all enchantments |
| GetLevel | EnchantmentNumID | number | Returns the level of the specified enchantment stored in this object; 0 if not stored |
| IsEmpty | | bool | Returns true if the object stores no enchantments |
| SetLevel | EnchantmentNumID, Level | | Sets the level for the specified enchantment, adding it if not stored before or removing it if level < = 0 |
| StringToEnchantmentID | EnchantmentTextID | number | (static) Returns the enchantment numerical ID, -1 if not understood. Case insensitive |
| ToString | | string | Returns the string description of all the enchantments stored in this object, in numerical-ID form |

===== Code Examples =====
The following code example creates several enchanted items using different techniques (adapted from the Debuggers plugin):
<code lua>
local Item1 = cItem();  -- empty item
local Item2 = cItem(E_ITEM_DIAMOND_SWORD, 1, 0, "1=1");  -- enchanted sword, enchantment given as numeric string
local Item3 = cItem(E_ITEM_DIAMOND_SHOVEL);  -- 1 undamaged shovel, no enchantment
Item3.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 4);  -- Add the Unbreaking enchantment. Note that Vanilla's levelcap isn't enforced
local Item4 = cItem(E_ITEM_DIAMOND_PICKAXE);  -- 1 undamaged pickaxe, no enchantment
Item4.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 5);
Item4.m_Enchantments:SetLevel(cEnchantments.enchEfficiency, 3);  -- Add multiple enchantments
local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");  -- enchanted chestplate, enchantment given as textual stringdesc
</code>
