Added ability to set the default water block

Can be set to anything, but LAVA is the most likely for the nether

Also reworked the nether and end islands to not assume water.

https://github.com/BentoBoxWorld/AcidIsland/issues/63
This commit is contained in:
tastybento 2022-03-20 19:43:12 +00:00
parent ea3e92ea67
commit 8c8c70d749
6 changed files with 114 additions and 42 deletions

View File

@ -9,6 +9,7 @@ import java.util.Set;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffectType;
@ -206,7 +207,7 @@ public class AISettings implements WorldSettings {
@ConfigComment("It is the y coordinate of the bedrock block in the schem.")
@ConfigEntry(path = "world.island-height")
private int islandHeight = 50;
@ConfigComment("Use your own world generator for this world.")
@ConfigComment("In this case, the plugin will not generate anything.")
@ConfigEntry(path = "world.use-own-generator", experimental = true)
@ -216,6 +217,10 @@ public class AISettings implements WorldSettings {
@ConfigComment("Minimum is 0, which means you are playing Skyblock!")
@ConfigEntry(path = "world.sea-height")
private int seaHeight = 54;
@ConfigComment("Water block. This should usually stay as WATER, but may be LAVA for fun")
@ConfigEntry(path = "world.water-block", needsReset = true)
private Material waterBlock = Material.WATER;
@ConfigComment("Maximum number of islands in the world. Set to -1 or 0 for unlimited. ")
@ConfigComment("If the number of islands is greater than this number, no new island will be created.")
@ -260,6 +265,10 @@ public class AISettings implements WorldSettings {
@ConfigComment("Changing mid-game will cause problems!")
@ConfigEntry(path = "world.nether.sea-height", needsReset = true)
private int netherSeaHeight = 54;
@ConfigComment("Water block. This should usually stay as WATER, but may be LAVA for fun")
@ConfigEntry(path = "world.nether.water-block", needsReset = true)
private Material netherWaterBlock = Material.WATER;
@ConfigComment("Make the nether roof, if false, there is nothing up there")
@ConfigComment("Change to false if lag is a problem from the generation")
@ -294,6 +303,10 @@ public class AISettings implements WorldSettings {
@ConfigComment("Changing mid-game will cause problems!")
@ConfigEntry(path = "world.end.sea-height", needsReset = true)
private int endSeaHeight = 54;
@ConfigComment("Water block. This should usually stay as WATER, but may be LAVA for fun")
@ConfigEntry(path = "world.end.water-block", needsReset = true)
private Material endWaterBlock = Material.WATER;
@ConfigComment("This option indicates if obsidian platform in the end should be generated")
@ConfigComment("when player enters the end world.")
@ -1960,4 +1973,22 @@ public class AISettings implements WorldSettings {
public void setMakeEndPortals(boolean makeEndPortals) {
this.makeEndPortals = makeEndPortals;
}
public Material getWaterBlock() {
return waterBlock;
}
public void setWaterBlock(Material waterBlock) {
this.waterBlock = waterBlock;
}
public Material getNetherWaterBlock() {
return netherWaterBlock;
}
public void setNetherWaterBlock(Material netherWaterBlock) {
this.netherWaterBlock = netherWaterBlock;
}
public Material getEndWaterBlock() {
return endWaterBlock;
}
public void setEndWaterBlock(Material endWaterBlock) {
this.endWaterBlock = endWaterBlock;
}
}

View File

@ -27,8 +27,10 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
private final AcidIsland addon;
private final Random rand = new Random();
private final Map<Environment, Integer> seaHeight = new EnumMap<>(Environment.class);
private final Map<Environment, WorldConfig> seaHeight = new EnumMap<>(Environment.class);
private final Map<Vector, Material> roofChunk = new HashMap<>();
private record WorldConfig(int seaHeight, Material waterBlock) {}
/**
* @param addon - addon
@ -36,17 +38,18 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
public ChunkGeneratorWorld(AcidIsland addon) {
super();
this.addon = addon;
seaHeight.put(Environment.NORMAL, addon.getSettings().getSeaHeight());
seaHeight.put(Environment.NETHER, addon.getSettings().getNetherSeaHeight());
seaHeight.put(Environment.THE_END, addon.getSettings().getEndSeaHeight());
seaHeight.put(Environment.NORMAL, new WorldConfig(addon.getSettings().getSeaHeight(), addon.getSettings().getWaterBlock()));
seaHeight.put(Environment.NETHER, new WorldConfig(addon.getSettings().getNetherSeaHeight(), addon.getSettings().getNetherWaterBlock()));
seaHeight.put(Environment.THE_END, new WorldConfig(addon.getSettings().getEndSeaHeight(), addon.getSettings().getEndWaterBlock()));
makeNetherRoof();
}
public ChunkData generateChunks(World world) {
ChunkData result = createChunkData(world);
int sh = seaHeight.getOrDefault(world.getEnvironment(), world.getMinHeight());
WorldConfig wc = seaHeight.get(world.getEnvironment());
int sh = wc.seaHeight();
if (sh > world.getMinHeight()) {
result.setRegion(0, world.getMinHeight(), 0, 16, sh + 1, 16, Material.WATER);
result.setRegion(0, world.getMinHeight(), 0, 16, sh + 1, 16, wc.waterBlock());
}
if (world.getEnvironment().equals(Environment.NETHER) && addon.getSettings().isNetherRoof()) {
roofChunk.forEach((k,v) -> result.setBlock(k.getBlockX(), world.getMaxHeight() + k.getBlockY(), k.getBlockZ(), v));

View File

@ -132,6 +132,10 @@ world:
# Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing Skyblock!
sea-height: 54
# Water block this should usually stay as WATER, but may be LAVA for fun
# Changing mid-game will cause problems!
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
water-block: WATER
# Maximum number of islands in the world. Set to -1 or 0 for unlimited.
# If the number of islands is greater than this number, no new island will be created.
max-islands: 0
@ -162,6 +166,10 @@ world:
# Changing mid-game will cause problems!
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
sea-height: 54
# Water block this should usually stay as WATER, but may be LAVA for fun
# Changing mid-game will cause problems!
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
water-block: WATER
# Make the nether roof, if false, there is nothing up there
# Change to false if lag is a problem from the generation
# Only applies to islands Nether
@ -186,6 +194,10 @@ world:
# Changing mid-game will cause problems!
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
sea-height: 54
# Water block this should usually stay as WATER, but may be LAVA for fun
# Changing mid-game will cause problems!
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
water-block: WATER
# This option indicates if obsidian platform in the end should be generated when player enters the end world.
# Added since 1.14.6
create-obsidian-platform: false

View File

@ -29,8 +29,8 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland;
/**
* @author tastybento
@ -48,7 +48,6 @@ public class ChunkGeneratorWorldTest {
private final Random random = new Random();
@Mock
private BiomeGrid biomeGrid;
@Mock
private AISettings settings;
@Mock
private ChunkData data;
@ -66,54 +65,79 @@ public class ChunkGeneratorWorldTest {
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
when(world.getMaxHeight()).thenReturn(256);
// Settings
settings = new AISettings();
when(addon.getSettings()).thenReturn(settings);
when(settings.getSeaHeight()).thenReturn(0);
when(settings.isNetherRoof()).thenReturn(true);
// Instance
cg = new ChunkGeneratorWorld(addon);
}
/**
*/
@After
public void tearDown() {
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldVoid() {
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldNormal() {
// Instance
cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(settings).getDefaultBiome();
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Sea height
verify(settings).getSeaHeight();
// Void
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
verify(cd).setRegion(0, 0, 0, 16, 55, 16, Material.WATER);
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldNormalVoid() {
settings.setSeaHeight(0);
// Instance
cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Void
verify(cd, never()).setRegion(anyInt(), anyInt(),anyInt(),anyInt(),anyInt(),anyInt(), any(Material.class));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldVoidLava() {
settings.setSeaHeight(54);
settings.setWaterBlock(Material.LAVA);
cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Void
verify(cd).setRegion(0, 0, 0, 16, 55, 16, Material.LAVA);
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldSea() {
// Set sea height
when(settings.getSeaHeight()).thenReturn(10);
settings.setSeaHeight(10);
// new instance
cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(settings).getDefaultBiome();
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Sea height
verify(settings, times(2)).getSeaHeight();
// Water. Blocks = 16 x 16 x 11 because block 0
verify(cd).setRegion(0, 0, 0, 16, 11, 16, Material.WATER);
}
@ -121,35 +145,34 @@ public class ChunkGeneratorWorldTest {
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridEnd() {
settings.setEndSeaHeight(0);
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.THE_END);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(settings).getDefaultEndBiome();
// Set biome in end
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Sea height
verify(settings).getSeaHeight();
// Void
verify(cd, never()).setRegion(anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), any(Material.class));
verify(cd, never()).setRegion(anyInt(), anyInt(),anyInt(),anyInt(),anyInt(),anyInt(), any(Material.class));
}
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherWithRoof() {
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Default biome
verify(settings).getDefaultNetherBiome();
// Nether roof check
verify(settings).isNetherRoof();
// Never set biome in nether
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Nether roof - at least bedrock layer
@ -159,17 +182,16 @@ public class ChunkGeneratorWorldTest {
/**
* Test method for {@link world.bentobox.bskyblock.generators.ChunkGeneratorWorld#generateChunkData(org.bukkit.World, java.util.Random, int, int, org.bukkit.generator.ChunkGenerator.BiomeGrid)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherNoRoof() {
when(settings.isNetherRoof()).thenReturn(false);
settings.setNetherRoof(false);
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd);
// Verifications
// Nether roof check
verify(settings).isNetherRoof();
// Nether roof check
verify(settings).isNetherRoof();
// Never set biome in nether
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Nether roof - at least bedrock layer
@ -181,6 +203,8 @@ public class ChunkGeneratorWorldTest {
*/
@Test
public void testCanSpawnWorldIntInt() {
// Instance
cg = new ChunkGeneratorWorld(addon);
assertTrue(cg.canSpawn(mock(World.class), 0, 1));
}
@ -189,6 +213,8 @@ public class ChunkGeneratorWorldTest {
*/
@Test
public void testGetDefaultPopulatorsWorld() {
// Instance
cg = new ChunkGeneratorWorld(addon);
assertTrue(cg.getDefaultPopulators(mock(World.class)).isEmpty());
}