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.Difficulty;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffectType; 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.") @ConfigComment("It is the y coordinate of the bedrock block in the schem.")
@ConfigEntry(path = "world.island-height") @ConfigEntry(path = "world.island-height")
private int islandHeight = 50; private int islandHeight = 50;
@ConfigComment("Use your own world generator for this world.") @ConfigComment("Use your own world generator for this world.")
@ConfigComment("In this case, the plugin will not generate anything.") @ConfigComment("In this case, the plugin will not generate anything.")
@ConfigEntry(path = "world.use-own-generator", experimental = true) @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!") @ConfigComment("Minimum is 0, which means you are playing Skyblock!")
@ConfigEntry(path = "world.sea-height") @ConfigEntry(path = "world.sea-height")
private int seaHeight = 54; 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("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.") @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!") @ConfigComment("Changing mid-game will cause problems!")
@ConfigEntry(path = "world.nether.sea-height", needsReset = true) @ConfigEntry(path = "world.nether.sea-height", needsReset = true)
private int netherSeaHeight = 54; 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("Make the nether roof, if false, there is nothing up there")
@ConfigComment("Change to false if lag is a problem from the generation") @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!") @ConfigComment("Changing mid-game will cause problems!")
@ConfigEntry(path = "world.end.sea-height", needsReset = true) @ConfigEntry(path = "world.end.sea-height", needsReset = true)
private int endSeaHeight = 54; 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("This option indicates if obsidian platform in the end should be generated")
@ConfigComment("when player enters the end world.") @ConfigComment("when player enters the end world.")
@ -1960,4 +1973,22 @@ public class AISettings implements WorldSettings {
public void setMakeEndPortals(boolean makeEndPortals) { public void setMakeEndPortals(boolean makeEndPortals) {
this.makeEndPortals = 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 AcidIsland addon;
private final Random rand = new Random(); 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 final Map<Vector, Material> roofChunk = new HashMap<>();
private record WorldConfig(int seaHeight, Material waterBlock) {}
/** /**
* @param addon - addon * @param addon - addon
@ -36,17 +38,18 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
public ChunkGeneratorWorld(AcidIsland addon) { public ChunkGeneratorWorld(AcidIsland addon) {
super(); super();
this.addon = addon; this.addon = addon;
seaHeight.put(Environment.NORMAL, addon.getSettings().getSeaHeight()); seaHeight.put(Environment.NORMAL, new WorldConfig(addon.getSettings().getSeaHeight(), addon.getSettings().getWaterBlock()));
seaHeight.put(Environment.NETHER, addon.getSettings().getNetherSeaHeight()); seaHeight.put(Environment.NETHER, new WorldConfig(addon.getSettings().getNetherSeaHeight(), addon.getSettings().getNetherWaterBlock()));
seaHeight.put(Environment.THE_END, addon.getSettings().getEndSeaHeight()); seaHeight.put(Environment.THE_END, new WorldConfig(addon.getSettings().getEndSeaHeight(), addon.getSettings().getEndWaterBlock()));
makeNetherRoof(); makeNetherRoof();
} }
public ChunkData generateChunks(World world) { public ChunkData generateChunks(World world) {
ChunkData result = createChunkData(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()) { 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()) { if (world.getEnvironment().equals(Environment.NETHER) && addon.getSettings().isNetherRoof()) {
roofChunk.forEach((k,v) -> result.setBlock(k.getBlockX(), world.getMaxHeight() + k.getBlockY(), k.getBlockZ(), v)); 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) # Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing Skyblock! # Minimum is 0, which means you are playing Skyblock!
sea-height: 54 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. # 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. # If the number of islands is greater than this number, no new island will be created.
max-islands: 0 max-islands: 0
@ -162,6 +166,10 @@ world:
# Changing mid-game will cause problems! # 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. # /!\ 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 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 # Make the nether roof, if false, there is nothing up there
# Change to false if lag is a problem from the generation # Change to false if lag is a problem from the generation
# Only applies to islands Nether # Only applies to islands Nether
@ -186,6 +194,10 @@ world:
# Changing mid-game will cause problems! # 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. # /!\ 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 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. # This option indicates if obsidian platform in the end should be generated when player enters the end world.
# Added since 1.14.6 # Added since 1.14.6
create-obsidian-platform: false 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.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland;
/** /**
* @author tastybento * @author tastybento
@ -48,7 +48,6 @@ public class ChunkGeneratorWorldTest {
private final Random random = new Random(); private final Random random = new Random();
@Mock @Mock
private BiomeGrid biomeGrid; private BiomeGrid biomeGrid;
@Mock
private AISettings settings; private AISettings settings;
@Mock @Mock
private ChunkData data; private ChunkData data;
@ -66,54 +65,79 @@ public class ChunkGeneratorWorldTest {
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL); when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
when(world.getMaxHeight()).thenReturn(256); when(world.getMaxHeight()).thenReturn(256);
// Settings // Settings
settings = new AISettings();
when(addon.getSettings()).thenReturn(settings); 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)}. * 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 @Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldVoid() { public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldNormal() {
// Instance
cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid); ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd); assertEquals(data, cd);
// Verifications // Verifications
// Default biome // Default biome
verify(settings).getDefaultBiome();
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any()); verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Sea height
verify(settings).getSeaHeight();
// Void // 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)}. * 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 @Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldSea() { public void testGenerateChunkDataWorldRandomIntIntBiomeGridOverworldSea() {
// Set sea height // Set sea height
when(settings.getSeaHeight()).thenReturn(10); settings.setSeaHeight(10);
// new instance // new instance
cg = new ChunkGeneratorWorld(addon); cg = new ChunkGeneratorWorld(addon);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid); ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd); assertEquals(data, cd);
// Verifications // Verifications
// Default biome // Default biome
verify(settings).getDefaultBiome();
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any()); 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 // Water. Blocks = 16 x 16 x 11 because block 0
verify(cd).setRegion(0, 0, 0, 16, 11, 16, Material.WATER); 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)}. * 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 @Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridEnd() { public void testGenerateChunkDataWorldRandomIntIntBiomeGridEnd() {
settings.setEndSeaHeight(0);
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.THE_END); when(world.getEnvironment()).thenReturn(World.Environment.THE_END);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid); ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd); assertEquals(data, cd);
// Verifications // Verifications
// Default biome
verify(settings).getDefaultEndBiome();
// Set biome in end // Set biome in end
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any()); verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Sea height
verify(settings).getSeaHeight();
// Void // 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)}. * 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 @Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherWithRoof() { public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherWithRoof() {
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.NETHER); when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid); ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd); assertEquals(data, cd);
// Verifications // Verifications
// Default biome
verify(settings).getDefaultNetherBiome();
// Nether roof check
verify(settings).isNetherRoof();
// Never set biome in nether // Never set biome in nether
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any()); verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Nether roof - at least bedrock layer // 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)}. * 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 @Test
public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherNoRoof() { public void testGenerateChunkDataWorldRandomIntIntBiomeGridNetherNoRoof() {
when(settings.isNetherRoof()).thenReturn(false); settings.setNetherRoof(false);
// Instance
cg = new ChunkGeneratorWorld(addon);
when(world.getEnvironment()).thenReturn(World.Environment.NETHER); when(world.getEnvironment()).thenReturn(World.Environment.NETHER);
ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid); ChunkData cd = cg.generateChunkData(world, random, 0 , 0 , biomeGrid);
assertEquals(data, cd); assertEquals(data, cd);
// Verifications // Verifications
// Nether roof check
verify(settings).isNetherRoof();
// Nether roof check
verify(settings).isNetherRoof();
// Never set biome in nether // Never set biome in nether
verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any()); verify(biomeGrid, times(1024)).setBiome(anyInt(), anyInt(), anyInt(), any());
// Nether roof - at least bedrock layer // Nether roof - at least bedrock layer
@ -181,6 +203,8 @@ public class ChunkGeneratorWorldTest {
*/ */
@Test @Test
public void testCanSpawnWorldIntInt() { public void testCanSpawnWorldIntInt() {
// Instance
cg = new ChunkGeneratorWorld(addon);
assertTrue(cg.canSpawn(mock(World.class), 0, 1)); assertTrue(cg.canSpawn(mock(World.class), 0, 1));
} }
@ -189,6 +213,8 @@ public class ChunkGeneratorWorldTest {
*/ */
@Test @Test
public void testGetDefaultPopulatorsWorld() { public void testGetDefaultPopulatorsWorld() {
// Instance
cg = new ChunkGeneratorWorld(addon);
assertTrue(cg.getDefaultPopulators(mock(World.class)).isEmpty()); assertTrue(cg.getDefaultPopulators(mock(World.class)).isEmpty());
} }