| 1 | package net.minecraft.world.chunk.storage;
|
| 2 |
|
| 3 | import net.minecraft.nbt.NBTTagCompound;
|
| 4 | import net.minecraft.nbt.NBTTagList;
|
| 5 | import net.minecraft.util.BlockPos;
|
| 6 | import net.minecraft.world.biome.BiomeGenBase;
|
| 7 | import net.minecraft.world.biome.WorldChunkManager;
|
| 8 | import net.minecraft.world.chunk.NibbleArray;
|
| 9 |
|
| 10 | public class ChunkLoader
|
| 11 | {
|
| 12 | public static ChunkLoader.AnvilConverterData load(NBTTagCompound nbt)
|
| 13 | {
|
| 14 | int i = nbt.getInteger("xPos");
|
| 15 | int j = nbt.getInteger("zPos");
|
| 16 | ChunkLoader.AnvilConverterData chunkloader$anvilconverterdata = new ChunkLoader.AnvilConverterData(i, j);
|
| 17 | chunkloader$anvilconverterdata.blocks = nbt.getByteArray("Blocks");
|
| 18 | chunkloader$anvilconverterdata.data = new NibbleArrayReader(nbt.getByteArray("Data"), 7);
|
| 19 | chunkloader$anvilconverterdata.skyLight = new NibbleArrayReader(nbt.getByteArray("SkyLight"), 7);
|
| 20 | chunkloader$anvilconverterdata.blockLight = new NibbleArrayReader(nbt.getByteArray("BlockLight"), 7);
|
| 21 | chunkloader$anvilconverterdata.heightmap = nbt.getByteArray("HeightMap");
|
| 22 | chunkloader$anvilconverterdata.terrainPopulated = nbt.getBoolean("TerrainPopulated");
|
| 23 | chunkloader$anvilconverterdata.entities = nbt.getTagList("Entities", 10);
|
| 24 | chunkloader$anvilconverterdata.tileEntities = nbt.getTagList("TileEntities", 10);
|
| 25 | chunkloader$anvilconverterdata.tileTicks = nbt.getTagList("TileTicks", 10);
|
| 26 |
|
| 27 | try
|
| 28 | {
|
| 29 | chunkloader$anvilconverterdata.lastUpdated = nbt.getLong("LastUpdate");
|
| 30 | }
|
| 31 | catch (ClassCastException var5)
|
| 32 | {
|
| 33 | chunkloader$anvilconverterdata.lastUpdated = (long)nbt.getInteger("LastUpdate");
|
| 34 | }
|
| 35 |
|
| 36 | return chunkloader$anvilconverterdata;
|
| 37 | }
|
| 38 |
|
| 39 | public static void convertToAnvilFormat(ChunkLoader.AnvilConverterData p_76690_0_, NBTTagCompound compound, WorldChunkManager p_76690_2_)
|
| 40 | {
|
| 41 | compound.setInteger("xPos", p_76690_0_.x);
|
| 42 | compound.setInteger("zPos", p_76690_0_.z);
|
| 43 | compound.setLong("LastUpdate", p_76690_0_.lastUpdated);
|
| 44 | int[] aint = new int[p_76690_0_.heightmap.length];
|
| 45 |
|
| 46 | for (int i = 0; i < p_76690_0_.heightmap.length; ++i)
|
| 47 | {
|
| 48 | aint[i] = p_76690_0_.heightmap[i];
|
| 49 | }
|
| 50 |
|
| 51 | compound.setIntArray("HeightMap", aint);
|
| 52 | compound.setBoolean("TerrainPopulated", p_76690_0_.terrainPopulated);
|
| 53 | NBTTagList nbttaglist = new NBTTagList();
|
| 54 |
|
| 55 | for (int j = 0; j < 8; ++j)
|
| 56 | {
|
| 57 | boolean flag = true;
|
| 58 |
|
| 59 | for (int k = 0; k < 16 && flag; ++k)
|
| 60 | {
|
| 61 | for (int l = 0; l < 16 && flag; ++l)
|
| 62 | {
|
| 63 | for (int i1 = 0; i1 < 16; ++i1)
|
| 64 | {
|
| 65 | int j1 = k << 11 | i1 << 7 | l + (j << 4);
|
| 66 | int k1 = p_76690_0_.blocks[j1];
|
| 67 |
|
| 68 | if (k1 != 0)
|
| 69 | {
|
| 70 | flag = false;
|
| 71 | break;
|
| 72 | }
|
| 73 | }
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | if (!flag)
|
| 78 | {
|
| 79 | byte[] abyte1 = new byte[4096];
|
| 80 | NibbleArray nibblearray = new NibbleArray();
|
| 81 | NibbleArray nibblearray1 = new NibbleArray();
|
| 82 | NibbleArray nibblearray2 = new NibbleArray();
|
| 83 |
|
| 84 | for (int j3 = 0; j3 < 16; ++j3)
|
| 85 | {
|
| 86 | for (int l1 = 0; l1 < 16; ++l1)
|
| 87 | {
|
| 88 | for (int i2 = 0; i2 < 16; ++i2)
|
| 89 | {
|
| 90 | int j2 = j3 << 11 | i2 << 7 | l1 + (j << 4);
|
| 91 | int k2 = p_76690_0_.blocks[j2];
|
| 92 | abyte1[l1 << 8 | i2 << 4 | j3] = (byte)(k2 & 255);
|
| 93 | nibblearray.set(j3, l1, i2, p_76690_0_.data.get(j3, l1 + (j << 4), i2));
|
| 94 | nibblearray1.set(j3, l1, i2, p_76690_0_.skyLight.get(j3, l1 + (j << 4), i2));
|
| 95 | nibblearray2.set(j3, l1, i2, p_76690_0_.blockLight.get(j3, l1 + (j << 4), i2));
|
| 96 | }
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 101 | nbttagcompound.setByte("Y", (byte)(j & 255));
|
| 102 | nbttagcompound.setByteArray("Blocks", abyte1);
|
| 103 | nbttagcompound.setByteArray("Data", nibblearray.getData());
|
| 104 | nbttagcompound.setByteArray("SkyLight", nibblearray1.getData());
|
| 105 | nbttagcompound.setByteArray("BlockLight", nibblearray2.getData());
|
| 106 | nbttaglist.appendTag(nbttagcompound);
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | compound.setTag("Sections", nbttaglist);
|
| 111 | byte[] abyte = new byte[256];
|
| 112 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 113 |
|
| 114 | for (int l2 = 0; l2 < 16; ++l2)
|
| 115 | {
|
| 116 | for (int i3 = 0; i3 < 16; ++i3)
|
| 117 | {
|
| 118 | blockpos$mutableblockpos.set(p_76690_0_.x << 4 | l2, 0, p_76690_0_.z << 4 | i3);
|
| 119 | abyte[i3 << 4 | l2] = (byte)(p_76690_2_.getBiomeGenerator(blockpos$mutableblockpos, BiomeGenBase.field_180279_ad).biomeID & 255);
|
| 120 | }
|
| 121 | }
|
| 122 |
|
| 123 | compound.setByteArray("Biomes", abyte);
|
| 124 | compound.setTag("Entities", p_76690_0_.entities);
|
| 125 | compound.setTag("TileEntities", p_76690_0_.tileEntities);
|
| 126 |
|
| 127 | if (p_76690_0_.tileTicks != null)
|
| 128 | {
|
| 129 | compound.setTag("TileTicks", p_76690_0_.tileTicks);
|
| 130 | }
|
| 131 | }
|
| 132 |
|
| 133 | public static class AnvilConverterData
|
| 134 | {
|
| 135 | public long lastUpdated;
|
| 136 | public boolean terrainPopulated;
|
| 137 | public byte[] heightmap;
|
| 138 | public NibbleArrayReader blockLight;
|
| 139 | public NibbleArrayReader skyLight;
|
| 140 | public NibbleArrayReader data;
|
| 141 | public byte[] blocks;
|
| 142 | public NBTTagList entities;
|
| 143 | public NBTTagList tileEntities;
|
| 144 | public NBTTagList tileTicks;
|
| 145 | public final int x;
|
| 146 | public final int z;
|
| 147 |
|
| 148 | public AnvilConverterData(int xIn, int zIn)
|
| 149 | {
|
| 150 | this.x = xIn;
|
| 151 | this.z = zIn;
|
| 152 | }
|
| 153 | }
|
| 154 | }
|
| 155 |
|