using System; using System.Collections.Generic; using Substrate.Nbt; using Substrate.Core; namespace Substrate { /// /// Represents an enchantment that can be applied to some s. /// public class Enchantment : INbtObject, ICopyable { private static readonly SchemaNodeCompound _schema = new SchemaNodeCompound("") { new SchemaNodeScaler("id", TagType.TAG_SHORT), new SchemaNodeScaler("lvl", TagType.TAG_SHORT), }; private TagNodeCompound _source; private short _id; private short _level; /// /// Constructs a blank . /// public Enchantment () { } /// /// Constructs an from a given id and level. /// /// The id (type) of the enchantment. /// The level of the enchantment. public Enchantment (int id, int level) { _id = (short)id; _level = (short)level; } #region Properties /// /// Gets an entry for this enchantment's type. /// public EnchantmentInfo Info { get { return EnchantmentInfo.EnchantmentTable[_id]; } } /// /// Gets or sets the current type (id) of the enchantment. /// public int Id { get { return _id; } set { _id = (short)value; } } /// /// Gets or sets the level of the enchantment. /// public int Level { get { return _level; } set { _level = (short)value; } } /// /// Gets a representing the schema of an enchantment. /// public static SchemaNodeCompound Schema { get { return _schema; } } #endregion #region INbtObject Members /// public Enchantment LoadTree (TagNode tree) { TagNodeCompound ctree = tree as TagNodeCompound; if (ctree == null) { return null; } _id = ctree["id"].ToTagShort(); _level = ctree["lvl"].ToTagShort(); _source = ctree.Copy() as TagNodeCompound; return this; } /// public Enchantment LoadTreeSafe (TagNode tree) { if (!ValidateTree(tree)) { return null; } return LoadTree(tree); } /// public TagNode BuildTree () { TagNodeCompound tree = new TagNodeCompound(); tree["id"] = new TagNodeShort(_id); tree["lvl"] = new TagNodeShort(_level); if (_source != null) { tree.MergeFrom(_source); } return tree; } /// public bool ValidateTree (TagNode tree) { return new NbtVerifier(tree, _schema).Verify(); } #endregion #region ICopyable Members /// public Enchantment Copy () { Enchantment ench = new Enchantment(_id, _level); if (_source != null) { ench._source = _source.Copy() as TagNodeCompound; } return ench; } #endregion } }