Performs nether

This commit is contained in:
tastybento 2022-12-09 20:22:06 -08:00
parent e6026dca4f
commit 739b1d5eab
9 changed files with 215 additions and 65 deletions

View File

@ -47,7 +47,7 @@ public class Boxed extends GameModeAddon {
.type(Type.WORLD_SETTING)
.defaultSetting(true)
.build();
private static final String SEED = "seed";
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
@ -56,8 +56,10 @@ public class Boxed extends GameModeAddon {
private BoxedChunkGenerator chunkGenerator;
private final Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager;
private ChunkGenerator netherChunkGenerator;
private BoxedChunkGenerator netherChunkGenerator;
private World seedWorld;
private World seedWorldNether;
private World seedWorldEnd;
private BiomeProvider boxedBiomeProvider;
@Override
@ -85,6 +87,7 @@ public class Boxed extends GameModeAddon {
}
// Initialize the Generator because createWorlds will be run after onLoad
this.chunkGenerator = new BoxedChunkGenerator(this);
this.netherChunkGenerator = new BoxedChunkGenerator(this);
return true;
}
@ -147,14 +150,16 @@ public class Boxed extends GameModeAddon {
// Create seed world
log("Creating Boxed Seed world ...");
seedWorld = WorldCreator
.name("seed")
.generator(new BoxedSeedChunkGenerator(this))
.name(SEED)
.generator(new BoxedSeedChunkGenerator(this, Environment.NORMAL))
.environment(Environment.NORMAL)
.generateStructures(false)
.seed(getSettings().getSeed())
.createWorld();
seedWorld.setDifficulty(Difficulty.PEACEFUL); // No damage wanted in this world.
saveChunks(seedWorld);
// Unload seed world
//Bukkit.getServer().unloadWorld("seed", false);
String worldName = settings.getWorldName().toLowerCase();
@ -165,14 +170,25 @@ public class Boxed extends GameModeAddon {
// Create the world if it does not exist
islandWorld = getWorld(worldName, World.Environment.NORMAL);
/*
// Make the nether if it does not exist
if (settings.isNetherGenerate()) {
log("Creating Boxed Seed Nether world ...");
seedWorldNether = WorldCreator
.name(SEED + NETHER)
.generator(new BoxedSeedChunkGenerator(this, Environment.NETHER))
.environment(Environment.NETHER)
.seed(getSettings().getSeed())
.createWorld();
seedWorldNether.setDifficulty(Difficulty.PEACEFUL); // No damage wanted in this world.
saveChunks(seedWorldNether);
if (getServer().getWorld(worldName + NETHER) == null) {
log("Creating Boxed's Nether...");
}
netherWorld = settings.isNetherIslands() ? getWorld(worldName, World.Environment.NETHER) : getWorld(worldName, World.Environment.NETHER);
netherWorld = getWorld(worldName, World.Environment.NETHER);
}
/*
// Make the end if it does not exist
if (settings.isEndGenerate()) {
if (getServer().getWorld(worldName + THE_END) == null) {
@ -184,6 +200,19 @@ public class Boxed extends GameModeAddon {
}
private void saveChunks(World seedWorld) {
BoxedChunkGenerator gen;
int startX = 0;
int startZ = 0;
if (seedWorld.getEnvironment().equals(Environment.NORMAL)) {
gen = chunkGenerator;
startX = this.settings.getSeedX() >> 4;
startZ = this.settings.getSeedZ() >> 4;
} else {
gen = netherChunkGenerator;
startX = this.settings.getNetherSeedX() >> 4;
startZ = this.settings.getNetherSeedZ() >> 4;
}
// Convert to chunks
int size = (int)(this.getSettings().getIslandDistance() / 16D);
double percent = size * 4D * size;
@ -191,13 +220,13 @@ public class Boxed extends GameModeAddon {
int last = 0;
for (int x = -size; x <= size; x ++) {
for (int z = -size; z <= size; z++) {
ChunkSnapshot chunk = seedWorld.getChunkAt(this.settings.getChunkX() + x, this.settings.getChunkZ() + z).getChunkSnapshot(true, true, false);
this.chunkGenerator.setChunk(x, z, chunk);
ChunkSnapshot chunk = seedWorld.getChunkAt(startX + x, startZ + z).getChunkSnapshot(true, true, false);
gen.setChunk(x, z, chunk);
count++;
int p = (int) (count / percent * 100);
if (p % 10 == 0 && p != last) {
last = p;
this.log("Storing seed chunks. " + p + "% done");
this.log("Storing seed chunks for " + seedWorld.getEnvironment() + " " + p + "% done");
}
}
@ -205,10 +234,15 @@ public class Boxed extends GameModeAddon {
}
/**
* @return the chunkGenerator
* Get the chunk generator for a Boxed world
* @param env - nether, normal, or end
* @return the chunkGenerator for the environment
*/
public BoxedChunkGenerator getChunkGenerator() {
return chunkGenerator;
public BoxedChunkGenerator getChunkGenerator(Environment env) {
if (env.equals(Environment.NORMAL)) {
return chunkGenerator;
}
return netherChunkGenerator;
}
/**
@ -224,7 +258,7 @@ public class Boxed extends GameModeAddon {
boxedBiomeProvider = new BoxedBiomeGenerator(this);
World w = WorldCreator
.name(worldName2)
.generator(chunkGenerator)
.generator(env.equals(World.Environment.NETHER) ? netherChunkGenerator : chunkGenerator)
.environment(env)
.seed(seedWorld.getSeed()) // For development
.createWorld();

View File

@ -76,11 +76,23 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.generator.seed", needsReset = true)
private long seed = 602103456450L;
@ConfigComment("Seed center chunk. This is where the areas are copied from.")
@ConfigEntry(path = "world.generator.start-chunk.x")
private int chunkX = 0;
@ConfigEntry(path = "world.generator.start-chunk.z")
private int chunkZ = 0;
@ConfigComment("Area seed center. This is where the areas are copied from.")
@ConfigEntry(path = "world.generator.seed-start.normal.x")
private int seedX = 0;
@ConfigEntry(path = "world.generator.seed-start.normal.z")
private int seedZ = 0;
@ConfigComment("Nether area seed center. This is where the areas are copied from.")
@ConfigEntry(path = "world.generator.seed-start.nether.x")
private int netherSeedX = 0;
@ConfigEntry(path = "world.generator.seed-start.nether.z")
private int netherSeedZ = 0;
@ConfigComment("End area seed center. This is where the areas are copied from.")
@ConfigEntry(path = "world.generator.seed-start.end.x")
private int endSeedX = 0;
@ConfigEntry(path = "world.generator.seed-start.end.z")
private int endSeedZ = 0;
@ConfigComment("World difficulty setting - PEACEFUL, EASY, NORMAL, HARD")
@ConfigComment("Other plugins may override this setting")
@ -1832,30 +1844,88 @@ public class Settings implements WorldSettings {
}
/**
* @return the chunkX
* @return the seedX
*/
public int getChunkX() {
return chunkX;
public int getSeedX() {
return seedX;
}
/**
* @param chunkX the chunkX to set
* @param seedX the seedX to set
*/
public void setChunkX(int chunkX) {
this.chunkX = chunkX;
public void setSeedX(int seedX) {
this.seedX = seedX;
}
/**
* @return the chunkZ
* @return the seedZ
*/
public int getChunkZ() {
return chunkZ;
public int getSeedZ() {
return seedZ;
}
/**
* @param chunkZ the chunkZ to set
* @param seedZ the seedZ to set
*/
public void setChunkZ(int chunkZ) {
this.chunkZ = chunkZ;
public void setSeedZ(int seedZ) {
this.seedZ = seedZ;
}
/**
* @return the netherSeedX
*/
public int getNetherSeedX() {
return netherSeedX;
}
/**
* @param netherSeedX the netherSeedX to set
*/
public void setNetherSeedX(int netherSeedX) {
this.netherSeedX = netherSeedX;
}
/**
* @return the netherSeedZ
*/
public int getNetherSeedZ() {
return netherSeedZ;
}
/**
* @param netherSeedZ the netherSeedZ to set
*/
public void setNetherSeedZ(int netherSeedZ) {
this.netherSeedZ = netherSeedZ;
}
/**
* @return the endSeedX
*/
public int getEndSeedX() {
return endSeedX;
}
/**
* @param endSeedX the endSeedX to set
*/
public void setEndSeedX(int endSeedX) {
this.endSeedX = endSeedX;
}
/**
* @return the endSeedZ
*/
public int getEndSeedZ() {
return endSeedZ;
}
/**
* @param endSeedZ the endSeedZ to set
*/
public void setEndSeedZ(int endSeedZ) {
this.endSeedZ = endSeedZ;
}
}

View File

@ -88,7 +88,7 @@ public abstract class AbstractBoxedBiomeProvider extends BiomeProvider {
int size = (int)(dist / 16D); // Convert to chunk
chunkX = BoxedChunkGenerator.repeatCalc(chunkX, size);
chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ, size);
ChunkSnapshot c = addon.getChunkGenerator().getChunk(chunkX, chunkZ);
ChunkSnapshot c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ);
if (c != null) {
int xx = Math.floorMod(x, 16);

View File

@ -36,7 +36,7 @@ public abstract class AbstractCopyBiomeProvider extends BiomeProvider {
int size = (int)(dist / 16D); // Convert to chunk
chunkX = BoxedChunkGenerator.repeatCalc(chunkX, size);
chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ, size);
ChunkSnapshot c = addon.getChunkGenerator().getChunk(chunkX, chunkZ);
ChunkSnapshot c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ);
if (c != null) {
int xx = Math.floorMod(x, 16);

View File

@ -0,0 +1,18 @@
package world.bentobox.boxed.generators;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import world.bentobox.boxed.Boxed;
/**
* @author tastybento
*
*/
public class BoxedNetherBiomeGenerator extends AbstractCopyBiomeProvider {
public BoxedNetherBiomeGenerator(Boxed boxed) {
super(boxed, Environment.NETHER, Biome.BASALT_DELTAS);
}
}

View File

@ -1,8 +1,8 @@
package world.bentobox.boxed.generators;
import org.bukkit.World.Environment;
import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;
import world.bentobox.boxed.Boxed;
@ -13,13 +13,16 @@ import world.bentobox.boxed.Boxed;
*/
public class BoxedSeedChunkGenerator extends ChunkGenerator {
BiomeProvider seedBiomeProvider;
private final BiomeProvider seedBiomeProvider;
private final Environment env;
/**
* @param env
* @param seedBiomeProvider
*/
public BoxedSeedChunkGenerator(Boxed boxed) {
public BoxedSeedChunkGenerator(Boxed boxed, Environment env) {
this.seedBiomeProvider = new SeedBiomeGenerator(boxed);
this.env = env;
}
/*
@ -56,6 +59,6 @@ public class BoxedSeedChunkGenerator extends ChunkGenerator {
@Override
public boolean shouldGenerateStructures() {
return false;
return env.equals(Environment.NETHER); // We allow structures in the Nether
}
}

View File

@ -4,21 +4,20 @@ import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Pair;
import world.bentobox.bentobox.util.Util;
@ -35,6 +34,8 @@ public class NewAreaListener implements Listener {
private Queue<Item> itemsToBuild = new LinkedList<>();
private boolean pasting;
private record Item(World w, List<Pair<Integer, Integer>> cs, String cmd) {};
Pair<Integer, Integer> min = new Pair<Integer, Integer>(0,0);
Pair<Integer, Integer> max = new Pair<Integer, Integer>(0,0);
/**
@ -87,13 +88,15 @@ public class NewAreaListener implements Listener {
// Loop through the structures in the file - there could be more than one
for (String structure : section.getKeys(false)) {
addon.log(structure);
String value = section.getString(structure,"");
String key = section.getString(structure,"");
// Extract coords
String[] coords = value.split(",");
if (coords.length == 3) {
int x = Integer.valueOf(coords[0]) + center.getBlockX();
int y = Integer.valueOf(coords[1]);
int z = Integer.valueOf(coords[2]) + center.getBlockZ();
String[] value = key.split(",");
if (value.length == 4) {
Environment env = Environment.valueOf(value[0].toUpperCase(Locale.ENGLISH).strip());
World world = env.equals(Environment.NORMAL) ? addon.getOverWorld() : addon.getNetherWorld();
int x = Integer.valueOf(value[1].strip()) + center.getBlockX();
int y = Integer.valueOf(value[2].strip());
int z = Integer.valueOf(value[3].strip()) + center.getBlockZ();
List<Pair<Integer, Integer>> cs = new ArrayList<>();
int size = 10;
for (int cx = (x >> 4) - size; cx < (x >>4) + size; cx++) {
@ -102,13 +105,13 @@ public class NewAreaListener implements Listener {
}
}
// Make command
String cmd = "execute in " + center.getWorld().getName() + " run place "+ string + " minecraft:" + structure + " "
String cmd = "execute in " + world.getName() + " run place "+ string + " minecraft:" + structure + " "
+ x + " "
+ y + " "
+ z + " ";
itemsToBuild.add(new Item(center.getWorld(), cs, cmd));
itemsToBuild.add(new Item(world, cs, cmd));
} else {
addon.logError("Structure file syntax error: " + structure + " " + value);
addon.logError("Structure file syntax error: " + structure + " " + key);
}
}
}
@ -117,15 +120,27 @@ public class NewAreaListener implements Listener {
private void LoadChunksAsync(World w, List<Pair<Integer, Integer>> cs, int i, String cmd) {
pasting = true;
int total = cs.size();
//addon.log("Loading chunk async " + i);
if (i < total) {
if (i == 0) {
min = new Pair<>(cs.get(0).x, cs.get(0).z);
max = new Pair<>(cs.get(0).x, cs.get(0).z);
}
if (cs.get(i).x < min.x || cs.get(i).z < min.z) {
min = cs.get(i);
}
if (cs.get(i).x > min.x || cs.get(i).z > min.z) {
max = cs.get(i);
}
Util.getChunkAtAsync(w, cs.get(i).x, cs.get(i).z, true).thenAccept(c -> {
//addon.log("Loaded chunk " + c.getX() + " " + c.getZ());
LoadChunksAsync(w, cs, i + 1, cmd);
});
} else {
addon.log("Complete");
addon.log("Loaded chunks in " + w.getName() + " min " + (min.x << 4) + " " + (min.z << 4) + " to " +
(max.x << 4) + " " + (max.z << 4));
addon.log("run command " + cmd);
Bukkit.getScheduler().runTaskLater(addon.getPlugin(), () -> {
addon.log("Comand success = " + addon.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd));

View File

@ -29,15 +29,24 @@ world:
world-name: boxed_world
generator:
# World seed.
# If you change this, stop the server and delete the worlds made.
# /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.
seed: 602103456450
seed-start:
normal:
# Area seed center. This is where the areas are copied from.
x: 9920
z: 9856
nether:
# Nether area seed center. This is where the areas are copied from.
x: 9999
z: 10015
end:
# End area seed center. This is where the areas are copied from.
x: 0
z: 0
# Generate surface
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
generate-surface: true
# Generate bedrock
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
generate-bedrock: true
# Generate caves
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
generate-caves: true
@ -50,7 +59,7 @@ world:
# Allow surface structures - villages, shipwrecks, broken portals, etc.
# These will be randomly placed, so may not be available for every player.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
allow-structures: true
allow-structures: false
# World difficulty setting - PEACEFUL, EASY, NORMAL, HARD
# Other plugins may override this setting
difficulty: NORMAL
@ -100,7 +109,7 @@ world:
# Note: Some default challenges will not be possible if there is no nether.
# Note that with a standard nether all players arrive at the same portal and entering a
# portal will return them back to their areas.
generate: false
generate: true
# Nether spawn protection radius - this is the distance around the nether spawn
# that will be public from player interaction (breaking blocks, pouring lava etc.)
# Minimum is 0 (not recommended), maximum is 100. Default is 25.
@ -170,6 +179,7 @@ world:
CROP_TRAMPLE: false
BREWING: false
DROPPER: false
ENTITY_PORTAL_TELEPORT: false
OBSIDIAN_SCOOPING: false
CREEPER_DAMAGE: true
TNT_PRIMING: false
@ -232,8 +242,8 @@ world:
BREAK_HOPPERS: 500
FURNACE: 500
MONSTER_SPAWNERS_SPAWN: 500
MINECART: 500
ANVIL: 500
MINECART: 500
FISH_SCOOPING: 500
FIRE_IGNITE: 500
END_PORTAL: 500
@ -246,8 +256,8 @@ world:
LEVER: 0
ELYTRA: 0
CAKE: 500
RIDING: 500
HURT_MONSTERS: 0
RIDING: 500
NAME_TAG: 500
ARMOR_STAND: 500
TRADING: 0
@ -268,15 +278,15 @@ world:
COMMAND_RANKS: 500
BEACON: 500
TRAPDOOR: 500
PRESSURE_PLATE: 0
EXPERIENCE_BOTTLE_THROWING: 500
PRESSURE_PLATE: 0
DYE: 500
PLACE_BLOCKS: 500
ITEM_FRAME: 500
PLACE_BLOCKS: 500
CRAFTING: 0
SHEARING: 500
ANIMAL_SPAWNERS_SPAWN: 500
ENCHANTING: 500
ANIMAL_SPAWNERS_SPAWN: 500
SHEARING: 500
BOAT: 0
BED: 500
SPAWN_EGGS: 500

View File

@ -1,6 +1,6 @@
structures:
new:
village_plains: "0,64,80"
ruined_portal_mountain: "-38,63,20"
pillager_outpost: "3,63,-60"
village_plains: "normal, 0 ,64, 80"
ruined_portal_mountain: "normal, -38, 63, 20"
pillager_outpost: "normal, 3, 63, -60"