Skip to content

Commit

Permalink
Release 1.16.0 (#81)
Browse files Browse the repository at this point in the history
* Fixes a 1.18 world generator bug where it generated dirt-grass layers.

Expose 3 world generator options for overworld:
- natural-surface - generates surface that is natural(-ish). Currently, it may be just grass and dirt layers.
- natural-caves - generates caves inside world.
- natural-bedrock - generates natural looking bedrock pattern.

This also fixes a bug with floor and roof config option not working properly.

Fixes BentoBoxWorld/Level#258

* Fixes issue when ores were not generated in correct form. #77
  • Loading branch information
BONNe authored May 17, 2022
1 parent e6e3c97 commit 0cbb775
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 123 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.15.0</build.version>
<build.version>1.16.0</build.version>
<build.number>-LOCAL</build.number>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down
37 changes: 30 additions & 7 deletions src/main/java/world/bentobox/caveblock/CaveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public void onLoad()
this.saveDefaultConfig();
this.loadSettings();

this.chunkGenerator = new ChunkGeneratorWorld(this);
this.chunkNormalGenerator = new ChunkGeneratorWorld(this, World.Environment.NORMAL);
this.chunkNetherGenerator = new ChunkGeneratorWorld(this, World.Environment.NETHER);
this.chunkEndGenerator = new ChunkGeneratorWorld(this, World.Environment.THE_END);

// Player Command
this.playerCommand = new DefaultPlayerCommand(this)
Expand Down Expand Up @@ -137,7 +139,7 @@ public void createWorlds()
// Create the world if it does not exist
this.islandWorld = WorldCreator.name(worldName).
environment(World.Environment.NORMAL).
generator(this.chunkGenerator).
generator(this.chunkNormalGenerator).
createWorld();
// Set spawn rates
setSpawnRates(islandWorld);
Expand All @@ -162,7 +164,7 @@ public void createWorlds()
{
this.netherWorld = WorldCreator.name(worldName + NETHER).
type(WorldType.FLAT).
generator(this.chunkGenerator).
generator(this.chunkNetherGenerator).
environment(World.Environment.NETHER).
createWorld();
}
Expand All @@ -187,7 +189,7 @@ public void createWorlds()
{
this.endWorld = WorldCreator.name(worldName + THE_END).
type(WorldType.FLAT).
generator(this.chunkGenerator).
generator(this.chunkEndGenerator).
environment(World.Environment.THE_END).
createWorld();
}
Expand Down Expand Up @@ -232,7 +234,18 @@ private void setSpawnRates(World w) {
@Override
public @NonNull ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
{
return this.chunkGenerator;
if (worldName.endsWith("_nether"))
{
return this.chunkNetherGenerator;
}
else if (worldName.endsWith("_the_end"))
{
return this.chunkEndGenerator;
}
else
{
return this.chunkNormalGenerator;
}
}

// ---------------------------------------------------------------------
Expand Down Expand Up @@ -284,9 +297,19 @@ public void saveWorldSettings()
private Settings settings;

/**
* This stores CaveBlock addon WorldGenerator.
* This stores CaveBlock addon WorldGenerator for overworld.
*/
private ChunkGeneratorWorld chunkNormalGenerator;

/**
* This stores CaveBlock addon WorldGenerator for the nether.
*/
private ChunkGeneratorWorld chunkNetherGenerator;

/**
* This stores CaveBlock addon WorldGenerator for the end.
*/
private ChunkGeneratorWorld chunkGenerator;
private ChunkGeneratorWorld chunkEndGenerator;


// ---------------------------------------------------------------------
Expand Down
94 changes: 90 additions & 4 deletions src/main/java/world/bentobox/caveblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,72 @@ public void setOnRespawnCommands(List<String> onRespawnCommands)
}


/**
* Is generate caves boolean.
*
* @return the boolean
*/
public boolean isGenerateCaves()
{
return generateCaves;
}


/**
* Sets generate caves.
*
* @param generateCaves the generate caves
*/
public void setGenerateCaves(boolean generateCaves)
{
this.generateCaves = generateCaves;
}


/**
* Is generate natural bedrock boolean.
*
* @return the boolean
*/
public boolean isGenerateNaturalBedrock()
{
return generateNaturalBedrock;
}


/**
* Sets generate natural bedrock.
*
* @param generateNaturalBedrock the generate natural bedrock
*/
public void setGenerateNaturalBedrock(boolean generateNaturalBedrock)
{
this.generateNaturalBedrock = generateNaturalBedrock;
}


/**
* Is generate natural surface boolean.
*
* @return the boolean
*/
public boolean isGenerateNaturalSurface()
{
return generateNaturalSurface;
}


/**
* Sets generate natural surface.
*
* @param generateNaturalSurface the generate natural surface
*/
public void setGenerateNaturalSurface(boolean generateNaturalSurface)
{
this.generateNaturalSurface = generateNaturalSurface;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -2196,8 +2262,8 @@ public void setOnRespawnCommands(List<String> onRespawnCommands)
private int banLimit = -1;

@ConfigComment("")
@ConfigComment("This is cave.. no height... only depth. Max 256.")
@ConfigComment("Should not be less then cave height.")
@ConfigComment("This is cave.. no height... only depth. If depth is set smaller than maximal world height, then area above will be empty.")
@ConfigComment("Should not be less than cave height.")
@ConfigEntry(path = "world.world-depth", needsReset = true)
private int worldDepth = 256;

Expand All @@ -2212,14 +2278,34 @@ public void setOnRespawnCommands(List<String> onRespawnCommands)
private boolean newMaterialGenerator = false;

@ConfigComment("")
@ConfigComment("Make over world roof of bedrock, if false, it will be made from stone")
@ConfigComment("Make over world roof of bedrock, if false, it will be made from stone.")
@ConfigEntry(path = "world.normal.roof", needsReset = true)
private boolean normalRoof = true;

@ConfigComment("Make over world floor of bedrock, if false, it will be made from stone")
@ConfigComment("")
@ConfigComment("Option allows to toggle if world generator should generate natural(-ish) looking surface with dirt and grass blocks.")
@ConfigComment("Enabling this option will ignore roof setting.")
@ConfigComment("Default value is false.")
@ConfigEntry(path = "world.normal.natural-surface", needsReset = true, experimental = true)
private boolean generateNaturalSurface = false;

@ConfigComment("")
@ConfigComment("Option allows to toggle if world generator should generate natural looking caves.")
@ConfigComment("Default value is false.")
@ConfigEntry(path = "world.normal.natural-caves", needsReset = true)
private boolean generateCaves = false;

@ConfigComment("Make over world floor of bedrock, if false, it will be made from stone.")
@ConfigEntry(path = "world.normal.floor", needsReset = true)
private boolean normalFloor = true;

@ConfigComment("")
@ConfigComment("Option allows to toggle if world generator should generate natural looking bedrock block patterns.")
@ConfigComment("Enabling this option will ignore floor setting.")
@ConfigComment("Default value is false.")
@ConfigEntry(path = "world.normal.natural-bedrock", needsReset = true)
private boolean generateNaturalBedrock = false;

@ConfigComment("Main block of which world will be generated.")
@ConfigEntry(path = "world.normal.main-block", needsReset = true)
private Material normalMainBlock = Material.STONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;

import world.bentobox.caveblock.CaveBlock;
import world.bentobox.caveblock.Settings;
import world.bentobox.caveblock.generators.populators.EntitiesPopulator;
import world.bentobox.caveblock.generators.populators.FlatBiomeProvider;
import world.bentobox.caveblock.generators.populators.MaterialPopulator;
import world.bentobox.caveblock.generators.populators.NewMaterialPopulator;
import world.bentobox.caveblock.generators.populators.*;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,6 +29,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
private final CaveBlock addon;
private final Settings settings;
private final List<BlockPopulator> blockPopulators;
private final World.Environment environment;
private BiomeProvider biomeProvider;
private boolean isNewGenerator;

Expand All @@ -40,27 +39,39 @@ public class ChunkGeneratorWorld extends ChunkGenerator {

/**
* @param addon - CaveBlock object
* @param environment - World environment
*/
public ChunkGeneratorWorld(CaveBlock addon) {
public ChunkGeneratorWorld(CaveBlock addon, World.Environment environment) {
this.addon = addon;
this.settings = addon.getSettings();
this.blockPopulators = new ArrayList<>(2);

this.environment = environment;
reload();
}

// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------

private Material getGroundCeilMaterial(World.Environment environment) {
private Material getGroundRoofMaterial(World.Environment environment) {
return switch (environment) {
case NETHER -> this.settings.isNetherRoof() ? Material.BEDROCK : this.settings.getNetherMainBlock();
case THE_END -> this.settings.isEndRoof() ? Material.BEDROCK : this.settings.getEndMainBlock();
default -> this.settings.isNormalRoof() ? Material.BEDROCK : this.settings.getNormalMainBlock();
};
}


private Material getGroundFloorMaterial(World.Environment environment) {
return switch (environment) {
case NETHER -> this.settings.isNetherFloor() ? Material.BEDROCK : this.settings.getNetherMainBlock();
case THE_END -> this.settings.isEndFloor() ? Material.BEDROCK : this.settings.getEndMainBlock();
default -> this.settings.isNormalFloor() ? Material.BEDROCK : this.settings.getNormalMainBlock();
};
}


private Material getBaseMaterial(World.Environment environment) {
return switch (environment) {
case NETHER -> this.settings.getNetherMainBlock();
Expand All @@ -70,19 +81,35 @@ private Material getBaseMaterial(World.Environment environment) {
}

@Override
public void generateBedrock(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, ChunkData chunkData) {
final int minHeight = worldInfo.getMinHeight();
Material material = getGroundCeilMaterial(worldInfo.getEnvironment());
chunkData.setRegion(0, minHeight, 0, 16, minHeight + 1, 16, material);
public void generateBedrock(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, ChunkData chunkData)
{
if (!this.shouldGenerateBedrock())
{
final int minHeight = worldInfo.getMinHeight();
Material material = this.getGroundFloorMaterial(worldInfo.getEnvironment());
chunkData.setRegion(0, minHeight, 0, 16, minHeight + 1, 16, material);
}
else
{
// Apparently default surface generation does not include 0 bedrock layer.
final int minHeight = worldInfo.getMinHeight();
chunkData.setRegion(0, minHeight, 0, 16, minHeight + 1, 16, Material.BEDROCK);
}
}


@Override
public void generateSurface(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, ChunkData chunkData) {
final int worldHeight = Math.min(worldInfo.getMaxHeight(), this.settings.getWorldDepth());
Material material = getGroundCeilMaterial(worldInfo.getEnvironment());
chunkData.setRegion(0, worldHeight - 1, 0, 16, worldHeight, 16, material);
public void generateSurface(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, ChunkData chunkData)
{
if (!this.shouldGenerateSurface())
{
final int worldHeight = Math.min(worldInfo.getMaxHeight(), this.settings.getWorldDepth());
Material material = this.getGroundRoofMaterial(worldInfo.getEnvironment());
chunkData.setRegion(0, worldHeight - 1, 0, 16, worldHeight, 16, material);
}
}


@Override
public void generateNoise(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, ChunkData chunkData) {
final int minHeight = worldInfo.getMinHeight();
Expand Down Expand Up @@ -127,18 +154,22 @@ public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) {
}

@Override
public boolean shouldGenerateSurface() {
return true;
public boolean shouldGenerateSurface()
{
// Surface generation should happen only in overworld. Nether and end worlds does not have surface.
return this.environment.equals(World.Environment.NORMAL) && this.settings.isGenerateNaturalSurface();
}

@Override
public boolean shouldGenerateBedrock() {
return true;
// Bedrock generation should happen only in overworld. Nether and end worlds does not have nice bedrock layers.
return this.environment.equals(World.Environment.NORMAL) && this.settings.isGenerateNaturalBedrock();
}

@Override
public boolean shouldGenerateCaves() {
return this.isNewGenerator;
// Cave generation should happen only in overworld. Nether and end worlds does not have nice cave layers.
return this.environment.equals(World.Environment.NORMAL) && this.settings.isGenerateCaves();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ public class NewMaterialPopulator extends BlockPopulator {
Map<World.Environment, List<Ore>> ores = new EnumMap<>(World.Environment.class);
// Source https://minecraft.fandom.com/wiki/Blob
List<Ore> worldOres = new ArrayList<>();
worldOres.add(new Ore(-64, 16, Material.DIAMOND_ORE, 1, 10, true));
worldOres.add(new Ore(-64, 64, Material.LAPIS_ORE, 1, 7, true));
worldOres.add(new Ore(-64, 30, Material.GOLD_ORE, 2, 9, true));
worldOres.add(new Ore(-64, 7, Material.DEEPSLATE_DIAMOND_ORE, 1, 10, true));
worldOres.add(new Ore(7, 16, Material.DIAMOND_ORE, 1, 10, true));
worldOres.add(new Ore(-64, 7, Material.DEEPSLATE_LAPIS_ORE, 1, 7, true));
worldOres.add(new Ore(7, 64, Material.LAPIS_ORE, 1, 7, true));
worldOres.add(new Ore(-64, 7, Material.DEEPSLATE_GOLD_ORE, 2, 9, true));
worldOres.add(new Ore(7, 30, Material.GOLD_ORE, 2, 9, true));
worldOres.add(new Ore(0, 16, Material.TUFF, 2, 33, false));
worldOres.add(new Ore(-64, 16, Material.REDSTONE_ORE, 8, 8, true));
worldOres.add(new Ore(-64, 7, Material.DEEPSLATE_REDSTONE_ORE, 8, 8, true));
worldOres.add(new Ore(7, 16, Material.REDSTONE_ORE, 8, 8, true));
worldOres.add(new Ore(0, 16, Material.GRAVEL, 8, 33, false));
worldOres.add(new Ore(0, 79, Material.GRANITE, 5, 33, false));
worldOres.add(new Ore(0, 79, Material.ANDESITE, 5, 33, false));
worldOres.add(new Ore(0, 79, Material.DIORITE, 5, 33, false));
worldOres.add(new Ore(32, 320, Material.EMERALD_ORE, 11, 1, true));
worldOres.add(new Ore(95, 136, Material.COAL_ORE, 20, 17, false));
worldOres.add(new Ore(0, 96, Material.COPPER_ORE, 20, 9, true));
worldOres.add(new Ore(-64, 320, Material.IRON_ORE, 20, 9, true));
worldOres.add(new Ore(0, 7, Material.DEEPSLATE_COPPER_ORE, 20, 9, true));
worldOres.add(new Ore(7, 96, Material.COPPER_ORE, 20, 9, true));
worldOres.add(new Ore(-64, 7, Material.DEEPSLATE_IRON_ORE, 20, 9, true));
worldOres.add(new Ore(7, 320, Material.IRON_ORE, 20, 9, true));
worldOres.add(new Ore(-64, 320, Material.CAVE_AIR, 8, 33, false));
ores.put(World.Environment.NORMAL, worldOres);
List<Ore> netherOres = new ArrayList<>();
Expand Down
Loading

0 comments on commit 0cbb775

Please sign in to comment.