use of org.terasology.engine.world.zones.Zone in project Terasology by MovingBlocks.
the class LayeredZoneRegionFunctionTest method setup.
@BeforeEach
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(ElevationFacet.class, (generatingRegion) -> {
ElevationFacet facet = new ElevationFacet(generatingRegion.getRegion(), generatingRegion.getBorderForFacet(ElevationFacet.class));
for (Vector2ic pos : facet.getRelativeArea()) {
facet.set(pos, 100);
}
generatingRegion.setRegionFacet(ElevationFacet.class, facet);
});
Map<Class<? extends WorldFacet>, Border3D> borders = new HashMap<>();
borders.put(ElevationFacet.class, new Border3D(0, 0, 0));
region = new RegionImpl(new BlockRegion(0, 0, 0).expand(4, 4, 4), facetProviderChains, borders, 1);
}
use of org.terasology.engine.world.zones.Zone 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.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"));
}
use of org.terasology.engine.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 dependencies for " + worldGenUri);
}
}
Aggregations