diff --git a/DuneRealms-minecraft-only/README.md b/DuneRealms-minecraft-only/README.md index 077e67e9..c9627ff0 100644 --- a/DuneRealms-minecraft-only/README.md +++ b/DuneRealms-minecraft-only/README.md @@ -1,10 +1,10 @@ # DuneCore for Paper 1.21.4 -Requires Java 21 and Gradle 8+. Run `gradle build` and copy `build/libs/DuneCore-1.0.2.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`. +Requires Java 21 and Gradle 8+. Run `gradle build` and copy `build/libs/DuneCore-1.0.3.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). -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. On Arrakis, defaults place cave sietches about every 2,000 blocks and sand-covered darkstone islands about every 750 blocks. Sietches include sleeping and kitchen chambers, a water descent to a reservoir, and a personal cache with at least 250 tagged spice, enchanted gold armor, planks, and bread. Oasis trees remain sparse at roughly 300-block spacing. Admins can use `/dune admin sietch [player]` to teleport to the nearest generated sietch, `/dune admin arrakis [player]` to reach the Arrakis spawn, and `/dune admin solari ` to grant Solaris to an online player. +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. On Arrakis, defaults place cave sietches and spice blows about every 2,000 blocks, and sand-covered darkstone islands about every 750 blocks. Sietches include sleeping and kitchen chambers, a water descent to a reservoir, and a personal cache with at least 250 tagged spice, enchanted gold armor, planks, and bread. Hitting a spice blow with an arrow or trident, or touching it with a living entity, releases a rich spice field worth about 15,000 Solaris. Oasis trees remain sparse at roughly 300-block spacing. Admins can use `/dune admin sietch [player]` and `/dune admin spiceblow [player]` to teleport to the nearest generated structure, `/dune admin arrakis [player]` to reach the Arrakis spawn, and `/dune admin solari ` to grant Solaris to an online player. Hostile Spice Raider husks spawn randomly on Arrakis, with an increased chance near fields worth more than 5,000 Solaris; configure them under `spice-raiders` in DuneCore's config. 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. diff --git a/DuneRealms-minecraft-only/build.gradle.kts b/DuneRealms-minecraft-only/build.gradle.kts index ef02b910..ac304715 100644 --- a/DuneRealms-minecraft-only/build.gradle.kts +++ b/DuneRealms-minecraft-only/build.gradle.kts @@ -1,6 +1,6 @@ plugins { java } group = "com.example" -version = "1.0.2" +version = "1.0.3" repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/") } dependencies { compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") diff --git a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java index 6cd1e4f8..5119c0eb 100644 --- a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java +++ b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java @@ -47,7 +47,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu private final String[] factions = {"Fremen", "Harkonnen", "Corrino", "Atreides", "Ordos"}; private final Map selected = new HashMap<>(); private final Map money = new HashMap<>(); - private NamespacedKey itemKey, npcKey, wormKey, armorFactionKey; + private NamespacedKey itemKey, npcKey, wormKey, armorFactionKey, raiderKey; private File dataFile; private final Map jobs = new HashMap<>(); private final Map activeWorkers = new HashMap<>(); @@ -68,7 +68,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu @Override public void onEnable() { migrateLegacyData(); - saveDefaultConfig(); itemKey = new NamespacedKey("dunerealms", "item"); npcKey = new NamespacedKey("dunerealms", "guild"); wormKey = new NamespacedKey("dunerealms", "sandworm"); armorFactionKey = new NamespacedKey("dunerealms", "armor_faction"); + saveDefaultConfig(); itemKey = new NamespacedKey("dunerealms", "item"); npcKey = new NamespacedKey("dunerealms", "guild"); wormKey = new NamespacedKey("dunerealms", "sandworm"); armorFactionKey = new NamespacedKey("dunerealms", "armor_faction"); raiderKey = new NamespacedKey("dunerealms", "spice_raider"); 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)); @@ -99,7 +99,8 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu Objects.requireNonNull(getCommand("dune")).setExecutor(this); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getScheduler().runTaskTimer(this, this::spawnSandworms, 200L, 200L); - getLogger().info("DuneCore enabled. Gameplay, faction travel, and Arrakis sandworms ready."); + Bukkit.getScheduler().runTaskTimer(this, this::spawnSpiceRaiders, 200L, 200L); + getLogger().info("DuneCore enabled. Gameplay, faction travel, Arrakis threats, and spice raiders ready."); } @Override public void onDisable() { for (UUID playerId : new ArrayList<>(ordosCloakedArmor.keySet())) restoreOrdosArmor(playerId); @@ -476,8 +477,9 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length > 0 && args[0].equalsIgnoreCase("admin")) { if (!sender.hasPermission("dune.admin")) { sender.sendMessage(ChatColor.RED + "Admin only."); return true; } - if (args.length < 2 || (!args[1].equalsIgnoreCase("arrakis") && !args[1].equalsIgnoreCase("sietch") && !args[1].equalsIgnoreCase("solari"))) { - sender.sendMessage(ChatColor.YELLOW + "Usage: /dune admin [player] | solari "); return true; + if (args.length < 2 || (!args[1].equalsIgnoreCase("arrakis") && !args[1].equalsIgnoreCase("sietch") + && !args[1].equalsIgnoreCase("spiceblow") && !args[1].equalsIgnoreCase("solari"))) { + sender.sendMessage(ChatColor.YELLOW + "Usage: /dune admin [player] | solari "); return true; } if (args[1].equalsIgnoreCase("solari")) { if (args.length != 4) { sender.sendMessage(ChatColor.YELLOW + "Usage: /dune admin solari "); return true; } @@ -500,13 +502,17 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu target = Bukkit.getPlayerExact(args[2]); if (target == null) { sender.sendMessage(ChatColor.RED + "That player is not online."); return true; } } else if (sender instanceof Player player) target = player; - else { sender.sendMessage(ChatColor.YELLOW + "From console, specify an online player: /dune admin "); return true; } + else { sender.sendMessage(ChatColor.YELLOW + "From console, specify an online player: /dune admin "); return true; } World arrakis = Bukkit.getWorld("arrakis"); if (arrakis == null) { sender.sendMessage(ChatColor.RED + "Arrakis is not loaded on this server. Set DuneTerrain's server.planet to arrakis and restart this backend."); return true; } if (args[1].equalsIgnoreCase("sietch")) { teleportToNearestSietch(sender, target, arrakis); return true; } + if (args[1].equalsIgnoreCase("spiceblow")) { + teleportToNearestSpiceBlow(sender, target, arrakis); + return true; + } if (target.teleport(arrakis.getSpawnLocation())) { target.sendMessage(ChatColor.AQUA + "An admin sent you to Arrakis."); sender.sendMessage(ChatColor.GREEN + "Teleported " + target.getName() + " to Arrakis."); @@ -516,7 +522,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu if (!(sender instanceof Player p)) { sender.sendMessage("Run this command in-game."); return true; } if (args.length == 0) { gui.open(p, "main"); return true; } if (args[0].equalsIgnoreCase("help")) { - p.sendMessage(ChatColor.GOLD + "/dune choose , kit, balance, sell, water, travel, politics, exchange, serverjobs, serverjobs accept , job post , job accept , job finish, admin arrakis|sietch [player], admin solari "); return true; + p.sendMessage(ChatColor.GOLD + "/dune choose , kit, balance, sell, water, travel, politics, exchange, serverjobs, serverjobs accept , job post , job accept , job finish, admin arrakis|sietch|spiceblow [player], admin solari "); return true; } switch (args[0].toLowerCase(Locale.ROOT)) { case "choose" -> { @@ -601,6 +607,39 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu value = (value ^ (value >>> 27)) * 0x94D049BB133111EBL; return value ^ (value >>> 31); } + + private void teleportToNearestSpiceBlow(CommandSender sender, Player target, World arrakis) { + Location origin = target.getWorld().equals(arrakis) ? target.getLocation() : arrakis.getSpawnLocation(); + int spacing = 2000; + long cellX = Math.floorDiv(origin.getBlockX(), spacing), cellZ = Math.floorDiv(origin.getBlockZ(), spacing); + List candidates = new ArrayList<>(); + long salt = 0x5350494345424c4fL; + for (long gx = cellX - 2; gx <= cellX + 2; gx++) for (long gz = cellZ - 2; gz <= cellZ + 2; gz++) { + long h1 = sietchMix64(gx * 0x9E3779B97F4A7C15L ^ gz * 0xC2B2AE3D27D4EB4FL ^ salt); + long h2 = sietchMix64(gz * 0x165667B19E3779F9L ^ gx * 0x85EBCA77C2B2AE63L ^ ~salt); + long x = gx * spacing + 8 + Math.floorMod(h1, spacing - 16); + long z = gz * spacing + 8 + Math.floorMod(h2, spacing - 16); + long dx = x - origin.getBlockX(), dz = z - origin.getBlockZ(); + candidates.add(new long[]{x, z, dx * dx + dz * dz}); + } + candidates.sort(Comparator.comparingLong(candidate -> candidate[2])); + for (long[] candidate : candidates) { + int x = (int)candidate[0], z = (int)candidate[1]; + arrakis.getChunkAt(x >> 4, z >> 4).load(true); + int top = arrakis.getHighestBlockYAt(x, z); + Material marker = arrakis.getBlockAt(x, top, z).getType(); + if (marker != Material.MAGMA_BLOCK && marker != Material.GLOWSTONE) continue; + int safeX = x + 4, safeZ = z + 4; + int safeY = arrakis.getHighestBlockYAt(safeX, safeZ) + 1; + if (target.teleport(new Location(arrakis, safeX + 0.5, safeY, safeZ + 0.5))) { + target.sendMessage(ChatColor.AQUA + "An admin sent you to a spice blow on Arrakis."); + sender.sendMessage(ChatColor.GREEN + "Teleported " + target.getName() + " to the nearest spice blow at " + x + ", " + z + "."); + } else sender.sendMessage(ChatColor.RED + "Teleport to the spice blow failed."); + return; + } + sender.sendMessage(ChatColor.RED + "No spice blow was found nearby. Explore new Arrakis terrain with DuneTerrain enabled, then try again."); + } + void runGuiCommand(Player p, String command) { String[] args = command.trim().split("\\s+"); if (args.length == 0 || args[0].isEmpty()) return; @@ -800,6 +839,71 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu private boolean isWorm(Entity entity) { return entity.getPersistentDataContainer().has(wormKey, PersistentDataType.BYTE); } + private boolean isSpiceRaider(Entity entity) { + return entity.getPersistentDataContainer().has(raiderKey, PersistentDataType.BYTE); + } + private void spawnSpiceRaiders() { + if (!getConfig().getBoolean("spice-raiders.enabled", true)) return; + World world = Bukkit.getWorld("arrakis"); + if (world == null) return; + int max = Math.max(0, getConfig().getInt("spice-raiders.max-per-world", 12)); + int count = (int)world.getEntitiesByClass(Husk.class).stream().filter(this::isSpiceRaider).count(); + if (count >= max) return; + Random random = java.util.concurrent.ThreadLocalRandom.current(); + for (Player player : world.getPlayers()) { + if (count >= max) break; + boolean nearRichField = nearHighValueSpice(player); + double chance = getConfig().getDouble(nearRichField ? "spice-raiders.chance-near-rich-field" : "spice-raiders.chance-per-player-check", nearRichField ? 0.45 : 0.08); + if (random.nextDouble() >= Math.max(0, Math.min(1, chance))) continue; + if (world.getNearbyEntities(player.getLocation(), 32, 24, 32).stream().anyMatch(this::isSpiceRaider)) continue; + Husk raider = spawnSpiceRaiderNear(player, random); + if (raider != null) count++; + } + } + private boolean nearHighValueSpice(Player player) { + String path = "spice-raiders."; + int radius = Math.max(8, getConfig().getInt(path + "field-radius", 24)); + int valueThreshold = Math.max(1, getConfig().getInt(path + "field-value-threshold", 5000)); + int price = Math.max(1, getConfig().getInt("spice-sell-price", 15)); + int required = valueThreshold / price + 1; + World world = player.getWorld(); + int centerX = player.getLocation().getBlockX(), centerZ = player.getLocation().getBlockZ(); + int deposits = 0; + for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { + if (dx * dx + dz * dz > radius * radius) continue; + int x = centerX + dx, z = centerZ + dz, y = world.getHighestBlockYAt(x, z); + if (world.getBlockAt(x, y, z).getType() == Material.SUSPICIOUS_SAND && ++deposits >= required) return true; + } + return false; + } + private Husk spawnSpiceRaiderNear(Player target, Random random) { + World world = target.getWorld(); + for (int attempt = 0; attempt < 12; attempt++) { + double angle = random.nextDouble() * Math.PI * 2; + int distance = 16 + random.nextInt(17); + int x = target.getLocation().getBlockX() + (int)Math.round(Math.cos(angle) * distance); + int z = target.getLocation().getBlockZ() + (int)Math.round(Math.sin(angle) * distance); + int y = world.getHighestBlockYAt(x, z); + if (world.getBlockAt(x, y, z).getType() != Material.SAND && world.getBlockAt(x, y, z).getType() != Material.RED_SAND) continue; + if (!world.getBlockAt(x, y + 1, z).isPassable() || !world.getBlockAt(x, y + 2, z).isPassable()) continue; + Location spawn = new Location(world, x + 0.5, y + 1, z + 0.5); + return world.spawn(spawn, Husk.class, raider -> { + raider.getPersistentDataContainer().set(raiderKey, PersistentDataType.BYTE, (byte)1); + raider.setCustomName(ChatColor.DARK_RED + "Spice Raider"); + raider.setCustomNameVisible(true); + raider.setRemoveWhenFarAway(true); + raider.setCanPickupItems(false); + raider.getAttribute(Attribute.MAX_HEALTH).setBaseValue(getConfig().getDouble("spice-raiders.health", 36.0)); + raider.setHealth(raider.getAttribute(Attribute.MAX_HEALTH).getValue()); + raider.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(getConfig().getDouble("spice-raiders.attack-damage", 6.0)); + raider.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(getConfig().getDouble("spice-raiders.movement-speed", 0.28)); + raider.getEquipment().setItemInMainHand(new ItemStack(Material.IRON_SWORD)); + raider.getEquipment().setItemInMainHandDropChance(0.0f); + raider.setTarget(target); + }); + } + return null; + } private void spawnSandworms() { if (!getConfig().getBoolean("sandworms.enabled", true)) return; long now = System.currentTimeMillis(); diff --git a/DuneRealms-minecraft-only/src/main/resources/config.yml b/DuneRealms-minecraft-only/src/main/resources/config.yml index fbc10a90..e89ea16f 100644 --- a/DuneRealms-minecraft-only/src/main/resources/config.yml +++ b/DuneRealms-minecraft-only/src/main/resources/config.yml @@ -12,6 +12,19 @@ sandworms: spawn-chance: 0.35 spawn-interval-seconds: 3600 +# Hostile husk raiders appear around Arrakis players and are more common near +# spice fields worth over this many Solaris at the base selling price. +spice-raiders: + enabled: true + max-per-world: 12 + chance-per-player-check: 0.08 + chance-near-rich-field: 0.45 + field-radius: 32 + field-value-threshold: 5000 + health: 36.0 + attack-damage: 6.0 + movement-speed: 0.28 + # Arrakis solar exposure: 5 minutes of uninterrupted direct sunlight without a full stillsuit. arrakis-sun: enabled: true diff --git a/DuneRealms-minecraft-only/src/main/resources/plugin.yml b/DuneRealms-minecraft-only/src/main/resources/plugin.yml index 6705f9b7..1023a6c1 100644 --- a/DuneRealms-minecraft-only/src/main/resources/plugin.yml +++ b/DuneRealms-minecraft-only/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: DuneCore -version: 1.0.2 +version: 1.0.3 main: com.example.dunerealms.DuneCore api-version: '1.21' softdepend: [DuneTerrain] diff --git a/DuneTerrain/README.md b/DuneTerrain/README.md index d7569248..3f4d076e 100644 --- a/DuneTerrain/README.md +++ b/DuneTerrain/README.md @@ -10,7 +10,7 @@ Build the plugin from this directory with Java 21 and Gradle 8.14 or newer: gradle clean build ``` -Copy `build/libs/DuneTerrain-1.0.3.jar` into the Paper server's `plugins/` directory. Set `server.planet` in `plugins/DuneTerrain/config.yml` separately on each backend, then restart. +Copy `build/libs/DuneTerrain-1.0.4.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. @@ -29,6 +29,6 @@ For another primary planet, replace both `arrakis` values with that planet name. The generator applies to newly generated chunks. Existing chunks are never replaced by a config change. If the selected planet world already exists with non-Arrakis terrain or rivers, stop the server, back up and move that world's folder out of the server directory, then restart to create it with DuneTerrain. DuneTerrain registers the generator at startup and creates a separate planet world only after Paper has finished loading, if needed. -Arrakis uses the Desert biome throughout and has no vanilla vegetation. Sparse persistent-leaf oasis trees remain about 300 blocks apart. A larger underground cave sietch generates about every 2,000 blocks; it has connected sleeping and kitchen chambers, a concealed entry, a waterfall descent into a bottom reservoir, and a personal cache per player containing at least 250 tagged spice, enchanted gold armor, planks, and bread. Sand-covered darkstone islands generate about every 750 blocks. Set `sietches.spacing` and `planets.arrakis.darkstone-islands.spacing` to adjust those intervals. Random spice patches generate about 35% of 600-by-600-block regions; each patch has roughly 5,000 Solaris in deposits at the default 15 Solaris per spice. Adjust `spice-deposits.patches` for patch frequency, size, or value. +Arrakis uses the Desert biome throughout and has no vanilla vegetation. Sparse persistent-leaf oasis trees remain about 300 blocks apart. A larger underground cave sietch generates about every 2,000 blocks; it has connected sleeping and kitchen chambers, a concealed entry, a waterfall descent into a bottom reservoir, and a personal cache per player containing at least 250 tagged spice, enchanted gold armor, planks, and bread. Sand-covered darkstone islands generate about every 750 blocks. Spice blows also generate about every 2,000 blocks as a magma cluster; touching one with a living entity or hitting it with an arrow or trident releases a rich suspicious-sand field worth about 15,000 Solaris at the default 15 Solaris per spice. Admins can use `/dune admin spiceblow [player]` to teleport to the nearest generated or erupted spice blow. Set `sietches.spacing`, `spice-blow.spacing`, and `planets.arrakis.darkstone-islands.spacing` to adjust structure intervals. Random spice patches generate about 35% of 600-by-600-block regions; each patch has roughly 5,000 Solaris in deposits at the default price. Adjust `spice-deposits.patches` for patch frequency, size, or value. DuneCore sends new players who have not chosen a faction from Paper's default `world` to the local planet spawn, so they arrive in the world generated by DuneTerrain. diff --git a/DuneTerrain/build.gradle.kts b/DuneTerrain/build.gradle.kts index 8ec70399..4fb6b7e0 100644 --- a/DuneTerrain/build.gradle.kts +++ b/DuneTerrain/build.gradle.kts @@ -1,7 +1,7 @@ plugins { java } group = "com.example" -version = "1.0.3" +version = "1.0.4" repositories { mavenCentral() diff --git a/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java index cc09183e..f9921563 100644 --- a/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java +++ b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java @@ -2,18 +2,24 @@ package com.example.duneterrain; import org.bukkit.*; import org.bukkit.block.Biome; +import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.block.BlockState; import org.bukkit.block.data.type.Bed; import org.bukkit.entity.Entity; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Trident; import org.bukkit.entity.Villager; +import io.papermc.paper.event.entity.EntityMoveEvent; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.generator.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -33,6 +39,87 @@ public final class DuneTerrain extends JavaPlugin implements Listener { private final Map openSietchLoot = new HashMap<>(); private record PersonalLoot(Inventory inventory, String id) {} + @EventHandler public void onSpiceBlowProjectile(ProjectileHitEvent event) { + if (!(event.getEntity() instanceof Arrow) && !(event.getEntity() instanceof Trident)) return; + if (event.getHitBlock() != null) triggerSpiceBlowAt(event.getHitBlock().getLocation()); + else if (event.getHitEntity() != null) triggerSpiceBlowAt(event.getHitEntity().getLocation()); + } + + @EventHandler public void onSpiceBlowPlayerMove(PlayerMoveEvent event) { + if (event.getTo() == null || (event.getFrom().getBlockX() == event.getTo().getBlockX() + && event.getFrom().getBlockY() == event.getTo().getBlockY() + && event.getFrom().getBlockZ() == event.getTo().getBlockZ())) return; + triggerSpiceBlowAt(event.getTo()); + } + + @EventHandler public void onSpiceBlowEntityMove(EntityMoveEvent event) { + if (event.hasChangedBlock() && event.getTo() != null) triggerSpiceBlowAt(event.getTo()); + } + + private void triggerSpiceBlowAt(Location location) { + if (location == null || location.getWorld() == null || !location.getWorld().getName().equalsIgnoreCase("arrakis")) return; + int x = location.getBlockX(), y = location.getBlockY(), z = location.getBlockZ(); + for (int dy = -1; dy <= 0; dy++) for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) { + Block block = location.getWorld().getBlockAt(x + dx, y + dy, z + dz); + if (block.getType() != Material.MAGMA_BLOCK) continue; + Block center = findSpiceBlowCenter(block); + if (center != null) detonateSpiceBlow(center); + } + } + + private Block findSpiceBlowCenter(Block touched) { + World world = touched.getWorld(); + for (int cx = touched.getX() - 1; cx <= touched.getX() + 1; cx++) + for (int cz = touched.getZ() - 1; cz <= touched.getZ() + 1; cz++) + for (int topY = touched.getY() - 1; topY <= touched.getY() + 1; topY++) { + if (world.getBlockAt(cx, topY, cz).getType() != Material.MAGMA_BLOCK + || world.getBlockAt(cx, topY - 1, cz).getType() != Material.MAGMA_BLOCK) continue; + boolean patch = true; + for (int dx = -1; dx <= 1 && patch; dx++) for (int dz = -1; dz <= 1; dz++) + if (world.getBlockAt(cx + dx, topY - 1, cz + dz).getType() != Material.MAGMA_BLOCK) { patch = false; break; } + if (patch) return world.getBlockAt(cx, topY, cz); + } + return null; + } + + private void detonateSpiceBlow(Block center) { + if (center.getType() != Material.MAGMA_BLOCK) return; + World world = center.getWorld(); + int x = center.getX(), z = center.getZ(), baseY = center.getY() - 1; + for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) + world.getBlockAt(x + dx, baseY, z + dz).setType(Material.AIR, false); + center.setType(Material.GLOWSTONE, false); + world.playSound(center.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.5f, 0.7f); + world.spawnParticle(Particle.EXPLOSION, center.getLocation().add(0.5, 0.5, 0.5), 1); + + String path = "spice-blow."; + int targetValue = Math.max(1, getConfig().getInt(path + "target-value", 15000)); + int unitPrice = Math.max(1, getConfig().getInt(path + "unit-price", 15)); + org.bukkit.plugin.Plugin core = Bukkit.getPluginManager().getPlugin("DuneCore"); + if (core instanceof JavaPlugin corePlugin) + unitPrice = Math.max(1, corePlugin.getConfig().getInt("spice-sell-price", unitPrice)); + int targetDeposits = (int)Math.ceil(targetValue / (double)unitPrice); + int radius = Math.max(12, getConfig().getInt(path + "radius", 24)); + List candidates = new ArrayList<>(); + for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { + if (dx * dx + dz * dz > radius * radius) continue; + int bx = x + dx, bz = z + dz; + int surfaceY = world.getHighestBlockYAt(bx, bz); + Material surface = world.getBlockAt(bx, surfaceY, bz).getType(); + if (surface == Material.SAND || surface == Material.RED_SAND) candidates.add(world.getBlockAt(bx, surfaceY, bz)); + } + candidates.sort(Comparator.comparingLong(block -> mix64((long)block.getX() * 0x9E3779B97F4A7C15L + ^ (long)block.getZ() * 0xC2B2AE3D27D4EB4FL ^ world.getSeed() ^ 0x5350494345424c4fL))); + int placed = 0; + for (Block block : candidates) { + if (placed >= targetDeposits) break; + block.setType(Material.SUSPICIOUS_SAND, false); + placed++; + } + world.getPlayers().forEach(player -> player.sendMessage(ChatColor.GOLD + "A spice blow erupted on Arrakis! A rich field has surfaced nearby.")); + getLogger().info("Spice blow at " + x + ", " + z + " deployed " + placed + " spice deposits (target value " + targetValue + " Solaris)."); + } + @EventHandler public void onSietchChestOpen(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null) return; if (event.getHand() != org.bukkit.inventory.EquipmentSlot.HAND) return; @@ -240,7 +327,7 @@ public final class DuneTerrain extends JavaPlugin implements Listener { 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(plugin)) : List.of(); + return planet.equals("arrakis") ? List.of(new SietchPopulator(plugin), new SpiceBlowPopulator(plugin)) : List.of(); } @Override public void generateNoise(WorldInfo world, Random random, int chunkX, int chunkZ, ChunkData data) { String path = "planets." + planet + "."; @@ -591,4 +678,28 @@ public final class DuneTerrain extends JavaPlugin implements Listener { if (region.isInRegion(x, y, z)) region.setType(x, y, z, material); } } + + private static final class SpiceBlowPopulator extends BlockPopulator { + private static final long SALT = 0x5350494345424c4fL; + private final DuneTerrain plugin; + private SpiceBlowPopulator(DuneTerrain plugin) { this.plugin = plugin; } + + @Override public void populate(WorldInfo world, Random random, int chunkX, int chunkZ, LimitedRegion region) { + if (!world.getName().equalsIgnoreCase("arrakis") || !plugin.getConfig().getBoolean("spice-blow.enabled", true)) return; + int spacing = Math.max(256, plugin.getConfig().getInt("spice-blow.spacing", 2000)); + long centerX = chunkX * 16L + 8, centerZ = chunkZ * 16L + 8; + long cellX = Math.floorDiv(centerX, spacing), cellZ = Math.floorDiv(centerZ, spacing); + long h1 = mix64(cellX * 0x9E3779B97F4A7C15L ^ cellZ * 0xC2B2AE3D27D4EB4FL ^ SALT); + long h2 = mix64(cellZ * 0x165667B19E3779F9L ^ cellX * 0x85EBCA77C2B2AE63L ^ ~SALT); + long anchorX = cellX * spacing + 8 + Math.floorMod(h1, spacing - 16); + long anchorZ = cellZ * spacing + 8 + Math.floorMod(h2, spacing - 16); + if (Math.floorDiv(anchorX, 16) != chunkX || Math.floorDiv(anchorZ, 16) != chunkZ) return; + int x = (int)anchorX, z = (int)anchorZ, y = region.getHighestBlockYAt(x, z); + if (y < world.getMinHeight() + 2 || y + 2 >= world.getMaxHeight()) return; + if (!region.isInRegion(x, y, z) || region.getType(x, y, z) != Material.SAND) return; + for (int dx = -1; dx <= 1; dx++) for (int dz = -1; dz <= 1; dz++) + if (region.isInRegion(x + dx, y, z + dz)) region.setType(x + dx, y, z + dz, Material.MAGMA_BLOCK); + if (region.isInRegion(x, y + 1, z)) region.setType(x, y + 1, z, Material.MAGMA_BLOCK); + } + } } diff --git a/DuneTerrain/src/main/resources/config.yml b/DuneTerrain/src/main/resources/config.yml index a73cab45..c26025c9 100644 --- a/DuneTerrain/src/main/resources/config.yml +++ b/DuneTerrain/src/main/resources/config.yml @@ -11,6 +11,13 @@ sietches: enabled: true spacing: 2000 +spice-blow: + enabled: true + spacing: 2000 + radius: 24 + target-value: 15000 + unit-price: 15 + spice-deposits: per-chunk: 2 patches: diff --git a/DuneTerrain/src/main/resources/plugin.yml b/DuneTerrain/src/main/resources/plugin.yml index 9d8415e9..6f3052d0 100644 --- a/DuneTerrain/src/main/resources/plugin.yml +++ b/DuneTerrain/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: DuneTerrain -version: 1.0.3 +version: 1.0.4 main: com.example.duneterrain.DuneTerrain api-version: '1.21' load: STARTUP