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
        protected override void EntityInit(CompoundTag nbt)
        {
            base.EntityInit(nbt);

            this.Age         = nbt.GetShort("Age");
            this.PickupDelay = nbt.GetShort("PickupDelay");
            this.Owner       = nbt.GetString("Owner");
            this.Item        = NBTIO.ReadItem(nbt.GetCompound("Item"));

            this.SetFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_IMMOBILE, true);
        }
Exemplo n.º 3
0
        public Enchantment GetEnchantment(int id)
        {
            if (!this.HasEnchantment(id))
            {
                return(null);
            }
            CompoundTag tag  = this.GetNamedTag();
            ListTag     list = tag.GetList("ench");

            for (int i = 0; i < list.Count; ++i)
            {
                CompoundTag ench = (CompoundTag)list[i];
                if (ench.GetShort("id") == id)
                {
                    return(Enchantment.GetEnchantment(id, ench.GetShort("lvl")));
                }
            }
            return(null);
        }
Exemplo n.º 4
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());
        }
        internal static JObject CompoundTagSerialize(CompoundTag tag)
        {
            JObject json = new JObject();

            foreach (KeyValuePair <string, Tag> kv in tag.Tags)
            {
                Tag t = kv.Value;
                if (t is ByteTag)
                {
                    json.Add(t.Name, new JValue(tag.GetByte(t.Name)));
                }
                else if (t is CompoundTag)
                {
                    json.Add(t.Name, NBTJsonSerializer.CompoundTagSerialize((CompoundTag)t));
                }
                else if (t is DoubleTag)
                {
                    json.Add(t.Name, new JValue(tag.GetDouble(t.Name)));
                }
                else if (t is FloatTag)
                {
                    json.Add(t.Name, new JValue(tag.GetFloat(t.Name)));
                }
                else if (t is IntTag)
                {
                    json.Add(t.Name, new JValue(tag.GetInt(t.Name)));
                }
                else if (t is ListTag)
                {
                    json.Add(t.Name, new JArray(NBTJsonSerializer.ListTagSerialize((ListTag)t)));
                }
                else if (t is LongTag)
                {
                    json.Add(t.Name, new JValue(tag.GetLong(t.Name)));
                }
                else if (t is ShortTag)
                {
                    json.Add(t.Name, new JValue(tag.GetShort(t.Name)));
                }
                else if (t is StringTag)
                {
                    json.Add(t.Name, new JValue(tag.GetString(t.Name)));
                }
            }

            return(json);
        }
Exemplo n.º 6
0
        public void NBTIOTests_ReadRawFileTest()
        {
            CompoundTag tag = NBTIO.ReadRawFile(Environment.CurrentDirectory + "\\test.nbt");

            tag.GetBool("bool");
            tag.GetByte("byte");
            tag.GetByteArray("byteArray");
            tag.GetShort("short");
            tag.GetInt("int");
            tag.GetIntArray("intArray");
            tag.GetLong("long");
            tag.GetLongArray("longArray");
            tag.GetFloat("float");
            tag.GetDouble("double");
            tag.GetList("list");
            tag.GetCompound("com");
            Console.WriteLine(tag);
        }
Exemplo n.º 7
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);
        }