mirror of
https://github.com/BentoBoxWorld/BSkyBlock.git
synced 2025-01-27 22:03:30 +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;
|
package world.bentobox.bskyblock.generators;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -10,6 +12,7 @@ import org.bukkit.World.Environment;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||||
|
|
||||||
import world.bentobox.bskyblock.BSkyBlock;
|
import world.bentobox.bskyblock.BSkyBlock;
|
||||||
@ -20,43 +23,48 @@ import world.bentobox.bskyblock.BSkyBlock;
|
|||||||
*/
|
*/
|
||||||
public class ChunkGeneratorWorld extends ChunkGenerator {
|
public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||||
|
|
||||||
BSkyBlock addon;
|
private final BSkyBlock addon;
|
||||||
Random rand;
|
private final Random rand = new Random();
|
||||||
PerlinOctaveGenerator gen;
|
private Map<Vector, Material> roofChunk = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param addon - BSkyBlock object
|
* @param addon - addon
|
||||||
*/
|
*/
|
||||||
public ChunkGeneratorWorld(BSkyBlock addon) {
|
public ChunkGeneratorWorld(BSkyBlock addon) {
|
||||||
super();
|
super();
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
|
makeNetherRoof();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChunkData generateChunks(World world) {
|
||||||
|
ChunkData result = createChunkData(world);
|
||||||
|
if (world.getEnvironment().equals(Environment.NORMAL) && addon.getSettings().getSeaHeight() > 0) {
|
||||||
|
result.setRegion(0, 0, 0, 16, addon.getSettings().getSeaHeight() + 1, 16, 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
|
@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, BiomeGrid biomeGrid) {
|
||||||
this.rand = random;
|
if (world.getEnvironment().equals(Environment.NORMAL)) setBiome(biomeGrid);
|
||||||
if (world.getEnvironment().equals(World.Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
return generateChunks(world);
|
||||||
return generateNetherRoofChunks(world, random);
|
|
||||||
}
|
|
||||||
ChunkData result = createChunkData(world);
|
|
||||||
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++) {
|
|
||||||
result.setBlock(x, y, z, Material.WATER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public boolean canSpawn(World world, int x, int z) {
|
public boolean canSpawn(World world, int x, int z) {
|
||||||
return true;
|
return true;
|
||||||
@ -70,91 +78,75 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
|||||||
/*
|
/*
|
||||||
* Nether Section
|
* Nether Section
|
||||||
*/
|
*/
|
||||||
private ChunkData generateNetherRoofChunks(World world, Random random) {
|
private void makeNetherRoof() {
|
||||||
ChunkData result = createChunkData(world);
|
rand.setSeed(System.currentTimeMillis());
|
||||||
rand.setSeed(world.getSeed());
|
PerlinOctaveGenerator gen = new PerlinOctaveGenerator((long) (rand.nextLong() * rand.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());
|
setBlock(x, -1, z, Material.BEDROCK);
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
// 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, - y, z, 0.5, 0.5);
|
||||||
if (r > 0D) {
|
if (r > 0D) {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.BEDROCK);
|
setBlock(x, - 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, - y, z, 0.5, 0.5);
|
||||||
if (r > 0D) {
|
if (r > 0D) {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.NETHERRACK);
|
setBlock(x, -y, z, Material.NETHERRACK);
|
||||||
} else {
|
} else {
|
||||||
result.setBlock(x, (maxHeight - y), z, Material.AIR);
|
setBlock(x, -y, z, Material.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Layer 8 may be glowstone
|
// Layer 8 may be glowstone
|
||||||
doGlowStone(result, maxHeight, x, z);
|
double r = gen.noise(x, - 8, z, rand.nextFloat(), rand.nextFloat());
|
||||||
}
|
if (r > 0.5D) {
|
||||||
|
|
||||||
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
|
// Have blobs of glowstone
|
||||||
switch (rand.nextInt(4)) {
|
switch (rand.nextInt(4)) {
|
||||||
case 1:
|
case 1:
|
||||||
// Blob type 1
|
// Single block
|
||||||
setBlob1(result, x, maxHeight - 8, z);
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Stalactite
|
// Stalatite
|
||||||
setStalactite(result, x, maxHeight - 8, z);
|
for (int i = 0; i < rand.nextInt(10); i++) {
|
||||||
|
setBlock(x, - 8 - i, z, Material.GLOWSTONE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
setBlob2(result, x, maxHeight - 8, z);
|
setBlock(x, -8, z, Material.GLOWSTONE);
|
||||||
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) {
|
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);
|
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) {
|
private void setBlock(int x, int y, int z, Material m) {
|
||||||
result.setBlock(x, y, z, Material.GLOWSTONE);
|
roofChunk.put(new Vector(x, y, z), m);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,14 @@ package world.bentobox.bskyblock.generators;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
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.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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -18,7 +25,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -55,7 +61,7 @@ public class ChunkGeneratorWorldTest {
|
|||||||
// Bukkit
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
when(server.createChunkData(Mockito.any())).thenReturn(data);
|
when(server.createChunkData(any())).thenReturn(data);
|
||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
|
|
||||||
// Instance
|
// Instance
|
||||||
@ -84,12 +90,12 @@ public class ChunkGeneratorWorldTest {
|
|||||||
assertEquals(data, cd);
|
assertEquals(data, cd);
|
||||||
// Verifications
|
// Verifications
|
||||||
// Default biome
|
// Default biome
|
||||||
Mockito.verify(settings).getDefaultBiome();
|
verify(settings).getDefaultBiome();
|
||||||
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
verify(biomeGrid, times(16 * 16)).setBiome(anyInt(), anyInt(), any());
|
||||||
// Sea height
|
// Sea height
|
||||||
Mockito.verify(settings).getSeaHeight();
|
verify(settings).getSeaHeight();
|
||||||
// Void
|
// 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);
|
assertEquals(data, cd);
|
||||||
// Verifications
|
// Verifications
|
||||||
// Default biome
|
// Default biome
|
||||||
Mockito.verify(settings).getDefaultBiome();
|
verify(settings).getDefaultBiome();
|
||||||
Mockito.verify(biomeGrid, Mockito.times(16 * 16)).setBiome(Mockito.anyInt(), Mockito.anyInt(), Mockito.any());
|
verify(biomeGrid, times(16 * 16)).setBiome(anyInt(), anyInt(), any());
|
||||||
// Sea height
|
// Sea height
|
||||||
Mockito.verify(settings).getSeaHeight();
|
verify(settings, times(2)).getSeaHeight();
|
||||||
// Water. Blocks = 16 x 16 x 11 because block 0
|
// 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);
|
assertEquals(data, cd);
|
||||||
// Verifications
|
// Verifications
|
||||||
// Default biome
|
// Default biome
|
||||||
Mockito.verify(settings, Mockito.never()).getDefaultBiome();
|
verify(settings, never()).getDefaultBiome();
|
||||||
// Never set biome in end
|
// 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
|
// Sea height
|
||||||
Mockito.verify(settings, Mockito.never()).getSeaHeight();
|
verify(settings, never()).getSeaHeight();
|
||||||
// Void
|
// 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);
|
assertEquals(data, cd);
|
||||||
// Verifications
|
// Verifications
|
||||||
// Nether roof check
|
// Nether roof check
|
||||||
Mockito.verify(settings).isNetherRoof();
|
verify(settings).isNetherRoof();
|
||||||
// Never set biome in nether
|
// 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
|
// 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);
|
assertEquals(data, cd);
|
||||||
// Verifications
|
// Verifications
|
||||||
// Nether roof check
|
// Nether roof check
|
||||||
Mockito.verify(settings).isNetherRoof();
|
verify(settings).isNetherRoof();
|
||||||
// Never set biome in nether
|
// 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
|
// 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