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.Player; import org.bukkit.entity.Arrow; import org.bukkit.entity.Trident; 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; import org.bukkit.enchantments.Enchantment; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.server.ServerLoadEvent; import org.bukkit.event.world.ChunkLoadEvent; import java.io.File; import java.util.*; public final class DuneTerrain extends JavaPlugin implements Listener { private static final String[] PLANETS = {"arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv"}; private NamespacedKey sietchLootIdKey; final SpiceDepositProvenance spiceProvenance=new SpiceDepositProvenance(); public boolean isGeneratedSpiceDeposit(Block block){return block!=null&&block.getWorld().getName().equals("arrakis")&&SpiceDepositProvenance.authentic(block);} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void placedSpice(org.bukkit.event.block.BlockPlaceEvent event){if(event.getBlock().getWorld().getName().equals("arrakis")){SpiceDepositProvenance.forget(event.getBlock());SpiceDepositProvenance.invalidateBloom(event.getBlock());}} @EventHandler public void spiceChunkPopulated(org.bukkit.event.world.ChunkPopulateEvent event){if(event.getWorld().getName().equals("arrakis"))spiceProvenance.commitBloom(event.getChunk());} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void brokenBloom(org.bukkit.event.block.BlockBreakEvent event){if(event.getBlock().getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(event.getBlock());} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void movedBloom(org.bukkit.event.block.BlockPistonExtendEvent event){for(Block block:event.getBlocks())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void retractedBloom(org.bukkit.event.block.BlockPistonRetractEvent event){for(Block block:event.getBlocks())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void explodedBloom(org.bukkit.event.entity.EntityExplodeEvent event){for(Block block:event.blockList())if(block.getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(block);} @EventHandler(priority=org.bukkit.event.EventPriority.MONITOR,ignoreCancelled=true) public void changedBloom(org.bukkit.event.entity.EntityChangeBlockEvent event){if(event.getBlock().getWorld().getName().equals("arrakis"))SpiceDepositProvenance.invalidateBloom(event.getBlock());} private final Map openSietchLoot = new HashMap<>(); private record PersonalLoot(Inventory inventory, String id) {} public void announceSpiceBloom(Location location) { ArrakisEcology.bloom(this, location); org.bukkit.plugin.Plugin core = Bukkit.getPluginManager().getPlugin("DuneCore"); if (core == null || !core.isEnabled()) return; try { String id = "bloom:" + location.getWorld().getUID() + ":" + location.getBlockX() + ":" + location.getBlockY() + ":" + location.getBlockZ(); core.getClass().getMethod("announceArrakisEvent", String.class, Location.class, String.class) .invoke(core, "spicebloom", location, id); } catch (ReflectiveOperationException ex) { getLogger().warning("Spice bloom announcement failed: " + ex.getMessage()); } } @EventHandler public void onBloomChunkLoad(ChunkLoadEvent event) { if (!event.getWorld().getName().equalsIgnoreCase("arrakis")) return; Chunk chunk = event.getChunk(); Bukkit.getScheduler().runTask(this, () -> inspectBlooms(chunk)); } private void inspectBlooms(Chunk chunk) { World world = chunk.getWorld(); if (!chunk.isLoaded()) return; for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int wx = chunk.getX() * 16 + x, wz = chunk.getZ() * 16 + z; int y = world.getHighestBlockYAt(wx, wz); // The raised marker sits above a 3x3 magma patch; no neighbouring chunk access. if (y > world.getMinHeight() && chunk.getBlock(x, y, z).getType() == Material.MAGMA_BLOCK && chunk.getBlock(x, y - 1, z).getType() == Material.MAGMA_BLOCK) announceSpiceBloom(new Location(world, wx, y, wz)); } } @EventHandler public void onSpiceBlowProjectile(ProjectileHitEvent event) { if (!(event.getEntity() instanceof Arrow) && !(event.getEntity() instanceof Trident)) return; Player actor=event.getEntity().getShooter() instanceof Player p?p:null; if (event.getHitBlock() != null) triggerSpiceBlowAt(event.getHitBlock().getLocation(),actor); else if (event.getHitEntity() != null) triggerSpiceBlowAt(event.getHitEntity().getLocation(),actor); } @EventHandler(ignoreCancelled=true) 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(),event.getPlayer()); } @EventHandler public void onSpiceBlowEntityMove(EntityMoveEvent event) { if (event.hasChangedBlock() && event.getTo() != null) triggerSpiceBlowAt(event.getTo(),null); } private void triggerSpiceBlowAt(Location location,Player actor) { 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); if(actor!=null&&(generatedSpiceBlow(center.getX(),center.getZ(),Math.max(256,getConfig().getInt("spice-blow.spacing",2000)))||ArrakisBlooms.matches(center.getWorld().getSeed(),center.getX(),center.getZ(),Math.max(1,getConfig().getInt("spice-blow.rarity",ArrakisBlooms.DESERT_WELL_RARITY))))&¢er.getType()==Material.GLOWSTONE){ UUID reference=UUID.nameUUIDFromBytes((center.getWorld().getUID()+":"+center.getX()+":"+center.getZ()).getBytes(java.nio.charset.StandardCharsets.UTF_8)); FaunaProof.milestone(actor,"husbandry_spice_blow",reference); } } } } static boolean generatedSpiceBlow(int x,int z,int spacing){long cx=Math.floorDiv((long)x,spacing),cz=Math.floorDiv((long)z,spacing);long salt=SpiceBlowPopulator.SALT;long h1=mix64(cx*0x9E3779B97F4A7C15L^cz*0xC2B2AE3D27D4EB4FL^salt),h2=mix64(cz*0x165667B19E3779F9L^cx*0x85EBCA77C2B2AE63L^~salt);return x==cx*spacing+8+Math.floorMod(h1,spacing-16)&&z==cz*spacing+8+Math.floorMod(h2,spacing-16);} 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; boolean authenticatedBloom=SpiceDepositProvenance.takeBloom(center); 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 economy = Bukkit.getPluginManager().getPlugin("DuneEss"); if (economy instanceof JavaPlugin economyPlugin) unitPrice = Math.max(1, economyPlugin.getConfig().getInt("currency.spice-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); if(authenticatedBloom)SpiceDepositProvenance.mark(block.getState()); placed++; } announceSpiceBloom(center.getLocation()); for (org.bukkit.entity.Player player : world.getPlayers()) player.sendMessage(ChatColor.GOLD + "A spice blow erupted at X " + x + ", Y " + center.getY() + ", Z " + z + " on Arrakis! " + placed + " deposits surfaced."); 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; BlockState state = event.getClickedBlock().getState(); if (!(state instanceof Chest chest)) return; String id = chest.getPersistentDataContainer().get(sietchLootIdKey, PersistentDataType.STRING); if (id == null) return; event.setCancelled(true); org.bukkit.entity.Player player = event.getPlayer(); NamespacedKey claimedKey = new NamespacedKey(this, "sietch_claim_" + id); if (player.getPersistentDataContainer().has(claimedKey, PersistentDataType.BYTE)) { player.sendMessage(ChatColor.YELLOW + "You have already claimed this sietch cache."); return; } Inventory inventory = Bukkit.createInventory(null, 27, ChatColor.DARK_GRAY + "Sietch Cache"); addLoot(inventory, spiceItem(64)); addLoot(inventory, spiceItem(64)); addLoot(inventory, spiceItem(64)); addLoot(inventory, spiceItem(58)); addLoot(inventory, enchantedGold(Material.GOLDEN_HELMET)); addLoot(inventory, enchantedGold(Material.GOLDEN_CHESTPLATE)); addLoot(inventory, enchantedGold(Material.GOLDEN_LEGGINGS)); addLoot(inventory, enchantedGold(Material.GOLDEN_BOOTS)); addLoot(inventory, new ItemStack(Material.OAK_PLANKS, 32)); addLoot(inventory, new ItemStack(Material.BREAD, 16)); openSietchLoot.put(player.getUniqueId(), new PersonalLoot(inventory, id)); player.openInventory(inventory); player.sendMessage(ChatColor.GOLD + "This personal cache contains supplies for you."); } @EventHandler public void onSietchLootClick(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof org.bukkit.entity.Player player)) return; PersonalLoot loot = openSietchLoot.get(player.getUniqueId()); if (loot == null || event.getView().getTopInventory() != loot.inventory()) return; if (event.getClickedInventory() != loot.inventory()) return; event.setCancelled(true); ItemStack item = event.getCurrentItem(); if (item == null || item.getType().isAir()) return; Map leftovers = player.getInventory().addItem(item.clone()); if (leftovers.isEmpty()) loot.inventory().setItem(event.getSlot(), null); else { loot.inventory().setItem(event.getSlot(), leftovers.values().iterator().next()); player.sendMessage(ChatColor.RED + "Your inventory only had room for part of that stack."); } } @EventHandler public void onSietchLootDrag(InventoryDragEvent event) { if (!(event.getWhoClicked() instanceof org.bukkit.entity.Player player)) return; PersonalLoot loot = openSietchLoot.get(player.getUniqueId()); if (loot != null && event.getView().getTopInventory() == loot.inventory()) event.setCancelled(true); } @EventHandler public void onSietchLootClose(InventoryCloseEvent event) { if (!(event.getPlayer() instanceof org.bukkit.entity.Player player)) return; PersonalLoot loot = openSietchLoot.get(player.getUniqueId()); if (loot == null || event.getView().getTopInventory() != loot.inventory()) return; openSietchLoot.remove(player.getUniqueId()); for (ItemStack item : loot.inventory().getContents()) if (item != null && !item.getType().isAir()) { Map leftovers = player.getInventory().addItem(item); leftovers.values().forEach(left -> player.getWorld().dropItemNaturally(player.getLocation(), left)); } player.getPersistentDataContainer().set(new NamespacedKey(this, "sietch_claim_" + loot.id()), PersistentDataType.BYTE, (byte) 1); } private static void addLoot(Inventory inventory, ItemStack item) { for (int slot = 0; slot < inventory.getSize(); slot++) if (inventory.getItem(slot) == null) { inventory.setItem(slot, item); return; } } static ItemStack spiceItem(int amount) { ItemStack item = new ItemStack(Material.ORANGE_DYE, amount); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(ChatColor.GOLD + "Melange Spice"); meta.getPersistentDataContainer().set(new NamespacedKey("dunerealms", "item"), PersistentDataType.STRING, "spice"); item.setItemMeta(meta); return item; } private static ItemStack enchantedGold(Material material) { ItemStack item = new ItemStack(material); ItemMeta meta = item.getItemMeta(); meta.addEnchant(Enchantment.PROTECTION, 2, true); meta.addEnchant(Enchantment.UNBREAKING, 2, true); item.setItemMeta(meta); return item; } @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { String planet = id == null || id.isBlank() ? getConfig().getString("server.planet", "arrakis") : id; planet = planet.toLowerCase(Locale.ROOT); if (!Arrays.asList(PLANETS).contains(planet)) { getLogger().severe("Invalid generator planet '" + planet + "' for world '" + worldName + "'."); return null; } if (!getConfig().getBoolean("planets." + planet + ".enabled", true)) { getLogger().severe("Generator planet '" + planet + "' is disabled in config.yml."); return null; } return new PlanetChunkGenerator(this, planet); } @Override public BiomeProvider getDefaultBiomeProvider(String worldName, String id) { String planet = id == null || id.isBlank() ? getConfig().getString("server.planet", "arrakis") : id; planet = planet.toLowerCase(Locale.ROOT); if (!Arrays.asList(PLANETS).contains(planet)) { getLogger().severe("Invalid biome-provider planet '" + planet + "' for world '" + worldName + "'."); return null; } return new PlanetBiomeProvider(this, planet); } @Override public void onEnable() { com.dunerealms.npc.CitizensBridge.start(this,new NamespacedKey("dunerealms","spice-seller")); saveDefaultConfig(); String formations = "planets.arrakis.darkstone-islands."; if (getConfig().getInt(formations + "min-radius") == 10 && getConfig().getInt(formations + "max-radius") == 18) { getConfig().set(formations + "min-radius", 45); getConfig().set(formations + "max-radius", 55); saveConfig(); getLogger().info("Upgraded default Arrakis rock formations to about 100 blocks across in new chunks."); } getServer().getPluginManager().registerEvents(this, this); 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); 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; } getLogger().info("DuneTerrain registered the " + planet + " generator. World setup will run after Paper finishes loading worlds."); } @EventHandler public void onServerLoad(ServerLoadEvent event) { World arrakis = Bukkit.getWorld("arrakis"); if (arrakis != null) for (Chunk chunk : arrakis.getLoadedChunks()) Bukkit.getScheduler().runTask(this, () -> inspectBlooms(chunk)); String planet = getConfig().getString("server.planet", "arrakis").toLowerCase(Locale.ROOT); World world = Bukkit.getWorld(planet); if (world == null) { File worldFolder = new File(getServer().getWorldContainer(), planet); boolean existingWorld = worldFolder.isDirectory(); 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 + "'."); return; } if (existingWorld) getLogger().warning("Loaded existing world '" + planet + "'. Existing chunks remain unchanged; move the world folder after backing it up to regenerate terrain."); else getLogger().info("Created world '" + planet + "' with DuneTerrain."); } else if (!(world.getGenerator() instanceof PlanetChunkGenerator)) { getLogger().severe("World '" + planet + "' was loaded without DuneTerrain's generator. Configure bukkit.yml worlds." + planet + ".generator: DuneTerrain:" + planet + " and worlds." + planet + ".biome-provider: DuneTerrain:" + planet + ". Existing chunks remain unchanged."); } else { getLogger().info("World '" + planet + "' was loaded with DuneTerrain's configured generator."); } world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !planet.equals("arrakis")&&!planet.equals("giedi_prime")); if(planet.equals("giedi_prime")){world.setStorm(false);world.setGameRule(GameRule.DO_WEATHER_CYCLE,false);} world.setTime(planet.equals("giedi_prime") ? 18000 : 6000); setupPlanetSpawn(world, planet); } 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); } 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 static class PlanetChunkGenerator extends ChunkGenerator { private final DuneTerrain plugin; private final String planet; private record GroundKey(RockPlateaus.Shape shape, int baseHeight, double variation) {} private final java.util.concurrent.ConcurrentHashMap formationGround = new java.util.concurrent.ConcurrentHashMap<>(); PlanetChunkGenerator(DuneTerrain plugin, String planet) { this.plugin = plugin; this.planet = planet; } @Override public List 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), 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)){ TemperateLandscape.generate(world,random,chunkX,chunkZ,data,planet); placeOres(data,random,"planets."+planet+".",world.getMinHeight(),world.getMaxHeight()-1);return; } 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); if(planet.equals("arrakis")){ for(int y=minY+1;y<=h;y++)data.setBlock(x,y,z,ArrakisStrata.material(h-y)); }else{ 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); } } boolean arrakisWorld = planet.equals("arrakis") && world.getName().equalsIgnoreCase("arrakis"); if (arrakisWorld) placeOasisTree(data, chunkX, chunkZ, heights, minY, maxY); var emittedSpice=new ArrayList(); if (arrakisWorld) { placeDarkstoneIsland(data, chunkX, chunkZ, heights, minY, maxY); placeSpiceDeposits(data, heights, random, minY, maxY,emittedSpice); placeRandomSpicePatch(data, chunkX, chunkZ, heights,emittedSpice); if (plugin.getConfig().getBoolean("dense-spice.enabled", true)) { int spacing = Math.max(128, plugin.getConfig().getInt("dense-spice.spacing", 512)); for(var entries=emittedSpice.iterator();entries.hasNext();){ var p=entries.next(); if(DenseSpice.contains(world.getSeed(),chunkX*16+p.x(),chunkZ*16+p.z(),spacing))entries.remove(); } for (int x=0;x<16;x++) for(int z=0;z<16;z++) if(DenseSpice.contains(world.getSeed(),chunkX*16+x,chunkZ*16+z,spacing)) data.setBlock(x,heights[x][z],z,Material.ORANGE_TERRACOTTA); } } placeOres(data, random, path, minY, maxY); if(arrakisWorld&&plugin.spiceProvenance!=null)plugin.spiceProvenance.capture(world,chunkX,chunkZ,emittedSpice,data); } @Override public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) { return new PlanetBiomeProvider(plugin, planet); } @Override public void generateCaves(WorldInfo world,Random random,int x,int z,ChunkData data){OceanAquifers.flood(world,x,z,data,planet);OrdosSulfurSurfaces.apply(world,x,z,data);} @Override public boolean shouldGenerateStructures(WorldInfo world,Random random,int x,int z){return Set.of("caladan","kaitain","giedi_prime","sigma_draconis_iv","arrakis").contains(planet);} @Override public boolean shouldGenerateDecorations(WorldInfo world,Random random,int x,int z){return TemperateLandscape.enabled(planet);} @Override public boolean shouldGenerateMobs(WorldInfo world,Random random,int x,int z){return planet.equals("arrakis")||TemperateLandscape.enabled(planet);} @Override public boolean shouldGenerateCaves(WorldInfo world,Random random,int x,int z){return Set.of("caladan","kaitain","giedi_prime","sigma_draconis_iv","arrakis").contains(planet);} @Override public int getBaseHeight(WorldInfo world,Random random,int x,int z,org.bukkit.HeightMap map){if(planet.equals("arrakis")){String path="planets.arrakis.terrain.";int base=plugin.getConfig().getInt(path+"base-height",68);double variation=plugin.getConfig().getDouble(path+"height-variation",8),scale=Math.max(.001,plugin.getConfig().getDouble(path+"noise-scale",.02));double n=Math.sin(x*scale)*Math.cos(z*scale*1.13)+Math.sin(x*scale*2.7+z*scale*1.45)*.35;return Math.max(world.getMinHeight()+8,Math.min(world.getMaxHeight()-9,base+(int)Math.round(n*variation)))+1;}if(!TemperateLandscape.enabled(planet))return super.getBaseHeight(world,random,x,z,map);int h=TemperateLandscape.height(world.getSeed(),x,z,planet);return (map==org.bukkit.HeightMap.OCEAN_FLOOR||map==org.bukkit.HeightMap.OCEAN_FLOOR_WG||planet.equals("giedi_prime")&&!TemperateLandscape.lavaSurface(world.getSeed(),x,z)?h:Math.max(TemperateLandscape.SEA,h))+1;} private void placeOasisTree(ChunkData data, int chunkX, int chunkZ, int[][] heights, int minY, int maxY) { String path = "planets.arrakis.oasis-trees."; if (!plugin.getConfig().getBoolean(path + "enabled", true)) return; int spacing = Math.max(64, plugin.getConfig().getInt(path + "spacing", 300)); long[] anchor = gridAnchor(chunkX, chunkZ, spacing, 0x4f41534953545245L); if (Math.floorDiv(anchor[0], 16) != chunkX || Math.floorDiv(anchor[1], 16) != chunkZ) return; int x = Math.floorMod(anchor[0], 16), z = Math.floorMod(anchor[1], 16); int y = heights[x][z] + 1; int height = Math.max(4, plugin.getConfig().getInt(path + "trunk-height", 7)); if (y + height + 3 >= maxY || data.getType(x, y - 1, z) != Material.SAND) return; for (int dy = 0; dy < height; dy++) data.setBlock(x, y + dy, z, Material.OAK_LOG); for (int dy = height - 3; dy <= height + 2; dy++) { int radius = dy >= height + 1 ? 2 : 3; for (int dx = -radius; dx <= radius; dx++) for (int dz = -radius; dz <= radius; dz++) { if (Math.abs(dx) == radius && Math.abs(dz) == radius && Math.floorMod(dx * 31 + dz * 17, 3) == 0) continue; int lx = x + dx, lz = z + dz, ly = y + dy; if (lx < 0 || lx >= 16 || lz < 0 || lz >= 16 || ly >= maxY || !data.getType(lx, ly, lz).isAir()) continue; org.bukkit.block.data.type.Leaves leaves = (org.bukkit.block.data.type.Leaves) Bukkit.createBlockData(Material.OAK_LEAVES); leaves.setPersistent(false); leaves.setDistance(Math.min(7,Math.max(1,Math.abs(dx)+Math.abs(dz)+Math.max(0,dy-height+1)))); data.setBlock(lx, ly, lz, leaves); } } } private long[] gridAnchor(int chunkX, int chunkZ, int spacing, long salt) { int centerX = chunkX * 16 + 8, centerZ = chunkZ * 16 + 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 x = cellX * spacing + 8 + Math.floorMod(h1, spacing - 16); long z = cellZ * spacing + 8 + Math.floorMod(h2, spacing - 16); if (Math.floorDiv(x, spacing) != cellX || Math.floorDiv(z, spacing) != cellZ) return new long[]{Long.MIN_VALUE, Long.MIN_VALUE}; return new long[]{x, z}; } private void placeDarkstoneIsland(ChunkData data, int chunkX, int chunkZ, int[][] heights, int minY, int maxY) { String path = "planets.arrakis.darkstone-islands."; if (!plugin.getConfig().getBoolean("planets.arrakis.highlands.enabled", true)) return; int minimumGap = Math.max(192, plugin.getConfig().getInt("planets.arrakis.highlands.min-spacing", 300)); int maximumGap = Math.max(minimumGap, plugin.getConfig().getInt("planets.arrakis.highlands.max-spacing", 500)); int spacing = (minimumGap + maximumGap) / 2; int minRadius = Math.max(6, plugin.getConfig().getInt(path + "min-radius", 45)); int maxRadius = Math.max(minRadius, plugin.getConfig().getInt(path + "max-radius", 55)); int maxRise = Math.max(1, plugin.getConfig().getInt(path + "max-height", 14)); boolean highlands = plugin.getConfig().getBoolean("planets.arrakis.highlands.enabled", true); int mountainRise = highlands ? Math.max(0, Math.min(96, plugin.getConfig().getInt("planets.arrakis.highlands.mountain-rise", 32))) : 0; int baseHeight = plugin.getConfig().getInt("planets.arrakis.terrain.base-height", 70); double variation = plugin.getConfig().getDouble("planets.arrakis.terrain.height-variation", 11); double scale = Math.max(0.001, plugin.getConfig().getDouble("planets.arrakis.terrain.noise-scale", 0.02)); int worldMinX = chunkX * 16, worldMinZ = chunkZ * 16; int reach = (int)Math.ceil(maxRadius * 2.0) + 3; int firstCellX = Math.floorDiv(worldMinX - reach, spacing), lastCellX = Math.floorDiv(worldMinX + 15 + reach, spacing); int firstCellZ = Math.floorDiv(worldMinZ - reach, spacing), lastCellZ = Math.floorDiv(worldMinZ + 15 + reach, spacing); for (int cellX = firstCellX; cellX <= lastCellX; cellX++) for (int cellZ = firstCellZ; cellZ <= lastCellZ; cellZ++) { if(!RockPlateaus.activeCell(cellX,cellZ))continue; long seed = RockPlateaus.formationSeed(cellX, cellZ); long centerX = RockPlateaus.centerX(cellX,minimumGap,maximumGap); long centerZ = RockPlateaus.centerZ(cellZ,minimumGap,maximumGap); int radius = RockPlateaus.radius(seed,minRadius,maxRadius); RockPlateaus.Shape shape = RockPlateaus.shape(seed, centerX, centerZ, radius, scale); if (formationGround.size() > 2048) formationGround.clear(); int highestGround = formationGround.computeIfAbsent(new GroundKey(shape,baseHeight,variation), key -> RockPlateaus.highestGround(key.shape(),key.baseHeight(),key.variation())); int allowedPlateaus = Math.max(1, Math.min(3, Math.min(maxRise, plugin.getConfig().getInt(path + "max-plateaus", 3)))); int plateauCount = highlands ? allowedPlateaus : RockPlateaus.count(seed, allowedPlateaus); int interval = RockPlateaus.interval(plugin.getConfig().getInt(path + "plateau-interval", 5), maxRise, plateauCount); int plateauY = highestGround + mountainRise + plateauCount * interval; for (int lx = 0; lx < 16; lx++) for (int lz = 0; lz < 16; lz++) { long gx = (long) worldMinX + lx, gz = (long) worldMinZ + lz; long rough = mix64(gx * 0x9E3779B97F4A7C15L ^ gz * 0xC2B2AE3D27D4EB4FL ^ seed); double depth = shape.depth(gx, gz); if (depth < 0) continue; int baseY = heights[lx][lz]; if (plateauY + 2 >= maxY || baseY <= minY + 1) continue; int level = RockPlateaus.level(highlands ? (depth - 0.40) / 0.60 : depth, plateauCount); int lowerLevel = highlands ? RockPlateaus.lowerTerrace(depth) : 0; boolean plateau = level > 0 || lowerLevel > 0; int terraceY = lowerLevel > 0 ? highestGround + lowerLevel * interval : highestGround + mountainRise + level * interval; double slope = Math.max(0.0, Math.min(1.0, depth / (highlands ? 0.46 : 0.10))); slope = slope * slope * (3 - 2 * slope); int sideTop = highlands ? baseY + (int)Math.floor(slope * (highestGround + mountainRise - baseY)) : highestGround + (int)Math.floor(slope * interval); Material[] darkRock = {Material.BLACKSTONE, Material.BASALT, Material.POLISHED_BLACKSTONE}; if (plateau) { for (int y = baseY + 1; y < terraceY; y++) { int hashIndex = (int)Math.floorMod(mix64(rough + y * 0x9E3779B97F4A7C15L), darkRock.length); data.setBlock(lx, y, lz, darkRock[hashIndex]); } data.setBlock(lx, terraceY, lz, Material.SAND); heights[lx][lz] = terraceY; } else { int spire = highlands ? RockPlateaus.spireRise(seed,gx,gz,depth, plugin.getConfig().getInt("planets.arrakis.highlands.spire-height",40)) : 0; int sideSurface = Math.max(baseY, Math.min(maxY - 2, sideTop + spire)); heights[lx][lz] = sideSurface; for (int y = baseY; y <= sideSurface; y++) { int hashIndex = (int)Math.floorMod(mix64(rough + y * 0x9E3779B97F4A7C15L), darkRock.length); data.setBlock(lx, y, lz, darkRock[hashIndex]); } } } } } 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,List emitted) { 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]; Material surface = data.getType(x, y, z); if (y + 1 < maxY && y > minY && SpiceDepositProvenance.hostSand(surface)) emitted.add(new SpiceDepositProvenance.Position(x,y,z)); } } private void placeRandomSpicePatch(ChunkData data, int chunkX, int chunkZ, int[][] heights,List emitted) { String path = "spice-deposits.patches."; if (!plugin.getConfig().getBoolean(path + "enabled", true)) return; int spacing = Math.max(128, plugin.getConfig().getInt(path + "region-spacing", 600)); int radius = Math.max(2, plugin.getConfig().getInt(path + "radius", 12)); int targetValue = Math.max(1, plugin.getConfig().getInt(path + "target-value", 5000)); int unitPrice = Math.max(1, plugin.getConfig().getInt(path + "unit-price", 15)); double density = Math.min(1.0, Math.ceil(targetValue / (double) unitPrice) / (Math.PI * radius * radius)); double chance = Math.max(0, Math.min(1, plugin.getConfig().getDouble(path + "chance-per-region", 0.35))); int worldMinX = chunkX * 16, worldMinZ = chunkZ * 16; int firstCellX = Math.floorDiv(worldMinX - radius, spacing), lastCellX = Math.floorDiv(worldMinX + 15 + radius, spacing); int firstCellZ = Math.floorDiv(worldMinZ - radius, spacing), lastCellZ = Math.floorDiv(worldMinZ + 15 + radius, spacing); long salt = 0x5350494345504154L; for (int cellX = firstCellX; cellX <= lastCellX; cellX++) for (int cellZ = firstCellZ; cellZ <= lastCellZ; cellZ++) { long cellSeed = mix64((long) cellX * 0x9E3779B97F4A7C15L ^ (long) cellZ * 0xC2B2AE3D27D4EB4FL ^ salt); if (hashUnit(cellSeed) >= chance) continue; long offsetX = Math.floorMod(mix64(cellSeed ^ 0x165667B19E3779F9L), spacing - radius * 2L); long offsetZ = Math.floorMod(mix64(cellSeed ^ 0x85EBCA77C2B2AE63L), spacing - radius * 2L); long centerX = (long) cellX * spacing + radius + offsetX; long centerZ = (long) cellZ * spacing + radius + offsetZ; for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { long gx = (long) worldMinX + x, gz = (long) worldMinZ + z; long dx = gx - centerX, dz = gz - centerZ; if (dx * dx + dz * dz > (long) radius * radius) continue; long blockSeed = mix64(gx * 0x9E3779B97F4A7C15L ^ gz * 0xC2B2AE3D27D4EB4FL ^ salt); if (hashUnit(blockSeed) >= density) continue; int y = heights[x][z]; if (SpiceDepositProvenance.hostSand(data.getType(x, y, z))) emitted.add(new SpiceDepositProvenance.Position(x,y,z)); } } } private static double hashUnit(long hash) { return (hash >>> 11) * 0x1.0p-53; } private void placeOres(ChunkData data, Random random, String path, int minWorldY, int maxWorldY) { if(planet.equals("arrakis")){ // Dunes stay visibly ordinary sand, including dense-spice areas. // Preserve suspicious-sand deposits and exposed rock formations. for(int x=0;x<16;x++)for(int z=0;z<16;z++)for(int y=maxWorldY;y>minWorldY;y--){ var top=data.getType(x,y,z);if(ArrakisStrata.air(top))continue; if(top==Material.RED_SAND||top==Material.ORANGE_TERRACOTTA)data.setBlock(x,y,z,Material.SAND); break; } // Native clay disk geometry: one candidate per chunk, radius 2–3, // half-height 1, inside sandstone below the four sand layers. int cx=3+random.nextInt(10),cz=3+random.nextInt(10),radius=2+random.nextInt(2),surface=-1; for(int y=maxWorldY;y>minWorldY+5;y--)if(!ArrakisStrata.air(data.getType(cx,y,cz))){surface=y;break;} if(surface>minWorldY+7&&data.getType(cx,surface,cz)==Material.SAND&&data.getType(cx,surface-3,cz)==Material.SAND&&data.getType(cx,surface-4,cz)==Material.SANDSTONE){ int center=surface-5; for(int dx=-radius;dx<=radius;dx++)for(int dz=-radius;dz<=radius;dz++)if(dx*dx+dz*dz<=radius*radius)for(int dy=-1;dy<=1;dy++){ int x=cx+dx,z=cz+dz,y=center+dy,columnSurface=surface+radius; while(columnSurface>minWorldY+5&&ArrakisStrata.air(data.getType(x,columnSurface,z)))columnSurface--; if(y>columnSurface-4||data.getType(x,columnSurface,z)!=Material.SAND||data.getType(x,columnSurface-3,z)!=Material.SAND||data.getType(x,columnSurface-4,z)!=Material.SANDSTONE)continue; var material=data.getType(x,y,z); if(material==Material.RED_SAND||material==Material.SAND||material==Material.SANDSTONE||material==Material.STONE)data.setBlock(x,y,z,Material.DRIED_KELP_BLOCK); } } } OreHeights.place(plugin.getConfig().getConfigurationSection(path + "ores"), data, random, path, planet, minWorldY, maxWorldY); } 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 PlanetBiomeProvider extends BiomeProvider { private final DuneTerrain plugin; private final String planet; private final Biome biome, highlands, denseSpice; PlanetBiomeProvider(DuneTerrain plugin, String planet) { this.plugin = plugin; this.planet = planet; String configured = plugin.getConfig().getString("planets." + planet + ".biome", "DESERT"); NamespacedKey key = NamespacedKey.fromString(configured.toLowerCase(Locale.ROOT)); Biome selected = key == null ? null : Registry.BIOME.get(key); this.biome = selected == null ? Biome.DESERT : selected; String custom = plugin.getConfig().getString("planets.arrakis.highlands.biome", "dunerealms:dune-highlands"); NamespacedKey customKey = NamespacedKey.fromString(custom); this.denseSpice = planet.equals("arrakis") && plugin.getConfig().getBoolean("dense-spice.enabled", true) ? Registry.BIOME.get(new NamespacedKey("dunerealms", "dense-spice")) : null; this.highlands = planet.equals("arrakis") && plugin.getConfig().getBoolean("planets.arrakis.highlands.enabled", true) && customKey != null ? Registry.BIOME.get(customKey) : null; } @Override public Biome getBiome(WorldInfo info, int x, int y, int z) { if(TemperateLandscape.enabled(planet))return TemperateLandscape.biome(info,x,y,z,planet); if (denseSpice != null && DenseSpice.contains(info.getSeed(),x,z,Math.max(128,plugin.getConfig().getInt("dense-spice.spacing",512)))) return denseSpice; if (highlands == null) return biome; String path = "planets.arrakis.darkstone-islands."; int minimumGap = Math.max(192, plugin.getConfig().getInt("planets.arrakis.highlands.min-spacing", 300)); int maximumGap = Math.max(minimumGap, plugin.getConfig().getInt("planets.arrakis.highlands.max-spacing", 500)); int minimum = Math.max(6, plugin.getConfig().getInt(path + "min-radius", 45)); int maximum = Math.max(minimum, plugin.getConfig().getInt(path + "max-radius", 55)); double scale = Math.max(.001, plugin.getConfig().getDouble("planets.arrakis.terrain.noise-scale", .02)); return RockPlateaus.regionDepth(x,z,minimumGap,maximumGap,minimum,maximum,scale) >= 0 ? highlands : biome; } @Override public List getBiomes(WorldInfo info) { if(TemperateLandscape.enabled(planet))return TemperateLandscape.biomes(planet); Set all = new LinkedHashSet<>(); all.add(biome); if(highlands!=null)all.add(highlands); if(denseSpice!=null)all.add(denseSpice); return List.copyOf(all); } } private static long mix64(long value) { value = (value ^ (value >>> 30)) * 0xBF58476D1CE4E5B9L; value = (value ^ (value >>> 27)) * 0x94D049BB133111EBL; return value ^ (value >>> 31); } private static final class SietchPopulator extends BlockPopulator { private final DuneTerrain plugin; private final SietchBuilder builder; private SietchPopulator(DuneTerrain plugin) { this.plugin = plugin; this.builder = new SietchBuilder((region, x, y, z, a, b) -> placePersonalChest(region, x, y, z, a, b)); } private int spacing(SietchLayout.Tier tier) { return Math.max(128, plugin.getConfig().getInt("sietches." + tier.key() + ".spacing", tier.spacing)); } @Override public void populate(WorldInfo world, Random random, int cx, int cz, LimitedRegion region) { if (!world.getName().equalsIgnoreCase("arrakis")) return; if (!plugin.getConfig().getBoolean("sietches.enabled", true)) return; for (SietchLayout.Tier tier : SietchLayout.Tier.values()) { if (!plugin.getConfig().getBoolean("sietches." + tier.key() + ".enabled", true)) continue; SietchLayout.Anchor anchor = SietchLayout.anchor(tier, spacing(tier), cx, cz); if (anchor == null || !SietchLayout.fitsWindow(tier, anchor.x(), anchor.z(), cx, cz)) continue; if (!SietchLayout.clear(tier, anchor, this::spacing)) continue; builder.build(region, tier, anchor, world.getMinHeight(), world.getMaxHeight()); return; } } private void placePersonalChest(LimitedRegion r, int x, int y, int z, long cellX, long cellZ) { set(r, x, y-1, z, Material.CHISELED_SANDSTONE); set(r, x, y, z, Material.CHEST); BlockState state = r.getBlockState(x, y, z); if (state instanceof Chest chest) { String id = Long.toUnsignedString(mix64(cellX * 0x9E3779B97F4A7C15L ^ cellZ * 0xC2B2AE3D27D4EB4FL ^ 0x534945544348L), 16); chest.setCustomName("Personal Sietch Cache"); chest.getPersistentDataContainer().set(plugin.sietchLootIdKey, PersistentDataType.STRING, id); chest.update(true, false); } } private static void set(LimitedRegion region, int x, int y, int z, Material material) { 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; var anchor=ArrakisBlooms.anchor(world.getSeed(),chunkX,chunkZ,Math.max(1,plugin.getConfig().getInt("spice-blow.rarity",ArrakisBlooms.DESERT_WELL_RARITY))); if(anchor==null)return; int x=anchor.x(),z=anchor.z(),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); if(plugin.spiceProvenance!=null)plugin.spiceProvenance.bloom(world,chunkX,chunkZ,new SpiceDepositProvenance.Position(x,y+1,z)); } } }