use of net.minecraft.util.LongHashMap in project RFTools by McJty.
the class WorldRefresher method refreshChunksBad.
public static void refreshChunksBad(World world) {
try {
ChunkProviderServer chunkServer = (ChunkProviderServer) world.getChunkProvider();
Field u;
try {
// chunksToUnload
u = ChunkProviderServer.class.getDeclaredField("field_73248_b");
} catch (NoSuchFieldException e) {
u = ChunkProviderServer.class.getDeclaredField("chunksToUnload");
}
u.setAccessible(true);
Set<?> unloadQueue = (Set<?>) u.get(chunkServer);
Field m;
try {
// loadedChunkHashMap
m = ChunkProviderServer.class.getDeclaredField("field_73244_f");
} catch (NoSuchFieldException e) {
m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap");
}
m.setAccessible(true);
LongHashMap loadedMap = (LongHashMap) m.get(chunkServer);
Field lc;
try {
// loadedChunkHashMap
lc = ChunkProviderServer.class.getDeclaredField("field_73245_g");
} catch (NoSuchFieldException e) {
lc = ChunkProviderServer.class.getDeclaredField("loadedChunks");
}
lc.setAccessible(true);
@SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
Field p;
try {
// currentChunkProvider
p = ChunkProviderServer.class.getDeclaredField("field_73246_d");
} catch (NoSuchFieldException e) {
p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider");
}
p.setAccessible(true);
IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer);
List<ChunkCoordIntPair> toUnload = new ArrayList<ChunkCoordIntPair>();
for (Object obj : chunkServer.loadedChunks) {
Chunk chunk = (Chunk) obj;
toUnload.add(chunk.getChunkCoordIntPair());
}
for (ChunkCoordIntPair pair : toUnload) {
int x = pair.chunkXPos;
int z = pair.chunkZPos;
long pos = ChunkCoordIntPair.chunkXZ2Int(x, z);
Chunk chunk;
if (chunkServer.chunkExists(x, z)) {
chunk = chunkServer.loadChunk(x, z);
chunk.onChunkUnload();
}
unloadQueue.remove(pos);
loadedMap.remove(pos);
chunk = chunkProvider.provideChunk(x, z);
loadedMap.add(pos, chunk);
loaded.add(chunk);
if (chunk != null) {
chunk.onChunkLoad();
chunk.populateChunk(chunkProvider, chunkProvider, x, z);
}
}
} catch (Exception e) {
Logging.logError("Failed to regenerate chunks!");
e.printStackTrace();
}
}
Aggregations