Add tiered Arrakis sietches and explicit no-backup regeneration
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-11-29 22:33:07 +01:00
commit e4a5b72406
10 changed files with 1383 additions and 1001 deletions

View file

@ -1,7 +1,7 @@
plugins { java }
group = "com.example"
version = "1.0.15-pillager1"
version = "1.0.16-sietch1"
repositories {
mavenCentral()

View file

@ -0,0 +1,324 @@
package com.example.duneterrain;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Farmland;
import org.bukkit.block.data.type.Ladder;
import org.bukkit.block.data.type.Lantern;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.block.data.type.TrapDoor;
import org.bukkit.generator.LimitedRegion;
/**
* Builds the three Arrakis sietch tiers inside a populate window. Geometry comes from {@link SietchLayout}.
* Small: a hidden cell with no water. Medium: three rooms plus an organic pool. Large: a cistern hall with a big
* pool, a bridge, six rooms and a three-plot farm. All entrances are windtrap towers (Medium, Large) or a hatch (Small).
* Untested in game; the placement is written against Paper 1.21.8 LimitedRegion.
*/
final class SietchBuilder {
interface Cache { void place(LimitedRegion region, int x, int y, int z, long a, long b); }
private final Cache cache;
SietchBuilder(Cache cache) { this.cache = cache; }
/** Returns false when the terrain is unsuitable (too steep, wet or too shallow) and nothing was built. */
boolean build(LimitedRegion region, SietchLayout.Tier tier, SietchLayout.Anchor anchor, int minHeight, int maxHeight) {
return new Site(region, tier, anchor, minHeight, maxHeight).run();
}
private static final Material WALL = Material.CUT_SANDSTONE, FLOOR = Material.SMOOTH_SANDSTONE, CEIL = Material.SMOOTH_SANDSTONE;
private final class Site {
final LimitedRegion r; final SietchLayout.Tier tier; final int ax, az, minHeight, maxHeight; final long id; final Random rng;
int L; // y of the hall/room floor row; floor top is L+1
int hallH; // air height of the hall
Site(LimitedRegion r, SietchLayout.Tier tier, SietchLayout.Anchor a, int minHeight, int maxHeight) {
this.r = r; this.tier = tier; this.ax = a.x(); this.az = a.z(); this.id = a.id(); this.minHeight = minHeight; this.maxHeight = maxHeight;
this.rng = new Random(a.id());
}
// ---------- low-level helpers (dx/dz relative to the anchor, y absolute) ----------
void put(int dx, int y, int dz, Material m) { int x = ax + dx, z = az + dz; if (r.isInRegion(x, y, z)) r.setType(x, y, z, m); }
void data(int dx, int y, int dz, BlockData d) { int x = ax + dx, z = az + dz; if (r.isInRegion(x, y, z)) r.setBlockData(x, y, z, d); }
int surface(int dx, int dz) { return r.getHighestBlockYAt(ax + dx, az + dz); }
void box(int x1, int y1, int z1, int x2, int y2, int z2, Material m) {
for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++)
for (int z = Math.min(z1, z2); z <= Math.max(z1, z2); z++) put(x, y, z, m);
}
BlockData stairs(Material m, BlockFace face) { Stairs s = (Stairs) m.createBlockData(); s.setFacing(face); s.setHalf(Bisected.Half.BOTTOM); return s; }
void lantern(int dx, int y, int dz) { Lantern l = (Lantern) Material.LANTERN.createBlockData(); l.setHanging(true); data(dx, y, dz, l); }
void bed(int footX, int y, int footZ, BlockFace headToward, Material color) {
Bed foot = (Bed) color.createBlockData(); foot.setFacing(headToward); foot.setPart(Bed.Part.FOOT);
Bed head = (Bed) color.createBlockData(); head.setFacing(headToward); head.setPart(Bed.Part.HEAD);
data(footX, y, footZ, foot); data(footX + headToward.getModX(), y, footZ + headToward.getModZ(), head);
}
// ---------- driver ----------
boolean run() {
int minS = Integer.MAX_VALUE, maxS = Integer.MIN_VALUE, h = tier.half - 2;
for (int[] p : new int[][]{{0, 0}, {h, h}, {-h, h}, {h, -h}, {-h, -h}, {h, 0}, {-h, 0}, {0, h}, {0, -h}}) {
int s = surface(p[0], p[1]); minS = Math.min(minS, s); maxS = Math.max(maxS, s);
}
if (maxS - minS > 12 || maxS + 16 >= maxHeight) return false;
var top = r.getType(ax, surface(0, 0), az);
if (top == Material.WATER || top == Material.LAVA || top == Material.ICE || top == Material.PACKED_ICE) return false;
switch (tier) {
case SMALL -> { int fy = minS - 9; if (fy - 3 < minHeight) return false; small(fy, surface(-6, 0)); }
case MEDIUM -> { hallH = 6; L = minS - 11; if (L - 4 < minHeight) return false; big(); }
case LARGE -> { hallH = 8; L = minS - 13; if (L - 4 < minHeight) return false; big(); }
}
return true;
}
// ---------- rooms ----------
void shell(SietchLayout.Room rm, int y1, int y2) {
box(rm.x1() - 1, y1 - 1, rm.z1() - 1, rm.x2() + 1, y2 + 1, rm.z2() + 1, WALL);
box(rm.x1() - 1, y1 - 1, rm.z1() - 1, rm.x2() + 1, y1 - 1, rm.z2() + 1, FLOOR);
box(rm.x1() - 1, y2 + 1, rm.z1() - 1, rm.x2() + 1, y2 + 1, rm.z2() + 1, CEIL);
}
void hollow(SietchLayout.Room rm, int y1, int y2) { box(rm.x1(), y1, rm.z1(), rm.x2(), y2, rm.z2(), Material.AIR); }
int y1Of(SietchLayout.Room rm) { return rm.kind().equals("farm") ? L : L + 1; }
// ---------- SMALL: the hidden cell ----------
void small(int fy, int hatchY) {
var rooms = SietchLayout.rooms(tier);
for (var rm : rooms) shell(rm, fy, fy + rm.height() - 1);
for (var rm : rooms) hollow(rm, fy, fy + rm.height() - 1);
box(5, fy, -1, 5, fy + 2, 1, Material.AIR); // arch between chamber and alcove
for (int x = -5; x <= 1; x += 2) bed(x, fy, -2, BlockFace.NORTH, Material.RED_BED); // four bunks along the north wall
put(4, fy, 3, Material.BARREL); put(3, fy, 3, Material.BARREL);
put(-1, fy, 1, Material.ACACIA_FENCE); put(-1, fy + 1, 1, Material.ACACIA_PRESSURE_PLATE);
lantern(-1, fy + 3, 0); lantern(7, fy + 2, 0);
cache.place(r, ax + 7, fy, az, id, 0x534d414c4cL);
put(7, fy, -1, Material.BARREL);
// ladder shaft above the west wall of the chamber, hatch on the surface
int ceilingRow = fy + 4;
for (int y = fy; y < hatchY; y++) { put(-6, y, 0, Material.AIR); }
for (int y = ceilingRow; y < hatchY; y++) { put(-7, y, 0, WALL); put(-5, y, 0, WALL); put(-6, y, -1, WALL); put(-6, y, 1, WALL); }
for (int y = fy; y < hatchY; y++) { Ladder l = (Ladder) Material.LADDER.createBlockData(); l.setFacing(BlockFace.EAST); data(-6, y, 0, l); }
for (int dx = -7; dx <= -5; dx++) for (int dz = -1; dz <= 1; dz++) put(dx, hatchY, dz, Material.SMOOTH_SANDSTONE_SLAB);
TrapDoor hatch = (TrapDoor) Material.JUNGLE_TRAPDOOR.createBlockData(); hatch.setFacing(BlockFace.NORTH); hatch.setHalf(Bisected.Half.BOTTOM); hatch.setOpen(false);
data(-6, hatchY, 0, hatch);
}
// ---------- MEDIUM and LARGE ----------
void big() {
var rooms = SietchLayout.rooms(tier);
var pool = SietchLayout.pool(tier);
SietchLayout.Room hall = rooms.get(0);
int hallTop = L + hallH, ceilRow = hallTop + 1;
int[] sw = SietchLayout.stairwell(tier);
int gStair = surface(sw[0], sw[1]);
int topSky = 0;
for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) topSky = Math.max(topSky, surface(pool.cx() + dx, pool.cz() + dz));
int g2 = tier == SietchLayout.Tier.LARGE ? surface(-18, 8) : 0;
for (var rm : rooms) shell(rm, y1Of(rm), y1Of(rm) + rm.height() - 1);
shell5(sw[0], sw[1], ceilRow, gStair + 7); // stairwell shell above the hall ceiling
shell5(pool.cx(), pool.cz(), ceilRow, topSky); // skylight shell
for (var rm : rooms) hollow(rm, y1Of(rm), y1Of(rm) + rm.height() - 1);
doors();
pool(hall, pool);
pillars(hall, pool);
if (tier == SietchLayout.Tier.LARGE) bridge(pool);
spout(hall, pool);
for (var rm : rooms) furnish(rm);
hallLanterns(hall);
stairwell(sw[0], sw[1], gStair, ceilRow);
skylight(pool, ceilRow, topSky);
if (tier == SietchLayout.Tier.LARGE) windtrapDecor(-18, 8, g2);
}
void shell5(int cx, int cz, int fromY, int toY) {
for (int y = fromY; y <= toY; y++) for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++)
if (Math.abs(dx) == 2 || Math.abs(dz) == 2) put(cx + dx, y, cz + dz, WALL);
}
void doors() {
if (tier == SietchLayout.Tier.MEDIUM) {
for (int x : new int[]{-8, 0, 8}) box(x - 1, L + 1, -5, x + 1, L + 3, -5, Material.AIR);
} else {
for (int x : new int[]{-15, -5, 5, 15}) box(x - 1, L + 1, -11, x + 1, L + 3, -10, Material.AIR);
box(-16, L + 1, -4, -15, L + 3, -2, Material.AIR);
box(15, L + 1, -4, 16, L + 3, -2, Material.AIR);
box(-1, L + 1, 11, 1, L + 3, 12, Material.AIR);
box(-1, L, 11, 1, L, 12, Material.DIRT_PATH);
}
}
// ---------- the organic pool: stepped depth, mosaic floor, curbed rim ----------
void pool(SietchLayout.Room hall, SietchLayout.Pool p) {
int rx = SietchLayout.reachX(p) + 1, rz = SietchLayout.reachZ(p) + 1;
for (int dx = p.cx() - rx; dx <= p.cx() + rx; dx++) for (int dz = p.cz() - rz; dz <= p.cz() + rz; dz++) {
if (!hall.contains(dx, dz)) continue;
int depth = SietchLayout.poolDepth(id, p, dx, dz);
if (depth > 0) {
Material mosaic = depth == p.maxDepth() ? Material.YELLOW_TERRACOTTA
: ((Math.floorMod(dx, 2) + Math.floorMod(dz, 2)) % 2 == 0 ? Material.BLUE_TERRACOTTA : Material.LIGHT_BLUE_TERRACOTTA);
put(dx, L - depth, dz, mosaic);
for (int y = L - depth + 1; y <= L; y++) put(dx, y, dz, Material.WATER);
} else if (neighbourWet(hall, p, dx, dz)) {
for (int y = L - p.maxDepth(); y < L; y++) put(dx, y, dz, WALL);
put(dx, L, dz, (dx + dz) % 2 == 0 ? Material.CHISELED_SANDSTONE : Material.CUT_SANDSTONE); // curb
}
}
}
boolean neighbourWet(SietchLayout.Room hall, SietchLayout.Pool p, int dx, int dz) {
for (int[] d : new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}})
if (hall.contains(dx + d[0], dz + d[1]) && SietchLayout.poolDepth(id, p, dx + d[0], dz + d[1]) > 0) return true;
return false;
}
void pillars(SietchLayout.Room hall, SietchLayout.Pool p) {
int[][] spots;
if (tier == SietchLayout.Tier.MEDIUM) spots = new int[][]{{-5, -3}, {5, -3}, {-5, 3}};
else {
spots = new int[12][];
for (int i = 0; i < 12; i++) {
double a = i * Math.PI / 6;
spots[i] = new int[]{(int) Math.round(p.cx() + (p.rx() + 2) * Math.cos(a)), (int) Math.round(p.cz() + (p.rz() + 2) * Math.sin(a))};
}
}
int[] sw = SietchLayout.stairwell(tier);
for (int[] s : spots) {
if (!hall.contains(s[0], s[1]) || SietchLayout.poolDepth(id, p, s[0], s[1]) > 0) continue;
if (Math.abs(s[0] - sw[0]) <= 3 && Math.abs(s[1] - sw[1]) <= 3) continue;
box(s[0], L + 1, s[1], s[0], L + hallH, s[1], WALL);
put(s[0], L + hallH, s[1], Material.CHISELED_SANDSTONE);
put(s[0], L + 1, s[1], Material.SMOOTH_SANDSTONE);
}
}
void bridge(SietchLayout.Pool p) {
for (int dx = p.cx() - SietchLayout.reachX(p); dx <= p.cx() + SietchLayout.reachX(p); dx++) for (int dz = p.cz() - 1; dz <= p.cz() + 1; dz++)
if (SietchLayout.poolDepth(id, p, dx, dz) > 0) put(dx, L, dz, Material.SMOOTH_SANDSTONE);
}
/** A copper hood spills a falling stream into the north edge of the pool. Only the top cell is a source. */
void spout(SietchLayout.Room hall, SietchLayout.Pool p) {
int x = p.cx(), zEdge = Integer.MIN_VALUE;
for (int dz = p.cz() - SietchLayout.reachZ(p) - 1; dz <= p.cz(); dz++) if (SietchLayout.poolDepth(id, p, x, dz) > 0) { zEdge = dz; break; }
if (zEdge == Integer.MIN_VALUE || !hall.contains(x, zEdge - 1)) return;
int yTop = L + hallH - 1;
box(x, L + 1, zEdge - 1, x, L + hallH, zEdge - 1, Material.EXPOSED_CUT_COPPER);
put(x - 1, yTop, zEdge, Material.CUT_COPPER); put(x + 1, yTop, zEdge, Material.CUT_COPPER);
put(x, yTop, zEdge + 1, Material.CUT_COPPER); put(x, yTop + 1, zEdge, Material.CUT_COPPER);
put(x, yTop, zEdge, Material.WATER);
Levelled falling = (Levelled) Material.WATER.createBlockData(); falling.setLevel(8);
for (int y = yTop - 1; y > L; y--) data(x, y, zEdge, falling);
}
void hallLanterns(SietchLayout.Room hall) {
int step = tier == SietchLayout.Tier.LARGE ? 6 : 4;
for (int x = hall.x1() + 1; x <= hall.x2() - 1; x += step) { lantern(x, L + hallH, hall.z1()); lantern(x, L + hallH, hall.z2()); }
}
// ---------- stairwell: a spiral inside a windtrap tower, opening onto the hall's corner ----------
static final int[][] RING = {{0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}};
BlockFace face(int dx, int dz) { return dx > 0 ? BlockFace.EAST : dx < 0 ? BlockFace.WEST : dz > 0 ? BlockFace.SOUTH : BlockFace.NORTH; }
void stairwell(int sx, int sz, int g, int ceilRow) {
for (int[] c : RING) box(sx + c[0], ceilRow, sz + c[1], sx + c[0], g + 6, sz + c[1], Material.AIR); // open shaft through the ceiling
box(sx, L + 1, sz, sx, g + 6, sz, WALL); // central pillar
put(sx, g + 6, sz, Material.CHISELED_SANDSTONE);
for (int k = 0; k < g - L; k++) {
int[] cell = RING[k % 8], prev = RING[Math.floorMod(k - 1, 8)];
int y = g - k, px = sx + cell[0], pz = sz + cell[1];
box(px, y + 1, pz, px, y + 3, pz, Material.AIR);
BlockFace f = k == 0 ? BlockFace.SOUTH : face(prev[0] - cell[0], prev[1] - cell[1]);
data(px, y, pz, stairs(Material.SANDSTONE_STAIRS, f));
}
// the tower above ground: 5x5 body with vents, a door on the south side, a tapered spire
for (int y = g + 1; y <= g + 7; y++) for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++)
if (Math.abs(dx) == 2 || Math.abs(dz) == 2) put(sx + dx, y, sz + dz, WALL);
for (int y = g + 3; y <= g + 5; y += 2) { put(sx - 2, y, sz, Material.SANDSTONE_WALL); put(sx + 2, y, sz, Material.SANDSTONE_WALL); put(sx, y, sz - 2, Material.SANDSTONE_WALL); }
box(sx, g + 1, sz + 2, sx, g + 2, sz + 2, Material.AIR);
put(sx, g + 3, sz + 2, Material.CHISELED_SANDSTONE);
box(sx - 2, g + 8, sz - 2, sx + 2, g + 8, sz + 2, Material.SMOOTH_SANDSTONE_SLAB);
box(sx - 1, g + 8, sz - 1, sx + 1, g + 9, sz + 1, WALL);
box(sx, g + 10, sz, sx, g + 11, sz, WALL);
put(sx, g + 12, sz, Material.CUT_COPPER_SLAB);
lantern(sx, g + 7, sz + 1);
}
/** A purely decorative second windtrap (no interior), so the surface reads as a sietch from a distance. */
void windtrapDecor(int tx, int tz, int g) {
int base = Integer.MAX_VALUE;
for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++) base = Math.min(base, surface(tx + dx, tz + dz));
for (int y = base; y <= g + 7; y++) for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++)
if (Math.abs(dx) == 2 || Math.abs(dz) == 2) put(tx + dx, y, tz + dz, WALL);
for (int y = g + 3; y <= g + 5; y += 2) { put(tx - 2, y, tz, Material.SANDSTONE_WALL); put(tx + 2, y, tz, Material.SANDSTONE_WALL); put(tx, y, tz - 2, Material.SANDSTONE_WALL); put(tx, y, tz + 2, Material.SANDSTONE_WALL); }
box(tx - 2, g + 8, tz - 2, tx + 2, g + 8, tz + 2, Material.SMOOTH_SANDSTONE_SLAB);
box(tx - 1, g + 8, tz - 1, tx + 1, g + 9, tz + 1, WALL);
box(tx, g + 10, tz, tx, g + 11, tz, WALL);
put(tx, g + 12, tz, Material.CUT_COPPER_SLAB);
}
void skylight(SietchLayout.Pool p, int ceilRow, int top) {
for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) {
box(p.cx() + dx, ceilRow, p.cz() + dz, p.cx() + dx, top - 1, p.cz() + dz, Material.AIR);
put(p.cx() + dx, top, p.cz() + dz, Material.GLASS);
}
}
// ---------- furnishing ----------
void furnish(SietchLayout.Room rm) {
int y = y1Of(rm), top = y + rm.height() - 1, cx = (rm.x1() + rm.x2()) / 2, cz = (rm.z1() + rm.z2()) / 2;
switch (rm.kind()) {
case "sleeping" -> {
for (int x = rm.x1() + 1; x <= rm.x2() - 1; x += 2) bed(x, y, rm.z1() + 1, BlockFace.NORTH, Material.RED_BED);
put(rm.x2(), y, rm.z2(), Material.BARREL); put(rm.x1(), y, rm.z2(), Material.BARREL);
lantern(cx, top, cz);
}
case "kitchen" -> {
put(rm.x1() + 1, y, rm.z1(), Material.FURNACE); put(rm.x1() + 2, y, rm.z1(), Material.SMOKER);
put(rm.x1() + 3, y, rm.z1(), Material.CRAFTING_TABLE); put(rm.x1() + 4, y, rm.z1(), Material.COMPOSTER);
for (int x = rm.x1(); x <= rm.x2(); x += 2) put(x, y, rm.z2(), Material.BARREL);
lantern(cx, top, cz);
}
case "workshop" -> {
put(rm.x1() + 1, y, rm.z1(), Material.SMITHING_TABLE); put(rm.x1() + 3, y, rm.z1(), Material.GRINDSTONE);
put(rm.x1() + 5, y, rm.z1(), Material.ANVIL); put(rm.x2(), y, rm.z2(), Material.BARREL); put(rm.x1(), y, rm.z2(), Material.BARREL);
lantern(cx, top, cz);
}
case "council" -> {
put(cx, y, rm.z1(), Material.LECTERN);
for (int z = rm.z1() + 1; z <= rm.z2(); z++) { put(cx, y, z, Material.RED_CARPET); put(rm.x1(), y, z, Material.BOOKSHELF); put(rm.x2(), y, z, Material.BOOKSHELF); }
lantern(cx, top, cz);
}
case "bank" -> {
for (int z = rm.z1(); z <= rm.z2(); z++) put(rm.x1(), y, z, Material.BOOKSHELF);
put(cx, y, rm.z1(), Material.LECTERN); put(cx + 1, y, rm.z1(), Material.COPPER_BLOCK); put(cx - 1, y, rm.z1(), Material.COPPER_BLOCK);
cache.place(r, ax + cx, y, az + rm.z2(), id, 0x42414e4bL);
lantern(cx, top, cz);
}
case "farm" -> farm(rm);
default -> { }
}
}
// ---------- farm: three plots, each split by an open irrigation channel ----------
void farm(SietchLayout.Room rm) {
int y = L; // farmland row; the floor row is below
box(rm.x1(), y, rm.z1(), rm.x2(), y, rm.z2(), Material.DIRT_PATH);
int[][] plots = {{-19, -8}, {-6, 5}, {7, 18}};
Material[] crops = {Material.BEETROOTS, Material.CARROTS, Material.POTATOES};
for (int i = 0; i < 3; i++) for (int x = plots[i][0]; x <= plots[i][1]; x++) {
for (int z = 13; z <= 19; z++) {
if (z == 16) { put(x, y, z, Material.WATER); continue; }
Farmland f = (Farmland) Material.FARMLAND.createBlockData(); f.setMoisture(7); data(x, y, z, f);
Ageable crop = (Ageable) crops[i].createBlockData();
crop.setAge(rng.nextInt(crop.getMaximumAge() + 1)); data(x, y + 1, z, crop);
}
}
for (int x = rm.x1() + 2; x <= rm.x2() - 2; x += 5) { lantern(x, y + 4, 14); lantern(x, y + 4, 18); }
}
}
}

