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:
tastybento 2021-02-05 19:13:26 -08:00
parent df58768b2c
commit f0806310ba
5 changed files with 82 additions and 8 deletions

View File

@ -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.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.boxed.generators.BasicWorldGenerator; import world.bentobox.boxed.generators.BasicWorldGenerator;
import world.bentobox.boxed.generators.DeleteGen;
import world.bentobox.boxed.listeners.AdvancementListener; import world.bentobox.boxed.listeners.AdvancementListener;
/** /**
@ -33,6 +34,7 @@ public class Boxed extends GameModeAddon {
private ChunkGenerator chunkGenerator; private ChunkGenerator chunkGenerator;
private Config<Settings> configObject = new Config<>(this, Settings.class); private Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager; private AdvancementsManager advManager;
private DeleteGen delChunks;
@Override @Override
public void onLoad() { 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. // Load settings from config.yml. This will check if there are any issues with it too.
loadSettings(); loadSettings();
// Chunk generator // Chunk generator
//chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
WorldRef wordRef = WorldRef.ofName(getSettings().getWorldName()); WorldRef wordRef = WorldRef.ofName(getSettings().getWorldName());
chunkGenerator = WorldGeneratorApi chunkGenerator = WorldGeneratorApi
.getInstance(getPlugin(), 0, 5) .getInstance(getPlugin(), 0, 5)
.createCustomGenerator(wordRef, generator -> { .createCustomGenerator(wordRef, generator -> {
// Set the noise 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.SURFACE_STRUCTURES);
generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS); generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS);
}); });
@ -86,6 +87,8 @@ public class Boxed extends GameModeAddon {
//registerListener(new JoinListener(this)); //registerListener(new JoinListener(this));
// Advancements manager // Advancements manager
advManager = new AdvancementsManager(this); advManager = new AdvancementsManager(this);
// Get delete chunk generator
delChunks = new DeleteGen(this);
} }
@Override @Override
@ -144,8 +147,9 @@ public class Boxed extends GameModeAddon {
// Set world name // Set world name
worldName2 = env.equals(World.Environment.NETHER) ? worldName2 + NETHER : worldName2; worldName2 = env.equals(World.Environment.NETHER) ? worldName2 + NETHER : worldName2;
worldName2 = env.equals(World.Environment.THE_END) ? worldName2 + THE_END : worldName2; worldName2 = env.equals(World.Environment.THE_END) ? worldName2 + THE_END : worldName2;
WorldCreator wc = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env); World w = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env).generator(chunkGenerator2).createWorld();
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld(); // Backup world
WorldCreator.name(worldName2 + "_bak").type(WorldType.FLAT).environment(env).generator(chunkGenerator2).createWorld();
// Set spawn rates // Set spawn rates
if (w != null) { if (w != null) {
if (getSettings().getSpawnLimitMonsters() > 0) { if (getSettings().getSpawnLimitMonsters() > 0) {
@ -178,6 +182,9 @@ public class Boxed extends GameModeAddon {
@Override @Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
if (id.equals("delete")) {
return delChunks;
}
return chunkGenerator; return chunkGenerator;
} }

View File

@ -64,10 +64,15 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.world-name") @ConfigEntry(path = "world.world-name")
private String worldName = "boxed_world"; 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("World difficulty setting - PEACEFUL, EASY, NORMAL, HARD")
@ConfigComment("Other plugins may override this setting") @ConfigComment("Other plugins may override this setting")
@ConfigEntry(path = "world.difficulty") @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("Spawn limits. These override the limits set in bukkit.yml")
@ConfigComment("If set to a negative number, the server defaults will be used") @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() { public float getNoiseScaleHorizontal() {
return 10; return 10;
} }
/**
* @return the seed
*/
public long getSeed() {
return seed;
}
/**
* @param seed the seed to set
*/
public void setSeed(long seed) {
this.seed = seed;
}
} }

View File

@ -17,10 +17,10 @@ public class BasicWorldGenerator implements BaseNoiseGenerator {
private final Boxed addon; private final Boxed addon;
public BasicWorldGenerator(Boxed addon, WorldRef world) { public BasicWorldGenerator(Boxed addon, WorldRef world, long seed) {
this.addon = addon; this.addon = addon;
// Initialize the noise generator based on the world seed // Initialize the noise generator based on the world seed
this.mainNoiseGenerator = new SimplexNoiseGenerator(123456789L); this.mainNoiseGenerator = new SimplexNoiseGenerator(seed);
} }

View 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;
}
}

View File

@ -34,7 +34,7 @@ public class AdvancementListener implements Listener {
if (score != 0) { if (score != 0) {
User user = User.getInstance(e.getPlayer()); User user = User.getInstance(e.getPlayer());
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F); 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.completed", TextVariables.NAME, adv);
user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score)); user.sendMessage("boxed.size-changed", TextVariables.NUMBER, String.valueOf(score));
} }