return "Creating World Entity...";
}
@Override
public boolean step() {
EntityManager entityManager = CoreRegistry.get(EntityManager.class);
WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
Iterator<EntityRef> worldEntityIterator = entityManager.getEntitiesWith(WorldComponent.class).iterator();
// TODO: Move the world renderer bits elsewhere
if (worldEntityIterator.hasNext()) {
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);