@Override public Block getBlock(int x, int y, int z) { Vector3i pos = new Vector3i(x, y, z); Block block = blocks.get(pos); if (block != null) { return block; } // TODO block & biome manager Vector3i chunkPos = ChunkMath.calcChunkPos(pos); Chunk chunk = chunks.get(chunkPos); if (chunk == null && worldGenerator != null) { chunk = new ChunkImpl(chunkPos, blockManager, biomeManager, extraDataManager); worldGenerator.createChunk(chunk, entityBuffer); chunks.put(chunkPos, chunk); } if (chunk != null) { return chunk.getBlock(ChunkMath.calcBlockPos(pos.x, pos.y, pos.z)); } return null; }
@Override public boolean step() { WorldGenerator worldGenerator = context.get(WorldGenerator.class); worldGenerator.initialize(); WorldRenderer worldRenderer = context.get(WorldRenderer.class); worldRenderer.getActiveCamera().setReflectionHeight(worldGenerator.getWorld().getSeaLevel() + 0.5f); return true; }
private void resetEnvironment() { CoreRegistry.setContext(context); if (environment != null) { EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class); environmentSwitchHandler.handleSwitchBackFromPreviewEnvironment(subContext); environment.close(); environment = null; } previewGen.close(); WorldConfigurator worldConfig = worldGenerator.getConfigurator(); Map<String, Component> params = worldConfig.getProperties(); if (params != null) { config.setModuleConfigs(worldGenerator.getUri(), params); } }
@Override public void set(String value) { selectedWorld = value; try { if (findWorldByName(selectedWorld).getWorldGenerator() == null) { worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment); findWorldByName(selectedWorld).setWorldGenerator(worldGenerator); } else { worldGenerator = findWorldByName(selectedWorld).getWorldGenerator(); } if (worldGenerator.getWorldSeed() == null) { worldGenerator.setWorldSeed(createSeed(selectedWorld)); } previewGen = new FacetLayerPreview(environment, worldGenerator); updatePreview(); } catch (UnresolvedWorldGeneratorException e) { e.printStackTrace(); } } });
public void setupWorldProvider(WorldGenerator generator) { generator.initialize(); WorldProviderCore stub = new MapWorldProvider(generator, context.get(BlockManager.class), Mockito.mock(BiomeManager.class), context.get(ExtraBlockDataManager.class)); WorldProvider world = new WorldProviderWrapper(stub, context.get(ExtraBlockDataManager.class)); CoreRegistry.put(WorldProvider.class, world); CoreRegistry.put(BlockEntityRegistry.class, new EntityAwareWorldProvider(stub, context)); }
worldGenerator.setWorldSeed(seed.getText()); List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()) .stream() .filter(z -> !z.getPreviewLayers().isEmpty())
/** * Determines a spawn position suitable for this world, such as that used to spawn the initial player. * The default implementation simply picks a position in the very center of the world. * * @param entity the entity related to spawning, if needed (or not). Can be ignored. * @return the chosen position */ default Vector3f getSpawnPosition(EntityRef entity) { return new FixedSpawner(0, 0).getSpawnPosition(getWorld(), entity); } }
private void setWorldGenerators() { for (WorldSetupWrapper worldSetupWrapper : worldList) { if (worldSetupWrapper.getWorldGenerator() == null) { try { worldSetupWrapper.setWorldGenerator(WorldGeneratorManager.createWorldGenerator(findWorldByName(worldSetupWrapper.getWorldName().toString()).getWorldGeneratorInfo().getUri(), context, environment)); } catch (UnresolvedWorldGeneratorException e) { e.printStackTrace(); } } worldSetupWrapper.getWorldGenerator().setWorldSeed(createSeed(worldSetupWrapper.getWorldName().toString())); } }
private void fetchWorldGenerator() { WorldGenerator generator = CoreRegistry.get(WorldGenerator.class); if (generator != null) { worldGenerator = generator.getUri().toString(); } }
@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = {ClientComponent.class}) public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) { EntityRef clientInfo = entity.getComponent(ClientComponent.class).clientInfo; Vector3f spawnPosition; if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) { spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position; } else { spawnPosition = worldGenerator.getSpawnPosition(entity); } LocationComponent loc = entity.getComponent(LocationComponent.class); loc.setWorldPosition(spawnPosition); loc.setLocalRotation(new Quat4f()); // reset rotation entity.saveComponent(loc); }
/** * 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); } }
i++; uri = world.getWorldGeneratorInfo().getUri(); worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD + i, world.getWorldName().toString(), world.getWorldGenerator().getWorldSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), uri); gameManifest.addWorld(worldInfo);
@Override public void onOpened() { try { if (findWorldByName(selectedWorld).getWorldGenerator() == null) { worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment); findWorldByName(selectedWorld).setWorldGenerator(worldGenerator); } else { worldGenerator = findWorldByName(selectedWorld).getWorldGenerator(); } if (worldGenerator.getWorldSeed().isEmpty()) { worldGenerator.setWorldSeed(createSeed(selectedWorld)); } previewGen = new FacetLayerPreview(environment, worldGenerator); updatePreview(); } catch (UnresolvedWorldGeneratorException e) { e.printStackTrace(); } }
public FacetLayerPreview(ModuleEnvironment environment, WorldGenerator worldGenerator) { this.worldGenerator = worldGenerator; World world = worldGenerator.getWorld(); Set<Class<? extends WorldFacet>> facets = world.getAllFacets(); facetLayers = FacetLayers.createLayersFor(facets, environment); }
private void updatePreview() { final NUIManager manager = context.get(NUIManager.class); final WaitPopup<TextureData> popup = manager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class); popup.setMessage("Updating Preview", "Please wait ..."); ProgressListener progressListener = progress -> popup.setMessage("Updating Preview", String.format("Please wait ... %d%%", (int) (progress * 100f))); Callable<TextureData> operation = () -> { if (seed != null) { worldGenerator.setWorldSeed(seed.getText()); } int zoom = TeraMath.floorToInt(zoomSlider.getValue()); TextureData data = texture.getData(); if (zoneSelector.isVisible()) { previewGen = zoneSelector.getSelection().preview(worldGenerator); } previewGen.render(data, zoom, progressListener); return data; }; popup.onSuccess(texture::reload); popup.startOperation(operation, true); }
String seed; if (universeWrapper.getTargetWorld() != null) { uri = universeWrapper.getTargetWorld().getWorldGenerator().getUri(); seed = universeWrapper.getTargetWorld().getWorldName().toString() + 0; gameManifest.setSeed(seed);
Vector3f spawnPosition = worldGenerator.getSpawnPosition(entity); loc.setWorldPosition(spawnPosition); entity.saveComponent(loc);
private void configureProperties() { PropertyLayout propLayout = find("properties", PropertyLayout.class); propLayout.setOrdering(PropertyOrdering.byLabel()); propLayout.clear(); WorldConfigurator worldConfig = worldGenerator.getConfigurator(); Map<String, Component> params = worldConfig.getProperties(); for (String key : params.keySet()) { Class<? extends Component> clazz = params.get(key).getClass(); Component comp = config.getModuleConfig(worldGenerator.getUri(), key, clazz); if (comp != null) { worldConfig.setProperty(key, comp); // use the data from the config instead of defaults } } ComponentLibrary compLib = subContext.get(ComponentLibrary.class); for (String label : params.keySet()) { PropertyProvider provider = new PropertyProvider() { @Override protected <T> Binding<T> createTextBinding(Object target, FieldMetadata<Object, T> fieldMetadata) { return new WorldConfigBinding<>(worldConfig, label, compLib, fieldMetadata); } @Override protected Binding<Float> createFloatBinding(Object target, FieldMetadata<Object, ?> fieldMetadata) { return new WorldConfigNumberBinding(worldConfig, label, compLib, fieldMetadata); } }; Component target = params.get(label); List<Property<?, ?>> properties = provider.createProperties(target); propLayout.addProperties(label, properties); } }
@Override public void run() { ChunkStore chunkStore = storageManager.loadChunkStore(getPosition()); Chunk chunk; EntityBufferImpl buffer = new EntityBufferImpl(); if (chunkStore == null) { chunk = new ChunkImpl(getPosition(), blockManager, biomeManager, extraDataManager); generator.createChunk(chunk, buffer); } else { chunk = chunkStore.getChunk(); } InternalLightProcessor.generateInternalLighting(chunk); chunk.deflate(); TShortObjectMap<TIntList> mappings = createBatchBlockEventMappings(chunk); readyChunks.offer(new ReadyChunkInfo(chunk, mappings, chunkStore, buffer.getAll())); } });
private Region createRegion(ImmutableVector2i chunkPos) { int vertChunks = 4; // 4 chunks high (relevant for trees, etc) int minX = chunkPos.getX() * TILE_SIZE_X; int minZ = chunkPos.getY() * TILE_SIZE_Y; int height = vertChunks * ChunkConstants.SIZE_Y; Region3i area3d = Region3i.createFromMinAndSize(new Vector3i(minX, 0, minZ), new Vector3i(TILE_SIZE_X, height, TILE_SIZE_Y)); World world = worldGenerator.getWorld(); Region region = world.getWorldData(area3d); return region; }