Exemplo n.º 1
0
        public ViewerTab(CompoundTag tag)
        {
            InitializeComponent();

            NamedTag = (CompoundTag)tag.Clone();
            BuildTree();
        }
        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);
        }
        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);
        }