View file

@ -0,0 +1,130 @@
package com.example.duneterrain;
import java.util.List;
import java.util.function.ToIntFunction;
/**
* Pure geometry for the three sietch tiers: placement grids, room boxes (relative to the anchor) and the organic
* pool shape. No Bukkit types, so it is unit-tested without a server.
*
* Every footprint is centred on the middle of its chunk so it stays inside the populator's 16-block margin.
*/
final class SietchLayout {
private SietchLayout() {}
enum Tier {
SMALL("small", 8, 600, 0x534d414c4c43454cL, 0),
MEDIUM("medium", 14, 900, 0x4d454449554d5753L, 1),
LARGE("large", 22, 2000, 0x534945544348L, 2); // LARGE keeps the legacy hash so existing anchors stay put
final String key; final int half, spacing, rank; final long salt;
Tier(String key, int half, int spacing, long salt, int rank) { this.key = key; this.half = half; this.spacing = spacing; this.salt = salt; this.rank = rank; }
String key() { return key; }
}
record Anchor(int x, int z, long id) {}
/** Interior box relative to the anchor, inclusive; {@code height} is the number of air blocks above the floor row. */
record Room(String kind, int x1, int z1, int x2, int z2, int height) {
boolean contains(int x, int z) { return x >= x1 && x <= x2 && z >= z1 && z <= z2; }
}
record Pool(int cx, int cz, int rx, int rz, int maxDepth) {}
// ---------- placement ----------
static long mix(long z) {
z = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9L; z = (z ^ (z >>> 27)) * 0x94D049BB133111EBL; return z ^ (z >>> 31);
}
/** The anchor of one grid cell, snapped to the centre of the chunk it falls in. */
static Anchor cellAnchor(Tier tier, int spacing, long cellX, long cellZ) {
long h1 = mix(cellX * 0x9E3779B97F4A7C15L ^ cellZ * 0xC2B2AE3D27D4EB4FL ^ tier.salt);
long h2 = mix(cellZ * 0x165667B19E3779F9L ^ cellX * 0x85EBCA77C2B2AE63L ^ ~tier.salt);
long ax = cellX * spacing + 8 + Math.floorMod(h1, spacing - 16), az = cellZ * spacing + 8 + Math.floorMod(h2, spacing - 16);
int cx = (int) Math.floorDiv(ax, 16), cz = (int) Math.floorDiv(az, 16);
return new Anchor(cx * 16 + 8, cz * 16 + 8, mix(h1 ^ h2 * 31));
}
/** The anchor for this chunk, or null when the chunk does not host one. */
static Anchor anchor(Tier tier, int spacing, int chunkX, int chunkZ) {
int centreX = chunkX * 16 + 8, centreZ = chunkZ * 16 + 8;
long cellX = Math.floorDiv(centreX, spacing), cellZ = Math.floorDiv(centreZ, spacing);
// the hosting cell can differ from the chunk's cell when the anchor is near a cell edge
for (long dx = -1; dx <= 1; dx++) for (long dz = -1; dz <= 1; dz++) {
Anchor a = cellAnchor(tier, spacing, cellX + dx, cellZ + dz);
if (a.x() == centreX && a.z() == centreZ) return a;
}
return null;
}
/** Larger tiers win; equal tiers are broken by anchor id. Distances keep footprints plus a margin apart. */
static boolean clear(Tier tier, Anchor anchor, ToIntFunction<Tier> spacingOf) {
for (Tier other : Tier.values()) {
if (other.rank < tier.rank) continue;
int spacing = spacingOf.applyAsInt(other);
long cellX = Math.floorDiv(anchor.x(), spacing), cellZ = Math.floorDiv(anchor.z(), spacing);
long limit = tier.half + other.half + 16;
for (long dx = -1; dx <= 1; dx++) for (long dz = -1; dz <= 1; dz++) {
Anchor o = cellAnchor(other, spacing, cellX + dx, cellZ + dz);
if (o.x() == anchor.x() && o.z() == anchor.z() && other == tier) continue;
long ddx = o.x() - anchor.x(), ddz = o.z() - anchor.z();
if (ddx * ddx + ddz * ddz >= limit * limit) continue;
if (other != tier) return false;
if (o.id() < anchor.id()) return false;
}
}
return true;
}
/** True when the whole footprint (shell included) lies inside the chunk plus its 16-block populate margin. */
static boolean fitsWindow(Tier tier, int anchorX, int anchorZ, int chunkX, int chunkZ) {
int reach = tier.half + 1;
return anchorX - reach >= chunkX * 16 - 16 && anchorX + reach <= chunkX * 16 + 31
&& anchorZ - reach >= chunkZ * 16 - 16 && anchorZ + reach <= chunkZ * 16 + 31;
}
// ---------- rooms (interior boxes relative to the anchor) ----------
static List<Room> rooms(Tier tier) {
return switch (tier) {
case SMALL -> List.of(new Room("chamber", -6, -3, 4, 3, 4), new Room("alcove", 6, -1, 7, 1, 3));
case MEDIUM -> List.of(
new Room("hall", -6, -4, 6, 4, 6),
new Room("sleeping", -11, -10, -5, -6, 4), new Room("bank", -3, -10, 3, -6, 4), new Room("kitchen", 5, -10, 11, -6, 4));
case LARGE -> List.of(
new Room("hall", -14, -9, 14, 10, 8),
new Room("sleeping", -19, -20, -11, -12, 4), new Room("sleeping", -9, -20, -1, -12, 4),
new Room("kitchen", 1, -20, 9, -12, 4), new Room("workshop", 11, -20, 19, -12, 4),
new Room("bank", -21, -8, -17, 2, 4), new Room("council", 17, -8, 21, 2, 4),
new Room("farm", -20, 13, 20, 20, 5));
};
}
static Pool pool(Tier tier) {
return switch (tier) {
case SMALL -> null;
case MEDIUM -> new Pool(0, 0, 4, 3, 3);
case LARGE -> new Pool(0, 1, 10, 7, 4);
};
}
/** Hall corner where the entrance stairwell descends (centre of its 3x3 ring), or null for the ladder-shaft tier. */
static int[] stairwell(Tier tier) {
return switch (tier) { case SMALL -> null; case MEDIUM -> new int[]{5, 3}; case LARGE -> new int[]{13, 9}; };
}
// ---------- organic pool ----------
private static double phase(long seed, int k) { return (mix(seed * 31 + k) >>> 11) / (double) (1L << 53) * Math.PI * 2; }
/** Water depth in blocks at an anchor-relative column: 0 outside the pool, 1 on the shallow shelf up to maxDepth in the middle. */
static int poolDepth(long seed, Pool pool, int dx, int dz) {
double x = (dx - pool.cx()) / (double) pool.rx(), z = (dz - pool.cz()) / (double) pool.rz();
double d = Math.sqrt(x * x + z * z);
if (d == 0) return pool.maxDepth();
double theta = Math.atan2(z, x);
double r = 1 + 0.12 * Math.sin(3 * theta + phase(seed, 1)) + 0.06 * Math.sin(5 * theta + phase(seed, 2));
double n = d / r;
if (n >= 1) return 0;
return Math.min(pool.maxDepth(), 1 + (int) ((1 - n) * pool.maxDepth()));
}
/** Outer reach of the pool along each axis, including the wobble. */
static int reachX(Pool p) { return (int) Math.ceil(p.rx() * 1.18); }
static int reachZ(Pool p) { return (int) Math.ceil(p.rz() * 1.18); }
}

