Search in sources :

Example 1 with Module

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);
}
Also used : Module(org.terasology.gestalt.module.Module)

Example 2 with Module

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());
    }
}
Also used : UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 3 with Module

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);
}
Also used : RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 4 with Module

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();
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) ByteString(com.google.protobuf.ByteString) ModuleManager(org.terasology.engine.core.module.ModuleManager) WorldProvider(org.terasology.engine.world.WorldProvider) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) TIntLongMap(gnu.trove.map.TIntLongMap) TIntLongHashMap(gnu.trove.map.hash.TIntLongHashMap)

Example 5 with Module

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;
}
Also used : ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) UIWidget(org.terasology.nui.UIWidget)

Aggregations

Module (org.terasology.gestalt.module.Module)51 ModuleManager (org.terasology.engine.core.module.ModuleManager)18 Name (org.terasology.gestalt.naming.Name)17 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)13 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)11 List (java.util.List)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 SimpleUri (org.terasology.engine.core.SimpleUri)9 UILabel (org.terasology.nui.widgets.UILabel)9 UIText (org.terasology.nui.widgets.UIText)9 DependencyInfo (org.terasology.gestalt.module.dependencyresolution.DependencyInfo)8 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)8 Canvas (org.terasology.nui.Canvas)8 Collection (java.util.Collection)7 Comparator (java.util.Comparator)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)7 In (org.terasology.engine.registry.In)7