void BoxLoreTextChanged(object sender, EventArgs e) { var tag = (slot.Item.tag.Contains("tag") ? slot.Item.tag["tag"] : null); var display = ((tag != null && tag.Contains("display")) ? tag["display"] : null); if (boxLore.Text != "") { if (tag == null) { tag = NbtTag.CreateCompound(); slot.Item.tag.Add("tag", tag); } if (display == null) { display = NbtTag.CreateCompound(); tag.Add("display", display); } var lore = (display.Contains("Lore") ? display["Lore"] : null); if (lore == null) { lore = NbtTag.CreateList(NbtTagType.String); display.Add("Lore", lore); } else { lore.Clear(); } lore.Add(boxLore.Lines); } else { display["Lore"].Remove(); } 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); } }
void ChangeLevel(short level) { boxEnchantments.ItemSelectionChanged -= BoxEnchantmentsItemSelectionChanged; editId.ValueChanged -= EditIdValueChanged; boxName.SelectedIndexChanged -= BoxNameSelectedIndexChanged; editLevel.ValueChanged -= EditLevelValueChanged; editLevel.Value = level; var enchantment = (Data.Enchantment)boxName.SelectedItem; if (level != 0) { if (!slot.Item.tag.Contains("tag")) { slot.Item.tag.Add("tag", NbtTag.CreateCompound()); } if (!slot.Item.tag["tag"].Contains("ench")) { slot.Item.tag["tag"].Add("ench", NbtTag.CreateList(NbtTagType.Compound)); } NbtTag tag = null; foreach (var ench in slot.Item.tag["tag"]["ench"]) { if ((short)ench["id"] == enchantment.id) { tag = ench; break; } } if (tag == null) { tag = NbtTag.CreateCompound( "id", enchantment.id, "lvl", level); slot.Item.tag["tag"]["ench"].Add(tag); var listItem = new ListViewItem(new string[] { enchantment.name, editLevel.Value.ToString() }); listItem.Tag = enchantment.id; boxEnchantments.Items.Add(listItem); listItem.Selected = true; enchantments.Add(enchantment.id, Tuple.Create(tag, listItem)); } else { tag["lvl"].Value = level; foreach (ListViewItem item in boxEnchantments.Items) { if ((short)item.Tag == enchantment.id) { item.SubItems[1].Text = editLevel.Value.ToString(); } } } } else { NbtTag tag = null; foreach (var ench in slot.Item.tag["tag"]["ench"]) { if ((short)ench["id"] == enchantment.id) { tag = ench; break; } } tag.Remove(); foreach (ListViewItem item in boxEnchantments.Items) { if ((short)item.Tag == enchantment.id) { item.Remove(); break; } } if (slot.Item.tag["tag"]["ench"].Count == 0) { slot.Item.tag["tag"]["ench"].Remove(); } if (slot.Item.tag["tag"].Count == 0) { slot.Item.tag["tag"].Remove(); } enchantments.Remove(enchantment.id); } slot.CallChanged(); boxEnchantments.ItemSelectionChanged += BoxEnchantmentsItemSelectionChanged; editId.ValueChanged += EditIdValueChanged; boxName.SelectedIndexChanged += BoxNameSelectedIndexChanged; editLevel.ValueChanged += EditLevelValueChanged; }
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; }
void Save(Page page, string file) { try { FileInfo info = new FileInfo(file); if (info.Exists && page.file != info.FullName) { string str; if (info.Name == "level.dat") { str = "Are you sure you want to overwrite " + info.Directory.Name + "?"; } else { str = "Are you sure you want to overwrite '" + info.Name + "'?"; } DialogResult result = MessageBox.Show(str, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result != DialogResult.Yes) { return; } } page.file = info.FullName; NbtTag root, tag; if (info.Exists) { root = NbtTag.Load(page.file); if (info.Extension.ToLower() == ".dat") { CreateBackup(file); } tag = root; } else { if (info.Extension.ToLower() == ".dat") { MessageBox.Show("You can't create a new Minecraft level/player file.\n" + "Select an existing one instead.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } root = NbtTag.CreateCompound("Inventory", NbtTag.CreateList(NbtTagType.Compound)); tag = root; } 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")) { throw new Exception("Can't find Inventory tag."); } Inventory.Save(tag, page.slots); root.Save(page.file); if (info.Name == "level.dat") { page.Text = info.Directory.Name; } else { page.Text = info.Name; } Text = "INVedit - " + page.Text; page.changed = false; btnReload.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }