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);
        }
        public void NBTJsonSerializerTests_DeserializeTest()
        {
            ListTag list = new ListTag("list", NBTTagType.INT);

            list.Add(new IntTag(12345));
            list.Add(new IntTag(67890));
            CompoundTag subTag = new CompoundTag();

            subTag.PutBool("bool", true);
            subTag.PutByte("byte", 123);
            CompoundTag tag = new CompoundTag();

            tag.PutBool("bool", true);
            tag.PutByte("byte", 123);
            tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200));
            tag.PutShort("short", 12345);
            tag.PutInt("int", 12345678);
            tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200));
            tag.PutLong("long", 123456789123456);
            tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200));
            tag.PutFloat("float", 12.3456f);
            tag.PutDouble("double", 12.3456789);
            tag.PutList(list);
            tag.PutCompound("com", subTag);

            JObject json = NBTJsonSerializer.Serialize(tag);

            Console.WriteLine(NBTJsonSerializer.Serialize(NBTJsonSerializer.Deserialize(json)).ToString());
        }
Exemplo n.º 3
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.º 4
0
        public void WriteRawFileTest()
        {
            ListTag list = new ListTag(Data.NBTTagType.BYTE);

            list.Name = "listTag";
            list.Add(new ByteTag(0xff));
            list.Add(new ByteTag(0x00));
            list.Add(new ByteTag(0xff));

            CompoundTag tag = new CompoundTag();

            tag.PutBool("bool", true);
            tag.PutByte("byte", 0xff);
            tag.PutShort("short", 0x7fff);
            tag.PutInt("int", 0x7fffffff);
            tag.PutLong("long", 0x7fffffffffffffff);
            tag.PutFloat("float", 0.0001f);
            tag.PutDouble("double", 0.00000001d);
            tag.PutString("string", "Hello NBT");
            tag.PutByteArray("byte[]", ArrayUtils.CreateArray <byte>(100, 0xff));
            tag.PutIntArray("int[]", ArrayUtils.CreateArray <int>(100, 0x7fffffff));
            tag.PutLongArray("long[]", ArrayUtils.CreateArray <long>(100, 0x7fffffffffffffff));
            tag.PutList(list);

            NBTIO.WriteRawFile(Path + "\\" + "raw.nbt", tag);
        }
Exemplo n.º 5
0
        public void NBTIOTests_WriteGZFileTest()
        {
            ListTag list = new ListTag("list", NBTTagType.COMPOUND);

            list.Add(new CompoundTag().PutInt("c1", 123));
            list.Add(new CompoundTag().PutLong("c2", 123456));
            CompoundTag subTag = new CompoundTag();

            subTag.PutBool("bool", true);
            subTag.PutByte("byte", 123);
            CompoundTag tag = new CompoundTag();

            tag.PutBool("bool", true);
            tag.PutByte("byte", 123);
            tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200));
            tag.PutShort("short", 12345);
            tag.PutInt("int", 12345678);
            tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200));
            tag.PutLong("long", 123456789123456);
            tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200));
            tag.PutFloat("float", 12.3456f);
            tag.PutDouble("double", 12.3456789);
            tag.PutList(list);
            tag.PutCompound("com", subTag);
            NBTIO.WriteGZIPFile(Environment.CurrentDirectory + "\\test2.nbt", tag);
        }
Exemplo n.º 6
0
        public static CompoundTag WriteItem(Item item, int slot = -1)
        {
            CompoundTag nbt = new CompoundTag()
                              .PutShort("id", (short)item.ID)
                              .PutShort("damage", (short)item.Damage)
                              .PutByte("count", (byte)item.Count);

            if (slot != -1)
            {
                nbt.PutByte("slot", (byte)slot);
            }

            if (item.NamedTag.Count != 0)
            {
                nbt.PutCompound("tag", item.NamedTag);
            }

            string[] canPlaceOn = item.CanPlaceOn;
            if (canPlaceOn.Length > 0)
            {
                ListTag list = new ListTag("CanPlaceOn", NBTTagType.STRING);
                for (int i = 0; i < canPlaceOn.Length; ++i)
                {
                    list.Add(new StringTag(canPlaceOn[i]));
                }

                nbt.PutList(list);
            }

            string[] canDestroy = item.CanDestroy;
            if (canDestroy.Length > 0)
            {
                ListTag list = new ListTag("CanDestroy", NBTTagType.STRING);
                for (int i = 0; i < canDestroy.Length; ++i)
                {
                    list.Add(new StringTag(canDestroy[i]));
                }

                nbt.PutList(list);
            }

            return(nbt);
        }
Exemplo n.º 7
0
        /// <summary>
        /// <see cref="Entity"/> のNBTデータを取得します
        /// </summary>
        /// <returns> <see cref="Entity"/> のNBTを <see cref="CompoundTag"/> で取得します</returns>
        public virtual CompoundTag SaveNBT()
        {
            CompoundTag nbt = new CompoundTag();

            nbt.PutString("id", this.SaveId);

            nbt.PutList(new ListTag("Pos", NBTTagType.FLOAT)
                        .Add(new FloatTag("", this.X))
                        .Add(new FloatTag("", this.Y))
                        .Add(new FloatTag("", this.Z)));
            nbt.PutList(new ListTag("Motion", NBTTagType.FLOAT)
                        .Add(new FloatTag("", this.MotionX))
                        .Add(new FloatTag("", this.MotionY))
                        .Add(new FloatTag("", this.MotionZ)));
            nbt.PutList(new ListTag("Rotation", NBTTagType.FLOAT)
                        .Add(new FloatTag("", this.Yaw))
                        .Add(new FloatTag("", this.Pitch)));
            return(nbt);
        }
Exemplo n.º 8
0
        public virtual CompoundTag SaveNBT()
        {
            CompoundTag nbt  = new CompoundTag();
            ListTag     list = new ListTag(this.Name, NBTTagType.COMPOUND);

            for (int i = 0; i < this.Size; ++i)
            {
                list.Add(NBTIO.WriteItem(this.GetItem(i), i));
            }
            nbt.PutList(list);
            return(nbt);
        }
        internal static CompoundTag CompoundTagDeserialize(JObject json)
        {
            CompoundTag tag = new CompoundTag();

            foreach (KeyValuePair <string, JToken> kv in json)
            {
                JToken token = kv.Value;
                if (token is JValue)
                {
                    JValue value = (JValue)token;
                    object t     = value.Value;
                    if (t is byte)
                    {
                        tag.PutByte(kv.Key, (byte)t);
                    }
                    else if (t is double)
                    {
                        tag.PutDouble(kv.Key, (double)t);
                    }
                    else if (t is float)
                    {
                        tag.PutFloat(kv.Key, (float)t);
                    }
                    else if (t is int)
                    {
                        tag.PutInt(kv.Key, (int)t);
                    }
                    else if (t is long)
                    {
                        tag.PutLong(kv.Key, (long)t);
                    }
                    else if (t is short)
                    {
                        tag.PutShort(kv.Key, (short)t);
                    }
                    else if (t is string)
                    {
                        tag.PutString(kv.Key, (string)t);
                    }
                }
                else if (token is JObject)
                {
                    tag.PutCompound(kv.Key, NBTJsonSerializer.CompoundTagDeserialize((JObject)token));
                }
                else
                {
                    tag.PutList(NBTJsonSerializer.ListTagDeserialize((JArray)token, kv.Key));
                }
            }

            return(tag);
        }
