Search in sources :

Example 6 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class EnvironmentSwitchHandler method handleSwitchBackFromPreviewEnvironment.

public void handleSwitchBackFromPreviewEnvironment(Context context) {
    // The newly created ComponentLibrary instance cannot be invalidated in context
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    cheapAssetManagerUpdate(context, environment);
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ModuleManager(org.terasology.engine.module.ModuleManager)

Example 7 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class StorageManagerTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
    FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
    PathManager.getInstance().useOverrideHomePath(temporaryFolder.getRoot().toPath());
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(vfs.getPath("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = context.get(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    biomeManager = context.get(BiomeManager.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, biomeManager, false);
    context.put(StorageManager.class, esm);
    this.character = entityManager.create();
    Client client = createClientMock(PLAYER_ID, character);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
    context.put(NetworkSystem.class, networkSystem);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
    testBlock = context.get(BlockManager.class).getBlock("test:testblock");
    testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
    context.put(ChunkProvider.class, mock(ChunkProvider.class));
    BiomeManager mockBiomeManager = mock(BiomeManager.class);
    when(mockBiomeManager.getBiomes()).thenReturn(Collections.<Biome>emptyList());
    context.put(BiomeManager.class, mockBiomeManager);
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) BiomeManager(org.terasology.world.biomes.BiomeManager) AssetManager(org.terasology.assets.management.AssetManager) NetworkSystem(org.terasology.network.NetworkSystem) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BlockManager(org.terasology.world.block.BlockManager) FileSystem(java.nio.file.FileSystem) WorldProvider(org.terasology.world.WorldProvider) WorldInfo(org.terasology.world.internal.WorldInfo) Client(org.terasology.network.Client) ResourceUrn(org.terasology.assets.ResourceUrn) ChunkProvider(org.terasology.world.chunks.ChunkProvider) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) Before(org.junit.Before)

Example 8 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupModuleManager.

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleRegistry registry = moduleManager.getRegistry();
    DependencyResolver resolver = new DependencyResolver(registry);
    ResolutionResult result = resolver.resolve(moduleNames);
    if (result.isSuccess()) {
        ModuleEnvironment modEnv = moduleManager.loadEnvironment(result.getModules(), true);
        logger.debug("Loaded modules: " + modEnv.getModuleIdsOrderedByDependencies());
    } else {
        logger.error("Could not resolve module dependencies for " + moduleNames);
    }
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleRegistry(org.terasology.module.ModuleRegistry) ModuleManager(org.terasology.engine.module.ModuleManager) DependencyResolver(org.terasology.module.DependencyResolver)

Example 9 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class ApiScraper method main.

/**
 * @param args (ignored)
 * @throws Exception if the module environment cannot be loaded
 */
public static void main(String[] args) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new);
    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        // System.out.println("Processing: " + apiClass);
        boolean isPackage = apiClass.isSynthetic();
        URL location;
        String category;
        String apiPackage = "";
        if (isPackage) {
            apiPackage = apiClass.getPackage().getName();
            location = classLoader.getResource(apiPackage.replace('.', '/'));
        } else {
            location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class");
        }
        if (location == null) {
            System.out.println("Failed to get a class/package location, skipping " + apiClass);
            continue;
        }
        switch(location.getProtocol()) {
            case "jar":
                // Find out what jar it came from and consider that the category
                String categoryFragment = location.getPath();
                // System.out.println("category fragment as path: " + categoryFragment);
                int bang = categoryFragment.lastIndexOf("!");
                int hyphen = categoryFragment.lastIndexOf("-", bang);
                int slash = categoryFragment.lastIndexOf("/", hyphen);
                category = categoryFragment.substring(slash + 1, hyphen);
                if (isPackage) {
                    // System.out.println("Jar-based Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Jar-based Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            case "file":
                // If file based we know it is local so organize it like that
                category = "terasology engine";
                if (isPackage) {
                    // System.out.println("Local Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Local Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            default:
                System.out.println("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
    System.out.println("# Modding API:\n");
    for (String key : sortedApi.keySet()) {
        System.out.println("## " + key + "\n");
        for (String value : sortedApi.get(key)) {
            System.out.println("* " + value);
        }
        System.out.println("");
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) TreeSet(java.util.TreeSet) ModuleManager(org.terasology.engine.module.ModuleManager) URL(java.net.URL)

Example 10 with ModuleEnvironment

use of org.terasology.module.ModuleEnvironment in project Terasology by MovingBlocks.

the class ModulesMetric method updateModules.

private void updateModules() {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    ModuleEnvironment moduleEnvironment = moduleManager.getEnvironment();
    modules.clear();
    Iterator<Module> iterator = moduleEnvironment.iterator();
    while (iterator.hasNext()) {
        Module next = iterator.next();
        modules.add(next);
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module)

Aggregations

ModuleEnvironment (org.terasology.module.ModuleEnvironment)23 ModuleManager (org.terasology.engine.module.ModuleManager)18 DependencyResolver (org.terasology.module.DependencyResolver)9 Module (org.terasology.module.Module)9 ResolutionResult (org.terasology.module.ResolutionResult)9 Name (org.terasology.naming.Name)8 FromModule (org.terasology.module.predicates.FromModule)5 SimpleUri (org.terasology.engine.SimpleUri)4 RegisterBindButton (org.terasology.input.RegisterBindButton)4 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)2 StateMainMenu (org.terasology.engine.modes.StateMainMenu)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 RegisterBindAxis (org.terasology.input.RegisterBindAxis)2 NetworkSystem (org.terasology.network.NetworkSystem)2 WorldProvider (org.terasology.world.WorldProvider)2 BiomeManager (org.terasology.world.biomes.BiomeManager)2 BlockManager (org.terasology.world.block.BlockManager)2 UnresolvedWorldGeneratorException (org.terasology.world.generator.UnresolvedWorldGeneratorException)2 WorldInfo (org.terasology.world.internal.WorldInfo)2 Lists (com.google.common.collect.Lists)1