    001    package net.minecraft.src;
    002
    003    public class ChunkLoader
    004    {
    005        public static AnvilConverterData load(NBTTagCompound par0NBTTagCompound)
    006        {
    007            int var1 = par0NBTTagCompound.getInteger("xPos");
    008            int var2 = par0NBTTagCompound.getInteger("zPos");
    009            AnvilConverterData var3 = new AnvilConverterData(var1, var2);
    010            var3.blocks = par0NBTTagCompound.getByteArray("Blocks");
    011            var3.data = new NibbleArrayReader(par0NBTTagCompound.getByteArray("Data"), 7);
    012            var3.skyLight = new NibbleArrayReader(par0NBTTagCompound.getByteArray("SkyLight"), 7);
    013            var3.blockLight = new NibbleArrayReader(par0NBTTagCompound.getByteArray("BlockLight"), 7);
    014            var3.heightmap = par0NBTTagCompound.getByteArray("HeightMap");
    015            var3.terrainPopulated = par0NBTTagCompound.getBoolean("TerrainPopulated");
    016            var3.entities = par0NBTTagCompound.getTagList("Entities");
    017            var3.tileEntities = par0NBTTagCompound.getTagList("TileEntities");
    018            var3.tileTicks = par0NBTTagCompound.getTagList("TileTicks");
    019
    020            try
    021            {
    022                var3.lastUpdated = par0NBTTagCompound.getLong("LastUpdate");
    023            }
    024            catch (ClassCastException var5)
    025            {
    026                var3.lastUpdated = (long)par0NBTTagCompound.getInteger("LastUpdate");
    027            }
    028
    029            return var3;
    030        }
    031
    032        public static void convertToAnvilFormat(AnvilConverterData par0AnvilConverterData, NBTTagCompound par1NBTTagCompound, WorldChunkManager par2WorldChunkManager)
    033        {
    034            par1NBTTagCompound.setInteger("xPos", par0AnvilConverterData.x);
    035            par1NBTTagCompound.setInteger("zPos", par0AnvilConverterData.z);
    036            par1NBTTagCompound.setLong("LastUpdate", par0AnvilConverterData.lastUpdated);
    037            int[] var3 = new int[par0AnvilConverterData.heightmap.length];
    038
    039            for (int var4 = 0; var4 < par0AnvilConverterData.heightmap.length; ++var4)
    040            {
    041                var3[var4] = par0AnvilConverterData.heightmap[var4];
    042            }
    043
    044            par1NBTTagCompound.setIntArray("HeightMap", var3);
    045            par1NBTTagCompound.setBoolean("TerrainPopulated", par0AnvilConverterData.terrainPopulated);
    046            NBTTagList var16 = new NBTTagList("Sections");
    047            int var7;
    048
    049            for (int var5 = 0; var5 < 8; ++var5)
    050            {
    051                boolean var6 = true;
    052
    053                for (var7 = 0; var7 < 16 && var6; ++var7)
    054                {
    055                    int var8 = 0;
    056
    057                    while (var8 < 16 && var6)
    058                    {
    059                        int var9 = 0;
    060
    061                        while (true)
    062                        {
    063                            if (var9 < 16)
    064                            {
    065                                int var10 = var7 << 11 | var9 << 7 | var8 + (var5 << 4);
    066                                byte var11 = par0AnvilConverterData.blocks[var10];
    067
    068                                if (var11 == 0)
    069                                {
    070                                    ++var9;
    071                                    continue;
    072                                }
    073
    074                                var6 = false;
    075                            }
    076
    077                            ++var8;
    078                            break;
    079                        }
    080                    }
    081                }
    082
    083                if (!var6)
    084                {
    085                    byte[] var19 = new byte[4096];
    086                    NibbleArray var20 = new NibbleArray(var19.length, 4);
    087                    NibbleArray var21 = new NibbleArray(var19.length, 4);
    088                    NibbleArray var23 = new NibbleArray(var19.length, 4);
    089
    090                    for (int var22 = 0; var22 < 16; ++var22)
    091                    {
    092                        for (int var12 = 0; var12 < 16; ++var12)
    093                        {
    094                            for (int var13 = 0; var13 < 16; ++var13)
    095                            {
    096                                int var14 = var22 << 11 | var13 << 7 | var12 + (var5 << 4);
    097                                byte var15 = par0AnvilConverterData.blocks[var14];
    098                                var19[var12 << 8 | var13 << 4 | var22] = (byte)(var15 & 255);
    099                                var20.set(var22, var12, var13, par0AnvilConverterData.data.get(var22, var12 + (var5 << 4), var13));
    100                                var21.set(var22, var12, var13, par0AnvilConverterData.skyLight.get(var22, var12 + (var5 << 4), var13));
    101                                var23.set(var22, var12, var13, par0AnvilConverterData.blockLight.get(var22, var12 + (var5 << 4), var13));
    102                            }
    103                        }
    104                    }
    105
    106                    NBTTagCompound var24 = new NBTTagCompound();
    107                    var24.setByte("Y", (byte)(var5 & 255));
    108                    var24.setByteArray("Blocks", var19);
    109                    var24.setByteArray("Data", var20.data);
    110                    var24.setByteArray("SkyLight", var21.data);
    111                    var24.setByteArray("BlockLight", var23.data);
    112                    var16.appendTag(var24);
    113                }
    114            }
    115
    116            par1NBTTagCompound.setTag("Sections", var16);
    117            byte[] var17 = new byte[256];
    118
    119            for (int var18 = 0; var18 < 16; ++var18)
    120            {
    121                for (var7 = 0; var7 < 16; ++var7)
    122                {
    123                    var17[var7 << 4 | var18] = (byte)(par2WorldChunkManager.getBiomeGenAt(par0AnvilConverterData.x << 4 | var18, par0AnvilConverterData.z << 4 | var7).biomeID & 255);
    124                }
    125            }
    126
    127            par1NBTTagCompound.setByteArray("Biomes", var17);
    128            par1NBTTagCompound.setTag("Entities", par0AnvilConverterData.entities);
    129            par1NBTTagCompound.setTag("TileEntities", par0AnvilConverterData.tileEntities);
    130
    131            if (par0AnvilConverterData.tileTicks != null)
    132            {
    133                par1NBTTagCompound.setTag("TileTicks", par0AnvilConverterData.tileTicks);
    134            }
    135        }
    136    }