Added generation modes.
This commit is contained in:
parent
479e28c090
commit
785f7a1ea3
@ -6,6 +6,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.world.WorldInfoManager;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.GeneratorModes;
|
||||
|
||||
public class IslandSurvivalCraft extends JavaPlugin implements Listener {
|
||||
private PluginManager pluginManager;
|
||||
@ -29,7 +30,13 @@ public class IslandSurvivalCraft extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
return worldInfos.getChunkGenerator(getServer().getWorld(worldName));
|
||||
GeneratorModes gID = null;
|
||||
try {
|
||||
gID = GeneratorModes.valueOf(id);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
gID = GeneratorModes.UNIQUE;
|
||||
}
|
||||
return worldInfos.getChunkGenerator(getServer().getWorld(worldName), gID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,48 +8,49 @@ import ca.recrown.islandsurvivalcraft.world.generation.chunks.IslandWorldChunkGe
|
||||
|
||||
public class WorldInfo {
|
||||
private final WorldInfoManager manager;
|
||||
private volatile Random random;
|
||||
private volatile int seaLevel;
|
||||
private volatile int worldHeight;
|
||||
private volatile boolean initialized;
|
||||
public volatile long seed;
|
||||
public volatile BiomeMap biomeMap;
|
||||
public volatile TemperatureMap tempMap;
|
||||
public volatile IslandWorldMap islandMap;
|
||||
public volatile IslandWorldChunkGenerator generator;
|
||||
private volatile long seed;
|
||||
private volatile BiomeMap biomeMap;
|
||||
private volatile TemperatureMap tempMap;
|
||||
private volatile IslandWorldMap islandMap;
|
||||
private volatile IslandWorldChunkGenerator generator;
|
||||
|
||||
/**
|
||||
* Will initialize with the known information extracted from the given world if world is not null.
|
||||
* If the world is null, this world info will not be initialized and awaits initialization from the generator.
|
||||
* @param world The world this object is describing. May be null to create a non-initialized info object.
|
||||
* Will initialize with the known information extracted from the given world if
|
||||
* world is not null. If the world is null, this world info will not be
|
||||
* initialized and awaits initialization from the generator.
|
||||
*
|
||||
* @param world The world this object is describing. May be null to create a
|
||||
* non-initialized info object.
|
||||
*/
|
||||
public WorldInfo(WorldInfoManager manager, World world) {
|
||||
this.manager = manager;
|
||||
if (world != null) {
|
||||
initialize(world);
|
||||
initialize(world, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize(World world, IslandWorldChunkGenerator chunkGenerator) {
|
||||
if (initialized) throw new IllegalStateException("This world information object has already been initialized.");
|
||||
initialized = true;
|
||||
if (initialized)
|
||||
throw new IllegalStateException("This world information object has already been initialized.");
|
||||
this.initialized = true;
|
||||
this.seed = world.getSeed();
|
||||
Random random = new Random(seed);
|
||||
biomeMap = new BiomeMap(random);
|
||||
tempMap = new TemperatureMap(random);
|
||||
islandMap = new IslandWorldMap(random);
|
||||
generator = chunkGenerator;
|
||||
generator.initialize(random, true, world.getSeaLevel(), world.getMaxHeight());
|
||||
manager.register(world, this);
|
||||
}
|
||||
|
||||
private void initialize(World world) {
|
||||
if (initialized) throw new IllegalStateException("This world information object has already been initialized.");
|
||||
initialized = true;
|
||||
this.seed = world.getSeed();
|
||||
Random random = new Random(seed);
|
||||
biomeMap = new BiomeMap(random);
|
||||
tempMap = new TemperatureMap(random);
|
||||
islandMap = new IslandWorldMap(random);
|
||||
generator = new IslandWorldChunkGenerator(this);
|
||||
generator.initialize(random, true, world.getSeaLevel(), world.getMaxHeight());
|
||||
this.random = new Random(seed);
|
||||
this.biomeMap = new BiomeMap(random);
|
||||
this.tempMap = new TemperatureMap(random);
|
||||
this.islandMap = new IslandWorldMap(random);
|
||||
this.worldHeight = world.getMaxHeight();
|
||||
this.seaLevel = world.getSeaLevel();
|
||||
if (chunkGenerator != null) {
|
||||
this.generator = chunkGenerator;
|
||||
this.generator.initialize();
|
||||
this.manager.register(world, this);
|
||||
} else {
|
||||
generator = new IslandWorldChunkGenerator(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,4 +59,67 @@ public class WorldInfo {
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the biomeMap
|
||||
*/
|
||||
public BiomeMap getBiomeMap() {
|
||||
return biomeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generator
|
||||
*/
|
||||
public IslandWorldChunkGenerator getGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandMap
|
||||
*/
|
||||
public IslandWorldMap getIslandMap() {
|
||||
return islandMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the manager
|
||||
*/
|
||||
public WorldInfoManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the random
|
||||
*/
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the seaLevel
|
||||
*/
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the seed
|
||||
*/
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tempMap
|
||||
*/
|
||||
public TemperatureMap getTempMap() {
|
||||
return tempMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the worldHeight
|
||||
*/
|
||||
public int getWorldHeight() {
|
||||
return worldHeight;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.GeneratorModes;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.chunks.IslandWorldChunkGenerator;
|
||||
|
||||
public class WorldInfoManager implements Listener {
|
||||
@ -42,20 +43,28 @@ public class WorldInfoManager implements Listener {
|
||||
* @param world The world the chunk generator is for. If it does not yet exist, it will be created.
|
||||
* @return The chunk generator associated with the given world.
|
||||
*/
|
||||
public ChunkGenerator getChunkGenerator(World world) {
|
||||
if (world == null) {
|
||||
WorldInfo worldInfo = new WorldInfo(this, world);
|
||||
IslandWorldChunkGenerator islandWorldChunkGenerator = new IslandWorldChunkGenerator(worldInfo);
|
||||
return islandWorldChunkGenerator;
|
||||
public ChunkGenerator getChunkGenerator(World world, GeneratorModes mode) {
|
||||
WorldInfo worldInfo = null;
|
||||
if (world != null) {
|
||||
worldInfo = retrieve(world);
|
||||
if (!worldInfo.getGenerator().isInitialized()) {
|
||||
worldInfo.getGenerator().setGeneratorType(mode);
|
||||
worldInfo.getGenerator().initialize();
|
||||
}
|
||||
return worldInfo.getGenerator();
|
||||
} else {
|
||||
worldInfo = new WorldInfo(this, null);
|
||||
IslandWorldChunkGenerator generator = new IslandWorldChunkGenerator(worldInfo);
|
||||
generator.setGeneratorType(mode);
|
||||
return generator;
|
||||
}
|
||||
return retrieve(world).generator;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChunkLoaded(ChunkLoadEvent event) {
|
||||
if (event.isNewChunk()) {
|
||||
Chunk chunk = event.getChunk();
|
||||
retrieve(event.getWorld()).generator.updateChunkLoadedCache(chunk.getX(), chunk.getZ());
|
||||
retrieve(event.getWorld()).getGenerator().updateChunkLoadedCache(chunk.getX(), chunk.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
package ca.recrown.islandsurvivalcraft.world.generation;
|
||||
|
||||
public enum GeneratorModes {
|
||||
UNIQUE
|
||||
}
|
@ -22,15 +22,17 @@ import ca.recrown.islandsurvivalcraft.world.BiomeMap;
|
||||
import ca.recrown.islandsurvivalcraft.world.IslandWorldMap;
|
||||
import ca.recrown.islandsurvivalcraft.world.TemperatureMap;
|
||||
import ca.recrown.islandsurvivalcraft.world.WorldInfo;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.GeneratorModes;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.biomes.BiomeGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.biomes.UniqueBiomeGenerator;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.shaders.WorldHeightShader;
|
||||
import ca.recrown.islandsurvivalcraft.world.generation.shaders.WorldLayerShader;
|
||||
|
||||
public class IslandWorldChunkGenerator extends ChunkGenerator implements Listener {
|
||||
private final int BEDROCK_HEIGHT = 5;
|
||||
private volatile GeneratorModes generatorType;
|
||||
private volatile boolean initialized = false;
|
||||
private volatile WorldInfo worldInfo;
|
||||
private final int BEDROCK_HEIGHT = 5;
|
||||
private volatile IslandWorldMap islandMap;
|
||||
private volatile TemperatureMap temperatureMap;
|
||||
private volatile BiomeMap biomeMap;
|
||||
@ -42,24 +44,32 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
|
||||
private volatile ExecutorService exAlpha = GeneralUtilities.ISC_EXECUTOR_ALPHA;
|
||||
private volatile ExecutorService exBeta = GeneralUtilities.ISC_EXECUTOR_BETA;
|
||||
|
||||
public void initialize(Random random, boolean uniqueBiome, int seaLevel, int worldHeight) {
|
||||
if (initialized) throw new IllegalStateException("This generator has already been initialized");
|
||||
public void initialize() {
|
||||
if (initialized) throw new IllegalStateException("This generator has already been initialized.");
|
||||
initialized = true;
|
||||
this.islandMap = worldInfo.islandMap;
|
||||
this.temperatureMap = worldInfo.tempMap;
|
||||
this.biomeMap = worldInfo.biomeMap;
|
||||
this.heightShader = new WorldHeightShader(random, islandMap, seaLevel, worldHeight, BEDROCK_HEIGHT + 1);
|
||||
this.layerShader = new WorldLayerShader(random, seaLevel, worldHeight, islandMap);
|
||||
this.islandMap = worldInfo.getIslandMap();
|
||||
this.temperatureMap = worldInfo.getTempMap();
|
||||
this.biomeMap = worldInfo.getBiomeMap();
|
||||
this.heightShader = new WorldHeightShader(worldInfo.getRandom(), islandMap, worldInfo.getSeaLevel(), worldInfo.getWorldHeight(), BEDROCK_HEIGHT + 1);
|
||||
this.layerShader = new WorldLayerShader(worldInfo.getRandom(), worldInfo.getSeaLevel(), worldInfo.getWorldHeight(), islandMap);
|
||||
|
||||
if (uniqueBiome) {
|
||||
if (generatorType == GeneratorModes.UNIQUE) {
|
||||
biomeGenerator = new UniqueBiomeGenerator();
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generatorType the gID to set to.
|
||||
*/
|
||||
public void setGeneratorType(GeneratorModes generatorType) {
|
||||
if (initialized) throw new IllegalStateException("This generator has already been initialized.");
|
||||
this.generatorType = generatorType;
|
||||
}
|
||||
|
||||
public IslandWorldChunkGenerator(WorldInfo worldInfo) {
|
||||
this.worldInfo = worldInfo;
|
||||
this.worldInfo = worldInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,10 +79,6 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
|
||||
}
|
||||
if (!initialized) throw new IllegalStateException("This generator has not been initialized.");
|
||||
|
||||
long seed = world.getSeed();
|
||||
int maxHeight = world.getMaxHeight();
|
||||
int seaLevel = world.getSeaLevel();
|
||||
|
||||
LinkedList<Future<Boolean>> tasks = new LinkedList<>();
|
||||
ChunkData chunkData = createChunkData(world);
|
||||
Future<Boolean> preLoader = exAlpha.submit(() -> {
|
||||
@ -98,7 +104,7 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
|
||||
}
|
||||
if (biomeArraySet[localX][localZ][0] == null) throw new IllegalStateException("Biome was null.");
|
||||
tasks.add(exBeta.submit(() -> {
|
||||
for (int y = 0; y < maxHeight; y++) {
|
||||
for (int y = 0; y < worldInfo.getWorldHeight(); y++) {
|
||||
biomeGrid.setBiome(localX, y, localZ, biomeArraySet[localX][localZ][0]);
|
||||
}
|
||||
return true;
|
||||
@ -109,11 +115,11 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
|
||||
int currentTerrainHeight = terrainHeight - 1;
|
||||
int bedrockHeight = random.nextInt(5) + 1;
|
||||
if (layerShader.hasSpecialLayers(currentBiomeSet[0])) {
|
||||
BlockData currentMaterial = layerShader.getMaterialForHeight(seed, worldX, worldZ, currentTerrainHeight, terrainHeight - 1, currentBiomeSet);
|
||||
BlockData currentMaterial = layerShader.getMaterialForHeight(worldInfo.getSeed(), worldX, worldZ, currentTerrainHeight, terrainHeight - 1, currentBiomeSet);
|
||||
while (currentMaterial != null) {
|
||||
chunkData.setBlock(localX, currentTerrainHeight, localZ, currentMaterial);
|
||||
currentTerrainHeight--;
|
||||
currentMaterial = layerShader.getMaterialForHeight(seed, worldX, worldZ, currentTerrainHeight, terrainHeight - 1, currentBiomeSet);
|
||||
currentMaterial = layerShader.getMaterialForHeight(worldInfo.getSeed(), worldX, worldZ, currentTerrainHeight, terrainHeight - 1, currentBiomeSet);
|
||||
}
|
||||
} else {
|
||||
int surfaceThickness = layerShader.getSurfaceThickness(worldX, worldZ, currentBiomeSet[0]);
|
||||
@ -124,8 +130,8 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene
|
||||
chunkData.setRegion(localX, currentTerrainHeight, localZ, localX + 1, currentTerrainHeight + transitionThickness + 1, localZ + 1, layerShader.getTransitionMaterial(currentBiomeSet[0]));
|
||||
}
|
||||
chunkData.setRegion(localX, bedrockHeight, localZ, localX + 1, currentTerrainHeight + 1, localZ + 1, Material.STONE);
|
||||
if (terrainHeight < seaLevel) {
|
||||
chunkData.setRegion(localX, terrainHeight, localZ, localX + 1, seaLevel, localZ + 1, Material.WATER);
|
||||
if (terrainHeight < worldInfo.getSeaLevel()) {
|
||||
chunkData.setRegion(localX, terrainHeight, localZ, localX + 1, worldInfo.getSeaLevel(), localZ + 1, Material.WATER);
|
||||
}
|
||||
chunkData.setRegion(localX, 0, localZ, localX + 1, bedrockHeight, localZ + 1, Material.BEDROCK);
|
||||
}
|
||||
|
@ -29,15 +29,15 @@ public class WorldHeightShader {
|
||||
if (!mapper.isLand(worldX, worldZ)) {
|
||||
height = (int) calculateTerrainFactor(worldX, worldZ, seaLevel * 0.8d, 1.7d, 0.5d, 1d, 0.1d);
|
||||
} else if (biomeName.contains("beach")) {
|
||||
height = (int) (getIslandBiomeHeight(worldX, worldZ, biomeSet[1], 5d));
|
||||
height = (int) (getIslandBiomeHeight(worldX, worldZ, biomeSet[1], 10d));
|
||||
} else if (biomeName.contains("shore")) {
|
||||
height = (int) (getIslandBiomeHeight(worldX, worldZ, biomeSet[1], 30d));
|
||||
height = (int) (getIslandBiomeHeight(worldX, worldZ, biomeSet[1], -30d));
|
||||
} else {
|
||||
height = getIslandBiomeHeight(worldX, worldZ, biomeSet[0], 0d) + 1;
|
||||
}
|
||||
|
||||
if (height > worldHeight) throw new IllegalStateException("Resulting height is greater than world height! Biome this occurred on: " + biomeName);
|
||||
height = Math.max(minimumHeight, height);
|
||||
if (height > worldHeight) throw new IllegalStateException(String.format("Resulting height is greater than world height! Current biome set: %s, maximum height: %d, minimum height %d", biomeSet, worldHeight, minimumHeight));
|
||||
return height;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user