EntityRef worldEntity = worldEntityIterator.next();
worldRenderer.getChunkProvider().setWorldEntity(worldEntity);
// get the world generator config from the world entity
// replace the world generator values from the components in the world entity
WorldGenerator worldGenerator = CoreRegistry.get(WorldGenerator.class);
Optional<WorldConfigurator> ocf = worldGenerator.getConfigurator();
if (ocf.isPresent()) {
Map<String, Component> params = ocf.get().getProperties();
for (Map.Entry<String, Component> entry : params.entrySet()) {
Class<? extends Component> clazz = entry.getValue().getClass();
Component comp = worldEntity.getComponent(clazz);
if (comp != null) {
entry.setValue(comp);
}
}
// save the world config back to the world generator
worldGenerator.setConfigurator(ocf.get());
}
} else {
EntityRef worldEntity = entityManager.create();
worldEntity.addComponent(new WorldComponent());
worldRenderer.getChunkProvider().setWorldEntity(worldEntity);
// transfer all world generation parameters from Config to WorldEntity
WorldGenerator worldGenerator = CoreRegistry.get(WorldGenerator.class);
Optional<WorldConfigurator> ocf = worldGenerator.getConfigurator();
if (ocf.isPresent()) {
SimpleUri generatorUri = worldGenerator.getUri();
Config config = CoreRegistry.get(Config.class);
// get the map of properties from the world generator. Replace its values with values from the config set by the UI.
// Also set all the components to the world entity.
Map<String, Component> params = ocf.get().getProperties();
for (Map.Entry<String, Component> entry : params.entrySet()) {
Class<? extends Component> clazz = entry.getValue().getClass();
Component comp = config.getModuleConfig(generatorUri, entry.getKey(), clazz);
if (comp != null) {
worldEntity.addComponent(comp);
entry.setValue(comp);
} else {
worldEntity.addComponent(entry.getValue());
}
}
// save the world config back to the world generator
worldGenerator.setConfigurator(ocf.get());
}
}