View file

@ -8,12 +8,16 @@ server:
sietches:
enabled: true
spacing: 2000
# Additional sites only in Dune-highlands; open-desert grid stays unchanged.
highlands:
# Three tiers on separate grids. Larger tiers win when footprints would collide.
small: # hidden cell, no water
enabled: true
frequency-multiplier: 3
minimum-per-region: 3
spacing: 600
medium: # three rooms and a pool
enabled: true
spacing: 900
large: # cistern hall, big pool, six rooms and a farm
enabled: true
spacing: 2000
spice-blow:
enabled: true

View file

@ -1,5 +1,5 @@
name: DuneTerrain
version: 1.0.15-pillager1
version: 1.0.16-sietch1
main: com.example.duneterrain.DuneTerrain
api-version: '1.21'
load: STARTUP

View file

@ -12,31 +12,4 @@ class HighlandSietchesTest {
for(var a:sites){assertTrue(shape.depth(a.x(),a.z())>=.25);for(var b:sites)if(a!=b){int dx=a.x()-b.x(),dz=a.z()-b.z();assertTrue(dx*dx+dz*dz>=676);}}
}
}
@Test void highlandPopulationPlacesThreeSeparateCachesWithoutChangingDesertSpacing() throws Exception {
var plugin=org.mockito.Mockito.mock(DuneTerrain.class);
var config=new org.bukkit.configuration.file.YamlConfiguration();
org.mockito.Mockito.when(plugin.getConfig()).thenReturn(config);
var world=org.mockito.Mockito.mock(org.bukkit.generator.WorldInfo.class);
org.mockito.Mockito.when(world.getMinHeight()).thenReturn(-64);
org.mockito.Mockito.when(world.getMaxHeight()).thenReturn(320);
var region=org.mockito.Mockito.mock(org.bukkit.generator.LimitedRegion.class);
org.mockito.Mockito.when(region.getHighestBlockYAt(org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.anyInt())).thenReturn(110);
org.mockito.Mockito.when(region.isInRegion(org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.anyInt())).thenReturn(true);
var cls=Class.forName("com.example.duneterrain.DuneTerrain$SietchPopulator");
var constructor=cls.getDeclaredConstructor(DuneTerrain.class);constructor.setAccessible(true);
var populator=constructor.newInstance(plugin);
var method=cls.getDeclaredMethod("populateHighlands",org.bukkit.generator.WorldInfo.class,int.class,int.class,org.bukkit.generator.LimitedRegion.class);method.setAccessible(true);
int activeX=0,activeZ=0;outer:for(int ax=0;ax<8;ax++)for(int az=0;az<8;az++)if(RockPlateaus.activeCell(ax,az)){activeX=ax;activeZ=az;break outer;}
long seed=RockPlateaus.formationSeed(activeX,activeZ);
var shape=RockPlateaus.shape(seed,RockPlateaus.centerX(activeX,300,500),RockPlateaus.centerZ(activeZ,300,500),RockPlateaus.radius(seed,45,55),.02);
var chunks=new java.util.HashSet<String>();
for(var site:HighlandSietches.sites(shape,3,3))chunks.add(Math.floorDiv(site.x(),16)+","+Math.floorDiv(site.z(),16));
for(var chunk:chunks){var parts=chunk.split(",");method.invoke(populator,world,Integer.parseInt(parts[0]),Integer.parseInt(parts[1]),region);}
org.mockito.Mockito.verify(region,org.mockito.Mockito.times(3)).setType(org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.anyInt(),org.mockito.ArgumentMatchers.eq(org.bukkit.Material.CHEST));
config.set("sietches.highlands.enabled",false);
org.mockito.Mockito.clearInvocations(region);
method.invoke(populator,world,10,10,region);
org.mockito.Mockito.verifyNoInteractions(region);
assertFalse(config.contains("sietches.spacing"));
}
}

