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