use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class PrefabSerializer method deserializeDeltaOnto.
public void deserializeDeltaOnto(EntityData.Prefab delta, PrefabData result) {
Module context = ModuleContext.getContext();
applyCommonDataDelta(delta, result);
applyComponentChanges(context, delta, result);
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class WorldGeneratorManager method createGenerator.
/**
* @param uri uri of the world generator to create.
* @param context objects from this context will be injected into the
* @return The instantiated world generator.
*/
public static WorldGenerator createGenerator(SimpleUri uri, Context context) throws UnresolvedWorldGeneratorException {
ModuleManager moduleManager = context.get(ModuleManager.class);
Module module = moduleManager.getEnvironment().get(uri.getModuleName());
if (module == null) {
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(uri.getModuleName());
if (!result.isSuccess()) {
if (moduleManager.getRegistry().getLatestModuleVersion(uri.getModuleName()) == null) {
throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
} else {
throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - unable to resolve module dependencies");
}
}
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
return createWorldGenerator(uri, context, environment);
}
} else {
return createWorldGenerator(uri, context, moduleManager.getEnvironment());
}
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class WorldGeneratorManager method refresh.
public void refresh() {
ModuleManager moduleManager = verifyNotNull(context.get(ModuleManager.class), "no ModuleManager");
List<WorldGeneratorInfo> infos = Lists.newArrayList();
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult resolutionResult = resolver.resolve(module.getId());
if (resolutionResult.isSuccess()) {
try (ModuleEnvironment tempEnvironment = moduleManager.loadEnvironment(resolutionResult.getModules(), false)) {
for (Class<?> generatorClass : tempEnvironment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) {
if (tempEnvironment.getModuleProviding(generatorClass).equals(module.getId())) {
RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class);
if (isValidWorldGenerator(generatorClass)) {
SimpleUri uri = new SimpleUri(moduleId, annotation.id());
infos.add(new WorldGeneratorInfo(uri, annotation.displayName(), annotation.description()));
} else {
logger.error("{} marked to be registered as a World Generator, " + "but is not a subclass of WorldGenerator or lacks the correct constructor", generatorClass);
}
}
}
} catch (Exception e) {
logger.error("Error loading world generator in module {}, skipping", module.getId(), e);
}
} else {
logger.warn("Could not resolve dependencies for module: {}", module);
}
}
Collections.sort(infos);
generatorInfo = ImmutableList.copyOf(infos);
}
use of org.terasology.gestalt.module.Module 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.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManagerFactory method create.
public static ModuleManager create() throws Exception {
// Loading screens, among other things, break when NUI classes are not added to engine.
ModuleManager moduleManager = new ModuleManager("", ImmutableList.of(UIWidget.class));
Module unittestModule = moduleManager.registerPackageModule("org.terasology.unittest");
moduleManager.resolveAndLoadEnvironment(unittestModule.getId());
return moduleManager;
}
Aggregations