View file

@ -0,0 +1,91 @@
package com.example.duneterrain;
import static org.junit.jupiter.api.Assertions.*;
import com.example.duneterrain.SietchLayout.Tier;
import java.util.*;
import org.junit.jupiter.api.Test;
class SietchLayoutTest {
static int spacing(Tier t) { return t.spacing; }
@Test void anchorsAreDeterministicAndChunkCentred() {
for (Tier t : Tier.values()) for (int c = -3; c <= 3; c++) {
var a = SietchLayout.cellAnchor(t, t.spacing, c, -c);
assertEquals(a, SietchLayout.cellAnchor(t, t.spacing, c, -c));
assertEquals(8, Math.floorMod(a.x(), 16)); assertEquals(8, Math.floorMod(a.z(), 16));
}
}
@Test void everyAnchorIsFoundByExactlyItsOwnChunk() {
for (Tier t : Tier.values()) for (int cell = -2; cell <= 2; cell++) {
var a = SietchLayout.cellAnchor(t, t.spacing, cell, 3 - cell);
int cx = Math.floorDiv(a.x(), 16), cz = Math.floorDiv(a.z(), 16);
assertEquals(a, SietchLayout.anchor(t, t.spacing, cx, cz));
assertNull(SietchLayout.anchor(t, t.spacing, cx + 1, cz));
assertTrue(SietchLayout.fitsWindow(t, a.x(), a.z(), cx, cz));
}
}
@Test void clearRejectsOverlapsAndKeepsLargerTier() {
int checked = 0, rejected = 0;
for (long cx = -40; cx < 40; cx++) for (long cz = -40; cz < 40; cz++) {
var s = SietchLayout.cellAnchor(Tier.SMALL, Tier.SMALL.spacing, cx, cz);
boolean ok = SietchLayout.clear(Tier.SMALL, s, SietchLayoutTest::spacing);
checked++; if (!ok) rejected++;
for (long lx = -2; lx <= 2; lx++) for (long lz = -2; lz <= 2; lz++) {
var l = SietchLayout.cellAnchor(Tier.LARGE, Tier.LARGE.spacing, lx, lz);
long dx = l.x() - s.x(), dz = l.z() - s.z(), lim = Tier.SMALL.half + Tier.LARGE.half + 16;
if (dx * dx + dz * dz < lim * lim) assertFalse(ok);
}
}
assertTrue(checked > rejected);
var l = SietchLayout.cellAnchor(Tier.LARGE, Tier.LARGE.spacing, 0, 0);
assertTrue(SietchLayout.clear(Tier.LARGE, l, SietchLayoutTest::spacing));
}
@Test void roomsStayInsideTheFootprint() {
for (Tier t : Tier.values()) for (var r : SietchLayout.rooms(t)) {
for (int v : new int[]{r.x1() - 1, r.x2() + 1, r.z1() - 1, r.z2() + 1}) assertTrue(Math.abs(v) <= t.half, t + " " + r);
assertTrue(r.x1() <= r.x2() && r.z1() <= r.z2());
}
}
@Test void smallHasNoPoolMediumAndLargeDo() {
assertNull(SietchLayout.pool(Tier.SMALL)); assertNotNull(SietchLayout.pool(Tier.MEDIUM)); assertNotNull(SietchLayout.pool(Tier.LARGE));
assertEquals(3, SietchLayout.rooms(Tier.MEDIUM).size() - 1);
assertEquals(1L, SietchLayout.rooms(Tier.LARGE).stream().filter(r -> r.kind().equals("farm")).count());
}
@Test void poolIsOrganicInsideTheHallAndDeepestInTheMiddle() {
for (Tier t : new Tier[]{Tier.MEDIUM, Tier.LARGE}) {
var p = SietchLayout.pool(t); var hall = SietchLayout.rooms(t).get(0);
for (long seed = 1; seed <= 50; seed++) {
assertEquals(p.maxDepth(), SietchLayout.poolDepth(seed, p, p.cx(), p.cz()));
Set<Integer> depths = new TreeSet<>(); int wet = 0;
for (int x = hall.x1(); x <= hall.x2(); x++) for (int z = hall.z1(); z <= hall.z2(); z++) {
int d = SietchLayout.poolDepth(seed, p, x, z);
if (d > 0) { wet++; depths.add(d); assertTrue(d <= p.maxDepth()); }
}
assertTrue(wet > 20); assertTrue(depths.size() >= 3, "stepped shelf");
for (int x = p.cx() - SietchLayout.reachX(p) - 2; x <= p.cx() + SietchLayout.reachX(p) + 2; x++)
for (int z = p.cz() - SietchLayout.reachZ(p) - 2; z <= p.cz() + SietchLayout.reachZ(p) + 2; z++)
if (SietchLayout.poolDepth(seed, p, x, z) > 0) assertTrue(hall.contains(x, z), "pool inside hall with a rim");
}
assertNotEquals(poolMask(1, p), poolMask(2, p));
}
}
static String poolMask(long seed, SietchLayout.Pool p) {
StringBuilder b = new StringBuilder();
for (int x = -15; x <= 15; x++) for (int z = -12; z <= 12; z++) b.append(SietchLayout.poolDepth(seed, p, x, z) > 0 ? '1' : '0');
return b.toString();
}
@Test void stairwellFitsInsideTheHall() {
for (Tier t : new Tier[]{Tier.MEDIUM, Tier.LARGE}) {
var h = SietchLayout.rooms(t).get(0); var s = SietchLayout.stairwell(t);
assertTrue(h.contains(s[0] + 1, s[1] + 1) && h.contains(s[0] - 1, s[1] - 1));
}
assertNull(SietchLayout.stairwell(Tier.SMALL));
}
}

