public static void Save(NbtTag parent, Dictionary<byte, ItemSlot> slots)
 {
     if (parent.Contains("Inventory")) parent["Inventory"].Remove();
     NbtTag inventory = parent.Add("Inventory", NbtTag.CreateList(NbtTagType.Compound));
     foreach (ItemSlot slot in slots.Values) {
         if (slot.Item == null) continue;
         inventory.Add(slot.Item.tag);
     }
 }
Exemple #2
0
 void Open(Page page, string file)
 {
     try {
         FileInfo info = new FileInfo(file);
         page.file = info.FullName;
         if (info.Name == "level.dat")
         {
             page.Text = info.Directory.Name;
         }
         else
         {
             page.Text = info.Name;
         }
         Text                = "INVedit - " + page.Text;
         page.changed        = false;
         btnSave.Enabled     = true;
         btnCloseTab.Enabled = true;
         btnReload.Enabled   = true;
         NbtTag tag = NbtTag.Load(file);
         if (tag.Type == NbtTagType.Compound && tag.Contains("Data"))
         {
             tag = tag["Data"];
         }
         if (tag.Type == NbtTagType.Compound && tag.Contains("Player"))
         {
             tag = tag["Player"];
         }
         if (tag.Type == NbtTagType.Compound && tag.Contains("Inventory"))
         {
             tag = tag["Inventory"];
         }
         if (tag.Name != "Inventory")
         {
             throw new Exception("Can't find Inventory tag.");
         }
         Inventory.Load(tag, page.slots);
     } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }
Exemple #3
0
        public static void Save(NbtTag parent, Dictionary <byte, ItemSlot> slots)
        {
            if (parent.Contains("Inventory"))
            {
                parent["Inventory"].Remove();
            }
            NbtTag inventory = parent.Add("Inventory", NbtTag.CreateList(NbtTagType.Compound));

            foreach (ItemSlot slot in slots.Values)
            {
                if (slot.Item == null)
                {
                    continue;
                }
                inventory.Add(slot.Item.tag);
            }
        }
        public void Update(ItemSlot slot)
        {
            boxTitle.TextChanged     -= BoxTitleTextChanged;
            boxAuthor.TextChanged    -= BoxAuthorTextChanged;
            boxSigned.CheckedChanged -= BoxSignedCheckedChanged;
            boxText.TextChanged      -= BoxTextTextChanged;

            this.slot = slot;
            Item item = ((slot != null) ? slot.Item : null);

            if (item != null && (item.ID == 386 || item.ID == 387))
            {
                string title    = "";
                string author   = "";
                int    pages    = 0;
                string pageText = "";

                if (!item.tag.Contains("tag"))
                {
                    item.tag["tag"] = NbtTag.CreateCompound();
                }
                NbtTag tag = item.tag["tag"];
                if (item.ID == 387)
                {
                    if (!tag.Contains("title"))
                    {
                        tag.Add("title", "");
                    }
                    if (!tag.Contains("author"))
                    {
                        tag.Add("author", "");
                    }
                    title  = (string)tag["title"];
                    author = (string)tag["author"];
                }
                if (!tag.Contains("pages"))
                {
                    tag["pages"] = NbtTag.CreateList(NbtTagType.String);
                }
                if (tag["pages"].Count == 0)
                {
                    tag["pages"].Add("");
                }
                page     = 0;
                pages    = tag["pages"].Count;
                pageText = ((string)tag["pages"][page]).Replace("\n", "\r\n");

                boxTitle.Text     = title;
                boxTitle.Enabled  = (item.ID == 387);
                boxAuthor.Text    = author;
                boxAuthor.Enabled = (item.ID == 387);
                boxSigned.Checked = (item.ID == 387);
                boxSigned.Enabled = true;
                boxText.Text      = pageText;
                boxText.Enabled   = true;
                labelPage.Text    = "Page " + (page + 1) + " of " + pages;
                btnNext.Enabled   = true;
            }
            else
            {
                boxTitle.Text       = "";
                boxTitle.Enabled    = false;
                boxAuthor.Text      = "";
                boxAuthor.Enabled   = false;
                boxSigned.Checked   = false;
                boxSigned.Enabled   = false;
                boxText.Text        = "";
                boxText.Enabled     = false;
                labelPage.Text      = "Page 0 of 0";
                btnPrevious.Enabled = false;
                btnNext.Enabled     = false;
            }

            boxTitle.TextChanged     += BoxTitleTextChanged;
            boxAuthor.TextChanged    += BoxAuthorTextChanged;
            boxSigned.CheckedChanged += BoxSignedCheckedChanged;
            boxText.TextChanged      += BoxTextTextChanged;
        }