Added the shape shader, also refactored.

This commit is contained in:
Harrison Deng 2020-04-21 19:31:09 -05:00
parent 66673e2f52
commit e306d828e9
6 changed files with 77 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateValidatable;
import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
public class IslandLocationMapper implements CoordinateValidatable {
public class IslandWorldBaseTerrainMap implements CoordinateValidatable {
private SimplexOctaveGenerator noiseGenerator;
private final int noiseOctaves = 8;
private final int islandGenerationPercent = 47;
@ -21,7 +21,7 @@ public class IslandLocationMapper implements CoordinateValidatable {
private int shallowDepth;
private final DepthFirstSearch dfs;
public IslandLocationMapper(Random random, int seaLevel, int shallowDepth) {
public IslandWorldBaseTerrainMap(Random random, int seaLevel, int shallowDepth) {
dfs = new DepthFirstSearch(this);
this.seaLevel = seaLevel;
this.shallowDepth = shallowDepth;

View File

@ -20,7 +20,7 @@ public class IslandWorldGenerator {
private final IslandBiomeGenerator biomeGenerator;
public final World world;
public final IslandLocationMapper islandMapGenerator;
public final IslandWorldBaseTerrainMap islandMapGenerator;
public final Random random;
public IslandWorldGenerator(World world, IslandBiomeGenerator generator, Random random) {
@ -29,7 +29,7 @@ public class IslandWorldGenerator {
this.random = random;
this.biomeSelector = new BiomeSelector(random);
this.bedrockGenerator = new BedrockGenerator(random);
this.islandMapGenerator = new IslandLocationMapper(random, world.getSeaLevel(), 4);
this.islandMapGenerator = new IslandWorldBaseTerrainMap(random, world.getSeaLevel(), 4);
this.biomeGenerator = generator;
biomeSelector.initialize();
}

View File

@ -7,11 +7,11 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateTargetValidatable;
import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch;
import ca.recrown.islandsurvivalcraft.world.BiomeSelector;
import ca.recrown.islandsurvivalcraft.world.IslandLocationMapper;
import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap;
public class BiomePerIslandGenerator implements IslandBiomeGenerator, CoordinateTargetValidatable {
private boolean initialized;
private IslandLocationMapper islandLocator;
private IslandWorldBaseTerrainMap islandLocator;
private BiomeSelector biomeSelector;
private TemperatureMapGenerator temperatureMapGenerator;
private int buildHeight;
@ -30,7 +30,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
}
@Override
public void initialize(World world, IslandLocationMapper mapGenerator, BiomeSelector biomeSelector) {
public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biomeSelector) {
if (initialized) throw new IllegalStateException("Biome generator already initialized.");
initialized = true;
this.islandLocator = mapGenerator;
@ -92,7 +92,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate
Biome designatedBiome = mainBiome;
if (mainBiome == null) {
designatedBiome = Biome.OCEAN;
designatedBiome = biomeSelector.getOceanBiome(temperatureMapGenerator.getTemperature(worldX, worldZ));
} else if (islandLocator.isShore(worldX, worldZ)) {
designatedBiome = shoreBiome;
}

View File

@ -5,10 +5,10 @@ import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import ca.recrown.islandsurvivalcraft.world.BiomeSelector;
import ca.recrown.islandsurvivalcraft.world.IslandLocationMapper;
import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap;
public interface IslandBiomeGenerator {
public void initialize(World world, IslandLocationMapper mapGenerator, BiomeSelector biome);
public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biome);
public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biomeGrid);
public IslandBiomeGenerator getInstance();
}

View File

@ -1,5 +0,0 @@
package ca.recrown.islandsurvivalcraft.world.shapers;
public class IslandShaper {
}

View File

@ -0,0 +1,67 @@
package ca.recrown.islandsurvivalcraft.world.shapers;
import java.util.Random;
import org.bukkit.block.Biome;
import org.bukkit.util.noise.SimplexOctaveGenerator;
import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap;
public class WorldShapeShader {
private Random random;
private SimplexOctaveGenerator noiseGenerator;
private IslandWorldBaseTerrainMap islandLocator;
private final float probabilityOfAdditive = 0.75f;
public WorldShapeShader(long seed, IslandWorldBaseTerrainMap islandLocator) {
random = new Random(seed);
noiseGenerator = new SimplexOctaveGenerator(random, 2);
noiseGenerator.setScale(0.05D);
this.islandLocator = islandLocator;
}
public int getAltitude(int worldX, int worldZ, Biome biome) {
double modifier = getHeightModifier(worldX, worldZ);
int baseValue = islandLocator.getBaseTerrainHeight(worldX, worldZ);
int height = 0;
String biomeName = biome.name();
if (biomeName.contains("hills")) {
height = (int) (modifier * 40D + baseValue);
} else if (biomeName.contains("mountains")) {
height = (int) (modifier * 70D + baseValue);
} else if (biomeName.contains("plateau")) {
height = (int) (Math.min(60, Math.max(2, modifier * 80D)) + baseValue);
} else if (biomeName.contains("modified")) {
height = (int) (modifier * 50D + baseValue);
} else if (biomeName.contains("shattered")) {
height = (int) (modifier * 60D + baseValue);
} else if (biomeName.contains("tall")) {
height = (int) (modifier * 55D + baseValue);
} else if (!biomeName.contains("ocean")) {
height = (int) (getNormalizedHeightModifier(worldX, worldZ) * 20D + baseValue);
} else {
height = (int) (getNormalizedHeightModifier(worldX, worldZ) * 10D + baseValue);
}
return height;
}
private double getHeightModifier(int worldX, int worldZ) {
return (2 * probabilityOfAdditive - noiseGenerator.noise(worldX, worldZ, 0.5D, 0.5D, true));
}
private double maxHeightModifier() {
return 2 * probabilityOfAdditive + 1;
}
private double minHeightModifier() {
return 2 * probabilityOfAdditive - 1;
}
private double getNormalizedHeightModifier(int worldX, int worldZ) {
double heightModifier = getHeightModifier(worldX, worldZ);
if (heightModifier > 0) {
return heightModifier / maxHeightModifier();
}
return minHeightModifier();
}
}