Exemplo n.º 10
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.º 11
0
        public CompoundTag NBTSerialize(Chunk chunk)
        {
            CompoundTag tag = new CompoundTag("Level");

            tag.PutInt("xPos", chunk.X);                                                 //Chunk X
            tag.PutInt("zPos", chunk.Z);                                                 //Chunk Z

            tag.PutLong("LastUpdate", chunk.LastUpdate);                                 //Last Save Tick

            tag.PutByte("LightPopulated", chunk.LightPopulated ? (byte)1 : (byte)0);     //
            tag.PutByte("TerrainPopulated", chunk.TerrainPopulated ? (byte)1 : (byte)0); //

            tag.PutByte("V", 1);                                                         //Version

            tag.PutLong("InhabitedTime", chunk.InhabitedTime);

            tag.PutByteArray("Biomes", chunk.Biomes);

            int[] cast = new int[256];
            chunk.HeightMap.CopyTo(cast, 0);
            tag.PutIntArray("HeightMap", cast);

            ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND);

            SubChunk[] subChunks = chunk.SubChunks;
            for (int i = 0; i < subChunks.Length; ++i)
            {
                if (subChunks[i].IsEnpty)
                {
                    continue;
                }
                CompoundTag data = new CompoundTag();
                data.PutByte("Y", (byte)i);
                data.PutIntArray("Blocks", subChunks[i].BlockDatas);
                data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData);
                data.PutByteArray("SkyLight", subChunks[i].SkyLights.ArrayData);
                data.PutByteArray("BlockLight", subChunks[i].BlockLigths.ArrayData);
                sections.Add(data);
            }
            tag.PutList(sections);

            ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND);

            Entity[] entities = chunk.GetEntities();
            for (int i = 0; i < entities.Length; ++i)
            {
                if (entities[i].IsPlayer)
                {
                    continue;
                }
                entitiesTag.Add(entities[i].SaveNBT());
            }
            tag.PutList(entitiesTag);

            ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND);

            BlockEntity[] blockEntities = chunk.GetBlockEntities();
            for (int i = 0; i < blockEntities.Length; ++i)
            {
                blockEntitiesTag.Add(blockEntities[i].SaveNBT());
            }
            tag.PutList(blockEntitiesTag);

            CompoundTag outTag = new CompoundTag("");

            outTag.PutCompound(tag.Name, tag);

            return(outTag);
        }
Exemplo n.º 12
0
        public override CompoundTag SerializeChunk(Chunk chunk)
        {
            CompoundTag tag = new CompoundTag();

            tag.PutInt("xPos", chunk.X);
            tag.PutInt("zPos", chunk.Z);

            tag.PutLong("LastUpdate", chunk.LastUpdate);
            tag.PutByte("LightPopulated", chunk.LightPopulated);
            tag.PutByte("TerrainPopulated", chunk.TerrainPopulated);
            tag.PutByte("V", chunk.V);
            tag.PutLong("InhabitedTime", chunk.InhabitedTime);

            tag.PutByteArray("Biomes", chunk.Biomes);
            int[] cast = new int[256];
            chunk.HeightMap.CopyTo(cast, 0);
            tag.PutIntArray("HeightMap", cast);

            ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND);

            SubChunk[] subChunks = chunk.SubChunks;
            for (int i = 0; i < subChunks.Length; ++i)
            {
                if (subChunks[i] == null)
                {
                    continue;
                }
                CompoundTag data = new CompoundTag();
                data.PutByte("Y", (byte)i);
                byte[] blocks = new byte[subChunks[i].BlockDatas.Length];
                for (int j = 0; j < subChunks[i].BlockDatas.Length; ++j)
                {
                    blocks[j] = (byte)subChunks[i].BlockDatas[j];
                }
                data.PutByteArray("Blocks", blocks);
                data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData);
                data.PutByteArray("BlockLight", subChunks[i].BlockLight);
                data.PutByteArray("SkyLight", subChunks[i].SkyLight);
                sections.Add(data);
            }
            tag.PutList(sections);

            ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND);

            CompoundTag[] entities = chunk.EntitiesTag;
            for (int i = 0; i < entities.Length; ++i)
            {
                entitiesTag.Add(entities[i]);
            }
            tag.PutList(entitiesTag);

            ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND);

            CompoundTag[] blockEntities = chunk.BlockEntitiesTag;
            for (int i = 0; i < blockEntities.Length; ++i)
            {
                blockEntitiesTag.Add(blockEntities[i]);
            }
            tag.PutList(blockEntitiesTag);

            return(new CompoundTag().PutCompound("", new CompoundTag().PutCompound("Level", tag)));
        }