From 38b1a55d4595a61f84813c1a5e04bed8552fe8e2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 12 Nov 2021 08:26:11 -0800 Subject: [PATCH] Baseline world gen. Random. --- pom.xml | 7 ++- src/main/java/world/bentobox/boxed/Boxed.java | 19 ++++--- .../boxed/generators/BoxedChunkGenerator.java | 51 +++++++++++++++---- .../bentobox/boxed/generators/DeleteGen.java | 49 +++++++++++++----- .../boxed/generators/OverWorldGenerator.java | 24 +++++---- 5 files changed, 107 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index bc555c7..da33531 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.0.9 - 1.17-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT 1.18.0-SNAPSHOT ${build.version}-SNAPSHOT @@ -165,9 +165,8 @@ nl.rutgerkok worldgeneratorapi - 1.2.0 - provided + 1.3 + provided diff --git a/src/main/java/world/bentobox/boxed/Boxed.java b/src/main/java/world/bentobox/boxed/Boxed.java index 4846824..7af0b49 100644 --- a/src/main/java/world/bentobox/boxed/Boxed.java +++ b/src/main/java/world/bentobox/boxed/Boxed.java @@ -2,7 +2,6 @@ package world.bentobox.boxed; import java.util.Collections; -import org.bukkit.Bukkit; import org.bukkit.Difficulty; import org.bukkit.Material; import org.bukkit.World; @@ -63,26 +62,28 @@ public class Boxed extends GameModeAddon { // Save biomes this.saveResource("biomes.yml", false); // Check for WGAPI + /* if (isNoWGAPI()) { logError("WorldGeneratorAPI plugin is required."); logError("Download the correct one for your server from https://github.com/rutgerkok/WorldGeneratorApi/releases"); this.setState(State.DISABLED); return; } + */ // Chunk generator - chunkGenerator = new BoxedChunkGenerator(this).getGenerator(); - netherChunkGenerator = new BoxedChunkGenerator(this).getNetherGenerator(); + chunkGenerator = new BoxedChunkGenerator(this); + netherChunkGenerator = new BoxedChunkGenerator(this); // Register commands playerCommand = new DefaultPlayerCommand(this) {}; adminCommand = new DefaultAdminCommand(this) {}; } - + /* private boolean isNoWGAPI() { return Bukkit.getPluginManager().getPlugin("WorldGeneratorApi") == null; } - + */ private boolean loadSettings() { // Load settings again to get worlds settings = configObject.loadConfigObject(); @@ -98,10 +99,12 @@ public class Boxed extends GameModeAddon { @Override public void onEnable(){ // Disable in onEnable + /* if (isNoWGAPI()) { this.setState(State.DISABLED); return; } + */ // Check for recommended addons if (this.getPlugin().getAddonsManager().getAddonByName("Border").isEmpty()) { this.logWarning("Boxed normally requires the Border addon."); @@ -157,9 +160,11 @@ public class Boxed extends GameModeAddon { @Override public void createWorlds() { + /* if (isNoWGAPI()) { return; } + */ String worldName = settings.getWorldName().toLowerCase(); if (getServer().getWorld(worldName) == null) { log("Creating Boxed world ..."); @@ -194,9 +199,9 @@ public class Boxed extends GameModeAddon { // Set world name worldName2 = env.equals(World.Environment.NETHER) ? worldName2 + NETHER : worldName2; worldName2 = env.equals(World.Environment.THE_END) ? worldName2 + THE_END : worldName2; - World w = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env).generator(chunkGenerator2).seed(settings.getSeed()).createWorld(); + World w = WorldCreator.name(worldName2).environment(env).generator(chunkGenerator2).seed(settings.getSeed()).createWorld(); // Backup world - World b = WorldCreator.name(worldName2 + "_bak").type(WorldType.FLAT).environment(env).generator(chunkGenerator2).seed(settings.getSeed()).createWorld(); + World b = WorldCreator.name(worldName2 + "_bak").environment(env).generator(chunkGenerator2).seed(settings.getSeed()).createWorld(); b.setDifficulty(Difficulty.PEACEFUL); // No damage wanted in this world. // Set spawn rates if (w != null) { diff --git a/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java b/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java index abe6509..ef322cc 100644 --- a/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java +++ b/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java @@ -1,28 +1,58 @@ package world.bentobox.boxed.generators; -import org.bukkit.generator.ChunkGenerator; +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.WorldInfo; -import nl.rutgerkok.worldgeneratorapi.WorldGeneratorApi; -import nl.rutgerkok.worldgeneratorapi.WorldRef; -import nl.rutgerkok.worldgeneratorapi.decoration.DecorationType; import world.bentobox.boxed.Boxed; /** * @author tastybento * */ -public class BoxedChunkGenerator { +public class BoxedChunkGenerator extends ChunkGenerator { - private final WorldRef wordRef; + //private final WorldRef wordRef; private final Boxed addon; - private final WorldRef wordRefNether; + //private final WorldRef wordRefNether; public BoxedChunkGenerator(Boxed addon) { this.addon = addon; - wordRef = WorldRef.ofName(addon.getSettings().getWorldName()); - wordRefNether = WorldRef.ofName(addon.getSettings().getWorldName() + "_nether"); + //wordRef = WorldRef.ofName(addon.getSettings().getWorldName()); + //wordRefNether = WorldRef.ofName(addon.getSettings().getWorldName() + "_nether"); } + @Override + public boolean canSpawn(World world, int x, int z) + { + return true; + } + + @Override + public boolean shouldGenerateNoise() { + return true; + } + + @Override + public boolean shouldGenerateSurface() { + return true; + } + + @Override + public boolean shouldGenerateBedrock() { + return true; + } + + @Override + public boolean shouldGenerateCaves() { + return true; + } + + /* + @SuppressWarnings({ "removal", "deprecation" }) public ChunkGenerator getGenerator() { return WorldGeneratorApi .getInstance(addon.getPlugin(), 0, 5) @@ -39,6 +69,7 @@ public class BoxedChunkGenerator { }); } + @SuppressWarnings({ "removal", "deprecation" }) public ChunkGenerator getNetherGenerator() { return WorldGeneratorApi .getInstance(addon.getPlugin(), 0, 5) @@ -54,5 +85,5 @@ public class BoxedChunkGenerator { generator.setBiomeGenerator(new NetherBiomeGenerator(addon)); }); } - + */ } diff --git a/src/main/java/world/bentobox/boxed/generators/DeleteGen.java b/src/main/java/world/bentobox/boxed/generators/DeleteGen.java index bc60d68..4cb81b2 100644 --- a/src/main/java/world/bentobox/boxed/generators/DeleteGen.java +++ b/src/main/java/world/bentobox/boxed/generators/DeleteGen.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.WorldInfo; import world.bentobox.boxed.Boxed; @@ -17,33 +18,57 @@ import world.bentobox.boxed.Boxed; */ public class DeleteGen extends ChunkGenerator { - private final Map backMap; + private final Map backMap; /** * @param addon addon */ public DeleteGen(Boxed addon) { backMap = new HashMap<>(); - backMap.put(addon.getOverWorld(), Bukkit.getWorld(addon.getOverWorld().getName() + "_bak")); + backMap.put(addon.getOverWorld().getName(), Bukkit.getWorld(addon.getOverWorld().getName() + "_bak")); if (addon.getNetherWorld() != null) { - backMap.put(addon.getNetherWorld(), Bukkit.getWorld(addon.getNetherWorld().getName() + "_bak")); + backMap.put(addon.getNetherWorld().getName(), Bukkit.getWorld(addon.getNetherWorld().getName() + "_bak")); } } @Override - public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) { - ChunkData result = createChunkData(world); - if (backMap.containsKey(world)) { + public void generateSurface(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunkData) { + if (backMap.containsKey(worldInfo.getName())) { // Load the chunk from the back world - Chunk chunk = backMap.get(world).getChunkAt(chunkX, chunkZ); - for (int x = 0; x < 16; x++) { - for (int y = 0; y < world.getMaxHeight(); y++) { - for (int z = 0; z < 16; z++) { - result.setBlock(x, y, z, chunk.getBlock(x, y, z).getBlockData()); + Chunk chunk = backMap.get(worldInfo.getName()).getChunkAt(x, z); + for (int xx = 0; xx < 16; xx++) { + for (int y = 0; y < worldInfo.getMaxHeight(); y++) { + for (int zz = 0; zz < 16; zz++) { + chunkData.setBlock(xx, y, zz, chunk.getBlock(xx, y, zz).getBlockData()); } } } } - return result; + } + + @Override + public boolean canSpawn(World world, int x, int z) + { + return true; + } + + @Override + public boolean shouldGenerateNoise() { + return true; + } + + @Override + public boolean shouldGenerateSurface() { + return true; + } + + @Override + public boolean shouldGenerateBedrock() { + return true; + } + + @Override + public boolean shouldGenerateCaves() { + return true; } } diff --git a/src/main/java/world/bentobox/boxed/generators/OverWorldGenerator.java b/src/main/java/world/bentobox/boxed/generators/OverWorldGenerator.java index f3c8796..1fe8bf7 100644 --- a/src/main/java/world/bentobox/boxed/generators/OverWorldGenerator.java +++ b/src/main/java/world/bentobox/boxed/generators/OverWorldGenerator.java @@ -5,17 +5,18 @@ import java.io.File; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.generator.BiomeProvider; +import org.bukkit.generator.WorldInfo; import org.bukkit.util.noise.SimplexNoiseGenerator; -import nl.rutgerkok.worldgeneratorapi.BaseNoiseGenerator; -import nl.rutgerkok.worldgeneratorapi.BiomeGenerator; +import nl.rutgerkok.worldgeneratorapi.BaseNoiseProvider; import world.bentobox.boxed.Boxed; /** * @author tastybento * */ -public class OverWorldGenerator implements BaseNoiseGenerator { +public class OverWorldGenerator implements BaseNoiseProvider { private final SimplexNoiseGenerator mainNoiseGenerator; private final Boxed addon; @@ -35,29 +36,32 @@ public class OverWorldGenerator implements BaseNoiseGenerator { } @Override - public TerrainSettings getTerrainSettings() { - TerrainSettings ts = new TerrainSettings(); + public TerrainConfig getTerrainSettings() { + TerrainConfig ts = new TerrainConfig(); ts.stoneBlock = Material.STONE.createBlockData(); ts.waterBlock = Material.WATER.createBlockData(); return ts; } - @Override - public void getNoise(BiomeGenerator biomeGenerator, double[] buffer, int scaledX, int scaledZ) { + public void getNoise(WorldInfo worldInfo, double[] buffer, int scaledX, int scaledZ) { + BiomeProvider bp = addon.getPlugin().getDefaultBiomeProvider(worldInfo.getName(), ""); // Repeat on an island boundary int dist = addon.getSettings().getIslandDistance(); - Biome biome = biomeGenerator.getZoomedOutBiome(scaledX, scaledZ); + int blockX = scaledX * 4; + int blockZ = scaledZ * 4; + Biome biome = bp.getBiome(worldInfo, blockX, 63, blockZ); double noiseScaleHorizontal = config.getDouble("biomes." + biome.name() + ".scale", 10D); double height = config.getDouble("biomes." + biome.name() + ".height", 8D); - double x = ((((double)scaledX*4) % dist) / 4) / noiseScaleHorizontal; - double z = ((((double)scaledZ*4) % dist) / 4) / noiseScaleHorizontal; + double x = ((((double)blockX) % dist) / 4) / noiseScaleHorizontal; + double z = ((((double)blockZ) % dist) / 4) / noiseScaleHorizontal; for (int y = 0; y < buffer.length; y++) { double noise = this.mainNoiseGenerator.noise(x, y, z); double heightOffset = height - y; buffer[y] = noise + heightOffset; } + } } \ No newline at end of file