Replace Arrakis fortress and add abandoned Fremen village
All checks were successful
DuneRealms Resourcepack CI / resourcepack (push) Successful in 1m56s
DuneRealms Plugin CI / plugins (push) Successful in 3m16s

This commit is contained in:
unimatrixgit 2026-11-29 22:48:55 +01:00
commit bc8b2b2a00
16 changed files with 957 additions and 83 deletions

View file

@ -8,7 +8,8 @@ DuneRealms terrain runs on Java 21. Build with `gradle build`; install `build/li
- **Dense Spice** (`dunerealms:dense-spice`): one 30 × 30 rich patch per 512-block placement region, with seed-dependent positions. This is configurable village-like density, not vanilla village placement. Deep orange terracotta represents finite rich spice sand. Each authentic deposit yields four existing tagged Melange Spice items by default. Silk Touch and Fortune cannot clone or multiply it; creative mining consumes the deposit without a reward. A chunk Persistent Data Container stores each deposit's position and removes it on harvest. Ordinary orange terracotta has no spice value. Pistons and explosions cannot move or duplicate registered deposits. Ledger state persists in normal chunk saves across restarts; restoring a world backup restores its historical deposits too.
- A persistent spice seller appears in the centre of each new rich field. Right-click opens the shared native menu and offers 16 tagged spice at **standard DuneEss price × 1.35**. At 15 Solaris each, 16 cost 324 Solaris. Existing spice sales, taxes and CHOAM trading remain unchanged. Confirming purchases checks distance, inventory capacity and successful economy withdrawal.
- **Desert villages**: custom four-house sandstone settlements, with cut-sandstone lanes, villagers, beds, non-farming workstations, lanterns and finite shared supply chests. No farmland, crops or hay bales enter the structure palette. Chests use `dunerealms:chests/desert-village`: bread, dried kelp, apples and raw iron. Placement regions default to 768 blocks, with terrain suitability checks.
- **Old Harkonnen Fortress**: a custom jungle-temple-style Arrakis adaptation with sandstone walls, darkstone pillars, a stepped roof, red banner, stair and underground loot vault. It is a custom layout, not a replacement of Minecraft's built-in jungle temple structure definition. The default attempt rate is one per 1,000 Arrakis chunks, matching the Java desert-well-style chance; uneven terrain can reject an attempt. Its finite chest uses `dunerealms:chests/old-harkonnen-fortress`. When loot is generated, DuneTerrain appends a complete Harkonnen kit from the updated DuneCore kit factory: red faction stillsuit, native equipment attributes and trim, and the enchanted spice shovel. Food and raw iron also come from the loot table. Install updated Core and Terrain together; without the updated Core API, fortress rewards fall back to basic sword/food rather than fabricated faction equipment.
- **Harkonnen garrison fortress** (pillager-outpost mechanic): a walled black-stone fortress with four searchlight towers, a three-storey keep (barracks, armoury, command room, roof), a landing pad, a cell block, a supply depot and a vault under the keep. Placement copies the vanilla pillager outpost: one attempt per 32x32-chunk region, 8 chunks of separation, 20% frequency (`harkonnen-fortress.spacing-chunks|separation-chunks|frequency`). Harkonnen pillagers (8 guards plus a commander, black dyed armour, no bad-omen banner) are spawned when a player comes near and replaced after `respawn-seconds`. The vault chest is filled on first open with one Harkonnen stillsuit piece plus 3 random valuables (Maker's Tooth when supported by DuneCore, refined spice, spice block, smuggler shovel, etc.; override with `harkonnen-fortress.loot`). Chests from the old temple-style fortress keep their loot rules.
- **Abandoned Fremen village**: always generated beside a Harkonnen outpost (one of eight fixed offsets chosen from the outpost id): a dry cistern, broken windtrap, six sand-drifted sandstone and terracotta houses with faded Fremen-blue cloth, dry qanat channels and two caches. No villagers, no farmland.
Arrakis generates small, medium, and large sietches on separate grids with default spacing of 600, 900, and 2,000 blocks. Larger tiers take priority when footprints overlap. Each tier has independent `enabled` and `spacing` settings under `sietches`. Placement applies as chunks generate.
@ -31,7 +32,7 @@ worlds:
Set `server.planet` in `plugins/DuneTerrain/config.yml` to `arrakis`, `giedi_prime`, `kaitain`, `caladan` or `sigma_draconis_iv`. Public Velocity server names may use hyphens; these internal planet IDs keep underscores. A separate planet world created by the plugin gets its generator and biome provider directly.
Existing configurations receive the new features through code defaults. Old radius defaults 10/18 automatically upgrade to 45/55; customized radii are retained. `planets.arrakis.highlands` now controls formation enablement, density and mountain rise. The old `darkstone-islands` radius and terrace settings remain compatible, but its old `spacing` and `enabled` values no longer control highlands. Use `highlands.enabled` to disable the replacement. New density options are `dense-spice.spacing`, `desert-villages.spacing` and `harkonnen-fortress.rarity`.
Existing configurations receive the new features through code defaults. Old radius defaults 10/18 automatically upgrade to 45/55; customized radii are retained. `planets.arrakis.highlands` now controls formation enablement, density and mountain rise. The old `darkstone-islands` radius and terrace settings remain compatible, but its old `spacing` and `enabled` values no longer control highlands. Use `highlands.enabled` to disable the replacement. New density options are `dense-spice.spacing`, `desert-villages.spacing` and `harkonnen-fortress.frequency`.
DuneNPC continues to own Guild Navigators. Install updated DuneCore and DuneEss alongside Terrain for authentic fortress kits and native spice-seller purchases.

View file

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

View file

@ -0,0 +1,174 @@
package com.example.duneterrain;
import java.util.*;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.data.*;
import org.bukkit.block.data.type.*;
import org.bukkit.generator.*;
import org.bukkit.persistence.PersistentDataType;
/**
* Abandoned Fremen settlement that always stands next to a Harkonnen outpost (see {@link StructureGrid}): a dry
* cistern, a broken windtrap, six sand-drifted adobe houses in sandstone, terracotta and faded Fremen blue, and
* dry qanat channels. No villagers and no farmland. Caches are rolled on first open by {@link StructureCaches}.
*/
final class AbandonedVillages extends BlockPopulator {
private final DuneTerrain plugin;
AbandonedVillages(DuneTerrain plugin) { this.plugin = plugin; }
@Override public void populate(WorldInfo world, Random random, int cx, int cz, LimitedRegion region) {
var c = plugin.getConfig();
if (!world.getName().equalsIgnoreCase("arrakis") || !c.getBoolean("harkonnen-fortress.enabled", true) || !c.getBoolean("abandoned-villages.enabled", true)) return;
var anchor = StructureGrid.village(world.getSeed(), HarkonnenFortress.spacing(c), HarkonnenFortress.separation(c), HarkonnenFortress.frequency(c), cx, cz);
if (anchor == null) return;
new Site(region, anchor, world.getMinHeight(), world.getMaxHeight()).run();
}
private static final Material SAND = Material.SAND, WALLM = Material.SANDSTONE, TRIM = Material.CUT_SANDSTONE, DRY = Material.BROWN_TERRACOTTA;
private final class Site {
final LimitedRegion r; final int ax, az, minY, maxY; final long id; final Random rng; int P;
Site(LimitedRegion r, SietchLayout.Anchor a, int minY, int maxY) { this.r = r; this.ax = a.x(); this.az = a.z(); this.id = a.id(); this.minY = minY; this.maxY = maxY; this.rng = new Random(a.id()); }
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 hy(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 facing(Material m, BlockFace f) { BlockData d = m.createBlockData(); if (d instanceof Directional dir) dir.setFacing(f); return d; }
BlockFace face(int[] v) { return v[0] > 0 ? BlockFace.EAST : v[0] < 0 ? BlockFace.WEST : v[1] > 0 ? BlockFace.SOUTH : BlockFace.NORTH; }
void run() {
P = hy(0, 0);
Material top = r.getType(ax, P, az);
if (top == Material.WATER || top == Material.LAVA || top == Material.ICE || top == Material.PACKED_ICE) return;
if (P - 6 <= minY || P + 16 >= maxY) return;
plaza(); channels(); windtrap();
for (int i = 0; i < RuinsPlan.HOUSES.size(); i++) house(i, RuinsPlan.HOUSES.get(i));
banners(); debris();
}
// ---------- plaza and dry cistern ----------
void plaza() {
for (int dx = -RuinsPlan.PLAZA_RADIUS; dx <= RuinsPlan.PLAZA_RADIUS; dx++) for (int dz = -RuinsPlan.PLAZA_RADIUS; dz <= RuinsPlan.PLAZA_RADIUS; dz++) {
if (dx * dx + dz * dz > RuinsPlan.PLAZA_RADIUS * RuinsPlan.PLAZA_RADIUS) continue;
int g = hy(dx, dz);
for (int y = P + 1; y <= g + 1; y++) put(dx, y, dz, Material.AIR);
for (int y = g; y < P; y++) put(dx, y, dz, SAND);
boolean paved = SietchLayout.mix(id ^ dx * 31L ^ dz * 17L) % 5 < 3;
put(dx, P, dz, paved ? TRIM : SAND);
int depth = RuinsPlan.basinDepth(dx, dz);
if (depth > 0) {
box(dx, P - depth, dz, dx, P, dz, Material.AIR);
put(dx, P - depth - 1, dz, depth == 3 ? Material.RED_TERRACOTTA : DRY);
if (RuinsPlan.drift(id, dx, dz) > 0) put(dx, P - depth, dz, SAND);
}
}
for (int s : new int[]{-1, 1}) { put(s * 6, P + 1, 0, Material.SANDSTONE_WALL); put(0, P + 1, s * 6, Material.SANDSTONE_WALL); }
}
void channels() {
for (int[] ch : RuinsPlan.CHANNELS) for (int i = 0; i < ch[4]; i++) {
int x = ch[0] + ch[2] * i, z = ch[1] + ch[3] * i;
put(x, P - 1, z, Material.SMOOTH_SANDSTONE); put(x, P, z, Material.AIR);
if (rng.nextInt(10) < 4) put(x, P, z, SAND);
for (int s : new int[]{-1, 1}) put(x + ch[3] * s, P, z + ch[2] * s, Material.SMOOTH_SANDSTONE_SLAB);
}
}
// ---------- broken windtrap ----------
void windtrap() {
int tx = RuinsPlan.WINDTRAP_X, tz = RuinsPlan.WINDTRAP_Z, height = 7 + rng.nextInt(5);
for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++) {
int g = hy(tx + dx, tz + dz);
for (int y = g; y < P; y++) put(tx + dx, y, tz + dz, SAND);
put(tx + dx, P, tz + dz, TRIM);
for (int y = P + 1; y <= P + height; y++) {
boolean edge = Math.abs(dx) == 2 || Math.abs(dz) == 2;
boolean vent = edge && y >= P + 3 && (y - P) % 2 == 1 && (Math.abs(dx) + Math.abs(dz)) % 2 == 1;
double broken = y > P + 4 ? (y - P - 4) * 0.13 : 0.04;
put(tx + dx, y, tz + dz, !edge || vent || rng.nextDouble() < broken ? Material.AIR : y == P + height && (dx + dz) % 2 == 0 ? TRIM : WALLM);
}
}
box(tx - 2, P + 1, tz, tx - 2, P + 2, tz, Material.AIR); // doorway toward the plaza
put(tx, P + 1, tz, Material.CHEST);
data(tx, P + 1, tz, facing(Material.CHEST, BlockFace.WEST));
cache(tx, P + 1, tz);
put(tx - 1, P + 1, tz, SAND);
}
// ---------- houses ----------
void house(int index, RuinsPlan.House h) {
boolean collapsed = RuinsPlan.collapsed(id, index);
int base = Math.max(P - 4, Math.min(P + 4, hy(h.cx(), h.cz())));
for (int x = h.x1(); x <= h.x2(); x++) for (int z = h.z1(); z <= h.z2(); z++) {
for (int y = hy(x, z); y < base; y++) put(x, y, z, WALLM);
for (int y = base + 1; y <= base + 8; y++) put(x, y, z, Material.AIR);
put(x, base, z, TRIM);
}
int[] door = h.door();
for (int x = h.x1(); x <= h.x2(); x++) for (int z = h.z1(); z <= h.z2(); z++) {
boolean wall = x == h.x1() || x == h.x2() || z == h.z1() || z == h.z2();
boolean corner = (x == h.x1() || x == h.x2()) && (z == h.z1() || z == h.z2());
if (wall) {
for (int y = 1; y <= 4; y++) {
if (rng.nextDouble() < RuinsPlan.erosion(y, collapsed)) continue;
put(x, base + y, z, y == 4 || corner ? TRIM : (y == 1 ? Material.TERRACOTTA : WALLM));
}
} else if (!collapsed && rng.nextInt(10) < 6) put(x, base + 5, z, Material.SMOOTH_SANDSTONE_SLAB);
if (!wall && !collapsed && rng.nextInt(10) < 3) put(x, base + 5, z, TRIM);
if (!wall) { int d = RuinsPlan.drift(id, x, z); for (int y = 1; y <= d; y++) put(x, base + y, z, SAND); }
}
int dx = h.cx() + door[0] * 3, dz = h.cz() + door[1] * 3;
box(dx, base + 1, dz, dx, base + 2, dz, Material.AIR);
put(dx, base + 3, dz, Material.LIGHT_BLUE_TERRACOTTA);
for (int s : new int[]{-1, 1}) put(dx + door[1] * s, base + 2, dz + door[0] * s, Material.LIGHT_BLUE_TERRACOTTA);
furnish(index, h, base, collapsed);
}
void furnish(int index, RuinsPlan.House h, int base, boolean collapsed) {
int ix = h.x1() + 1, iz = h.z1() + 1, fx = h.x2() - 1, fz = h.z2() - 1;
if (RuinsPlan.drift(id, ix, iz) < 2) put(ix, base + 1, iz, Material.BARREL);
put(fx, base + 1, iz, Material.COMPOSTER);
if (index % 2 == 0) { for (int x = ix + 1; x <= fx - 1; x++) put(x, base + 1, fz, Material.LIGHT_BLUE_CARPET); }
put(ix, base + 1, fz, Material.DEAD_BUSH);
if (rng.nextInt(3) == 0) put(fx - 1, base + 2, iz, Material.COBWEB);
if (!collapsed && index == 3) {
put(fx, base + 1, fz, Material.CHEST);
data(fx, base + 1, fz, facing(Material.CHEST, face(new int[]{-h.door()[0], -h.door()[1]})));
cache(fx, base + 1, fz);
}
}
void cache(int dx, int y, int dz) {
int x = ax + dx, z = az + dz;
if (r.isInRegion(x, y, z) && r.getBlockState(x, y, z) instanceof Chest chest) {
chest.setCustomName("Abandoned Fremen Cache");
chest.getPersistentDataContainer().set(StructureCaches.KEY, PersistentDataType.STRING, StructureCaches.RUIN);
chest.getPersistentDataContainer().set(StructureCaches.SEED, PersistentDataType.LONG, id ^ dx * 31L ^ dz);
chest.update(true, false);
}
}
void banners() {
for (int[] p : new int[][]{{4, 4}, {-4, 4}, {-4, -4}, {4, -4}}) {
if (rng.nextInt(3) == 0) continue;
put(p[0], P + 1, p[1], Material.SANDSTONE_WALL);
Rotatable b = (Rotatable) Material.LIGHT_BLUE_BANNER.createBlockData(); b.setRotation(new BlockFace[]{BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH_EAST}[rng.nextInt(4)]);
data(p[0], P + 2, p[1], b);
}
}
void debris() {
for (int i = 0; i < 40; i++) {
int x = rng.nextInt(41) - 20, z = rng.nextInt(41) - 20;
if (RuinsPlan.HOUSES.stream().anyMatch(h -> h.contains(x, z))) continue;
int g = hy(x, z);
int kind = rng.nextInt(4);
if (kind == 0) put(x, g + 1, z, Material.DEAD_BUSH);
else if (kind == 1) put(x, g + 1, z, Material.SANDSTONE_SLAB);
else if (kind == 2) { put(x, g + 1, z, Material.SANDSTONE_WALL); put(x, g + 2, z, Material.SANDSTONE_WALL); }
}
}
}
}

View file

@ -109,6 +109,6 @@ public final class ArrakisEcology implements Listener {
}catch(ReflectiveOperationException failure){plugin.getLogger().severe("Native Arrakis item definition unavailable: "+failure.getClass().getSimpleName());}
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void cook(BlockCookEvent event){if(!event.getBlock().getWorld().getName().equalsIgnoreCase("arrakis"))return;String source=itemId(event.getSource());String result="jerboa_raw_meat".equals(source)?"jerboa_cooked_meat":"chukka_raw_meat".equals(source)?"chukka_cooked_meat":null;if(result==null)return;try{event.setResult(items.build(result));}catch(ReflectiveOperationException failure){event.setCancelled(true);plugin.getLogger().warning("Fauna cooking definition unavailable; input retained");}}
private static ItemStack item(String id)throws ReflectiveOperationException{var score=Bukkit.getPluginManager().getPlugin("SCore");if(score==null||!score.isEnabled())throw new ReflectiveOperationException("Native item engine unavailable");var loader=score.getClass().getClassLoader();var api=loader.loadClass("com.ssomar.score.api.executableitems.ExecutableItemsAPI");var manager=api.getMethod("getExecutableItemsManager").invoke(null);var managerAPI=loader.loadClass("com.ssomar.score.api.executableitems.config.ExecutableItemsManagerInterface");var definition=(Optional<?>)managerAPI.getMethod("getExecutableItem",String.class).invoke(manager,id);if(definition.isEmpty())throw new ReflectiveOperationException("Missing native item definition");var itemAPI=loader.loadClass("com.ssomar.score.api.executableitems.config.ExecutableItemInterface");var built=(ItemStack)itemAPI.getMethod("buildItem",int.class,Optional.class,Optional.class).invoke(definition.get(),1,Optional.empty(),Optional.empty());var origin=built.getItemMeta();origin.getPersistentDataContainer().set(new NamespacedKey("dunerealms","origin_world"),PersistentDataType.STRING,"arrakis");built.setItemMeta(origin);var translator=Bukkit.getPluginManager().getPlugin("JarvisTranslator");if(translator!=null&&translator.isEnabled())try{translator.getClass().getMethod("markCreatedItem",ItemStack.class).invoke(translator,built);}catch(NoSuchMethodException olderTranslator){/* Old translators still receive the stable origin field. */}return built;}
static ItemStack item(String id)throws ReflectiveOperationException{var score=Bukkit.getPluginManager().getPlugin("SCore");if(score==null||!score.isEnabled())throw new ReflectiveOperationException("Native item engine unavailable");var loader=score.getClass().getClassLoader();var api=loader.loadClass("com.ssomar.score.api.executableitems.ExecutableItemsAPI");var manager=api.getMethod("getExecutableItemsManager").invoke(null);var managerAPI=loader.loadClass("com.ssomar.score.api.executableitems.config.ExecutableItemsManagerInterface");var definition=(Optional<?>)managerAPI.getMethod("getExecutableItem",String.class).invoke(manager,id);if(definition.isEmpty())throw new ReflectiveOperationException("Missing native item definition");var itemAPI=loader.loadClass("com.ssomar.score.api.executableitems.config.ExecutableItemInterface");var built=(ItemStack)itemAPI.getMethod("buildItem",int.class,Optional.class,Optional.class).invoke(definition.get(),1,Optional.empty(),Optional.empty());var origin=built.getItemMeta();origin.getPersistentDataContainer().set(new NamespacedKey("dunerealms","origin_world"),PersistentDataType.STRING,"arrakis");built.setItemMeta(origin);var translator=Bukkit.getPluginManager().getPlugin("JarvisTranslator");if(translator!=null&&translator.isEnabled())try{translator.getClass().getMethod("markCreatedItem",ItemStack.class).invoke(translator,built);}catch(NoSuchMethodException olderTranslator){/* Old translators still receive the stable origin field. */}return built;}
@EventHandler public void disable(PluginDisableEvent event){if(event.getPlugin()!=plugin)return;INSTANCES.remove(plugin);if(jerboas!=null)jerboas.close();for(var world:Bukkit.getWorlds())for(var wolf:world.getEntitiesByClass(Wolf.class))if(pet(wolf)){modifier(wolf,Attribute.ATTACK_DAMAGE,DAMAGE,false);modifier(wolf,Attribute.MAX_HEALTH,HEALTH,false);wolf.setHealth(Math.min(wolf.getHealth(),wolf.getAttribute(Attribute.MAX_HEALTH).getValue()));}}
}

View file

@ -0,0 +1,38 @@
package com.example.duneterrain;
import java.util.*;
/** Pure weighted loot rolling for structure caches; the Bukkit side turns picks into ItemStacks. */
final class CacheLoot {
private CacheLoot() {}
/** source: "vanilla" (id is a Material name), "ei" (ExecutableItems id) or "tooth" (Maker's Tooth from DuneCore). */
record Entry(String source, String id, int weight, int min, int max) {
int amount(Random rnd) { return min >= max ? Math.max(1, min) : min + rnd.nextInt(max - min + 1); }
}
record Pick(Entry entry, int amount) {}
static Entry parse(Map<?, ?> m) {
String source = String.valueOf(m.containsKey("source") ? m.get("source") : "vanilla").toLowerCase(Locale.ROOT);
String id = String.valueOf(m.get("id"));
int weight = num(m.get("weight"), 1), min = num(m.get("min"), 1), max = num(m.get("max"), min);
return new Entry(source, id, Math.max(0, weight), Math.max(1, min), Math.max(Math.max(1, min), max));
}
private static int num(Object o, int fallback) { return o instanceof Number n ? n.intValue() : fallback; }
/** {@code rolls} distinct entries by weight, without replacement. */
static List<Pick> roll(Random rnd, List<Entry> entries, int rolls) {
List<Entry> pool = new ArrayList<>();
for (Entry e : entries) if (e.weight() > 0) pool.add(e);
List<Pick> out = new ArrayList<>();
for (int i = 0; i < rolls && !pool.isEmpty(); i++) {
int total = 0; for (Entry e : pool) total += e.weight();
int roll = rnd.nextInt(total), at = 0;
for (int k = 0; k < pool.size(); k++) {
at += pool.get(k).weight();
if (roll < at) { var e = pool.remove(k); out.add(new Pick(e, e.amount(rnd))); break; }
}
}
return out;
}
}

View file

@ -300,6 +300,12 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
PlanetMobs.start(this);StarterRepairDrops.start(this);TrailsBridge.start(this);if(getConfig().getString("server.planet","arrakis").equalsIgnoreCase("arrakis"))ArrakisEcology.start(this);
getServer().getPluginManager().registerEvents(new DenseSpice(this), this);
getServer().getPluginManager().registerEvents(new HarkonnenFortress(this), this);
if (getConfig().getString("server.planet", "arrakis").equalsIgnoreCase("arrakis")) {
getServer().getPluginManager().registerEvents(new StructureCaches(this), this);
FortressGarrison garrison = new FortressGarrison(this);
getServer().getPluginManager().registerEvents(garrison, this);
garrison.start();
}
sietchLootIdKey = new NamespacedKey(this, "sietch-loot-id");
String planet = getConfig().getString("server.planet", "arrakis").toLowerCase(Locale.ROOT);
@ -378,7 +384,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener {
PlanetChunkGenerator(DuneTerrain plugin, String planet) { this.plugin = plugin; this.planet = planet; }
@Override public List<BlockPopulator> getDefaultPopulators(World world) {
return planet.equals("arrakis") && world.getName().equalsIgnoreCase("arrakis")
? List.of(new SietchPopulator(plugin), new SpiceBlowPopulator(plugin), new DesertVillages(plugin), new HarkonnenFortress(plugin),plugin.spiceProvenance) : List.of();
? List.of(new SietchPopulator(plugin), new SpiceBlowPopulator(plugin), new DesertVillages(plugin), new HarkonnenFortress(plugin), new AbandonedVillages(plugin), plugin.spiceProvenance) : List.of();
}
@Override public void generateNoise(WorldInfo world, Random random, int chunkX, int chunkZ, ChunkData data) {
if(TemperateLandscape.enabled(planet)){

View file

@ -0,0 +1,135 @@
package com.example.duneterrain;
import java.util.*;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Chest;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
/**
* Pillager-outpost mechanic for the Harkonnen fortress: while a player is near a loaded outpost, Harkonnen pillagers
* (and one commander) are kept up to strength, and killed guards are replaced after a cooldown. No bad-omen captain banner,
* so killing the commander does not start vanilla raids. Sites are found when their vault chunk loads.
*/
final class FortressGarrison implements Listener {
private record Site(World world, int x, int y, int z) { long key() { return ((long) (x >> 4) << 32) ^ ((z >> 4) & 0xffffffffL); } }
private final DuneTerrain plugin;
private final NamespacedKey guardKey, commanderKey;
private final Map<String, Site> sites = new HashMap<>();
private final Map<String, Long> cooldownUntil = new HashMap<>();
private final Set<String> missing = new HashSet<>();
private BukkitTask task;
FortressGarrison(DuneTerrain plugin) {
this.plugin = plugin;
guardKey = new NamespacedKey(plugin, "harkonnen_guard"); commanderKey = new NamespacedKey(plugin, "harkonnen_commander");
}
void start() { task = Bukkit.getScheduler().runTaskTimer(plugin, this::tick, 200L, 20L * plugin.getConfig().getInt("harkonnen-fortress.garrison.check-seconds", 20)); }
void stop() { if (task != null) task.cancel(); }
private String id(Site s) { return s.world().getName() + ":" + s.x() + ":" + s.z(); }
@EventHandler public void load(ChunkLoadEvent e) {
if (!e.getWorld().getName().equalsIgnoreCase("arrakis") || e.isNewChunk()) return;
var anchor = HarkonnenFortress.outpostAt(plugin.getConfig(), e.getWorld().getSeed(), e.getChunk().getX(), e.getChunk().getZ());
if (anchor != null) register(e.getWorld(), anchor);
}
@EventHandler public void unload(ChunkUnloadEvent e) {
sites.values().removeIf(s -> s.world().equals(e.getWorld()) && (s.x() >> 4) == e.getChunk().getX() && (s.z() >> 4) == e.getChunk().getZ());
}
/** Called by the tick for newly generated chunks too, via a delayed scan of chunks that host an outpost. */
private void register(World w, SietchLayout.Anchor anchor) {
String mark = w.getName() + ":" + anchor.x() + ":" + anchor.z();
if (missing.contains(mark)) return;
for (int y = w.getMinHeight() + 4; y < w.getMaxHeight() - 4; y++) {
var state = w.getBlockAt(anchor.x() + FortressPlan.CHEST_X, y, anchor.z() + FortressPlan.CHEST_Z).getState(false);
if (state instanceof Chest chest && StructureCaches.VAULT.equals(chest.getPersistentDataContainer().get(StructureCaches.KEY, PersistentDataType.STRING))) {
Site s = new Site(w, anchor.x(), y + 4, anchor.z());
sites.put(id(s), s);
return;
}
}
missing.add(mark);
}
private void tick() {
var c = plugin.getConfig();
if (!c.getBoolean("harkonnen-fortress.garrison.enabled", true)) return;
int cap = Math.max(0, c.getInt("harkonnen-fortress.garrison.guards", 8)), radius = Math.max(16, c.getInt("harkonnen-fortress.garrison.activation-radius", 72));
long cooldown = c.getLong("harkonnen-fortress.garrison.respawn-seconds", 600) * 1000L, now = System.currentTimeMillis();
for (World w : Bukkit.getWorlds()) {
if (!w.getName().equalsIgnoreCase("arrakis")) continue;
for (Player p : w.getPlayers()) { // pick up sites whose chunk is already loaded around a player
int pcx = p.getLocation().getBlockX() >> 4, pcz = p.getLocation().getBlockZ() >> 4;
for (int dx = -4; dx <= 4; dx++) for (int dz = -4; dz <= 4; dz++) {
if (!w.isChunkLoaded(pcx + dx, pcz + dz)) continue;
var a = HarkonnenFortress.outpostAt(c, w.getSeed(), pcx + dx, pcz + dz);
if (a != null && !sites.containsKey(w.getName() + ":" + a.x() + ":" + a.z())) register(w, a);
}
}
}
for (Site s : new ArrayList<>(sites.values())) {
var center = new Location(s.world(), s.x() + 0.5, s.y(), s.z() + 0.5);
if (s.world().getNearbyPlayers(center, radius).isEmpty()) continue;
int have = 0; boolean commander = false;
for (Entity e : s.world().getNearbyEntities(center, 30, 24, 30, en -> en instanceof Pillager)) {
var pdc = e.getPersistentDataContainer();
if (pdc.has(guardKey, PersistentDataType.BYTE)) have++;
if (pdc.has(commanderKey, PersistentDataType.BYTE)) commander = true;
}
if (have >= cap && commander) continue;
Long until = cooldownUntil.get(id(s));
if (until != null && now < until) continue;
if (have == 0 && !commander && until == null) { fill(s, cap); cooldownUntil.put(id(s), now); continue; } // first activation spawns immediately
fill(s, cap);
cooldownUntil.put(id(s), now + cooldown);
}
}
private void fill(Site s, int cap) {
Random rnd = new Random(s.key());
int have = 0; boolean commander = false;
for (Entity e : s.world().getNearbyEntities(new Location(s.world(), s.x(), s.y(), s.z()), 30, 24, 30, en -> en instanceof Pillager)) {
if (e.getPersistentDataContainer().has(guardKey, PersistentDataType.BYTE)) have++;
if (e.getPersistentDataContainer().has(commanderKey, PersistentDataType.BYTE)) commander = true;
}
int pad = s.y();
if (!commander) spawn(s, FortressPlan.COMMANDER, pad, true);
List<FortressPlan.Post> posts = new ArrayList<>(FortressPlan.GUARDS);
Collections.shuffle(posts, rnd);
for (int i = 0; have < cap && i < posts.size(); i++, have++) spawn(s, posts.get(i), pad, false);
}
private void spawn(Site s, FortressPlan.Post post, int p, boolean commander) {
int y = switch (post.level()) { case 1 -> p + FortressPlan.TOWER_HEIGHT + 1; case 2 -> p + 6; case 3 -> p + 1; default -> p + 1; };
var loc = new Location(s.world(), s.x() + post.x() + 0.5, y, s.z() + post.z() + 0.5);
if (!s.world().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) return;
s.world().spawn(loc, Pillager.class, g -> {
g.getPersistentDataContainer().set(commander ? commanderKey : guardKey, PersistentDataType.BYTE, (byte) 1);
if (commander) g.getPersistentDataContainer().set(guardKey, PersistentDataType.BYTE, (byte) 1);
g.customName(net.kyori.adventure.text.Component.text(commander ? "Harkonnen Commander" : "Harkonnen Guard",
commander ? net.kyori.adventure.text.format.NamedTextColor.DARK_RED : net.kyori.adventure.text.format.NamedTextColor.GRAY));
g.setCustomNameVisible(false); g.setPersistent(true); g.setRemoveWhenFarAway(false); g.setCanJoinRaid(false); g.setPatrolLeader(false);
var max = g.getAttribute(Attribute.MAX_HEALTH);
if (max != null) { max.setBaseValue(commander ? 48 : 28); g.setHealth(commander ? 48 : 28); }
EntityEquipment eq = g.getEquipment();
eq.setHelmet(dyed(Material.LEATHER_HELMET, 0x1b1b1f)); eq.setChestplate(dyed(Material.LEATHER_CHESTPLATE, commander ? 0x5b0d12 : 0x232329));
eq.setLeggings(dyed(Material.LEATHER_LEGGINGS, 0x1b1b1f)); eq.setBoots(dyed(Material.LEATHER_BOOTS, 0x111114));
eq.setHelmetDropChance(0f); eq.setChestplateDropChance(0f); eq.setLeggingsDropChance(0f); eq.setBootsDropChance(0f);
});
}
private static ItemStack dyed(Material m, int rgb) {
ItemStack i = new ItemStack(m); LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta(); meta.setColor(Color.fromRGB(rgb)); i.setItemMeta(meta); return i;
}
}

View file

@ -0,0 +1,34 @@
package com.example.duneterrain;
import java.util.List;
/** Pure geometry of the Harkonnen garrison fortress, relative to its anchor (x east, z south, gate on the south wall). */
final class FortressPlan {
private FortressPlan() {}
record Box(String name, int x1, int z1, int x2, int z2) {
boolean overlaps(Box o) { return x1 <= o.x2 && x2 >= o.x1 && z1 <= o.z2 && z2 >= o.z1; }
boolean contains(int x, int z) { return x >= x1 && x <= x2 && z >= z1 && z <= z2; }
}
/** Guard post: level 0 = courtyard ground, 1 = tower top, 2 = keep upper floor, 3 = keep ground floor. */
record Post(int x, int z, int level) {}
static final int WALL = 16, TOWER_HEIGHT = 11;
static final int[][] TOWERS = {{-WALL, -WALL}, {WALL, -WALL}, {-WALL, WALL}, {WALL, WALL}};
/** Outer boxes of the courtyard buildings; none may overlap. The vault sits under the keep. */
static final Box KEEP = new Box("keep", -7, -13, 7, -1), PAD = new Box("pad", -13, 3, -5, 11),
CELLS = new Box("cells", 5, 2, 13, 9), DEPOT = new Box("depot", 5, 11, 13, 14), GATE = new Box("gate", -2, 15, 2, 16);
static final List<Box> BUILDINGS = List.of(KEEP, PAD, CELLS, DEPOT);
/** Vault interior (relative x/z) and chest position, below the keep. */
static final int VAULT_X1 = -6, VAULT_X2 = 6, VAULT_Z1 = -12, VAULT_Z2 = -4, CHEST_X = 0, CHEST_Z = -11;
static final List<Post> GUARDS = List.of(
new Post(-3, 6, 0), new Post(3, 6, 0), new Post(0, -0, 0), new Post(10, 0, 0), new Post(-10, 0, 0),
new Post(-16, -16, 1), new Post(16, -16, 1), new Post(-16, 16, 1), new Post(16, 16, 1),
new Post(-3, -6, 3), new Post(3, -6, 3));
static final Post COMMANDER = new Post(0, -8, 2);
static boolean insideCourtyard(int x, int z) { return Math.abs(x) <= WALL - 2 && Math.abs(z) <= WALL - 2; }
}

View file

@ -1,66 +1,265 @@
package com.example.duneterrain;
import java.util.*;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.data.*;
import org.bukkit.block.data.type.*;
import org.bukkit.event.*;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.generator.*;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import org.bukkit.persistence.PersistentDataType;
/** Arrakis temple adaptation: stepped roof, upper chamber, stair and buried vault. */
/**
* House Harkonnen garrison fortress (pillager-outpost mechanic): walled, black polished stone, four searchlight towers,
* a three-storey keep with barracks, armoury and command room, a landing pad, a cell block and a vault under the keep.
* Garrison pillagers are spawned and topped up by {@link FortressGarrison}; vault loot is rolled on first open by {@link StructureCaches}.
*/
final class HarkonnenFortress extends BlockPopulator implements Listener {
static final NamespacedKey LOOT=new NamespacedKey("dunerealms","chests/old-harkonnen-fortress");
/** Key of the previous temple-style fortress; chests it already generated keep their loot rules. */
static final NamespacedKey LOOT = new NamespacedKey("dunerealms", "chests/old-harkonnen-fortress");
static final int SPACING_DEFAULT = 32, SEPARATION_DEFAULT = 8;
static final double FREQUENCY_DEFAULT = 0.2;
private final DuneTerrain plugin;
HarkonnenFortress(DuneTerrain plugin) { this.plugin=plugin; }
static boolean attempt(long seed,int cx,int cz,int rarity) {
return Math.floorMod(DenseSpice.mix(seed^cx*0x9e3779b97f4a7c15L^cz*0xc2b2ae3d27d4eb4fL^0x4841524b4f4e4e45L),Math.max(1,rarity))==0;
HarkonnenFortress(DuneTerrain plugin) { this.plugin = plugin; }
static int spacing(org.bukkit.configuration.file.FileConfiguration c) { return Math.max(4, c.getInt("harkonnen-fortress.spacing-chunks", SPACING_DEFAULT)); }
static int separation(org.bukkit.configuration.file.FileConfiguration c) { return Math.max(0, Math.min(spacing(c) - 1, c.getInt("harkonnen-fortress.separation-chunks", SEPARATION_DEFAULT))); }
static double frequency(org.bukkit.configuration.file.FileConfiguration c) { return Math.max(0, Math.min(1, c.getDouble("harkonnen-fortress.frequency", FREQUENCY_DEFAULT))); }
static SietchLayout.Anchor outpostAt(org.bukkit.configuration.file.FileConfiguration c, long seed, int cx, int cz) {
return StructureGrid.outpost(seed, spacing(c), separation(c), frequency(c), cx, cz);
}
@Override public void populate(WorldInfo world,Random random,int cx,int cz,LimitedRegion r) {
if(!world.getName().equalsIgnoreCase("arrakis")||!plugin.getConfig().getBoolean("harkonnen-fortress.enabled",true)
|| !attempt(world.getSeed(),cx,cz,plugin.getConfig().getInt("harkonnen-fortress.rarity",1000)))return;
int x=cx*16+8,z=cz*16+8,y=r.getHighestBlockYAt(x,z);
if(y-7<=world.getMinHeight()||y+10>=world.getMaxHeight())return;
for(int dx:new int[]{-7,7})for(int dz:new int[]{-8,8})
if(!r.isInRegion(x+dx,y,z+dz)||Math.abs(r.getHighestBlockYAt(x+dx,z+dz)-y)>6)return;
// Jungle-temple proportions translated into sandstone and Harkonnen dark stone.
for(int dx=-6;dx<=6;dx++)for(int dz=-7;dz<=7;dz++)for(int dy=-6;dy<=6;dy++) {
boolean shell=dy==-6||dy==0||dy==6||Math.abs(dx)==6||Math.abs(dz)==7;
Material m=shell?((dx+dz+dy)%5==0?Material.CRACKED_POLISHED_BLACKSTONE_BRICKS:Material.SANDSTONE):Material.AIR;
r.setType(x+dx,y+dy,z+dz,m);
}
for(int level=0;level<3;level++)for(int dx=-5+level;dx<=5-level;dx++)for(int dz=-6+level;dz<=6-level;dz++)
r.setType(x+dx,y+7+level,z+dz,Material.CUT_SANDSTONE);
for(int dx:new int[]{-5,5})for(int dz:new int[]{-6,6})for(int dy=1;dy<=5;dy++)r.setType(x+dx,y+dy,z+dz,Material.POLISHED_BLACKSTONE_BRICKS);
for(int dy=1;dy<=3;dy++)r.setType(x,y+dy,z-7,Material.AIR);
for(int step=0;step<6;step++) {
r.setType(x-3,y-step,z+4-step,Material.SANDSTONE);
for(int clear=1;clear<=3;clear++)r.setType(x-3,y-step+clear,z+4-step,Material.AIR);
}
r.setType(x+3,y-5,z+3,Material.CHEST);
if(r.getBlockState(x+3,y-5,z+3) instanceof Chest chest) {
chest.setCustomName("Old Harkveen Fortress");
var table=Bukkit.getLootTable(LOOT);
if(table!=null){chest.setLootTable(table);chest.setSeed(DenseSpice.mix(world.getSeed()^cx^((long)cz<<32)));}
else for(ItemStack item:kit())chest.getSnapshotInventory().addItem(item);
chest.update(true,false);
}
// Ruined red banner and lanterns, no moss, jungle trees, farms or hay.
r.setType(x,y+4,z-8,Material.RED_WALL_BANNER);
var banner=Material.RED_WALL_BANNER.createBlockData();
((org.bukkit.block.data.Directional)banner).setFacing(org.bukkit.block.BlockFace.NORTH);
r.setBlockData(x,y+4,z-8,banner);
r.setType(x+3,y-2,z+3,Material.LANTERN);
@Override public void populate(WorldInfo world, Random random, int cx, int cz, LimitedRegion region) {
if (!world.getName().equalsIgnoreCase("arrakis") || !plugin.getConfig().getBoolean("harkonnen-fortress.enabled", true)) return;
var anchor = outpostAt(plugin.getConfig(), world.getSeed(), cx, cz);
if (anchor == null) return;
new Site(region, anchor, world.getMinHeight(), world.getMaxHeight()).run();
}
@SuppressWarnings("unchecked") private List<ItemStack> kit() {
var core=Bukkit.getPluginManager().getPlugin("DuneCore");
if(core!=null && core.isEnabled())try {
return (List<ItemStack>)core.getClass().getMethod("createFactionKit",String.class).invoke(core,"Harkonnen");
}catch(ReflectiveOperationException ex){plugin.getLogger().warning("Harkveen kit requires updated DuneCore: "+ex.getMessage());}
return List.of(new ItemStack(Material.IRON_SWORD),new ItemStack(Material.BREAD,8));
/** Pre-existing chests from the old temple keep working: add the faction kit to their generated loot. */
@EventHandler(ignoreCancelled = true) public void loot(LootGenerateEvent e) {
if (!e.getLootTable().getKey().equals(LOOT)) return;
List<ItemStack> items = new ArrayList<>(e.getLoot());
items.addAll(StructureCaches.coreKit("Harkonnen"));
e.setLoot(items);
}
@EventHandler(ignoreCancelled=true) public void loot(LootGenerateEvent e) {
if(!e.getLootTable().getKey().equals(LOOT))return;
List<ItemStack> items=new ArrayList<>(e.getLoot());items.addAll(kit());e.setLoot(items);
private static final Material BR = Material.POLISHED_BLACKSTONE_BRICKS, PLINTH = Material.BLACKSTONE, ACC = Material.CHISELED_POLISHED_BLACKSTONE,
F1 = Material.POLISHED_BLACKSTONE, F2 = Material.DEEPSLATE_TILES, AIR = Material.AIR;
private final class Site {
final LimitedRegion r; final int ax, az, minY, maxY; final long id; int P;
Site(LimitedRegion r, SietchLayout.Anchor a, int minY, int maxY) { this.r = r; this.ax = a.x(); this.az = a.z(); this.id = a.id(); this.minY = minY; this.maxY = maxY; }
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 hy(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);
}
/** Hollow stone box: shell material on all faces, air inside. Rows y1..y2 are the interior. */
void room(int x1, int z1, int x2, int z2, int y1, int y2, Material shell, Material floor, Material ceil) {
box(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1, shell);
box(x1 - 1, y1 - 1, z1 - 1, x2 + 1, y1 - 1, z2 + 1, floor);
box(x1 - 1, y2 + 1, z1 - 1, x2 + 1, y2 + 1, z2 + 1, ceil);
box(x1, y1, z1, x2, y2, z2, AIR);
}
BlockData facing(Material m, BlockFace f) { BlockData d = m.createBlockData(); if (d instanceof Directional dir) dir.setFacing(f); return d; }
BlockData stairs(Material m, BlockFace f) { Stairs s = (Stairs) m.createBlockData(); s.setFacing(f); return s; }
void lantern(int dx, int y, int dz, boolean hanging, Material m) { Lantern l = (Lantern) m.createBlockData(); l.setHanging(hanging); data(dx, y, dz, l); }
void lamp(int dx, int y, int dz) { Lightable l = (Lightable) Material.REDSTONE_LAMP.createBlockData(); l.setLit(true); data(dx, y, dz, l); }
void bed(int fx, int y, int fz) {
Bed foot = (Bed) Material.BLACK_BED.createBlockData(); foot.setFacing(BlockFace.NORTH); foot.setPart(Bed.Part.FOOT);
Bed head = (Bed) Material.BLACK_BED.createBlockData(); head.setFacing(BlockFace.NORTH); head.setPart(Bed.Part.HEAD);
data(fx, y, fz, foot); data(fx, y, fz - 1, head);
}
void banner(int dx, int y, int dz, BlockFace f) { data(dx, y, dz, facing(Material.RED_WALL_BANNER, f)); }
void run() {
int sum = 0, n = 0;
for (int dx = -18; dx <= 18; dx += 6) for (int dz = -18; dz <= 18; dz += 6) { sum += hy(dx, dz); n++; }
Material top = r.getType(ax, hy(0, 0), az);
if (top == Material.WATER || top == Material.LAVA || top == Material.ICE || top == Material.PACKED_ICE) return;
P = Math.round(sum / (float) n);
if (P - 12 <= minY || P + 18 >= maxY) return;
terrain(); courtyard(); wall(); gate(); for (int[] t : FortressPlan.TOWERS) tower(t[0], t[1]);
keep(); vault(); pad(); cells(); depot();
}
// ---------- ground ----------
void terrain() {
for (int dx = -20; dx <= 20; dx++) for (int dz = -20; dz <= 20; dz++) {
int g = hy(dx, dz);
boolean skirt = Math.max(Math.abs(dx), Math.abs(dz)) > 17;
for (int y = g + 1; y <= Math.max(g, P + 14); y++) if (y > P || !skirt) put(dx, y, dz, AIR);
for (int y = g; y < P; y++) put(dx, y, dz, skirt ? Material.SANDSTONE : PLINTH);
if (g != P && !skirt || g < P) put(dx, P, dz, skirt ? Material.SAND : F1);
}
}
void courtyard() {
for (int dx = -14; dx <= 14; dx++) for (int dz = -14; dz <= 14; dz++)
put(dx, P, dz, (Math.floorDiv(dx, 2) + Math.floorDiv(dz, 2)) % 2 == 0 ? F1 : F2);
for (int dz = 0; dz <= 16; dz++) for (int dx = -1; dx <= 1; dx++) put(dx, P, dz, Material.POLISHED_BASALT);
}
// ---------- perimeter ----------
void wall() {
for (int dx = -17; dx <= 17; dx++) for (int dz = -17; dz <= 17; dz++) {
int d = Math.max(Math.abs(dx), Math.abs(dz));
if (d < 15 || d > 16 || Math.min(Math.abs(dx), Math.abs(dz)) > 15) continue;
box(dx, P + 1, dz, dx, P + 2, dz, PLINTH); box(dx, P + 3, dz, dx, P + 6, dz, BR);
if ((dx + dz) % 2 == 0) put(dx, P + 7, dz, BR);
}
}
void gate() {
box(-2, P + 1, 15, 2, P + 7, 16, AIR);
box(-3, P + 5, 15, 3, P + 6, 16, BR); box(-1, P + 5, 15, 1, P + 5, 16, ACC);
for (int s : new int[]{-3, 3}) { box(s, P + 1, 15, s, P + 9, 16, ACC); lantern(s, P + 10, 15, false, Material.SOUL_LANTERN); }
for (int s : new int[]{-2, 2}) lantern(s, P + 4, 15, true, Material.SOUL_LANTERN);
banner(-5, P + 5, 14, BlockFace.NORTH); banner(5, P + 5, 14, BlockFace.NORTH);
}
void tower(int tx, int tz) {
int sx = tx < 0 ? -1 : 1;
box(tx - 2, P + 1, tz - 2, tx + 2, P + 2, tz + 2, PLINTH);
box(tx - 2, P + 3, tz - 2, tx + 2, P + FortressPlan.TOWER_HEIGHT, tz + 2, BR);
box(tx - 1, P + 1, tz - 1, tx + 1, P + FortressPlan.TOWER_HEIGHT - 1, tz + 1, AIR);
box(tx - 2, P + FortressPlan.TOWER_HEIGHT, tz - 2, tx + 2, P + FortressPlan.TOWER_HEIGHT, tz + 2, F2);
for (int dx = -2; dx <= 2; dx++) for (int dz = -2; dz <= 2; dz++)
if ((Math.abs(dx) == 2 || Math.abs(dz) == 2) && (dx + dz) % 2 == 0) put(tx + dx, P + FortressPlan.TOWER_HEIGHT + 1, tz + dz, BR);
box(tx - 2, P + FortressPlan.TOWER_HEIGHT + 1, tz - 2, tx - 2, P + FortressPlan.TOWER_HEIGHT + 1, tz - 2, ACC);
// searchlight: a lit lamp stack on a pedestal
put(tx, P + FortressPlan.TOWER_HEIGHT + 1, tz, ACC); lamp(tx, P + FortressPlan.TOWER_HEIGHT + 2, tz);
box(tx - sx * 2, P + 1, tz, tx - sx * 2, P + 2, tz, AIR); // door toward the courtyard
int lx = tx + sx; // ladder against the outer wall
Ladder ladder = (Ladder) Material.LADDER.createBlockData(); ladder.setFacing(sx < 0 ? BlockFace.EAST : BlockFace.WEST);
for (int y = P + 1; y <= P + FortressPlan.TOWER_HEIGHT; y++) data(lx, y, tz, ladder);
put(lx, P + FortressPlan.TOWER_HEIGHT, tz, AIR); data(lx, P + FortressPlan.TOWER_HEIGHT, tz, ladder);
lantern(tx - sx, P + FortressPlan.TOWER_HEIGHT - 1, tz, true, Material.SOUL_LANTERN);
for (int y = P + 4; y <= P + 8; y += 4) put(tx, y, tz + (tz < 0 ? -2 : 2), Material.BLACK_STAINED_GLASS_PANE); // slit windows
}
// ---------- keep ----------
void keep() {
var K = FortressPlan.KEEP;
box(K.x1(), P, K.z1(), K.x2(), P, K.z2(), F2);
room(K.x1() + 1, K.z1() + 1, K.x2() - 1, K.z2() - 1, P + 1, P + 4, BR, F2, F1);
room(K.x1() + 1, K.z1() + 1, K.x2() - 1, K.z2() - 1, P + 6, P + 9, BR, F2, F2);
box(K.x1(), P + 1, K.z1(), K.x2(), P + 2, K.z2(), PLINTH);
box(K.x1() + 1, P + 1, K.z1() + 1, K.x2() - 1, P + 2, K.z2() - 1, AIR);
box(K.x1() + 1, P + 1, K.z1() + 1, K.x2() - 1, P + 4, K.z2() - 1, AIR);
box(K.x1() + 1, P + 5, K.z1() + 1, K.x2() - 1, P + 5, K.z2() - 1, F1);
box(K.x1() + 1, P + 6, K.z1() + 1, K.x2() - 1, P + 9, K.z2() - 1, AIR);
for (int x = K.x1(); x <= K.x2(); x++) for (int z = K.z1(); z <= K.z2(); z++)
if ((x == K.x1() || x == K.x2() || z == K.z1() || z == K.z2()) && (x + z) % 2 == 0) put(x, P + 11, z, BR);
box(-1, P + 1, -1, 1, P + 3, -1, AIR); // entrance
box(-2, P + 1, -1, -2, P + 4, -1, ACC); box(2, P + 1, -1, 2, P + 4, -1, ACC); box(-1, P + 4, -1, 1, P + 4, -1, ACC);
for (int x : new int[]{-5, -2, 2, 5}) for (int y : new int[]{P + 3, P + 8}) { put(x, y, -13, Material.BLACK_STAINED_GLASS_PANE); if (x != -2 && x != 2 || y != P + 3) put(x, y, -1, Material.BLACK_STAINED_GLASS_PANE); }
for (int z : new int[]{-10, -6}) for (int y : new int[]{P + 3, P + 8}) { put(-7, y, z, Material.BLACK_STAINED_GLASS_PANE); put(7, y, z, Material.BLACK_STAINED_GLASS_PANE); }
banner(-5, P + 6, 0, BlockFace.SOUTH); banner(5, P + 6, 0, BlockFace.SOUTH);
groundFloor(); upperFloor(); roof();
}
void groundFloor() {
for (int x : new int[]{-6, -4}) for (int z : new int[]{-3, -6, -9}) bed(x, P + 1, z);
put(-5, P + 1, -3, Material.BARREL); put(-5, P + 1, -9, Material.BARREL);
Material[] bench = {Material.SMITHING_TABLE, Material.GRINDSTONE, Material.ANVIL, Material.BLAST_FURNACE, Material.BARREL, Material.BARREL};
for (int i = 0; i < bench.length; i++) put(1 + i, P + 1, -12, bench[i]);
for (int z = -11; z <= -9; z++) put(6, P + 1, z, Material.BARREL);
for (int z = -2; z >= -11; z -= 3) { lantern(-1, P + 4, z, true, Material.SOUL_LANTERN); lantern(1, P + 4, z, true, Material.SOUL_LANTERN); }
// stairs: up to the command room (x=6) and down to the vault (x=5)
for (int j = 0; j < 5; j++) {
box(6, P + 2 + j, -3 - j, 6, P + 4 + j, -3 - j, AIR);
data(6, P + 1 + j, -3 - j, stairs(Material.POLISHED_BLACKSTONE_BRICK_STAIRS, BlockFace.SOUTH));
}
for (int i = 0; i < 5; i++) {
box(5, P - i + 1, -3 - i, 5, P + 3, -3 - i, AIR);
data(5, P - i, -3 - i, stairs(Material.POLISHED_BLACKSTONE_BRICK_STAIRS, BlockFace.SOUTH));
}
}
void upperFloor() {
put(0, P + 6, -12, Material.LECTERN); put(-2, P + 6, -12, Material.CARTOGRAPHY_TABLE); put(2, P + 6, -12, Material.LOOM);
for (int x = -3; x <= 3; x++) put(x, P + 6, -7, Material.BLACKSTONE_SLAB);
for (int z = -10; z <= -3; z++) if (z != -7) put(0, P + 6, z, Material.RED_CARPET);
for (int x : new int[]{-4, 0, 4}) banner(x, P + 8, -12, BlockFace.SOUTH);
for (int z : new int[]{-3, -8}) { lantern(-3, P + 9, z, true, Material.SOUL_LANTERN); lantern(3, P + 9, z, true, Material.SOUL_LANTERN); }
put(-5, P + 6, -4, Material.BARREL); put(-5, P + 6, -11, Material.BARREL);
box(-6, P + 6, -11, -6, P + 6, -9, Material.BOOKSHELF);
Ladder ladder = (Ladder) Material.LADDER.createBlockData(); ladder.setFacing(BlockFace.SOUTH);
for (int y = P + 6; y <= P + 10; y++) data(5, y, -12, ladder);
put(5, P + 10, -12, AIR); data(5, P + 10, -12, ladder);
}
void roof() {
box(-6, P + 10, -12, 6, P + 10, -2, F2); put(5, P + 10, -12, AIR);
Ladder ladder = (Ladder) Material.LADDER.createBlockData(); ladder.setFacing(BlockFace.SOUTH);
data(5, P + 10, -12, ladder);
data(0, P + 11, -7, ((Lightable) Material.SOUL_CAMPFIRE.createBlockData()));
for (int x : new int[]{-6, 6}) for (int z : new int[]{-12, -2}) { box(x, P + 11, z, x, P + 13, z, ACC); lantern(x, P + 14, z, false, Material.SOUL_LANTERN); }
}
// ---------- vault under the keep ----------
void vault() {
int x1 = FortressPlan.VAULT_X1, x2 = FortressPlan.VAULT_X2, z1 = FortressPlan.VAULT_Z1, z2 = FortressPlan.VAULT_Z2;
box(x1 - 1, P - 5, z1 - 1, x2 + 1, P - 1, z2 + 1, BR);
box(x1 - 1, P - 5, z1 - 1, x2 + 1, P - 5, z2 + 1, F2);
box(x1, P - 4, z1, x2, P - 1, z2, AIR);
for (int i = 0; i < 5; i++) { // re-cut the stair shaft the shell covered
box(5, P - i + 1, -3 - i, 5, P + 3, -3 - i, AIR);
data(5, P - i, -3 - i, stairs(Material.POLISHED_BLACKSTONE_BRICK_STAIRS, BlockFace.SOUTH));
}
for (int z = -11; z <= -5; z += 2) for (int x : new int[]{-6, 6}) box(x, P - 4, z, x, P - 1, z, ACC);
for (int z = -11; z <= -6; z++) put(0, P - 4, z, Material.RED_CARPET);
lantern(-3, P - 1, -11, true, Material.SOUL_LANTERN); lantern(3, P - 1, -11, true, Material.SOUL_LANTERN); lantern(0, P - 1, -7, true, Material.SOUL_LANTERN);
put(-2, P - 4, -11, Material.RAW_GOLD_BLOCK); put(2, P - 4, -11, Material.RAW_GOLD_BLOCK);
put(-5, P - 4, -11, Material.BARREL); put(5, P - 4, -11, Material.BARREL); put(5, P - 4, -10, Material.BARREL);
banner(-3, P - 2, -12 + 0, BlockFace.SOUTH);
int cx = ax + FortressPlan.CHEST_X, cy = P - 4, cz = az + FortressPlan.CHEST_Z;
put(FortressPlan.CHEST_X, cy, FortressPlan.CHEST_Z, Material.CHEST);
data(FortressPlan.CHEST_X, cy, FortressPlan.CHEST_Z, facing(Material.CHEST, BlockFace.SOUTH));
if (r.isInRegion(cx, cy, cz) && r.getBlockState(cx, cy, cz) instanceof Chest chest) {
chest.setCustomName("Harkonnen Armoury Vault");
chest.getPersistentDataContainer().set(StructureCaches.KEY, PersistentDataType.STRING, StructureCaches.VAULT);
chest.getPersistentDataContainer().set(StructureCaches.SEED, PersistentDataType.LONG, id);
chest.update(true, false);
}
}
// ---------- courtyard buildings ----------
void pad() {
var B = FortressPlan.PAD;
box(B.x1(), P, B.z1(), B.x2(), P, B.z2(), Material.SMOOTH_BASALT);
for (int x = B.x1(); x <= B.x2(); x++) for (int z : new int[]{B.z1(), B.z2()}) if ((x - B.x1()) % 2 == 0) put(x, P, z, Material.REDSTONE_LAMP);
for (int z = B.z1(); z <= B.z2(); z++) for (int x : new int[]{B.x1(), B.x2()}) if ((z - B.z1()) % 2 == 0) put(x, P, z, Material.REDSTONE_LAMP);
for (int x = B.x1(); x <= B.x2(); x++) for (int z : new int[]{B.z1(), B.z2()}) if ((x - B.x1()) % 2 == 0) lampAt(x, z);
for (int z = B.z1(); z <= B.z2(); z++) for (int x : new int[]{B.x1(), B.x2()}) if ((z - B.z1()) % 2 == 0) lampAt(x, z);
int cx = (B.x1() + B.x2()) / 2, cz = (B.z1() + B.z2()) / 2;
box(cx - 1, P, cz - 1, cx + 1, P, cz + 1, ACC);
put(cx, P, cz, Material.GILDED_BLACKSTONE);
box(B.x1(), P + 1, B.z1() - 1, B.x1(), P + 2, B.z1() - 1, Material.POLISHED_BLACKSTONE_WALL);
}
void lampAt(int x, int z) { lamp(x, P, z); }
void cells() {
var B = FortressPlan.CELLS;
room(B.x1() + 1, B.z1() + 1, B.x2() - 1, B.z2() - 1, P + 1, P + 4, BR, F2, F1);
box(B.x1(), P + 1, B.z1(), B.x2(), P + 2, B.z2(), PLINTH);
box(B.x1() + 1, P + 1, B.z1() + 1, B.x2() - 1, P + 4, B.z2() - 1, AIR);
box(B.x1(), P + 1, B.z1() + 5, B.x1(), P + 3, B.z1() + 6, AIR); // west door onto the courtyard side
for (int x : new int[]{8, 11}) box(x, P + 1, 3, x, P + 4, 5, BR); // dividing walls
for (int x : new int[]{6, 7, 9, 10, 12}) { // chain fronts, one open doorway per cell
if (x == 6 || x == 9 || x == 12) continue;
for (int y = P + 1; y <= P + 4; y++) put(x, y, 6, Material.CHAIN);
}
for (int x : new int[]{6, 9, 12}) { put(x, P + 1, 3, Material.BARREL); lantern(x, P + 4, 4, true, Material.SOUL_LANTERN); }
put(12, P + 1, 3, Material.BARREL);
}
void depot() {
var B = FortressPlan.DEPOT;
for (int x = B.x1() + 1; x <= B.x2() - 1; x += 2) for (int z = B.z1(); z <= B.z2(); z += 2) { put(x, P + 1, z, Material.BARREL); if ((x + z) % 4 == 0) put(x, P + 2, z, Material.BARREL); }
for (int x = B.x1(); x <= B.x2(); x += 8) box(x, P + 1, B.z2(), x, P + 3, B.z2(), PLINTH);
lantern(B.x1(), P + 4, B.z2(), false, Material.SOUL_LANTERN);
}
}
}

View file

@ -0,0 +1,37 @@
package com.example.duneterrain;
import java.util.List;
/** Pure geometry of the abandoned Fremen settlement, relative to its anchor. */
final class RuinsPlan {
private RuinsPlan() {}
record House(int cx, int cz) {
int x1() { return cx - 3; } int x2() { return cx + 3; } int z1() { return cz - 3; } int z2() { return cz + 3; }
boolean contains(int x, int z) { return x >= x1() && x <= x2() && z >= z1() && z <= z2(); }
boolean overlaps(House o) { return x1() <= o.x2() && x2() >= o.x1() && z1() <= o.z2() && z2() >= o.z1(); }
/** Unit vector of the wall that faces the plaza (the door). */
int[] door() { return Math.abs(cx) > Math.abs(cz) ? new int[]{cx > 0 ? -1 : 1, 0} : new int[]{0, cz > 0 ? -1 : 1}; }
}
static final int BASIN_RADIUS = 5, PLAZA_RADIUS = 11, WINDTRAP_X = 10, WINDTRAP_Z = 0;
static final List<House> HOUSES = List.of(new House(-14, -10), new House(0, -16), new House(14, -10),
new House(-14, 9), new House(1, 15), new House(15, 9));
/** Dry irrigation channels from the basin rim: {x, z, dx, dz, length}. */
static final List<int[]> CHANNELS = List.of(new int[]{0, -6, 0, -1, 6}, new int[]{0, 6, 0, 1, 6}, new int[]{-6, 0, -1, 0, 5});
/** Basin depth at a plaza column: 0 outside, up to 3 in the middle. */
static int basinDepth(int x, int z) {
double d = Math.sqrt((double) x * x + (double) z * z);
return d <= 2.2 ? 3 : d <= 4.2 ? 2 : d <= BASIN_RADIUS + 0.5 ? 1 : 0;
}
/** Chance that a wall block at height h (1..4 above the base) is gone. */
static double erosion(int h, boolean collapsed) { return collapsed ? 0.35 + 0.15 * h : 0.05 + 0.12 * h; }
/** Deterministic 0..2 block sand drift at a column. */
static int drift(long id, int x, int z) {
long h = SietchLayout.mix(id ^ (x * 0x9E3779B97F4A7C15L) ^ (z * 0xC2B2AE3D27D4EB4FL));
int v = (int) Math.floorMod(h, 10);
return v < 4 ? 0 : v < 8 ? 1 : 2;
}
static boolean collapsed(long id, int house) { return Math.floorMod(SietchLayout.mix(id ^ house * 0x51ed27L), 3L) == 0; }
}

View file

@ -0,0 +1,112 @@
package com.example.duneterrain;
import java.util.*;
import java.util.logging.Level;
import org.bukkit.*;
import org.bukkit.block.Chest;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.*;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
/**
* Loot for structure chests, rolled the first time a chest is opened (no datapack needed). The vault always holds one
* Harkonnen stillsuit piece plus a few random valuables. Entries come from config ({@code harkonnen-fortress.loot} and
* {@code abandoned-villages.loot}); defaults are built in. A chest is filled exactly once.
*/
final class StructureCaches implements Listener {
static NamespacedKey KEY, SEED, FILLED;
static final String VAULT = "harkonnen_vault", RUIN = "ruin_cache";
private final DuneTerrain plugin;
StructureCaches(DuneTerrain plugin) {
this.plugin = plugin;
KEY = new NamespacedKey(plugin, "structure_cache"); SEED = new NamespacedKey(plugin, "structure_cache_seed"); FILLED = new NamespacedKey(plugin, "structure_cache_filled");
}
static List<CacheLoot.Entry> defaults(String kind) {
List<CacheLoot.Entry> l = new ArrayList<>();
if (kind.equals(VAULT)) {
l.add(new CacheLoot.Entry("tooth", "maker_tooth", 12, 1, 1));
l.add(new CacheLoot.Entry("ei", "refined_spice", 30, 2, 5));
l.add(new CacheLoot.Entry("ei", "spice_block", 10, 1, 2));
l.add(new CacheLoot.Entry("ei", "refined_smuggled_spice", 14, 1, 3));
l.add(new CacheLoot.Entry("ei", "dr_smuggler_shovel", 12, 1, 1));
l.add(new CacheLoot.Entry("kit-shovel", "shovel", 10, 1, 1));
l.add(new CacheLoot.Entry("vanilla", "GOLD_INGOT", 20, 8, 24));
l.add(new CacheLoot.Entry("vanilla", "DIAMOND", 10, 1, 3));
l.add(new CacheLoot.Entry("vanilla", "ENCHANTED_GOLDEN_APPLE", 3, 1, 1));
} else {
l.add(new CacheLoot.Entry("vanilla", "DRIED_KELP", 20, 4, 12));
l.add(new CacheLoot.Entry("vanilla", "RAW_IRON", 12, 2, 6));
l.add(new CacheLoot.Entry("vanilla", "LEATHER", 12, 2, 6));
l.add(new CacheLoot.Entry("vanilla", "GOLD_NUGGET", 14, 4, 16));
l.add(new CacheLoot.Entry("ei", "jerboa_water_vial", 14, 1, 2));
l.add(new CacheLoot.Entry("ei", "dunesponge", 10, 1, 2));
l.add(new CacheLoot.Entry("ei", "jerboa_hide", 10, 1, 3));
l.add(new CacheLoot.Entry("ei", "smuggled_spice", 6, 1, 2));
}
return l;
}
static List<CacheLoot.Entry> entries(FileConfiguration c, String kind) {
String path = kind.equals(VAULT) ? "harkonnen-fortress.loot" : "abandoned-villages.loot";
List<CacheLoot.Entry> l = new ArrayList<>();
for (Map<?, ?> m : c.getMapList(path)) try { l.add(CacheLoot.parse(m)); } catch (RuntimeException ignored) { }
return l.isEmpty() ? defaults(kind) : l;
}
/** All pieces of the faction kit from DuneCore, empty when DuneCore is unavailable. */
@SuppressWarnings("unchecked") static List<ItemStack> coreKit(String faction) {
var core = Bukkit.getPluginManager().getPlugin("DuneCore");
if (core != null && core.isEnabled()) try { return (List<ItemStack>) core.getClass().getMethod("createFactionKit", String.class).invoke(core, faction); }
catch (ReflectiveOperationException ex) { Bukkit.getLogger().warning("Harkonnen kit unavailable: " + ex.getMessage()); }
return List.of();
}
static boolean isStillsuit(ItemStack i) {
return i != null && i.hasItemMeta() && "stillsuit".equals(i.getItemMeta().getPersistentDataContainer().get(new NamespacedKey("dunerealms", "item"), PersistentDataType.STRING));
}
ItemStack build(CacheLoot.Pick p) {
var e = p.entry();
try {
switch (e.source()) {
case "ei": { ItemStack i = ArrakisEcology.item(e.id()); i.setAmount(Math.min(i.getMaxStackSize(), p.amount())); return i; }
case "tooth": {
var core = Bukkit.getPluginManager().getPlugin("DuneCore");
if (core == null || !core.isEnabled()) return null;
ItemStack i = (ItemStack) core.getClass().getMethod("createMakerTooth").invoke(core); i.setAmount(p.amount()); return i;
}
case "kit-shovel": for (ItemStack i : coreKit("Harkonnen")) if (i.getType() == Material.NETHERITE_SHOVEL) return i; return null;
default: { Material m = Material.matchMaterial(e.id()); return m == null ? null : new ItemStack(m, Math.min(m.getMaxStackSize(), p.amount())); }
}
} catch (ReflectiveOperationException | RuntimeException ex) {
plugin.getLogger().log(Level.WARNING, "Cache item '" + e.id() + "' skipped: " + ex.getMessage());
return null;
}
}
@EventHandler(ignoreCancelled = true) public void open(InventoryOpenEvent event) {
if (!(event.getInventory().getHolder() instanceof Chest chest)) return;
var pdc = chest.getPersistentDataContainer();
String kind = pdc.get(KEY, PersistentDataType.STRING);
if (kind == null || pdc.has(FILLED, PersistentDataType.BYTE)) return;
pdc.set(FILLED, PersistentDataType.BYTE, (byte) 1); chest.update(true, false);
Random rnd = new Random(Objects.requireNonNullElse(pdc.get(SEED, PersistentDataType.LONG), 0L));
List<ItemStack> items = new ArrayList<>();
if (kind.equals(VAULT)) {
List<ItemStack> suits = new ArrayList<>();
for (ItemStack i : coreKit("Harkonnen")) if (isStillsuit(i)) suits.add(i);
if (!suits.isEmpty()) items.add(suits.get(rnd.nextInt(suits.size())));
items.add(new ItemStack(Material.CROSSBOW));
items.add(new ItemStack(Material.ARROW, 16 + rnd.nextInt(33)));
}
int rolls = kind.equals(VAULT) ? plugin.getConfig().getInt("harkonnen-fortress.loot-rolls", 3) : plugin.getConfig().getInt("abandoned-villages.loot-rolls", 3);
for (var pick : CacheLoot.roll(rnd, entries(plugin.getConfig(), kind), rolls)) { ItemStack i = build(pick); if (i != null) items.add(i); }
var inv = chest.getBlockInventory();
List<Integer> slots = new ArrayList<>(); for (int s = 0; s < inv.getSize(); s++) slots.add(s);
Collections.shuffle(slots, rnd);
for (int k = 0; k < items.size() && k < slots.size(); k++) inv.setItem(slots.get(k), items.get(k));
}
}

View file

@ -0,0 +1,47 @@
package com.example.duneterrain;
/**
* Vanilla-style {@code random_spread} placement for the Harkonnen outpost: one attempt per spacing x spacing chunk region
* (default 32, with 8 chunks of separation, linear spread) that succeeds with probability {@code frequency} (default 0.2).
* Those are the values of the vanilla pillager_outposts structure set. The abandoned Fremen village is bound to its outpost
* by a fixed offset chosen from the outpost's id, so every outpost always has one beside it.
*/
final class StructureGrid {
private StructureGrid() {}
static final long SALT = 0x4841524b46525453L;
/** Offsets of the companion village from the outpost, all multiples of 16 so both anchors sit on chunk centres. */
static final int[][] VILLAGE_OFFSETS = {{64, 0}, {-64, 0}, {0, 64}, {0, -64}, {48, 48}, {-48, 48}, {48, -48}, {-48, -48}};
static final int HALF = 22;
/** The outpost anchor of one spread region; independent of whether the frequency roll succeeds. */
static SietchLayout.Anchor regionAnchor(long seed, int spacing, int separation, long regionX, long regionZ) {
long h1 = SietchLayout.mix(regionX * 0x9E3779B97F4A7C15L ^ regionZ * 0xC2B2AE3D27D4EB4FL ^ SALT ^ seed);
long h2 = SietchLayout.mix(regionZ * 0x165667B19E3779F9L ^ regionX * 0x85EBCA77C2B2AE63L ^ ~SALT ^ seed);
int range = Math.max(1, spacing - separation);
long chunkX = regionX * spacing + Math.floorMod(h1, range), chunkZ = regionZ * spacing + Math.floorMod(h2, range);
return new SietchLayout.Anchor((int) chunkX * 16 + 8, (int) chunkZ * 16 + 8, SietchLayout.mix(h1 ^ h2 * 31));
}
/** True when the frequency roll for this anchor succeeds. */
static boolean rolls(SietchLayout.Anchor a, double frequency) {
return (SietchLayout.mix(a.id() ^ 0x4652455155454e43L) >>> 11) / (double) (1L << 53) < frequency;
}
/** The outpost anchored in exactly this chunk, or null. */
static SietchLayout.Anchor outpost(long seed, int spacing, int separation, double frequency, int chunkX, int chunkZ) {
var a = regionAnchor(seed, spacing, separation, Math.floorDiv(chunkX, spacing), Math.floorDiv(chunkZ, spacing));
return Math.floorDiv(a.x(), 16) == chunkX && Math.floorDiv(a.z(), 16) == chunkZ && rolls(a, frequency) ? a : null;
}
static int villageDirection(SietchLayout.Anchor outpost) { return (int) Math.floorMod(SietchLayout.mix(outpost.id() ^ 0x56494c4c41474531L), (long) VILLAGE_OFFSETS.length); }
/** The village anchored in exactly this chunk (the one that belongs to some outpost), or null. */
static SietchLayout.Anchor village(long seed, int spacing, int separation, double frequency, int chunkX, int chunkZ) {
for (int i = 0; i < VILLAGE_OFFSETS.length; i++) {
var o = outpost(seed, spacing, separation, frequency, chunkX - VILLAGE_OFFSETS[i][0] / 16, chunkZ - VILLAGE_OFFSETS[i][1] / 16);
if (o != null && villageDirection(o) == i) return new SietchLayout.Anchor(chunkX * 16 + 8, chunkZ * 16 + 8, SietchLayout.mix(o.id() ^ 0x56494c4c41474532L));
}
return null;
}
}

View file

@ -117,7 +117,26 @@ desert-villages:
enabled: true
spacing: 768
# Java desert-well-style attempt rate (1 per 1000 chunks), subject to terrain checks.
# Harkonnen garrison fortress with the vanilla pillager-outpost placement: one attempt per
# spacing x spacing chunk region (32), 8 chunks of separation, 20% success.
harkonnen-fortress:
enabled: true
rarity: 1000
spacing-chunks: 32
separation-chunks: 8
frequency: 0.2
loot-rolls: 3 # valuables rolled from `loot` when the vault is first opened
garrison:
enabled: true
guards: 8 # pillagers kept near the fortress, plus one commander
respawn-seconds: 600
activation-radius: 72
check-seconds: 20
# Optional override of the vault valuables. source: vanilla | ei | tooth | kit-shovel.
# The vault always also holds one Harkonnen stillsuit piece. Leave empty to use the built-in list.
loot: []
# Abandoned Fremen village: always generated beside a Harkonnen outpost (same rarity).
abandoned-villages:
enabled: true
loot-rolls: 3
loot: []

View file

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

View file

@ -22,14 +22,6 @@ class ArrakisFeaturesTest {
assertFalse(DenseSpice.contains(seed,a[0]+30,a[1],512));
}
}
@Test void fortressAttemptsAreDeterministicAndWellRare() {
int count=0;
for(int cx=-500;cx<500;cx++)for(int cz=-100;cz<100;cz++) {
boolean yes=HarkonnenFortress.attempt(1701,cx,cz,1000);
assertEquals(yes,HarkonnenFortress.attempt(1701,cx,cz,1000));if(yes)count++;
}
assertTrue(count>140&&count<260,"observed "+count+" in 200000 chunks");
}
@Test void depositIdentitySurvivesListenerRestartAndCreativeMiningConsumesIt() {
DuneTerrain plugin=mock(DuneTerrain.class);Chunk chunk=mock(Chunk.class);Block block=mock(Block.class);
PersistentDataContainer pdc=mock(PersistentDataContainer.class);
@ -68,21 +60,4 @@ class ArrakisFeaturesTest {
assertFalse(palette.contains(Material.HAY_BLOCK));assertFalse(palette.contains(Material.FARMLAND));assertFalse(palette.contains(Material.WHEAT));
verify(region,never()).spawnEntity(any(Location.class),eq(org.bukkit.entity.EntityType.VILLAGER));
}
@Test void fortressHasAccessibleEntryVaultAndSteppedRoof() {
DuneTerrain plugin=mock(DuneTerrain.class);
var config=new org.bukkit.configuration.file.YamlConfiguration();config.set("harkonnen-fortress.rarity",1);when(plugin.getConfig()).thenReturn(config);
var world=mock(org.bukkit.generator.WorldInfo.class);when(world.getName()).thenReturn("arrakis");when(world.getMaxHeight()).thenReturn(320);when(world.getMinHeight()).thenReturn(-64);
var region=mock(org.bukkit.generator.LimitedRegion.class);when(region.isInRegion(anyInt(),anyInt(),anyInt())).thenReturn(true);when(region.getHighestBlockYAt(anyInt(),anyInt())).thenReturn(70);
Map<String,Material> blocks=new HashMap<>();
doAnswer(call->{blocks.put(call.getArgument(0)+","+call.getArgument(1)+","+call.getArgument(2),call.getArgument(3));return null;}).when(region).setType(anyInt(),anyInt(),anyInt(),any(Material.class));
try(var api=mockStatic(Bukkit.class)) {
api.when(()->Bukkit.createBlockData(Material.RED_WALL_BANNER)).thenReturn(mock(org.bukkit.block.data.Directional.class));
new HarkonnenFortress(plugin).populate(world,new Random(0),0,0,region);
}
assertEquals(Material.AIR,blocks.get("8,71,1"));
assertEquals(Material.CHEST,blocks.get("11,65,11"));
assertEquals(Material.CUT_SANDSTONE,blocks.get("8,79,8"));
assertEquals(Material.AIR,blocks.get("5,66,7"));
assertFalse(blocks.containsValue(Material.HAY_BLOCK));assertFalse(blocks.containsValue(Material.FARMLAND));
}
}

View file

@ -0,0 +1,97 @@
package com.example.duneterrain;
import static org.junit.jupiter.api.Assertions.*;
import java.util.*;
import org.junit.jupiter.api.Test;
class OutpostStructuresTest {
static final long SEED = 1701L;
@Test void outpostsFollowVanillaPillagerOutpostRarity() {
int regions = 60, hits = 0;
for (int rx = 0; rx < regions; rx++) for (int rz = 0; rz < regions; rz++) {
var a = StructureGrid.regionAnchor(SEED, 32, 8, rx, rz);
int cx = Math.floorDiv(a.x(), 16), cz = Math.floorDiv(a.z(), 16);
assertTrue(cx >= rx * 32 && cx < rx * 32 + 24 && cz >= rz * 32 && cz < rz * 32 + 24, "linear spread within spacing - separation");
assertEquals(8, Math.floorMod(a.x(), 16));
if (StructureGrid.outpost(SEED, 32, 8, 0.2, cx, cz) != null) hits++;
assertEquals(StructureGrid.rolls(a, 0.2), StructureGrid.outpost(SEED, 32, 8, 0.2, cx, cz) != null);
}
double rate = hits / (double) (regions * regions);
assertTrue(rate > 0.16 && rate < 0.24, "success rate " + rate);
}
@Test void everyOutpostHasExactlyOneVillageBesideIt() {
int found = 0;
for (int rx = -15; rx < 15; rx++) for (int rz = -15; rz < 15; rz++) {
var a = StructureGrid.regionAnchor(SEED, 32, 8, rx, rz);
if (!StructureGrid.rolls(a, 0.2)) continue;
found++;
int dir = StructureGrid.villageDirection(a);
int vx = Math.floorDiv(a.x() + StructureGrid.VILLAGE_OFFSETS[dir][0], 16), vz = Math.floorDiv(a.z() + StructureGrid.VILLAGE_OFFSETS[dir][1], 16);
var v = StructureGrid.village(SEED, 32, 8, 0.2, vx, vz);
assertNotNull(v);
assertEquals(a.x() + StructureGrid.VILLAGE_OFFSETS[dir][0], v.x());
int dx = v.x() - a.x(), dz = v.z() - a.z();
assertTrue(Math.max(Math.abs(dx), Math.abs(dz)) >= 2 * StructureGrid.HALF, "footprints do not overlap");
int villages = 0;
for (int cx = vx - 4; cx <= vx + 4; cx++) for (int cz = vz - 4; cz <= vz + 4; cz++) if (StructureGrid.village(SEED, 32, 8, 0.2, cx, cz) != null) villages++;
assertTrue(villages >= 1);
}
assertTrue(found > 20);
}
@Test void villageWindowFitsInTheChunkBuffer() {
var a = StructureGrid.regionAnchor(SEED, 32, 8, 3, 3);
int cx = Math.floorDiv(a.x(), 16), cz = Math.floorDiv(a.z(), 16);
assertTrue(a.x() - 23 >= cx * 16 - 16 && a.x() + 23 <= cx * 16 + 31);
}
@Test void fortressBuildingsAreDisjointAndInsideTheWall() {
var b = FortressPlan.BUILDINGS;
for (int i = 0; i < b.size(); i++) {
for (int j = i + 1; j < b.size(); j++) assertFalse(b.get(i).overlaps(b.get(j)), b.get(i).name() + " vs " + b.get(j).name());
var x = b.get(i);
assertTrue(Math.abs(x.x1()) <= 14 && Math.abs(x.x2()) <= 14 && Math.abs(x.z1()) <= 14 && Math.abs(x.z2()) <= 14, x.name());
}
assertTrue(FortressPlan.VAULT_X1 >= FortressPlan.KEEP.x1() && FortressPlan.VAULT_X2 <= FortressPlan.KEEP.x2());
assertTrue(FortressPlan.CHEST_Z >= FortressPlan.VAULT_Z1 && FortressPlan.CHEST_Z <= FortressPlan.VAULT_Z2);
for (var p : FortressPlan.GUARDS) assertTrue(Math.abs(p.x()) <= 16 && Math.abs(p.z()) <= 16);
assertEquals(11, FortressPlan.GUARDS.size());
}
@Test void abandonedHousesDoNotOverlapEachOtherOrThePlaza() {
var h = RuinsPlan.HOUSES;
for (int i = 0; i < h.size(); i++) {
for (int j = i + 1; j < h.size(); j++) assertFalse(h.get(i).overlaps(h.get(j)));
var a = h.get(i);
assertTrue(Math.abs(a.x1()) <= 19 && Math.abs(a.x2()) <= 19 && Math.abs(a.z1()) <= 19 && Math.abs(a.z2()) <= 19);
for (int x = a.x1(); x <= a.x2(); x++) for (int z = a.z1(); z <= a.z2(); z++) assertEquals(0, RuinsPlan.basinDepth(x, z));
int[] d = a.door();
assertEquals(1, Math.abs(d[0]) + Math.abs(d[1]));
assertTrue(Math.abs(a.cx() + d[0] * 3) < Math.abs(a.cx()) || Math.abs(a.cz() + d[1] * 3) < Math.abs(a.cz()), "door faces the plaza");
}
int w = RuinsPlan.WINDTRAP_X;
for (var a : h) assertFalse(a.x1() <= w + 2 && a.x2() >= w - 2 && a.z1() <= RuinsPlan.WINDTRAP_Z + 2 && a.z2() >= RuinsPlan.WINDTRAP_Z - 2);
assertEquals(3, RuinsPlan.basinDepth(0, 0)); assertEquals(0, RuinsPlan.basinDepth(8, 0));
for (long id = 0; id < 30; id++) { int d = RuinsPlan.drift(id, 3, 4); assertTrue(d >= 0 && d <= 2); assertEquals(d, RuinsPlan.drift(id, 3, 4)); }
assertTrue(RuinsPlan.erosion(4, true) > RuinsPlan.erosion(1, true) && RuinsPlan.erosion(4, true) > RuinsPlan.erosion(4, false));
}
@Test void cacheLootRollsDistinctWeightedEntriesAndParsesConfig() {
var entries = StructureCaches.defaults(StructureCaches.VAULT);
for (long seed = 0; seed < 200; seed++) {
var picks = CacheLoot.roll(new Random(seed), entries, 3);
assertEquals(3, picks.size());
assertEquals(3, picks.stream().map(p -> p.entry().id()).distinct().count());
for (var p : picks) assertTrue(p.amount() >= p.entry().min() && p.amount() <= p.entry().max());
assertEquals(picks, CacheLoot.roll(new Random(seed), entries, 3));
}
assertTrue(CacheLoot.roll(new Random(1), List.of(), 3).isEmpty());
assertEquals(1, CacheLoot.roll(new Random(1), List.of(new CacheLoot.Entry("ei", "x", 0, 1, 1), new CacheLoot.Entry("ei", "y", 5, 2, 2)), 3).size());
var e = CacheLoot.parse(Map.of("source", "EI", "id", "refined_spice", "weight", 7, "min", 2, "max", 5));
assertEquals("ei", e.source()); assertEquals(7, e.weight()); assertEquals(2, e.min()); assertEquals(5, e.max());
assertTrue(entries.stream().anyMatch(x -> x.source().equals("tooth")));
assertFalse(StructureCaches.defaults(StructureCaches.RUIN).isEmpty());
}
}