Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 224 lines 7.2 kB view raw
1package net.minecraft.server; 2 3import java.io.*; 4import java.util.Iterator; 5 6public class ChunkLoader implements IChunkLoader { 7 8 private File a; 9 private boolean b; 10 11 public ChunkLoader(File file1, boolean flag) { 12 this.a = file1; 13 this.b = flag; 14 } 15 16 private File a(int i, int j) { 17 String s = "c." + Integer.toString(i, 36) + "." + Integer.toString(j, 36) + ".dat"; 18 String s1 = Integer.toString(i & 63, 36); 19 String s2 = Integer.toString(j & 63, 36); 20 File file1 = new File(this.a, s1); 21 22 if (!file1.exists()) { 23 if (!this.b) { 24 return null; 25 } 26 27 file1.mkdir(); 28 } 29 30 file1 = new File(file1, s2); 31 if (!file1.exists()) { 32 if (!this.b) { 33 return null; 34 } 35 36 file1.mkdir(); 37 } 38 39 file1 = new File(file1, s); 40 return !file1.exists() && !this.b ? null : file1; 41 } 42 43 public Chunk a(World world, int i, int j) { 44 File file1 = this.a(i, j); 45 46 if (file1 != null && file1.exists()) { 47 try { 48 FileInputStream fileinputstream = new FileInputStream(file1); 49 NBTTagCompound nbttagcompound = CompressedStreamTools.a((InputStream) fileinputstream); 50 51 if (!nbttagcompound.hasKey("Level")) { 52 System.out.println("Chunk file at " + i + "," + j + " is missing level data, skipping"); 53 return null; 54 } 55 56 if (!nbttagcompound.k("Level").hasKey("Blocks")) { 57 System.out.println("Chunk file at " + i + "," + j + " is missing block data, skipping"); 58 return null; 59 } 60 61 Chunk chunk = a(world, nbttagcompound.k("Level")); 62 63 if (!chunk.a(i, j)) { 64 System.out.println("Chunk file at " + i + "," + j + " is in the wrong location; relocating. (Expected " + i + ", " + j + ", got " + chunk.x + ", " + chunk.z + ")"); 65 nbttagcompound.a("xPos", i); 66 nbttagcompound.a("zPos", j); 67 chunk = a(world, nbttagcompound.k("Level")); 68 } 69 70 chunk.h(); 71 return chunk; 72 } catch (Exception exception) { 73 exception.printStackTrace(); 74 } 75 } 76 77 return null; 78 } 79 80 public void a(World world, Chunk chunk) { 81 world.k(); 82 File file1 = this.a(chunk.x, chunk.z); 83 84 if (file1.exists()) { 85 WorldData worlddata = world.q(); 86 87 worlddata.b(worlddata.g() - file1.length()); 88 } 89 90 try { 91 File file2 = new File(this.a, "tmp_chunk.dat"); 92 FileOutputStream fileoutputstream = new FileOutputStream(file2); 93 NBTTagCompound nbttagcompound = new NBTTagCompound(); 94 NBTTagCompound nbttagcompound1 = new NBTTagCompound(); 95 96 nbttagcompound.a("Level", (NBTBase) nbttagcompound1); 97 a(chunk, world, nbttagcompound1); 98 CompressedStreamTools.a(nbttagcompound, (OutputStream) fileoutputstream); 99 fileoutputstream.close(); 100 if (file1.exists()) { 101 file1.delete(); 102 } 103 104 file2.renameTo(file1); 105 WorldData worlddata1 = world.q(); 106 107 worlddata1.b(worlddata1.g() + file1.length()); 108 } catch (Exception exception) { 109 exception.printStackTrace(); 110 } 111 } 112 113 public static void a(Chunk chunk, World world, NBTTagCompound nbttagcompound) { 114 world.k(); 115 nbttagcompound.a("xPos", chunk.x); 116 nbttagcompound.a("zPos", chunk.z); 117 nbttagcompound.setLong("LastUpdate", world.getTime()); 118 nbttagcompound.a("Blocks", chunk.b); 119 nbttagcompound.a("Data", chunk.e.a); 120 nbttagcompound.a("SkyLight", chunk.f.a); 121 nbttagcompound.a("BlockLight", chunk.g.a); 122 nbttagcompound.a("HeightMap", chunk.heightMap); 123 nbttagcompound.a("TerrainPopulated", chunk.done); 124 chunk.q = false; 125 NBTTagList nbttaglist = new NBTTagList(); 126 127 Iterator iterator; 128 NBTTagCompound nbttagcompound1; 129 130 for (int i = 0; i < chunk.entitySlices.length; ++i) { 131 iterator = chunk.entitySlices[i].iterator(); 132 133 while (iterator.hasNext()) { 134 Entity entity = (Entity) iterator.next(); 135 136 chunk.q = true; 137 nbttagcompound1 = new NBTTagCompound(); 138 if (entity.c(nbttagcompound1)) { 139 nbttaglist.a((NBTBase) nbttagcompound1); 140 } 141 } 142 } 143 144 nbttagcompound.a("Entities", (NBTBase) nbttaglist); 145 NBTTagList nbttaglist1 = new NBTTagList(); 146 147 iterator = chunk.tileEntities.values().iterator(); 148 149 while (iterator.hasNext()) { 150 TileEntity tileentity = (TileEntity) iterator.next(); 151 152 nbttagcompound1 = new NBTTagCompound(); 153 tileentity.b(nbttagcompound1); 154 nbttaglist1.a((NBTBase) nbttagcompound1); 155 } 156 157 nbttagcompound.a("TileEntities", (NBTBase) nbttaglist1); 158 } 159 160 public static Chunk a(World world, NBTTagCompound nbttagcompound) { 161 int i = nbttagcompound.e("xPos"); 162 int j = nbttagcompound.e("zPos"); 163 Chunk chunk = new Chunk(world, i, j); 164 165 chunk.b = nbttagcompound.j("Blocks"); 166 chunk.e = new NibbleArray(nbttagcompound.j("Data")); 167 chunk.f = new NibbleArray(nbttagcompound.j("SkyLight")); 168 chunk.g = new NibbleArray(nbttagcompound.j("BlockLight")); 169 chunk.heightMap = nbttagcompound.j("HeightMap"); 170 chunk.done = nbttagcompound.m("TerrainPopulated"); 171 if (!chunk.e.a()) { 172 chunk.e = new NibbleArray(chunk.b.length); 173 } 174 175 if (chunk.heightMap == null || !chunk.f.a()) { 176 chunk.heightMap = new byte[256]; 177 chunk.f = new NibbleArray(chunk.b.length); 178 chunk.initLighting(); 179 } 180 181 if (!chunk.g.a()) { 182 chunk.g = new NibbleArray(chunk.b.length); 183 chunk.a(); 184 } 185 186 NBTTagList nbttaglist = nbttagcompound.l("Entities"); 187 188 if (nbttaglist != null) { 189 for (int k = 0; k < nbttaglist.c(); ++k) { 190 NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(k); 191 Entity entity = EntityTypes.a(nbttagcompound1, world); 192 193 chunk.q = true; 194 if (entity != null) { 195 chunk.a(entity); 196 } 197 } 198 } 199 200 NBTTagList nbttaglist1 = nbttagcompound.l("TileEntities"); 201 202 if (nbttaglist1 != null) { 203 for (int l = 0; l < nbttaglist1.c(); ++l) { 204 NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist1.a(l); 205 TileEntity tileentity = TileEntity.c(nbttagcompound2); 206 207 if (tileentity != null) { 208 chunk.a(tileentity); 209 } 210 } 211 } 212 213 return chunk; 214 } 215 216 public void a() { 217 } 218 219 public void b() { 220 } 221 222 public void b(World world, Chunk chunk) { 223 } 224}