}
WorldServer worldObj = DimensionManager.getWorld(0);
if (worldObj == null) {
LogHelper.warning("Target dimension 0 is not loaded for genesis?!");
}
ChunkProviderServer providerServer = (ChunkProviderServer) worldObj.getChunkProvider();
GenesisChunkProvider providerGenesis = new GenesisChunkProvider(world, newBiome);
// clear players from the danger zone and force unload chunks in
// question
List<EntityPlayerMP> players = new ArrayList<EntityPlayerMP>();
Map<EntityPlayerMP, Vec3> playerOrigPositions = new HashMap<EntityPlayerMP, Vec3>();
players.addAll(worldObj.playerEntities);
final int safePad = 2;
final double safeX = ( ( chunkX.intValue() - range - safePad ) << 4 ) - 8.0;
final double safeZ = ( ( chunkZ.intValue() - range - safePad ) << 4 ) - 8.0;
LogHelper.info("Safe position = " + safeX + "," + safeZ);
Map<Pair<Integer, Integer>, Chunk> chunks = new HashMap<Pair<Integer, Integer>, Chunk>();
for (int x1 = chunkX.intValue() - range; x1 <= chunkX.intValue() + range; x1++) {
for (int z1 = chunkZ.intValue() - range; z1 <= chunkZ.intValue() + range; z1++) {
for (EntityPlayerMP player : players) {
if (worldObj.getPlayerManager().isPlayerWatchingChunk(player, x1, z1) && !playerOrigPositions.containsKey(player)) {
final Vec3 origPosition = Vec3.createVectorHelper(player.posX, player.posY,player.posZ);
playerOrigPositions.put(player, origPosition);
LogHelper.info("Moving player " + player);
player.setLocationAndAngles(safeX, player.posY, safeZ, 0.0F, 0.0F);
worldObj.updateEntityWithOptionalForce(player, true);
}
}
final Chunk chunk = world.getChunkFromBlockCoords(x, z);
chunks.put(Pair.of(x1, z1), chunk); // save map of chunks
providerServer.unloadChunksIfNotNearSpawn(x1, z1);
}
}
// verify that chunks unloaded
int lastloaded = 0;
while (providerServer.getLoadedChunkCount() != lastloaded) {
lastloaded = providerServer.getLoadedChunkCount();
providerServer.unloadQueuedChunks();
for (final Pair<Integer, Integer> coord : chunks.keySet()) {
final Chunk chunk = chunks.get(coord);
if (chunk != null) {
if (chunk.isChunkLoaded) {
LogHelper.warning("Failed to unload chunk @ " + coord);
/*
* } else { LogHelper.info("Chunk unloaded @ " + coord);
*/
}
}
}
}
chunks.clear();
LogHelper.info(providerServer.makeString());
IChunkLoader chunkloader = providerServer.currentChunkLoader;
providerServer.currentChunkLoader = null;
for (int x1 = chunkX.intValue() - range; x1 <= chunkX.intValue() + range; x1++) {
for (int z1 = chunkZ.intValue() - range; z1 <= chunkZ.intValue() + range; z1++) {
// GenesisBiomeOverrideHandler.myQueue.add(new
// GenesisBiomeOverrideHandler.coord(x1, z1));
final Chunk chunk = providerServer.loadChunk(x1, z1);
byte[] chunkBiomes = chunk.getBiomeArray();
for (int k = 0; k < chunkBiomes.length; ++k) {
chunkBiomes[k] = (byte) newBiome.biomeID;
}