mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2024-11-15 10:25:22 +01:00
Baseline world gen. Random.
This commit is contained in:
parent
9e300914d4
commit
38b1a55d45
7
pom.xml
7
pom.xml
@ -58,7 +58,7 @@
|
||||
<!-- Non-minecraft related dependencies -->
|
||||
<powermock.version>2.0.9</powermock.version>
|
||||
<!-- More visible way how to change dependency versions -->
|
||||
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
|
||||
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>1.18.0-SNAPSHOT</bentobox.version>
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
@ -165,9 +165,8 @@
|
||||
<dependency>
|
||||
<groupId>nl.rutgerkok</groupId>
|
||||
<artifactId>worldgeneratorapi</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>provided</scope> <!-- Important, otherwise WorldGeneratorApi will be placed in your JAR file
|
||||
if you're using maven-shade-plugin -->
|
||||
<version>1.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
@ -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<World, World> backMap;
|
||||
private final Map<String, World> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user