Logs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package mc.world.generated_world;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.block.BlockFactory;
|
||||
import mc.core.block.BlockType;
|
||||
import mc.core.world.*;
|
||||
@@ -15,17 +16,22 @@ import java.util.UUID;
|
||||
|
||||
import static mc.world.generated_world.WorldConstants.*;
|
||||
|
||||
@Slf4j
|
||||
public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
WorldGenerator worldGenerator = new SeedBasedWorldGenerator();
|
||||
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 123);
|
||||
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 2626949);
|
||||
Region region = worldGenerator.generateRegion(0, 0, world);
|
||||
region.save(new ChunkSerializerDeserializer(), new RegionSerializerDeserializer());
|
||||
/*worldGenerator.generateRegion(1, 0, world);
|
||||
//region.save(new ChunkSerializerDeserializer(), new RegionSerializerDeserializer());
|
||||
worldGenerator.generateRegion(1, 0, world);
|
||||
worldGenerator.generateRegion(-1, 0, world);
|
||||
worldGenerator.generateRegion(0, 1, world);
|
||||
worldGenerator.generateRegion(0, -1, world);
|
||||
worldGenerator.generateRegion(-1, -1, world);
|
||||
worldGenerator.generateRegion(1, -1, world);
|
||||
worldGenerator.generateRegion(-1, 1, world);
|
||||
worldGenerator.generateRegion(1, 1, world);
|
||||
BufferedImage image = new BufferedImage(3 * 256, 3 * 256, BufferedImage.TYPE_INT_RGB);
|
||||
BufferedImage currentImage;
|
||||
int shiftX;
|
||||
@@ -80,14 +86,56 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
image.setRGB(tx, ty, currentImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File("out", "merged.png"));*/
|
||||
currentImage = ImageIO.read(new File("out/-1.-1", "biomeMap.png"));
|
||||
shiftX = 0;
|
||||
shiftY = 0;
|
||||
for (int x = 0; x < 256; x ++){
|
||||
for (int y = 0; y < 256; y ++){
|
||||
int tx = 256 * shiftX + x;
|
||||
int ty = 256 * shiftY + y;
|
||||
image.setRGB(tx, ty, currentImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
currentImage = ImageIO.read(new File("out/1.-1", "biomeMap.png"));
|
||||
shiftX = 2;
|
||||
shiftY = 0;
|
||||
for (int x = 0; x < 256; x ++){
|
||||
for (int y = 0; y < 256; y ++){
|
||||
int tx = 256 * shiftX + x;
|
||||
int ty = 256 * shiftY + y;
|
||||
image.setRGB(tx, ty, currentImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
currentImage = ImageIO.read(new File("out/1.1", "biomeMap.png"));
|
||||
shiftX = 2;
|
||||
shiftY = 2;
|
||||
for (int x = 0; x < 256; x ++){
|
||||
for (int y = 0; y < 256; y ++){
|
||||
int tx = 256 * shiftX + x;
|
||||
int ty = 256 * shiftY + y;
|
||||
image.setRGB(tx, ty, currentImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
currentImage = ImageIO.read(new File("out/-1.1", "biomeMap.png"));
|
||||
shiftX = 0;
|
||||
shiftY = 2;
|
||||
for (int x = 0; x < 256; x ++){
|
||||
for (int y = 0; y < 256; y ++){
|
||||
int tx = 256 * shiftX + x;
|
||||
int ty = 256 * shiftY + y;
|
||||
image.setRGB(tx, ty, currentImage.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File("out", "merged.png"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region generateRegion(int x, int z, World world) {
|
||||
log.info("Generating region [{},{}]...", x, z);
|
||||
Region region = new RegionImpl(x, z, world);
|
||||
RegionGenerator regionGenerator = new RegionGenerator(world, region);
|
||||
regionGenerator.generate();
|
||||
log.info("Region [{},{}] is generated", x, z);
|
||||
return region;
|
||||
}
|
||||
|
||||
@@ -109,19 +157,21 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
log.debug("Starting generating region [{}, {}] for world '{}' with seed '{}'", region.getX(), region.getZ(), world.getWorldId(), world.getSeed());
|
||||
|
||||
noiseGenerator = new NoiseGenerator(world.getSeed());
|
||||
noiseGenerator.init();
|
||||
File file = new File("out", region.getX() + "." + region.getZ());
|
||||
file.mkdirs();
|
||||
int[][] heightMap = new int[WorldConstants.WORLD_REGION_SIZE][WorldConstants.WORLD_REGION_SIZE];
|
||||
int[][] grassMap = new int[WorldConstants.WORLD_REGION_SIZE][WorldConstants.WORLD_REGION_SIZE];
|
||||
int[][] temperatureMap = new int[WorldConstants.WORLD_REGION_SIZE][WorldConstants.WORLD_REGION_SIZE];
|
||||
int[][] wetMap = new int[WorldConstants.WORLD_REGION_SIZE][WorldConstants.WORLD_REGION_SIZE];
|
||||
Biome[][] biomes = new Biome[WorldConstants.WORLD_REGION_SIZE][WorldConstants.WORLD_REGION_SIZE];
|
||||
for (int x = 0; x < WorldConstants.WORLD_REGION_SIZE; x ++) {
|
||||
for (int z = 0; z < WorldConstants.WORLD_REGION_SIZE; z ++) {
|
||||
int tx = convert(x + region.getX() * WorldConstants.WORLD_REGION_SIZE);
|
||||
int tz = convert(z + region.getZ() * WorldConstants.WORLD_REGION_SIZE);
|
||||
|
||||
int[][] heightMap = new int[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
int[][] grassMap = new int[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
int[][] temperatureMap = new int[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
int[][] wetMap = new int[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
Biome[][] biomes = new Biome[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
|
||||
for (int x = 0; x < WORLD_REGION_SIZE; x ++) {
|
||||
for (int z = 0; z < WORLD_REGION_SIZE; z ++) {
|
||||
int tx = convert(x + region.getX() * WORLD_REGION_SIZE);
|
||||
int tz = convert(z + region.getZ() * WORLD_REGION_SIZE);
|
||||
double p = sigmoid(noiseGenerator.noise(tx / WORLD_LAND_SIZE, tz / WORLD_LAND_SIZE));
|
||||
double r = Math.sqrt(noiseGenerator.noise(tx / WORLD_LAKE_SIZE, tz / WORLD_LAKE_SIZE));
|
||||
double h = (WORLD_MAX_HEIGHT - WORLD_MIN_HEIGHT) * Math.min(p * r, 1);
|
||||
@@ -141,8 +191,9 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = 1; x < WorldConstants.WORLD_REGION_SIZE - 1; x ++) {
|
||||
for (int z = 1; z < WorldConstants.WORLD_REGION_SIZE - 1; z++) {
|
||||
|
||||
for (int x = 1; x < WORLD_REGION_SIZE - 1; x ++) {
|
||||
for (int z = 1; z < WORLD_REGION_SIZE - 1; z++) {
|
||||
int mid = 0;
|
||||
for (int tx = x - 1; tx <= x + 1; tx ++) {
|
||||
for (int tz = z - 1; tz <= z + 1; tz ++) {
|
||||
@@ -152,8 +203,8 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
wetMap[x][z] = mid / 9;
|
||||
}
|
||||
}
|
||||
for (int z = 1; z < WorldConstants.WORLD_REGION_SIZE - 1; z++) {
|
||||
for (int x = 1; x < WorldConstants.WORLD_REGION_SIZE - 1; x ++) {
|
||||
for (int z = 1; z < WORLD_REGION_SIZE - 1; z++) {
|
||||
for (int x = 1; x < WORLD_REGION_SIZE - 1; x ++) {
|
||||
int mid = 0;
|
||||
for (int tx = x - 1; tx <= x + 1; tx ++) {
|
||||
for (int tz = z - 1; tz <= z + 1; tz ++) {
|
||||
@@ -165,9 +216,9 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
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 * (SeedRandomGenerator.random(x, z, world.getSeed()))));
|
||||
for (int z = 1; z < WORLD_REGION_SIZE - 1; z++) {
|
||||
for (int x = 1; x < WORLD_REGION_SIZE - 1; x ++) {
|
||||
wetMap[x][z] = (int) Math.min(WORLD_MAX_WETNESS, WORLD_BASE_WETNESS * noiseGenerator.noise(x / 31d, z / 31d) + wetMap[x][z] * (1 + 0.2 * (SeedRandomGenerator.random(x, z, world.getSeed()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,67 +227,77 @@ 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()[ 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 =======================================
|
||||
if (DEBUG_ENABLED) {
|
||||
log.debug("Creating debug images");
|
||||
File outFile;
|
||||
outFile = new File("out", region.getX() + "." + region.getZ());
|
||||
outFile.mkdirs();
|
||||
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 < WORLD_REGION_SIZE; x ++) {
|
||||
for (int z = 0; z < WORLD_REGION_SIZE; z ++) {
|
||||
Temperature temperature = Temperature.values()[Temperature.values().length * temperatureMap[x][z] / WORLD_MAX_TEMPERATURE];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ImageIO.write(tempImg, "png", new File(outFile, "temp_img.png"));
|
||||
ImageIO.write(wetImg, "png", new File(outFile, "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++) {
|
||||
for (int z = 0; z < 256; z++) {
|
||||
int h = heightMap[x][z];
|
||||
h = h << 16 | h << 8 | h;
|
||||
image.setRGB(x, z, h);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File(outFile, "heightmap.png"));
|
||||
image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
|
||||
for (int x = 0; x < 256; x++) {
|
||||
for (int z = 0; z < 256; z++) {
|
||||
int temp = 0xff * temperatureMap[x][z] / 100;
|
||||
temp = temp << 16;
|
||||
image.setRGB(x, z, temp);
|
||||
subImage.setRGB(x, z, (0xff * (int) (temperatureMap[x][z] / 20) / 5) << 16);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File(outFile, "temperatureMap.png"));
|
||||
ImageIO.write(subImage, "png", new File(outFile, "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(outFile, "wetMap.png"));
|
||||
ImageIO.write(subImage, "png", new File(outFile, "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++) {
|
||||
image.setRGB(x, z, biomes[x][z].getColor());
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File(outFile, "biomeMap.png"));
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while creating debug images", e);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================ 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 ++) {
|
||||
for (int z = 0; z < 256; z ++) {
|
||||
int h = heightMap[x][z];
|
||||
h = h << 16 | h << 8 | h;
|
||||
image.setRGB(x, z, h);
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File("out/" + region.getX() + "." +region.getZ() +"/hightmap.png"));
|
||||
image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
|
||||
for (int x = 0; x < 256; x ++) {
|
||||
for (int z = 0; z < 256; z ++) {
|
||||
int temp = 0xff * temperatureMap[x][z] / 100;
|
||||
temp = temp << 16;
|
||||
image.setRGB(x, z, temp);
|
||||
subImage.setRGB(x, z, (0xff * (int) (temperatureMap[x][z] / 20) / 5) << 16);
|
||||
}
|
||||
}
|
||||
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 ++) {
|
||||
image.setRGB(x, z, biomes[x][z].getColor());
|
||||
}
|
||||
}
|
||||
ImageIO.write(image, "png", new File("out/" + region.getX() + "." +region.getZ() + "/biomeMap.png"));
|
||||
} catch (Exception e) {}
|
||||
// ================================ DEBUG FINISH =======================================
|
||||
|
||||
for (int x = 0; x < WorldConstants.WORLD_REGION_SIZE; x ++) {
|
||||
for (int z = 0; z < WorldConstants.WORLD_REGION_SIZE; z ++) {
|
||||
log.debug("Creating chunks...");
|
||||
|
||||
for (int x = 0; x < WORLD_REGION_SIZE; x ++) {
|
||||
for (int z = 0; z < WORLD_REGION_SIZE; z ++) {
|
||||
region.setBiome(x, z, biomes[x][z]);
|
||||
if (heightMap[x][z] < WORLD_SEA_LEVEL) {
|
||||
for (int y = 0; y < WORLD_SEA_LEVEL; y ++) {
|
||||
@@ -277,6 +338,13 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO
|
||||
log.debug("Creating rivers...");
|
||||
log.debug("Creating caves...");
|
||||
log.debug("Planting trees...");
|
||||
log.debug("Spawning animals...");
|
||||
*/
|
||||
}
|
||||
|
||||
private Biome selectBiome (Temperature temperature, Wetness wetness, int height) {
|
||||
@@ -411,6 +479,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
||||
gradsX[i] = Math.cos(2.0f * Math.PI * i / WORLD_REGION_SIZE);
|
||||
gradsY[i] = Math.sin(2.0f * Math.PI * i / WORLD_REGION_SIZE);
|
||||
}
|
||||
log.debug("Noise generator is initialized");
|
||||
}
|
||||
|
||||
double f(double t) {
|
||||
|
||||
Reference in New Issue
Block a user