Implemented changes to world generator and plugin class.

This commit is contained in:
Harrison Deng 2020-04-20 16:28:30 -05:00
parent 5b0942202a
commit a3024f6e91
2 changed files with 28 additions and 10 deletions

View File

@ -1,6 +1,5 @@
package ca.recrown.islandsurvivalcraft;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
@ -24,7 +23,7 @@ public class IslandSurvivalCraft extends JavaPlugin {
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
if (generator == null) {
World world = getServer().getWorld(worldName);
generator = new IslandSurvivalCraftWorldGenerator(world.getSeed(), world.getMaxHeight(), world.getSeaLevel(), true);
generator = new IslandSurvivalCraftWorldGenerator(this, world, true);
}
return generator;
}

View File

@ -3,31 +3,50 @@ package ca.recrown.islandsurvivalcraft.worldgen;
import java.util.Random;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft;
public class IslandSurvivalCraftWorldGenerator extends ChunkGenerator {
private final BiomeSelector biomeSelector;
private final BiomePerIslandGenerator biomePerIslandGenerator;
private final IslandBiomeGenerator biomeGenerator;
private final IslandMapGenerator islandMapGenerator;
private final TemperatureMapGenerator temperatureMapGenerator;
private final BedrockGenerator bedrockGenerator;
private final Random random;
public IslandSurvivalCraftWorldGenerator(long seed, int worldHeight, int seaLevel, boolean biomePerIsland) {
random = new Random(seed);
public IslandSurvivalCraftWorldGenerator(IslandSurvivalCraft plugin, World world, boolean biomePerIsland) {
random = new Random(world.getSeed());
this.biomeSelector = new BiomeSelector(random);
this.islandMapGenerator = new IslandMapGenerator(random, seaLevel, 3);
this.temperatureMapGenerator = new TemperatureMapGenerator(seed);
this.bedrockGenerator = new BedrockGenerator(random);
this.islandMapGenerator = new IslandMapGenerator(random, world.getSeaLevel(), 3);
this.temperatureMapGenerator = new TemperatureMapGenerator(world.getSeed());
if (biomePerIsland) {
this.biomePerIslandGenerator = new BiomePerIslandGenerator(worldHeight, islandMapGenerator, random, biomeSelector);
this.biomeGenerator = new BiomePerIslandGenerator(plugin, world, islandMapGenerator, biomeSelector, temperatureMapGenerator);
} else {
throw new NotImplementedException();
}
biomeSelector.initialize();
}
@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);
ChunkData chunk = createChunkData(world);
for (int localX = 0; localX < 16; localX++) {
for (int localZ = 0; localZ < 16; localZ++) {
int worldX = 16*x + localX;
int worldZ = 16*z + localZ;
//generate bedrock layer
int bedrockHeight = bedrockGenerator.getBedrockHeight(worldX, worldZ);
chunk.setBlock(localX, bedrockHeight, localZ, Material.BEDROCK);
//Set biomes
biomeGenerator.GenerateBiome(x, z, localX, localZ, biome);
}
}
return chunk;
}
}