use of org.terasology.engine.world.generator.UnresolvedWorldGeneratorException in project Terasology by MovingBlocks.
the class InitialiseWorld method step.
@Override
public boolean step() {
BlockManager blockManager = context.get(BlockManager.class);
ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
verify(worldInfo.getWorldGenerator().isValid(), "Game manifest did not specify world type.");
if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
FastRandom random = new FastRandom();
worldInfo.setSeed(random.nextString(16));
}
logger.info("World seed: \"{}\"", worldInfo.getSeed());
// TODO: Separate WorldRenderer from world handling in general
WorldGeneratorManager worldGeneratorManager = context.get(WorldGeneratorManager.class);
WorldGenerator worldGenerator;
try {
worldGenerator = WorldGeneratorManager.createGenerator(worldInfo.getWorldGenerator(), context);
// setting the world seed will create the world builder
worldGenerator.setWorldSeed(worldInfo.getSeed());
context.put(WorldGenerator.class, worldGenerator);
} catch (UnresolvedWorldGeneratorException e) {
logger.error("Unable to load world generator {}. Available world generators: {}", worldInfo.getWorldGenerator(), worldGeneratorManager.getWorldGenerators());
context.get(GameEngine.class).changeState(new StateMainMenu("Failed to resolve world generator."));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
// Init. a new world
EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
boolean writeSaveGamesEnabled = context.get(SystemConfig.class).writeSaveGamesEnabled.get();
// Gets save data from a normal save or from a recording if it is a replay
Path saveOrRecordingPath = getSaveOrRecordingPath();
StorageManager storageManager;
RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
try {
storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus) : new ReadOnlyStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager);
} catch (IOException e) {
logger.error("Unable to create storage manager!", e);
context.get(GameEngine.class).changeState(new StateMainMenu("Unable to create storage manager!"));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
context.put(StorageManager.class, storageManager);
LocalChunkProvider chunkProvider = new LocalChunkProvider(storageManager, entityManager, worldGenerator, blockManager, extraDataManager, Maps.newConcurrentMap());
RelevanceSystem relevanceSystem = new RelevanceSystem(chunkProvider);
context.put(RelevanceSystem.class, relevanceSystem);
context.get(ComponentSystemManager.class).register(relevanceSystem, "engine:relevanceSystem");
chunkProvider.setRelevanceSystem(relevanceSystem);
Block unloadedBlock = blockManager.getBlock(BlockManager.UNLOADED_ID);
WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(worldInfo, chunkProvider, unloadedBlock, context);
EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager);
context.put(WorldProvider.class, worldProvider);
chunkProvider.setBlockEntityRegistry(entityWorldProvider);
context.put(BlockEntityRegistry.class, entityWorldProvider);
context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
context.put(CelestialSystem.class, celestialSystem);
context.get(ComponentSystemManager.class).register(celestialSystem);
Skysphere skysphere = new Skysphere(context);
BackdropProvider backdropProvider = skysphere;
context.put(BackdropProvider.class, backdropProvider);
RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
context.put(WorldRenderer.class, worldRenderer);
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
LocalPlayer localPlayer = new LocalPlayer();
localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
context.put(LocalPlayer.class, localPlayer);
context.put(Camera.class, worldRenderer.getActiveCamera());
return true;
}
use of org.terasology.engine.world.generator.UnresolvedWorldGeneratorException in project Terasology by MovingBlocks.
the class UniverseSetupScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
final UIDropdownScrollable<WorldGeneratorInfo> worldGenerator = find("worldGenerators", UIDropdownScrollable.class);
if (worldGenerator != null) {
worldGenerator.bindOptions(new ReadOnlyBinding<List<WorldGeneratorInfo>>() {
@Override
public List<WorldGeneratorInfo> get() {
// grab all the module names and their dependencies
// This grabs modules from `config.getDefaultModSelection()` which is updated in AdvancedGameSetupScreen
final Set<Name> enabledModuleNames = new HashSet<>(getAllEnabledModuleNames());
final List<WorldGeneratorInfo> result = Lists.newArrayList();
for (WorldGeneratorInfo option : worldGeneratorManager.getWorldGenerators()) {
if (enabledModuleNames.contains(option.getUri().getModuleName())) {
result.add(option);
}
}
return result;
}
});
worldGenerator.setVisibleOptions(3);
worldGenerator.bindSelection(new Binding<WorldGeneratorInfo>() {
@Override
public WorldGeneratorInfo get() {
// get the default generator from the config. This is likely to have a user triggered selection.
WorldGeneratorInfo info = worldGeneratorManager.getWorldGeneratorInfo(config.getWorldGeneration().getDefaultGenerator());
if (info != null && getAllEnabledModuleNames().contains(info.getUri().getModuleName())) {
return info;
}
// just use the first available generator
for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
if (getAllEnabledModuleNames().contains(worldGenInfo.getUri().getModuleName())) {
set(worldGenInfo);
return worldGenInfo;
}
}
return null;
}
@Override
public void set(WorldGeneratorInfo value) {
if (value != null) {
config.getWorldGeneration().setDefaultGenerator(value.getUri());
}
}
});
worldGenerator.setOptionRenderer(new StringTextRenderer<WorldGeneratorInfo>() {
@Override
public String getString(WorldGeneratorInfo value) {
if (value != null) {
return value.getDisplayName();
}
return "";
}
});
}
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.bindSelection(new Binding<String>() {
@Override
public String get() {
return selectedWorld;
}
@Override
public void set(String value) {
selectedWorld = value;
indexOfSelectedWorld = findIndex(worlds, selectedWorld);
}
});
WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
WidgetUtil.trySubscribe(this, "worldConfig", button -> {
final WorldSetupScreen worldSetupScreen = getManager().createScreen(WorldSetupScreen.ASSET_URI, WorldSetupScreen.class);
try {
if (!worlds.isEmpty() || !selectedWorld.isEmpty()) {
worldSetupScreen.setWorld(context, findWorldByName(), worldsDropdown);
triggerForwardAnimation(worldSetupScreen);
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
}
} catch (UnresolvedWorldGeneratorException e) {
logger.error("Can't configure the world! due to {}", e.getMessage());
}
});
WidgetUtil.trySubscribe(this, "addGenerator", button -> {
// modules may do
if (worldGenerator.getSelection().getUri().toString().equals("CoreWorlds:heightMap")) {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("HeightMap not supported", "HeightMap is not supported for advanced setup right now, a game template will be introduced soon.");
} else {
addNewWorld(worldGenerator.getSelection());
worldsDropdown.setOptions(worldNames());
}
});
WidgetUtil.trySubscribe(this, "continue", button -> {
final WorldPreGenerationScreen worldPreGenerationScreen = getManager().createScreen(WorldPreGenerationScreen.ASSET_URI, WorldPreGenerationScreen.class);
if (!worlds.isEmpty()) {
final WaitPopup<Boolean> loadPopup = getManager().pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
loadPopup.setMessage("Loading", "please wait ...");
loadPopup.onSuccess(result -> {
if (result != null && result) {
triggerForwardAnimation(worldPreGenerationScreen);
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't load world pre generation screen! Please, try again!");
}
});
loadPopup.startOperation(() -> {
try {
worldPreGenerationScreen.setEnvironment(context);
} catch (UnresolvedWorldGeneratorException e) {
return false;
}
return true;
}, true);
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "Please select a world generator and add words to the dropdown!");
}
});
WidgetUtil.trySubscribe(this, "mainMenu", button -> {
getManager().pushScreen("engine:mainMenuScreen");
});
}
Aggregations