View file

@ -7,7 +7,7 @@ import sys
import zipfile
sys.path.insert(0,str(Path(__file__).resolve().parent))
from plugin_backend_abi import jar_classes
REVIEWED_TERRAIN_SHA256='b0777941e5c320e16731e447101b4157fb8af917951fc0e3128c4e6b73710b4f'
REVIEWED_TERRAIN_SHA256='d373aa5e0b83c85c8270f099df46bdb6343565434a20976de2f5ffff6ecf6748'
def verify_contract(path,fixture,require_hash=False):

View file

@ -249,6 +249,51 @@ def apply(value, controller, stamp=None):
raise
def regenerate_without_backup(value, controller):
if not controller.active():
raise ValueError('Arrakis must be running before regeneration')
world, dimension, target = map(Path, (value['world'], value['dimension'], value['target']))
controller.stop()
if controller.active():
raise RuntimeError('Arrakis service did not stop')
destructive = False
temporary = target.with_suffix('.incoming')
staged_here = False
try:
if digest(target) != value['previousSha256'] or digest(value['incoming']) != value['incomingSha256']:
raise ValueError('Terrain changed after planning')
verify_retained(value)
profiles = protected(world)
chunks = []
for name in CHUNKS:
for file in sorted(checked(dimension / name).iterdir()):
if not re.fullmatch(r'[rc]\.-?\d+\.-?\d+\.(?:mca|mcc)', file.name) or not checked(file).is_file():
raise ValueError('Unexpected entry in Arrakis chunk storage')
chunks.append(file)
with temporary.open('xb') as staged:
staged_here = True
with Path(value['incoming']).open('rb') as source:
shutil.copyfileobj(source, staged)
set_metadata(temporary, value['previousMetadata'])
if digest(temporary) != value['incomingSha256']:
raise ValueError('Staged Terrain hash mismatch')
os.replace(temporary, target)
destructive = True
for file in chunks:
file.unlink()
if protected(world) != profiles:
raise ValueError('Protected world/player data changed')
verify_retained(value)
controller.start()
return len(chunks)
except Exception:
if not destructive:
if staged_here:
temporary.unlink(missing_ok=True)
controller.start()
raise
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--root', required=True)
@ -256,8 +301,11 @@ def main():
parser.add_argument('--expected-source', required=True)
parser.add_argument('--expected-terrain-sha', default=OLD_TERRAIN_SHA)
parser.add_argument('--apply-reset', action='store_true')
parser.add_argument('--no-backup', action='store_true')
parser.add_argument('--rollback-receipt')
args = parser.parse_args()
if args.no_backup and (not args.apply_reset or args.rollback_receipt):
parser.error('--no-backup requires --apply-reset without rollback')
value = None
if args.rollback_receipt:
value = json.loads(Path(args.rollback_receipt).read_text())
@ -277,6 +325,9 @@ def main():
if args.rollback_receipt:
rollback(args.rollback_receipt, Service(checked(args.root)))
print('Receipt-backed Arrakis rollback completed; player metadata retained.')
elif args.no_backup:
removed = regenerate_without_backup(value, Service(checked(args.root)))
print(f'Removed {removed} Arrakis chunk files; awaiting Paper readiness.')
else:
print('Receipt:', apply(value, Service(checked(args.root))))