void BoxTextTextChanged(object sender, EventArgs e) { string text = boxText.Text.Replace("\r\n", "\n"); NbtTag pages = slot.Item.tag["tag"]["pages"]; if (text == "") { pages[page].Value = text; if (page == pages.Count - 1) { for (int p = page; p > 1; p--) { if ((string)pages[p].Value == "") { pages[p].Remove(); } else { break; } } } } else { while (pages.Count < page + 1) { pages.Add(""); } pages[page].Value = text; } slot.CallChanged(); }
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 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; }