Search in sources :

Example 1 with Zone

use of org.terasology.world.zones.Zone in project Terasology by MovingBlocks.

the class ZoneTest method testGetChildZones.

@Test
public void testGetChildZones() {
    assertTrue(zone.getChildZones().isEmpty());
    Zone child = new Zone("Child", () -> false);
    zone.addZone(child);
    assertFalse(zone.getChildZones().isEmpty());
    assertTrue(zone.getChildZones().contains(child));
    try {
        zone.getChildZone("Invalid name");
        fail();
    } catch (Exception e) {
    }
    assertEquals(child, zone.getChildZone("Child"));
}
Also used : Zone(org.terasology.world.zones.Zone) Test(org.junit.Test)

Example 2 with Zone

use of org.terasology.world.zones.Zone in project Terasology by MovingBlocks.

the class PreviewWorldScreen method setEnvironment.

public void setEnvironment() throws Exception {
    // TODO: pass world gen and module list directly rather than using the config
    SimpleUri worldGenUri = config.getWorldGeneration().getDefaultGenerator();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        subContext = new ContextImpl(context);
        CoreRegistry.setContext(subContext);
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        subContext.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, subContext));
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        environmentSwitchHandler.handleSwitchToPreviewEnvironment(subContext, environment);
        genTexture();
        worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, subContext, environment);
        worldGenerator.setWorldSeed(seed.getText());
        List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
        if (previewZones.isEmpty()) {
            zoneSelector.setVisible(false);
            previewGen = new FacetLayerPreview(environment, worldGenerator);
        } else {
            zoneSelector.setVisible(true);
            zoneSelector.setOptions(previewZones);
            zoneSelector.setSelection(previewZones.get(0));
        }
        configureProperties();
    } else {
        throw new UnresolvedDependencyException("Unable to resolve depencencies for " + worldGenUri);
    }
}
Also used : CoreScreenLayer(org.terasology.rendering.nui.CoreScreenLayer) Zone(org.terasology.world.zones.Zone) ContextImpl(org.terasology.context.internal.ContextImpl) DependencyResolver(org.terasology.module.DependencyResolver) UISlider(org.terasology.rendering.nui.widgets.UISlider) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) Property(org.terasology.rendering.nui.properties.Property) ByteBuffer(java.nio.ByteBuffer) WorldConfigurator(org.terasology.world.generator.WorldConfigurator) Map(java.util.Map) PropertyLayout(org.terasology.rendering.nui.layouts.PropertyLayout) SimpleUri(org.terasology.engine.SimpleUri) TeraMath(org.terasology.math.TeraMath) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) WidgetUtil(org.terasology.rendering.nui.WidgetUtil) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) Collectors(java.util.stream.Collectors) PropertyProvider(org.terasology.rendering.nui.properties.PropertyProvider) UIImage(org.terasology.rendering.nui.widgets.UIImage) Objects(java.util.Objects) List(java.util.List) UnresolvedDependencyException(org.terasology.module.exceptions.UnresolvedDependencyException) CoreRegistry(org.terasology.registry.CoreRegistry) TextureData(org.terasology.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.assets.ResourceUrn) In(org.terasology.registry.In) MenuAnimationSystems(org.terasology.rendering.nui.animation.MenuAnimationSystems) Texture(org.terasology.rendering.assets.texture.Texture) Callable(java.util.concurrent.Callable) FacetLayerPreview(org.terasology.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) Lists(com.google.common.collect.Lists) WorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary) ResolutionResult(org.terasology.module.ResolutionResult) NUIManager(org.terasology.rendering.nui.NUIManager) ModuleManager(org.terasology.engine.module.ModuleManager) Assets(org.terasology.utilities.Assets) Logger(org.slf4j.Logger) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) TempWorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.TempWorldGeneratorPluginLibrary) UIText(org.terasology.rendering.nui.widgets.UIText) WorldGeneratorManager(org.terasology.world.generator.internal.WorldGeneratorManager) UIDropdown(org.terasology.rendering.nui.widgets.UIDropdown) WorldGenerator(org.terasology.world.generator.WorldGenerator) Binding(org.terasology.rendering.nui.databinding.Binding) PreviewGenerator(org.terasology.rendering.nui.layers.mainMenu.preview.PreviewGenerator) Component(org.terasology.entitySystem.Component) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler) UIButton(org.terasology.rendering.nui.widgets.UIButton) PropertyOrdering(org.terasology.rendering.nui.properties.PropertyOrdering) Zone(org.terasology.world.zones.Zone) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.world.generator.plugin.TempWorldGeneratorPluginLibrary) UnresolvedDependencyException(org.terasology.module.exceptions.UnresolvedDependencyException) ContextImpl(org.terasology.context.internal.ContextImpl) FacetLayerPreview(org.terasology.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) DependencyResolver(org.terasology.module.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.bootstrap.EnvironmentSwitchHandler)

Example 3 with Zone

use of org.terasology.world.zones.Zone in project Terasology by MovingBlocks.

the class LayeredZoneRegionFunctionTest method setup.

@Before
public void setup() {
    parent.addZone(new Zone("Medium sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_SKY))).addZone(new Zone("Low sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), LOW_SKY))).addZone(new Zone("Above ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), ABOVE_GROUND))).addZone(new Zone("Ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), GROUND))).addZone(new Zone("Shallow underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), SHALLOW_UNDERGROUND))).addZone(new Zone("Medium underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_UNDERGROUND)));
    parent.setSeed(12345);
    parent.initialize();
    ListMultimap<Class<? extends WorldFacet>, FacetProvider> facetProviderChains = ArrayListMultimap.create();
    facetProviderChains.put(SurfaceHeightFacet.class, (generatingRegion) -> {
        SurfaceHeightFacet facet = new SurfaceHeightFacet(generatingRegion.getRegion(), generatingRegion.getBorderForFacet(SurfaceHeightFacet.class));
        for (BaseVector2i pos : facet.getRelativeRegion().contents()) {
            facet.set(pos, 100);
        }
        generatingRegion.setRegionFacet(SurfaceHeightFacet.class, facet);
    });
    Map<Class<? extends WorldFacet>, Border3D> borders = new HashMap<>();
    borders.put(SurfaceHeightFacet.class, new Border3D(0, 0, 0));
    region = new RegionImpl(Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), 4), facetProviderChains, borders);
}
Also used : HashMap(java.util.HashMap) Zone(org.terasology.world.zones.Zone) FacetProvider(org.terasology.world.generation.FacetProvider) Border3D(org.terasology.world.generation.Border3D) MinMaxLayerThickness(org.terasology.world.zones.MinMaxLayerThickness) LayeredZoneRegionFunction(org.terasology.world.zones.LayeredZoneRegionFunction) WorldFacet(org.terasology.world.generation.WorldFacet) SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Vector3i(org.terasology.math.geom.Vector3i) RegionImpl(org.terasology.world.generation.RegionImpl) Before(org.junit.Before)

Aggregations

Zone (org.terasology.world.zones.Zone)3 Lists (com.google.common.collect.Lists)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)1 Config (org.terasology.config.Config)1 Context (org.terasology.context.Context)1 ContextImpl (org.terasology.context.internal.ContextImpl)1 SimpleUri (org.terasology.engine.SimpleUri)1 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)1