Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Never hold the whole region in memory or load the seed world on a normal boot

`generators/biomes/BiomeLayout` reads one dimension of a biomes file and answers "which chosen biome is at dx,dz from the middle" (null = the seed's own). It supports per-quarter lists, `rings`, random `patches`, and `blend` (noise that bends the edges). `AbstractSeedBiomeProvider` only adds the centres and the vanilla fallback. `biomes.yml` is the "original" style; `biomes/*.yml` are the others (`workshop/BiomeStyles` maps names to files). With `blend: 0` the original layout must stay exactly as it was, because existing areas depend on it.

`workshop/WorkshopManager` runs the one workshop: temporary worlds `<worldname>/workshop` and `/workshop_nether` (folders inside the game world's folder, like seed worlds) made with the seed generator, peaceful, spawn limits 0. Its state (`workshop/Workshop`: seed, biomes file, source area, centres, the players inside and the game mode each had outside) is saved to `areas/workshop.yml` on every change and reloaded, with the worlds, in `onEnable`. `listeners/WorkshopListener` forces creative on entry, restores the game mode on exit, respawns in place, and sends players home if the workshop was discarded while they were offline (`areas/displaced.yml`). `/boxadmin areas edit` (`AdminAreasEditCommand`) holds the logic and can be typed; `WorkshopDialogs` is only the Paper dialog UI on top, and cannot be unit tested under MockBukkit. Still to build: spot scanning in the workshop, choosing the centre, structure logging and turning the workshop into an area without a restart.
`workshop/WorkshopManager` runs the one workshop: temporary worlds `<worldname>/workshop` and `/workshop_nether` (folders inside the game world's folder, like seed worlds) made with the seed generator, peaceful, spawn limits 0. Its state (`workshop/Workshop`: seed, biomes file, source area, centres, the players inside and the game mode each had outside) is saved to `areas/workshop.yml` on every change and reloaded, with the worlds, in `onEnable`. `listeners/WorkshopListener` forces creative on entry, restores the game mode on exit, respawns in place, and sends players home if the workshop was discarded while they were offline (`areas/displaced.yml`). `/boxadmin areas edit` (`AdminAreasEditCommand`) holds the logic and can be typed; `WorkshopDialogs` is only the Paper dialog UI on top, and cannot be unit tested under MockBukkit. When the workshop overworld is made, `WorkshopManager.scan` searches the vanilla biomes (`reach/SpotFinder`), stores the candidates as unscored `Workshop.Spot`s, calls `setCentres` with all of them (spot 0 is always the starting centre; the others are kept `4 * area radius` from it so layouts do not overlap) and scores them one at a time with `reach/SpotScorer` (shared with the find command). The spot list is saved after each score and the scan resumes after a restart; the centres must be set again before the world is created or new chunks would get the wrong biomes. `/boxadmin areas spots` (`AdminAreasSpotsCommand`) lists them and `select` sets `Workshop.setCentre`, teleports, and `showCentre` sends a fake diamond block and a per-player `WorldBorder`. Still to build: structure logging and turning the workshop into an area without a restart, then the Nether and End spots.

### Deleted boxes

Expand Down
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ You can also do the same by hand: add the area to `areas.yml` and make a bluepri
| `/boxadmin areas rebuild <area> [regenerate]` | Builds the area's land again at the next restart. With `regenerate` the seed worlds are thrown away first, which is needed after changing the area's seed, centres or biomes. Without it, the land is rebuilt from the seed worlds as they are, which keeps changes made to them by hand. |
| `/boxadmin areas clean [x z]` | Puts the land of the box position you are in (or the one at x, z) back the way it was. Use it after trying out structures in a position nobody has a box in. Positions with a box in use are refused. |
| `/boxadmin areas check <area>` | Plays out how a box grows in the area and reports where players get stuck. See [Checking that an area can be played](#checking-that-an-area-can-be-played). |
| `/boxadmin areas find <area> [seed\|random] [radius]` | Looks through a seed for good places to start a box. See [Finding a good place to start](#finding-a-good-place-to-start). |
| `boxadmin areas find <area> [seed\|random] [radius]` | Console only. Looks through a seed for good places to start a box. See [Finding a good place to start](#finding-a-good-place-to-start). |
| `/boxadmin areas edit` | Opens the area workshop, where a new area is tried out in a temporary world. See [The area workshop](#the-area-workshop). |

Areas can be chained so that a player's box in one area has to reach a certain size before the next area is unlocked, and can be closed to new boxes:
Expand Down Expand Up @@ -168,6 +168,8 @@ An advancement that scores points but can never be earned is worth either removi

### Finding a good place to start

**The easy way is [the area workshop](#the-area-workshop)**, which searches by itself and lets you go and look at each place. The command described here does the same search from the console and only writes a report.

Every box in an area is a copy of the land around one place in the area's seed. By default that place is 0,0, so whether new players start in a forest or in the sea depends on the seed. `/boxadmin areas find <area> [seed|random] [radius]` finds better places for you:

* with no seed it searches the seed the area already has, so you can see how the current place compares,
Expand Down Expand Up @@ -202,7 +204,7 @@ A good start does not mean the area can be finished. Run `/boxadmin areas check

### The area workshop

The workshop is a set of temporary worlds for trying out a seed and a biome style before they become an area. **It is not finished yet:** today it makes the worlds and lets you look around and build in them. Picking the middle of the box, placing structures and turning the result into an area are still to come.
The workshop is a set of temporary worlds for trying out a seed and a biome style before they become an area. **It is not finished yet:** today it makes the worlds, finds good places to start and lets you pick one as the middle of the box. Placing structures and turning the result into an area are still to come.

Run `/boxadmin areas edit`. A dialog box asks for:

Expand All @@ -217,6 +219,33 @@ You are then taken to the temporary world. While you are there:
* You can leave and come back. The workshop, and everything built in it, stays until you discard it, including over a server restart. There is one workshop at a time, and other admins can join it.
* If you start from an existing area without changing its seed or biome style, the workshop starts as a copy of the land that area was built from, so changes made to it by hand are kept.

#### Picking the middle of the box

As soon as the world is made, Boxed starts looking through the seed for good places to start a box, in the same way as `/boxadmin areas find`. It looks for wooded, dry land with water a short walk away and no mountains within about 130 blocks, so that a new player can see what there is to reach. You can fly around while it works. You are told in chat when the first place is ready and when the search has finished. In between, progress is shown above the hotbar. The first ones arrive within a few seconds and there are up to thirteen.

Press **F** (the swap hands key), click the message, or run `/boxadmin areas spots`, to see the places as numbered buttons with their coordinates and scores. Hover over a button to see what the score is made of. The first place is always where the workshop started: 0,0, or the middle of the area you started from.

Clicking a button:

* takes you there, on the ground under any trees,
* makes it the middle of every box,
* puts a diamond block under your feet to mark it, and
* sets a world border that shows how far a box can grow.

Only you see the diamond block and the border, and neither changes the world. The border also stops you flying out, so hide it with the button in the dialog or `/boxadmin areas spots border` when you want to look further afield. You can pick another place at any time.

The biome style is laid out around every place that was found, so each one looks exactly as a box there will look. This is why you pick from the places found and cannot use just anywhere: biomes are fixed when land is generated.

| Command | Description |
|---------|-------------|
| `/boxadmin areas spots` | Shows the places found so far. |
| `/boxadmin areas spots <number>` | Picks a place and takes you there. |
| `/boxadmin areas spots border` | Shows or hides the border. |

The permission is `boxed.admin.areas.spots`.

#### Coming back and discarding

Run `/boxadmin areas edit` again to go back to it, go to its Nether, or discard it. Discarding sends everyone inside to their box (or to spawn if they have none) and deletes the temporary worlds. Players who were inside but offline are sent to their box when they next join.

Everything can also be typed, which is the only way from the console:
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/world/bentobox/boxed/commands/AdminAreasCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void setup() {
new Check(this);
new AdminAreasFindCommand(this);
new AdminAreasEditCommand(this);
new AdminAreasSpotsCommand(this);
}

@Override
Expand Down Expand Up @@ -100,6 +101,22 @@ public boolean execute(User user, String label, List<String> args) {
return true;
}

/**
* Works out which parameter of a command is being typed. BentoBox gives tab completion
* everything typed after the top command, so the labels of the commands on the way down
* (for example "areas" and "find") come before the parameters.
* @param command the command being completed
* @param args everything typed after the top command
* @return 1 for the first parameter, 2 for the second and so on
*/
static int parameter(CompositeCommand command, List<String> args) {
int labels = 0;
for (CompositeCommand c = command; c.getParent() != null; c = c.getParent()) {
labels++;
}
return args.size() - labels;
}

private static Optional<List<String>> areaNames(Boxed addon, List<String> args) {
if (args.isEmpty()) {
return Optional.empty();
Expand Down Expand Up @@ -316,8 +333,8 @@ public boolean execute(User user, String label, List<String> args) {

@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
if (args.size() == 2) {
return Optional.of(Util.tabLimit(List.of(REGENERATE), args.get(1)));
if (parameter(this, args) == 2) {
return Optional.of(Util.tabLimit(List.of(REGENERATE), args.get(args.size() - 1)));
}
return areaNames(getAddon(), args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ boolean go(User user, Environment env) {
if (error != null || !Boolean.TRUE.equals(ok)) {
user.sendMessage(FAILED);
} else {
user.sendMessage(PREFIX + "welcome");
user.sendMessage(PREFIX + "welcome", TextVariables.LABEL, getTopLabel());
}
});
return true;
Expand All @@ -238,21 +238,22 @@ boolean discard(User user) {
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
Boxed addon = getAddon();
String last = args.isEmpty() ? "" : args.get(args.size() - 1);
// The first argument is this command's own label
List<String> options = new ArrayList<>();
String sub = args.size() > 2 ? args.get(1).toLowerCase(Locale.ENGLISH) : "";
if (args.size() <= 2) {
int parameter = AdminAreasCommand.parameter(this, args);
// The first parameter says what to do, and the rest depend on it
String sub = parameter > 1 ? args.get(args.size() - parameter).toLowerCase(Locale.ENGLISH) : "";
if (parameter <= 1) {
options.addAll(List.of(START, GO, DISCARD));
} else if (sub.equals(START) && args.size() == 3) {
} else if (sub.equals(START) && parameter == 2) {
options.addAll(List.of(RANDOM, SAME));
} else if (sub.equals(START) && args.size() == 4) {
} else if (sub.equals(START) && parameter == 3) {
options.add(SAME);
options.addAll(BiomeStyles.list(addon.getDataFolder()));
} else if (sub.equals(START) && args.size() == 5) {
} else if (sub.equals(START) && parameter == 4) {
addon.getAreas().getAreas().forEach(a -> options.add(a.id()));
} else if (sub.equals(GO) && args.size() == 3) {
} else if (sub.equals(GO) && parameter == 2) {
options.add(NETHER);
} else if (sub.equals(DISCARD) && args.size() == 3) {
} else if (sub.equals(DISCARD) && parameter == 2) {
options.add(CONFIRM);
}
return Optional.of(Util.tabLimit(options, last));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import world.bentobox.boxed.generators.chunks.BoxedSeedChunkGenerator;
import world.bentobox.boxed.reach.FortressSpot;
import world.bentobox.boxed.reach.SpotFinder;
import world.bentobox.boxed.reach.SpotScorer;
import world.bentobox.boxed.reach.SpotFinder.Candidate;
import world.bentobox.boxed.reach.SpotSurvey;

Expand Down Expand Up @@ -152,40 +153,14 @@ private void survey(int index) {
return;
}
Candidate spot = spots.get(index);
int reach = SpotSurvey.RADIUS >> 4;
int chunkX = spot.x() >> 4;
int chunkZ = spot.z() >> 4;
List<CompletableFuture<Chunk>> chunks = new ArrayList<>();
for (int x = -reach; x < reach; x++) {
for (int z = -reach; z < reach; z++) {
chunks.add(world.getChunkAtAsync(chunkX + x, chunkZ + z));
}
}
CompletableFuture.allOf(chunks.toArray(CompletableFuture[]::new)).whenComplete((v, error) ->
// Chunks have to be read on the main thread
Bukkit.getScheduler().runTask(getPlugin(), () -> {
SpotScorer.score(getPlugin(), world, spot.x(), spot.z(), true).whenComplete((score, error) -> {
if (error != null) {
getAddon().logError("Could not generate the land at " + spot.x() + "," + spot.z() + ": " + error);
survey(index + 1);
return;
} else {
scored.add(new Scored(spot, score));
}
List<ChunkSnapshot> snapshots = new ArrayList<>();
for (CompletableFuture<Chunk> chunk : chunks) {
Chunk c = chunk.join();
snapshots.add(c.getChunkSnapshot(true, false, false));
world.unloadChunk(c.getX(), c.getZ(), false);
}
int minY = world.getMinHeight();
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), () -> {
SpotSurvey spotSurvey = new SpotSurvey();
snapshots.forEach(s -> spotSurvey.add(s, (s.getX() - chunkX) << 4, (s.getZ() - chunkZ) << 4, minY));
SpotSurvey.Score score = spotSurvey.score();
Bukkit.getScheduler().runTask(getPlugin(), () -> {
scored.add(new Scored(spot, score));
survey(index + 1);
});
});
}));
survey(index + 1);
});
}

/**
Expand Down Expand Up @@ -456,7 +431,8 @@ public AdminAreasFindCommand(CompositeCommand parent) {
@Override
public void setup() {
this.setPermission("admin.areas.find");
this.setOnlyPlayer(false);
// Players use the area workshop, which searches by itself and lets them go and look
this.setOnlyConsole(true);
this.setParametersHelp(PREFIX + "parameters");
this.setDescription(PREFIX + "description");
}
Expand Down Expand Up @@ -507,10 +483,11 @@ public boolean execute(User user, String label, List<String> args) {

@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
if (args.size() == 3) {
return Optional.of(Util.tabLimit(List.of(RANDOM), args.get(2)));
int parameter = AdminAreasCommand.parameter(this, args);
if (parameter == 2) {
return Optional.of(Util.tabLimit(List.of(RANDOM), args.get(args.size() - 1)));
}
if (args.size() > 3) {
if (parameter > 2) {
return Optional.empty();
}
return Optional.of(Util.tabLimit(this.<Boxed>getAddon().getAreas().getAreas().stream().map(Area::id).toList(),
Expand Down
Loading
Loading