Exemplo n.º 1
0
        public static Item ReadItem(CompoundTag nbt)
        {
            Item item = Item.Get(nbt.GetShort("id"), nbt.GetShort("damage"), nbt.GetByte("count"));

            if (nbt.Exist("tag"))
            {
                CompoundTag tag = (CompoundTag)nbt.GetCompound("tag").Clone();
                tag.Name = "";
                item.SetNamedTag(tag);
            }
            if (nbt.Exist("CanPlaceOn"))
            {
                ListTag list = nbt.GetList("CanPlaceOn");
                for (int i = 0; i < list.Count; ++i)
                {
                    item.AddCanPlaceOn(((StringTag)list[i]).Data);
                }
            }
            if (nbt.Exist("CanDestroy"))
            {
                ListTag list = nbt.GetList("CanDestroy");
                for (int i = 0; i < list.Count; ++i)
                {
                    item.AddCanDestroy(((StringTag)list[i]).Data);
                }
            }
            return(item);
        }
Exemplo n.º 2
0
        public Item AddEnchantment(Enchantment enchantment)
        {
            CompoundTag tag = this.NamedTag;
            ListTag     list;

            if (tag.Exist("ench"))
            {
                list = tag.GetList("ench");
            }
            else
            {
                list = new ListTag("ench", NBTTagType.COMPOUND);
                tag.PutList(list);
            }
            for (int i = 0; i < list.Count; ++i)
            {
                if (((CompoundTag)list[i]).GetShort("id") == enchantment.ID)
                {
                    list[i] = new CompoundTag()
                              .PutShort("id", (short)enchantment.ID)
                              .PutShort("lvl", (short)enchantment.Level);
                    this.NamedTag = tag;
                    return(this);
                }
            }
            CompoundTag ench = new CompoundTag()
                               .PutShort("id", (short)enchantment.ID)
                               .PutShort("lvl", (short)enchantment.Level);

            list.Add(ench);
            this.NamedTag = tag;
            return(this);
        }
Exemplo n.º 3
0
        public string[] GetLore()
        {
            if (!this.HasTags)
            {
                return(new string[0]);
            }

            CompoundTag tag = this.GetNamedTag();

            if (tag.Exist("display"))
            {
                return(new string[0]);
            }
            CompoundTag display = tag.GetCompound("display");

            if (!display.Exist("Lore"))
            {
                return(new string[0]);
            }
            ListTag lores = display.GetList("Lore");

            string[] data = new string[lores.Count];
            for (int i = 0; i < lores.Count; ++i)
            {
                data[i] = ((StringTag)lores[i]).Data;
            }
            return(data);
        }
Exemplo n.º 4
0
        public Item SetLore(params string[] lores)
        {
            if (lores == null || lores.Length < 1)
            {
                this.ClearLore();
                return(this);
            }

            CompoundTag tag  = this.NamedTag;
            ListTag     list = new ListTag("Lore", NBTTagType.STRING);

            for (int i = 0; i < lores.Length; ++i)
            {
                list.Add(new StringTag(lores[i]));
            }

            if (tag.Exist("display"))
            {
                tag.GetCompound("display").PutList(list);
            }
            else
            {
                tag.PutCompound("display", new CompoundTag("display").PutList(list));
            }
            this.NamedTag = tag;
            return(this);
        }
Exemplo n.º 5
0
        public Item RemoveEnchantments()
        {
            CompoundTag tag = this.NamedTag;

            if (tag.Exist("ench"))
            {
                tag.Remove("ench");
            }
            return(this);
        }
Exemplo n.º 6
0
        public bool GetUnbreakable()
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("Unbreakable"))
            {
                return(false);
            }
            return(tag.GetBool("Unbreakable"));
        }
        private void ConvertChunkData(ChunkData data)
        {
            CompoundTag oldTag = data.Data.GetCompound("").GetCompound("Level");
            CompoundTag newTag = (CompoundTag)oldTag.Clone();

            ListTag sections    = oldTag.GetList("Sections");
            ListTag newSections = ConvertSections(sections);

            if (newSections != null)
            {
                newTag.Remove("Sections");
                newTag.PutList(newSections);

                List <byte> biomes = new List <byte>();
                foreach (int b in oldTag.GetIntArray("Biomes"))
                {
                    biomes.Add((byte)b);
                }
                newTag.Remove("Biomes");
                newTag.PutByteArray("Biomes", biomes.ToArray());
            }

            CheckCancel();

            if (newTag.Exist("Heightmaps"))
            {
                newTag.Remove("Heightmaps");
            }
            else
            {
                newTag.Remove("HeightMap");
            }

            int[] map = new int[256];
            for (int i = 0; i < 256; i++)
            {
                map[i] = 0xff;
            }
            newTag.PutIntArray("HeightMap", map);

            newTag.PutList(new ListTag("TileTicks", NBTTagType.COMPOUND));

            newTag.PutList(new ListTag("Entities", NBTTagType.COMPOUND));
            newTag.PutList(new ListTag("TileEntities", NBTTagType.COMPOUND));

            newTag.PutBool("TerrainPopulated", true);
            newTag.PutBool("TerrainGenerated", true);

            newTag.Remove("CarvingMasks");
            newTag.Remove("Structures");

            data.Data = new CompoundTag("").PutCompound("Level", newTag);
        }
