示例#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);
        }
示例#2
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);
        }
示例#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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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"));
        }
示例#7
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);
        }
示例#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);
        }
示例#9
0
        public Item AddLore(params string[] lores)
        {
            if (lores == null || lores.Length < 1)
            {
                return(this);
            }
            if (!this.HasTags || this.GetLore().Length < 1)
            {
                this.SetLore(lores);
                return(this);
            }
            CompoundTag tag  = this.GetNamedTag();
            ListTag     list = tag.GetCompound("display").GetList("Lore");

            for (int i = 0; i < lores.Length; ++i)
            {
                list.Add(new StringTag(lores[i]));
            }
            this.SetNamedTag(tag);
            return(this);
        }
示例#10
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);
        }
示例#11
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);
        }
        private CompoundTag ConvertSection(Tag sectionTag)
        {
            byte[]      blockData = new byte[4096];
            NibbleArray metaData  = new NibbleArray(4096);

            CompoundTag section = (CompoundTag)sectionTag;

            long[]  states  = section.GetLongArray("BlockStates");
            ListTag palette = section.GetList("Palette");
            List <RuntimeTable.Table> indexs = new List <RuntimeTable.Table>();

            foreach (Tag paletteTag in palette.Tags)
            {
                if (paletteTag is CompoundTag)
                {
                    CompoundTag pt   = (CompoundTag)paletteTag;
                    string      name = pt.GetString("Name");
                    indexs.Add(RuntimeTable.GetNameToTable(name, pt.GetCompound("Properties").Tags));
                }
            }

            int         bits      = CheckMostBit(indexs.Count - 1);
            List <byte> fixStates = new List <byte>();

            foreach (long state in states)
            {
                fixStates.AddRange(BitConverter.GetBytes((ulong)state));
            }

            BitArray stateBits = new BitArray(fixStates.ToArray());

            for (int i = 0; i < 4096; i++)
            {
                int  bitOffset = i * bits;
                uint index     = stateBits.Get(bitOffset + bits - 1) ? 1u : 0u;
                for (int j = bits - 2; j >= 0; j--)
                {
                    index <<= 1;
                    index  |= stateBits.Get(bitOffset + j) ? 1u : 0u;
                }

                try
                {
                    RuntimeTable.Table table = indexs[(int)index];
                    blockData[i] = (byte)(table.Id & 0xff);
                    metaData[i]  = (byte)(table.Data & 0xf);
                }
                catch (Exception e)
                {
                    Logger.Info(indexs.Count + " = " + states[0] + " >>> " + states[1]);
                    throw e;
                }
            }

            var newSection = (CompoundTag)section.Clone();

            newSection.Remove("BlockStates");
            newSection.Remove("Palette");

            newSection.PutByteArray("Blocks", blockData);
            newSection.PutByteArray("Data", metaData.ArrayData);

            return(newSection);
        }
示例#13
0
        public void Load(World world)
        {
            CompoundTag tag = NBTIO.ReadGZIPFile($"{Server.ExecutePath}\\worlds\\{world.Name}\\level.dat");

            CompoundTag data = tag.GetCompound("Data");
        }
示例#14
0
        public void Load()
        {
            CompoundTag tag = NBTIO.ReadGZIPFile(this.FolderPath, NBTEndian.BIG_ENDIAN);

            this.Data = tag.GetCompound("").GetCompound("Data");
        }