name = creator.name();
environment = creator.environment();
worldType = creator.type();
generateStructures = creator.generateStructures();
final ChunkGenerator generator = creator.generator();
storageProvider = new AnvilWorldStorageProvider(new File(server.getWorldContainer(), name));
storageProvider.setWorld(this);
chunks = new ChunkManager(this, storageProvider.getChunkIoService(), generator);
populators = generator.getDefaultPopulators(this);
// set up values from server defaults
ticksPerAnimal = server.getTicksPerAnimalSpawns();
ticksPerMonster = server.getTicksPerMonsterSpawns();
monsterLimit = server.getMonsterSpawnLimit();
animalLimit = server.getAnimalSpawnLimit();
waterAnimalLimit = server.getWaterAnimalSpawnLimit();
ambientLimit = server.getAmbientSpawnLimit();
keepSpawnLoaded = server.keepSpawnLoaded();
difficulty = server.getDifficulty();
// read in world data
WorldFinalValues values = null;
try {
values = storageProvider.getMetadataService().readWorldData();
} catch (IOException e) {
server.getLogger().log(Level.SEVERE, "Error reading world for creation", e);
}
if (values != null) {
if (values.getSeed() == 0L) {
this.seed = creator.seed();
} else {
this.seed = values.getSeed();
}
this.uid = values.getUuid();
} else {
this.seed = creator.seed();
this.uid = UUID.randomUUID();
}
// begin loading spawn area
spawnChunkLock = newChunkLock("spawn");
server.addWorld(this);
server.getLogger().info("Preparing spawn for " + name + "...");
EventFactory.callEvent(new WorldInitEvent(this));
// determine the spawn location if we need to
if (spawnLocation == null) {
// no location loaded, look for fixed spawn
spawnLocation = generator.getFixedSpawnLocation(this, random);
if (spawnLocation == null) {
// determine a location randomly
int spawnX = random.nextInt(128) - 64, spawnZ = random.nextInt(128) - 64;
GlowChunk chunk = getChunkAt(spawnX >> 4, spawnZ >> 4);
//GlowServer.logger.info("determining spawn: " + chunk.getX() + " " + chunk.getZ());
chunk.load(true); // I'm not sure there's a sane way around this
for (int tries = 0; tries < 10 && !generator.canSpawn(this, spawnX, spawnZ); ++tries) {
spawnX += random.nextInt(128) - 64;
spawnZ += random.nextInt(128) - 64;
}
setSpawnLocation(spawnX, getHighestBlockYAt(spawnX, spawnZ), spawnZ);
}