Archived
0

Advanced biome selector

This commit is contained in:
Forwolk
2018-08-01 13:33:48 +03:00
parent 3e889c2e7c
commit ec8e414ba1
4 changed files with 98 additions and 43 deletions

View File

@@ -26,7 +26,10 @@ public enum Biome {
EXTREME_HILLS_EDGE(20, "Extreme hills edge", 0xffffff),
JUNGLE(21, "Jungle", 0xadff2f),
JUNGLE_HILLS(22, "Jungle hills", 0xadff2f),
DEEP_OCEAN(23, "Deep ocean", 0x000080);
DEEP_OCEAN(23, "Deep ocean", 0x000080),
TUNDRA(24, "Tundra", 0xc0c0c0),
SAVANNA(25, "Savana", 0xcd8513),
SAVANNA_FOREST(26, "Savana forest", 0x8b4513);
@Getter
private final int id;

View File

@@ -20,7 +20,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
WorldGenerator worldGenerator = new SeedBasedWorldGenerator();
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 123);
worldGenerator.generateRegion(0, 0, world);
worldGenerator.generateRegion(1, 0, world);
/*worldGenerator.generateRegion(1, 0, world);
worldGenerator.generateRegion(-1, 0, world);
worldGenerator.generateRegion(0, 1, world);
worldGenerator.generateRegion(0, -1, world);
@@ -78,7 +78,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
image.setRGB(tx, ty, currentImage.getRGB(x, y));
}
}
ImageIO.write(image, "png", new File("out", "merged.png"));
ImageIO.write(image, "png", new File("out", "merged.png"));*/
}
@Override
@@ -131,7 +131,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
temperatureMap[x][z] = (int) (WORLD_MAX_TEMPERATURE * Math.min((k * k + q * q + k * q) * k * q, 0.99));
if (heightMap[x][z] < WORLD_SEA_LEVEL) {
biomes[x][z] = Biome.OCEAN;
wetMap[x][z] = (int) (WORLD_MAX_WETNESS * noiseGenerator.noise(tx, tz));
wetMap[x][z] = (int) (WORLD_MAX_WETNESS * WORLD_WET_SEA_PERCENT *noiseGenerator.noise(tx, tz));
} else {
int th = heightMap[x][z] - WORLD_SEA_LEVEL;
th = (int) (th * (1 + 1.25 * th / (WORLD_MAX_HEIGHT - WORLD_SEA_LEVEL)));
@@ -158,14 +158,14 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
mid += wetMap[tx][tz];
}
}
wetMap[x][z] = (int) (mid / 9 * (1 + 0.1 * SeedRandomGenerator.random(x, z, world.getSeed())));
wetMap[x][z] = (int) (mid / 9 * (1 + 0.4 * SeedRandomGenerator.random(x, z, world.getSeed())));
temperatureMap[x][z] = (int) Math.min(Math.max(temperatureMap[x][z] - WORLD_TEMPERATURE_HEIGHT_GRAD_SIZE * SeedRandomGenerator.random(x, z, world.getSeed()) * (heightMap[x][z] - WORLD_SEA_LEVEL), 0), WORLD_MAX_TEMPERATURE);
}
}
for (int z = 1; z < WorldConstants.WORLD_REGION_SIZE - 1; z++) {
for (int x = 1; x < WorldConstants.WORLD_REGION_SIZE - 1; x ++) {
wetMap[x][z] = (int) Math.min(WORLD_MAX_WETNESS, WORLD_BASE_WETNESS * noiseGenerator.noise(x / 31d, z / 67d) + wetMap[x][z] * (1 + 0.2 * (0.5 - SeedRandomGenerator.random(x, z, world.getSeed()))));
wetMap[x][z] = (int) Math.min(WORLD_MAX_WETNESS, WORLD_BASE_WETNESS * noiseGenerator.noise(x / 31d, z / 67d) + wetMap[x][z] * (1 + 0.2 * (SeedRandomGenerator.random(x, z, world.getSeed()))));
}
}
@@ -174,16 +174,23 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
smooth(wetMap);
//smooth(heightMap);
BufferedImage tempImg = new BufferedImage(WORLD_REGION_SIZE, WORLD_REGION_SIZE, BufferedImage.TYPE_INT_RGB);
BufferedImage wetImg = new BufferedImage(WORLD_REGION_SIZE, WORLD_REGION_SIZE, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < WorldConstants.WORLD_REGION_SIZE; x ++) {
for (int z = 0; z < WorldConstants.WORLD_REGION_SIZE; z ++) {
Temperature temperature = Temperature.values()[Temperature.values().length * temperatureMap[x][z] / WORLD_MAX_TEMPERATURE];
Wetness wetness = Wetness.values()[(Math.min(wetMap[x][z], 100) - 1) / WORLD_MAX_WETNESS * Wetness.values().length];
Wetness wetness = Wetness.values()[ Wetness.values().length * (Math.min(wetMap[x][z], WORLD_MAX_WETNESS) - 1) / WORLD_MAX_WETNESS];
biomes[x][z] = selectBiome(temperature, wetness, heightMap[x][z]);
tempImg.setRGB(x, z, temperature.ordinal() * 0xff / Temperature.values().length);
wetImg.setRGB(x, z, wetness.ordinal() * 0xff / Wetness.values().length);
}
}
// ================================ DEBUG =======================================
try {
ImageIO.write(tempImg, "png", new File("out/" + region.getX() + "." +region.getZ() +"/temp_img.png"));
ImageIO.write(wetImg, "png", new File("out/" + region.getX() + "." +region.getZ() +"/wet_img.png"));
BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
BufferedImage subImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < 256; x ++) {
@@ -205,14 +212,17 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
}
ImageIO.write(image, "png", new File("out/" + region.getX() + "." +region.getZ() + "/temperatureMap.png"));
ImageIO.write(subImage, "png", new File("out/" + region.getX() + "." +region.getZ() + "/reg_temperatureMap.png"));
subImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < 256; x ++) {
for (int z = 0; z < 256; z ++) {
int wet = 0xff * wetMap[x][z] / 100;
image.setRGB(x, z, wet);
subImage.setRGB(x, z, 0xff * (int) (Wetness.values().length * wetMap[x][z] / (WORLD_MAX_WETNESS)));
}
}
ImageIO.write(image, "png", new File("out/" + region.getX() + "." +region.getZ() + "/wetMap.png"));
ImageIO.write(subImage, "png", new File("out/" + region.getX() + "." +region.getZ() + "/reg_wetMap.png"));
image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < 256; x ++) {
for (int z = 0; z < 256; z ++) {
@@ -268,60 +278,100 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
}
private Biome selectBiome (Temperature temperature, Wetness wetness, int height) {
if (wetness == Wetness.WATER || height < WORLD_SEA_LEVEL) {
if (temperature == Temperature.FROST) {
if (height < WORLD_SEA_LEVEL) {
return Biome.FROZEN_OCEAN;
} else {
if (height > (WORLD_SEA_LEVEL + WORLD_MAX_HEIGHT) / 2) {
return Biome.ICE_PLAINS;
}
} else {
if (height < WORLD_SEA_LEVEL) {
if (height < WORLD_MIN_HEIGHT + (WORLD_SEA_LEVEL - WORLD_MIN_HEIGHT) / 2) {
return Biome.DEEP_OCEAN;
} else {
return Biome.OCEAN;
}
} else {
return Biome.SWAMPLAND;
}
}
}
final int HILLS_HEIGHT = WORLD_SEA_LEVEL + (WORLD_MAX_HEIGHT - WORLD_SEA_LEVEL) / 3;
if (temperature == Temperature.FROST) {
if (wetness == Wetness.DRIEST || wetness == Wetness.DRY) {
return Biome.TUNDRA;
} else {
if (height > HILLS_HEIGHT) {
return Biome.ICE_MOUNTAINS;
} else {
return Biome.ICE_PLAINS;
}
}
}
if (height < WORLD_SEA_LEVEL) {
if (height < (WORLD_SEA_LEVEL + WORLD_MIN_HEIGHT) / 2){
return Biome.DEEP_OCEAN;
} else {
return Biome.OCEAN;
}
}
if (temperature == Temperature.COLD) {
if (height > (WORLD_SEA_LEVEL + WORLD_MAX_HEIGHT) / 2) {
return Biome.TAIGA_HILLS;
} else {
return Biome.TAIGA;
}
}
if (temperature == Temperature.WARM) {
if (wetness.ordinal() < 2) {
if (wetness == Wetness.DRIEST) {
if (temperature == Temperature.COLD || temperature == Temperature.WARM) {
return Biome.PLAINS;
} else if (wetness == Wetness.WATER){
return Biome.SWAMPLAND;
} else {
if (height > (WORLD_SEA_LEVEL + WORLD_MAX_HEIGHT) / 2) {
return Biome.FOREST_HILLS;
} else {
return Biome.FOREST;
}
}
}
if (temperature == Temperature.HOTTEST && wetness.ordinal() < 2) {
if (height > (WORLD_SEA_LEVEL + WORLD_MAX_HEIGHT) / 2) {
if (height > HILLS_HEIGHT) {
return Biome.DESERT_HILLS;
} else {
return Biome.DESERT;
}
}
}
if (wetness.ordinal() > 2) {
if (height > (WORLD_SEA_LEVEL + WORLD_MAX_HEIGHT) / 2) {
if (temperature == Temperature.COLD) {
if (wetness == Wetness.DRY || wetness == Wetness.WET) {
if (height > HILLS_HEIGHT) {
return Biome.TAIGA_HILLS;
} else {
return Biome.TAIGA;
}
} else {
return Biome.SWAMPLAND;
}
}
if (wetness == Wetness.WETTEST) {
if (temperature == Temperature.WARM) {
return Biome.SWAMPLAND;
} else {
if (height > HILLS_HEIGHT) {
return Biome.JUNGLE_HILLS;
} else {
return Biome.JUNGLE;
}
}
}
if (wetness == Wetness.WETTER) {
if (temperature == Temperature.WARM) {
if (height > HILLS_HEIGHT) {
return Biome.FOREST_HILLS;
} else {
return Biome.FOREST;
}
} else {
return Biome.SAVANNA_FOREST;
}
}
if (temperature == Temperature.HOTTEST) {
return Biome.SAVANNA;
}
if (wetness == Wetness.WET) {
if (height > HILLS_HEIGHT) {
return Biome.FOREST_HILLS;
} else {
return Biome.FOREST;
}
}
return Biome.PLAINS;
}

View File

@@ -12,10 +12,11 @@ public final class WorldConstants {
public static final int WORLD_REGION_SIZE = 256;
public static final int WORLD_MAX_TEMPERATURE = 100;
public static final int WORLD_MAX_WETNESS = 100;
public static final int WORLD_BASE_WETNESS = 30;
public static final int WORLD_BASE_WETNESS = 80;
public static final double WORLD_LAND_SIZE = 53.0;
public static final double WORLD_LAKE_SIZE = 6.0;
public static final double WORLD_WET_SEA_PERCENT = 0.8;
public static final double WORLD_TEMPERATURE_SIZE = 41.0;
public static final double WORLD_TEMPERATURE_ZONE_SIZE = 2.99;
public static final double WORLD_TEMPERATURE_HEIGHT_GRAD_SIZE = 0.25;

View File

@@ -1,9 +1,10 @@
package mc.world.generated_world.word;
public enum Wetness {
DRYEST,
DRIEST,
DRY,
WET,
WETTER,
WETTEST,
WATER
}