mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2024-12-10 14:33:32 +01:00
Areas are now deleted from a world copy
The world is duplicated and the back-up copy is used to replace areas that are deleted. This is not as efficient as it could be right now, but it works. The main issue is that lighting updates do not occur due to NMS fast pasting, so dark areas can occur on the landscape.
This commit is contained in:
parent
df58768b2c
commit
f0806310ba
@ -16,6 +16,7 @@ import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand;
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.boxed.generators.BasicWorldGenerator;
|
||||
import world.bentobox.boxed.generators.DeleteGen;
|
||||
import world.bentobox.boxed.listeners.AdvancementListener;
|
||||
|
||||
/**
|
||||
@ -33,6 +34,7 @@ public class Boxed extends GameModeAddon {
|
||||
private ChunkGenerator chunkGenerator;
|
||||
private Config<Settings> configObject = new Config<>(this, Settings.class);
|
||||
private AdvancementsManager advManager;
|
||||
private DeleteGen delChunks;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -41,13 +43,12 @@ public class Boxed extends GameModeAddon {
|
||||
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||
loadSettings();
|
||||
// Chunk generator
|
||||
//chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
|
||||
WorldRef wordRef = WorldRef.ofName(getSettings().getWorldName());
|
||||
chunkGenerator = WorldGeneratorApi
|
||||
.getInstance(getPlugin(), 0, 5)
|
||||
.createCustomGenerator(wordRef, generator -> {
|
||||
// Set the noise generator
|
||||
generator.setBaseNoiseGenerator(new BasicWorldGenerator(this, wordRef));
|
||||
generator.setBaseNoiseGenerator(new BasicWorldGenerator(this, wordRef, getSettings().getSeed()));
|
||||
generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.SURFACE_STRUCTURES);
|
||||
generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS);
|
||||
});
|
||||
@ -86,6 +87,8 @@ public class Boxed extends GameModeAddon {
|
||||
//registerListener(new JoinListener(this));
|
||||
// Advancements manager
|
||||
advManager = new AdvancementsManager(this);
|
||||
// Get delete chunk generator
|
||||
delChunks = new DeleteGen(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,8 +147,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;
|
||||
WorldCreator wc = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env);
|
||||
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
|
||||
World w = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env).generator(chunkGenerator2).createWorld();
|
||||
// Backup world
|
||||
WorldCreator.name(worldName2 + "_bak").type(WorldType.FLAT).environment(env).generator(chunkGenerator2).createWorld();
|
||||
// Set spawn rates
|
||||
if (w != null) {
|
||||
if (getSettings().getSpawnLimitMonsters() > 0) {
|
||||
@ -178,6 +182,9 @@ public class Boxed extends GameModeAddon {
|
||||
|
||||
@Override
|
||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
if (id.equals("delete")) {
|
||||
return delChunks;
|
||||
}
|
||||
return chunkGenerator;
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,15 @@ public class Settings implements WorldSettings {
|
||||
@ConfigEntry(path = "world.world-name")
|
||||
private String worldName = "boxed_world";
|
||||
|
||||
@ConfigComment("World seed.")
|
||||
@ConfigComment("If you change this, stop the server and delete the worlds made.")
|
||||
@ConfigEntry(path = "world.seed", needsReset = true)
|
||||
private long seed = 978573758696L;
|
||||
|
||||
@ConfigComment("World difficulty setting - PEACEFUL, EASY, NORMAL, HARD")
|
||||
@ConfigComment("Other plugins may override this setting")
|
||||
@ConfigEntry(path = "world.difficulty")
|
||||
private Difficulty difficulty = Difficulty.PEACEFUL;
|
||||
private Difficulty difficulty = Difficulty.NORMAL;
|
||||
|
||||
@ConfigComment("Spawn limits. These override the limits set in bukkit.yml")
|
||||
@ConfigComment("If set to a negative number, the server defaults will be used")
|
||||
@ -1603,4 +1608,18 @@ public class Settings implements WorldSettings {
|
||||
public float getNoiseScaleHorizontal() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the seed
|
||||
*/
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param seed the seed to set
|
||||
*/
|
||||
public void setSeed(long seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ public class BasicWorldGenerator implements BaseNoiseGenerator {
|
||||
private final Boxed addon;
|
||||
|
||||
|
||||
public BasicWorldGenerator(Boxed addon, WorldRef world) {
|
||||
public BasicWorldGenerator(Boxed addon, WorldRef world, long seed) {
|
||||
this.addon = addon;
|
||||
// Initialize the noise generator based on the world seed
|
||||
this.mainNoiseGenerator = new SimplexNoiseGenerator(123456789L);
|
||||
this.mainNoiseGenerator = new SimplexNoiseGenerator(seed);
|
||||
}
|
||||
|
||||
|
||||
|
48
src/main/java/world/bentobox/boxed/generators/DeleteGen.java
Normal file
48
src/main/java/world/bentobox/boxed/generators/DeleteGen.java
Normal file
@ -0,0 +1,48 @@
|
||||
package world.bentobox.boxed.generators;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import world.bentobox.boxed.Boxed;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class DeleteGen extends ChunkGenerator {
|
||||
|
||||
private final Map<World, World> backMap;
|
||||
/**
|
||||
* @param addon
|
||||
*/
|
||||
public DeleteGen(Boxed addon) {
|
||||
backMap = new HashMap<>();
|
||||
backMap.put(addon.getOverWorld(), Bukkit.getWorld(addon.getOverWorld().getName() + "_bak"));
|
||||
backMap.put(addon.getNetherWorld(), Bukkit.getWorld(addon.getNetherWorld().getName() + "_bak"));
|
||||
backMap.put(addon.getEndWorld(), Bukkit.getWorld(addon.getEndWorld().getName() + "_bak"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||
ChunkData result = createChunkData(world);
|
||||
if (backMap.containsKey(world)) {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -34,7 +34,7 @@ public class AdvancementListener implements Listener {
|
||||
if (score != 0) {
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F);
|
||||
String adv = Util.prettifyText(e.getAdvancement().getKey().getKey().substring(e.getAdvancement().getKey().getKey().lastIndexOf("/"), e.getAdvancement().getKey().getKey().length()));
|
||||
String adv = Util.prettifyText(e.getAdvancement().getKey().getKey().substring(e.getAdvancement().getKey().getKey().lastIndexOf("/") + 1, e.getAdvancement().getKey().getKey().length()));
|
||||
user.sendMessage("boxed.completed", TextVariables.NAME, adv);
|
||||
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user