diff --git a/src/main/java/org/terasology/core/world/CoreBiome.java b/src/main/java/org/terasology/core/world/CoreBiome.java index fe2929a..5872db4 100644 --- a/src/main/java/org/terasology/core/world/CoreBiome.java +++ b/src/main/java/org/terasology/core/world/CoreBiome.java @@ -49,5 +49,4 @@ public String getDisplayName() { public String toString() { return this.displayName; } - } diff --git a/src/main/java/org/terasology/core/world/generator/facetProviders/BiomeProvider.java b/src/main/java/org/terasology/core/world/generator/facetProviders/BiomeProvider.java index 8b8893d..04ef301 100644 --- a/src/main/java/org/terasology/core/world/generator/facetProviders/BiomeProvider.java +++ b/src/main/java/org/terasology/core/world/generator/facetProviders/BiomeProvider.java @@ -61,17 +61,17 @@ public void process(GeneratingRegion region) { float hum = temp * humidityFacet.get(pos); float height = heightFacet.get(pos); - if (height <= seaLevel) { + if (height <= seaLevel || hum >= .85) { // TODO: remove hum qualifier here and for ocean? biomeFacet.set(pos, CoreBiome.OCEAN); - } else if (height <= seaLevel + 2) { + } else if (height <= seaLevel + 2 || hum >= .8) { biomeFacet.set(pos, CoreBiome.BEACH); - } else if (temp >= 0.5f && hum < 0.3f) { + } else if (hum <= 0.15f) { biomeFacet.set(pos, CoreBiome.DESERT); - } else if (hum >= 0.3f && hum <= 0.6f && temp >= 0.5f) { + } else if (hum <= 0.6f && temp >= 0.20f) { biomeFacet.set(pos, CoreBiome.PLAINS); - } else if (temp <= 0.3f && hum > 0.5f) { + } else if (hum >= .55f && temp <= 0.05f) { biomeFacet.set(pos, CoreBiome.SNOW); - } else if (hum >= 0.2f && hum <= 0.6f && temp < 0.5f) { + } else if (hum <= .45f && temp <= .15f) { biomeFacet.set(pos, CoreBiome.MOUNTAINS); } else { biomeFacet.set(pos, CoreBiome.FOREST); diff --git a/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexHumidityProvider.java b/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexHumidityProvider.java index fb766c5..fde755a 100644 --- a/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexHumidityProvider.java +++ b/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexHumidityProvider.java @@ -17,6 +17,8 @@ import org.terasology.entitySystem.Component; import org.terasology.math.TeraMath; +import org.terasology.math.geom.BaseVector2i; +import org.terasology.math.geom.Rect2i; import org.terasology.math.geom.Vector2f; import org.terasology.nui.properties.Range; import org.terasology.utilities.procedural.BrownianNoise; @@ -63,11 +65,13 @@ public void process(GeneratingRegion region) { Border3D border = region.getBorderForFacet(SurfaceHumidityFacet.class); SurfaceHumidityFacet facet = new SurfaceHumidityFacet(region.getRegion(), border); - float[] noise = humidityNoise.noise(facet.getWorldRegion()); - for (int i = 0; i < noise.length; ++i) { - noise[i] = TeraMath.clamp((noise[i] * 2.11f + 1f) * 0.5f); + Rect2i processRegion = facet.getWorldRegion(); + for (BaseVector2i position : processRegion.contents()) { + // clamp to reasonable values (between 0 and 1, since it's relative humidity), just in case + float noiseAdjusted = TeraMath.clamp(humidityNoise.noise(position.x(), position.y()) + .6f, 0f, 1f); + facet.setWorld(position, noiseAdjusted); } - facet.set(noise); + region.setRegionFacet(SurfaceHumidityFacet.class, facet); } diff --git a/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexSurfaceTemperatureProvider.java b/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexSurfaceTemperatureProvider.java index d7a87ba..9b7f347 100644 --- a/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexSurfaceTemperatureProvider.java +++ b/src/main/java/org/terasology/core/world/generator/facetProviders/SimplexSurfaceTemperatureProvider.java @@ -16,6 +16,8 @@ package org.terasology.core.world.generator.facetProviders; import org.terasology.math.TeraMath; +import org.terasology.math.geom.BaseVector2i; +import org.terasology.math.geom.Rect2i; import org.terasology.math.geom.Vector2f; import org.terasology.utilities.procedural.BrownianNoise; import org.terasology.utilities.procedural.SimplexNoise; @@ -30,6 +32,7 @@ @Produces(SurfaceTemperatureFacet.class) public class SimplexSurfaceTemperatureProvider implements FacetProvider { private static final int SAMPLE_RATE = 4; + private static final float TEMPERATURE_BASE = .25f; private SubSampledNoise temperatureNoise; @@ -41,13 +44,17 @@ public void setSeed(long seed) { @Override public void process(GeneratingRegion region) { SurfaceTemperatureFacet facet = new SurfaceTemperatureFacet(region.getRegion(), region.getBorderForFacet(SurfaceTemperatureFacet.class)); - float[] noise = this.temperatureNoise.noise(facet.getWorldRegion()); + Rect2i processRegion = facet.getWorldRegion(); - for (int i = 0; i < noise.length; ++i) { - noise[i] = TeraMath.clamp((noise[i] * 2.11f + 1f) * 0.5f); + for (BaseVector2i position : processRegion.contents()) { + // modify initial noise to make it closer to temperature base + float noiseAdjusted = this.temperatureNoise.noise(position.x(), position.y()) / 5 + TEMPERATURE_BASE; + + // clamp to more reasonable base values, where each value is a Celsuis temperature / 100 + noiseAdjusted = TeraMath.clamp(noiseAdjusted, -.45f, .45f); + facet.setWorld(position, noiseAdjusted); } - facet.set(noise); region.setRegionFacet(SurfaceTemperatureFacet.class, facet); } } diff --git a/src/main/java/org/terasology/core/world/generator/rasterizers/SolidRasterizer.java b/src/main/java/org/terasology/core/world/generator/rasterizers/SolidRasterizer.java index 40fa81f..5c10ae1 100644 --- a/src/main/java/org/terasology/core/world/generator/rasterizers/SolidRasterizer.java +++ b/src/main/java/org/terasology/core/world/generator/rasterizers/SolidRasterizer.java @@ -27,13 +27,19 @@ import org.terasology.world.block.BlockManager; import org.terasology.world.chunks.ChunkConstants; import org.terasology.world.chunks.CoreChunk; +import org.terasology.world.chunks.blockdata.ExtraBlockDataManager; +import org.terasology.world.chunks.blockdata.ExtraDataSystem; +import org.terasology.world.chunks.blockdata.RegisterExtraData; import org.terasology.world.generation.Region; import org.terasology.world.generation.WorldRasterizer; import org.terasology.world.generation.facets.DensityFacet; import org.terasology.world.generation.facets.SeaLevelFacet; import org.terasology.world.generation.facets.SurfaceDepthFacet; import org.terasology.world.generation.facets.SurfaceHeightFacet; +import org.terasology.world.generation.facets.SurfaceHumidityFacet; +import org.terasology.world.generation.facets.SurfaceTemperatureFacet; +@ExtraDataSystem public class SolidRasterizer implements WorldRasterizer { private Block water; @@ -44,6 +50,7 @@ public class SolidRasterizer implements WorldRasterizer { private Block snow; private Block dirt; private BiomeRegistry biomeRegistry; + private ExtraBlockDataManager extraBlockDataManager; @Override public void initialize() { @@ -56,10 +63,15 @@ public void initialize() { grass = blockManager.getBlock("CoreAssets:Grass"); snow = blockManager.getBlock("CoreAssets:Snow"); dirt = blockManager.getBlock("CoreAssets:Dirt"); + + extraBlockDataManager = CoreRegistry.get(ExtraBlockDataManager.class); } @Override public void generateChunk(CoreChunk chunk, Region chunkRegion) { + int temperatureSlot = extraBlockDataManager.getSlotNumber("climateConditions.temperature"); + int humiditySlot = extraBlockDataManager.getSlotNumber("climateConditions.humidity"); + DensityFacet solidityFacet = chunkRegion.getFacet(DensityFacet.class); SurfaceHeightFacet surfaceFacet = chunkRegion.getFacet(SurfaceHeightFacet.class); SurfaceDepthFacet surfaceDepthFacet = chunkRegion.getFacet(SurfaceDepthFacet.class); @@ -67,6 +79,9 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) { SeaLevelFacet seaLevelFacet = chunkRegion.getFacet(SeaLevelFacet.class); int seaLevel = seaLevelFacet.getSeaLevel(); + SurfaceHumidityFacet surfaceHumidityFacet = chunkRegion.getFacet(SurfaceHumidityFacet.class); + SurfaceTemperatureFacet surfaceTemperatureFacet = chunkRegion.getFacet(SurfaceTemperatureFacet.class); + Vector2i pos2d = new Vector2i(); for (Vector3i pos : ChunkConstants.CHUNK_REGION) { pos2d.set(pos.x, pos.z); @@ -99,6 +114,11 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) { // } } } + + // extra data has to be an int, so multiply by 1000, convert to int, and + // then convert to float/divide by 1000 once using the block data + chunk.setExtraData(temperatureSlot, pos.x, pos.y, pos.z, (int) (surfaceTemperatureFacet.get(pos.x, pos.z) * 1000)); + chunk.setExtraData(humiditySlot, pos.x, pos.y, pos.z, (int) (surfaceHumidityFacet.get(pos.x, pos.z) * 1000)); } } @@ -154,4 +174,13 @@ private Block getSurfaceBlock(int depth, int height, } return dirt; } + + @RegisterExtraData(name="climateConditions.humidity", bitSize=16) + public static boolean humidityByBlock(Block block) { + return true; + } + @RegisterExtraData(name="climateConditions.temperature", bitSize=16) + public static boolean temperatureByBlock(Block block) { + return true; + } } diff --git a/src/main/java/org/terasology/core/world/generator/worldGenerators/FlatWorldGenerator.java b/src/main/java/org/terasology/core/world/generator/worldGenerators/FlatWorldGenerator.java index 7cc4d4d..490bbe3 100644 --- a/src/main/java/org/terasology/core/world/generator/worldGenerators/FlatWorldGenerator.java +++ b/src/main/java/org/terasology/core/world/generator/worldGenerators/FlatWorldGenerator.java @@ -19,9 +19,9 @@ import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider; import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider; import org.terasology.core.world.generator.facetProviders.FlatSurfaceHeightProvider; -import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider; -import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider; import org.terasology.core.world.generator.facetProviders.SeaLevelProvider; +import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider; +import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider; import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider; import org.terasology.core.world.generator.rasterizers.FloraRasterizer; import org.terasology.core.world.generator.rasterizers.SolidRasterizer; @@ -49,8 +49,8 @@ protected WorldBuilder createWorld() { .addProvider(new SeaLevelProvider(32)) // height of 40 so that it is far enough from sea level so that it doesnt just create beachfront .addProvider(new FlatSurfaceHeightProvider(40)) - .addProvider(new PerlinHumidityProvider()) - .addProvider(new PerlinSurfaceTemperatureProvider()) + .addProvider(new SimplexSurfaceTemperatureProvider()) + .addProvider(new SimplexHumidityProvider()) .addProvider(new BiomeProvider()) .addProvider(new SurfaceToDensityProvider()) .addProvider(new DefaultFloraProvider()) diff --git a/src/main/java/org/terasology/core/world/generator/worldGenerators/HeightMapWorldGenerator.java b/src/main/java/org/terasology/core/world/generator/worldGenerators/HeightMapWorldGenerator.java index 9dd13ad..ed3f466 100644 --- a/src/main/java/org/terasology/core/world/generator/worldGenerators/HeightMapWorldGenerator.java +++ b/src/main/java/org/terasology/core/world/generator/worldGenerators/HeightMapWorldGenerator.java @@ -19,9 +19,9 @@ import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider; import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider; import org.terasology.core.world.generator.facetProviders.HeightMapSurfaceHeightProvider; -import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider; -import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider; import org.terasology.core.world.generator.facetProviders.SeaLevelProvider; +import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider; +import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider; import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider; import org.terasology.core.world.generator.rasterizers.FloraRasterizer; import org.terasology.core.world.generator.rasterizers.SolidRasterizer; @@ -51,8 +51,8 @@ protected WorldBuilder createWorld() { .setSeaLevel(16) .addProvider(new SeaLevelProvider(16)) .addProvider(new HeightMapSurfaceHeightProvider()) - .addProvider(new PerlinHumidityProvider()) - .addProvider(new PerlinSurfaceTemperatureProvider()) + .addProvider(new SimplexSurfaceTemperatureProvider()) + .addProvider(new SimplexHumidityProvider()) .addProvider(new BiomeProvider()) .addProvider(new SurfaceToDensityProvider()) .addProvider(new DefaultFloraProvider()) diff --git a/src/main/java/org/terasology/core/world/generator/worldGenerators/PerlinFacetedWorldGenerator.java b/src/main/java/org/terasology/core/world/generator/worldGenerators/PerlinFacetedWorldGenerator.java index 57e1e83..b16eafd 100644 --- a/src/main/java/org/terasology/core/world/generator/worldGenerators/PerlinFacetedWorldGenerator.java +++ b/src/main/java/org/terasology/core/world/generator/worldGenerators/PerlinFacetedWorldGenerator.java @@ -18,14 +18,14 @@ import org.terasology.core.world.generator.facetProviders.BiomeProvider; import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider; import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider; -import org.terasology.core.world.generator.facetProviders.PlateauProvider; import org.terasology.core.world.generator.facetProviders.PerlinBaseSurfaceProvider; import org.terasology.core.world.generator.facetProviders.PerlinHillsAndMountainsProvider; -import org.terasology.core.world.generator.facetProviders.PerlinHumidityProvider; import org.terasology.core.world.generator.facetProviders.PerlinOceanProvider; import org.terasology.core.world.generator.facetProviders.PerlinRiverProvider; -import org.terasology.core.world.generator.facetProviders.PerlinSurfaceTemperatureProvider; +import org.terasology.core.world.generator.facetProviders.PlateauProvider; import org.terasology.core.world.generator.facetProviders.SeaLevelProvider; +import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider; +import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider; import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider; import org.terasology.core.world.generator.rasterizers.FloraRasterizer; import org.terasology.core.world.generator.rasterizers.SolidRasterizer; @@ -68,12 +68,12 @@ protected WorldBuilder createWorld() { return new WorldBuilder(worldGeneratorPluginLibrary) .setSeaLevel(seaLevel) .addProvider(new SeaLevelProvider(seaLevel)) - .addProvider(new PerlinHumidityProvider()) - .addProvider(new PerlinSurfaceTemperatureProvider()) .addProvider(new PerlinBaseSurfaceProvider()) .addProvider(new PerlinRiverProvider()) .addProvider(new PerlinOceanProvider()) .addProvider(new PerlinHillsAndMountainsProvider()) + .addProvider(new SimplexSurfaceTemperatureProvider()) + .addProvider(new SimplexHumidityProvider()) .addProvider(new BiomeProvider()) .addProvider(new SurfaceToDensityProvider()) .addProvider(new DefaultFloraProvider()) diff --git a/src/main/java/org/terasology/core/world/generator/worldGenerators/SimplexFacetedWorldGenerator.java b/src/main/java/org/terasology/core/world/generator/worldGenerators/SimplexFacetedWorldGenerator.java index 730a5e9..ad25f97 100644 --- a/src/main/java/org/terasology/core/world/generator/worldGenerators/SimplexFacetedWorldGenerator.java +++ b/src/main/java/org/terasology/core/world/generator/worldGenerators/SimplexFacetedWorldGenerator.java @@ -19,13 +19,13 @@ import org.terasology.core.world.generator.facetProviders.DefaultFloraProvider; import org.terasology.core.world.generator.facetProviders.DefaultTreeProvider; import org.terasology.core.world.generator.facetProviders.PlateauProvider; +import org.terasology.core.world.generator.facetProviders.SeaLevelProvider; import org.terasology.core.world.generator.facetProviders.SimplexBaseSurfaceProvider; import org.terasology.core.world.generator.facetProviders.SimplexHillsAndMountainsProvider; import org.terasology.core.world.generator.facetProviders.SimplexHumidityProvider; import org.terasology.core.world.generator.facetProviders.SimplexOceanProvider; import org.terasology.core.world.generator.facetProviders.SimplexRiverProvider; import org.terasology.core.world.generator.facetProviders.SimplexSurfaceTemperatureProvider; -import org.terasology.core.world.generator.facetProviders.SeaLevelProvider; import org.terasology.core.world.generator.facetProviders.SurfaceToDensityProvider; import org.terasology.core.world.generator.rasterizers.FloraRasterizer; import org.terasology.core.world.generator.rasterizers.SolidRasterizer;