示例#1
0
        /// <summary>
        /// <see cref="BlockEntity"/> を保存するNBTを返します
        /// </summary>
        public virtual CompoundTag SaveNBT()
        {
            CompoundTag nbt = new CompoundTag();

            nbt.PutString("id", this.Name);
            nbt.PutInt("x", (int)this.X);
            nbt.PutInt("y", (int)this.Y);
            nbt.PutInt("z", (int)this.Z);
            return(nbt);
        }
        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());
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        public override bool Place(Block clicked, Block replace, BlockFace face, Vector3 clickPos, Player player,
                                   Item item)
        {
            int[] faces = { 2, 5, 3, 4 };
            this.Damage = faces[player.GetDirection().GetHorizontalIndex()];
            this.World.SetBlock(this.ToVector3(), this, true);

            CompoundTag nbt = new CompoundTag();

            nbt.PutInt("x", this.X);
            nbt.PutInt("y", this.Y);
            nbt.PutInt("z", this.Z);

            Chunk chunk = this.World.GetChunk(new Tuple <int, int>(this.X >> 4, this.Z >> 4));

            BlockEntity blockEntity = BlockEntity.CreateBlockEntity("chest", chunk, nbt);

            ((BlockEntitySpawnable)blockEntity).SpawnToAll();
            return(true);
        }
示例#6
0
        public void Save()
        {
            CompoundTag nbt = this.SaveNBT();

            nbt.PutInt("PlayerGameType", this.GameMode.GetIndex());

            nbt.PutString("World", this.World.Name);

            nbt.PutInt("SpawnX", this.SpawnX);
            nbt.PutInt("SpawnY", this.SpawnY);
            nbt.PutInt("SpawnZ", this.SpawnZ);

            Dictionary <string, Tag> tags = this.Inventory.SaveNBT().Tags;

            foreach (string name in tags.Keys)
            {
                nbt.PutTag(name, tags[name]);
            }

            Server.Instance.SaveOfflinePlayerData(this.LoginData.XUID, 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);
        }
示例#8
0
        public override bool Activate(Player player, Item item)
        {
            BlockEntity blockEntity = this.World.GetBlockEntity(this.ToBlockCoordinate3D());

            if (!(blockEntity is BlockEntityChest))
            {
                CompoundTag nbt = new CompoundTag();
                nbt.PutInt("x", this.X);
                nbt.PutInt("y", this.Y);
                nbt.PutInt("z", this.Z);

                Chunk chunk = this.World.GetChunk(new Tuple <int, int>(this.X >> 4, this.Z >> 4));

                blockEntity = BlockEntity.CreateBlockEntity("chest", chunk, nbt);
                ((BlockEntitySpawnable)blockEntity).SpawnToAll();
            }

            Inventory inventory = ((BlockEntityChest)blockEntity).Inventory;

            player.Inventory.OpenInventory(inventory);
            return(true);
        }
示例#9
0
        public override CompoundTag SaveNBT()
        {
            CompoundTag nbt = base.SaveNBT();

            nbt.PutInt("MainHand", this.MainHandSlot);

            Dictionary <string, Tag> tags = this.ArmorInventory.SaveNBT().Tags;

            foreach (string key in tags.Keys)
            {
                nbt.PutTag(key, tags[key]);
            }
            tags = this.EntityOffhandInventory.SaveNBT().Tags;
            foreach (string key in tags.Keys)
            {
                nbt.PutTag(key, tags[key]);
            }
            return(nbt);
        }
示例#10
0
        public void Convert()
        {
            for (int i = 0; i < this.BlockEntitiesTag.Length; ++i)
            {
                CompoundTag tag = this.BlockEntitiesTag[i];
                switch (tag.GetString("id"))
                {
                case "minecraft:flower_pot":
                    tag.PutShort("item", (short)Util.GetItemIdFromString(tag.GetString("Item")).Item1);
                    tag.PutInt("mData", tag.GetInt("Data"));

                    tag.Remove("Item");
                    tag.Remove("Data");
                    break;

                case "minecraft:sign":
                    string text1 = tag.GetString("Text1").Remove(0, 9);
                    text1 = text1.Remove(text1.Length - 2, 2);
                    string text2 = tag.GetString("Text2").Remove(0, 9);
                    text2 = text2.Remove(text2.Length - 2, 2);
                    string text3 = tag.GetString("Text3").Remove(0, 9);
                    text3 = text3.Remove(text3.Length - 2, 2);
                    string text4 = tag.GetString("Text4").Remove(0, 9);
                    text4 = text4.Remove(text4.Length - 2, 2);
                    string text = $"{text1}\n{text2}\n{text3}\n{text4}";
                    tag.PutString("Text", text);
                    break;
                }
            }

            for (int i = 0; i < this.SubChunks.Length; ++i)
            {
                if (this.SubChunks[i] == null)
                {
                    continue;
                }
                this.SubChunks[i].Convert();
            }
        }
示例#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);
        }
示例#12
0
        public CompoundTag CreateData(World world)
        {
            CompoundTag customBossEvents = new CompoundTag("CustomBossEvents");
            CompoundTag dimensionData    = new CompoundTag("DimensionData");
            CompoundTag gameRules        = new CompoundTag("GameRules");
            CompoundTag version          = new CompoundTag("Version");

            version.PutInt("Id", -1);
            version.PutString("Name", ProtocolInfo.CLIENT_VERSION);
            version.PutByte("Snapshot", 0);

            CompoundTag data = new CompoundTag("Data");

            data.PutCompound("CustomBossEvents", customBossEvents);
            data.PutCompound("DimensionData", dimensionData);

            data.PutInt("version", 19133);

            data.PutByte("initialized", 0);

            data.PutString("LevelName", world.Name);
            data.PutString("generatorName", world.GeneratorName);
            data.PutInt("generatorVersion", 0);
            data.PutString("generatorOptions", "{}");

            data.PutLong("RandomSeed", world.Seed);

            data.PutByte("MapFeatures", 0);

            data.PutLong("LastPlayed", world.LastPlayed);
            data.PutLong("SizeOnDisk", 0);

            data.PutByte("allowCommands", 1);

            data.PutByte("hardcore", 0);

            data.PutInt("GameType", world.DefaultGameMode.GameModeToInt());

            data.PutByte("Difficulty", (byte)world.Difficulty);
            data.PutByte("DifficultyLocked", 0);

            data.PutLong("Time", 0);
            data.PutLong("DayTime", 0);

            data.PutInt("SpawnX", (int)world.SpawnPoint.X);
            data.PutInt("SpawnY", (int)world.SpawnPoint.Y);
            data.PutInt("SpawnZ", (int)world.SpawnPoint.Z);

            data.PutDouble("BorderCenterX", 0d);
            data.PutDouble("BorderCenterZ", 0d);

            data.PutDouble("BorderSize", 60000000);

            data.PutDouble("BorderSafeZone", 5);
            data.PutDouble("BorderWarningBlocks", 5);
            data.PutDouble("BorderWarningTime", 15);
            data.PutDouble("BorderSizeLerpTarget", 60000000);
            data.PutDouble("BorderSizeLerpTime", 0);
            data.PutDouble("BorderDamagePerBlock", 0.2d);

            data.PutByte("raining", 0);
            data.PutInt("rainTime", 0);
            data.PutByte("thundering", 0);
            data.PutInt("thunderTime", 0);
            data.PutInt("clearWeatherTime", 0);

            data.PutCompound("GameRules", gameRules);

            data.PutCompound("Version", version);

            return(data);
        }
示例#13
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)));
        }