2018-10-25 09:54:40 +02:00
|
|
|
package world.bentobox.bskyblock.generators;
|
2018-07-29 22:42:25 +02:00
|
|
|
|
2019-03-08 08:34:27 +01:00
|
|
|
import java.util.Collections;
|
2018-07-29 22:42:25 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.World.Environment;
|
2019-03-09 18:26:05 +01:00
|
|
|
import org.bukkit.block.Biome;
|
2018-07-29 22:42:25 +02:00
|
|
|
import org.bukkit.generator.BlockPopulator;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
|
|
|
|
2018-10-25 09:54:40 +02:00
|
|
|
import world.bentobox.bskyblock.BSkyBlock;
|
2018-07-29 22:42:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author tastybento
|
|
|
|
* Creates the world
|
|
|
|
*/
|
|
|
|
public class ChunkGeneratorWorld extends ChunkGenerator {
|
|
|
|
|
2018-08-25 20:53:25 +02:00
|
|
|
BSkyBlock addon;
|
2019-03-09 18:26:05 +01:00
|
|
|
Random rand;
|
2018-07-29 22:42:25 +02:00
|
|
|
PerlinOctaveGenerator gen;
|
|
|
|
|
|
|
|
/**
|
2018-08-08 23:03:57 +02:00
|
|
|
* @param addon - BSkyBlock object
|
2018-07-29 22:42:25 +02:00
|
|
|
*/
|
2018-08-08 23:03:57 +02:00
|
|
|
public ChunkGeneratorWorld(BSkyBlock addon) {
|
2018-07-29 22:42:25 +02:00
|
|
|
super();
|
2018-08-25 20:53:25 +02:00
|
|
|
this.addon = addon;
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
|
2019-03-09 18:26:05 +01:00
|
|
|
this.rand = random;
|
|
|
|
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
|
|
|
return generateNetherRoofChunks(world, random);
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
|
|
|
ChunkData result = createChunkData(world);
|
2019-03-09 18:26:05 +01:00
|
|
|
if (!world.getEnvironment().equals(Environment.NORMAL)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
Biome bio = addon.getSettings().getDefaultBiome();
|
|
|
|
int seaHeight = addon.getSettings().getSeaHeight();
|
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
for (int z = 0; z < 16; z++) {
|
|
|
|
biomeGrid.setBiome(x, z, bio);
|
|
|
|
if (seaHeight != 0) {
|
|
|
|
for (int y = 0; y <= seaHeight; y++) {
|
2018-07-30 01:57:42 +02:00
|
|
|
result.setBlock(x, y, z, Material.WATER);
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canSpawn(World world, int x, int z) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
2019-03-08 08:34:27 +01:00
|
|
|
return Collections.emptyList();
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nether Section
|
|
|
|
*/
|
2019-03-09 18:26:05 +01:00
|
|
|
private ChunkData generateNetherRoofChunks(World world, Random random) {
|
2018-07-29 22:42:25 +02:00
|
|
|
ChunkData result = createChunkData(world);
|
|
|
|
rand.setSeed(world.getSeed());
|
|
|
|
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
2019-03-09 18:26:05 +01:00
|
|
|
// Make the roof - common across the world
|
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
for (int z = 0; z < 16; z++) {
|
|
|
|
// Do the ceiling
|
|
|
|
makeCeiling(result, x, z, world.getMaxHeight());
|
2019-03-08 08:34:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-09 18:26:05 +01:00
|
|
|
private void makeCeiling(ChunkData result, int x, int z, int maxHeight) {
|
|
|
|
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
|
|
|
|
// Next three layers are a mix of bedrock and netherrack
|
|
|
|
for (int y = 2; y < 5; y++) {
|
|
|
|
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
|
|
|
|
if (r > 0D) {
|
|
|
|
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Next three layers are a mix of netherrack and air
|
|
|
|
for (int y = 5; y < 8; y++) {
|
|
|
|
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
|
|
|
|
if (r > 0D) {
|
|
|
|
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
|
|
|
|
} else {
|
|
|
|
result.setBlock(x, (maxHeight - y), z, Material.AIR);
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
2019-03-09 18:26:05 +01:00
|
|
|
}
|
|
|
|
// Layer 8 may be glowstone
|
|
|
|
doGlowStone(result, maxHeight, x, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doGlowStone(ChunkData result, int maxHeight, int x, int z) {
|
|
|
|
double r = gen.noise(x, (double)maxHeight - 8, z, rand.nextFloat(), rand.nextFloat());
|
|
|
|
if (r < 0.5D) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Have blobs of glowstone
|
|
|
|
switch (rand.nextInt(4)) {
|
|
|
|
case 1:
|
|
|
|
// Blob type 1
|
|
|
|
setBlob1(result, x, maxHeight - 8, z);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// Stalactite
|
|
|
|
setStalactite(result, x, maxHeight - 8, z);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
setBlob2(result, x, maxHeight - 8, z);
|
|
|
|
break;
|
|
|
|
default:
|
2019-03-08 08:34:27 +01:00
|
|
|
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
2019-03-09 18:26:05 +01:00
|
|
|
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
|
|
|
}
|
2018-07-29 22:42:25 +02:00
|
|
|
|
2019-03-09 18:26:05 +01:00
|
|
|
private void setBlob2(ChunkData result, int x, int y, int z) {
|
|
|
|
result.setBlock(x, y, z, Material.GLOWSTONE);
|
|
|
|
if (x > 3 && z > 3) {
|
|
|
|
for (int xx = 0; xx < 3; xx++) {
|
|
|
|
for (int zz = 0; zz < 3; zz++) {
|
|
|
|
result.setBlock(x - xx, y - rand.nextInt(2), z - xx, Material.GLOWSTONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setStalactite(ChunkData result, int x, int y, int z) {
|
|
|
|
for (int i = 0; i < rand.nextInt(10); i++) {
|
|
|
|
result.setBlock(x, y - i, z, Material.GLOWSTONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setBlob1(ChunkData result, int x, int y, int z) {
|
|
|
|
result.setBlock(x, y, z, Material.GLOWSTONE);
|
|
|
|
if (x < 14 && z < 14) {
|
|
|
|
result.setBlock(x + 1, y, z + 1, Material.GLOWSTONE);
|
|
|
|
result.setBlock(x + 2, y, z + 2, Material.GLOWSTONE);
|
|
|
|
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
|
|
|
|
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
|
|
|
|
}
|
2018-07-29 22:42:25 +02:00
|
|
|
}
|
|
|
|
}
|