Exemplo n.º 8
0
        public bool GetUnbreakable()
        {
            if (!this.HasTags)
            {
                return(false);
            }

            CompoundTag tag = this.GetNamedTag();

            if (!tag.Exist("Unbreakable"))
            {
                return(false);
            }
            return(tag.GetBool("Unbreakable"));
        }
Exemplo n.º 9
0
        public string GetCustomName()
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("display"))
            {
                return("");
            }

            CompoundTag display = tag.GetCompound("display");

            if (!display.Exist("Name"))
            {
                return("");
            }
            return(display.GetString("Name"));
        }
Exemplo n.º 10
0
        public Item ClearLore()
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("display"))
            {
                return(this);
            }

            CompoundTag display = tag.GetCompound("display");

            if (display.Exist("Lore"))
            {
                display.Remove("Lore");
            }
            this.NamedTag = tag;
            return(this);
        }
Exemplo n.º 11
0
        public Enchantment[] GetEnchantments()
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("ench"))
            {
                return(new Enchantment[0]);
            }

            ListTag            list   = tag.GetList("ench");
            List <Enchantment> enches = new List <Enchantment>();

            for (int i = 0; i < list.Count; ++i)
            {
                CompoundTag ench = (CompoundTag)list[i];
                enches.Add(Enchantment.GetEnchantment(ench.GetShort("id"), ench.GetShort("lvl")));
            }
            return(enches.ToArray());
        }
Exemplo n.º 12
0
        public virtual void LoadNBT(CompoundTag nbt)
        {
            if (!nbt.Exist(this.Name))
            {
                ListTag list = new ListTag(this.Name, NBTTagType.COMPOUND);
                for (int i = 0; i < this.Size; ++i)
                {
                    list.Add(NBTIO.WriteItem(Item.Get(0, 0, 0)));
                }
                nbt.PutList(list);
            }

            ListTag items = nbt.GetList(this.Name);

            for (int i = 0; i < this.Size; ++i)
            {
                Item item = NBTIO.ReadItem((CompoundTag)items[i]);
                this.SetItem(i, item, false);
            }
        }
Exemplo n.º 13
0
        public Item RemoveEnchantment(Enchantment enchantment)
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("ench"))
            {
                return(this);
            }
            ListTag list = tag.GetList("ench");

            for (int i = 0; i < list.Count; ++i)
            {
                if (((CompoundTag)list[i]).GetShort("id") == enchantment.ID)
                {
                    list.RemoveAt(i);
                }
            }
            this.NamedTag = tag;
            return(this);
        }
Exemplo n.º 14
0
        public bool HasEnchantment(int id)
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("ench"))
            {
                return(false);
            }

            ListTag list = tag.GetList("ench");

            for (int i = 0; i < list.Count; ++i)
            {
                CompoundTag ench = (CompoundTag)list[i];
                if (ench.GetShort("id") == id)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 15
0
        public Item SetCustomName(string name)
        {
            if (name == null || name == "")
            {
                this.ClearCustomName();
                return(this);
            }

            CompoundTag tag = this.NamedTag;

            if (tag.Exist("display"))
            {
                tag.GetCompound("display").PutString("Name", name);
            }
            else
            {
                tag.PutCompound("display", new CompoundTag("display").PutString("Name", name));
            }
            this.NamedTag = tag;
            return(this);
        }
Exemplo n.º 16
0
        public Item ClearLore()
        {
            if (!this.HasTags)
            {
                return(this);
            }

            CompoundTag tag = this.GetNamedTag();

            if (!tag.Exist("display"))
            {
                return(this);
            }
            CompoundTag display = tag.GetCompound("display");

            if (display.Exist("Lore"))
            {
                display.Remove("Lore");
            }
            this.SetNamedTag(tag);
            return(this);
        }