From 2f209fcf373fb6b23ed1672193bac8b7dffd72fd Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 15 Aug 2021 15:26:42 -0700 Subject: [PATCH] Uses the new 1.17.1 ChunkGenerator options --- pom.xml | 11 +- .../world/bentobox/caveblock/CaveBlock.java | 2 - .../generators/ChunkGeneratorWorld.java | 253 +++++------------- .../bentobox/caveblock/generators/Ore.java | 7 + 4 files changed, 80 insertions(+), 193 deletions(-) create mode 100644 src/main/java/world/bentobox/caveblock/generators/Ore.java diff --git a/pom.xml b/pom.xml index f3d163f..257f4a6 100644 --- a/pom.xml +++ b/pom.xml @@ -43,14 +43,14 @@ UTF-8 UTF-8 - 1.8 + 16 - 1.16.4-R0.1-SNAPSHOT - 1.16.0 + 1.17.1-R0.1-SNAPSHOT + 1.17.0 ${build.version}-SNAPSHOT - 1.14.5 + 1.15.0 -LOCAL bentobox-world https://sonarcloud.io @@ -170,8 +170,7 @@ maven-compiler-plugin 3.7.0 - ${java.version} - ${java.version} + ${java.version} diff --git a/src/main/java/world/bentobox/caveblock/CaveBlock.java b/src/main/java/world/bentobox/caveblock/CaveBlock.java index d0e4cb4..70dc5e9 100644 --- a/src/main/java/world/bentobox/caveblock/CaveBlock.java +++ b/src/main/java/world/bentobox/caveblock/CaveBlock.java @@ -76,7 +76,6 @@ public class CaveBlock extends GameModeAddon { super.onReload(); this.loadSettings(); - this.chunkGenerator.reload(); } @@ -137,7 +136,6 @@ public class CaveBlock extends GameModeAddon // Create the world if it does not exist this.islandWorld = WorldCreator.name(worldName). - type(WorldType.FLAT). environment(World.Environment.NORMAL). generator(this.chunkGenerator). createWorld(); diff --git a/src/main/java/world/bentobox/caveblock/generators/ChunkGeneratorWorld.java b/src/main/java/world/bentobox/caveblock/generators/ChunkGeneratorWorld.java index 6b845df..86d7e1f 100644 --- a/src/main/java/world/bentobox/caveblock/generators/ChunkGeneratorWorld.java +++ b/src/main/java/world/bentobox/caveblock/generators/ChunkGeneratorWorld.java @@ -2,18 +2,19 @@ package world.bentobox.caveblock.generators; import java.util.ArrayList; +import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.Random; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; +import org.bukkit.World.Environment; 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.MaterialPopulator; /** @@ -24,6 +25,12 @@ import world.bentobox.caveblock.generators.populators.MaterialPopulator; */ public class ChunkGeneratorWorld extends ChunkGenerator { + private CaveBlock addon; + private Settings settings; + private Map map = new EnumMap<>(Environment.class); + private final Random r = new Random(); + private List ores = new ArrayList<>(); + // --------------------------------------------------------------------- // Section: Constructor // --------------------------------------------------------------------- @@ -38,7 +45,18 @@ public class ChunkGeneratorWorld extends ChunkGenerator this.addon = addon; this.settings = addon.getSettings(); - reload(); + ores.add(new Ore(0, 16, Material.TUFF,2)); + ores.add(new Ore(0, 79, Material.GRANITE,10)); + ores.add(new Ore(0, 79, Material.ANDESITE,10)); + ores.add(new Ore(0, 79, Material.DIORITE,10)); + ores.add(new Ore(95, 136, Material.COAL_ORE, 5)); + ores.add(new Ore(0, 96, Material.COPPER_ORE, 3)); + ores.add(new Ore(-64, 64, Material.LAPIS_ORE, 2)); + ores.add(new Ore(-64, 320, Material.IRON_ORE, 3)); + ores.add(new Ore(-64, 30, Material.GOLD_ORE, 3)); + ores.add(new Ore(-64, 16, Material.REDSTONE_ORE, 2)); + ores.add(new Ore(-64, 16, Material.DIAMOND_ORE, 1)); + ores.add(new Ore(32, 320, Material.EMERALD_ORE, 2)); } @@ -46,7 +64,42 @@ public class ChunkGeneratorWorld extends ChunkGenerator // Section: Methods // --------------------------------------------------------------------- + @SuppressWarnings("deprecation") + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { + //BentoBox.getInstance().logDebug("Generate Chunk Data " + x + " " + z); + return createChunkData(world); + } + @Override + public void generateNoise(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunkData) { + //BentoBox.getInstance().logDebug("Generate Noise " + x + " " + z + " " + chunkData); + chunkData.setRegion(0, worldInfo.getMinHeight(), 0, 16, worldInfo.getMaxHeight(), 16, Material.STONE); + chunkData.setRegion(0, worldInfo.getMinHeight(), 0, 16, 7, 16, Material.DEEPSLATE); + // Generate ores + for (int y = worldInfo.getMinHeight(); y < worldInfo.getMaxHeight(); y++) { + for (Ore o: ores) { + if (o.minY() < y && o.maxY() > y && r.nextInt(30) < o.chance()) { + chunkData.setBlock(r.nextInt(16), y, r.nextInt(16), o.material()); + break; + } + } + } + } + + @Override + public void generateSurface(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunkData) { + //BentoBox.getInstance().logDebug("generateSurface " + x + " " + z + " " + chunkData); + } + + @Override + public void generateBedrock(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunkData) { + //BentoBox.getInstance().logDebug("generateBedrock " + x + " " + z + " " + chunkData); + } + @Override + public void generateCaves(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunkData) { + //BentoBox.getInstance().logDebug("generateCaves " + x + " " + z + " " + chunkData); + } /** * This method sets if given coordinates can be set as spawn location */ @@ -56,196 +109,26 @@ public class ChunkGeneratorWorld extends ChunkGenerator return true; } - - /** - * This method generates given chunk. - * @param world World where chunk must be generated. - * @param random Random that allows define object randomness. - * @param chunkX Chunk X coordinate. - * @param chunkZ Chunk Z coordinate. - * @param biomeGrid BiomeGrid that contains biomes. - * @return new ChunkData for given chunk. - */ @Override - public ChunkData generateChunkData(World world, - Random random, - int chunkX, - int chunkZ, - ChunkGenerator.BiomeGrid biomeGrid) - { - ChunkData result = this.createChunkData(world); - - // Populate chunk with necessary information - if (world.getEnvironment().equals(World.Environment.NETHER)) - { - this.populateNetherChunk(world, result, biomeGrid); - } - else if (world.getEnvironment().equals(World.Environment.THE_END)) - { - this.populateTheEndChunk(world, result, biomeGrid); - } - else - { - this.populateOverWorldChunk(world, result, biomeGrid); - } - - return result; + public boolean shouldGenerateNoise() { + return false; } - - /** - * This method populates The End world chunk data. - * @param world world where chunks are generated. - * @param chunkData ChunkData that must be populated. - * @param biomeGrid BiomeGrid for this chunk. - */ - private void populateTheEndChunk(World world, ChunkData chunkData, BiomeGrid biomeGrid) - { - // because everything starts at 0 and ends at 255 - final int worldHeight = this.settings.getWorldDepth(); - - // Fill all blocks - chunkData.setRegion(0, 1, 0, - 16, worldHeight - 1, 16, - this.settings.getEndMainBlock()); - - // Generate ground and ceiling. - chunkData.setRegion(0, 0, 0, - 16, 1, 16, - this.settings.isEndFloor() ? Material.BEDROCK : this.settings.getEndMainBlock()); - chunkData.setRegion(0, worldHeight - 1, 0, - 16, worldHeight, 16, - this.settings.isEndRoof() ? Material.BEDROCK : this.settings.getEndMainBlock()); - - // Set biome - for (int x = 0; x < 16; x += 4) - { - for (int y = 0; y < world.getMaxHeight(); y += 4) - { - for (int z = 0; z < 16; z += 4) - { - biomeGrid.setBiome(x, y, z, this.settings.getDefaultTheEndBiome()); - } - } - } - } - - - /** - * This method populates nether world chunk data. - * @param world world where chunks are generated. - * @param chunkData ChunkData that must be populated. - * @param biomeGrid BiomeGrid for this chunk. - */ - private void populateNetherChunk(World world, ChunkData chunkData, BiomeGrid biomeGrid) - { - // because everything starts at 0 and ends at 255 - final int worldHeight = this.settings.getWorldDepth(); - - // Fill all blocks - chunkData.setRegion(0, 1, 0, - 16, worldHeight - 1, 16, - this.settings.getNetherMainBlock()); - - // Generate ground and ceiling. - chunkData.setRegion(0, 0, 0, - 16, 1, 16, - this.settings.isNetherFloor() ? Material.BEDROCK : this.settings.getNetherMainBlock()); - chunkData.setRegion(0, worldHeight - 1, 0, - 16, worldHeight, 16, - this.settings.isNetherRoof() ? Material.BEDROCK : this.settings.getNetherMainBlock()); - - // Set biome - for (int x = 0; x < 16; x += 4) - { - for (int y = 0; y < world.getMaxHeight(); y += 4) - { - for (int z = 0; z < 16; z += 4) - { - biomeGrid.setBiome(x, y, z, this.settings.getDefaultNetherBiome()); - } - } - } - } - - - /** - * This method populates Over world chunk data. - * @param world world where chunks are generated. - * @param chunkData ChunkData that must be populated. - * @param biomeGrid BiomeGrid for this chunk. - */ - private void populateOverWorldChunk(World world, ChunkData chunkData, BiomeGrid biomeGrid) - { - // because everything starts at 0 and ends at 255 - final int worldHeight = this.settings.getWorldDepth(); - - // Fill all blocks - chunkData.setRegion(0, 1, 0, - 16, worldHeight - 1, 16, - this.settings.getNormalMainBlock()); - - // Generate ground and ceiling. - chunkData.setRegion(0, 0, 0, - 16, 1, 16, - this.settings.isNormalFloor() ? Material.BEDROCK : this.settings.getNormalMainBlock()); - chunkData.setRegion(0, worldHeight - 1, 0, - 16, worldHeight, 16, - this.settings.isNormalRoof() ? Material.BEDROCK : this.settings.getNormalMainBlock()); - - // Set biome - for (int x = 0; x < 16; x += 4) - { - for (int y = 0; y < world.getMaxHeight(); y += 4) - { - for (int z = 0; z < 16; z += 4) - { - biomeGrid.setBiome(x, y, z, this.settings.getDefaultBiome()); - } - } - } - } - - - /** - * This method set world block populators. - * @param world World where this must apply. - * @return List with block populators. - */ @Override - public List getDefaultPopulators(final World world) - { - return this.blockPopulators; + public boolean shouldGenerateSurface() { + return true; } - /** - * Called when config is reloaded - */ - public void reload() { - this.blockPopulators = new ArrayList<>(2); - - this.blockPopulators.add(new MaterialPopulator(this.addon)); - this.blockPopulators.add(new EntitiesPopulator(this.addon)); - + @Override + public boolean shouldGenerateBedrock() { + return true; } - // --------------------------------------------------------------------- - // Section: Variables - // --------------------------------------------------------------------- + @Override + public boolean shouldGenerateCaves() { + return true; + } - /** - * CaveBlock addon. - */ - private CaveBlock addon; - /** - * Addon settings. - */ - private Settings settings; - - /** - * This list contains block populators that will be applied after chunk is generated. - */ - private List blockPopulators; } diff --git a/src/main/java/world/bentobox/caveblock/generators/Ore.java b/src/main/java/world/bentobox/caveblock/generators/Ore.java new file mode 100644 index 0000000..a89abbb --- /dev/null +++ b/src/main/java/world/bentobox/caveblock/generators/Ore.java @@ -0,0 +1,7 @@ +package world.bentobox.caveblock.generators; + +import org.bukkit.Material; + +public record Ore (int minY, int maxY, Material material, int chance){ + +}