mirror of
https://github.com/BentoBoxWorld/BSkyBlock.git
synced 2025-01-14 20:01:20 +01:00
Uses optimized chunk generator for nether ceiling
This commit is contained in:
parent
b0c6499bf7
commit
191d2b9cc2
@ -1,7 +1,9 @@
|
||||
package world.bentobox.bskyblock.generators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Material;
|
||||
@ -10,6 +12,7 @@ import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
@ -20,43 +23,48 @@ import world.bentobox.bskyblock.BSkyBlock;
|
||||
*/
|
||||
public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
|
||||
BSkyBlock addon;
|
||||
Random rand;
|
||||
PerlinOctaveGenerator gen;
|
||||
private final BSkyBlock addon;
|
||||
private final Random rand = new Random();
|
||||
private Map<Vector, Material> roofChunk = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param addon - BSkyBlock object
|
||||
* @param addon - addon
|
||||
*/
|
||||
public ChunkGeneratorWorld(BSkyBlock addon) {
|
||||
super();
|
||||
this.addon = addon;
|
||||
makeNetherRoof();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {
|
||||
this.rand = random;
|
||||
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
||||
return generateNetherRoofChunks(world, random);
|
||||
}
|
||||
public ChunkData generateChunks(World world) {
|
||||
ChunkData result = createChunkData(world);
|
||||
if (!world.getEnvironment().equals(Environment.NORMAL)) {
|
||||
return result;
|
||||
if (world.getEnvironment().equals(Environment.NORMAL) && addon.getSettings().getSeaHeight() > 0) {
|
||||
result.setRegion(0, 0, 0, 16, addon.getSettings().getSeaHeight() + 1, 16, Material.WATER);
|
||||
}
|
||||
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++) {
|
||||
result.setBlock(x, y, z, Material.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (world.getEnvironment().equals(Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
||||
roofChunk.forEach((k,v) -> result.setBlock(k.getBlockX(), world.getMaxHeight() + k.getBlockY(), k.getBlockZ(), v));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||
if (world.getEnvironment().equals(Environment.NORMAL)) setBiome(biomeGrid);
|
||||
return generateChunks(world);
|
||||
}
|
||||
|
||||
private void setBiome(BiomeGrid biomeGrid) {
|
||||
Biome biome = addon.getSettings().getDefaultBiome();
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
biomeGrid.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This needs to be set to return true to override minecraft's default
|
||||
// behavior
|
||||
@Override
|
||||
public boolean canSpawn(World world, int x, int z) {
|
||||
return true;
|
||||
@ -70,91 +78,75 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
/*
|
||||
* Nether Section
|
||||
*/
|
||||
private ChunkData generateNetherRoofChunks(World world, Random random) {
|
||||
ChunkData result = createChunkData(world);
|
||||
rand.setSeed(world.getSeed());
|
||||
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
||||
private void makeNetherRoof() {
|
||||
rand.setSeed(System.currentTimeMillis());
|
||||
PerlinOctaveGenerator gen = new PerlinOctaveGenerator((long) (rand.nextLong() * rand.nextGaussian()), 8);
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 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:
|
||||
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) {
|
||||
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);
|
||||
setBlock(x, -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, - y, z, 0.5, 0.5);
|
||||
if (r > 0D) {
|
||||
setBlock(x, - 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, - y, z, 0.5, 0.5);
|
||||
if (r > 0D) {
|
||||
setBlock(x, -y, z, Material.NETHERRACK);
|
||||
} else {
|
||||
setBlock(x, -y, z, Material.AIR);
|
||||
}
|
||||
}
|
||||
// Layer 8 may be glowstone
|
||||
double r = gen.noise(x, - 8, z, rand.nextFloat(), rand.nextFloat());
|
||||
if (r > 0.5D) {
|
||||
// Have blobs of glowstone
|
||||
switch (rand.nextInt(4)) {
|
||||
case 1:
|
||||
// Single block
|
||||
setBlock(x, -8, z, Material.GLOWSTONE);
|
||||
if (x < 14 && z < 14) {
|
||||
setBlock(x + 1, -8, z + 1, Material.GLOWSTONE);
|
||||
setBlock(x + 2, -8, z + 2, Material.GLOWSTONE);
|
||||
setBlock(x + 1, -8, z + 2, Material.GLOWSTONE);
|
||||
setBlock(x + 1, -8, z + 2, Material.GLOWSTONE);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// Stalatite
|
||||
for (int i = 0; i < rand.nextInt(10); i++) {
|
||||
setBlock(x, - 8 - i, z, Material.GLOWSTONE);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
setBlock(x, -8, z, Material.GLOWSTONE);
|
||||
if (x > 3 && z > 3) {
|
||||
for (int xx = 0; xx < 3; xx++) {
|
||||
for (int zz = 0; zz < 3; zz++) {
|
||||
setBlock(x - xx, - 8 - rand.nextInt(2), z - xx, Material.GLOWSTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
setBlock(x, -8, z, Material.GLOWSTONE);
|
||||
}
|
||||
setBlock(x, -8, z, Material.GLOWSTONE);
|
||||
} else {
|
||||
setBlock(x, -8, z, Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
private void setBlock(int x, int y, int z, Material m) {
|
||||
roofChunk.put(new Vector(x, y, z), m);
|
||||
}
|
||||
}
|
@ -2,7 +2,14 @@ package world.bentobox.bskyblock.generators;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Random;
|
||||
@ -18,7 +25,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -55,7 +61,7 @@ public class ChunkGeneratorWorldTest {
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
Server server = mock(Server.class);
|
||||
when(server.createChunkData(Mockito.any())).thenReturn(data);
|
||||
when(server.createChunkData(any())).thenReturn(data);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
|
||||
// Instance
|
||||
@ -84,12 +90,12 @@ public class ChunkGeneratorWorldTest {
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
Mockito.verify(settings).getDefaultBiome();
|
||||
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
||||
verify(settings).getDefaultBiome();
|
||||
verify(biomeGrid, times(16 * 16)).setBiome(anyInt(), anyInt(), any());
|
||||
// Sea height
|
||||
Mockito.verify(settings).getSeaHeight();
|
||||
verify(settings).getSeaHeight();
|
||||
// Void
|
||||
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
|
||||
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,12 +109,12 @@ public class ChunkGeneratorWorldTest {
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
Mockito.verify(settings).getDefaultBiome();
|
||||
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
||||
verify(settings).getDefaultBiome();
|
||||
verify(biomeGrid, times(16 * 16)).setBiome(anyInt(), anyInt(), any());
|
||||
// Sea height
|
||||
Mockito.verify(settings).getSeaHeight();
|
||||
verify(settings, times(2)).getSeaHeight();
|
||||
// Water. Blocks = 16 x 16 x 11 because block 0
|
||||
Mockito.verify(cd, Mockito.times(2816)).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.eq(Material.WATER));
|
||||
verify(cd).setRegion(0, 0, 0, 16, 11, 16, Material.WATER);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,13 +127,13 @@ public class ChunkGeneratorWorldTest {
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Default biome
|
||||
Mockito.verify(settings, Mockito.never()).getDefaultBiome();
|
||||
verify(settings, never()).getDefaultBiome();
|
||||
// Never set biome in end
|
||||
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
||||
verify(biomeGrid, never()).setBiome(anyInt(), anyInt(), any());
|
||||
// Sea height
|
||||
Mockito.verify(settings, Mockito.never()).getSeaHeight();
|
||||
verify(settings, never()).getSeaHeight();
|
||||
// Void
|
||||
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
|
||||
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,11 +146,11 @@ public class ChunkGeneratorWorldTest {
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Nether roof check
|
||||
Mockito.verify(settings).isNetherRoof();
|
||||
verify(settings).isNetherRoof();
|
||||
// Never set biome in nether
|
||||
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
||||
verify(biomeGrid, never()).setBiome(anyInt(), anyInt(), any());
|
||||
// Nether roof - at least bedrock layer
|
||||
Mockito.verify(cd, Mockito.atLeast(16 * 16)).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.eq(Material.BEDROCK));
|
||||
verify(cd, atLeast(16 * 16)).setBlock(anyInt(), anyInt(), anyInt(), eq(Material.BEDROCK));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,11 +164,11 @@ public class ChunkGeneratorWorldTest {
|
||||
assertEquals(data, cd);
|
||||
// Verifications
|
||||
// Nether roof check
|
||||
Mockito.verify(settings).isNetherRoof();
|
||||
verify(settings).isNetherRoof();
|
||||
// Never set biome in nether
|
||||
Mockito.verify(biomeGrid, Mockito.never()).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
||||
verify(biomeGrid, never()).setBiome(anyInt(), anyInt(), any());
|
||||
// Nether roof - at least bedrock layer
|
||||
Mockito.verify(cd, Mockito.never()).setBlock(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(Material.class));
|
||||
verify(cd, never()).setBlock(anyInt(), anyInt(), anyInt(), any(Material.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user