Example #1
0
        protected override void EntityInit(CompoundTag nbt)
        {
            base.EntityInit(nbt);

            this.Attributes.AddAttribute(EntityAttribute.HUNGER);
            this.Attributes.AddAttribute(EntityAttribute.SATURATION);
            this.Attributes.AddAttribute(EntityAttribute.EXHAUSTION);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE_LEVEL);

            this.SetFlag(DATA_FLAGS, DATA_FLAG_BREATHING);
            this.SetFlag(DATA_FLAGS, DATA_FLAG_CAN_CLIMB);

            this.Inventory = new PlayerInventory(this);
            this.Inventory.LoadNBT(nbt);

            this.World = World.GetWorld(nbt.GetString("World")) ?? World.GetMainWorld();

            this.SpawnX = nbt.GetInt("SpawnX");
            this.SpawnY = nbt.GetInt("SpawnY");
            this.SpawnZ = nbt.GetInt("SpawnZ");

            this.AdventureSettingsEntry = new AdventureSettingsEntry();

            this.GameMode = GameModeExtention.FromIndex(nbt.GetInt("PlayerGameType"));
        }
Example #2
0
        public Chunk NBTDeserialize(CompoundTag tag)
        {
            CompoundTag level = (CompoundTag)tag["Level"];
            int         x     = level.GetInt("xPos");
            int         z     = level.GetInt("zPos");

            SubChunk[] subChunks = ArrayUtils.CreateArray <SubChunk>(16);
            ListTag    sections  = level.GetList("Sections");

            for (int i = 0; i < sections.Count; ++i)
            {
                CompoundTag section  = ((CompoundTag)sections[i]);
                SubChunk    subChunk = new SubChunk();
                byte        y        = section.GetByte("Y");
                subChunk.BlockDatas  = section.GetByteArray("Blocks");
                subChunk.MetaDatas   = new NibbleArray(section.GetByteArray("Data"));
                subChunk.SkyLights   = new NibbleArray(section.GetByteArray("SkyLight"));
                subChunk.BlockLigths = new NibbleArray(section.GetByteArray("BlockLight"));
                subChunks[y]         = subChunk;
            }

            byte[]  biomes    = level.GetByteArray("Biomes");
            short[] cast      = new short[256];
            int[]   heightMap = level.GetIntArray("HeightMap");
            heightMap.CopyTo(cast, 0);

            Chunk chunk = new Chunk(x, z, subChunks, biomes, cast, level.GetList("Entities"), level.GetList("TileEntities"));

            chunk.LastUpdate       = level.GetLong("LastUpdate");
            chunk.InhabitedTime    = level.GetLong("InhabitedTime");
            chunk.LightPopulated   = level.GetByte("LightPopulated") == 1;
            chunk.TerrainPopulated = level.GetByte("TerrainPopulated") == 1;

            return(chunk);
        }
        public BlockEntity(World world, CompoundTag nbt)
        {
            this.World = world;

            this.X = nbt.GetInt("x");
            this.Y = nbt.GetInt("y");
            this.Z = nbt.GetInt("z");

            this.NamedTag = nbt;
        }
Example #4
0
        public override Chunk DeserializeChunk(CompoundTag tag)
        {
            CompoundTag level = tag.GetCompound("").GetCompound("Level");

            int x = level.GetInt("xPos");
            int z = level.GetInt("zPos");

            byte[]  biomes    = level.GetByteArray("Biomes");
            short[] cast      = new short[256];
            int[]   heightMap = level.GetIntArray("HeightMap");
            for (int i = 0; i < 256; ++i)
            {
                cast[i] = (short)heightMap[i];
            }

            ListTag sections = level.GetList("Sections");

            SubChunk[] subChunks = new SubChunk[16];
            for (int i = 0; i < sections.Count; ++i)
            {
                CompoundTag section  = (CompoundTag)sections[i];
                SubChunk    subChunk = new SubChunk();
                byte        y        = section.GetByte("Y");
                byte[]      bytes    = section.GetByteArray("Blocks");
                int[]       blocks   = new int[4096];
                for (int j = 0; j < 4096; ++j)
                {
                    blocks[j] = bytes[j];
                }
                subChunk.BlockDatas = blocks;
                subChunk.MetaDatas  = new NibbleArray(section.GetByteArray("Data"));
                subChunk.BlockLight = section.GetByteArray("BlockLight");
                subChunk.SkyLight   = section.GetByteArray("SkyLight");
                subChunks[y]        = subChunk;
            }

            Chunk chunk = new Chunk(x, z, subChunks, level.GetList("Entities"), level.GetList("TileEntities"))
            {
                LastUpdate       = level.GetLong("LastUpdate"),
                LightPopulated   = level.GetByte("LightPopulated"),
                TerrainPopulated = level.GetByte("TerrainPopulated"),
                V             = level.GetByte("V"),
                InhabitedTime = level.GetLong("InhabitedTime"),
                Biomes        = biomes,
                HeightMap     = cast
            };

            return(chunk);
        }
Example #5
0
        /// <summary>
        /// <see cref="BlockEntity"/> クラスの新しいインスタンスを作成します。
        /// </summary>
        /// <param name="chunk"> <see cref="BlockEntity"/> を作成するための <see cref="Worlds.Chunk"/> </param>
        /// <param name="nbt"> <see cref="BlockEntity"/> を作成するための <see cref="CompoundTag"/> </param>
        public BlockEntity(Chunk chunk, CompoundTag nbt)
        {
            this.Chunk = chunk;
            this.World = chunk.World;
            if (nbt == null)
            {
                throw new ArgumentNullException(nameof(nbt));
            }
            this.X = nbt.GetInt("x");
            this.Y = nbt.GetInt("y");
            this.Z = nbt.GetInt("z");

            this.Init(nbt);

            this.World.AddBlockEntity(this);
        }
Example #6
0
        public override void LoadNBT(CompoundTag nbt)
        {
            base.LoadNBT(nbt);

            this.MainHandSlot = nbt.GetInt("MainHand");

            this.ArmorInventory.LoadNBT(nbt);
            this.EntityOffhandInventory.LoadNBT(nbt);
        }
        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);
        }
Example #8
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);
        }
Example #9
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();
            }
        }