Added a few more generators to aid map gen.

Untested.
This commit is contained in:
Harrison Deng 2020-04-19 20:31:43 -05:00
parent 4b644159cb
commit 943feece04
3 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,101 @@
package ca.recrown.islandsurvivalcraft.worldgen;
import java.util.Random;
import org.bukkit.util.noise.SimplexOctaveGenerator;
public class IslandMapGenerator {
private SimplexOctaveGenerator noiseGenerator;
private final int noiseOctaves = 8;
private final int islandGenerationPercent = 47;
private final float exaggerationFactor = 1.5f;
private final double noiseFrequency = 0.5D;
private final double noiseAmplitude = 0.5D;
private final int shoreSize = 4;
private final int maxHeightAboveWater = 8;
private final int seaLevel;
private final int shallowDepth;
public IslandMapGenerator(Random random, int seaLevel, int shallowDepth) {
this.noiseGenerator = new SimplexOctaveGenerator(random, noiseOctaves);
this.seaLevel = seaLevel;
this.shallowDepth = shallowDepth;
}
public boolean isLand(int worldX, int worldZ) {
if (getBaseBlockHeight(worldX, worldZ) >= seaLevel) {
return true;
}
return false;
}
public boolean isEdgeOfIsland(int worldX, int worldZ) {
return isIsland(worldX, worldZ) &&
(!isSameIsland(worldX, worldZ, worldX + 1, worldZ) ||
isSameIsland(worldX, worldZ, worldX - 1, worldZ) ||
isSameIsland(worldX, worldZ, worldX , worldZ + 1) ||
isSameIsland(worldX, worldZ, worldX, worldZ - 1));
}
public boolean isShore(int worldX, int worldZ) {
if (!isIsland(worldX, worldZ)) return false;
for (int xPos = 0; xPos < shoreSize; xPos++) {
for (int zPos = 0; zPos < shoreSize; zPos++) {
if (isEdgeOfIsland(worldX + xPos, worldZ + zPos) || isEdgeOfIsland(worldX - xPos, worldZ - zPos)) {
return true;
}
}
}
return false;
}
public boolean isIsland(int worldX, int worldZ) {
if (isLand(worldX, worldZ) || isShallowPortion(worldX, worldZ)) {
return true;
}
return false;
}
public boolean isShallowPortion(int worldX, int worldZ) {
int blockHeight = getBaseBlockHeight(worldX, worldZ);
if (blockHeight < seaLevel && blockHeight >= (seaLevel - shallowDepth)) {
return true;
}
return true;
}
private double getTerrainValue(int worldX, int worldZ) {
double normalized = getNoiseValue(worldX, worldZ);
return Math.pow(normalized, exaggerationFactor);
}
public double getNoiseValue(int worldX, int worldZ) {
return (noiseGenerator.noise(worldX, worldZ, noiseFrequency, noiseAmplitude, true) + 1D) / 2D;
}
public int getBaseBlockHeight(int worldX, int worldZ) {
return Math.min((int) getTerrainValue(worldX, worldZ) * (islandGenerationPercent + seaLevel), maxHeightAboveWater + seaLevel);
}
public boolean isSameIsland(int firstBlockX, int firstBlockZ, int secondBlockX, int secondBlockZ) {
if (!isIsland(firstBlockX, firstBlockZ)) return false;
if (!isIsland(secondBlockX, secondBlockZ)) return false;
int xDirection = (secondBlockX - firstBlockX) / Math.abs(secondBlockX - firstBlockX);
for (int xPos = firstBlockX; xPos != secondBlockX; xPos += xDirection) {
if (!isIsland(xPos, firstBlockZ)) {
return false;
}
}
int zDirection = (secondBlockZ - secondBlockZ) / Math.abs(secondBlockZ - secondBlockZ);
for (int zPos = firstBlockZ; zPos != secondBlockZ; zPos += zDirection) {
if (!isIsland(secondBlockX, zPos)) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,33 @@
package ca.recrown.islandsurvivalcraft.worldgen;
import java.util.Random;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
public class IslandSurvivalCraftWorldGenerator extends ChunkGenerator {
private final BiomeSelector biomeSelector;
private final BiomePerIslandGenerator biomePerIslandGenerator;
private final IslandMapGenerator islandMapGenerator;
private final TemperatureMapGenerator temperatureMapGenerator;
private final Random random;
public IslandSurvivalCraftWorldGenerator(long seed, int worldHeight, int seaLevel, boolean biomePerIsland) {
random = new Random(seed);
this.biomeSelector = new BiomeSelector(random);
this.islandMapGenerator = new IslandMapGenerator(random, seaLevel, 3);
this.temperatureMapGenerator = new TemperatureMapGenerator(seed);
if (biomePerIsland) {
this.biomePerIslandGenerator = new BiomePerIslandGenerator(worldHeight, islandMapGenerator, random, biomeSelector);
} else {
throw new NotImplementedException();
}
}
@Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
// TODO Auto-generated method stub
return super.generateChunkData(world, random, x, z, biome);
}
}

View File

@ -0,0 +1,20 @@
package ca.recrown.islandsurvivalcraft.worldgen;
import java.util.Random;
import org.bukkit.util.noise.SimplexOctaveGenerator;
class TemperatureMapGenerator {
private final double frequency = 0.5D;
private final double amplitude = 0.22D;
private SimplexOctaveGenerator noiseGenerator;
public TemperatureMapGenerator(long seed) {
noiseGenerator = new SimplexOctaveGenerator(new Random(seed), 4);
noiseGenerator.setScale(0.0008D);
}
public double getTemperature(int worldX, int worldZ) {
return noiseGenerator.noise(worldX, worldZ, frequency, amplitude, true);
}
}