diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc045ef9..3ab196cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ on: branches: [main] jobs: - build: + build-core: runs-on: ubuntu-latest defaults: @@ -35,6 +35,32 @@ jobs: - name: Upload compiled JAR uses: actions/upload-artifact@v4 with: - name: DuneRealms-Plugin + name: DuneCore-Plugin path: DuneRealms-minecraft-only/build/libs/*.jar if-no-files-found: error + + build-terrain: + runs-on: ubuntu-latest + defaults: + run: + working-directory: DuneTerrain + steps: + - name: Checkout source + uses: actions/checkout@v4 + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + with: + gradle-version: '8.14' + - name: Compile DuneTerrain + run: gradle clean build + - name: Upload compiled JAR + uses: actions/upload-artifact@v4 + with: + name: DuneTerrain-Plugin + path: DuneTerrain/build/libs/*.jar + if-no-files-found: error diff --git a/DuneRealms-minecraft-only/NETWORK_SETUP.md b/DuneRealms-minecraft-only/NETWORK_SETUP.md index f64af1a5..9320037c 100644 --- a/DuneRealms-minecraft-only/NETWORK_SETUP.md +++ b/DuneRealms-minecraft-only/NETWORK_SETUP.md @@ -1,8 +1,8 @@ -# DuneRealms — proxy server deployment (prototype) +# DuneCore + DuneTerrain — proxy server deployment (prototype) -Five separate Paper 1.21.x backend servers connect through a **Velocity** proxy. Each backend installs the same plugin JAR and uses a different `network.local-planet` value in its `config.yml`. Configure `network.servers` with the **exact Velocity server names**. The plugin now generates only its local planet when `network.enabled: true`. +Five separate Paper 1.21.x backend servers connect through a **Velocity** proxy. Install both `DuneCore` and `DuneTerrain` on each backend. Set `server.planet` in `plugins/DuneTerrain/config.yml` and `network.local-planet` in `plugins/DuneCore/config.yml` to the same planet on that backend. Set `network.servers` in DuneCore to the **exact Velocity server names**. DuneTerrain keeps all five planet profiles in config, but creates only the selected backend's planet world. -| Backend | `network.local-planet` | Velocity server name | +| Backend | DuneTerrain `server.planet` and DuneCore `network.local-planet` | Velocity server name | |---|---|---| | Arrakis | `arrakis` | `arrakis` | | Giedi Prime | `giedi_prime` | `giedi-prime` | @@ -27,8 +27,8 @@ bungee-plugin-message-channel = true Enable Velocity modern forwarding and configure each Paper backend for Velocity forwarding with the same forwarding secret. Block direct external access to backend ports. Players should connect only through the proxy. Check Velocity's current documentation for the exact forwarding options on your versions. -The Spacing Guild menu uses the `BungeeCord` `Connect` plugin message to ask Velocity to switch servers. This is an asynchronous request **without delivery acknowledgment**. The current plugin deducts travel fare when requesting a transfer, even if the destination is offline. +The Spacing Guild navigator is placed by DuneTerrain; DuneCore handles its click and opens the Guild menu. The menu uses the `BungeeCord` `Connect` plugin message to ask Velocity to switch servers. This is an asynchronous request **without delivery acknowledgment**. DuneCore deducts travel fare when requesting a transfer, even if the destination is offline. **Critical limitation — not production ready:** `players.yml`, hourly jobs, exchange listings, balances, and inventory are currently local to each backend. They do **not** synchronize across servers. A production network needs a shared authoritative database (e.g., MariaDB/PostgreSQL), transactional fare charges and payouts, cross-server inventory/player-data synchronization, and a proxy-side first-join/homeworld router. Without these, Solaris and contracts will differ between planets, and faction homeworld routing is not reliable. Do not deploy with a live economy until shared state and transfer confirmation are implemented. -Sandworms and burning sun only activate in the world named `arrakis`. Server job definitions remain per-backend until centralized. +Sandworms and burning sun only activate in the world named `arrakis`. Server job definitions remain per-backend until centralized. Existing worlds are not regenerated by changing DuneTerrain settings. diff --git a/DuneRealms-minecraft-only/README.md b/DuneRealms-minecraft-only/README.md index afa21a99..bf31d948 100644 --- a/DuneRealms-minecraft-only/README.md +++ b/DuneRealms-minecraft-only/README.md @@ -1,12 +1,12 @@ -# DuneRealms for Paper 1.21.4 +# DuneCore for Paper 1.21.4 -Requires Java 21 and Gradle 8+. Run `gradle build` and copy `build/libs/DuneRealms-1.0.0.jar` into your Paper server's `plugins/` directory. Restart the server. This project is source code, not a precompiled JAR. +Requires Java 21 and Gradle 8+. Run `gradle build` and copy `build/libs/DuneCore-1.0.0.jar` into your Paper server's `plugins/` directory. DuneCore provides factions, spice gameplay, politics, jobs, and Guild travel. Install the separate `DuneTerrain` plugin to generate the server's planet world. Remove the old `DuneRealms.jar` from the Paper `plugins/` folder when upgrading to `DuneCore.jar`. Commands: `/dune choose fremen|harkonnen|corrino|atreides`, `/dune kit`, `/dune balance`, `/dune sell`, `/dune travel`, `/dune guildnpc` (OP), `/dune givespice` (OP). -Worlds are generated on first server start: `arrakis`, `giedi_prime`, `kaitain`, `caladan`. Custom generator selection only applies when a world is first generated. Existing worlds with these names will not be replaced. For safety, back up your server before installing. +For proxy travel, configure `network.local-planet` for this backend and the `network.servers` proxy names. The selected world is generated by DuneTerrain, with `server.planet` in `plugins/DuneTerrain/config.yml` set to the same planet. DuneTerrain applies terrain generation only when the world is first created; existing worlds and generated chunks are not replaced. -Red sand in Arrakis is harvestable spice. You need all four stillsuit pieces equipped and the custom netherite spice shovel in hand. Spice can be sold with `/dune sell` and Solaris spent at Guild NPCs or `/dune travel`. Each faction has a passive perk; Fremen harvest double spice. Player faction and balances persist in `plugins/DuneRealms/players.yml`. +Suspicious sand on Arrakis is harvestable spice. Use the tagged netherite spice shovel from `/dune kit`. Spice can be sold with `/dune sell` and Solaris spent through Guild travel. Each faction has a passive perk; Fremen harvest double spice. Player faction and balances persist in `plugins/DuneCore/players.yml`; the plugin migrates existing flat files from `plugins/DuneRealms/` on first startup after the rename. Limitations: this is a gameplay prototype, not a fully polished mod. Custom equipment uses vanilla items and colored names, not resource-pack models. Worlds have themed terrain, but no cities, unique buildings, or detailed biome decorations. Guild NPCs are placed by operators. No permissions-based faction change for ordinary players. The plugin has not been compiled or tested against a running Paper server in this environment. @@ -15,7 +15,7 @@ Limitations: this is a gameplay prototype, not a fully polished mod. Custom equi Hostile, oversized husks representing sandworms spawn on sandy surfaces near players **only on Arrakis**, roughly every 10 seconds with a configurable chance. They target players, have 500 health and 30 base melee attack damage (Warden-level values), and play a Warden roar when emerging. They cannot teleport to other worlds. Settings are under `sandworms` in `config.yml`. The worm is represented by a scaled vanilla husk; a true animated worm model would require a resource pack or model plugin. ## Spice contracts and sandworm blooms -- On Arrakis, defeating a sandworm generates a broad patch of red-sand spice deposits with a target base harvest value of 100,000 Solaris (actual value depends on available sandy terrain and faction bonuses). +- On Arrakis, defeating a sandworm generates a broad patch of suspicious-sand spice deposits with a target base harvest value of 100,000 Solaris (actual value depends on available sandy terrain and faction bonuses). - Players begin on their faction's homeworld after choosing a faction and respawn there. - `/dune exchange` shows open spice contracts. - `/dune job post ` creates a contract. @@ -27,7 +27,7 @@ Hostile, oversized husks representing sandworms spawn on sandy surfaces near pla This is source code, not a tested compiled JAR. ## Hourly server-issued CHOAM jobs -Edit `plugins/DuneRealms/server-jobs.yml` to configure job `title`, `spice-required`, `pay`, and `time-limit-minutes`. `offers-per-hour` controls how many are randomly selected. Listings rotate every hour at UTC hour boundaries. Existing accepted contracts persist through restarts, including their original deadlines; if a definition is removed while active, that contract expires without a fine. +Edit `plugins/DuneCore/server-jobs.yml` to configure job `title`, `spice-required`, `pay`, and `time-limit-minutes`. `offers-per-hour` controls how many are randomly selected. Listings rotate every hour at UTC hour boundaries. Existing accepted contracts persist through restarts, including their original deadlines; if a definition is removed while active, that contract expires without a fine. Commands: `/dune serverjobs` (list), `/dune serverjobs accept ` (accept), `/dune serverjobs reload` (admin; reload definitions). Harvesting spice with the stillsuit and axe advances the active server contract. Successful completion pays the configured amount. Failure after the deadline incurs a **5% fine on the configured pay**, rounded up. Fines can produce negative Solaris balances (debt). Contracts expire even while players are offline, checked every 10 seconds while the server is running. @@ -40,7 +40,7 @@ Server-issued contracts are separate from player-to-player exchange contracts. H Each joining player receives a persistent-data-tagged Nether Star named **Dune Navigator** (unless already present). Left-click or right-click while holding it in the main hand opens the main chest GUI. Interaction is cancelled to avoid accidentally hitting or activating blocks. `/dune menuitem` gives a replacement when missing; `/dune` and `/dune gui` still work. The menu item is recognized by its plugin tag, not its display name. ## Fully configurable GUI (`gui.yml`) -The GUI is now configured by `plugins/DuneRealms/gui.yml`, copied from resources on first startup. Every menu has an editable title, chest size (9–54 in multiples of 9), and items with icon, slot, name, lore, and action. Use `/dune guireload` (admin) after editing. Supported actions are `open:`, `dune:`, `close`, and `none`. Arbitrary console commands are intentionally not supported. Dynamic CHOAM jobs, factions, and planets use editable `dynamic` sections, including icon, starting slot, step, lore, and action. Placeholders: `%player%`, `%balance%`, `%travel_cost%`, `%active_job%`, `%id%` (dynamic). Menu opener item continues to work with either mouse button. +The GUI is now configured by `plugins/DuneCore/gui.yml`, copied from resources on first startup. Every menu has an editable title, chest size (9–54 in multiples of 9), and items with icon, slot, name, lore, and action. Use `/dune guireload` (admin) after editing. Supported actions are `open:`, `dune:`, `close`, and `none`. Arbitrary console commands are intentionally not supported. Dynamic CHOAM jobs, factions, and planets use editable `dynamic` sections, including icon, starting slot, step, lore, and action. Placeholders: `%player%`, `%balance%`, `%travel_cost%`, `%active_job%`, `%id%` (dynamic). Menu opener item continues to work with either mouse button. NOTE: Player-to-player exchange listings can still be accepted through `/dune job accept `; the configurable exchange menu currently includes configurable posting/cancel/leave controls but does not yet render dynamic player listings. @@ -75,7 +75,7 @@ Each newly issued leather stillsuit piece receives a distinctive vanilla smithin | Fremen | Orange | Dune | Lapis / blue | | Spacing Guild (reserved) | Black | Eye | Quartz / white | -Ordos now starts and respawns on its own generated planet `sigma_draconis_iv` (Sigma Draconis IV), instead of Arrakis or Caladan. The world is automatically generated using the project's existing generic world generator; custom biome/terrain styling for Sigma Draconis IV is not yet implemented. The Spacing Guild remains a non-playable faction and does not receive its own kit through normal gameplay. Existing armor is not automatically upgraded; issue a fresh kit. +Ordos starts and respawns on its own generated planet `sigma_draconis_iv` (Sigma Draconis IV). Its dark, snowy terrain profile is configured by DuneTerrain. The Spacing Guild remains a non-playable faction and does not receive its own kit through normal gameplay. Existing armor is not automatically upgraded; issue a fresh kit. The trims are Minecraft's built-in vanilla patterns, not custom resource-pack models. This source has not been compiled or tested on Paper. diff --git a/DuneRealms-minecraft-only/build.gradle.kts b/DuneRealms-minecraft-only/build.gradle.kts index e8c2a089..9d6f7f1d 100644 --- a/DuneRealms-minecraft-only/build.gradle.kts +++ b/DuneRealms-minecraft-only/build.gradle.kts @@ -7,6 +7,7 @@ dependencies { implementation("org.postgresql:postgresql:42.7.4") } tasks.jar { + archiveBaseName.set("DuneCore") duplicatesStrategy = DuplicatesStrategy.EXCLUDE from(configurations.runtimeClasspath.get().map { if(it.isDirectory) it else zipTree(it) }) } diff --git a/DuneRealms-minecraft-only/settings.gradle.kts b/DuneRealms-minecraft-only/settings.gradle.kts index a0ce7c12..189ff3bc 100644 --- a/DuneRealms-minecraft-only/settings.gradle.kts +++ b/DuneRealms-minecraft-only/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "DuneRealms" +rootProject.name = "DuneCore" diff --git a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ArrakisWater.java b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ArrakisWater.java index 0e4bff75..2ed209de 100644 --- a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ArrakisWater.java +++ b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ArrakisWater.java @@ -15,15 +15,15 @@ import java.util.*; /** Finite, naturally generated Arrakis water caches and two water-trading careers. */ public final class ArrakisWater implements Listener { - private final DuneRealms plugin; + private final DuneCore plugin; private final NamespacedKey waterKey; private final Map careers = new HashMap<>(); private final Map money; private final Runnable save; private final Politics politics; - ArrakisWater(DuneRealms plugin,Map money,Runnable save,Politics politics) { + ArrakisWater(DuneCore plugin,Map money,Runnable save,Politics politics) { this.plugin=plugin;this.money=money;this.save=save;this.politics=politics; - waterKey=new NamespacedKey(plugin,"finite_arrakis_water"); + waterKey=new NamespacedKey("dunerealms","finite_arrakis_water"); } private boolean arrakis(World w){return w.getName().equalsIgnoreCase("arrakis");} public static final class SietchPopulator extends BlockPopulator { diff --git a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ConfigurableGui.java b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ConfigurableGui.java index 0a6076cc..f6b2edf6 100644 --- a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ConfigurableGui.java +++ b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/ConfigurableGui.java @@ -14,7 +14,7 @@ import java.util.*; /** Data-driven chest GUI with allowlisted actions; never executes arbitrary console commands. */ final class ConfigurableGui { - private final DuneRealms plugin; + private final DuneCore plugin; private final ServerJobs serverJobs; private final Map money; private final Map jobs; @@ -24,7 +24,7 @@ final class ConfigurableGui { private final Map opened = new HashMap<>(); private final Map> actions = new HashMap<>(); - ConfigurableGui(DuneRealms plugin, ServerJobs serverJobs, Map money, + ConfigurableGui(DuneCore plugin, ServerJobs serverJobs, Map money, Map jobs, String[] planets, String[] factions, Map selected) { this.plugin=plugin; this.serverJobs=serverJobs; this.money=money; this.jobs=jobs; this.planets=planets; this.factions=factions; this.selected=selected; diff --git a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneRealms.java b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java similarity index 73% rename from DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneRealms.java rename to DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java index c56e0ec5..696ad3cb 100644 --- a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneRealms.java +++ b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java @@ -32,20 +32,13 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.*; -import org.bukkit.block.Biome; -import org.bukkit.generator.BiomeProvider; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.generator.WorldInfo; -import org.bukkit.generator.LimitedRegion; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.util.noise.SimplexOctaveGenerator; import java.io.File; import java.io.IOException; import java.util.*; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; -public final class DuneRealms extends JavaPlugin implements Listener, CommandExecutor { +public final class DuneCore extends JavaPlugin implements Listener, CommandExecutor { private final String[] planets = {"arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv"}; private final String[] factions = {"Fremen", "Harkonnen", "Corrino", "Atreides", "Ordos"}; private final Map selected = new HashMap<>(); @@ -68,7 +61,8 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe private ArrakisWater arrakisWater; @Override public void onEnable() { - initializeConfig(); itemKey = new NamespacedKey(this, "item"); npcKey = new NamespacedKey(this, "guild"); wormKey = new NamespacedKey(this, "sandworm"); armorFactionKey = new NamespacedKey(this, "armor_faction"); + migrateLegacyData(); + saveDefaultConfig(); itemKey = new NamespacedKey("dunerealms", "item"); npcKey = new NamespacedKey("dunerealms", "guild"); wormKey = new NamespacedKey("dunerealms", "sandworm"); armorFactionKey = new NamespacedKey("dunerealms", "armor_faction"); dataFile = new File(getDataFolder(), "players.yml"); data = YamlConfiguration.loadConfiguration(dataFile); for (String key : data.getKeys(false)) try { UUID id = UUID.fromString(key); selected.put(id, data.getString(key + ".faction", "")); money.put(id, data.getInt(key + ".solaris", 0)); @@ -81,23 +75,7 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe if (quota > harvested) jobs.put(owner, new Job(owner, quota, harvested)); } catch (IllegalArgumentException ignored) {} } - if (!getConfig().getBoolean("network.enabled", true)) { - for (String name : planets) { - if (!getConfig().getBoolean("planets." + name + ".enabled", true)) continue; - WorldCreator creator = new WorldCreator(name).environment(World.Environment.NORMAL).generator(new PlanetGenerator(this, name)); - World world = Bukkit.createWorld(creator); - if (world != null) { - world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !name.equals("arrakis")); - world.setTime(name.equals("giedi_prime") ? 18000 : 6000); - setupPlanetSpawn(world); - } - } - } else { - String localPlanet = getConfig().getString("network.local-planet", "arrakis"); - if (!Arrays.asList(planets).contains(localPlanet)) throw new IllegalStateException("Invalid network.local-planet: " + localPlanet); - if (!getConfig().getBoolean("planets." + localPlanet + ".enabled", true)) throw new IllegalStateException("network.local-planet is disabled in config: " + localPlanet); - World world = Bukkit.createWorld(new WorldCreator(localPlanet).environment(World.Environment.NORMAL).generator(new PlanetGenerator(this, localPlanet))); - if (world != null) setupPlanetSpawn(world); + if (getConfig().getBoolean("network.enabled", true)) { getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); } if(getConfig().getBoolean("database.enabled",false)) { @@ -115,92 +93,7 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe Objects.requireNonNull(getCommand("dune")).setExecutor(this); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getScheduler().runTaskTimer(this, this::spawnSandworms, 200L, 200L); - getLogger().info("DuneRealms enabled. Planet worlds, spawn points, Guild navigators, and Arrakis sandworms ready."); - } - private void initializeConfig() { - if (getResource("config.yml") != null) saveDefaultConfig(); - org.bukkit.configuration.file.FileConfiguration config = getConfig(); - config.addDefault("network.enabled", false); - config.addDefault("network.local-planet", "arrakis"); - config.addDefault("travel-price", 100); - config.addDefault("spice-sell-price", 100); - config.addDefault("spice-respawn-seconds", 120); - config.addDefault("spice-deposits.per-chunk", 2); - config.addDefault("spice-deposits.respawn-seconds", 120); - config.addDefault("guild-npc.enabled", true); - addPlanetDefaults(config, "arrakis", 70, 11, "DESERT", "SAND", "RED_SAND", 63, false, false, 0, Map.of("COAL_ORE", 2, "IRON_ORE", 2, "COPPER_ORE", 1)); - addPlanetDefaults(config, "giedi_prime", 61, 5, "SWAMP", "BLACKSTONE", "DEEPSLATE", 63, true, false, 0, Map.of("COAL_ORE", 14, "IRON_ORE", 12, "COPPER_ORE", 9, "GOLD_ORE", 7, "REDSTONE_ORE", 8, "LAPIS_ORE", 5, "DIAMOND_ORE", 4, "EMERALD_ORE", 2)); - addPlanetDefaults(config, "kaitain", 70, 3, "PLAINS", "GRASS_BLOCK", "DIRT", 0, false, false, 64, Map.of("COAL_ORE", 4, "IRON_ORE", 5, "GOLD_ORE", 15, "DIAMOND_ORE", 18, "EMERALD_ORE", 3)); - addPlanetDefaults(config, "caladan", 67, 10, "JUNGLE", "GRASS_BLOCK", "DIRT", 64, true, true, 0.11, Map.of("COAL_ORE", 4, "IRON_ORE", 5, "COPPER_ORE", 5, "DIAMOND_ORE", 2)); - addPlanetDefaults(config, "sigma_draconis_iv", 72, 14, "SNOWY_PLAINS", "SNOW_BLOCK", "DEEPSLATE", 0, false, false, 0, Map.of("COAL_ORE", 5, "IRON_ORE", 5, "COPPER_ORE", 2, "DIAMOND_ORE", 2)); - config.options().copyDefaults(true); - saveConfig(); - } - private void addPlanetDefaults(org.bukkit.configuration.file.FileConfiguration config, String name, int height, int variation, - String biome, String surface, String filler, int waterLevel, boolean swampWater, - boolean trees, double flowers, Map ores) { - String path = "planets." + name + "."; - config.addDefault(path + "enabled", true); - config.addDefault(path + "spawn.x", 0); - config.addDefault(path + "spawn.z", 0); - config.addDefault(path + "terrain.base-height", height); - config.addDefault(path + "terrain.height-variation", variation); - config.addDefault(path + "terrain.noise-scale", 0.02); - config.addDefault(path + "biome", biome); - config.addDefault(path + "surface", surface); - config.addDefault(path + "filler", filler); - config.addDefault(path + "water.level", waterLevel); - config.addDefault(path + "water.swamp-pools", swampWater); - config.addDefault(path + "water.coverage", 0.18); - config.addDefault(path + "vegetation.trees", trees); - config.addDefault(path + "vegetation.tree-chance", trees ? 0.035 : 0.0); - config.addDefault(path + "vegetation.flowers-per-chunk", flowers); - config.addDefault(path + "ores.min-y", -48); - config.addDefault(path + "ores.max-y", 48); - config.addDefault(path + "ores.vein-size", 5); - for (Map.Entry ore : ores.entrySet()) config.addDefault(path + "ores." + ore.getKey(), ore.getValue()); - } - private void setupPlanetSpawn(World world) { - String name = world.getName().toLowerCase(Locale.ROOT); - int x = getConfig().getInt("planets." + name + ".spawn.x", 0); - int z = getConfig().getInt("planets." + name + ".spawn.z", 0); - world.getChunkAt(x >> 4, z >> 4).load(true); - Location spawn = findSafeSpawn(world, x, z); - world.setSpawnLocation(spawn); - if (getConfig().getBoolean("guild-npc.enabled", true)) ensureGuildNpc(world, spawn); - } - private Location findSafeSpawn(World world, int x, int z) { - for (int radius = 0; radius <= 12; radius++) { - for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { - if (radius > 0 && Math.abs(dx) != radius && Math.abs(dz) != radius) continue; - int bx = x + dx, bz = z + dz; - int y = world.getHighestBlockYAt(bx, bz); - Material ground = world.getBlockAt(bx, y, bz).getType(); - if (!ground.isSolid() || ground == Material.MAGMA_BLOCK || ground == Material.CACTUS || ground == Material.POWDER_SNOW) continue; - if (world.getBlockAt(bx, y + 1, bz).isLiquid() || world.getBlockAt(bx, y + 2, bz).isLiquid()) continue; - return new Location(world, bx + 0.5, y + 1, bz + 0.5); - } - } - int y = Math.max(world.getMinHeight() + 2, world.getHighestBlockYAt(x, z) + 1); - return new Location(world, x + 0.5, y, z + 0.5); - } - private void ensureGuildNpc(World world, Location spawn) { - Location npcLocation = findSafeSpawn(world, spawn.getBlockX() + 2, spawn.getBlockZ()); - for (Entity entity : world.getNearbyEntities(npcLocation, 8, 5, 8)) { - if (entity instanceof Villager villager && villager.getPersistentDataContainer().has(npcKey, PersistentDataType.BYTE)) { - villager.teleport(npcLocation); - return; - } - } - Villager villager = world.spawn(npcLocation, Villager.class); - villager.setCustomName(ChatColor.LIGHT_PURPLE + "Spacing Guild Navigator"); - villager.setCustomNameVisible(true); - villager.setProfession(Villager.Profession.CLERIC); - villager.setAI(false); - villager.setInvulnerable(true); - villager.setSilent(true); - villager.setPersistent(true); - villager.getPersistentDataContainer().set(npcKey, PersistentDataType.BYTE, (byte) 1); + getLogger().info("DuneCore enabled. Gameplay, faction travel, and Arrakis sandworms ready."); } @Override public void onDisable() { if(serverJobs!=null)serverJobs.save(); savePlayers(); } private void savePlayers() { @@ -226,7 +119,7 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe private ItemStack menuItem() { ItemStack item = custom(Material.NETHER_STAR, "Dune Navigator", "menu_opener"); ItemMeta meta = item.getItemMeta(); - meta.setLore(List.of(ChatColor.YELLOW + "Left or right click to open DuneRealms")); + meta.setLore(List.of(ChatColor.YELLOW + "Left or right click to open DuneCore")); item.setItemMeta(meta); return item; } @@ -308,13 +201,13 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe default -> EquipmentSlotGroup.FEET; }; meta.addAttributeModifier(Attribute.ARMOR, - new AttributeModifier(new NamespacedKey(this,"stillsuit_armor_"+piece.toLowerCase(Locale.ROOT)), + new AttributeModifier(new NamespacedKey("dunerealms","stillsuit_armor_"+piece.toLowerCase(Locale.ROOT)), armor, AttributeModifier.Operation.ADD_NUMBER, slot)); meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, - new AttributeModifier(new NamespacedKey(this,"stillsuit_toughness_"+piece.toLowerCase(Locale.ROOT)), + new AttributeModifier(new NamespacedKey("dunerealms","stillsuit_toughness_"+piece.toLowerCase(Locale.ROOT)), 3.0, AttributeModifier.Operation.ADD_NUMBER, slot)); meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, - new AttributeModifier(new NamespacedKey(this,"stillsuit_knockback_"+piece.toLowerCase(Locale.ROOT)), + new AttributeModifier(new NamespacedKey("dunerealms","stillsuit_knockback_"+piece.toLowerCase(Locale.ROOT)), 0.1, AttributeModifier.Operation.ADD_NUMBER, slot)); } private void mergeElytra(Player p) { @@ -409,7 +302,7 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe // No permanent potion refresh: the attribute is removed immediately when the set breaks. var health=p.getAttribute(Attribute.MAX_HEALTH); if(health!=null) { - NamespacedKey key=new NamespacedKey(this,"atreides_full_set_hearts"); + NamespacedKey key=new NamespacedKey("dunerealms","atreides_full_set_hearts"); AttributeModifier existing=null; for(AttributeModifier modifier:health.getModifiers()) if(modifier.getKey().equals(key)){existing=modifier;break;} @@ -464,7 +357,7 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe private void teleport(Player p, String planet) { if (!Arrays.asList(planets).contains(planet)) { p.sendMessage(ChatColor.RED + "Unknown planet."); return; } if (getConfig().getBoolean("network.enabled", true)) { - String local = getConfig().getString("network.local-planet", "arrakis"); + String local = localPlanet(); if (planet.equals(local)) { p.sendMessage(ChatColor.YELLOW + "You are already on " + planet); return; } String target = getConfig().getString("network.servers." + planet); if (target == null || target.isBlank()) { p.sendMessage(ChatColor.RED + "Planet server not configured."); return; } @@ -497,7 +390,13 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe } private boolean isLocalPlanet(String planet) { return !getConfig().getBoolean("network.enabled", true) - || planet.equals(getConfig().getString("network.local-planet", "arrakis")); + || planet.equals(localPlanet()); + } + private String localPlanet() { + String configured = getConfig().getString("network.local-planet", "arrakis"); + if (Arrays.asList(planets).contains(configured) && Bukkit.getWorld(configured) != null) return configured; + for (String planet : planets) if (Bukkit.getWorld(planet) != null) return planet; + return configured; } private void travelMenu(Player p) { Inventory inv = Bukkit.createInventory(null, 9, "Spacing Guild Travel"); @@ -708,9 +607,30 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe } private void scheduleSpiceRespawn(Location location) { Location loc = location.clone(); - long delay = 20L * getConfig().getLong("spice-deposits.respawn-seconds", getConfig().getLong("spice-respawn-seconds", 120)); + long delay = 20L * getConfig().getLong("spice-respawn-seconds", 120); Bukkit.getScheduler().runTaskLater(this, () -> { if (loc.getChunk().isLoaded() && loc.getBlock().getType() == Material.AIR) loc.getBlock().setType(Material.SUSPICIOUS_SAND); }, delay); } + private void migrateLegacyData() { + File legacy = new File(getDataFolder().getParentFile(), "DuneRealms"); + if (!legacy.isDirectory()) return; + File current = getDataFolder(); + if (!current.exists() && !current.mkdirs()) { + getLogger().warning("Could not create DuneCore data folder for legacy settings migration."); + return; + } + File[] files = legacy.listFiles(File::isFile); + if (files == null) return; + for (File source : files) { + File destination = new File(current, source.getName()); + if (destination.exists()) continue; + try { + java.nio.file.Files.copy(source.toPath(), destination.toPath()); + getLogger().info("Migrated " + source.getName() + " from the previous DuneRealms data folder."); + } catch (IOException ex) { + getLogger().warning("Could not migrate " + source.getName() + ": " + ex.getMessage()); + } + } + } private ItemStack spiceDrop(Player miner, int amount) { ItemStack spice = custom(Material.ORANGE_DYE, "Melange Spice", "spice").asQuantity(amount); ItemMeta meta = spice.getItemMeta(); @@ -806,114 +726,4 @@ public final class DuneRealms extends JavaPlugin implements Listener, CommandExe if (faction.equals("Atreides")) p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 130, 0, true, false)); if (faction.equals("Fremen") && p.getWorld().getName().equals("arrakis")) p.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE, 130, 0, true, false)); } - private static class PlanetGenerator extends ChunkGenerator { - private final DuneRealms plugin; - private final String planet; - PlanetGenerator(DuneRealms plugin, String planet) { this.plugin = plugin; this.planet = planet; } - @Override public List getDefaultPopulators(World world) { - return planet.equals("arrakis") ? List.of(new ArrakisWater.SietchPopulator()) : List.of(); - } - @Override public void generateNoise(WorldInfo world, Random random, int chunkX, int chunkZ, ChunkData data) { - String path = "planets." + planet + "."; - int minY = world.getMinHeight(), maxY = world.getMaxHeight() - 1; - int baseHeight = plugin.getConfig().getInt(path + "terrain.base-height", 68); - double variation = plugin.getConfig().getDouble(path + "terrain.height-variation", 8); - double scale = Math.max(0.001, plugin.getConfig().getDouble(path + "terrain.noise-scale", 0.02)); - int waterLevel = plugin.getConfig().getInt(path + "water.level", 63); - Material surface = configuredMaterial(path + "surface", Material.GRASS_BLOCK); - Material filler = configuredMaterial(path + "filler", Material.DIRT); - Material core = planet.equals("giedi_prime") || planet.equals("sigma_draconis_iv") ? Material.DEEPSLATE : Material.STONE; - double flowers = Math.max(0, plugin.getConfig().getDouble(path + "vegetation.flowers-per-chunk", 0)); - double treeChance = Math.max(0, plugin.getConfig().getDouble(path + "vegetation.tree-chance", 0)); - int[][] heights = new int[16][16]; - for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { - int gx = chunkX * 16 + x, gz = chunkZ * 16 + z; - double n = Math.sin(gx * scale) * Math.cos(gz * scale * 1.13) - + Math.sin(gx * scale * 2.7 + gz * scale * 1.45) * 0.35; - int h = Math.max(minY + 8, Math.min(maxY - 8, baseHeight + (int) Math.round(n * variation))); - heights[x][z] = h; - data.setBlock(x, minY, z, Material.BEDROCK); - for (int y = minY + 1; y < h - 3; y++) data.setBlock(x, y, z, core); - for (int y = h - 3; y < h; y++) data.setBlock(x, y, z, filler); - data.setBlock(x, h, z, surface); - - if (plugin.getConfig().getBoolean(path + "water.swamp-pools", false) && h < waterLevel) { - double poolNoise = Math.sin(gx * 0.035) * Math.cos(gz * 0.031); - double coverage = Math.max(0, Math.min(1, plugin.getConfig().getDouble(path + "water.coverage", 0.18))); - if (poolNoise > 0.72 - coverage * 0.75) { - for (int y = h + 1; y <= Math.min(waterLevel, maxY); y++) data.setBlock(x, y, z, Material.WATER); - } - } - if (flowers > 0 && surface == Material.GRASS_BLOCK && random.nextDouble() < Math.min(1, flowers / 256.0)) { - Material[] flowerTypes = {Material.POPPY, Material.DANDELION, Material.CORNFLOWER, - Material.AZURE_BLUET, Material.ALLIUM, Material.OXEYE_DAISY}; - data.setBlock(x, h + 1, z, flowerTypes[random.nextInt(flowerTypes.length)]); - } - if (plugin.getConfig().getBoolean(path + "vegetation.trees", false) - && surface == Material.GRASS_BLOCK && random.nextDouble() < treeChance && x >= 3 && x <= 12 && z >= 3 && z <= 12) { - placeJungleTree(data, x, h + 1, z, random, maxY); - } - } - if (planet.equals("arrakis")) placeSpiceDeposits(data, heights, random, minY, maxY); - placeOres(data, random, path, minY, maxY); - } - @Override public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) { - return new BiomeProvider() { - @Override public Biome getBiome(WorldInfo info, int x, int y, int z) { - String configured = plugin.getConfig().getString("planets." + planet + ".biome", "PLAINS"); - try { return Biome.valueOf(configured.toUpperCase(Locale.ROOT)); } - catch (IllegalArgumentException ex) { return Biome.PLAINS; } - } - @Override public List getBiomes(WorldInfo info) { return List.of(getBiome(info, 0, 64, 0)); } - }; - } - private Material configuredMaterial(String path, Material fallback) { - String name = plugin.getConfig().getString(path, fallback.name()); - Material material = Material.matchMaterial(name == null ? "" : name); - return material == null ? fallback : material; - } - private void placeSpiceDeposits(ChunkData data, int[][] heights, Random random, int minY, int maxY) { - int count = Math.max(0, plugin.getConfig().getInt("spice-deposits.per-chunk", 2)); - for (int i = 0; i < count; i++) { - int x = random.nextInt(16), z = random.nextInt(16), y = heights[x][z]; - if (y + 1 < maxY && y > minY) data.setBlock(x, y, z, Material.SUSPICIOUS_SAND); - } - } - private void placeOres(ChunkData data, Random random, String path, int minWorldY, int maxWorldY) { - org.bukkit.configuration.ConfigurationSection ores = plugin.getConfig().getConfigurationSection(path + "ores"); - if (ores == null) return; - int minY = Math.max(minWorldY + 1, plugin.getConfig().getInt(path + "ores.min-y", -48)); - int maxY = Math.min(maxWorldY - 4, plugin.getConfig().getInt(path + "ores.max-y", 48)); - int veinSize = Math.max(1, Math.min(16, plugin.getConfig().getInt(path + "ores.vein-size", 5))); - if (maxY < minY) return; - for (String key : ores.getKeys(false)) { - Material ore = Material.matchMaterial(key); - if (ore == null || !key.endsWith("_ORE")) continue; - int attempts = Math.max(0, Math.min(64, ores.getInt(key, 0))); - for (int attempt = 0; attempt < attempts; attempt++) { - int x = random.nextInt(16), z = random.nextInt(16), y = minY + random.nextInt(maxY - minY + 1); - for (int n = 0; n < veinSize; n++) { - int vx = Math.max(0, Math.min(15, x + random.nextInt(3) - 1)); - int vz = Math.max(0, Math.min(15, z + random.nextInt(3) - 1)); - int vy = Math.max(minY, Math.min(maxY, y + random.nextInt(3) - 1)); - Material existing = data.getType(vx, vy, vz); - if (existing == Material.STONE || existing == Material.DEEPSLATE || existing == Material.TUFF) data.setBlock(vx, vy, vz, ore); - } - } - } - } - private void placeJungleTree(ChunkData data, int x, int y, int z, Random random, int maxY) { - int height = 4 + random.nextInt(4); - if (y + height + 2 >= maxY || data.getType(x, y - 1, z) != Material.GRASS_BLOCK) return; - for (int dy = 0; dy < height; dy++) data.setBlock(x, y + dy, z, Material.JUNGLE_LOG); - for (int dy = height - 2; dy <= height + 1; dy++) { - int radius = dy >= height ? 1 : 2; - for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { - if (Math.abs(dx) == radius && Math.abs(dz) == radius && random.nextBoolean()) continue; - int lx = x + dx, lz = z + dz, ly = y + dy; - if (lx >= 0 && lx < 16 && lz >= 0 && lz < 16 && data.getType(lx, ly, lz).isAir()) data.setBlock(lx, ly, lz, Material.JUNGLE_LEAVES); - } - } - } - } } diff --git a/DuneRealms-minecraft-only/src/main/resources/config.yml b/DuneRealms-minecraft-only/src/main/resources/config.yml index 3e9ef22b..b3296190 100644 --- a/DuneRealms-minecraft-only/src/main/resources/config.yml +++ b/DuneRealms-minecraft-only/src/main/resources/config.yml @@ -19,8 +19,8 @@ arrakis-sun: # One Paper backend per planet, connected through Velocity's BungeeCord plugin messaging support. network: - enabled: false - local-planet: arrakis # CHANGE for each backend + enabled: true + local-planet: arrakis # Match server.planet in DuneTerrain on this backend servers: arrakis: arrakis giedi_prime: giedi-prime diff --git a/DuneRealms-minecraft-only/src/main/resources/plugin.yml b/DuneRealms-minecraft-only/src/main/resources/plugin.yml index 194c8327..16851893 100644 --- a/DuneRealms-minecraft-only/src/main/resources/plugin.yml +++ b/DuneRealms-minecraft-only/src/main/resources/plugin.yml @@ -1,8 +1,9 @@ -name: DuneRealms +name: DuneCore version: 1.0.0 -main: com.example.dunerealms.DuneRealms +main: com.example.dunerealms.DuneCore api-version: '1.21' -description: Dune-inspired factions, spice, planets and Guild travel +softdepend: [DuneTerrain] +description: Dune-inspired factions, spice economy, politics and Guild travel commands: dune: description: Dune realms commands diff --git a/DuneTerrain/README.md b/DuneTerrain/README.md new file mode 100644 index 00000000..1ffd9691 --- /dev/null +++ b/DuneTerrain/README.md @@ -0,0 +1,19 @@ +# DuneTerrain for Paper 1.21.4 + +DuneTerrain is a standalone Paper plugin that generates one Dune planet world per server. It includes the five planet profiles, terrain and ore generation, Arrakis spice deposits and sietches, safe world spawn setup, and a protected Spacing Guild navigator. + +## Build and install + +Build the plugin from this directory with Java 21 and Gradle 8.14 or newer: + +```sh +gradle clean build +``` + +Copy `build/libs/DuneTerrain-1.0.0.jar` into the Paper server's `plugins/` directory. Set `server.planet` in `plugins/DuneTerrain/config.yml` separately on each backend, then restart. + +Valid values are `arrakis`, `giedi_prime`, `kaitain`, `caladan`, and `sigma_draconis_iv`. All five planet profiles are present in each server's config; change `server.planet` to select the world that backend creates. The generated world is named after the selected planet. Adjust its `planets.` settings for terrain, biome, surface, water, vegetation, ores, and spawn coordinates. + +Install DuneCore alongside DuneTerrain if you want the Guild navigator to open DuneCore's travel menu. DuneCore reads the loaded planet world to identify its local backend. For proxy travel, set `network.local-planet` and `network.servers` in DuneCore's config to match the DuneTerrain selection and proxy server names. + +The generator applies only when a world is first created. Existing worlds and already-generated chunks are not replaced by a config change. diff --git a/DuneTerrain/build.gradle.kts b/DuneTerrain/build.gradle.kts new file mode 100644 index 00000000..5d6f121e --- /dev/null +++ b/DuneTerrain/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { java } + +group = "com.example" +version = "1.0.0" + +repositories { + mavenCentral() + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") +} + +java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } +tasks.jar { archiveBaseName.set("DuneTerrain") } +tasks.withType { options.encoding = "UTF-8" } diff --git a/DuneTerrain/settings.gradle.kts b/DuneTerrain/settings.gradle.kts new file mode 100644 index 00000000..b43ecd25 --- /dev/null +++ b/DuneTerrain/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "DuneTerrain" diff --git a/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java new file mode 100644 index 00000000..4285e6e1 --- /dev/null +++ b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java @@ -0,0 +1,221 @@ +package com.example.duneterrain; + +import org.bukkit.*; +import org.bukkit.block.Biome; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Villager; +import org.bukkit.generator.*; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import java.util.*; + +public final class DuneTerrain extends JavaPlugin { + private static final String[] PLANETS = {"arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv"}; + private NamespacedKey guildKey; + + @Override public void onEnable() { + saveDefaultConfig(); + guildKey = new NamespacedKey("dunerealms", "guild"); + String planet = getConfig().getString("server.planet", "arrakis").toLowerCase(Locale.ROOT); + if (!Arrays.asList(PLANETS).contains(planet)) { + getLogger().severe("Invalid server.planet '" + planet + "'. Choose one of: " + String.join(", ", PLANETS)); + getServer().getPluginManager().disablePlugin(this); + return; + } + if (!getConfig().getBoolean("planets." + planet + ".enabled", true)) { + getLogger().severe("Planet '" + planet + "' is disabled in config.yml."); + getServer().getPluginManager().disablePlugin(this); + return; + } + World world = Bukkit.createWorld(new WorldCreator(planet) + .environment(World.Environment.NORMAL) + .generator(new PlanetChunkGenerator(this, planet))); + if (world == null) { + getLogger().severe("Could not create or load world '" + planet + "'."); + getServer().getPluginManager().disablePlugin(this); + return; + } + world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !planet.equals("arrakis")); + world.setTime(planet.equals("giedi_prime") ? 18000 : 6000); + setupPlanetSpawn(world, planet); + getLogger().info("DuneTerrain is generating " + planet + " on this Paper server."); + } + + private void setupPlanetSpawn(World world, String planet) { + String path = "planets." + planet + ".spawn."; + int x = getConfig().getInt(path + "x", 0), z = getConfig().getInt(path + "z", 0); + world.getChunkAt(x >> 4, z >> 4).load(true); + Location spawn = findSafeSpawn(world, x, z); + world.setSpawnLocation(spawn); + if (getConfig().getBoolean("guild-npc.enabled", true)) ensureGuildNpc(world, spawn); + } + + private Location findSafeSpawn(World world, int x, int z) { + for (int radius = 0; radius <= 12; radius++) { + for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { + if (radius > 0 && Math.abs(dx) != radius && Math.abs(dz) != radius) continue; + int bx = x + dx, bz = z + dz; + int y = world.getHighestBlockYAt(bx, bz); + Material ground = world.getBlockAt(bx, y, bz).getType(); + if (!ground.isSolid() || ground == Material.MAGMA_BLOCK || ground == Material.CACTUS || ground == Material.POWDER_SNOW) continue; + if (world.getBlockAt(bx, y + 1, bz).isLiquid() || world.getBlockAt(bx, y + 2, bz).isLiquid()) continue; + return new Location(world, bx + 0.5, y + 1, bz + 0.5); + } + } + int y = Math.max(world.getMinHeight() + 2, world.getHighestBlockYAt(x, z) + 1); + return new Location(world, x + 0.5, y, z + 0.5); + } + + private void ensureGuildNpc(World world, Location spawn) { + Location at = findSafeSpawn(world, spawn.getBlockX() + 2, spawn.getBlockZ()); + for (Entity entity : world.getNearbyEntities(at, 8, 5, 8)) { + if (entity instanceof Villager villager && villager.getPersistentDataContainer().has(guildKey, PersistentDataType.BYTE)) { + villager.teleport(at); + return; + } + } + Villager villager = world.spawn(at, Villager.class); + villager.setCustomName(ChatColor.LIGHT_PURPLE + "Spacing Guild Navigator"); + villager.setCustomNameVisible(true); + villager.setProfession(Villager.Profession.CLERIC); + villager.setAI(false); + villager.setInvulnerable(true); + villager.setSilent(true); + villager.setPersistent(true); + villager.getPersistentDataContainer().set(guildKey, PersistentDataType.BYTE, (byte) 1); + } + + private static class PlanetChunkGenerator extends ChunkGenerator { + private final DuneTerrain plugin; + private final String planet; + PlanetChunkGenerator(DuneTerrain plugin, String planet) { this.plugin = plugin; this.planet = planet; } + @Override public List getDefaultPopulators(World world) { + return planet.equals("arrakis") ? List.of(new SietchPopulator()) : List.of(); + } + @Override public void generateNoise(WorldInfo world, Random random, int chunkX, int chunkZ, ChunkData data) { + String path = "planets." + planet + "."; + int minY = world.getMinHeight(), maxY = world.getMaxHeight() - 1; + int baseHeight = plugin.getConfig().getInt(path + "terrain.base-height", 68); + double variation = plugin.getConfig().getDouble(path + "terrain.height-variation", 8); + double scale = Math.max(0.001, plugin.getConfig().getDouble(path + "terrain.noise-scale", 0.02)); + int waterLevel = plugin.getConfig().getInt(path + "water.level", 63); + Material surface = configuredMaterial(path + "surface", Material.GRASS_BLOCK); + Material filler = configuredMaterial(path + "filler", Material.DIRT); + Material core = planet.equals("giedi_prime") || planet.equals("sigma_draconis_iv") ? Material.DEEPSLATE : Material.STONE; + double flowers = Math.max(0, plugin.getConfig().getDouble(path + "vegetation.flowers-per-chunk", 0)); + double treeChance = Math.max(0, plugin.getConfig().getDouble(path + "vegetation.tree-chance", 0)); + int[][] heights = new int[16][16]; + for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { + int gx = chunkX * 16 + x, gz = chunkZ * 16 + z; + double n = Math.sin(gx * scale) * Math.cos(gz * scale * 1.13) + + Math.sin(gx * scale * 2.7 + gz * scale * 1.45) * 0.35; + int h = Math.max(minY + 8, Math.min(maxY - 8, baseHeight + (int) Math.round(n * variation))); + heights[x][z] = h; + data.setBlock(x, minY, z, Material.BEDROCK); + for (int y = minY + 1; y < h - 3; y++) data.setBlock(x, y, z, core); + for (int y = h - 3; y < h; y++) data.setBlock(x, y, z, filler); + data.setBlock(x, h, z, surface); + + if (plugin.getConfig().getBoolean(path + "water.swamp-pools", false) && h < waterLevel) { + double poolNoise = Math.sin(gx * 0.035) * Math.cos(gz * 0.031); + double coverage = Math.max(0, Math.min(1, plugin.getConfig().getDouble(path + "water.coverage", 0.18))); + if (poolNoise > 0.72 - coverage * 0.75) { + for (int y = h + 1; y <= Math.min(waterLevel, maxY); y++) data.setBlock(x, y, z, Material.WATER); + } + } + if (flowers > 0 && surface == Material.GRASS_BLOCK && random.nextDouble() < Math.min(1, flowers / 256.0)) { + Material[] flowerTypes = {Material.POPPY, Material.DANDELION, Material.CORNFLOWER, + Material.AZURE_BLUET, Material.ALLIUM, Material.OXEYE_DAISY}; + data.setBlock(x, h + 1, z, flowerTypes[random.nextInt(flowerTypes.length)]); + } + if (plugin.getConfig().getBoolean(path + "vegetation.trees", false) + && surface == Material.GRASS_BLOCK && random.nextDouble() < treeChance && x >= 3 && x <= 12 && z >= 3 && z <= 12) { + placeJungleTree(data, x, h + 1, z, random, maxY); + } + } + if (planet.equals("arrakis")) placeSpiceDeposits(data, heights, random, minY, maxY); + placeOres(data, random, path, minY, maxY); + } + @Override public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) { + return new BiomeProvider() { + @Override public Biome getBiome(WorldInfo info, int x, int y, int z) { + String configured = plugin.getConfig().getString("planets." + planet + ".biome", "PLAINS"); + try { return Biome.valueOf(configured.toUpperCase(Locale.ROOT)); } + catch (IllegalArgumentException ex) { return Biome.PLAINS; } + } + @Override public List getBiomes(WorldInfo info) { return List.of(getBiome(info, 0, 64, 0)); } + }; + } + private Material configuredMaterial(String path, Material fallback) { + String name = plugin.getConfig().getString(path, fallback.name()); + Material material = Material.matchMaterial(name == null ? "" : name); + return material == null ? fallback : material; + } + private void placeSpiceDeposits(ChunkData data, int[][] heights, Random random, int minY, int maxY) { + int count = Math.max(0, plugin.getConfig().getInt("spice-deposits.per-chunk", 2)); + for (int i = 0; i < count; i++) { + int x = random.nextInt(16), z = random.nextInt(16), y = heights[x][z]; + if (y + 1 < maxY && y > minY) data.setBlock(x, y, z, Material.SUSPICIOUS_SAND); + } + } + private void placeOres(ChunkData data, Random random, String path, int minWorldY, int maxWorldY) { + org.bukkit.configuration.ConfigurationSection ores = plugin.getConfig().getConfigurationSection(path + "ores"); + if (ores == null) return; + int minY = Math.max(minWorldY + 1, plugin.getConfig().getInt(path + "ores.min-y", -48)); + int maxY = Math.min(maxWorldY - 4, plugin.getConfig().getInt(path + "ores.max-y", 48)); + int veinSize = Math.max(1, Math.min(16, plugin.getConfig().getInt(path + "ores.vein-size", 5))); + if (maxY < minY) return; + for (String key : ores.getKeys(false)) { + Material ore = Material.matchMaterial(key); + if (ore == null || !key.endsWith("_ORE")) continue; + int attempts = Math.max(0, Math.min(64, ores.getInt(key, 0))); + for (int attempt = 0; attempt < attempts; attempt++) { + int x = random.nextInt(16), z = random.nextInt(16), y = minY + random.nextInt(maxY - minY + 1); + for (int n = 0; n < veinSize; n++) { + int vx = Math.max(0, Math.min(15, x + random.nextInt(3) - 1)); + int vz = Math.max(0, Math.min(15, z + random.nextInt(3) - 1)); + int vy = Math.max(minY, Math.min(maxY, y + random.nextInt(3) - 1)); + Material existing = data.getType(vx, vy, vz); + if (existing == Material.STONE || existing == Material.DEEPSLATE || existing == Material.TUFF) data.setBlock(vx, vy, vz, ore); + } + } + } + } + private void placeJungleTree(ChunkData data, int x, int y, int z, Random random, int maxY) { + int height = 4 + random.nextInt(4); + if (y + height + 2 >= maxY || data.getType(x, y - 1, z) != Material.GRASS_BLOCK) return; + for (int dy = 0; dy < height; dy++) data.setBlock(x, y + dy, z, Material.JUNGLE_LOG); + for (int dy = height - 2; dy <= height + 1; dy++) { + int radius = dy >= height ? 1 : 2; + for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { + if (Math.abs(dx) == radius && Math.abs(dz) == radius && random.nextBoolean()) continue; + int lx = x + dx, lz = z + dz, ly = y + dy; + if (lx >= 0 && lx < 16 && lz >= 0 && lz < 16 && data.getType(lx, ly, lz).isAir()) data.setBlock(lx, ly, lz, Material.JUNGLE_LEAVES); + } + } + } + } + private static final class SietchPopulator extends BlockPopulator { + @Override public void populate(WorldInfo world, Random random, int cx, int cz, LimitedRegion region) { + if (!world.getName().equalsIgnoreCase("arrakis") || random.nextInt(90) != 0) return; + int x = cx * 16 + 4 + random.nextInt(8), z = cz * 16 + 4 + random.nextInt(8); + int y = region.getHighestBlockYAt(x, z); + if (y < 65 || y > world.getMaxHeight() - 12 || y - 12 < world.getMinHeight()) return; + for (int dx = -4; dx <= 4; dx++) for (int dz = -4; dz <= 4; dz++) for (int dy = -10; dy <= 3; dy++) { + int ax = x + dx, az = z + dz, ay = y + dy; + if (!region.isInRegion(ax, ay, az)) continue; + boolean cave = dy >= -9 && dy <= -5 && Math.abs(dx) <= 3 && Math.abs(dz) <= 3; + if (cave) region.setType(ax, ay, az, dy <= -8 ? Material.WATER : Material.AIR); + else if (dy >= 0 && dy <= 3 && Math.abs(dx) <= 3 && Math.abs(dz) <= 3) { + boolean wall = Math.abs(dx) == 3 || Math.abs(dz) == 3 || dy == 3; + region.setType(ax, ay, az, wall ? Material.SANDSTONE : Material.AIR); + } + } + for (int dy = -7; dy <= 2; dy++) { + if (region.isInRegion(x, y + dy, z)) region.setType(x, y + dy, z, Material.AIR); + if (region.isInRegion(x + 1, y + dy, z)) region.setType(x + 1, y + dy, z, Material.LADDER); + } + if (region.isInRegion(x, y + 4, z)) region.setType(x, y + 4, z, Material.ORANGE_BANNER); + } + } +} diff --git a/DuneTerrain/src/main/resources/config.yml b/DuneTerrain/src/main/resources/config.yml new file mode 100644 index 00000000..04b6d815 --- /dev/null +++ b/DuneTerrain/src/main/resources/config.yml @@ -0,0 +1,62 @@ +# Set this separately on each Paper backend. +# Accepted values: arrakis, giedi_prime, kaitain, caladan, sigma_draconis_iv +server: + planet: arrakis + +guild-npc: + enabled: true + +spice-deposits: + per-chunk: 2 + +planets: + arrakis: + enabled: true + spawn: {x: 0, z: 0} + terrain: {base-height: 70, height-variation: 11, noise-scale: 0.02} + biome: DESERT + surface: SAND + filler: RED_SAND + water: {level: 63, swamp-pools: false, coverage: 0.18} + vegetation: {trees: false, tree-chance: 0.0, flowers-per-chunk: 0} + ores: {min-y: -48, max-y: 48, vein-size: 5, COAL_ORE: 2, IRON_ORE: 2, COPPER_ORE: 1} + giedi_prime: + enabled: true + spawn: {x: 0, z: 0} + terrain: {base-height: 61, height-variation: 5, noise-scale: 0.02} + biome: SWAMP + surface: BLACKSTONE + filler: DEEPSLATE + water: {level: 63, swamp-pools: true, coverage: 0.18} + vegetation: {trees: false, tree-chance: 0.0, flowers-per-chunk: 0} + ores: {min-y: -48, max-y: 48, vein-size: 5, COAL_ORE: 14, IRON_ORE: 12, COPPER_ORE: 9, GOLD_ORE: 7, REDSTONE_ORE: 8, LAPIS_ORE: 5, DIAMOND_ORE: 4, EMERALD_ORE: 2} + kaitain: + enabled: true + spawn: {x: 0, z: 0} + terrain: {base-height: 70, height-variation: 3, noise-scale: 0.02} + biome: PLAINS + surface: GRASS_BLOCK + filler: DIRT + water: {level: 0, swamp-pools: false, coverage: 0.18} + vegetation: {trees: false, tree-chance: 0.0, flowers-per-chunk: 64} + ores: {min-y: -48, max-y: 48, vein-size: 5, COAL_ORE: 4, IRON_ORE: 5, GOLD_ORE: 15, DIAMOND_ORE: 18, EMERALD_ORE: 3} + caladan: + enabled: true + spawn: {x: 0, z: 0} + terrain: {base-height: 67, height-variation: 10, noise-scale: 0.02} + biome: JUNGLE + surface: GRASS_BLOCK + filler: DIRT + water: {level: 72, swamp-pools: true, coverage: 0.55} + vegetation: {trees: true, tree-chance: 0.035, flowers-per-chunk: 0} + ores: {min-y: -48, max-y: 48, vein-size: 5, COAL_ORE: 4, IRON_ORE: 5, COPPER_ORE: 5, DIAMOND_ORE: 2} + sigma_draconis_iv: + enabled: true + spawn: {x: 0, z: 0} + terrain: {base-height: 72, height-variation: 14, noise-scale: 0.02} + biome: SNOWY_PLAINS + surface: SNOW_BLOCK + filler: DEEPSLATE + water: {level: 0, swamp-pools: false, coverage: 0.18} + vegetation: {trees: false, tree-chance: 0.0, flowers-per-chunk: 0} + ores: {min-y: -48, max-y: 48, vein-size: 5, COAL_ORE: 5, IRON_ORE: 5, COPPER_ORE: 2, DIAMOND_ORE: 2} diff --git a/DuneTerrain/src/main/resources/plugin.yml b/DuneTerrain/src/main/resources/plugin.yml new file mode 100644 index 00000000..0e884836 --- /dev/null +++ b/DuneTerrain/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: DuneTerrain +version: 1.0.0 +main: com.example.duneterrain.DuneTerrain +api-version: '1.21' +description: Configurable Dune planet terrain and spawn generator for Paper