use of org.terasology.engine.world.generator.WorldGenerator in project Terasology by MovingBlocks.
the class NetworkSystemImpl method getServerInfoMessage.
private NetData.ServerInfoMessage getServerInfoMessage(String errorMessage) {
NetData.ServerInfoMessage.Builder serverInfoMessageBuilder = NetData.ServerInfoMessage.newBuilder();
serverInfoMessageBuilder.setTime(time.getGameTimeInMs());
if (config.getServerMOTD() != null) {
serverInfoMessageBuilder.setMOTD(config.getServerMOTD());
}
serverInfoMessageBuilder.setOnlinePlayersAmount(clientList.size());
WorldProvider worldProvider = context.get(WorldProvider.class);
if (worldProvider != null) {
NetData.WorldInfo.Builder worldInfoBuilder = NetData.WorldInfo.newBuilder();
worldInfoBuilder.setTime(worldProvider.getTime().getMilliseconds());
worldInfoBuilder.setTitle(worldProvider.getTitle());
serverInfoMessageBuilder.addWorldInfo(worldInfoBuilder);
}
WorldGenerator worldGen = context.get(WorldGenerator.class);
if (worldGen != null) {
serverInfoMessageBuilder.setReflectionHeight(worldGen.getWorld().getSeaLevel() + 0.5f);
}
for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
if (!StandardModuleExtension.isServerSideOnly(module)) {
serverInfoMessageBuilder.addModule(NetData.ModuleInfo.newBuilder().setModuleId(module.getId().toString()).setModuleVersion(module.getVersion().toString()).build());
}
}
for (Map.Entry<String, Short> blockMapping : blockManager.getBlockIdMap().entrySet()) {
serverInfoMessageBuilder.addBlockId(blockMapping.getValue());
serverInfoMessageBuilder.addBlockName(blockMapping.getKey());
}
for (BlockFamily registeredBlockFamily : blockManager.listRegisteredBlockFamilies()) {
serverInfoMessageBuilder.addRegisterBlockFamily(registeredBlockFamily.getURI().toString());
}
if (errorMessage != null && !errorMessage.isEmpty()) {
serverInfoMessageBuilder.setErrorMessage(errorMessage);
}
serializeComponentInfo(serverInfoMessageBuilder);
serializeEventInfo(serverInfoMessageBuilder);
return serverInfoMessageBuilder.build();
}
use of org.terasology.engine.world.generator.WorldGenerator in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method setEnvironment.
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
*
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
context = subContext;
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
worldList = context.get(UniverseSetupScreen.class).getWorldsList();
selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
worldNames = context.get(UniverseSetupScreen.class).worldNames();
setWorldGenerators();
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.setOptions(worldNames);
genTexture();
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
}
}
use of org.terasology.engine.world.generator.WorldGenerator 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.WorldGenerator in project Terasology by MovingBlocks.
the class InitialiseWorldGenerator method step.
@Override
public boolean step() {
WorldGenerator worldGenerator = context.get(WorldGenerator.class);
worldGenerator.initialize();
WorldRenderer worldRenderer = context.get(WorldRenderer.class);
worldRenderer.getActiveCamera().setReflectionHeight(worldGenerator.getWorld().getSeaLevel() + 0.5f);
return true;
}
use of org.terasology.engine.world.generator.WorldGenerator in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method addGameManifestToSaveTransaction.
private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
BlockManager blockManager = CoreRegistry.get(BlockManager.class);
UniverseConfig universeConfig = config.getUniverseConfig();
Time time = CoreRegistry.get(Time.class);
Game game = CoreRegistry.get(Game.class);
GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
gameManifest.addModule(module.getId(), module.getVersion());
}
List<String> registeredBlockFamilies = Lists.newArrayList();
for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
registeredBlockFamilies.add(family.getURI().toString());
}
gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
List<WorldInfo> worlds = universeConfig.getWorlds();
for (WorldInfo worldInfo : worlds) {
gameManifest.addWorld(worldInfo);
}
WorldGenerator worldGenerator = CoreRegistry.get(WorldGenerator.class);
if (worldGenerator != null) {
WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
Map<String, Component> params = worldConfigurator.getProperties();
gameManifest.setModuleConfigs(worldGenerator.getUri(), params);
}
saveTransactionBuilder.setGameManifest(gameManifest);
}
Aggregations