mirror of
https://github.com/BentoBoxWorld/BSkyBlock.git
synced 2024-09-26 03:53:45 +02:00
Performs chunk regeneration.
This commit is contained in:
parent
8a350b16c3
commit
8f0fc67ce0
2
pom.xml
2
pom.xml
@ -91,7 +91,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>world.bentobox</groupId>
|
<groupId>world.bentobox</groupId>
|
||||||
<artifactId>bentobox</artifactId>
|
<artifactId>bentobox</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.5.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package world.bentobox.bskyblock;
|
package world.bentobox.bskyblock;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
@ -130,4 +131,10 @@ public class BSkyBlock extends GameModeAddon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void regerateChunk(Chunk chunk) {
|
||||||
|
if (chunkGenerator != null) chunkGenerator.regenerateChunk(chunk);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
@ -20,141 +21,158 @@ import world.bentobox.bskyblock.BSkyBlock;
|
|||||||
*/
|
*/
|
||||||
public class ChunkGeneratorWorld extends ChunkGenerator {
|
public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||||
|
|
||||||
BSkyBlock addon;
|
BSkyBlock addon;
|
||||||
Random rand;
|
Random rand;
|
||||||
PerlinOctaveGenerator gen;
|
PerlinOctaveGenerator gen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param addon - BSkyBlock object
|
* @param addon - BSkyBlock object
|
||||||
*/
|
*/
|
||||||
public ChunkGeneratorWorld(BSkyBlock addon) {
|
public ChunkGeneratorWorld(BSkyBlock addon) {
|
||||||
super();
|
super();
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
|
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
|
||||||
this.rand = random;
|
this.rand = random;
|
||||||
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
||||||
return generateNetherRoofChunks(world, random);
|
return generateNetherRoofChunks(world, random);
|
||||||
}
|
}
|
||||||
ChunkData result = createChunkData(world);
|
ChunkData result = createChunkData(world);
|
||||||
if (!world.getEnvironment().equals(Environment.NORMAL)) {
|
if (!world.getEnvironment().equals(Environment.NORMAL)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Biome bio = addon.getSettings().getDefaultBiome();
|
Biome bio = addon.getSettings().getDefaultBiome();
|
||||||
int seaHeight = addon.getSettings().getSeaHeight();
|
int seaHeight = addon.getSettings().getSeaHeight();
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
biomeGrid.setBiome(x, z, bio);
|
if (biomeGrid != null) biomeGrid.setBiome(x, z, bio);
|
||||||
if (seaHeight != 0) {
|
if (seaHeight != 0) {
|
||||||
for (int y = 0; y <= seaHeight; y++) {
|
for (int y = 0; y <= seaHeight; y++) {
|
||||||
result.setBlock(x, y, z, Material.WATER);
|
result.setBlock(x, y, z, Material.WATER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSpawn(World world, int x, int z) {
|
public boolean canSpawn(World world, int x, int z) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Nether Section
|
* Nether Section
|
||||||
*/
|
*/
|
||||||
private ChunkData generateNetherRoofChunks(World world, Random random) {
|
private ChunkData generateNetherRoofChunks(World world, Random random) {
|
||||||
ChunkData result = createChunkData(world);
|
ChunkData result = createChunkData(world);
|
||||||
rand.setSeed(world.getSeed());
|
rand.setSeed(world.getSeed());
|
||||||
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
||||||
// Make the roof - common across the world
|
// Make the roof - common across the world
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
// Do the ceiling
|
// Do the ceiling
|
||||||
makeCeiling(result, x, z, world.getMaxHeight());
|
makeCeiling(result, x, z, world.getMaxHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeCeiling(ChunkData result, int x, int z, int maxHeight) {
|
private void makeCeiling(ChunkData result, int x, int z, int maxHeight) {
|
||||||
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
|
result.setBlock(x, (maxHeight - 1), z, Material.BEDROCK);
|
||||||
// Next three layers are a mix of bedrock and netherrack
|
// Next three layers are a mix of bedrock and netherrack
|
||||||
for (int y = 2; y < 5; y++) {
|
for (int y = 2; y < 5; y++) {
|
||||||
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
|
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
|
||||||
if (r > 0D) {
|
if (r > 0D) {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
|
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Next three layers are a mix of netherrack and air
|
// Next three layers are a mix of netherrack and air
|
||||||
for (int y = 5; y < 8; y++) {
|
for (int y = 5; y < 8; y++) {
|
||||||
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
|
double r = gen.noise(x, (double)maxHeight - y, z, 0.5, 0.5);
|
||||||
if (r > 0D) {
|
if (r > 0D) {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
|
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
|
||||||
} else {
|
} else {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.AIR);
|
result.setBlock(x, (maxHeight - y), z, Material.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Layer 8 may be glowstone
|
// Layer 8 may be glowstone
|
||||||
doGlowStone(result, maxHeight, x, z);
|
doGlowStone(result, maxHeight, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doGlowStone(ChunkData result, int maxHeight, int x, int 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());
|
double r = gen.noise(x, (double)maxHeight - 8, z, rand.nextFloat(), rand.nextFloat());
|
||||||
if (r < 0.5D) {
|
if (r < 0.5D) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Have blobs of glowstone
|
// Have blobs of glowstone
|
||||||
switch (rand.nextInt(4)) {
|
switch (rand.nextInt(4)) {
|
||||||
case 1:
|
case 1:
|
||||||
// Blob type 1
|
// Blob type 1
|
||||||
setBlob1(result, x, maxHeight - 8, z);
|
setBlob1(result, x, maxHeight - 8, z);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Stalactite
|
// Stalactite
|
||||||
setStalactite(result, x, maxHeight - 8, z);
|
setStalactite(result, x, maxHeight - 8, z);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
setBlob2(result, x, maxHeight - 8, z);
|
setBlob2(result, x, maxHeight - 8, z);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||||
}
|
}
|
||||||
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
result.setBlock(x, (maxHeight - 8), z, Material.GLOWSTONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBlob2(ChunkData result, int x, int y, int z) {
|
private void setBlob2(ChunkData result, int x, int y, int z) {
|
||||||
result.setBlock(x, y, z, Material.GLOWSTONE);
|
result.setBlock(x, y, z, Material.GLOWSTONE);
|
||||||
if (x > 3 && z > 3) {
|
if (x > 3 && z > 3) {
|
||||||
for (int xx = 0; xx < 3; xx++) {
|
for (int xx = 0; xx < 3; xx++) {
|
||||||
for (int zz = 0; zz < 3; zz++) {
|
for (int zz = 0; zz < 3; zz++) {
|
||||||
result.setBlock(x - xx, y - rand.nextInt(2), z - xx, Material.GLOWSTONE);
|
result.setBlock(x - xx, y - rand.nextInt(2), z - xx, Material.GLOWSTONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStalactite(ChunkData result, int x, int y, int z) {
|
private void setStalactite(ChunkData result, int x, int y, int z) {
|
||||||
for (int i = 0; i < rand.nextInt(10); i++) {
|
for (int i = 0; i < rand.nextInt(10); i++) {
|
||||||
result.setBlock(x, y - i, z, Material.GLOWSTONE);
|
result.setBlock(x, y - i, z, Material.GLOWSTONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBlob1(ChunkData result, int x, int y, int z) {
|
private void setBlob1(ChunkData result, int x, int y, int z) {
|
||||||
result.setBlock(x, y, z, Material.GLOWSTONE);
|
result.setBlock(x, y, z, Material.GLOWSTONE);
|
||||||
if (x < 14 && z < 14) {
|
if (x < 14 && z < 14) {
|
||||||
result.setBlock(x + 1, y, z + 1, Material.GLOWSTONE);
|
result.setBlock(x + 1, y, z + 1, Material.GLOWSTONE);
|
||||||
result.setBlock(x + 2, y, z + 2, 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);
|
||||||
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
|
result.setBlock(x + 1, y, z + 2, Material.GLOWSTONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Regenerate a chunk
|
||||||
|
* @param chunk - chunk to regenerate
|
||||||
|
*/
|
||||||
|
public void regenerateChunk(Chunk chunk) {
|
||||||
|
ChunkData cd = generateChunkData(chunk.getWorld(), new Random(), chunk.getX(), chunk.getZ(), null);
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
chunk.getBlock(x, 0, z).setBiome(addon.getSettings().getDefaultBiome());
|
||||||
|
for (int y = 0; y < chunk.getWorld().getMaxHeight(); y++) {
|
||||||
|
chunk.getBlock(x, y, z).setBlockData(cd.getBlockData(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user