mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-04 04:02:11 +00:00
Compare commits
43
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fc5914359 | ||
|
|
2a8ab26a14 | ||
|
|
ee911247b3 | ||
|
|
36b352ea05 | ||
|
|
713556bc30 | ||
|
|
94a8a9b139 | ||
|
|
ef24f2e8b2 | ||
|
|
a51802c487 | ||
|
|
5040d32cb8 | ||
|
|
d8c0c2cc61 | ||
|
|
1efb4c14db | ||
|
|
8fe8942f5d | ||
|
|
fadbcb8bb5 | ||
|
|
9489ffd4ad | ||
|
|
c6a7225fa8 | ||
|
|
2ae765ca16 | ||
|
|
5c7c2b30d8 | ||
|
|
424d8d8f51 | ||
|
|
1f27af6938 | ||
|
|
aa78f4d43d | ||
|
|
d41cbeb6db | ||
|
|
4079e0a708 | ||
|
|
2cfb3d8dcc | ||
|
|
98e296b666 | ||
|
|
3532c16906 | ||
|
|
dd7d838c6b | ||
|
|
a8470c8178 | ||
|
|
8afbff4b42 | ||
|
|
05984cf64a | ||
|
|
aafbb879df | ||
|
|
86ce2856e8 | ||
|
|
564dcdcc72 | ||
|
|
3ad55564ec | ||
|
|
b1f5c58b62 | ||
|
|
6dc2dec03b | ||
|
|
f4f2c15731 | ||
|
|
c10341af2b | ||
|
|
9d0f7a6887 | ||
|
|
1693e3f397 | ||
|
|
3922c8f57f | ||
|
|
71cac65f91 | ||
|
|
f8041b22ec | ||
|
|
64d1daf588 |
No files matched your search
+30
-58
@@ -6,13 +6,14 @@ import art.arcane.iris.pack.datapack.export.WorldgenExportMode;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportProgress;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportRequest;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportResult;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.levelgen.densityfunction.DensityFunction;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -23,11 +24,12 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** Listed caves are not exported yet: the exported world has no Iris caves, and the export says so. */
|
||||
public final class WorldgenExportDeepCaves263Test {
|
||||
@ClassRule
|
||||
public static final PaperRegistryIsolation registryIsolation = new PaperRegistryIsolation();
|
||||
@@ -36,35 +38,21 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
private static final String NAMESPACE = WorldgenExportRequest.DEFAULT_NAMESPACE;
|
||||
private static final String DIMENSION_ID = NAMESPACE + ":" + ExportTestPacks.DIMENSION;
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int LAVA_Y = -62;
|
||||
private static final int LAVA_LINE = -54;
|
||||
private static final int CAVE_TOP = -14;
|
||||
private static final int DEEP_Y = -14;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final String CAVE_FIELD = "cave/field";
|
||||
private static final String DIMENSION = """
|
||||
{
|
||||
"regions": ["region"],
|
||||
"dimensionHeight": {"min": -64, "max": 192},
|
||||
"fluidHeight": 63,
|
||||
"caveLavaHeight": 2,
|
||||
"caveProfile": {
|
||||
"enabled": true,
|
||||
"verticalRange": {"min": 0, "max": 50},
|
||||
"verticalEdgeFade": 0,
|
||||
"baseDensityStyle": {"style": "SIMPLEX", "zoom": 0.6},
|
||||
"detailDensityStyle": {"style": "SIMPLEX", "zoom": 0.3},
|
||||
"baseWeight": 1.0,
|
||||
"detailWeight": 0.0,
|
||||
"densityThreshold": {"min": 5.0, "max": 5.0, "style": {"style": "SIMPLEX"}},
|
||||
"thresholdBias": 0.0,
|
||||
"surfaceClearance": 0,
|
||||
"allowSurfaceBreak": false,
|
||||
"allowFluid": false,
|
||||
"allowLava": true,
|
||||
"modules": []
|
||||
}
|
||||
"caves": ["tunnels"]
|
||||
}
|
||||
""";
|
||||
private static final String TUNNELS = """
|
||||
{"tunnel": {"width": {"min": 5, "max": 8}, "spacing": {"horizontal": 32, "vertical": 24}},
|
||||
"depth": {"min": -60, "max": 0}, "surfaceClearance": 0, "allowLava": true}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -73,53 +61,42 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void deepCavesOpenAsAirAboveTheIrisLavaBand() throws IOException {
|
||||
public void listedCavesAreReportedAsNotExportedOnce() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
JsonObject head = JsonParser.parseString(Files.readString(result.output().resolve("data/" + NAMESPACE + "/worldgen/material_rule/"
|
||||
+ ExportTestPacks.DIMENSION + ".json"), StandardCharsets.UTF_8)).getAsJsonObject().getAsJsonArray("sequence").get(0).getAsJsonObject();
|
||||
assertEquals("minecraft:ore_vein", head.get("type").getAsString());
|
||||
String opening = head.get("density").getAsString();
|
||||
assertTrue(opening, Files.isRegularFile(densityFunction(result.output(), opening)));
|
||||
long reports = result.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LISTED_CAVES).count();
|
||||
assertEquals(result.diagnostics().toString(), 1, reports);
|
||||
assertTrue(result.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LISTED_CAVES)
|
||||
.allMatch(diagnostic -> diagnostic.severity() == ExportDiagnostic.Severity.WARNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theExportedWorldHasNoCaveFieldNoDeepCaveOpeningAndNoCaveAir() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
|
||||
Path materialRule = result.output().resolve("data/" + NAMESPACE + "/worldgen/material_rule/" + ExportTestPacks.DIMENSION + ".json");
|
||||
JsonObject rules = JsonParser.parseString(Files.readString(materialRule, StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
assertFalse(rules.toString(), rules.toString().contains("cave/"));
|
||||
assertFalse(Files.exists(result.output().resolve("data/" + NAMESPACE + "/worldgen/density_function/cave/field.json")));
|
||||
try (WorldgenExportSampler sampler = WorldgenExportSampler.open(result.output(), WorldgenExportMode.OVERWORLD, DIMENSION_ID, SEED)) {
|
||||
ProtoChunk chunk = sampler.terrainChunk(0, 0);
|
||||
for (int x = 0; x < CHUNK_WIDTH; x++) {
|
||||
for (int z = 0; z < CHUNK_WIDTH; z++) {
|
||||
for (int y = MIN_Y; y <= CAVE_TOP; y++) {
|
||||
for (int y = MIN_Y + 1; y <= DEEP_Y; y++) {
|
||||
BlockState state = chunk.getBlockState(new BlockPos(x, y, z));
|
||||
String where = state + " at " + x + "," + y + "," + z;
|
||||
if (y <= LAVA_Y) {
|
||||
assertTrue(where, state.is(Blocks.LAVA));
|
||||
} else {
|
||||
assertTrue(where, state.isAir());
|
||||
}
|
||||
assertFalse(state + " at " + x + "," + y + "," + z, state.isAir() || state.is(Blocks.LAVA));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(chunk.getBlockState(new BlockPos(0, LAVA_LINE - 1, 0)).isAir());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepCaveRuleSharesTheCaveFieldCacheWithTheFinalDensity() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
|
||||
try (WorldgenExportSampler sampler = WorldgenExportSampler.open(result.output(), WorldgenExportMode.OVERWORLD, DIMENSION_ID, SEED)) {
|
||||
CompiledCaches caches = CompiledCaches.open(sampler.registries(), SEED);
|
||||
DensityFunction opening = caches.oreVeins().getFirst().density();
|
||||
int field = caches.rootId(caches.function(NAMESPACE + ":" + CAVE_FIELD));
|
||||
Set<Integer> finalDensity = caches.ids(caches.finalDensity());
|
||||
|
||||
assertTrue(caches.ids(opening).toString(), caches.ids(opening).contains(field));
|
||||
assertTrue(finalDensity.toString(), finalDensity.contains(field));
|
||||
assertTrue(finalDensity.toString(), finalDensity.contains(caches.rootId(opening)));
|
||||
}
|
||||
}
|
||||
|
||||
private WorldgenExportResult export() throws IOException {
|
||||
File pack = ExportTestPacks.withDimension(temporaryFolder.newFolder("pack"), DIMENSION);
|
||||
Files.createDirectories(pack.toPath().resolve("caves"));
|
||||
Files.writeString(pack.toPath().resolve("caves/tunnels.json"), TUNNELS, StandardCharsets.UTF_8);
|
||||
WorldgenExportRequest request = WorldgenExportRequest.builder()
|
||||
.pack(pack.toPath())
|
||||
.dimension(ExportTestPacks.DIMENSION)
|
||||
@@ -128,9 +105,4 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
.build();
|
||||
return WorldgenDatapackExporter.create().export(request, WorldgenExportProgress.NONE);
|
||||
}
|
||||
|
||||
private static Path densityFunction(Path datapack, String id) {
|
||||
int separator = id.indexOf(':');
|
||||
return datapack.resolve("data/" + id.substring(0, separator) + "/worldgen/density_function/" + id.substring(separator + 1) + ".json");
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris;
|
||||
import art.arcane.iris.api.terrain.IrisTerrainService;
|
||||
import art.arcane.iris.command.CommandSVC;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
import art.arcane.iris.configuration.SettingsHotloadWatch;
|
||||
import art.arcane.iris.diagnostics.LogFilterSVC;
|
||||
import art.arcane.iris.diagnostics.splash.IrisSplashComposer;
|
||||
@@ -976,6 +977,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
return;
|
||||
}
|
||||
BukkitGuiHost.install();
|
||||
StudioAppInstaller.installInBackground();
|
||||
// super.onEnable() already registers this instance as a listener.
|
||||
plugin.enablePlugin();
|
||||
if (IrisStartupValidation.isRestartRequired()) {
|
||||
|
||||
@@ -28,8 +28,7 @@ import art.arcane.volmlib.util.director.annotations.Director;
|
||||
import art.arcane.volmlib.util.director.annotations.Param;
|
||||
import art.arcane.iris.localization.C;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
|
||||
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
@@ -51,15 +50,10 @@ public class CommandEdit implements DirectorExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
if (!FileOpener.isDesktopAvailable()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_OPEN_FILES_HEADLESS_ENVIRONMENTS));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Desktop.isDesktopSupported()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_DESKTOP_IS_NOT_SUPPORTED_BY_THIS_ENVIRONMENT));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,7 +68,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(biome.getLoadFile());
|
||||
FileOpener.open(biome.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE, MessageArgument.untrusted("value", biome.getTypeName()), MessageArgument.untrusted("value2", biome.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
@@ -92,7 +86,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM_2));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(region.getLoadFile());
|
||||
FileOpener.open(region.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE_2, MessageArgument.untrusted("value", region.getTypeName()), MessageArgument.untrusted("value2", region.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
@@ -110,7 +104,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM_3));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(dimension.getLoadFile());
|
||||
FileOpener.open(dimension.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE_3, MessageArgument.untrusted("value", dimension.getTypeName()), MessageArgument.untrusted("value2", dimension.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
@@ -21,9 +21,11 @@ package art.arcane.iris.command;
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.studio.map.MapWindow;
|
||||
import art.arcane.iris.studio.map.PaletteExplorerStart;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.bridge.StudioBridge;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
import art.arcane.iris.studio.bridge.StudioLaunch;
|
||||
import art.arcane.iris.studio.bridge.StudioWindow;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.workspace.IrisProject;
|
||||
import art.arcane.iris.studio.workspace.IrisCodeWorkspace;
|
||||
@@ -104,6 +106,7 @@ import java.util.function.Consumer;
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
import art.arcane.iris.localization.BukkitCommandMessages;
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
import art.arcane.volmlib.util.localization.TextKey;
|
||||
import art.arcane.volmlib.util.localization.LanguageAudience;
|
||||
import art.arcane.iris.localization.BukkitCommandMessagesExtended;
|
||||
@Director(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", descriptionKey = "iris.director.commandstudio.director.studio_commands")
|
||||
@@ -267,16 +270,10 @@ public class CommandStudio implements DirectorExecutor {
|
||||
|
||||
@Director(description = "Open the noise explorer (External GUI)", descriptionKey = "iris.director.commandstudio.director.open_noise_explorer_external_gui", aliases = {"nmap"})
|
||||
public void noise(
|
||||
@Param(description = "Optional pack generator to preview", descriptionKey = "iris.director.commandstudio.param.optional_pack_generator_preview", defaultValue = "null", contextual = true, contextualOverride = true)
|
||||
IrisGenerator generator,
|
||||
@Param(description = "The seed to preview the generator with", descriptionKey = "iris.director.commandstudio.param.seed_preview_generator_with", defaultValue = "12345")
|
||||
long seed
|
||||
@Param(name = "world", description = "The Iris world whose pack the noise explorer reads", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) return;
|
||||
VolmitSender commandSender = sender();
|
||||
UUID openerId = commandSender.isPlayer() ? commandSender.player().getUniqueId() : null;
|
||||
MapWindow.NoiseSelection selection = new MapWindow.NoiseSelection(generator == null ? null : generator.getLoadKey(), generator, seed);
|
||||
withPlayerContext(opener -> openNoiseAtPlayer(commandSender, openerId, opener, selection));
|
||||
openStudioApp(world, BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_NOISE_EXPLORER);
|
||||
}
|
||||
|
||||
@Director(description = "Open the image-map studio (External GUI)", descriptionKey = "iris.director.commandstudio.director.open_image_map_studio_external_gui", aliases = {"imap"})
|
||||
@@ -284,16 +281,7 @@ public class CommandStudio implements DirectorExecutor {
|
||||
@Param(name = "world", description = "The Iris world whose active pack receives image-map exports", descriptionKey = "iris.director.commandstudio.param.world_open_image_map_studio", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) {
|
||||
return;
|
||||
}
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
}
|
||||
|
||||
requestMapStart(world, MapWindow::openImageMaps);
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_IMAGE_MAP_STUDIO));
|
||||
openStudioApp(world, BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_IMAGE_MAP_STUDIO);
|
||||
}
|
||||
|
||||
@Director(description = "Show loot if a chest were right here", descriptionKey = "iris.director.commandstudio.director.show_loot_if_chest_were_right_here", origin = DirectorOrigin.PLAYER, sync = true)
|
||||
@@ -377,7 +365,7 @@ public class CommandStudio implements DirectorExecutor {
|
||||
boolean progressShown = false;
|
||||
int c = -1;
|
||||
try {
|
||||
engine.getDimension().getRegions().forEach(key -> data.put(key, new AtomicInteger(0)));
|
||||
engine.getDimension().getRegionKeys().forEach(key -> data.put(key, new AtomicInteger(0)));
|
||||
multiBurst = new MultiBurst("Region Sampler");
|
||||
var executor = multiBurst.burst(Math.min(radius * radius, 1 << 20));
|
||||
sender.sendMessage(IrisLanguage.text(BukkitCommandMessages.COMMAND_STUDIO_GENERATING_DATA));
|
||||
@@ -425,66 +413,45 @@ public class CommandStudio implements DirectorExecutor {
|
||||
@Param(name = "world", description = "The world to open the generator for", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) return;
|
||||
openStudioApp(world, BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP);
|
||||
}
|
||||
|
||||
@Director(description = "Open the Iris Studio app on a world", descriptionKey = "iris.director.commandstudio.director.render_world_map_external_gui", aliases = "app")
|
||||
public void studioApp(
|
||||
@Param(name = "world", description = "The world to open the generator for", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
openStudioApp(world, BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP);
|
||||
}
|
||||
|
||||
/** Opens the app on the world; when it can't, tells the sender why and hands over the link to connect by hand. */
|
||||
private void openStudioApp(World world, TextKey openedMessage) {
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
}
|
||||
|
||||
requestMapStart(world, MapWindow::openMap);
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP));
|
||||
}
|
||||
|
||||
// The map opens where the player stands when they are in that world, otherwise at the world origin.
|
||||
private PaletteExplorerStart mapStartIn(World world, Player opener, UUID openerId) {
|
||||
Location center = opener != null && opener.getWorld().equals(world) ? opener.getLocation() : null;
|
||||
return new PaletteExplorerStart(
|
||||
IrisToolbelt.access(world).getEngine(),
|
||||
world.getUID(),
|
||||
openerId,
|
||||
null,
|
||||
center == null ? 0D : center.getX(),
|
||||
center == null ? 0D : center.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
private void requestMapStart(World world, Consumer<PaletteExplorerStart> launch) {
|
||||
UUID openerId = sender().isPlayer() ? player().getUniqueId() : null;
|
||||
withPlayerContext(opener -> launch.accept(mapStartIn(world, opener, openerId)));
|
||||
}
|
||||
|
||||
private void openNoiseAtPlayer(VolmitSender commandSender, UUID openerId, Player opener, MapWindow.NoiseSelection selection) {
|
||||
World world = opener == null ? null : opener.getWorld();
|
||||
PlatformChunkGenerator worldGenerator = world == null ? null : IrisToolbelt.access(world);
|
||||
Engine engine = worldGenerator == null ? GuiHost.get().findActiveEngine() : worldGenerator.getEngine();
|
||||
if (engine == null) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(world);
|
||||
StudioBridge bridge;
|
||||
try {
|
||||
bridge = StudioBridges.open(world.getName(), generator::getEngine, openerId);
|
||||
} catch (IOException error) {
|
||||
IrisLogging.warn("Could not open the studio bridge: %s", error.getMessage());
|
||||
return;
|
||||
}
|
||||
PaletteExplorerStart start = worldGenerator == null
|
||||
? new PaletteExplorerStart(engine, null, openerId, null, 0D, 0D)
|
||||
: mapStartIn(world, opener, openerId);
|
||||
MapWindow.openNoise(start, selection);
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_NOISE_EXPLORER));
|
||||
}
|
||||
|
||||
private void withPlayerContext(Consumer<Player> action) {
|
||||
Player opener = sender().isPlayer() ? player() : null;
|
||||
if (opener == null) {
|
||||
action.accept(null);
|
||||
StudioLaunch launch = StudioWindow.show(bridge);
|
||||
if (launch.opened()) {
|
||||
sender().sendMessage(IrisLanguage.text(openedMessage));
|
||||
return;
|
||||
}
|
||||
AtomicBoolean completed = new AtomicBoolean();
|
||||
Consumer<Player> complete = player -> {
|
||||
if (completed.compareAndSet(false, true)) {
|
||||
action.accept(player);
|
||||
}
|
||||
};
|
||||
Runnable retired = () -> complete.accept(null);
|
||||
if (!J.runEntity(opener, () -> complete.accept(opener.isOnline() ? opener : null), 0, retired)) {
|
||||
retired.run();
|
||||
}
|
||||
IrisLogging.info("Iris Studio link for %s: %s", world.getName(), bridge.link());
|
||||
sendStudioLink(launch, bridge.link());
|
||||
}
|
||||
|
||||
private void sendStudioLink(StudioLaunch launch, String link) {
|
||||
sender().sendMessage(C.RED + IrisLanguage.text(launch.failureMessage()));
|
||||
sender().sendCopyButton(IrisLanguage.text(RuntimeUiMessages.STUDIO_LINK_COPY_BUTTON),
|
||||
IrisLanguage.text(RuntimeUiMessages.STUDIO_LINK_COPY_HOVER), link);
|
||||
}
|
||||
|
||||
@Director(description = "Profiles the performance of a dimension", descriptionKey = "iris.director.commandstudio.director.profiles_performance_dimension", origin = DirectorOrigin.PLAYER)
|
||||
@@ -953,21 +920,6 @@ public class CommandStudio implements DirectorExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if server GUIs are not enabled
|
||||
*/
|
||||
private boolean noGUI() {
|
||||
if (!IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_MUST_HAVE_SERVER_LAUNCHED_GUIS_ENABLED_SETTINGS));
|
||||
return true;
|
||||
}
|
||||
if (!GuiHost.isAvailable()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_DESKTOP_UNAVAILABLE));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if no studio is open or the player is not in one
|
||||
*/
|
||||
|
||||
+1
-2
@@ -10,6 +10,5 @@
|
||||
"dimensionHeight": {"min": 0, "max": 128},
|
||||
"logicalHeight": 128,
|
||||
"fluidHeight": 0,
|
||||
"bedrock": false,
|
||||
"caveProfile": {"enabled": false}
|
||||
"bedrock": false
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package art.arcane.iris.command;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CommandStudioDesktopTest {
|
||||
private IrisSettings previousSettings;
|
||||
private boolean previousSuppressed;
|
||||
private RecordingSender sender;
|
||||
private CommandStudio command;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
previousSuppressed = GuiHost.isDesktopSuppressed();
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
IrisSettings.settings.getGui().setUseServerLaunchedGuis(true);
|
||||
GuiHost.suppressDesktop(true);
|
||||
sender = new RecordingSender();
|
||||
command = new TestCommand(sender);
|
||||
}
|
||||
|
||||
@After
|
||||
public void restore() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
GuiHost.suppressDesktop(previousSuppressed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapReportsMissingDisplayBeforeAccessingWorld() {
|
||||
command.map(null);
|
||||
|
||||
assertDisplayMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imageMapReportsMissingDisplayInsteadOfDisabledSetting() {
|
||||
command.imagemap(null);
|
||||
|
||||
assertDisplayMessage();
|
||||
}
|
||||
|
||||
private void assertDisplayMessage() {
|
||||
assertEquals(1, sender.messages.size());
|
||||
assertTrue(sender.messages.getFirst(), sender.messages.getFirst().contains("display"));
|
||||
}
|
||||
|
||||
private static final class TestCommand extends CommandStudio {
|
||||
private final VolmitSender sender;
|
||||
|
||||
private TestCommand(VolmitSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolmitSender sender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingSender extends VolmitSender {
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
private RecordingSender() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
messages.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
package art.arcane.iris.command;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
|
||||
import art.arcane.iris.platform.generation.PlatformChunkGenerator;
|
||||
import art.arcane.iris.studio.map.MapWindow;
|
||||
import art.arcane.iris.studio.map.PaletteExplorerStart;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.world.task.J;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class StudioMapPositionTest {
|
||||
@Test
|
||||
public void mapCapturesItsStartingPositionOnThePlayerScheduler() {
|
||||
IrisSettings previous = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
IrisSettings.settings.getGui().setUseServerLaunchedGuis(true);
|
||||
World world = mock(World.class);
|
||||
Player player = mock(Player.class);
|
||||
VolmitSender sender = mock(VolmitSender.class);
|
||||
PlatformChunkGenerator generator = mock(PlatformChunkGenerator.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
UUID playerId = UUID.randomUUID();
|
||||
UUID worldId = UUID.randomUUID();
|
||||
AtomicBoolean owned = new AtomicBoolean();
|
||||
AtomicReference<Runnable> task = new AtomicReference<>();
|
||||
AtomicReference<PaletteExplorerStart> start = new AtomicReference<>();
|
||||
when(world.getUID()).thenReturn(worldId);
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(player.isOnline()).thenReturn(true);
|
||||
when(player.getWorld()).thenAnswer(invocation -> {
|
||||
assertTrue("world read must use the player scheduler", owned.get());
|
||||
return world;
|
||||
});
|
||||
when(player.getLocation()).thenAnswer(invocation -> {
|
||||
assertTrue("location read must use the player scheduler", owned.get());
|
||||
return new Location(world, 33.25D, 91D, -72.5D);
|
||||
});
|
||||
when(sender.isPlayer()).thenReturn(true);
|
||||
when(sender.player()).thenReturn(player);
|
||||
when(generator.getEngine()).thenReturn(engine);
|
||||
CommandStudio command = new CommandStudio() {
|
||||
@Override
|
||||
public VolmitSender sender() {
|
||||
return sender;
|
||||
}
|
||||
};
|
||||
try (MockedStatic<GuiHost> host = mockStatic(GuiHost.class);
|
||||
MockedStatic<IrisToolbelt> toolbelt = mockStatic(IrisToolbelt.class);
|
||||
MockedStatic<J> scheduling = mockStatic(J.class);
|
||||
MockedStatic<MapWindow> windows = mockStatic(MapWindow.class)) {
|
||||
host.when(GuiHost::isAvailable).thenReturn(true);
|
||||
toolbelt.when(() -> IrisToolbelt.isIrisWorld(world)).thenReturn(true);
|
||||
toolbelt.when(() -> IrisToolbelt.access(world)).thenReturn(generator);
|
||||
scheduling.when(() -> J.runEntity(same(player), any(Runnable.class), eq(0), any(Runnable.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
task.set(invocation.getArgument(1));
|
||||
return true;
|
||||
});
|
||||
windows.when(() -> MapWindow.openMap(any(PaletteExplorerStart.class))).thenAnswer(invocation -> {
|
||||
start.set(invocation.getArgument(0));
|
||||
return null;
|
||||
});
|
||||
|
||||
command.map(world);
|
||||
assertNull(start.get());
|
||||
owned.set(true);
|
||||
task.get().run();
|
||||
|
||||
assertEquals(engine, start.get().engine());
|
||||
assertEquals(playerId, start.get().playerId());
|
||||
assertEquals(worldId, start.get().worldId());
|
||||
assertEquals(33.25D, start.get().centerX(), 0D);
|
||||
assertEquals(-72.5D, start.get().centerZ(), 0D);
|
||||
} finally {
|
||||
IrisSettings.settings = previous;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeEntityBehavior;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeStateMerger;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedServerAccess;
|
||||
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
import art.arcane.iris.generation.decoration.DecoratorPlatformHooks;
|
||||
@@ -492,6 +493,7 @@ public final class ModdedEngineBootstrap {
|
||||
GuiHost.Provider previousGuiHost = GuiHost.get();
|
||||
ModdedGuiHost.install();
|
||||
rollback.add(() -> GuiHost.set(previousGuiHost));
|
||||
StudioAppInstaller.installInBackground();
|
||||
|
||||
ModdedDecoratorHooks decoratorHooks = new ModdedDecoratorHooks();
|
||||
DecoratorPlatformHooks.Bindings previousDecoratorBindings = DecoratorPlatformHooks.bind(decoratorHooks, decoratorHooks);
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeCommandSource;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPoint;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeEditPlayer;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
import java.io.File;
|
||||
|
||||
final class ModdedEditCommands {
|
||||
@@ -110,7 +110,7 @@ final class ModdedEditCommands {
|
||||
}
|
||||
|
||||
private static int openJson(NativeCommandSource source, IrisRegistrant registrant) {
|
||||
if (!GuiHost.isAvailable() || !Desktop.isDesktopSupported()) {
|
||||
if (!GuiHost.isAvailable() || !FileOpener.isDesktopAvailable()) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_CANNOT_OPEN_FILES_HERE, MessageArgument.untrusted("value", ModdedGuiHost.guiUnavailableReason())));
|
||||
return 0;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ final class ModdedEditCommands {
|
||||
}
|
||||
File file = registrant.getLoadFile();
|
||||
try {
|
||||
Desktop.getDesktop().open(file);
|
||||
FileOpener.open(file);
|
||||
} catch (Throwable e) {
|
||||
ModdedIrisLog.error("Iris edit failed to open {}", file, e);
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_COULD_NOT_OPEN, MessageArgument.untrusted("value", file.getName()), MessageArgument.untrusted("value2", e.getClass().getSimpleName())));
|
||||
|
||||
+64
-66
@@ -23,8 +23,11 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldView;
|
||||
|
||||
import art.arcane.iris.modded.ModdedIrisLog;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.studio.map.MapWindow;
|
||||
import art.arcane.iris.studio.map.PaletteExplorerStart;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.bridge.StudioBridge;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
import art.arcane.iris.studio.bridge.StudioLaunch;
|
||||
import art.arcane.iris.studio.bridge.StudioWindow;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.StructurePackageClosure;
|
||||
@@ -74,7 +77,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeProtocolPlayer;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -93,6 +96,9 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
import art.arcane.iris.localization.RuntimeUiMessages;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeCommandText;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeCommandText.Format;
|
||||
import art.arcane.iris.modded.localization.ModdedCommandMessages;
|
||||
import art.arcane.volmlib.util.localization.LanguageAudience;
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
@@ -226,11 +232,7 @@ public final class ModdedStudioCommands {
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> noiseTree(String name) {
|
||||
return NativeCommandRegistration.literal(name)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), null, 12345L)))
|
||||
.then(NativeCommandRegistration.argument("generator", StringArgumentType.word()).suggests(GENERATOR_KEYS)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), StringArgumentType.getString(context, "generator"), 12345L)))
|
||||
.then(NativeCommandRegistration.argument("seed", LongArgumentType.longArg())
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), StringArgumentType.getString(context, "generator"), LongArgumentType.getLong(context, "seed"))))));
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource())));
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> mapTree(String name) {
|
||||
@@ -243,88 +245,77 @@ public final class ModdedStudioCommands {
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> imageMap(context.getSource())));
|
||||
}
|
||||
|
||||
private static int noise(NativeCommandSource source, String generatorKey, long seed) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
if (engine != null) {
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
}
|
||||
Engine mapEngine = engine != null ? engine : GuiHost.get().findActiveEngine();
|
||||
if ((generatorKey == null || generatorKey.isBlank()) && mapEngine != null) {
|
||||
MapWindow.openNoise(mapStart(mapEngine, source.player()), new MapWindow.NoiseSelection(null, null, seed));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_ON_SERVER_DISPLAY));
|
||||
return 1;
|
||||
}
|
||||
private static int noise(NativeCommandSource source) {
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_THIS_DIMENSION_IS_NOT_GENERATED_BY_IRIS_RUN_IRIS_STUDIO));
|
||||
return 0;
|
||||
}
|
||||
IrisGenerator generator = engine.getData().getGeneratorLoader().load(generatorKey.trim());
|
||||
if (generator == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_UNKNOWN_GENERATOR_PACK, MessageArgument.untrusted("generatorKey", generatorKey), MessageArgument.untrusted("value", engine.getDimension().getLoadKey())));
|
||||
return 0;
|
||||
}
|
||||
String selectedGeneratorKey = generatorKey.trim();
|
||||
MapWindow.openNoise(mapStart(engine, source.player()), new MapWindow.NoiseSelection(selectedGeneratorKey, generator, seed));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_GENERATOR_SEED, MessageArgument.untrusted("value", generatorKey.trim()), MessageArgument.untrusted("seed", seed)));
|
||||
return 1;
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_ON_SERVER_DISPLAY));
|
||||
}
|
||||
|
||||
private static int map(NativeCommandSource source) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_THIS_DIMENSION_IS_NOT_GENERATED_BY_IRIS_STAND_IRIS_STUDIO));
|
||||
return 0;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
MapWindow.openMap(mapStart(engine, player));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_VISION_MAP_ON_SERVER_DISPLAY, MessageArgument.untrusted("value", level.name())));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Modded worlds have no Bukkit world id; the map finds the engine again through the bound GUI context.
|
||||
private static PaletteExplorerStart mapStart(Engine engine, NativeProtocolPlayer player) {
|
||||
IrisWorld world = engine.getWorld();
|
||||
NativeWorld level = world == null ? null : world.platformWorld();
|
||||
boolean inWorld = player != null && player.connected() && level != null && player.inWorld(level);
|
||||
return new PaletteExplorerStart(engine, null, player == null ? null : player.id(), null,
|
||||
inWorld ? player.x() : 0D, inWorld ? player.z() : 0D);
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_VISION_MAP_ON_SERVER_DISPLAY, MessageArgument.untrusted("value", source.world().name())));
|
||||
}
|
||||
|
||||
private static int imageMap(NativeCommandSource source) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_IMAGE_MAP_REQUIRES_IRIS_DIMENSION
|
||||
));
|
||||
return 0;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_IMAGE_MAP_STUDIO_ON_SERVER_DISPLAY,
|
||||
MessageArgument.untrusted("value", source.world().name())
|
||||
));
|
||||
}
|
||||
|
||||
/** Opens the studio app on the source's world; when it can't, tells the source why and hands over the link to connect by hand. */
|
||||
private static int openStudioApp(NativeCommandSource source, Engine engine, String openedMessage) {
|
||||
if (GuiHost.isDesktopSuppressed()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
NativeWorld level = source.world();
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
MapWindow.openImageMaps(mapStart(engine, player));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_IMAGE_MAP_STUDIO_ON_SERVER_DISPLAY,
|
||||
MessageArgument.untrusted("value", level.name())
|
||||
));
|
||||
UUID openerId = player == null ? null : player.id();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, openerId);
|
||||
StudioBridge bridge;
|
||||
try {
|
||||
bridge = StudioBridges.open(level.name(), () -> engine, openerId);
|
||||
} catch (IOException error) {
|
||||
IrisModdedCommands.fail(source, "Could not open the studio bridge: " + error.getMessage());
|
||||
return 0;
|
||||
}
|
||||
StudioLaunch launch = StudioWindow.show(bridge);
|
||||
if (!launch.opened()) {
|
||||
IrisLogging.info("Iris Studio link for %s: %s", level.name(), bridge.link());
|
||||
sendStudioLink(source, launch, bridge.link());
|
||||
return 0;
|
||||
}
|
||||
IrisModdedCommands.ok(source, openedMessage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static void sendStudioLink(NativeCommandSource source, StudioLaunch launch, String link) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(launch.failureMessage()));
|
||||
if (source.player() == null) {
|
||||
return;
|
||||
}
|
||||
NativeCommandText hover = NativeCommandText.literal(IrisLanguage.plain(RuntimeUiMessages.STUDIO_LINK_COPY_HOVER));
|
||||
NativeCommandText button = NativeCommandText.literal(IrisLanguage.plain(RuntimeUiMessages.STUDIO_LINK_COPY_BUTTON))
|
||||
.withStyle(Format.GREEN)
|
||||
.withStyle(style -> style.copyToClipboard(link).hover(hover));
|
||||
IrisModdedCommands.ok(source, button);
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> workspaceTree(String name, boolean open) {
|
||||
return NativeCommandRegistration.literal(name)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> workspace(context.getSource(), null, open)))
|
||||
@@ -349,12 +340,12 @@ public final class ModdedStudioCommands {
|
||||
if (!open) {
|
||||
return 1;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !Desktop.isDesktopSupported()) {
|
||||
if (!GuiHost.isAvailable() || !FileOpener.isDesktopAvailable()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
Desktop.getDesktop().open(workspace);
|
||||
FileOpener.open(workspace);
|
||||
} catch (Throwable e) {
|
||||
ModdedIrisLog.error("Iris workspace open failed for {}", workspace, e);
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_COULD_NOT_OPEN, MessageArgument.untrusted("value", workspace.getName()), MessageArgument.untrusted("value2", e.getClass().getSimpleName())));
|
||||
@@ -964,6 +955,7 @@ public final class ModdedStudioCommands {
|
||||
LinkedHashSet<String> entityKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> spawnerKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> generatorKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> caveKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> lootKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> objectKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> markerKeys = new LinkedHashSet<>();
|
||||
@@ -987,6 +979,7 @@ public final class ModdedStudioCommands {
|
||||
biomeKeys.add(biome.getLoadKey());
|
||||
}
|
||||
});
|
||||
caveKeys.addAll(exportedDimension.getCaves());
|
||||
lootKeys.addAll(exportedDimension.getLoot().getTables());
|
||||
spawnerKeys.addAll(exportedDimension.getEntitySpawners());
|
||||
collectStructureKeys(structureKeys, exportedDimension.getStructures());
|
||||
@@ -998,6 +991,7 @@ public final class ModdedStudioCommands {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
caveKeys.addAll(region.getCaves());
|
||||
lootKeys.addAll(region.getLoot().getTables());
|
||||
spawnerKeys.addAll(region.getEntitySpawners());
|
||||
collectStructureKeys(structureKeys, region.getStructures());
|
||||
@@ -1010,6 +1004,7 @@ public final class ModdedStudioCommands {
|
||||
continue;
|
||||
}
|
||||
biome.getGenerators().forEach((IrisBiomeGeneratorLink link) -> generatorKeys.add(link.getGenerator()));
|
||||
caveKeys.addAll(biome.getCaves());
|
||||
lootKeys.addAll(biome.getLoot().getTables());
|
||||
spawnerKeys.addAll(biome.getEntitySpawners());
|
||||
collectStructureKeys(structureKeys, biome.getStructures());
|
||||
@@ -1066,6 +1061,9 @@ public final class ModdedStudioCommands {
|
||||
for (String key : Stream.of(dm.getExpressionLoader().getPossibleKeys()).sorted().toList()) {
|
||||
hashes.append(copyJson(folder, "expressions", key, dm.getExpressionLoader().findFile(key)));
|
||||
}
|
||||
for (String key : caveKeys) {
|
||||
hashes.append(copyJson(folder, "caves", key, dm.getCaveLoader().findFile(key)));
|
||||
}
|
||||
hashes.append(PackExportClosure.copySnippets(packFolder, folder));
|
||||
for (String key : regionKeys) {
|
||||
hashes.append(copyJson(folder, "regions", key, dm.getRegionLoader().findFile(key)));
|
||||
@@ -1149,7 +1147,7 @@ public final class ModdedStudioCommands {
|
||||
int diameter = radius * 2;
|
||||
int totalTasks = diameter * diameter;
|
||||
KMap<String, AtomicInteger> counts = new KMap<>();
|
||||
engine.getDimension().getRegions().forEach((String key) -> counts.put(key, new AtomicInteger(0)));
|
||||
engine.getDimension().getRegionKeys().forEach((String key) -> counts.put(key, new AtomicInteger(0)));
|
||||
// finally-scoped: a throw mid-scan previously leaked the sampler's whole
|
||||
// ForkJoinPool (close() is the only thing that shuts it down).
|
||||
MultiBurst burst = new MultiBurst("Region Sampler");
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.DimensionStackLayout;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -174,9 +175,9 @@ public class ModdedBiomePolicyTest {
|
||||
isles.setLoadKey("isles");
|
||||
IrisBiome meadow = new IrisBiome().setDerivative("minecraft:plains");
|
||||
meadow.setLoadKey("meadow");
|
||||
IrisRegion main = new IrisRegion().setLandBiomes(new KList<>("meadow"));
|
||||
IrisRegion main = new IrisRegion().setLandBiomes(IrisBiomeEntry.plainList("meadow"));
|
||||
main.setLoadKey("main");
|
||||
IrisRegion archipelago = new IrisRegion().setLandBiomes(new KList<>("isles"));
|
||||
IrisRegion archipelago = new IrisRegion().setLandBiomes(IrisBiomeEntry.plainList("isles"));
|
||||
archipelago.setLoadKey("archipelago");
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getReachableBiomes(any())).thenReturn(new KList<>(meadow, isles));
|
||||
|
||||
@@ -190,6 +190,63 @@ def generateNoiseNatives = tasks.register('generateNoiseNatives') {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The studio app ships inside the Bukkit jar. The Electron build it runs on is 100+ MB per platform, so it stays out
|
||||
// and is pinned instead: StudioAppInstaller downloads the host's archive from Electron's release at startup and
|
||||
// checks it against these checksums.
|
||||
File studioAppDirectory = file('studio')
|
||||
List<String> electronPlatforms = ['linux-x64', 'linux-arm64', 'win32-x64', 'win32-arm64', 'darwin-x64', 'darwin-arm64']
|
||||
Provider<String> electronVersion = providers.fileContents(layout.projectDirectory.file('studio/package-lock.json')).asText.map { String lock ->
|
||||
(String) ((Map) ((Map) new groovy.json.JsonSlurper().parseText(lock)).packages).get('node_modules/electron').version
|
||||
}
|
||||
List<String> npmCommand = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('win') ? ['cmd', '/c', 'npm'] : ['npm']
|
||||
def installStudioDependencies = tasks.register('installStudioDependencies', Exec) {
|
||||
inputs.files('studio/package.json', 'studio/package-lock.json')
|
||||
outputs.file('studio/node_modules/.package-lock.json')
|
||||
workingDir(studioAppDirectory)
|
||||
commandLine(npmCommand + ['ci', '--no-audit', '--no-fund'])
|
||||
}
|
||||
def buildStudioApp = tasks.register('buildStudioApp', Exec) {
|
||||
dependsOn(installStudioDependencies)
|
||||
inputs.dir('studio/src')
|
||||
inputs.files('studio/package.json', 'studio/package-lock.json', 'studio/electron.vite.config.ts', 'studio/tsconfig.json', 'studio/components.json')
|
||||
outputs.dir('studio/out')
|
||||
workingDir(studioAppDirectory)
|
||||
commandLine(npmCommand + ['run', 'build'])
|
||||
}
|
||||
def bundleStudioApp = tasks.register('bundleStudioApp', Zip) {
|
||||
from(buildStudioApp) {
|
||||
into('out')
|
||||
}
|
||||
from('studio/package.json')
|
||||
archiveFileName.set('studio-app.zip')
|
||||
destinationDirectory.set(layout.buildDirectory.dir('generated/studio-app'))
|
||||
preserveFileTimestamps = false
|
||||
reproducibleFileOrder = true
|
||||
}
|
||||
def pinElectronRuntime = tasks.register('pinElectronRuntime') {
|
||||
inputs.property('electronVersion', electronVersion)
|
||||
inputs.property('platforms', electronPlatforms)
|
||||
def pins = layout.buildDirectory.file('generated/studio-app-pins/studio-app.properties')
|
||||
outputs.file(pins)
|
||||
doLast {
|
||||
String version = electronVersion.get()
|
||||
String checksums = URI.create("https://github.com/electron/electron/releases/download/v${version}/SHASUMS256.txt")
|
||||
.toURL().getText('UTF-8')
|
||||
Map<String, String> checksumByArchive = checksums.readLines().collectEntries { String line ->
|
||||
def match = line.trim() =~ /^([0-9a-f]{64}) \*?(\S+)$/
|
||||
match.matches() ? [(match.group(2)): match.group(1)] : [:]
|
||||
}
|
||||
List<String> lines = ["electron.version=${version}".toString()]
|
||||
electronPlatforms.each { String platform ->
|
||||
String checksum = checksumByArchive.get("electron-v${version}-${platform}.zip".toString())
|
||||
if (checksum == null) {
|
||||
throw new GradleException("Electron ${version} publishes no ${platform} archive")
|
||||
}
|
||||
lines.add("${platform}.sha256=${checksum}".toString())
|
||||
}
|
||||
pins.get().asFile.setText(lines.join('\n') + '\n', 'UTF-8')
|
||||
}
|
||||
}
|
||||
def jarJar = configurations.create('jarJar')
|
||||
dependencies {
|
||||
add('included', project(path: ':core', configuration: 'shadow'))
|
||||
@@ -208,6 +265,12 @@ tasks.named('jar', Jar).configure {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
includeEmptyDirs = false
|
||||
from(jarJar)
|
||||
from(bundleStudioApp) {
|
||||
into('META-INF/iris')
|
||||
}
|
||||
from(pinElectronRuntime) {
|
||||
into('META-INF/iris')
|
||||
}
|
||||
from(provider { included.resolve().collect { zipTree(it) } }) {
|
||||
exclude('META-INF/INDEX.LIST')
|
||||
exclude('languages/**')
|
||||
@@ -529,6 +592,8 @@ List<String> requiredBukkitArtifactEntries = [
|
||||
'slimjar-resolutions.dat',
|
||||
'META-INF/iris/native-runtime.properties',
|
||||
NoiseNativeArtifacts.MANIFEST,
|
||||
'META-INF/iris/studio-app.zip',
|
||||
'META-INF/iris/studio-app.properties',
|
||||
'META-INF/volmit/volmlib.properties',
|
||||
'iris-language-source.properties',
|
||||
'agent.jar',
|
||||
|
||||
@@ -404,6 +404,9 @@ public class IrisSettings {
|
||||
public boolean disableTimeAndWeather = true;
|
||||
public boolean entitySpawning = true;
|
||||
public boolean autoStartDefaultStudio = false;
|
||||
public boolean downloadApp = true;
|
||||
public String studioApp = "";
|
||||
public String electron = "electron";
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfileSampler;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
@@ -419,13 +418,11 @@ public final class FloatingIslandSample {
|
||||
CNG wallWarp = entry.getWallWarpCng(baseSeed, data);
|
||||
double warpAmp = Math.max(0, entry.getWallWarpAmplitude());
|
||||
double effectiveWarpAmp = effectiveWallWarpAmplitude(warpAmp, edgeFade);
|
||||
IrisCaveProfileSampler carvingProfileSampler = entry.getCarvingProfileSampler(engine, data);
|
||||
CNG carve = carvingProfileSampler == null && !entry.hasCarvingReference() ? entry.getCarveCng(baseSeed, data) : null;
|
||||
CNG carve = entry.getCarveCng(baseSeed, data);
|
||||
double carveThreshold = entry.getCarveThreshold();
|
||||
boolean useWarp = wallWarp != null && effectiveWarpAmp > 0;
|
||||
boolean useProfileCarve = carvingProfileSampler != null;
|
||||
boolean useCarve = directCarveEnabled(entry, carvingProfileSampler, carve, carveThreshold);
|
||||
boolean[] lateralCarveMask = useProfileCarve || useCarve ? new boolean[thickness] : null;
|
||||
boolean useCarve = directCarveEnabled(carve, carveThreshold);
|
||||
boolean[] lateralCarveMask = useCarve ? new boolean[thickness] : null;
|
||||
boolean baseCarveInterior = lateralCarveMask != null && canCarveLaterally(edgeFade, footprintSupport);
|
||||
|
||||
if (useWarp) {
|
||||
@@ -452,9 +449,7 @@ public final class FloatingIslandSample {
|
||||
}
|
||||
|
||||
int solidCount = solidifyUncarvedInterior(solidMask);
|
||||
if (useProfileCarve) {
|
||||
solidCount = carveSolidInterior(solidMask, lateralCarveMask, botY, wx, wz, carvingProfileSampler, carveThreshold);
|
||||
} else if (useCarve) {
|
||||
if (useCarve) {
|
||||
solidCount = carveSolidInterior(solidMask, lateralCarveMask, botY, wx, wz, carve, carveThreshold);
|
||||
}
|
||||
int highestSolidIdx = highestSolidIndex(solidMask);
|
||||
@@ -488,8 +483,8 @@ public final class FloatingIslandSample {
|
||||
return amplitude * fade;
|
||||
}
|
||||
|
||||
static boolean directCarveEnabled(IrisFloatingChildBiomes entry, IrisCaveProfileSampler carvingProfileSampler, CNG carve, double carveThreshold) {
|
||||
return carvingProfileSampler == null && (entry == null || !entry.hasCarvingReference()) && carve != null && carveThreshold < 1.0;
|
||||
static boolean directCarveEnabled(CNG carve, double carveThreshold) {
|
||||
return carve != null && carveThreshold < 1.0;
|
||||
}
|
||||
|
||||
static boolean canCarveLaterally(double edgeFade, NeighborSupport support) {
|
||||
@@ -504,10 +499,6 @@ public final class FloatingIslandSample {
|
||||
});
|
||||
}
|
||||
|
||||
static int carveSolidInterior(boolean[] solidMask, boolean[] lateralCarveMask, int botY, int wx, int wz, IrisCaveProfileSampler carve, double carveThreshold) {
|
||||
return carveSolidInterior(solidMask, lateralCarveMask, botY, wx, wz, (x, y, z) -> carve.shouldCarve(x, y, z, carveThreshold));
|
||||
}
|
||||
|
||||
private static int carveSolidInterior(boolean[] solidMask, boolean[] lateralCarveMask, int botY, int wx, int wz, CarveSampler carve) {
|
||||
int firstSolid = -1;
|
||||
int lastSolid = -1;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
@@ -33,6 +33,8 @@ import art.arcane.iris.generation.terrain.InferredType;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisTerrain3D;
|
||||
import art.arcane.iris.pack.validation.CompatPools;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.pack.value.WeightedReference;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.world.entity.IrisEffect;
|
||||
@@ -120,6 +122,7 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
||||
private final transient AtomicCache<Integer> maxWithObjectHeight = new AtomicCache<>();
|
||||
private final transient AtomicCache<IrisBiome> realCarveBiome = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<Weighted<IrisBiome>>> weightedChildren = new AtomicCache<>();
|
||||
private final transient IrisBiomeLayerHeightCache layerHeightGenerators = new IrisBiomeLayerHeightCache();
|
||||
private final transient IrisBiomeLayerHeightCache layerCeilingHeightGenerators = new IrisBiomeLayerHeightCache();
|
||||
private final transient IrisBiomeLayerHeightCache layerSeaHeightGenerators = new IrisBiomeLayerHeightCache();
|
||||
@@ -160,8 +163,10 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
||||
private boolean lockLayers = false;
|
||||
@Description("The max layers to iterate below the surface for locked layer biomes (mesa).")
|
||||
private int lockLayersMax = 7;
|
||||
@Description("Profile-driven 3D cave configuration")
|
||||
private IrisCaveProfile caveProfile = new IrisCaveProfile();
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
@RegistryListResource(IrisCave.class)
|
||||
@Description("Caves that carve under this biome, by their file in the pack's caves folder. As a cave biome, they carve where the cave biome is. They add to the dimension's and the region's lists.")
|
||||
private KList<String> caves = new KList<>();
|
||||
@Description("Water settings for this biome: rainfall, pond density, where streams and ponds may form, and the fluid that fills them. A value left unset comes from the region, then from the dimension.")
|
||||
private IrisHydrologyPolicy hydrologyPolicy = null;
|
||||
@MinNumber(1)
|
||||
@@ -192,10 +197,9 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
||||
@DependsOn({"children"})
|
||||
@Description("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?")
|
||||
private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Description("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 4 biomes down the tree.")
|
||||
private KList<String> children = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Description("List any biome names (file names without.json) here as children, or objects with a biome and a weight. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 4 biomes down the tree. When any child is written as an object, the list is weighted: the parent itself only stays in the mix if it is listed too.")
|
||||
private KList<IrisBiomeEntry> children = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Description("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.")
|
||||
private String carvingBiome = "";
|
||||
@@ -632,22 +636,39 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
|
||||
return IrisBiomeDerivatives.getCustomBiome(this, rng, engine, x, y, z);
|
||||
}
|
||||
|
||||
public KList<String> getChildKeys() {
|
||||
return WeightedReference.keys(children);
|
||||
}
|
||||
|
||||
public boolean hasWeightedChildren() {
|
||||
return WeightedReference.anyWrittenAsObject(children);
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealChildren(DataProvider g) {
|
||||
return realChildren.aquire(() ->
|
||||
{
|
||||
IrisData data = g == null ? null : g.getData();
|
||||
return CompatPools.load(data == null ? null : data.getBiomeLoader(), getChildren(), data,
|
||||
return CompatPools.load(data == null ? null : data.getBiomeLoader(), getChildKeys(), data,
|
||||
"biome", getLoadKey(), "children", null);
|
||||
});
|
||||
}
|
||||
|
||||
public KList<Weighted<IrisBiome>> getWeightedChildren(DataProvider g) {
|
||||
return weightedChildren.aquire(() ->
|
||||
{
|
||||
IrisData data = g == null ? null : g.getData();
|
||||
return CompatPools.loadWeighted(data == null ? null : data.getBiomeLoader(), children, data,
|
||||
"biome", getLoadKey(), "children", null);
|
||||
});
|
||||
}
|
||||
|
||||
public KList<String> getAllChildren(DataProvider g, int limit) {
|
||||
KSet<String> m = new KSet<>();
|
||||
m.addAll(getChildren());
|
||||
m.addAll(getChildKeys());
|
||||
limit--;
|
||||
|
||||
if (limit > 0) {
|
||||
for (String i : getChildren()) {
|
||||
for (String i : getChildKeys()) {
|
||||
IrisBiome b = g.getData().getBiomeLoader().load(i);
|
||||
m.addAll(b.getAllChildren(g, limit));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListResource;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.pack.value.WeightedReference;
|
||||
import art.arcane.iris.pack.value.WeightedReferenceAdapter;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Description("A biome in a list a noise picks from")
|
||||
@Data
|
||||
@JsonAdapter(IrisBiomeEntry.Adapter.class)
|
||||
public class IrisBiomeEntry implements WeightedReference {
|
||||
@Required
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Description("The biome (file name without .json)")
|
||||
private String biome;
|
||||
@MinNumber(Weighted.MIN_WEIGHT)
|
||||
@MaxNumber(Weighted.MAX_WEIGHT)
|
||||
@Description("A weight of two is just as if this entry were listed twice in a row, making the biome more common. The noise picks along the list in the order it is written.")
|
||||
private int weight = 1;
|
||||
private transient boolean writtenAsObject;
|
||||
|
||||
public IrisBiomeEntry(String biome, int weight, boolean writtenAsObject) {
|
||||
this.biome = biome;
|
||||
this.weight = weight;
|
||||
this.writtenAsObject = writtenAsObject;
|
||||
}
|
||||
|
||||
public static IrisBiomeEntry plain(String biome) {
|
||||
return new IrisBiomeEntry(biome, Weighted.MIN_WEIGHT, false);
|
||||
}
|
||||
|
||||
public static KList<IrisBiomeEntry> plainList(String... biomes) {
|
||||
KList<IrisBiomeEntry> entries = new KList<>();
|
||||
for (String biome : biomes) {
|
||||
entries.add(plain(biome));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReferenceKey() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
public static final class Adapter extends WeightedReferenceAdapter<IrisBiomeEntry> {
|
||||
public Adapter() {
|
||||
super("biome");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IrisBiomeEntry create(String key, int weight, boolean writtenAsObject) {
|
||||
return new IrisBiomeEntry(key, weight, writtenAsObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,8 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfileSampler;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.pack.validation.CompatPools;
|
||||
import art.arcane.iris.pack.value.OverrideMode;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
@@ -68,12 +64,6 @@ public class IrisFloatingChildBiomes implements Rarity {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient volatile CachedEdgeProfile recentEdgeProfile;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private final transient LazyBoundedCache<RuntimeKey, IrisCaveProfileSampler> carvingProfileSamplers = new LazyBoundedCache<>(8);
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient volatile CachedCarvingProfile recentCarvingProfile;
|
||||
private final transient AtomicCache<IrisObjectScale> shrinkScaleCache = new AtomicCache<>();
|
||||
|
||||
public CNG getFootprintCng(long baseSeed, IrisData data) {
|
||||
@@ -133,52 +123,6 @@ public class IrisFloatingChildBiomes implements Rarity {
|
||||
return style.create(baseSeed ^ 0xCA5EC1EE5EL, data);
|
||||
}
|
||||
|
||||
public IrisCaveProfileSampler getCarvingProfileSampler(Engine engine, IrisData data) {
|
||||
if (!hasCarvingReference()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CachedCarvingProfile recent = recentCarvingProfile;
|
||||
if (recent != null && recent.key.matches(0L, data, engine)) {
|
||||
return recent.sampler;
|
||||
}
|
||||
RuntimeKey key = new RuntimeKey(0L, data, engine);
|
||||
IrisCaveProfileSampler sampler = carvingProfileSamplers.computeIfAbsent(key, ignored -> {
|
||||
IrisBiome resolved = resolveCarvingBiome(carving, engine, data);
|
||||
if (resolved == null || resolved.getCaveProfile() == null || !resolved.getCaveProfile().isEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new IrisCaveProfileSampler(engine, resolved.getCaveProfile());
|
||||
});
|
||||
recentCarvingProfile = new CachedCarvingProfile(key, sampler);
|
||||
return sampler;
|
||||
}
|
||||
|
||||
public boolean hasCarvingReference() {
|
||||
return carving != null && !carving.isBlank();
|
||||
}
|
||||
|
||||
static IrisBiome resolveCarvingBiome(String carving, Engine engine, IrisData data) {
|
||||
if (carving == null || carving.isBlank() || engine == null || data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
if (dimension != null && dimension.getCarvingEntryIndex() != null) {
|
||||
IrisDimensionCarvingEntry entry = dimension.getCarvingEntryIndex().get(carving);
|
||||
if (entry != null) {
|
||||
return IrisDimensionCarvingResolver.resolveEntryBiome(engine, entry);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.getBiomeLoader() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return data.getBiomeLoader().load(carving);
|
||||
}
|
||||
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Description("The target biome whose visual design (layers, palette, decorators, surface objects, derivative, and — when topShapeMode=BIOME — generator profile) drives the floating island. Leave empty to reuse the parent biome (self).")
|
||||
private String biome = "";
|
||||
@@ -293,12 +237,9 @@ public class IrisFloatingChildBiomes implements Rarity {
|
||||
@Description("Optional 3D noise that swiss-cheeses the island interior by marking individual blocks as air when the noise exceeds carveThreshold. Leave null to keep the island solid. Good defaults: {\"style\":\"CELLULAR\",\"zoom\":0.3} for bubble pockets, {\"style\":\"VASCULAR\",\"zoom\":0.25} for wormy tunnels.")
|
||||
private IrisGeneratorStyle carveStyle = null;
|
||||
|
||||
@Description("Optional carving biome key or dimension carving entry id whose caveProfile drives floating-island internal air pockets. Dimension carving ids resolve first; biome keys such as carving/mushroom resolve second. When set, this overrides carveStyle while carveThreshold remains a final tuning bias.")
|
||||
private String carving = "";
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Threshold (0..1) above which carveStyle noise carves air pockets. 1.0 = no direct-noise carving. 0.75 = sparse pockets. 0.55 = heavy swiss-cheese. 0.4 = shredded lattice. When carving is set, lower values add a final positive threshold bias to the referenced caveProfile.")
|
||||
@Description("Threshold (0..1) above which carveStyle noise carves air pockets. 1.0 = no direct-noise carving. 0.75 = sparse pockets. 0.55 = heavy swiss-cheese. 0.4 = shredded lattice.")
|
||||
private double carveThreshold = 1.0;
|
||||
|
||||
@Description("Optional water surface height above the island base, in blocks. null = no internal water. Positive = water fills any dip in the top profile up to baseY + localFluidHeight (forms lakes/ponds in concavities of the biome-top heightmap).")
|
||||
@@ -421,7 +362,4 @@ public class IrisFloatingChildBiomes implements Rarity {
|
||||
|
||||
private record CachedEdgeProfile(RuntimeKey key, FloatingIslandEdgeProfile profile) {
|
||||
}
|
||||
|
||||
private record CachedCarvingProfile(RuntimeKey key, IrisCaveProfileSampler sampler) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The numbers a cave file writes outside what their keys allow, read from the {@link MinNumber} and {@link MaxNumber} of
|
||||
* each key and reported by their place in the file. A {@link CaveValue} is not a plain number, so the schema cannot
|
||||
* bound its ends: this does. It reads the file as written, so a style that names a snippet needs no resolving.
|
||||
*/
|
||||
public final class CaveBounds {
|
||||
private static final String CAVE_PACKAGE = IrisCave.class.getPackageName();
|
||||
private static final String MIN = "min";
|
||||
private static final String MAX = "max";
|
||||
private static final String COVERAGE_SHARE = "share";
|
||||
|
||||
private CaveBounds() {
|
||||
}
|
||||
|
||||
/** Each number of the cave file outside what its key allows, such as {@code fade is 200; it must be at most 128}. */
|
||||
public static List<String> valuesOutOfBounds(JsonObject cave) {
|
||||
List<String> problems = new ArrayList<>();
|
||||
collect(IrisCave.class, cave, "", problems);
|
||||
return problems;
|
||||
}
|
||||
|
||||
private static void collect(Class<?> type, JsonObject written, String path, List<String> problems) {
|
||||
for (Map.Entry<String, JsonElement> member : written.entrySet()) {
|
||||
Field field = declaredField(type, member.getKey());
|
||||
if (field != null) {
|
||||
collectMember(field, member.getValue(), path.isEmpty() ? member.getKey() : path + "." + member.getKey(), problems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectMember(Field field, JsonElement value, String path, List<String> problems) {
|
||||
Class<?> type = field.getType();
|
||||
if (type == CaveValue.class) {
|
||||
collectValue(field, value, path, problems);
|
||||
} else if (type == CaveTunnelCoverage.class && value.isJsonPrimitive()) {
|
||||
collectValue(declaredField(CaveTunnelCoverage.class, COVERAGE_SHARE), value, path + "." + COVERAGE_SHARE, problems);
|
||||
} else if (value.isJsonObject() && type.getPackageName().equals(CAVE_PACKAGE)) {
|
||||
collect(type, value.getAsJsonObject(), path, problems);
|
||||
} else if (isNumber(value)) {
|
||||
requireWithin(field, value.getAsDouble(), path, problems);
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectValue(Field field, JsonElement value, String path, List<String> problems) {
|
||||
if (isNumber(value)) {
|
||||
requireWithin(field, value.getAsDouble(), path, problems);
|
||||
return;
|
||||
}
|
||||
if (!value.isJsonObject() || !isNumber(value.getAsJsonObject().get(MIN)) || !isNumber(value.getAsJsonObject().get(MAX))) {
|
||||
return;
|
||||
}
|
||||
double min = value.getAsJsonObject().get(MIN).getAsDouble();
|
||||
double max = value.getAsJsonObject().get(MAX).getAsDouble();
|
||||
if (min == max) {
|
||||
requireWithin(field, min, path, problems);
|
||||
return;
|
||||
}
|
||||
requireWithin(field, min, path + "." + MIN, problems);
|
||||
requireWithin(field, max, path + "." + MAX, problems);
|
||||
}
|
||||
|
||||
private static boolean isNumber(JsonElement element) {
|
||||
return element != null && element.isJsonPrimitive() && element.getAsJsonPrimitive().isNumber();
|
||||
}
|
||||
|
||||
private static Field declaredField(Class<?> type, String name) {
|
||||
try {
|
||||
return type.getDeclaredField(name);
|
||||
} catch (NoSuchFieldException unknown) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireWithin(Field field, double value, String path, List<String> problems) {
|
||||
MinNumber least = field.getAnnotation(MinNumber.class);
|
||||
MaxNumber most = field.getAnnotation(MaxNumber.class);
|
||||
if (least != null && value < least.value()) {
|
||||
problems.add(path + " is " + shortNumber(value) + "; it must be at least " + shortNumber(least.value()));
|
||||
} else if (most != null && value > most.value()) {
|
||||
problems.add(path + " is " + shortNumber(value) + "; it must be at most " + shortNumber(most.value()));
|
||||
}
|
||||
}
|
||||
|
||||
private static String shortNumber(double value) {
|
||||
return value == Math.rint(value) ? Long.toString((long) value) : Double.toString(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** The caverns of a {@link IrisCave}: large open rooms, with pillars left standing in them where the cave asks for some. */
|
||||
@Description("Large open rooms.")
|
||||
public final class CaveCavern {
|
||||
/** Without a style, a value of the caverns or their pillars changes over this many room sizes. */
|
||||
public static final int VALUE_CHANGE_SIZES = 4;
|
||||
|
||||
@MinNumber(16)
|
||||
@MaxNumber(512)
|
||||
@Description("Rough span of a room in blocks, 16 to 512. A range changes over about " + VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue size = CaveValue.of(56);
|
||||
|
||||
@MinNumber(8)
|
||||
@MaxNumber(256)
|
||||
@Description("Rough height of a room in blocks, 8 to 256. A range changes over about " + VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue height = CaveValue.of(22);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(0.6)
|
||||
@Description("Share of the underground that is cavern, 0 to 0.6. 0.1 gives scattered rooms, 0.3 joins them into halls. A range changes over about "
|
||||
+ VALUE_CHANGE_SIZES + " room sizes; a min of 0 leaves areas without rooms. A range in size, height or roughness makes the share approximate.")
|
||||
private CaveValue coverage = CaveValue.of(0.1);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Strength of the finer noise on room walls, 0 to 1. 0 gives smooth bubbles. Ignored with a style, and in rooms under about 20 blocks tall or across. A range changes over about "
|
||||
+ VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue roughness = CaveValue.of(0.3);
|
||||
|
||||
@Description("Noise that shapes the rooms. Scaled to size and height, so its zoom has no effect; a fracture stays in blocks. Detail under about 12 blocks is lost. Leave out for smooth rooms with rough walls.")
|
||||
private IrisGeneratorStyle style;
|
||||
|
||||
@Description("Rock columns left standing inside the rooms. Leave out for open rooms.")
|
||||
private CavePillars pillars;
|
||||
|
||||
public CaveCavern() {
|
||||
}
|
||||
|
||||
/** The noise that shapes the rooms; empty where the pack wrote none. */
|
||||
public Optional<IrisGeneratorStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
public CaveValue size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public CaveValue height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public CaveValue coverage() {
|
||||
return coverage;
|
||||
}
|
||||
|
||||
public CaveValue roughness() {
|
||||
return roughness;
|
||||
}
|
||||
|
||||
public Optional<CavePillars> pillars() {
|
||||
return Optional.ofNullable(pillars);
|
||||
}
|
||||
}
|
||||
+21
-12
@@ -16,18 +16,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.map;
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
/**
|
||||
* Terrain as the 3D noise view draws it: its columns and their block faces, for any hole finer terrain cuts in it.
|
||||
*/
|
||||
record TerrainLayer(NoiseTerrain terrain, BlockFaces faces) {
|
||||
/**
|
||||
* @param floorY how far down sides on the terrain's edge or next to a hole reach, so they meet the terrain beside it
|
||||
* whatever its height
|
||||
*/
|
||||
static TerrainLayer of(NoiseTerrain terrain, int floorY) {
|
||||
int reachedFloorY = terrain.isEmpty() ? floorY : Math.min(floorY, terrain.baseY());
|
||||
return new TerrainLayer(terrain, BlockFaces.of(terrain, reachedFloorY));
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
/** The world Y range a {@link IrisCave} occurs in. Either end may vary across the world. */
|
||||
@Description("World Y range a cave occurs in.")
|
||||
public final class CaveDepth {
|
||||
@Description("Lowest world Y. A range changes over about " + IrisCave.VALUE_CHANGE_BLOCKS + " blocks.")
|
||||
private CaveValue min = CaveValue.of(16);
|
||||
|
||||
@Description("Highest world Y. A range changes over about " + IrisCave.VALUE_CHANGE_BLOCKS + " blocks.")
|
||||
private CaveValue max = CaveValue.of(32);
|
||||
|
||||
public CaveDepth() {
|
||||
}
|
||||
|
||||
public CaveValue min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public CaveValue max() {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Reads and writes the two cave types a pack may write as a plain number or as an object: {@link CaveValue} and
|
||||
* {@link CaveTunnelCoverage}. Both keep their object members to the ones named here, so a typo is an error, not a default.
|
||||
*/
|
||||
public final class CaveJson {
|
||||
private static final String MIN = "min";
|
||||
private static final String MAX = "max";
|
||||
private static final String SHARE = "share";
|
||||
private static final String SOFTNESS = "softness";
|
||||
private static final String STYLE = "style";
|
||||
private static final Set<String> VALUE_MEMBERS = Set.of(MIN, MAX, STYLE);
|
||||
private static final Set<String> COVERAGE_MEMBERS = Set.of(SHARE, SOFTNESS, STYLE);
|
||||
|
||||
private CaveJson() {
|
||||
}
|
||||
|
||||
public static void register(GsonBuilder builder) {
|
||||
builder.registerTypeAdapter(CaveValue.class, new ValueCodec());
|
||||
builder.registerTypeAdapter(CaveTunnelCoverage.class, new CoverageCodec());
|
||||
}
|
||||
|
||||
private static final class ValueCodec implements JsonDeserializer<CaveValue>, JsonSerializer<CaveValue> {
|
||||
@Override
|
||||
public CaveValue deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
|
||||
return readValue(json, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(CaveValue value, Type type, JsonSerializationContext context) {
|
||||
return writeValue(value, context);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CoverageCodec implements JsonDeserializer<CaveTunnelCoverage>, JsonSerializer<CaveTunnelCoverage> {
|
||||
@Override
|
||||
public CaveTunnelCoverage deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
|
||||
return readCoverage(json, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(CaveTunnelCoverage coverage, Type type, JsonSerializationContext context) {
|
||||
return writeCoverage(coverage, context);
|
||||
}
|
||||
}
|
||||
|
||||
private static CaveValue readValue(JsonElement json, JsonDeserializationContext context) {
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) {
|
||||
return CaveValue.of(json.getAsDouble());
|
||||
}
|
||||
if (!json.isJsonObject()) {
|
||||
throw new JsonParseException("A cave value is a number or {min, max} with an optional style, not " + json);
|
||||
}
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
requireOnlyMembers(object, VALUE_MEMBERS, "A varying cave value has min, max and style, not ");
|
||||
if (!object.has(MIN) || !object.has(MAX)) {
|
||||
throw new JsonParseException("A varying cave value needs both min and max: " + object);
|
||||
}
|
||||
return CaveValue.between(number(object, MIN), number(object, MAX), styleOf(object, context));
|
||||
}
|
||||
|
||||
private static JsonElement writeValue(CaveValue value, JsonSerializationContext context) {
|
||||
if (value.isWrittenAsPlainNumber()) {
|
||||
return context.serialize(value.min());
|
||||
}
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty(MIN, value.min());
|
||||
object.addProperty(MAX, value.max());
|
||||
value.style().ifPresent(style -> object.add(STYLE, context.serialize(style)));
|
||||
return object;
|
||||
}
|
||||
|
||||
private static CaveTunnelCoverage readCoverage(JsonElement json, JsonDeserializationContext context) {
|
||||
CaveTunnelCoverage everywhere = CaveTunnelCoverage.EVERYWHERE;
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) {
|
||||
return CaveTunnelCoverage.of(CaveValue.of(json.getAsDouble()), everywhere.softness(), null);
|
||||
}
|
||||
if (!json.isJsonObject()) {
|
||||
throw new JsonParseException("A tunnel coverage is a share or {share, softness, style}, not " + json);
|
||||
}
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
requireOnlyMembers(object, COVERAGE_MEMBERS, "A tunnel coverage has share, softness and style, not ");
|
||||
CaveValue share = object.has(SHARE) ? context.deserialize(object.get(SHARE), CaveValue.class) : everywhere.share();
|
||||
CaveValue softness = object.has(SOFTNESS) ? context.deserialize(object.get(SOFTNESS), CaveValue.class) : everywhere.softness();
|
||||
return CaveTunnelCoverage.of(share, softness, styleOf(object, context));
|
||||
}
|
||||
|
||||
private static JsonElement writeCoverage(CaveTunnelCoverage coverage, JsonSerializationContext context) {
|
||||
if (coverage.isWrittenAsShareOnly()) {
|
||||
return context.serialize(coverage.share(), CaveValue.class);
|
||||
}
|
||||
JsonObject object = new JsonObject();
|
||||
object.add(SHARE, context.serialize(coverage.share(), CaveValue.class));
|
||||
object.add(SOFTNESS, context.serialize(coverage.softness(), CaveValue.class));
|
||||
coverage.style().ifPresent(style -> object.add(STYLE, context.serialize(style)));
|
||||
return object;
|
||||
}
|
||||
|
||||
private static void requireOnlyMembers(JsonObject object, Set<String> allowed, String message) {
|
||||
for (String member : object.keySet()) {
|
||||
if (!allowed.contains(member)) {
|
||||
throw new JsonParseException(message + member);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double number(JsonObject object, String member) {
|
||||
JsonElement written = object.get(member);
|
||||
if (written.isJsonPrimitive() && written.getAsJsonPrimitive().isNumber()) {
|
||||
return written.getAsDouble();
|
||||
}
|
||||
throw new JsonParseException(member + " needs a number, not " + written);
|
||||
}
|
||||
|
||||
private static IrisGeneratorStyle styleOf(JsonObject object, JsonDeserializationContext context) {
|
||||
return object.has(STYLE) ? context.deserialize(object.get(STYLE), IrisGeneratorStyle.class) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** The pillars of a {@link CaveCavern}: columns of rock left standing from floor to ceiling. */
|
||||
@Description("Rock columns left standing inside caverns.")
|
||||
public final class CavePillars {
|
||||
@MinNumber(6)
|
||||
@MaxNumber(256)
|
||||
@Description("Rough distance between pillars in blocks, 6 to 256. A range changes over about " + CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue spacing = CaveValue.of(22);
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("Rough thickness of a pillar at its middle, in blocks, 1 to 64. Pillars widen towards floor and ceiling. A range changes over about "
|
||||
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue thickness = CaveValue.of(4);
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(16)
|
||||
@Description("How many times more ground a pillar covers at floor and ceiling than at its middle, 1 to 16. 1 gives straight columns. A range changes over about "
|
||||
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
|
||||
private CaveValue flare = CaveValue.of(4);
|
||||
|
||||
@MinNumber(8)
|
||||
@MaxNumber(512)
|
||||
@Description("Blocks over which the pillars change with height, 8 to 512, so they lean, pinch and break off. Detail under about 12 blocks is lost. A range changes over about "
|
||||
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes. Leave out for columns that run straight from floor to ceiling.")
|
||||
private CaveValue vertical;
|
||||
|
||||
@Description("Noise that places the pillars. Scaled to spacing, so its zoom has no effect; a fracture stays in blocks. Leave out for evenly scattered pillars.")
|
||||
private IrisGeneratorStyle style;
|
||||
|
||||
public CavePillars() {
|
||||
}
|
||||
|
||||
public CaveValue flare() {
|
||||
return flare;
|
||||
}
|
||||
|
||||
/** Blocks over which the pillars change with height; empty for pillars that run straight. */
|
||||
public Optional<CaveValue> vertical() {
|
||||
return Optional.ofNullable(vertical);
|
||||
}
|
||||
|
||||
/** The noise that places the pillars; empty where the pack wrote none. */
|
||||
public Optional<IrisGeneratorStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
public CaveValue spacing() {
|
||||
return spacing;
|
||||
}
|
||||
|
||||
public CaveValue thickness() {
|
||||
return thickness;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.field.CaveCarver;
|
||||
import art.arcane.iris.generation.cave.field.CavePart;
|
||||
import art.arcane.iris.generation.cave.field.CngNoiseFactory;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.scene.SceneBlocks;
|
||||
import art.arcane.iris.studio.scene.SceneEntry;
|
||||
import art.arcane.iris.studio.scene.SceneRequest;
|
||||
import art.arcane.iris.studio.scene.SceneSizes;
|
||||
import art.arcane.iris.studio.scene.SceneView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* The space each cave of the pack carves under flat ground, as blocks coloured by depth. Each block names the part of
|
||||
* the cave that carved it, its tunnel or its cavern. Caves are only shown here; their files are edited elsewhere.
|
||||
*/
|
||||
public final class CaveSceneView implements SceneView {
|
||||
private static final SceneSizes SIZES = new SceneSizes(List.of(64, 128, 256), 128);
|
||||
private static final int VARIANTS = 4;
|
||||
private static final int VARIANT_SPACING_BLOCKS = 4096;
|
||||
private static final int SURFACE_ABOVE_SEA_BLOCKS = 48;
|
||||
private static final int MAX_DEPTH_BLOCKS = 160;
|
||||
private static final int CHUNK_BLOCKS = 16;
|
||||
private static final int CHUNK_COLUMNS = CHUNK_BLOCKS * CHUNK_BLOCKS;
|
||||
private static final byte ROCK = 0;
|
||||
private static final String GROUP = "Caves";
|
||||
private static final String[] DEPTH_BANDS = {"minecraft:yellow_concrete", "minecraft:lime_concrete", "minecraft:light_blue_concrete",
|
||||
"minecraft:purple_concrete"};
|
||||
private static final int[][] NEIGHBOURS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "caves";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Caves";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "The space each cave of the pack carves under flat ground, its tunnel and its cavern";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneSizes sizes() {
|
||||
return SIZES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneEntry> entries(Engine engine) {
|
||||
return Arrays.stream(engine.getData().getCaveLoader().getPossibleKeys()).sorted()
|
||||
.map(key -> new SceneEntry(key, key, GROUP, VARIANTS))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBlocks scene(Engine engine, SceneRequest request) {
|
||||
IrisCave cave = caveOf(engine.getData(), request.key());
|
||||
int surfaceY = Math.min(engine.getHeight() - 1, engine.getDimension().getFluidHeight() + SURFACE_ABOVE_SEA_BLOCKS);
|
||||
HeightSpan span = HeightSpan.of(cave, engine.getMinHeight(), surfaceY);
|
||||
long seed = CaveCarver.seedOf(engine.getSeedManager().getCarve(), request.key());
|
||||
CaveCarver carver = new CaveCarver(cave, new CngNoiseFactory(engine.getData()), seed, engine.getMinHeight(), engine.getHeight());
|
||||
int originX = Math.floorMod(request.variant(), VARIANTS) * VARIANT_SPACING_BLOCKS;
|
||||
CarvedSpace carved = new CarvedSpace(request.size(), span);
|
||||
carveSquare(carver, originX, surfaceY, carved);
|
||||
return carved.outside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tracesParts() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IrisCave caveOf(IrisData data, String key) {
|
||||
IrisCave cave = data.getCaveLoader().load(key);
|
||||
if (cave == null) {
|
||||
throw new NoSuchElementException("No cave " + key);
|
||||
}
|
||||
return cave;
|
||||
}
|
||||
|
||||
private static void carveSquare(CaveCarver carver, int originX, int surfaceY, CarvedSpace carved) {
|
||||
int[] surface = new int[CHUNK_COLUMNS];
|
||||
Arrays.fill(surface, surfaceY);
|
||||
double[] listedEverywhere = new double[CHUNK_COLUMNS];
|
||||
Arrays.fill(listedEverywhere, 1D);
|
||||
boolean[] sealed = new boolean[CHUNK_COLUMNS];
|
||||
for (int chunkX = 0; chunkX < carved.size; chunkX += CHUNK_BLOCKS) {
|
||||
for (int chunkZ = 0; chunkZ < carved.size; chunkZ += CHUNK_BLOCKS) {
|
||||
int fromX = chunkX;
|
||||
int fromZ = chunkZ;
|
||||
carver.carveByPart(originX + chunkX, chunkZ, surface, listedEverywhere, sealed,
|
||||
(part, localX, y, localZ) -> carved.mark(fromX + localX, y, fromZ + localZ, part));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The heights shown, from the dimension's bottom: the cave's own depth where it has one, below the ground. */
|
||||
private record HeightSpan(int bottomY, int topY) {
|
||||
static HeightSpan of(IrisCave cave, int worldBottomY, int surfaceY) {
|
||||
int topY = cave.depth().map(depth -> Math.min(surfaceY, (int) Math.ceil(depth.max().highest()) - worldBottomY)).orElse(surfaceY);
|
||||
int depthBottomY = cave.depth().map(depth -> (int) Math.floor(depth.min().lowest()) - worldBottomY).orElse(0);
|
||||
int bottomY = Math.max(0, Math.max(depthBottomY, topY - MAX_DEPTH_BLOCKS));
|
||||
return new HeightSpan(bottomY, Math.max(bottomY, topY));
|
||||
}
|
||||
|
||||
int height() {
|
||||
return topY - bottomY + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/** The cells of the scene, each rock or carved by a part; a cell two parts carve keeps the last. */
|
||||
private static final class CarvedSpace {
|
||||
private final int size;
|
||||
private final HeightSpan span;
|
||||
private final byte[] cells;
|
||||
|
||||
CarvedSpace(int size, HeightSpan span) {
|
||||
this.size = size;
|
||||
this.span = span;
|
||||
this.cells = new byte[size * size * span.height()];
|
||||
}
|
||||
|
||||
void mark(int x, int worldY, int z, CavePart part) {
|
||||
int y = worldY - span.bottomY();
|
||||
if (y < 0 || y >= span.height()) {
|
||||
return;
|
||||
}
|
||||
cells[cellOf(x, y, z)] = (byte) (part.ordinal() + 1);
|
||||
}
|
||||
|
||||
// Only the carved blocks on the outside of the space are kept, as the inside could not be seen.
|
||||
SceneBlocks outside() {
|
||||
SceneBlocks scene = new SceneBlocks();
|
||||
int height = span.height();
|
||||
for (int y = 0; y < height; y++) {
|
||||
String band = DEPTH_BANDS[Math.min(DEPTH_BANDS.length - 1, (height - 1 - y) * DEPTH_BANDS.length / height)];
|
||||
for (int z = 0; z < size; z++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
byte cell = cells[cellOf(x, y, z)];
|
||||
if (cell != ROCK && touchesRock(x, y, z)) {
|
||||
scene.add(x, y, z, band, cell - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return scene;
|
||||
}
|
||||
|
||||
private boolean touchesRock(int x, int y, int z) {
|
||||
for (int[] step : NEIGHBOURS) {
|
||||
int nx = x + step[0];
|
||||
int ny = y + step[1];
|
||||
int nz = z + step[2];
|
||||
boolean inside = nx >= 0 && ny >= 0 && nz >= 0 && nx < size && ny < span.height() && nz < size;
|
||||
if (!inside || cells[cellOf(nx, ny, nz)] == ROCK) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int cellOf(int x, int y, int z) {
|
||||
return (y * size + z) * size + x;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** The tunnels of a {@link IrisCave}: long winding passages. Thin ones link other caves together. */
|
||||
@Description("Long winding passages.")
|
||||
public final class CaveTunnel {
|
||||
/** Without a style, the width changes over this many horizontal spacings. */
|
||||
public static final double WIDTH_CHANGE_SPACINGS = 1.5D;
|
||||
/** Without a style, any other value of the tunnels changes over this many horizontal spacings. */
|
||||
public static final int VALUE_CHANGE_SPACINGS = 6;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("Tunnel width in blocks, 1 to 64. A range changes over about " + WIDTH_CHANGE_SPACINGS + " horizontal spacings.")
|
||||
private CaveValue width = CaveValue.between(4, 7);
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("Tunnel height in blocks, 1 to 64. A range without a style follows the width: low where the tunnel is narrow, tall where it is wide. Leave out for round tunnels.")
|
||||
private CaveValue height;
|
||||
|
||||
@Description("Blocks between neighbouring tunnels.")
|
||||
private CaveTunnelSpacing spacing = new CaveTunnelSpacing();
|
||||
|
||||
@Description("Noise that bends the tunnels: zoom sets how often they turn, multiplier how many blocks they swing. A flat style keeps them straight. Leave out for a gentle bend that scales with spacing.")
|
||||
private IrisGeneratorStyle warp;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How far the warp moves tunnels up and down, as a share of how far it swings them sideways, 0 to 1. 0 adds no rise and fall. A range changes over about "
|
||||
+ VALUE_CHANGE_SPACINGS + " horizontal spacings.")
|
||||
private CaveValue verticalWarp = CaveValue.of(0.5);
|
||||
|
||||
@Description("Where tunnels occur: a share of the underground from 0 to 1, or {share, softness, style}. Softness, 0 to 1, is how gradually tunnels thin out at the edge of an area, from abrupt dead ends to long tails; style is the noise that shapes the areas. Share and softness change over about "
|
||||
+ VALUE_CHANGE_SPACINGS + " horizontal spacings as a range. Leave out to put tunnels everywhere.")
|
||||
private CaveTunnelCoverage coverage;
|
||||
|
||||
public CaveTunnel() {
|
||||
}
|
||||
|
||||
public CaveValue width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/** The height of an oval tunnel; empty for a round one. */
|
||||
public Optional<CaveValue> height() {
|
||||
return Optional.ofNullable(height);
|
||||
}
|
||||
|
||||
public CaveTunnelSpacing spacing() {
|
||||
return spacing == null ? new CaveTunnelSpacing() : spacing;
|
||||
}
|
||||
|
||||
/** The noise that bends the tunnels; empty where the pack wrote none. */
|
||||
public Optional<IrisGeneratorStyle> warp() {
|
||||
return Optional.ofNullable(warp);
|
||||
}
|
||||
|
||||
public CaveValue verticalWarp() {
|
||||
return verticalWarp;
|
||||
}
|
||||
|
||||
public CaveTunnelCoverage coverage() {
|
||||
return coverage == null ? CaveTunnelCoverage.EVERYWHERE : coverage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.schema.annotation.AcceptsPlainNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Where the tunnels of a {@link CaveTunnel} occur: the share of the underground that has them, in areas a noise shapes,
|
||||
* and how gradually they thin out at the edge of an area. Written as the share alone, {@code 0.4}, or as
|
||||
* {@code {"share": 0.4, "softness": 0.3, "style": {...}}} with each member optional.
|
||||
*/
|
||||
@AcceptsPlainNumber
|
||||
@Description("Where tunnels occur: a share, or {share, softness, style}.")
|
||||
public final class CaveTunnelCoverage {
|
||||
/** The softness that thins tunnels out over the same stretch they always did before softness was a key. */
|
||||
public static final double DEFAULT_SOFTNESS = 0.3D;
|
||||
static final CaveTunnelCoverage EVERYWHERE = new CaveTunnelCoverage();
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Share of the underground that has tunnels, 0 to 1. A range changes over about " + CaveTunnel.VALUE_CHANGE_SPACINGS + " horizontal spacings.")
|
||||
private CaveValue share = CaveValue.of(1);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("How gradually tunnels thin out at the edge of an area, 0 for abrupt dead ends to 1 for long tails.")
|
||||
private CaveValue softness = CaveValue.of(DEFAULT_SOFTNESS);
|
||||
|
||||
@Description("The noise that shapes the areas with tunnels. Leave out for areas a few spacings across.")
|
||||
private IrisGeneratorStyle style;
|
||||
|
||||
public CaveTunnelCoverage() {
|
||||
}
|
||||
|
||||
static CaveTunnelCoverage of(CaveValue share, CaveValue softness, IrisGeneratorStyle style) {
|
||||
CaveTunnelCoverage coverage = new CaveTunnelCoverage();
|
||||
coverage.share = share;
|
||||
coverage.softness = softness;
|
||||
coverage.style = style;
|
||||
return coverage;
|
||||
}
|
||||
|
||||
/** Share of the underground that has tunnels, from 0 to 1. */
|
||||
public CaveValue share() {
|
||||
return share;
|
||||
}
|
||||
|
||||
/** How gradually tunnels thin out at the edge of an area, from 0 for abrupt ends to 1 for long tails. */
|
||||
public CaveValue softness() {
|
||||
return softness;
|
||||
}
|
||||
|
||||
/** The noise that shapes the areas with tunnels; empty where the pack wrote none. */
|
||||
public Optional<IrisGeneratorStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
boolean isWrittenAsShareOnly() {
|
||||
return style == null && softness.min() == DEFAULT_SOFTNESS && !softness.varies();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
/** How far apart the tunnels of a {@link CaveTunnel} run, side by side and stacked. */
|
||||
@Description("Blocks between neighbouring tunnels.")
|
||||
public final class CaveTunnelSpacing {
|
||||
@MinNumber(16)
|
||||
@MaxNumber(512)
|
||||
@Description("Blocks between tunnels side by side. Larger gives longer, straighter and sparser tunnels.")
|
||||
private int horizontal = 96;
|
||||
|
||||
@MinNumber(8)
|
||||
@MaxNumber(512)
|
||||
@Description("Blocks between tunnels stacked above each other. Below horizontal keeps tunnels closer to level.")
|
||||
private int vertical = 69;
|
||||
|
||||
public CaveTunnelSpacing() {
|
||||
}
|
||||
|
||||
public int horizontal() {
|
||||
return horizontal;
|
||||
}
|
||||
|
||||
public int vertical() {
|
||||
return vertical;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.schema.annotation.AcceptsPlainNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A number that shapes how a cave looks, which may vary across the world: {@code 5} everywhere,
|
||||
* {@code {"min": 3, "max": 9}} picked by a smooth noise the cave chooses for the key, or
|
||||
* {@code {"min": 3, "max": 9, "style": {...}}} picked by that style, its zoom as written. The noise's low end gives
|
||||
* min and its high end max.
|
||||
*/
|
||||
@AcceptsPlainNumber
|
||||
@Description("A number, or {min, max} that varies across the world; add a style to decide where.")
|
||||
public final class CaveValue {
|
||||
@Required
|
||||
@Description("The value where the noise is lowest.")
|
||||
private double min;
|
||||
|
||||
@Required
|
||||
@Description("The value where the noise is highest.")
|
||||
private double max;
|
||||
|
||||
@Description("The noise that decides where the value is low or high, its zoom as written. Leave out and the cave picks a smooth noise for this key.")
|
||||
private IrisGeneratorStyle style;
|
||||
|
||||
public CaveValue() {
|
||||
}
|
||||
|
||||
private CaveValue(double min, double max, IrisGeneratorStyle style) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public static CaveValue of(double value) {
|
||||
return new CaveValue(value, value, null);
|
||||
}
|
||||
|
||||
public static CaveValue between(double min, double max) {
|
||||
return new CaveValue(min, max, null);
|
||||
}
|
||||
|
||||
public static CaveValue between(double min, double max, IrisGeneratorStyle style) {
|
||||
return new CaveValue(min, max, style);
|
||||
}
|
||||
|
||||
/** Whether the value differs from place to place; a plain number, or a min equal to max, does not. */
|
||||
public boolean varies() {
|
||||
return min != max;
|
||||
}
|
||||
|
||||
/** The value where the noise is lowest; the value everywhere when it does not vary. */
|
||||
public double min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
/** The value where the noise is highest. */
|
||||
public double max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public double middle() {
|
||||
return (min + max) / 2D;
|
||||
}
|
||||
|
||||
public double lowest() {
|
||||
return Math.min(min, max);
|
||||
}
|
||||
|
||||
public double highest() {
|
||||
return Math.max(min, max);
|
||||
}
|
||||
|
||||
/** The noise the pack chose to pick the value; empty where it wrote none and the cave picks a smooth one. */
|
||||
public Optional<IrisGeneratorStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
boolean isWrittenAsPlainNumber() {
|
||||
return style == null && min == max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return isWrittenAsPlainNumber() ? Double.toString(min) : "{min " + min + ", max " + max + (style == null ? "" : ", style " + style) + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.pack.loading.IrisRegistrant;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListResource;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* One kind of cave, a file of a pack's {@code caves/} folder that dimensions, regions and biomes list under
|
||||
* {@code caves}. It carves tunnels, caverns or both, within a depth range and under the surface rules it sets. Every
|
||||
* number that shapes the cave is a {@link CaveValue}, so it may vary across the world.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Description("One kind of cave: tunnels, caverns or both, with where they may occur.")
|
||||
public final class IrisCave extends IrisRegistrant {
|
||||
/** Without a style, a value of the whole cave changes over about this many blocks. */
|
||||
public static final int VALUE_CHANGE_BLOCKS = 256;
|
||||
static final String FOLDER_NAME = "caves";
|
||||
|
||||
@Description("Winding tunnels. Leave out for a cave without tunnels.")
|
||||
private CaveTunnel tunnel;
|
||||
|
||||
@Description("Large open rooms. Leave out for a cave without caverns.")
|
||||
private CaveCavern cavern;
|
||||
|
||||
@Description("World Y range this cave occurs in. Leave out to allow every height.")
|
||||
private CaveDepth depth;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@Description("Blocks over which the cave narrows to nothing at both ends of its depth range, 0 to 128. A range changes over about "
|
||||
+ VALUE_CHANGE_BLOCKS + " blocks.")
|
||||
private CaveValue fade = CaveValue.of(12);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@Description("Blocks of rock kept between the cave and the surface, 0 to 128. Ignored when opensToSurface is set. A range changes over about "
|
||||
+ VALUE_CHANGE_BLOCKS + " blocks.")
|
||||
private CaveValue surfaceClearance = CaveValue.of(8);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@Description("Blocks over which the cave closes under the rock it keeps, instead of ending in a flat ceiling, 0 to 128. Ignored where it opens to the surface. A range changes over about "
|
||||
+ VALUE_CHANGE_BLOCKS + " blocks.")
|
||||
private CaveValue ceilingFade = CaveValue.of(8);
|
||||
|
||||
@Description("Let the cave cut through the surface, which makes entrances wherever it reaches the top.")
|
||||
private boolean opensToSurface = false;
|
||||
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Description("Cave biome that paints this cave's walls. Leave out to use the cave biome of the place.")
|
||||
private String biome = "";
|
||||
|
||||
@Description("Allow pockets of the dimension's fluid in this cave below the dimension's fluid height.")
|
||||
private boolean allowFluid = true;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Description("Minimum depth below the surface before this cave may hold fluid.")
|
||||
private int fluidMinDepthBelowSurface = 12;
|
||||
|
||||
@Description("Only hold fluid where the cave has a solid floor under it, which keeps fluid from running out of the cave.")
|
||||
private boolean fluidRequiresFloor = true;
|
||||
|
||||
@Description("Allow lava below the dimension's cave lava height. When false that depth stays air.")
|
||||
private boolean allowLava = true;
|
||||
|
||||
public IrisCave() {
|
||||
}
|
||||
|
||||
public Optional<CaveTunnel> tunnel() {
|
||||
return Optional.ofNullable(tunnel);
|
||||
}
|
||||
|
||||
public Optional<CaveCavern> cavern() {
|
||||
return Optional.ofNullable(cavern);
|
||||
}
|
||||
|
||||
public Optional<CaveDepth> depth() {
|
||||
return Optional.ofNullable(depth);
|
||||
}
|
||||
|
||||
public CaveValue fade() {
|
||||
return fade;
|
||||
}
|
||||
|
||||
public CaveValue surfaceClearance() {
|
||||
return surfaceClearance;
|
||||
}
|
||||
|
||||
public CaveValue ceilingFade() {
|
||||
return ceilingFade;
|
||||
}
|
||||
|
||||
public boolean opensToSurface() {
|
||||
return opensToSurface;
|
||||
}
|
||||
|
||||
public String biome() {
|
||||
return biome == null ? "" : biome;
|
||||
}
|
||||
|
||||
public boolean allowFluid() {
|
||||
return allowFluid;
|
||||
}
|
||||
|
||||
public int fluidMinDepthBelowSurface() {
|
||||
return Math.max(0, fluidMinDepthBelowSurface);
|
||||
}
|
||||
|
||||
public boolean fluidRequiresFloor() {
|
||||
return fluidRequiresFloor;
|
||||
}
|
||||
|
||||
public boolean allowLava() {
|
||||
return allowLava;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return FOLDER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Cave";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTypeAdapters(GsonBuilder builder) {
|
||||
CaveJson.register(builder);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("cave-field-module")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("Represents a modular cave-density layer.")
|
||||
@Data
|
||||
public class IrisCaveFieldModule {
|
||||
@Description("Density style used by this module.")
|
||||
private IrisGeneratorStyle style = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Layer contribution multiplier.")
|
||||
private double weight = 1;
|
||||
|
||||
@MinNumber(-1)
|
||||
@MaxNumber(1)
|
||||
@Description("Threshold offset applied to this layer before blending.")
|
||||
private double threshold = 0;
|
||||
|
||||
@Description("Vertical bounds where this module can contribute, in engine-local Y where 0 is the bottom of the dimension, not world Y.")
|
||||
private IrisRange verticalRange = new IrisRange(0, 384);
|
||||
|
||||
@Description("Invert this module before weighting.")
|
||||
private boolean invert = false;
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.ArrayType;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("cave-profile")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Description("Represents a configurable 3D cave profile.")
|
||||
@Data
|
||||
public class IrisCaveProfile {
|
||||
@Description("Enable profile-driven cave carving.")
|
||||
private boolean enabled = false;
|
||||
|
||||
@Description("Global vertical bounds for profile cave carving, in engine-local Y where 0 is the bottom of the dimension, not world Y.")
|
||||
private IrisRange verticalRange = new IrisRange(0, 384);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@Description("Vertical fade range applied near cave profile min/max bounds to avoid abrupt hard-stop ceilings/floors.")
|
||||
private int verticalEdgeFade = 20;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Strength of the vertical edge fade at cave profile min/max bounds.")
|
||||
private double verticalEdgeFadeStrength = 0.18;
|
||||
|
||||
@Description("Base density style for cave field generation.")
|
||||
private IrisGeneratorStyle baseDensityStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
|
||||
|
||||
@Description("Detail density style blended into base caves.")
|
||||
private IrisGeneratorStyle detailDensityStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
|
||||
|
||||
@Description("Warp style used to distort cave coordinates.")
|
||||
private IrisGeneratorStyle warpStyle = new IrisGeneratorStyle(NoiseStyle.FLAT);
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Base cave field multiplier.")
|
||||
private double baseWeight = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Detail cave field multiplier.")
|
||||
private double detailWeight = 0.35;
|
||||
|
||||
@MinNumber(0)
|
||||
@Description("Coordinate warp strength for cave fields.")
|
||||
private double warpStrength = 0;
|
||||
|
||||
@Description("Threshold range used for carve cutoff decisions.")
|
||||
private IrisStyledRange densityThreshold = new IrisStyledRange(-0.2, 0.2, NoiseStyle.CELLULAR_IRIS_DOUBLE.style());
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Extra threshold bias subtracted from sampled threshold before carve tests.")
|
||||
private double thresholdBias = 0.16;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@Description("Vertical sample step used while evaluating cave density.")
|
||||
private int sampleStep = 1;
|
||||
|
||||
@Description("Use adaptive cave density prediction so only threshold-adjacent cells fall back to full-resolution evaluation.")
|
||||
private boolean adaptiveSampling = true;
|
||||
|
||||
@MinNumber(2)
|
||||
@MaxNumber(4)
|
||||
@Description("Horizontal adaptive predictor tuning. The carver always samples the predictor grid at a fixed step of 8; values below 8 only widen the ambiguity margin slightly and do not tighten the grid.")
|
||||
private int adaptiveSampleStep = 2;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Additional adaptive ambiguity margin used before the cave predictor falls back to exact sampling.")
|
||||
private double adaptiveThresholdMargin = 0.04;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Description("Minimum solid clearance below terrain surface where carving may occur.")
|
||||
private int surfaceClearance = 4;
|
||||
|
||||
@Description("Allow profile-driven cave carving to break through terrain surface in selected columns.")
|
||||
private boolean allowSurfaceBreak = true;
|
||||
|
||||
@Description("Noise style used to decide where surface-breaking cave columns are allowed.")
|
||||
private IrisGeneratorStyle surfaceBreakStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX).zoomed(0.08);
|
||||
|
||||
@MinNumber(-1)
|
||||
@MaxNumber(1)
|
||||
@Description("Minimum signed surface-break noise value required before near-surface carving is allowed.")
|
||||
private double surfaceBreakNoiseThreshold = 0.62;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Description("Near-surface depth window used for surface-break carve logic.")
|
||||
private int surfaceBreakDepth = 18;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Description("Additional threshold boost applied while carving in the surface-break depth window.")
|
||||
private double surfaceBreakThresholdBoost = 0.2;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Description("Minimum depth below terrain surface required for cave-only object anchor placement.")
|
||||
private int objectMinDepthBelowSurface = 6;
|
||||
|
||||
@ArrayType(type = IrisCaveFieldModule.class, min = 1)
|
||||
@Description("Additional layered cave-density modules.")
|
||||
private KList<IrisCaveFieldModule> modules = new KList<>();
|
||||
|
||||
@Description("Default cave anchor mode for cave-only object placement.")
|
||||
private IrisCaveAnchorMode defaultObjectAnchor = IrisCaveAnchorMode.FLOOR;
|
||||
|
||||
@Description("Default placement mode for cave objects. Only applies to placements that are still on the default CENTER_HEIGHT mode; an explicit mode on the placement always wins. Stilt modes tile the object base block down to the cave floor surface. FAST_MIN_STILT is recommended for cave objects to prevent floating.")
|
||||
private ObjectPlaceMode defaultObjectPlaceMode = null;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@Description("Vertical scan step used while searching cave anchors.")
|
||||
private int anchorScanStep = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("Maximum random column retries while searching a valid cave object anchor in the chunk.")
|
||||
private int anchorSearchAttempts = 6;
|
||||
|
||||
@Description("Allow cave fluid placement from the dimension fluid palette below fluid level.")
|
||||
private boolean allowFluid = true;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Description("Minimum depth below terrain surface required before cave fluid may be placed.")
|
||||
private int fluidMinDepthBelowSurface = 12;
|
||||
|
||||
@Description("Require solid floor support below cave fluid to reduce unsupported fluid flows.")
|
||||
private boolean fluidRequiresFloor = true;
|
||||
|
||||
@Description("Allow cave lava placement based on lava height.")
|
||||
private boolean allowLava = true;
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class IrisCaveProfileSampler {
|
||||
private static final double FLOATING_THRESHOLD_BIAS_SCALE = 0.2D;
|
||||
|
||||
private final IrisCaveProfile profile;
|
||||
private final CNG baseDensity;
|
||||
private final CNG detailDensity;
|
||||
private final CNG warpDensity;
|
||||
private final CNG thresholdDensity;
|
||||
private final double thresholdMin;
|
||||
private final double thresholdMax;
|
||||
private final double constantThreshold;
|
||||
private final boolean thresholdHasNoise;
|
||||
private final ModuleState[] modules;
|
||||
private final double inverseNormalization;
|
||||
private final double baseWeight;
|
||||
private final double detailWeight;
|
||||
private final double warpStrength;
|
||||
private final boolean enabled;
|
||||
private final boolean hasWarp;
|
||||
private final boolean hasModules;
|
||||
|
||||
public IrisCaveProfileSampler(Engine engine, IrisCaveProfile profile) {
|
||||
IrisData data = engine.getData();
|
||||
this.profile = profile;
|
||||
List<ModuleState> moduleStates = new ArrayList<>();
|
||||
RNG baseRng = new RNG(engine.getSeedManager().getCarve());
|
||||
this.baseDensity = profile.getBaseDensityStyle().create(baseRng.nextParallelRNG(934_447), data);
|
||||
this.detailDensity = profile.getDetailDensityStyle().create(baseRng.nextParallelRNG(612_991), data);
|
||||
this.warpDensity = profile.getWarpStyle().create(baseRng.nextParallelRNG(770_713), data);
|
||||
IrisStyledRange threshold = profile.getDensityThreshold();
|
||||
thresholdMin = threshold.getMin();
|
||||
thresholdMax = threshold.getMax();
|
||||
thresholdHasNoise = thresholdMin != thresholdMax && !threshold.getStyle().isFlat();
|
||||
thresholdDensity = thresholdHasNoise ? threshold.getStyle().create(baseRng.nextParallelRNG(489_112), data) : null;
|
||||
constantThreshold = thresholdMin == thresholdMax ? thresholdMin : M.lerp(thresholdMin, thresholdMax, 0.5D);
|
||||
this.baseWeight = profile.getBaseWeight();
|
||||
this.detailWeight = profile.getDetailWeight();
|
||||
this.warpStrength = profile.getWarpStrength();
|
||||
this.hasWarp = warpStrength > 0D;
|
||||
|
||||
double weight = Math.abs(baseWeight) + Math.abs(detailWeight);
|
||||
int index = 0;
|
||||
for (IrisCaveFieldModule module : profile.getModules()) {
|
||||
CNG moduleDensity = module.getStyle().create(baseRng.nextParallelRNG(1_000_003L + (index * 65_537L)), data);
|
||||
ModuleState state = new ModuleState(module, moduleDensity);
|
||||
moduleStates.add(state);
|
||||
weight += Math.abs(state.weight);
|
||||
index++;
|
||||
}
|
||||
|
||||
this.modules = moduleStates.toArray(new ModuleState[0]);
|
||||
double normalization = weight <= 0 ? 1D : weight;
|
||||
this.inverseNormalization = 1D / normalization;
|
||||
this.hasModules = modules.length > 0;
|
||||
this.enabled = profile.isEnabled() && baseDensity != null && detailDensity != null && (!hasWarp || warpDensity != null);
|
||||
}
|
||||
|
||||
public boolean shouldCarve(int x, int y, int z, double floatingCarveThreshold) {
|
||||
if (!enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double threshold = (thresholdHasNoise ? thresholdDensity.fitDouble(thresholdMin, thresholdMax, x, z)
|
||||
: constantThreshold) - profile.getThresholdBias();
|
||||
threshold += floatingThresholdBias(floatingCarveThreshold);
|
||||
return sampleDensity(x, y, z) <= threshold;
|
||||
}
|
||||
|
||||
double sampleDensity(int x, int y, int z) {
|
||||
if (hasWarp) {
|
||||
return sampleDensityWarped(x, y, z);
|
||||
}
|
||||
|
||||
return sampleDensityUnwarped(x, y, z);
|
||||
}
|
||||
|
||||
private double sampleDensityUnwarped(int x, int y, int z) {
|
||||
double density = baseDensity.noiseFastSigned3D(x, y, z) * baseWeight;
|
||||
density += detailDensity.noiseFastSigned3D(x, y, z) * detailWeight;
|
||||
if (hasModules) {
|
||||
for (ModuleState module : modules) {
|
||||
if (!module.isActive(y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
density += module.sample(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
return density * inverseNormalization;
|
||||
}
|
||||
|
||||
private double sampleDensityWarped(int x, int y, int z) {
|
||||
double warpA = warpDensity.noiseFastSigned3D(x, y, z);
|
||||
double warpB = warpDensity.noiseFastSigned3D(x + 31.37D, y - 17.21D, z + 23.91D);
|
||||
double warpedX = x + (warpA * warpStrength);
|
||||
double warpedY = y + (warpB * warpStrength);
|
||||
double warpedZ = z + ((warpA - warpB) * 0.5D * warpStrength);
|
||||
double density = baseDensity.noiseFastSigned3D(warpedX, warpedY, warpedZ) * baseWeight;
|
||||
density += detailDensity.noiseFastSigned3D(warpedX, warpedY, warpedZ) * detailWeight;
|
||||
if (hasModules) {
|
||||
for (ModuleState module : modules) {
|
||||
if (!module.isActive(y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
density += module.sample(warpedX, warpedY, warpedZ);
|
||||
}
|
||||
}
|
||||
|
||||
return density * inverseNormalization;
|
||||
}
|
||||
|
||||
private double floatingThresholdBias(double floatingCarveThreshold) {
|
||||
double clamped = Math.max(0D, Math.min(1D, floatingCarveThreshold));
|
||||
return (1D - clamped) * FLOATING_THRESHOLD_BIAS_SCALE;
|
||||
}
|
||||
|
||||
private static final class ModuleState {
|
||||
private final CNG density;
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final double weight;
|
||||
private final double threshold;
|
||||
private final boolean invert;
|
||||
|
||||
private ModuleState(IrisCaveFieldModule module, CNG density) {
|
||||
IrisRange range = module.getVerticalRange();
|
||||
this.density = density;
|
||||
this.minY = (int) Math.floor(range.getMin());
|
||||
this.maxY = (int) Math.ceil(range.getMax());
|
||||
this.weight = module.getWeight();
|
||||
this.threshold = module.getThreshold();
|
||||
this.invert = module.isInvert();
|
||||
}
|
||||
|
||||
private boolean isActive(int y) {
|
||||
return density != null && y >= minY && y <= maxY;
|
||||
}
|
||||
|
||||
private double sample(double x, double y, double z) {
|
||||
double sampled = density.noiseFastSigned3D(x, y, z);
|
||||
return invert ? (threshold - sampled) * weight : (sampled - threshold) * weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* Where a cave holds pockets of the dimension's fluid: a smooth noise read above a cutoff that rises towards the
|
||||
* fluid height, so pockets fill the deepest parts of a cave first. The noise is stretched to twice its horizontal
|
||||
* size vertically, the way the caves this replaces read theirs.
|
||||
*/
|
||||
public final class AquiferPockets {
|
||||
/** The spacing of the pockets' noise horizontally, in blocks: the SIMPLEX style at zoom 1. */
|
||||
private static final double POCKET_SPACING_BLOCKS = 52.6D;
|
||||
private static final double POCKET_VERTICAL_SPACING_BLOCKS = POCKET_SPACING_BLOCKS * 2D;
|
||||
private static final double CUTOFF_AT_FLUID_HEIGHT = 0.35D;
|
||||
private static final double CUTOFF_RISE_PER_DEPTH_SPAN = 0.2D;
|
||||
private static final double DEPTH_SPAN_BLOCKS = 48D;
|
||||
private static final double MOST_DEPTH_SPANS = 1.5D;
|
||||
private static final String NOISE_NAME = "aquifer.pockets";
|
||||
|
||||
private final Field3 pockets;
|
||||
|
||||
public AquiferPockets(NoiseFactory noise, long seed) {
|
||||
this.pockets = new CaveNoise(noise, seed).named(NOISE_NAME).smooth(POCKET_SPACING_BLOCKS, POCKET_VERTICAL_SPACING_BLOCKS);
|
||||
}
|
||||
|
||||
/** Whether the block at height {@code y} below fluid height {@code fluidHeight} lies in a pocket of fluid. */
|
||||
public boolean holdsFluidAt(int x, int y, int z, int fluidHeight) {
|
||||
double depthSpans = Math.max(0D, Math.min(MOST_DEPTH_SPANS, (fluidHeight - y) / DEPTH_SPAN_BLOCKS));
|
||||
double cutoff = CUTOFF_AT_FLUID_HEIGHT + (depthSpans * CUTOFF_RISE_PER_DEPTH_SPAN);
|
||||
return pockets.at(x, y, z) > cutoff;
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -16,11 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.map;
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* The block columns a stretch of terrain is sampled at: {@code columns} by {@code rows} from the origin, each
|
||||
* {@code step} blocks wide and deep. Heights stay in blocks whatever the step.
|
||||
*/
|
||||
record TerrainGrid(int originX, int originZ, int columns, int rows, int step) {
|
||||
/** Takes the blocks a cave shape carves in a chunk, by their place in the chunk and their height above the dimension's bottom. */
|
||||
@FunctionalInterface
|
||||
public interface CarveSink {
|
||||
void carve(int localX, int y, int localZ);
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveDepth;
|
||||
import art.arcane.iris.generation.cave.CaveValue;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.cave.field.CaveLimits.Columns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* One cave of a pack, ready to carve chunks of one world: its shapes with their noise built for the world's seed, and
|
||||
* the heights it may carve at. Heights count from the dimension's bottom. Safe to use from several threads at once.
|
||||
*/
|
||||
public final class CaveCarver {
|
||||
/** Caves stay this far above the dimension's bottom, clear of the bedrock floor. */
|
||||
private static final int ROCK_KEPT_ABOVE_BOTTOM_BLOCKS = 5;
|
||||
private static final int SEED_MIX_PER_CAVE_KEY = 31;
|
||||
|
||||
private final List<PartShape> shapes = new ArrayList<>();
|
||||
private final int worldBottomY;
|
||||
private final int worldHeight;
|
||||
private final ValueField depthMin;
|
||||
private final ValueField depthMax;
|
||||
private final ValueField fade;
|
||||
private final ValueField surfaceClearance;
|
||||
private final ValueField ceilingFade;
|
||||
private final boolean opensToSurface;
|
||||
|
||||
/**
|
||||
* @param seed the seed of this cave in this world; two caves with the same settings and seed carve the same
|
||||
* @param worldBottomY world Y of the dimension's lowest block
|
||||
* @param worldHeight the dimension's height in blocks
|
||||
*/
|
||||
public CaveCarver(IrisCave cave, NoiseFactory noise, long seed, int worldBottomY, int worldHeight) {
|
||||
CaveNoise caveNoise = new CaveNoise(noise, seed);
|
||||
this.worldBottomY = worldBottomY;
|
||||
this.worldHeight = worldHeight;
|
||||
CaveDepth depth = cave.depth().orElse(null);
|
||||
this.depthMin = depth == null ? ValueField.constant(worldBottomY) : caveValue(depth.min(), caveNoise, "depth.min");
|
||||
this.depthMax = depth == null ? ValueField.constant(worldBottomY + worldHeight - 1) : caveValue(depth.max(), caveNoise, "depth.max");
|
||||
this.fade = caveValue(cave.fade(), caveNoise, "fade");
|
||||
this.surfaceClearance = caveValue(cave.surfaceClearance(), caveNoise, "surfaceClearance");
|
||||
this.ceilingFade = caveValue(cave.ceilingFade(), caveNoise, "ceilingFade");
|
||||
this.opensToSurface = cave.opensToSurface();
|
||||
cave.tunnel().ifPresent(tunnel -> shapes.add(new PartShape(CavePart.TUNNEL, new TunnelShape(caveNoise, tunnel))));
|
||||
cave.cavern().ifPresent(cavern -> shapes.add(new PartShape(CavePart.CAVERN, new CavernShape(caveNoise, cavern))));
|
||||
}
|
||||
|
||||
private static ValueField caveValue(CaveValue value, CaveNoise caveNoise, String name) {
|
||||
return ValueField.inColumns(value, caveNoise, name, IrisCave.VALUE_CHANGE_BLOCKS);
|
||||
}
|
||||
|
||||
/** The seed the cave filed under {@code caveKey} carves with in a world whose carve seed is {@code carveSeed}. */
|
||||
public static long seedOf(long carveSeed, String caveKey) {
|
||||
return carveSeed + (SEED_MIX_PER_CAVE_KEY * (long) caveKey.hashCode());
|
||||
}
|
||||
|
||||
public boolean opensToSurface() {
|
||||
return opensToSurface;
|
||||
}
|
||||
|
||||
/** Which parts the cave has, in the order it carves them. */
|
||||
public List<CavePart> parts() {
|
||||
return shapes.stream().map(PartShape::part).toList();
|
||||
}
|
||||
|
||||
/** {@link #carve}, telling the sink which part carved each block. A block two parts carve is reported for each. */
|
||||
public void carveByPart(int originX, int originZ, int[] surfaceY, double[] columnWeight, boolean[] sealed, PartSink sink) {
|
||||
carveByPart(originX, originZ, new ChunkColumns(surfaceY, columnWeight, sealed, null), HeightBand.UNLIMITED, sink);
|
||||
}
|
||||
|
||||
/** Takes the blocks a cave carves, with the part that carved each. */
|
||||
@FunctionalInterface
|
||||
public interface PartSink {
|
||||
void carve(CavePart part, int localX, int y, int localZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a chunk's columns allow the cave, indexed as {@code (localX << 4) | localZ}.
|
||||
*
|
||||
* @param surfaceY the height of the surface in each column
|
||||
* @param weight how much each column lists this cave, from 0 to 1
|
||||
* @param sealed columns whose surface the cave must not cut through, even if it opens to the surface
|
||||
* @param topLimitY the highest height the cave may carve in each column, where something else caps it, such as the
|
||||
* ceiling of a cave pool; the cave closes under the cap like it does under the rock it keeps. Null for no caps
|
||||
* @param depthRange which heights the cave carves at
|
||||
*/
|
||||
public record ChunkColumns(int[] surfaceY, double[] weight, boolean[] sealed, int[] topLimitY, DepthRange depthRange) {
|
||||
public ChunkColumns(int[] surfaceY, double[] weight, boolean[] sealed, int[] topLimitY) {
|
||||
this(surfaceY, weight, sealed, topLimitY, DepthRange.OWN);
|
||||
}
|
||||
}
|
||||
|
||||
private record PartShape(CavePart part, LatticeShape shape) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Carves the chunk whose first block is {@code originX}, {@code originZ}. Columns are indexed as
|
||||
* {@code (localX << 4) | localZ}.
|
||||
*
|
||||
* @param surfaceY the height of the surface in each column
|
||||
* @param columnWeight how much each column lists this cave, from 0 to 1
|
||||
* @param sealed columns whose surface the cave must not cut through, even if it opens to the surface
|
||||
*/
|
||||
public void carve(int originX, int originZ, int[] surfaceY, double[] columnWeight, boolean[] sealed, CarveSink sink) {
|
||||
carve(originX, originZ, new ChunkColumns(surfaceY, columnWeight, sealed, null), HeightBand.UNLIMITED, sink);
|
||||
}
|
||||
|
||||
/** {@link #carve} within {@code band}, with the caps and seals of {@code columns}. */
|
||||
public void carve(int originX, int originZ, ChunkColumns columns, HeightBand band, CarveSink sink) {
|
||||
carveByPart(originX, originZ, columns, band, (part, localX, y, localZ) -> sink.carve(localX, y, localZ));
|
||||
}
|
||||
|
||||
private void carveByPart(int originX, int originZ, ChunkColumns columns, HeightBand band, PartSink sink) {
|
||||
if (shapes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CaveLimits limits = limitsOf(originX, originZ, columns, band);
|
||||
if (limits.carvesNothing()) {
|
||||
return;
|
||||
}
|
||||
ChunkLattice lattice = ChunkLattice.covering(originX, originZ, limits.lowestY(), limits.highestY());
|
||||
for (PartShape shape : shapes) {
|
||||
shape.shape().carve(lattice, limits, (localX, y, localZ) -> sink.carve(shape.part(), localX, y, localZ));
|
||||
}
|
||||
}
|
||||
|
||||
private CaveLimits limitsOf(int originX, int originZ, ChunkColumns chunk, HeightBand band) {
|
||||
Columns columns = Columns.of(chunk.weight());
|
||||
fillBlocks(fade, originX, originZ, columns.fadeBlocks());
|
||||
fillBlocks(ceilingFade, originX, originZ, columns.ceilingFadeBlocks());
|
||||
boolean wholeDimension = chunk.depthRange() == DepthRange.WHOLE_DIMENSION;
|
||||
boolean depthVaries = !wholeDimension && (depthMin.varies() || depthMax.varies());
|
||||
int constantClearance = surfaceClearanceAt(originX, originZ);
|
||||
int constantDepthMinY = wholeDimension ? ROCK_KEPT_ABOVE_BOTTOM_BLOCKS : depthMinYAt(originX, originZ);
|
||||
int constantDepthMaxY = wholeDimension ? worldHeight - 1 : depthMaxYAt(originX, originZ);
|
||||
for (int column = 0; column < CaveLimits.CHUNK_COLUMNS; column++) {
|
||||
double x = originX + (column >> 4);
|
||||
double z = originZ + (column & 15);
|
||||
columns.depthMinY()[column] = depthVaries ? depthMinYAt(x, z) : constantDepthMinY;
|
||||
columns.depthMaxY()[column] = depthVaries ? depthMaxYAt(x, z) : constantDepthMaxY;
|
||||
int clearance = surfaceClearance.varies() ? surfaceClearanceAt(x, z) : constantClearance;
|
||||
boolean opens = opensToSurface && !chunk.sealed()[column];
|
||||
int topY = opens ? chunk.surfaceY()[column] : chunk.surfaceY()[column] - clearance;
|
||||
if (chunk.topLimitY() != null && chunk.topLimitY()[column] < topY) {
|
||||
topY = chunk.topLimitY()[column];
|
||||
opens = false;
|
||||
}
|
||||
columns.opensToSurface()[column] = opens;
|
||||
columns.topY()[column] = topY;
|
||||
}
|
||||
return new CaveLimits(columns, band);
|
||||
}
|
||||
|
||||
/** Fills {@code blocks} with the value in each column of the chunk, at least 0. */
|
||||
private static void fillBlocks(ValueField value, int originX, int originZ, double[] blocks) {
|
||||
if (!value.varies()) {
|
||||
Arrays.fill(blocks, Math.max(0D, value.min()));
|
||||
return;
|
||||
}
|
||||
for (int column = 0; column < CaveLimits.CHUNK_COLUMNS; column++) {
|
||||
blocks[column] = Math.max(0D, value.at(originX + (column >> 4), originZ + (column & 15)));
|
||||
}
|
||||
}
|
||||
|
||||
private int depthMinYAt(double x, double z) {
|
||||
double lowest = Math.min(depthMin.at(x, z), depthMax.at(x, z));
|
||||
return Math.max(ROCK_KEPT_ABOVE_BOTTOM_BLOCKS, (int) Math.floor(lowest) - worldBottomY);
|
||||
}
|
||||
|
||||
private int depthMaxYAt(double x, double z) {
|
||||
double highest = Math.max(depthMin.at(x, z), depthMax.at(x, z));
|
||||
return Math.min(worldHeight - 1, (int) Math.ceil(highest) - worldBottomY);
|
||||
}
|
||||
|
||||
private int surfaceClearanceAt(double x, double z) {
|
||||
return (int) Math.round(Math.max(0D, surfaceClearance.at(x, z)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Where one cave may carve in one chunk, and how freely: fully inside its depth range and well under the surface,
|
||||
* narrowing to nothing towards the ends of the range, towards the rock it keeps under the surface and towards columns
|
||||
* that do not list it. Columns are indexed as {@code (localX << 4) | localZ}; heights count from the dimension's bottom.
|
||||
*/
|
||||
final class CaveLimits {
|
||||
static final int CHUNK_COLUMNS = 256;
|
||||
private static final int CELL_COLUMNS = ChunkLattice.CELLS_PER_CHUNK_AXIS * ChunkLattice.CELLS_PER_CHUNK_AXIS;
|
||||
|
||||
private final int[] depthMinYs;
|
||||
private final int[] depthMaxYs;
|
||||
private final double[] fadeBlocks;
|
||||
private final double[] ceilingFadeBlocks;
|
||||
private final int[] topY;
|
||||
private final boolean[] opensToSurface;
|
||||
private final double[] weight;
|
||||
/** Whether depth and fades are the same in every column, as they are for plain numbers; then they are read once. */
|
||||
private final boolean sameRangeInEveryColumn;
|
||||
private final int depthMinY;
|
||||
private final int depthMaxY;
|
||||
private final double fade;
|
||||
private final double ceilingFade;
|
||||
private final int lowestY;
|
||||
private final int highestY;
|
||||
private final int[] cellTopY = new int[CELL_COLUMNS];
|
||||
private final boolean[] cellHasWeight = new boolean[CELL_COLUMNS];
|
||||
|
||||
/**
|
||||
* What the cave allows in each column of the chunk.
|
||||
*
|
||||
* @param depthMinY lowest height of the cave's depth range
|
||||
* @param depthMaxY highest height of the cave's depth range
|
||||
* @param fadeBlocks blocks over which the cave narrows at both ends of the range
|
||||
* @param topY highest height the cave may carve
|
||||
* @param opensToSurface whether the cave reaches its top at full width, instead of closing under it
|
||||
* @param ceilingFadeBlocks blocks over which a cave that does not open to the surface closes under its top
|
||||
* @param weight how much the column lists the cave, from 0 to 1
|
||||
*/
|
||||
record Columns(int[] depthMinY, int[] depthMaxY, double[] fadeBlocks, int[] topY, boolean[] opensToSurface,
|
||||
double[] ceilingFadeBlocks, double[] weight) {
|
||||
static Columns of(double[] weight) {
|
||||
return new Columns(new int[CHUNK_COLUMNS], new int[CHUNK_COLUMNS], new double[CHUNK_COLUMNS], new int[CHUNK_COLUMNS],
|
||||
new boolean[CHUNK_COLUMNS], new double[CHUNK_COLUMNS], weight);
|
||||
}
|
||||
}
|
||||
|
||||
CaveLimits(Columns columns, HeightBand band) {
|
||||
this.depthMinYs = columns.depthMinY();
|
||||
this.depthMaxYs = columns.depthMaxY();
|
||||
this.fadeBlocks = columns.fadeBlocks();
|
||||
this.ceilingFadeBlocks = columns.ceilingFadeBlocks();
|
||||
this.topY = columns.topY();
|
||||
this.opensToSurface = columns.opensToSurface();
|
||||
this.weight = columns.weight();
|
||||
this.sameRangeInEveryColumn = isTheSameInEveryColumn(depthMinYs) && isTheSameInEveryColumn(depthMaxYs)
|
||||
&& isTheSameInEveryColumn(fadeBlocks) && isTheSameInEveryColumn(ceilingFadeBlocks);
|
||||
this.depthMinY = depthMinYs[0];
|
||||
this.depthMaxY = depthMaxYs[0];
|
||||
this.fade = fadeBlocks[0];
|
||||
this.ceilingFade = ceilingFadeBlocks[0];
|
||||
Arrays.fill(cellTopY, Integer.MIN_VALUE);
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (int column = 0; column < CHUNK_COLUMNS; column++) {
|
||||
if (columns.weight()[column] <= 0D) {
|
||||
continue;
|
||||
}
|
||||
int cell = cellOf(column >> 4, column & 15);
|
||||
cellHasWeight[cell] = true;
|
||||
cellTopY[cell] = Math.max(cellTopY[cell], topY[column]);
|
||||
lowest = Math.min(lowest, depthMinYs[column]);
|
||||
highest = Math.max(highest, Math.min(depthMaxYs[column], topY[column]));
|
||||
}
|
||||
this.lowestY = Math.max(lowest, band.lowestY());
|
||||
this.highestY = Math.min(highest, band.highestY());
|
||||
}
|
||||
|
||||
private static int cellOf(int localX, int localZ) {
|
||||
return ((localX / ChunkLattice.CELL_BLOCKS) * ChunkLattice.CELLS_PER_CHUNK_AXIS) + (localZ / ChunkLattice.CELL_BLOCKS);
|
||||
}
|
||||
|
||||
int lowestY() {
|
||||
return lowestY;
|
||||
}
|
||||
|
||||
int highestY() {
|
||||
return highestY;
|
||||
}
|
||||
|
||||
/** Whether the cave carves nothing in this chunk. */
|
||||
boolean carvesNothing() {
|
||||
return highestY < lowestY;
|
||||
}
|
||||
|
||||
/** Whether no column of the cell lets the cave carve at or above {@code bottomY}. */
|
||||
boolean cellIsClosed(int cellX, int cellZ, int bottomY) {
|
||||
int cell = (cellX * ChunkLattice.CELLS_PER_CHUNK_AXIS) + cellZ;
|
||||
return !cellHasWeight[cell] || cellTopY[cell] < bottomY;
|
||||
}
|
||||
|
||||
/** How freely the cave carves the block, from 0 (not at all) to 1 (at its full size). */
|
||||
double openness(int column, int y) {
|
||||
if (sameRangeInEveryColumn) {
|
||||
return openness(column, y, depthMinY, depthMaxY, fade, ceilingFade);
|
||||
}
|
||||
return openness(column, y, depthMinYs[column], depthMaxYs[column], fadeBlocks[column], ceilingFadeBlocks[column]);
|
||||
}
|
||||
|
||||
private double openness(int column, int y, int columnDepthMinY, int columnDepthMaxY, double columnFade, double columnCeilingFade) {
|
||||
double columnWeight = weight[column];
|
||||
if (columnWeight <= 0D || y < columnDepthMinY || y > columnDepthMaxY) {
|
||||
return 0D;
|
||||
}
|
||||
int belowTop = topY[column] - y;
|
||||
if (belowTop < 0) {
|
||||
return 0D;
|
||||
}
|
||||
double openness = columnWeight * easeIn(Math.min(y - columnDepthMinY, columnDepthMaxY - y), columnFade);
|
||||
if (!opensToSurface[column]) {
|
||||
openness *= easeIn(belowTop, columnCeilingFade);
|
||||
}
|
||||
return openness;
|
||||
}
|
||||
|
||||
private static boolean isTheSameInEveryColumn(int[] values) {
|
||||
for (int column = 1; column < values.length; column++) {
|
||||
if (values[column] != values[0]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isTheSameInEveryColumn(double[] values) {
|
||||
for (int column = 1; column < values.length; column++) {
|
||||
if (values[column] != values[0]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double easeIn(int distance, double fadeBlocks) {
|
||||
if (fadeBlocks <= 0D || distance >= fadeBlocks) {
|
||||
return 1D;
|
||||
}
|
||||
double share = distance / fadeBlocks;
|
||||
return share * share * (3D - (2D * share));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
|
||||
/**
|
||||
* Builds the noise fields of cave shapes, sized in blocks instead of in a noise style's zoom. Every field takes the
|
||||
* next seed of the cave, whichever way it is built, so changing how one field is built leaves the others alone.
|
||||
*/
|
||||
final class CaveNoise {
|
||||
/** Measured on the SIMPLEX style at zoom 1: the mean distance in blocks between two sign changes along a line. */
|
||||
private static final double SIMPLEX_ZERO_SPACING_BLOCKS = 52.6D;
|
||||
/** Measured on the same style: how much its value typically changes per block, times the spacing above. */
|
||||
private static final double SIMPLEX_SLOPE_TIMES_SPACING = 2.43D;
|
||||
/** The features of a field's finer second layer are this much smaller than its own. */
|
||||
private static final double DETAIL_SHRINK = 2.7D;
|
||||
/** Below this size a detail layer is finer than the sampling lattice can carry. */
|
||||
private static final double MIN_DETAIL_SPACING_BLOCKS = 12D;
|
||||
/** A pack style is rescaled until its measured feature spacing is within this share of the one asked for. */
|
||||
private static final double SCALING_TOLERANCE = 0.1D;
|
||||
private static final int MOST_SCALING_ROUNDS = 6;
|
||||
private static final long NAME_SEED_MIX = 0x9E3779B97F4A7C15L;
|
||||
private static final Field3 LEVEL = (x, y, z) -> 0D;
|
||||
|
||||
private final NoiseFactory noise;
|
||||
private final long seed;
|
||||
private int fieldsBuilt;
|
||||
|
||||
CaveNoise(NoiseFactory noise, long seed) {
|
||||
this.noise = noise;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The fields of one named value of the cave, seeded by the name: a value that varies takes no seed from the
|
||||
* cave's own fields, so writing a range anywhere leaves every other field of the cave where it was.
|
||||
*/
|
||||
CaveNoise named(String name) {
|
||||
return new CaveNoise(noise, seed ^ (name.hashCode() * NAME_SEED_MIX));
|
||||
}
|
||||
|
||||
/** How much a field with this spacing typically changes over one block. */
|
||||
static double typicalSlope(double spacing) {
|
||||
return SIMPLEX_SLOPE_TIMES_SPACING / spacing;
|
||||
}
|
||||
|
||||
/** A field whose sign changes about every {@code spacing} blocks horizontally and {@code verticalSpacing} vertically. */
|
||||
Field3 smooth(double spacing, double verticalSpacing) {
|
||||
NoiseSampler sampler = nextSampler(simplexStyle());
|
||||
double horizontal = SIMPLEX_ZERO_SPACING_BLOCKS / spacing;
|
||||
double vertical = SIMPLEX_ZERO_SPACING_BLOCKS / verticalSpacing;
|
||||
return (x, y, z) -> sampler.signed(x * horizontal, y * vertical, z * horizontal);
|
||||
}
|
||||
|
||||
/** {@link #smooth} with a finer layer of {@code detailWeight} times its strength on top, where the lattice can carry one. */
|
||||
Field3 detailed(double spacing, double verticalSpacing, double detailWeight) {
|
||||
Field3 base = smooth(spacing, verticalSpacing);
|
||||
double detailSpacing = spacing / DETAIL_SHRINK;
|
||||
double detailVerticalSpacing = verticalSpacing / DETAIL_SHRINK;
|
||||
if (Math.min(detailSpacing, detailVerticalSpacing) < MIN_DETAIL_SPACING_BLOCKS) {
|
||||
return base;
|
||||
}
|
||||
Field3 detail = smooth(detailSpacing, detailVerticalSpacing);
|
||||
double normalization = 1D / (1D + detailWeight);
|
||||
return (x, y, z) -> (base.at(x, y, z) + (detail.at(x, y, z) * detailWeight)) * normalization;
|
||||
}
|
||||
|
||||
/** {@link #detailed} with a detail weight that may vary from place to place. */
|
||||
Field3 detailed(double spacing, double verticalSpacing, ValueField detailWeight) {
|
||||
if (!detailWeight.varies()) {
|
||||
return detailed(spacing, verticalSpacing, detailWeight.min());
|
||||
}
|
||||
Field3 base = smooth(spacing, verticalSpacing);
|
||||
double detailSpacing = spacing / DETAIL_SHRINK;
|
||||
double detailVerticalSpacing = verticalSpacing / DETAIL_SHRINK;
|
||||
if (Math.min(detailSpacing, detailVerticalSpacing) < MIN_DETAIL_SPACING_BLOCKS) {
|
||||
return base;
|
||||
}
|
||||
Field3 detail = smooth(detailSpacing, detailVerticalSpacing);
|
||||
return (x, y, z) -> {
|
||||
double weight = detailWeight.at(x, y, z);
|
||||
return (base.at(x, y, z) + (detail.at(x, y, z) * weight)) / (1D + weight);
|
||||
};
|
||||
}
|
||||
|
||||
/** A field that only varies over X and Z, changing sign about every {@code spacing} blocks. */
|
||||
Field3 columns(double spacing) {
|
||||
NoiseSampler sampler = nextSampler(simplexStyle());
|
||||
double scale = SIMPLEX_ZERO_SPACING_BLOCKS / spacing;
|
||||
return (x, y, z) -> sampler.signed(x * scale, z * scale);
|
||||
}
|
||||
|
||||
/** A pack's style read in blocks as the pack wrote it, its zoom included. A flat style gives a level field at 0. */
|
||||
Field3 inBlocks(IrisGeneratorStyle style) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = nextSampler(style);
|
||||
return sampler::signed;
|
||||
}
|
||||
|
||||
/** {@link #inBlocks} for a field that only varies over X and Z. */
|
||||
Field3 columnsInBlocks(IrisGeneratorStyle style) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = nextSampler(style);
|
||||
return (x, y, z) -> sampler.signed(x, z);
|
||||
}
|
||||
|
||||
/** A pack's style rescaled so its features lie about {@code spacing} blocks apart horizontally and {@code verticalSpacing} vertically. */
|
||||
Field3 scaledTo(IrisGeneratorStyle style, double spacing, double verticalSpacing) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = scaledToSpacing(nextSampler(style), style, spacing);
|
||||
double vertical = spacing / verticalSpacing;
|
||||
return (x, y, z) -> sampler.signed(x, y * vertical, z);
|
||||
}
|
||||
|
||||
/** {@link #scaledTo} for a field that only varies over X and Z. */
|
||||
Field3 columnsScaledTo(IrisGeneratorStyle style, double spacing) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = scaledToSpacing(nextSampler(style), style, spacing);
|
||||
return (x, y, z) -> sampler.signed(x, z);
|
||||
}
|
||||
|
||||
/** How far apart the features of {@code field}, read from {@code style} in blocks, roughly lie. */
|
||||
static double featureBlocks(Field3 field, IrisGeneratorStyle style) {
|
||||
double guess = simplexLikeFeatureBlocks(style.getZoom());
|
||||
return FieldStats.featureBlocks(field, guess).orElse(guess);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescales {@code sampler} until its measured feature spacing matches {@code spacing}, starting from where a style
|
||||
* built like SIMPLEX would land. The scale is folded into the noise, so a fracture still moves it in blocks.
|
||||
*/
|
||||
private static NoiseSampler scaledToSpacing(NoiseSampler sampler, IrisGeneratorStyle style, double spacing) {
|
||||
double factor = simplexLikeFeatureBlocks(style.getZoom()) / spacing;
|
||||
for (int round = 0; round < MOST_SCALING_ROUNDS; round++) {
|
||||
NoiseSampler scaled = sampler.scaled(factor);
|
||||
OptionalDouble measured = FieldStats.featureBlocks((x, y, z) -> scaled.signed(x, y, z), spacing);
|
||||
if (measured.isEmpty()) {
|
||||
return scaled;
|
||||
}
|
||||
double measuredShare = measured.getAsDouble() / spacing;
|
||||
if (Math.abs(measuredShare - 1D) <= SCALING_TOLERANCE) {
|
||||
return scaled;
|
||||
}
|
||||
factor *= measuredShare;
|
||||
}
|
||||
return sampler.scaled(factor);
|
||||
}
|
||||
|
||||
private static double simplexLikeFeatureBlocks(double zoom) {
|
||||
return SIMPLEX_ZERO_SPACING_BLOCKS * zoom;
|
||||
}
|
||||
|
||||
private static IrisGeneratorStyle simplexStyle() {
|
||||
return new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
|
||||
}
|
||||
|
||||
private NoiseSampler nextSampler(IrisGeneratorStyle style) {
|
||||
return noise.sampler(style, nextSeed());
|
||||
}
|
||||
|
||||
private long nextSeed() {
|
||||
fieldsBuilt++;
|
||||
return seed + (fieldsBuilt * 1_000_003L);
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.map;
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* A rectangle of a terrain's columns and rows, from the first up to but not including the last.
|
||||
*/
|
||||
record ColumnArea(int fromColumn, int fromRow, int toColumn, int toRow) {
|
||||
/** The shapes a cave is made of, in the order a cave carves them. */
|
||||
public enum CavePart {
|
||||
TUNNEL,
|
||||
CAVERN
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveCavern;
|
||||
import art.arcane.iris.generation.cave.CavePillars;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
|
||||
/**
|
||||
* Caverns: the rooms where one slow field rises above a threshold. Pillars stand where a second field peaks: there the
|
||||
* room has to be more open to be carved, so a pillar widens towards floor and ceiling, where the room is least open.
|
||||
* The pillar field varies only across X and Z unless the pack lets pillars change with height; then it is read in 3D
|
||||
* on the lattice, and a pillar whose field fades out mid-room narrows and breaks off, leaving stubs that flare into
|
||||
* floor and ceiling.
|
||||
*
|
||||
* <p>A value that varies moves the threshold it sets point by point: the lattice then carries the room field less its
|
||||
* threshold, and the pillar thresholds, so blocks interpolate them like any field. A plain number keeps them constant.
|
||||
*/
|
||||
final class CavernShape extends LatticeShape {
|
||||
private static final int ROOMS = 0;
|
||||
private static final int NOT_READ = -1;
|
||||
/** A room is the part of a feature above the threshold, which is narrower than the feature itself. */
|
||||
private static final double FEATURE_BLOCKS_PER_ROOM_BLOCK = 1.6D;
|
||||
/** Closing a cavern takes a little more than its most open spot, so nothing is left at the very edge of its limits. */
|
||||
private static final double CLOSING_MARGIN = 1.1D;
|
||||
/** Pillars are two features apart: one peak, one trough. */
|
||||
private static final double PILLAR_FEATURES_PER_SPACING = 0.5D;
|
||||
private static final double LARGEST_PILLAR_AREA_SHARE = 0.3D;
|
||||
private static final double NO_PILLAR = 0D;
|
||||
private static final double FULL_PILLAR = 1D;
|
||||
/** Where the threshold is worked out at the lattice points, a block subtracts nothing more. */
|
||||
private static final double THRESHOLD_WORKED_OUT_AT_POINTS = 0D;
|
||||
|
||||
private final Field3 rooms;
|
||||
private final FieldStats roomStats;
|
||||
private final ValueField coverage;
|
||||
private final double threshold;
|
||||
private final double mostOpen;
|
||||
private final Field3 pillars;
|
||||
private final boolean pillarsChangeWithHeight;
|
||||
private final FieldStats pillarStats;
|
||||
private final ValueField pillarSpacing;
|
||||
private final ValueField pillarThickness;
|
||||
private final ValueField pillarFlare;
|
||||
private final boolean pillarSizeVaries;
|
||||
private final double pillarMiddle;
|
||||
private final double pillarFoot;
|
||||
private final int mostOpenField;
|
||||
private final int pillarField;
|
||||
private final int pillarMiddleField;
|
||||
private final int pillarFootField;
|
||||
private final int fieldCount;
|
||||
|
||||
CavernShape(CaveNoise noise, CaveCavern cavern) {
|
||||
double valueChangeBlocks = cavern.size().middle() * CaveCavern.VALUE_CHANGE_SIZES;
|
||||
ValueField size = ValueField.inBlocks(cavern.size(), noise, "cavern.size", valueChangeBlocks);
|
||||
ValueField height = ValueField.inColumns(cavern.height(), noise, "cavern.height", valueChangeBlocks);
|
||||
ValueField roughness = ValueField.inBlocks(cavern.roughness(), noise, "cavern.roughness", valueChangeBlocks);
|
||||
this.coverage = ValueField.inBlocks(cavern.coverage(), noise, "cavern.coverage", valueChangeBlocks);
|
||||
this.rooms = roomField(noise, cavern, size, height, roughness);
|
||||
this.roomStats = FieldStats.measure(rooms, size.middle() * FEATURE_BLOCKS_PER_ROOM_BLOCK);
|
||||
this.threshold = coverage.varies() ? THRESHOLD_WORKED_OUT_AT_POINTS : roomStats.valueAboveShare(coverage.min());
|
||||
this.mostOpen = Math.max(0D, roomStats.highest() - threshold);
|
||||
int nextField = ROOMS + 1;
|
||||
this.mostOpenField = coverage.varies() ? nextField++ : NOT_READ;
|
||||
if (cavern.pillars().isEmpty()) {
|
||||
this.pillars = null;
|
||||
this.pillarsChangeWithHeight = false;
|
||||
this.pillarStats = null;
|
||||
this.pillarSpacing = null;
|
||||
this.pillarThickness = null;
|
||||
this.pillarFlare = null;
|
||||
this.pillarSizeVaries = false;
|
||||
this.pillarMiddle = Double.POSITIVE_INFINITY;
|
||||
this.pillarFoot = Double.POSITIVE_INFINITY;
|
||||
this.pillarField = NOT_READ;
|
||||
this.pillarMiddleField = NOT_READ;
|
||||
this.pillarFootField = NOT_READ;
|
||||
this.fieldCount = nextField;
|
||||
return;
|
||||
}
|
||||
CavePillars settings = cavern.pillars().get();
|
||||
this.pillarSpacing = ValueField.inColumns(settings.spacing(), noise, "cavern.pillars.spacing", valueChangeBlocks);
|
||||
this.pillarThickness = ValueField.inColumns(settings.thickness(), noise, "cavern.pillars.thickness", valueChangeBlocks);
|
||||
this.pillarFlare = ValueField.inColumns(settings.flare(), noise, "cavern.pillars.flare", valueChangeBlocks);
|
||||
this.pillarSizeVaries = pillarSpacing.varies() || pillarThickness.varies() || pillarFlare.varies();
|
||||
this.pillarsChangeWithHeight = settings.vertical().isPresent();
|
||||
ValueField vertical = settings.vertical()
|
||||
.map(value -> ValueField.inColumns(value, noise, "cavern.pillars.vertical", valueChangeBlocks))
|
||||
.orElseGet(() -> ValueField.constant(0D));
|
||||
this.pillars = pillarField(noise, settings, pillarSpacing, vertical);
|
||||
this.pillarStats = FieldStats.measure(pillars, pillarSpacing.middle() * PILLAR_FEATURES_PER_SPACING);
|
||||
this.pillarMiddle = pillarSizeVaries ? Double.NaN : pillarMiddleAt(0D, 0D);
|
||||
this.pillarFoot = pillarSizeVaries ? Double.NaN : pillarFootAt(0D, 0D);
|
||||
this.pillarField = pillarsChangeWithHeight ? nextField++ : NOT_READ;
|
||||
boolean thresholdsAtPoints = pillarsChangeWithHeight && pillarSizeVaries;
|
||||
this.pillarMiddleField = thresholdsAtPoints ? nextField++ : NOT_READ;
|
||||
this.pillarFootField = thresholdsAtPoints ? nextField++ : NOT_READ;
|
||||
this.fieldCount = nextField;
|
||||
}
|
||||
|
||||
private static Field3 roomField(CaveNoise noise, CaveCavern cavern, ValueField size, ValueField height, ValueField roughness) {
|
||||
IrisGeneratorStyle style = cavern.style().orElse(null);
|
||||
return VaryingScale.of(noise, size, height, "cavern.rooms", (fieldNoise, roomSize, roomHeight) -> {
|
||||
double span = roomSize * FEATURE_BLOCKS_PER_ROOM_BLOCK;
|
||||
double featureHeight = roomHeight * FEATURE_BLOCKS_PER_ROOM_BLOCK;
|
||||
return style == null ? fieldNoise.detailed(span, featureHeight, roughness) : fieldNoise.scaledTo(style, span, featureHeight);
|
||||
});
|
||||
}
|
||||
|
||||
private static Field3 pillarField(CaveNoise noise, CavePillars settings, ValueField spacing, ValueField vertical) {
|
||||
IrisGeneratorStyle style = settings.style().orElse(null);
|
||||
boolean straight = settings.vertical().isEmpty();
|
||||
return VaryingScale.of(noise, spacing, vertical, "cavern.pillars", (fieldNoise, pillarSpacing, verticalBlocks) -> {
|
||||
double featureBlocks = pillarSpacing * PILLAR_FEATURES_PER_SPACING;
|
||||
if (straight) {
|
||||
return style == null ? fieldNoise.columns(featureBlocks) : fieldNoise.columnsScaledTo(style, featureBlocks);
|
||||
}
|
||||
return style == null ? fieldNoise.smooth(featureBlocks, verticalBlocks) : fieldNoise.scaledTo(style, featureBlocks, verticalBlocks);
|
||||
});
|
||||
}
|
||||
|
||||
/** The pillar field value above which a column is the middle of a pillar. */
|
||||
private double pillarMiddleAt(double x, double z) {
|
||||
return pillarStats.valueAboveShare(middleAreaShareAt(x, z));
|
||||
}
|
||||
|
||||
/** The pillar field value above which a column is on the foot a pillar widens into towards floor and ceiling. */
|
||||
private double pillarFootAt(double x, double z) {
|
||||
return pillarStats.valueAboveShare(Math.min(1D, middleAreaShareAt(x, z) * pillarFlare.at(x, z)));
|
||||
}
|
||||
|
||||
private double middleAreaShareAt(double x, double z) {
|
||||
double radius = pillarThickness.at(x, z) / 2D;
|
||||
double spacing = pillarSpacing.at(x, z);
|
||||
return Math.min(LARGEST_PILLAR_AREA_SHARE, (Math.PI * radius * radius) / (spacing * spacing));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int fieldCount() {
|
||||
return fieldCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFields(int x, int y, int z, double[] values) {
|
||||
double room = rooms.at(x, y, z);
|
||||
if (mostOpenField == NOT_READ) {
|
||||
values[ROOMS] = room;
|
||||
} else {
|
||||
double pointThreshold = roomStats.valueAboveShare(coverage.at(x, y, z));
|
||||
values[ROOMS] = room - pointThreshold;
|
||||
values[mostOpenField] = Math.max(0D, roomStats.highest() - pointThreshold);
|
||||
}
|
||||
if (pillarField != NOT_READ) {
|
||||
values[pillarField] = pillars.at(x, y, z);
|
||||
}
|
||||
if (pillarMiddleField != NOT_READ) {
|
||||
values[pillarMiddleField] = pillarMiddleAt(x, z);
|
||||
values[pillarFootField] = pillarFootAt(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mayCarveIn(Pass pass) {
|
||||
return pass.cell(ROOMS).highest() > threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean carvesAt(Pass pass, double shareX, double shareY, double shareZ, double openness, int column) {
|
||||
double mostOpenHere = mostOpenField == NOT_READ ? mostOpen : pass.cell(mostOpenField).at(shareX, shareY, shareZ);
|
||||
double open = pass.cell(ROOMS).at(shareX, shareY, shareZ) - threshold - ((1D - openness) * mostOpenHere * CLOSING_MARGIN);
|
||||
if (open <= 0D) {
|
||||
return false;
|
||||
}
|
||||
if (pillars == null) {
|
||||
return true;
|
||||
}
|
||||
double strength = pillarsChangeWithHeight
|
||||
? pointPillarStrength(pass, shareX, shareY, shareZ)
|
||||
: columnPillarStrength(pass, column);
|
||||
return open > strength * mostOpenHere;
|
||||
}
|
||||
|
||||
private double pointPillarStrength(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
double value = pass.cell(pillarField).at(shareX, shareY, shareZ);
|
||||
if (pillarMiddleField == NOT_READ) {
|
||||
return pillarStrength(value, pillarMiddle, pillarFoot);
|
||||
}
|
||||
return pillarStrength(value, pass.cell(pillarMiddleField).at(shareX, shareY, shareZ), pass.cell(pillarFootField).at(shareX, shareY, shareZ));
|
||||
}
|
||||
|
||||
/** {@link #pillarStrength} of a straight pillar, read once per column of the chunk. */
|
||||
private double columnPillarStrength(Pass pass, int column) {
|
||||
double[] strengths = pass.columnValues();
|
||||
double known = strengths[column];
|
||||
if (!Double.isNaN(known)) {
|
||||
return known;
|
||||
}
|
||||
double x = pass.lattice().originX() + (column >> 4);
|
||||
double z = pass.lattice().originZ() + (column & 15);
|
||||
double value = pillars.at(x, 0D, z);
|
||||
double strength = pillarSizeVaries
|
||||
? pillarStrength(value, pillarMiddleAt(x, z), pillarFootAt(x, z))
|
||||
: pillarStrength(value, pillarMiddle, pillarFoot);
|
||||
strengths[column] = strength;
|
||||
return strength;
|
||||
}
|
||||
|
||||
/** How strongly a pillar field value is a pillar: 0 outside one, 1 in its middle, in between on the foot it widens into. */
|
||||
private static double pillarStrength(double value, double middle, double foot) {
|
||||
if (value >= middle) {
|
||||
return FULL_PILLAR;
|
||||
}
|
||||
double footWidth = middle - foot;
|
||||
if (footWidth <= 0D) {
|
||||
return NO_PILLAR;
|
||||
}
|
||||
double intoPillar = Math.max(0D, Math.min(1D, (value - foot) / footWidth));
|
||||
return intoPillar * intoPillar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* The points one chunk samples its cave fields at: every fourth block along each axis, over the heights a cave may
|
||||
* carve. A shape reads its fields at these points only and interpolates between them, which is where the carver's
|
||||
* speed comes from. Points sit at multiples of four in world coordinates, so neighboring chunks sample the very same
|
||||
* points along their shared border and their caves meet without a seam.
|
||||
*/
|
||||
public final class ChunkLattice {
|
||||
public static final int CELL_BLOCKS = 4;
|
||||
public static final int CELLS_PER_CHUNK_AXIS = 16 / CELL_BLOCKS;
|
||||
private static final int POINTS_PER_AXIS = CELLS_PER_CHUNK_AXIS + 1;
|
||||
private static final int POINTS_PER_LAYER = POINTS_PER_AXIS * POINTS_PER_AXIS;
|
||||
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final int baseY;
|
||||
private final int cellsY;
|
||||
|
||||
private ChunkLattice(int originX, int originZ, int baseY, int cellsY) {
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.baseY = baseY;
|
||||
this.cellsY = cellsY;
|
||||
}
|
||||
|
||||
/** The lattice of the chunk whose first block is {@code originX}, {@code originZ}, covering heights {@code minY} to {@code maxY}. */
|
||||
public static ChunkLattice covering(int originX, int originZ, int minY, int maxY) {
|
||||
int baseY = Math.floorDiv(minY, CELL_BLOCKS) * CELL_BLOCKS;
|
||||
int cellsY = Math.max(1, Math.floorDiv(maxY - baseY, CELL_BLOCKS) + 1);
|
||||
return new ChunkLattice(originX, originZ, baseY, cellsY);
|
||||
}
|
||||
|
||||
public int originX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
public int originZ() {
|
||||
return originZ;
|
||||
}
|
||||
|
||||
public int baseY() {
|
||||
return baseY;
|
||||
}
|
||||
|
||||
public int cellsY() {
|
||||
return cellsY;
|
||||
}
|
||||
|
||||
public int pointCount() {
|
||||
return POINTS_PER_LAYER * (cellsY + 1);
|
||||
}
|
||||
|
||||
/** Takes the lattice's points one by one, each with its place in a list of {@link #pointCount()} values. */
|
||||
@FunctionalInterface
|
||||
interface PointReader {
|
||||
void read(int index, int x, int y, int z);
|
||||
}
|
||||
|
||||
void forEachPoint(PointReader reader) {
|
||||
int index = 0;
|
||||
for (int layer = 0; layer <= cellsY; layer++) {
|
||||
int y = baseY + (layer * CELL_BLOCKS);
|
||||
for (int pointX = 0; pointX < POINTS_PER_AXIS; pointX++) {
|
||||
int x = originX + (pointX * CELL_BLOCKS);
|
||||
for (int pointZ = 0; pointZ < POINTS_PER_AXIS; pointZ++) {
|
||||
reader.read(index++, x, y, originZ + (pointZ * CELL_BLOCKS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pointIndex(int pointX, int layer, int pointZ) {
|
||||
return (layer * POINTS_PER_LAYER) + (pointX * POINTS_PER_AXIS) + pointZ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Noise of cave fields from Iris's own generators: a style builds the same {@link CNG} the rest of Iris builds from it,
|
||||
* seeded from an {@link RNG} of the seed. The pack's data resolves expressions and image maps; without it only plain styles work.
|
||||
*/
|
||||
public final class CngNoiseFactory implements NoiseFactory {
|
||||
private static final double NO_EXTRA_SCALE = 1D;
|
||||
|
||||
private final IrisData data;
|
||||
|
||||
public CngNoiseFactory(IrisData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/** Noise with no pack behind it: the plain styles, but no expressions and no image maps. */
|
||||
public static CngNoiseFactory standalone() {
|
||||
return new CngNoiseFactory(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler sampler(IrisGeneratorStyle style, long seed) {
|
||||
return new CngSampler(style.create(new RNG(seed), data), () -> style.createNoCache(new RNG(seed), data), NO_EXTRA_SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code fresh} builds the same generator again, unshared, for {@link #scaled}: scaling a generator changes it, and
|
||||
* the one in use is shared.
|
||||
*/
|
||||
private record CngSampler(CNG noise, Supplier<CNG> fresh, double extraScale) implements NoiseSampler {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
return noise.noise(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
return noise.noise(worldX, y, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double signed(double worldX, double worldZ) {
|
||||
return noise.noiseFastSigned2D(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double signed(double worldX, double y, double worldZ) {
|
||||
return noise.noiseFastSigned3D(worldX, y, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler scaled(double factor) {
|
||||
double total = extraScale * factor;
|
||||
return new CngSampler(fresh.get().bake().scale(total).bake(), fresh, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/** Which heights a cave carves at, before a {@link HeightBand} cuts them off. */
|
||||
public enum DepthRange {
|
||||
/** The depth range the cave writes, or the whole dimension where it writes none. */
|
||||
OWN,
|
||||
/** The whole dimension, whatever the cave writes: for carving the terrain of an upper dimension. */
|
||||
WHOLE_DIMENSION
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/** A smooth value over the world's blocks, from -1 to 1, that a cave shape reads to decide where it carves. */
|
||||
@FunctionalInterface
|
||||
public interface Field3 {
|
||||
double at(double x, double y, double z);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.OptionalDouble;
|
||||
|
||||
/**
|
||||
* What a field's values look like, measured once on fixed sample points so every server measures the same: which value
|
||||
* a given share of the world lies above, and how far apart its features lie. Shapes turn a share of the underground
|
||||
* into a field threshold with it, and a pack's noise style into a size in blocks.
|
||||
*/
|
||||
final class FieldStats {
|
||||
private static final int SAMPLES = 4096;
|
||||
/** Samples spread over this many features, far enough apart to be independent. */
|
||||
private static final double SPAN_IN_FEATURES = 200D;
|
||||
private static final double STEP_X = 0.7548776662466927D;
|
||||
private static final double STEP_Y = 0.5698402909980532D;
|
||||
private static final double STEP_Z = 0.8191725133961645D;
|
||||
private static final int LINES = 64;
|
||||
private static final int LINE_SAMPLES = 128;
|
||||
private static final double LINE_STEPS_PER_FEATURE = 16D;
|
||||
private static final int FEWEST_CROSSINGS = 16;
|
||||
|
||||
private final double[] sortedValues;
|
||||
|
||||
private FieldStats(double[] sortedValues) {
|
||||
this.sortedValues = sortedValues;
|
||||
}
|
||||
|
||||
/** Measures {@code field}, whose features are about {@code featureBlocks} blocks apart. */
|
||||
static FieldStats measure(Field3 field, double featureBlocks) {
|
||||
double span = featureBlocks * SPAN_IN_FEATURES;
|
||||
double[] values = new double[SAMPLES];
|
||||
for (int sample = 0; sample < SAMPLES; sample++) {
|
||||
values[sample] = field.at(coordinate(sample, STEP_X, span), coordinate(sample, STEP_Y, span), coordinate(sample, STEP_Z, span));
|
||||
}
|
||||
Arrays.sort(values);
|
||||
return new FieldStats(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* How far apart the features of {@code field} lie in blocks, measured as the mean distance between two crossings
|
||||
* of its middle value along horizontal lines. Lines are read in steps of a fraction of {@code expectedBlocks}, so a
|
||||
* field far finer than expected measures too coarse; measuring again at the answer corrects that. Empty for a field
|
||||
* that hardly crosses its middle, such as a level one.
|
||||
*/
|
||||
static OptionalDouble featureBlocks(Field3 field, double expectedBlocks) {
|
||||
double step = expectedBlocks / LINE_STEPS_PER_FEATURE;
|
||||
double span = expectedBlocks * SPAN_IN_FEATURES;
|
||||
double[] values = new double[LINES * LINE_SAMPLES];
|
||||
for (int line = 0; line < LINES; line++) {
|
||||
double startX = coordinate(line, STEP_X, span);
|
||||
double y = coordinate(line, STEP_Y, span);
|
||||
double startZ = coordinate(line, STEP_Z, span);
|
||||
boolean alongX = (line & 1) == 0;
|
||||
for (int sample = 0; sample < LINE_SAMPLES; sample++) {
|
||||
double along = sample * step;
|
||||
values[(line * LINE_SAMPLES) + sample] = alongX ? field.at(startX + along, y, startZ) : field.at(startX, y, startZ + along);
|
||||
}
|
||||
}
|
||||
double[] sorted = values.clone();
|
||||
Arrays.sort(sorted);
|
||||
double middle = sorted[sorted.length / 2];
|
||||
int crossings = 0;
|
||||
for (int index = 1; index < values.length; index++) {
|
||||
boolean sameLine = index % LINE_SAMPLES != 0;
|
||||
if (sameLine && (values[index - 1] >= middle) != (values[index] >= middle)) {
|
||||
crossings++;
|
||||
}
|
||||
}
|
||||
if (crossings < FEWEST_CROSSINGS) {
|
||||
return OptionalDouble.empty();
|
||||
}
|
||||
double measuredLength = LINES * (LINE_SAMPLES - 1) * step;
|
||||
return OptionalDouble.of(measuredLength / crossings);
|
||||
}
|
||||
|
||||
private static double coordinate(int sample, double step, double span) {
|
||||
double fraction = (sample * step) % 1D;
|
||||
return (fraction - 0.5D) * span;
|
||||
}
|
||||
|
||||
/** The value that {@code share} of the world lies above, from 0 to 1. */
|
||||
double valueAboveShare(double share) {
|
||||
double clamped = Math.max(0D, Math.min(1D, share));
|
||||
int index = (int) Math.round((1D - clamped) * (sortedValues.length - 1));
|
||||
return sortedValues[index];
|
||||
}
|
||||
|
||||
double highest() {
|
||||
return sortedValues[sortedValues.length - 1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* The heights a carve is limited to, counted from the dimension's bottom and both included. A cave carved inside a
|
||||
* band is the very cave it would be without one, cut off at the band's ends.
|
||||
*/
|
||||
public record HeightBand(int lowestY, int highestY) {
|
||||
public static final HeightBand UNLIMITED = new HeightBand(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* One field's values at the eight corners of a lattice cell, and the value interpolated between them at any block of
|
||||
* the cell. An interpolated value never leaves the range of the corners, so a shape can rule a whole cell out from
|
||||
* {@link #lowest()} and {@link #highest()} without looking at its blocks.
|
||||
*/
|
||||
final class LatticeCell {
|
||||
/** A face holds four corners, and opposite faces are one cell apart. */
|
||||
private static final double SLOPE_PER_FACE_SUM = 1D / (4D * ChunkLattice.CELL_BLOCKS);
|
||||
|
||||
private double lowWestNorth;
|
||||
private double lowWestSouth;
|
||||
private double lowEastNorth;
|
||||
private double lowEastSouth;
|
||||
private double highWestNorth;
|
||||
private double highWestSouth;
|
||||
private double highEastNorth;
|
||||
private double highEastSouth;
|
||||
|
||||
void load(double[] values, ChunkLattice lattice, int cellX, int cellY, int cellZ) {
|
||||
lowWestNorth = values[lattice.pointIndex(cellX, cellY, cellZ)];
|
||||
lowWestSouth = values[lattice.pointIndex(cellX, cellY, cellZ + 1)];
|
||||
lowEastNorth = values[lattice.pointIndex(cellX + 1, cellY, cellZ)];
|
||||
lowEastSouth = values[lattice.pointIndex(cellX + 1, cellY, cellZ + 1)];
|
||||
highWestNorth = values[lattice.pointIndex(cellX, cellY + 1, cellZ)];
|
||||
highWestSouth = values[lattice.pointIndex(cellX, cellY + 1, cellZ + 1)];
|
||||
highEastNorth = values[lattice.pointIndex(cellX + 1, cellY + 1, cellZ)];
|
||||
highEastSouth = values[lattice.pointIndex(cellX + 1, cellY + 1, cellZ + 1)];
|
||||
}
|
||||
|
||||
double lowest() {
|
||||
return Math.min(Math.min(Math.min(lowWestNorth, lowWestSouth), Math.min(lowEastNorth, lowEastSouth)),
|
||||
Math.min(Math.min(highWestNorth, highWestSouth), Math.min(highEastNorth, highEastSouth)));
|
||||
}
|
||||
|
||||
double highest() {
|
||||
return Math.max(Math.max(Math.max(lowWestNorth, lowWestSouth), Math.max(lowEastNorth, lowEastSouth)),
|
||||
Math.max(Math.max(highWestNorth, highWestSouth), Math.max(highEastNorth, highEastSouth)));
|
||||
}
|
||||
|
||||
/** How far every value of the cell stays from zero; 0 when the cell may cross it. */
|
||||
double distanceFromZero() {
|
||||
double lowest = lowest();
|
||||
if (lowest > 0D) {
|
||||
return lowest;
|
||||
}
|
||||
double highest = highest();
|
||||
return highest < 0D ? -highest : 0D;
|
||||
}
|
||||
|
||||
/** How much the value changes per block towards higher X, averaged over the cell. */
|
||||
double slopeX() {
|
||||
return ((lowEastNorth + lowEastSouth + highEastNorth + highEastSouth)
|
||||
- (lowWestNorth + lowWestSouth + highWestNorth + highWestSouth)) * SLOPE_PER_FACE_SUM;
|
||||
}
|
||||
|
||||
/** How much the value changes per block upwards, averaged over the cell. */
|
||||
double slopeY() {
|
||||
return ((highWestNorth + highWestSouth + highEastNorth + highEastSouth)
|
||||
- (lowWestNorth + lowWestSouth + lowEastNorth + lowEastSouth)) * SLOPE_PER_FACE_SUM;
|
||||
}
|
||||
|
||||
/** How much the value changes per block towards higher Z, averaged over the cell. */
|
||||
double slopeZ() {
|
||||
return ((lowWestSouth + lowEastSouth + highWestSouth + highEastSouth)
|
||||
- (lowWestNorth + lowEastNorth + highWestNorth + highEastNorth)) * SLOPE_PER_FACE_SUM;
|
||||
}
|
||||
|
||||
/** The value at a block of the cell, each coordinate as its share of the way across the cell, from 0 to 1. */
|
||||
double at(double shareX, double shareY, double shareZ) {
|
||||
double low = across(lowWestNorth, lowWestSouth, lowEastNorth, lowEastSouth, shareX, shareZ);
|
||||
double high = across(highWestNorth, highWestSouth, highEastNorth, highEastSouth, shareX, shareZ);
|
||||
return low + ((high - low) * shareY);
|
||||
}
|
||||
|
||||
private static double across(double westNorth, double westSouth, double eastNorth, double eastSouth, double shareX, double shareZ) {
|
||||
double west = westNorth + ((westSouth - westNorth) * shareZ);
|
||||
double east = eastNorth + ((eastSouth - eastNorth) * shareZ);
|
||||
return west + ((east - west) * shareX);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A cave shape that reads smooth fields on a chunk's lattice and decides block by block from their interpolated
|
||||
* values. The fields are interpolated, never the decision, so a passage thinner than a lattice cell survives: its
|
||||
* fields still cross zero between the points.
|
||||
*/
|
||||
abstract class LatticeShape {
|
||||
private static final ThreadLocal<Pass> PASS = ThreadLocal.withInitial(Pass::new);
|
||||
private static final double CELL_SHARE = 1D / ChunkLattice.CELL_BLOCKS;
|
||||
|
||||
/** How many fields the shape reads. {@link Pass#cell} numbers them from 0. */
|
||||
protected abstract int fieldCount();
|
||||
|
||||
/** Reads every field of the shape at one block into {@code values}, one value per field. */
|
||||
protected abstract void readFields(int x, int y, int z, double[] values);
|
||||
|
||||
/** Whether the shape can carve anywhere in the cell the pass has loaded, whatever the limits allow. */
|
||||
protected abstract boolean mayCarveIn(Pass pass);
|
||||
|
||||
/** Whether the shape carves the block at these shares of the way across the loaded cell. */
|
||||
protected abstract boolean carvesAt(Pass pass, double shareX, double shareY, double shareZ, double openness, int column);
|
||||
|
||||
final void carve(ChunkLattice lattice, CaveLimits limits, CarveSink sink) {
|
||||
Pass pass = PASS.get();
|
||||
pass.begin(lattice, this);
|
||||
for (int cellY = 0; cellY < lattice.cellsY(); cellY++) {
|
||||
int bottomY = lattice.baseY() + (cellY * ChunkLattice.CELL_BLOCKS);
|
||||
if (bottomY > limits.highestY() || bottomY + ChunkLattice.CELL_BLOCKS <= limits.lowestY()) {
|
||||
continue;
|
||||
}
|
||||
for (int cellX = 0; cellX < ChunkLattice.CELLS_PER_CHUNK_AXIS; cellX++) {
|
||||
for (int cellZ = 0; cellZ < ChunkLattice.CELLS_PER_CHUNK_AXIS; cellZ++) {
|
||||
if (limits.cellIsClosed(cellX, cellZ, bottomY)) {
|
||||
continue;
|
||||
}
|
||||
pass.load(cellX, cellY, cellZ);
|
||||
if (mayCarveIn(pass)) {
|
||||
carveCell(pass, limits, sink, cellX, bottomY, cellZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void carveCell(Pass pass, CaveLimits limits, CarveSink sink, int cellX, int bottomY, int cellZ) {
|
||||
for (int stepY = 0; stepY < ChunkLattice.CELL_BLOCKS; stepY++) {
|
||||
int y = bottomY + stepY;
|
||||
if (y < limits.lowestY() || y > limits.highestY()) {
|
||||
continue;
|
||||
}
|
||||
for (int stepX = 0; stepX < ChunkLattice.CELL_BLOCKS; stepX++) {
|
||||
int localX = (cellX * ChunkLattice.CELL_BLOCKS) + stepX;
|
||||
for (int stepZ = 0; stepZ < ChunkLattice.CELL_BLOCKS; stepZ++) {
|
||||
int localZ = (cellZ * ChunkLattice.CELL_BLOCKS) + stepZ;
|
||||
int column = (localX << 4) | localZ;
|
||||
double openness = limits.openness(column, y);
|
||||
if (openness > 0D && carvesAt(pass, stepX * CELL_SHARE, stepY * CELL_SHARE, stepZ * CELL_SHARE, openness, column)) {
|
||||
sink.carve(localX, y, localZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** One chunk's carving by one shape on one thread: the sampled fields, the cell being decided and a value per column. */
|
||||
static final class Pass {
|
||||
private static final int CHUNK_COLUMNS = 256;
|
||||
private static final int CELL_VALUES = 12;
|
||||
|
||||
private ChunkLattice lattice;
|
||||
private double[] pointValues = new double[0];
|
||||
private double[][] values = new double[0][];
|
||||
private LatticeCell[] cells = new LatticeCell[0];
|
||||
private int fieldCount;
|
||||
private final double[] columnValues = new double[CHUNK_COLUMNS];
|
||||
private final double[] cellValues = new double[CELL_VALUES];
|
||||
|
||||
private void begin(ChunkLattice lattice, LatticeShape shape) {
|
||||
this.lattice = lattice;
|
||||
this.fieldCount = shape.fieldCount();
|
||||
if (values.length < fieldCount) {
|
||||
values = Arrays.copyOf(values, fieldCount);
|
||||
cells = Arrays.copyOf(cells, fieldCount);
|
||||
pointValues = new double[fieldCount];
|
||||
}
|
||||
int points = lattice.pointCount();
|
||||
for (int field = 0; field < fieldCount; field++) {
|
||||
if (values[field] == null || values[field].length < points) {
|
||||
values[field] = new double[points];
|
||||
}
|
||||
if (cells[field] == null) {
|
||||
cells[field] = new LatticeCell();
|
||||
}
|
||||
}
|
||||
lattice.forEachPoint((index, x, y, z) -> {
|
||||
shape.readFields(x, y, z, pointValues);
|
||||
for (int field = 0; field < fieldCount; field++) {
|
||||
values[field][index] = pointValues[field];
|
||||
}
|
||||
});
|
||||
Arrays.fill(columnValues, Double.NaN);
|
||||
}
|
||||
|
||||
private void load(int cellX, int cellY, int cellZ) {
|
||||
for (int field = 0; field < fieldCount; field++) {
|
||||
cells[field].load(values[field], lattice, cellX, cellY, cellZ);
|
||||
}
|
||||
}
|
||||
|
||||
LatticeCell cell(int field) {
|
||||
return cells[field];
|
||||
}
|
||||
|
||||
ChunkLattice lattice() {
|
||||
return lattice;
|
||||
}
|
||||
|
||||
/** A value the shape keeps per column of the chunk for the length of the pass; NaN until the shape sets it. */
|
||||
double[] columnValues() {
|
||||
return columnValues;
|
||||
}
|
||||
|
||||
/** Values the shape works out in {@link LatticeShape#mayCarveIn} for the blocks of the loaded cell. */
|
||||
double[] cellValues() {
|
||||
return cellValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
|
||||
/** Builds the noise of the styles a cave's pack writes. The same style and seed give the same values every time. */
|
||||
@FunctionalInterface
|
||||
public interface NoiseFactory {
|
||||
NoiseSampler sampler(IrisGeneratorStyle style, long seed);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/** Noise a cave field reads, built from one pack style and one seed. Safe for concurrent reads. */
|
||||
public interface NoiseSampler {
|
||||
/** The noise at a column, from 0 to 1. */
|
||||
double sample(double worldX, double worldZ);
|
||||
|
||||
/** The noise at a block, from 0 to 1. */
|
||||
double sample(double worldX, double y, double worldZ);
|
||||
|
||||
/** The noise at a column, from -1 to 1. */
|
||||
default double signed(double worldX, double worldZ) {
|
||||
return sample(worldX, worldZ) * 2D - 1D;
|
||||
}
|
||||
|
||||
/** The noise at a block, from -1 to 1. */
|
||||
default double signed(double worldX, double y, double worldZ) {
|
||||
return sample(worldX, y, worldZ) * 2D - 1D;
|
||||
}
|
||||
|
||||
/**
|
||||
* This noise with its coordinates multiplied by {@code factor}: above 1 squeezes the pattern, below 1 stretches it.
|
||||
* The factor is folded into the generator's own scale, so a fracture still moves the noise in blocks.
|
||||
*/
|
||||
NoiseSampler scaled(double factor);
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveTunnel;
|
||||
import art.arcane.iris.generation.cave.CaveTunnelCoverage;
|
||||
import art.arcane.iris.generation.cave.CaveValue;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
|
||||
/**
|
||||
* Tunnels: the lines along which two of three fields are both zero. Each field is zero on winding sheets through the
|
||||
* rock and two sheets meet in a line, which never ends on its own, so tunnels are long. Every line runs inside two
|
||||
* sheets and sooner or later crosses the third, and there all three lines meet: that is a junction, and it is what
|
||||
* joins the tunnels into one network.
|
||||
*
|
||||
* <p>A tunnel is every block within its radius of a line. The distance is worked out in blocks from how steeply the
|
||||
* fields change in the cell, so a tunnel keeps the width the pack asks for wherever the noise is steep or shallow.
|
||||
* An oval tunnel measures the distance with the vertical axis stretched by its width over its height, which keeps its
|
||||
* width and gives it its height. The fields are read at warped places, which makes a tunnel's path bend without ever
|
||||
* breaking it.
|
||||
*/
|
||||
final class TunnelShape extends LatticeShape {
|
||||
private static final int SHEETS = 3;
|
||||
private static final int NOT_READ = -1;
|
||||
private static final int[] PAIR_FIRST = {0, 0, 1};
|
||||
private static final int[] PAIR_SECOND = {1, 2, 2};
|
||||
private static final int PAIRS = PAIR_FIRST.length;
|
||||
/** A round tunnel keeps, per pair of sheets, the three terms of its squared distance from their line and whether it is near. */
|
||||
private static final int ROUND_VALUES_PER_PAIR = 4;
|
||||
private static final int FIRST_SQUARED = 0;
|
||||
private static final int FIRST_TIMES_SECOND = 1;
|
||||
private static final int SECOND_SQUARED = 2;
|
||||
private static final int PAIR_IS_NEAR = 3;
|
||||
/** An oval tunnel keeps each sheet's slope along the three axes, then whether each pair is near. */
|
||||
private static final int OVAL_SLOPE_X = 0;
|
||||
private static final int OVAL_SLOPE_Y = 1;
|
||||
private static final int OVAL_SLOPE_Z = 2;
|
||||
private static final int OVAL_VALUES_PER_SHEET = 3;
|
||||
private static final int OVAL_PAIR_IS_NEAR = SHEETS * OVAL_VALUES_PER_SHEET;
|
||||
/** An oval tunnel's terms depend on its height over its width at the block, so they are worked out block by block here. */
|
||||
private static final ThreadLocal<double[]> OVAL_TERMS = ThreadLocal.withInitial(() -> new double[PAIR_IS_NEAR]);
|
||||
private static final double NEAR = 1D;
|
||||
private static final double FAR = 0D;
|
||||
private static final double ROUND = 1D;
|
||||
/** Without a warp, a path shifts by this share of the horizontal spacing, and changes direction this many times per spacing. */
|
||||
private static final double DEFAULT_WARP_SHARE_OF_SPACING = 0.06D;
|
||||
private static final double DEFAULT_WARPS_PER_SPACING = 3D;
|
||||
private static final double SMALLEST_DEFAULT_WARP_SPACING_BLOCKS = 16D;
|
||||
/** Without a coverage style, the areas with tunnels are this many horizontal spacings across. */
|
||||
private static final double DEFAULT_PRESENCE_SPACINGS = 3D;
|
||||
/**
|
||||
* Field value over which tunnels widen from nothing to full size at the edge of an area that has them, at a
|
||||
* softness of 1. A softness of 0 still keeps the least edge, so the share never divides by zero.
|
||||
*/
|
||||
private static final double SOFTEST_PRESENCE_EDGE = 0.5D;
|
||||
private static final double LEAST_PRESENCE_EDGE = 0.005D;
|
||||
/** Where the share of an area's tunnels is worked out at the lattice points, a block divides by nothing and subtracts nothing. */
|
||||
private static final double PRESENCE_WORKED_OUT_AT_POINTS = 0D;
|
||||
private static final double EDGE_WORKED_OUT_AT_POINTS = 1D;
|
||||
/** A tunnel narrower or lower than this is not a passage any more, so it ends instead. */
|
||||
private static final double NARROWEST_RADIUS_BLOCKS = 1D;
|
||||
/** A cell's slope is an average, so a cell is only ruled out when the line is clearly further than the widest tunnel. */
|
||||
private static final double CELL_REACH_SLACK = 1.5D;
|
||||
/**
|
||||
* Where a field is nearly flat, a small value says little about how far its sheet is, and the tunnel would swell
|
||||
* into a blob. A field counts as changing at least this share of its typical slope.
|
||||
*/
|
||||
private static final double LEAST_SLOPE_SHARE = 0.45D;
|
||||
/** Where two sheets run nearly side by side the line between them is ill-defined; they count as crossing at least this squarely. */
|
||||
private static final double LEAST_CROSSING = 0.03D;
|
||||
|
||||
private final Field3[] sheets = new Field3[SHEETS];
|
||||
private final Field3 warpX;
|
||||
private final Field3 warpY;
|
||||
private final Field3 warpZ;
|
||||
private final double warpBlocks;
|
||||
private final ValueField verticalWarp;
|
||||
private final Field3 width;
|
||||
private final double narrowRadius;
|
||||
private final double wideRadius;
|
||||
private final TunnelHeight heightKind;
|
||||
private final boolean oval;
|
||||
private final double lowRadius;
|
||||
private final double tallRadius;
|
||||
private final ValueField height;
|
||||
private final Field3 presence;
|
||||
private final FieldStats presenceStats;
|
||||
private final ValueField presenceShare;
|
||||
private final ValueField presenceSoftness;
|
||||
private final boolean presenceWorkedOutAtPoints;
|
||||
private final double presenceThreshold;
|
||||
private final double presenceEdge;
|
||||
private final int widthField;
|
||||
private final int heightField;
|
||||
private final int presenceField;
|
||||
private final int fieldCount;
|
||||
private final double leastSteepness;
|
||||
|
||||
/** How tall a tunnel is against how wide. */
|
||||
private enum TunnelHeight {
|
||||
/** As tall as it is wide. */
|
||||
ROUND,
|
||||
/** Between its low and tall height, as far as it is between its narrow and wide width. */
|
||||
FOLLOWS_WIDTH,
|
||||
/** The height its own noise picks. */
|
||||
OWN_NOISE
|
||||
}
|
||||
|
||||
TunnelShape(CaveNoise noise, CaveTunnel tunnel) {
|
||||
double spacing = tunnel.spacing().horizontal();
|
||||
double verticalSpacing = tunnel.spacing().vertical();
|
||||
double valueChangeBlocks = spacing * CaveTunnel.VALUE_CHANGE_SPACINGS;
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
sheets[sheet] = noise.smooth(spacing, verticalSpacing);
|
||||
}
|
||||
this.verticalWarp = ValueField.inBlocks(tunnel.verticalWarp(), noise, "tunnel.verticalWarp", valueChangeBlocks);
|
||||
IrisGeneratorStyle warp = tunnel.warp().orElse(null);
|
||||
if (warp == null) {
|
||||
double warpSpacing = Math.max(SMALLEST_DEFAULT_WARP_SPACING_BLOCKS, spacing / DEFAULT_WARPS_PER_SPACING);
|
||||
this.warpX = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpY = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpZ = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpBlocks = spacing * DEFAULT_WARP_SHARE_OF_SPACING;
|
||||
} else {
|
||||
this.warpX = noise.inBlocks(warp);
|
||||
this.warpY = noise.inBlocks(warp);
|
||||
this.warpZ = noise.inBlocks(warp);
|
||||
this.warpBlocks = warp.isFlat() ? 0D : warp.getMultiplier() / 2D;
|
||||
}
|
||||
CaveValue widthValue = tunnel.width();
|
||||
double widthChangeBlocks = spacing * CaveTunnel.WIDTH_CHANGE_SPACINGS;
|
||||
this.width = widthValue.style().map(noise::inBlocks).orElseGet(() -> noise.smooth(widthChangeBlocks, widthChangeBlocks));
|
||||
this.narrowRadius = widthValue.lowest() / 2D;
|
||||
this.wideRadius = widthValue.highest() / 2D;
|
||||
CaveValue heightValue = tunnel.height().orElse(null);
|
||||
this.heightKind = heightKindOf(heightValue);
|
||||
this.oval = heightKind != TunnelHeight.ROUND;
|
||||
this.lowRadius = heightValue == null ? 0D : heightValue.lowest() / 2D;
|
||||
this.tallRadius = heightValue == null ? 0D : heightValue.highest() / 2D;
|
||||
this.height = heightKind == TunnelHeight.OWN_NOISE
|
||||
? ValueField.inBlocks(heightValue, noise, "tunnel.height", widthChangeBlocks)
|
||||
: null;
|
||||
double leastSlope = CaveNoise.typicalSlope(spacing) * LEAST_SLOPE_SHARE;
|
||||
this.leastSteepness = leastSlope * leastSlope;
|
||||
CaveTunnelCoverage coverage = tunnel.coverage();
|
||||
this.presenceShare = ValueField.inBlocks(coverage.share(), noise, "tunnel.coverage.share", valueChangeBlocks);
|
||||
this.presenceSoftness = ValueField.inBlocks(coverage.softness(), noise, "tunnel.coverage.softness", valueChangeBlocks);
|
||||
this.presenceWorkedOutAtPoints = presenceShare.varies() || presenceSoftness.varies();
|
||||
boolean heightReadsTheWidthNoise = heightKind == TunnelHeight.FOLLOWS_WIDTH && heightValue.varies();
|
||||
boolean readsWidth = widthValue.varies() || heightReadsTheWidthNoise;
|
||||
this.widthField = readsWidth ? SHEETS : NOT_READ;
|
||||
int nextField = readsWidth ? SHEETS + 1 : SHEETS;
|
||||
this.heightField = height == null ? NOT_READ : nextField++;
|
||||
if (presenceShare.lowest() >= 1D) {
|
||||
this.presence = null;
|
||||
this.presenceStats = null;
|
||||
this.presenceThreshold = Double.NEGATIVE_INFINITY;
|
||||
this.presenceEdge = EDGE_WORKED_OUT_AT_POINTS;
|
||||
this.presenceField = NOT_READ;
|
||||
this.fieldCount = nextField;
|
||||
return;
|
||||
}
|
||||
double presenceSpacing = spacing * DEFAULT_PRESENCE_SPACINGS;
|
||||
IrisGeneratorStyle presenceStyle = coverage.style().orElse(null);
|
||||
this.presence = presenceStyle == null ? noise.smooth(presenceSpacing, presenceSpacing) : noise.inBlocks(presenceStyle);
|
||||
double presenceFeatureBlocks = presenceStyle == null ? presenceSpacing : CaveNoise.featureBlocks(presence, presenceStyle);
|
||||
this.presenceStats = FieldStats.measure(presence, presenceFeatureBlocks);
|
||||
this.presenceThreshold = presenceWorkedOutAtPoints ? PRESENCE_WORKED_OUT_AT_POINTS : presenceStats.valueAboveShare(presenceShare.min());
|
||||
this.presenceEdge = presenceWorkedOutAtPoints ? EDGE_WORKED_OUT_AT_POINTS : presenceEdgeOf(presenceSoftness.min());
|
||||
this.presenceField = nextField++;
|
||||
this.fieldCount = nextField;
|
||||
}
|
||||
|
||||
private static TunnelHeight heightKindOf(CaveValue height) {
|
||||
if (height == null) {
|
||||
return TunnelHeight.ROUND;
|
||||
}
|
||||
return height.varies() && height.style().isPresent() ? TunnelHeight.OWN_NOISE : TunnelHeight.FOLLOWS_WIDTH;
|
||||
}
|
||||
|
||||
private static double presenceEdgeOf(double softness) {
|
||||
return Math.max(LEAST_PRESENCE_EDGE, softness * SOFTEST_PRESENCE_EDGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int fieldCount() {
|
||||
return fieldCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFields(int x, int y, int z, double[] values) {
|
||||
readSheets(x, y, z, values);
|
||||
if (widthField != NOT_READ) {
|
||||
values[widthField] = width.at(x, y, z);
|
||||
}
|
||||
if (heightField != NOT_READ) {
|
||||
values[heightField] = height.at(x, y, z);
|
||||
}
|
||||
if (presenceField != NOT_READ) {
|
||||
values[presenceField] = presenceAt(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The presence field, or where share or softness vary, how far into an area with tunnels the point lies in
|
||||
* edges: the threshold and edge are only known point by point then.
|
||||
*/
|
||||
private double presenceAt(int x, int y, int z) {
|
||||
double value = presence.at(x, y, z);
|
||||
if (!presenceWorkedOutAtPoints) {
|
||||
return value;
|
||||
}
|
||||
double threshold = presenceStats.valueAboveShare(presenceShare.at(x, y, z));
|
||||
return (value - threshold) / presenceEdgeOf(presenceSoftness.at(x, y, z));
|
||||
}
|
||||
|
||||
private void readSheets(int x, int y, int z, double[] values) {
|
||||
if (warpBlocks == 0D) {
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
values[sheet] = sheets[sheet].at(x, y, z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
double warpedX = x + (warpX.at(x, y, z) * warpBlocks);
|
||||
double warpedY = y + (warpY.at(x, y, z) * warpBlocks * verticalWarp.at(x, y, z));
|
||||
double warpedZ = z + (warpZ.at(x, y, z) * warpBlocks);
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
values[sheet] = sheets[sheet].at(warpedX, warpedY, warpedZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mayCarveIn(Pass pass) {
|
||||
if (presence != null && pass.cell(presenceField).highest() <= presenceThreshold) {
|
||||
return false;
|
||||
}
|
||||
double reach = Math.max(wideRadius, tallRadius) * CELL_REACH_SLACK;
|
||||
double[] cellValues = pass.cellValues();
|
||||
if (oval) {
|
||||
keepSlopes(pass, cellValues);
|
||||
}
|
||||
boolean anyPairNear = false;
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
LatticeCell first = pass.cell(PAIR_FIRST[pair]);
|
||||
LatticeCell second = pass.cell(PAIR_SECOND[pair]);
|
||||
boolean near = isNear(first, reach) && isNear(second, reach);
|
||||
if (near && !oval) {
|
||||
keepTerms(first, second, ROUND, cellValues, pair * ROUND_VALUES_PER_PAIR);
|
||||
}
|
||||
cellValues[nearIndex(pair)] = near ? NEAR : FAR;
|
||||
anyPairNear |= near;
|
||||
}
|
||||
return anyPairNear;
|
||||
}
|
||||
|
||||
private int nearIndex(int pair) {
|
||||
return oval ? OVAL_PAIR_IS_NEAR + pair : (pair * ROUND_VALUES_PER_PAIR) + PAIR_IS_NEAR;
|
||||
}
|
||||
|
||||
/** Whether the sheet of a field may come within {@code reach} blocks of the cell. */
|
||||
private boolean isNear(LatticeCell cell, double reach) {
|
||||
double fieldDistance = cell.distanceFromZero();
|
||||
double squaredSlope = Math.max(squaredSlope(cell, ROUND), leastSteepness);
|
||||
return fieldDistance * fieldDistance <= reach * reach * squaredSlope;
|
||||
}
|
||||
|
||||
private static void keepSlopes(Pass pass, double[] cellValues) {
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
LatticeCell cell = pass.cell(sheet);
|
||||
int offset = sheet * OVAL_VALUES_PER_SHEET;
|
||||
cellValues[offset + OVAL_SLOPE_X] = cell.slopeX();
|
||||
cellValues[offset + OVAL_SLOPE_Y] = cell.slopeY();
|
||||
cellValues[offset + OVAL_SLOPE_Z] = cell.slopeZ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out, for the line where two sheets meet, the terms that turn the two field values at a block into its
|
||||
* squared distance from that line in blocks, with the vertical axis squeezed by {@code verticalScale}.
|
||||
*/
|
||||
private void keepTerms(LatticeCell first, LatticeCell second, double verticalScale, double[] terms, int offset) {
|
||||
keepTerms(first.slopeX(), first.slopeY(), first.slopeZ(), second.slopeX(), second.slopeY(), second.slopeZ(), verticalScale, terms, offset);
|
||||
}
|
||||
|
||||
private void keepTerms(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ,
|
||||
double verticalScale, double[] terms, int offset) {
|
||||
double squaredScale = verticalScale * verticalScale;
|
||||
double firstSteepness = Math.max((firstX * firstX) + (squaredScale * firstY * firstY) + (firstZ * firstZ), leastSteepness);
|
||||
double secondSteepness = Math.max((secondX * secondX) + (squaredScale * secondY * secondY) + (secondZ * secondZ), leastSteepness);
|
||||
double together = (firstX * secondX) + (squaredScale * firstY * secondY) + (firstZ * secondZ);
|
||||
double crossing = Math.max((firstSteepness * secondSteepness) - (together * together), firstSteepness * secondSteepness * LEAST_CROSSING);
|
||||
terms[offset + FIRST_SQUARED] = secondSteepness / crossing;
|
||||
terms[offset + FIRST_TIMES_SECOND] = (-2D * together) / crossing;
|
||||
terms[offset + SECOND_SQUARED] = firstSteepness / crossing;
|
||||
}
|
||||
|
||||
private static double squaredSlope(LatticeCell cell, double verticalScale) {
|
||||
double squaredScale = verticalScale * verticalScale;
|
||||
return (cell.slopeX() * cell.slopeX()) + (squaredScale * cell.slopeY() * cell.slopeY()) + (cell.slopeZ() * cell.slopeZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean carvesAt(Pass pass, double shareX, double shareY, double shareZ, double openness, int column) {
|
||||
double widthShare = widthShareAt(pass, shareX, shareY, shareZ);
|
||||
double sizeShare = presenceShareAt(pass, shareX, shareY, shareZ);
|
||||
double radius = ((narrowRadius + ((wideRadius - narrowRadius) * widthShare)) * sizeShare) * openness;
|
||||
if (radius < NARROWEST_RADIUS_BLOCKS) {
|
||||
return false;
|
||||
}
|
||||
if (!oval) {
|
||||
return isWithinRoundTunnel(pass, shareX, shareY, shareZ, radius);
|
||||
}
|
||||
double heightRadius = (fullHeightRadiusAt(pass, shareX, shareY, shareZ, widthShare) * sizeShare) * openness;
|
||||
if (heightRadius < NARROWEST_RADIUS_BLOCKS) {
|
||||
return false;
|
||||
}
|
||||
return isWithinOvalTunnel(pass, shareX, shareY, shareZ, radius, heightRadius);
|
||||
}
|
||||
|
||||
private boolean isWithinRoundTunnel(Pass pass, double shareX, double shareY, double shareZ, double radius) {
|
||||
double squaredRadius = radius * radius;
|
||||
double[] terms = pass.cellValues();
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
int offset = pair * ROUND_VALUES_PER_PAIR;
|
||||
if (terms[offset + PAIR_IS_NEAR] == FAR) {
|
||||
continue;
|
||||
}
|
||||
if (squaredBlocksFromLine(pass, pair, terms, offset, shareX, shareY, shareZ) < squaredRadius) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures with the vertical axis stretched by the tunnel's width over its height, where the oval is a circle as
|
||||
* wide as the tunnel: a field's upward slope shrinks by the same share.
|
||||
*/
|
||||
private boolean isWithinOvalTunnel(Pass pass, double shareX, double shareY, double shareZ, double radius, double heightRadius) {
|
||||
double squaredRadius = radius * radius;
|
||||
double verticalScale = heightRadius / radius;
|
||||
double[] cellValues = pass.cellValues();
|
||||
double[] terms = OVAL_TERMS.get();
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
if (cellValues[OVAL_PAIR_IS_NEAR + pair] == FAR) {
|
||||
continue;
|
||||
}
|
||||
int first = PAIR_FIRST[pair] * OVAL_VALUES_PER_SHEET;
|
||||
int second = PAIR_SECOND[pair] * OVAL_VALUES_PER_SHEET;
|
||||
keepTerms(cellValues[first + OVAL_SLOPE_X], cellValues[first + OVAL_SLOPE_Y], cellValues[first + OVAL_SLOPE_Z],
|
||||
cellValues[second + OVAL_SLOPE_X], cellValues[second + OVAL_SLOPE_Y], cellValues[second + OVAL_SLOPE_Z],
|
||||
verticalScale, terms, 0);
|
||||
if (squaredBlocksFromLine(pass, pair, terms, 0, shareX, shareY, shareZ) < squaredRadius) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static double squaredBlocksFromLine(Pass pass, int pair, double[] terms, int offset, double shareX, double shareY, double shareZ) {
|
||||
double first = pass.cell(PAIR_FIRST[pair]).at(shareX, shareY, shareZ);
|
||||
double second = pass.cell(PAIR_SECOND[pair]).at(shareX, shareY, shareZ);
|
||||
return (terms[offset + FIRST_SQUARED] * first * first)
|
||||
+ (terms[offset + FIRST_TIMES_SECOND] * first * second)
|
||||
+ (terms[offset + SECOND_SQUARED] * second * second);
|
||||
}
|
||||
|
||||
/** How far between its narrow and its wide width the tunnel is at the block, from 0 to 1; 0 where the width is fixed. */
|
||||
private double widthShareAt(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
if (widthField == NOT_READ) {
|
||||
return 0D;
|
||||
}
|
||||
return ValueField.shareAt(pass.cell(widthField).at(shareX, shareY, shareZ));
|
||||
}
|
||||
|
||||
/** Half the height of an oval tunnel at the block, before it narrows at the edges of its areas and limits. */
|
||||
private double fullHeightRadiusAt(Pass pass, double shareX, double shareY, double shareZ, double widthShare) {
|
||||
if (heightKind == TunnelHeight.OWN_NOISE) {
|
||||
return pass.cell(heightField).at(shareX, shareY, shareZ) / 2D;
|
||||
}
|
||||
return lowRadius + ((tallRadius - lowRadius) * widthShare);
|
||||
}
|
||||
|
||||
/** How far the block lies into an area with tunnels: 1 inside, falling to 0 over the edge. */
|
||||
private double presenceShareAt(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
if (presence == null) {
|
||||
return 1D;
|
||||
}
|
||||
return clampToShare((pass.cell(presenceField).at(shareX, shareY, shareZ) - presenceThreshold) / presenceEdge);
|
||||
}
|
||||
|
||||
private static double clampToShare(double value) {
|
||||
return Math.max(0D, Math.min(1D, value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveValue;
|
||||
|
||||
/**
|
||||
* A {@link CaveValue} ready to read at a place: the same number everywhere, or the number its noise picks there. The
|
||||
* noise's middle picks the middle of the range and the value reaches min and max half a unit either side of it, so a
|
||||
* range has stretches at each end as well as the slopes between them.
|
||||
*/
|
||||
final class ValueField {
|
||||
private static final double MIDDLE_SHARE = 0.5D;
|
||||
|
||||
private final double min;
|
||||
private final double max;
|
||||
private final Field3 noise;
|
||||
|
||||
private ValueField(double min, double max, Field3 noise) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.noise = noise;
|
||||
}
|
||||
|
||||
static ValueField constant(double value) {
|
||||
return new ValueField(value, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code value} read in 3D, under its own seed of {@code name}. Without a style it changes over about
|
||||
* {@code changeBlocks} blocks in every direction.
|
||||
*/
|
||||
static ValueField inBlocks(CaveValue value, CaveNoise caveNoise, String name, double changeBlocks) {
|
||||
if (!value.varies()) {
|
||||
return constant(value.min());
|
||||
}
|
||||
CaveNoise noise = caveNoise.named(name);
|
||||
Field3 field = value.style().map(noise::inBlocks).orElseGet(() -> noise.smooth(changeBlocks, changeBlocks));
|
||||
return new ValueField(value.min(), value.max(), field);
|
||||
}
|
||||
|
||||
/** {@link #inBlocks} for a value that only varies over X and Z. */
|
||||
static ValueField inColumns(CaveValue value, CaveNoise caveNoise, String name, double changeBlocks) {
|
||||
if (!value.varies()) {
|
||||
return constant(value.min());
|
||||
}
|
||||
CaveNoise noise = caveNoise.named(name);
|
||||
Field3 field = value.style().map(noise::columnsInBlocks).orElseGet(() -> noise.columns(changeBlocks));
|
||||
return new ValueField(value.min(), value.max(), field);
|
||||
}
|
||||
|
||||
/** The share of the way from min to max that a noise value picks, from 0 to 1. */
|
||||
static double shareAt(double signedNoise) {
|
||||
return Math.max(0D, Math.min(1D, MIDDLE_SHARE + signedNoise));
|
||||
}
|
||||
|
||||
boolean varies() {
|
||||
return noise != null;
|
||||
}
|
||||
|
||||
double min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
double max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
double middle() {
|
||||
return (min + max) / 2D;
|
||||
}
|
||||
|
||||
double lowest() {
|
||||
return Math.min(min, max);
|
||||
}
|
||||
|
||||
double highest() {
|
||||
return Math.max(min, max);
|
||||
}
|
||||
|
||||
double at(double x, double y, double z) {
|
||||
if (noise == null) {
|
||||
return min;
|
||||
}
|
||||
return min + ((max - min) * shareAt(noise.at(x, y, z)));
|
||||
}
|
||||
|
||||
/** How far from min towards max the value is here, from 0 to 1; 0 where it does not vary. */
|
||||
double share(double x, double y, double z) {
|
||||
return noise == null ? 0D : shareAt(noise.at(x, y, z));
|
||||
}
|
||||
|
||||
/** {@link #at} for a value read in columns. */
|
||||
double at(double x, double z) {
|
||||
return at(x, 0D, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.cave.field;
|
||||
|
||||
/**
|
||||
* A field whose features' size varies from place to place. A noise read at a scale that changes along the way shears
|
||||
* and tears, so the scale a field is read at never changes: a field is built at the smallest and at the largest size
|
||||
* and the two are blended, horizontal and vertical sizes alike. Each size that varies doubles the fields read.
|
||||
*/
|
||||
final class VaryingScale {
|
||||
/** Builds a field whose features lie about {@code horizontal} blocks apart sideways and {@code vertical} blocks apart upwards. */
|
||||
@FunctionalInterface
|
||||
interface Builder {
|
||||
Field3 build(CaveNoise noise, double horizontal, double vertical);
|
||||
}
|
||||
|
||||
private VaryingScale() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The field {@code builder} makes at the sizes {@code horizontal} and {@code vertical} pick. The smallest field
|
||||
* takes the seeds of {@code noise}, so a field whose sizes are plain numbers is exactly the one the builder makes;
|
||||
* the others are seeded by {@code name}.
|
||||
*/
|
||||
static Field3 of(CaveNoise noise, ValueField horizontal, ValueField vertical, String name, Builder builder) {
|
||||
Field3 lowest = alongHorizontal(noise, horizontal, vertical.min(), name, builder);
|
||||
if (!vertical.varies()) {
|
||||
return lowest;
|
||||
}
|
||||
Field3 tallest = alongHorizontal(noise.named(name + ".tallest"), horizontal, vertical.max(), name, builder);
|
||||
return blended(lowest, tallest, vertical);
|
||||
}
|
||||
|
||||
private static Field3 alongHorizontal(CaveNoise noise, ValueField horizontal, double vertical, String name, Builder builder) {
|
||||
Field3 smallest = builder.build(noise, horizontal.min(), vertical);
|
||||
if (!horizontal.varies()) {
|
||||
return smallest;
|
||||
}
|
||||
Field3 largest = builder.build(noise.named(name + ".largest"), horizontal.max(), vertical);
|
||||
return blended(smallest, largest, horizontal);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code atMin} where {@code scale} is at its min, {@code atMax} where it is at its max, and both in between,
|
||||
* weighted so the blend spreads as far as either field alone and a threshold keeps its share.
|
||||
*/
|
||||
private static Field3 blended(Field3 atMin, Field3 atMax, ValueField scale) {
|
||||
return (x, y, z) -> {
|
||||
double towardsMax = scale.share(x, y, z);
|
||||
double towardsMin = 1D - towardsMax;
|
||||
double spread = Math.sqrt((towardsMin * towardsMin) + (towardsMax * towardsMax));
|
||||
return ((atMin.at(x, y, z) * towardsMin) + (atMax.at(x, y, z) * towardsMax)) / spread;
|
||||
};
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.studio.scene.SceneBlocks;
|
||||
import art.arcane.iris.studio.scene.SceneEntry;
|
||||
import art.arcane.iris.studio.scene.SceneForm;
|
||||
import art.arcane.iris.studio.scene.SceneRequest;
|
||||
import art.arcane.iris.studio.scene.SceneView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
/** How each formation profile shapes a formation's width from base to top. */
|
||||
public final class FormationProfileSceneView implements SceneView {
|
||||
private static final Set<String> HIDDEN = Set.of("name", "chance", "density", "variants", "seed", "mode", "carvingSupport",
|
||||
"surfaceSupportBuffer", "underwater", "profile");
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "formationProfiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Formation profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "How each formation profile shapes a formation's width from base to top";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneEntry> entries(Engine engine) {
|
||||
int variants = new IrisFormation().getVariants();
|
||||
return Arrays.stream(IrisFormationProfile.values()).map(profile -> SceneEntry.preset(profile, variants)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasForm() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneForm form(Engine engine, String key, Map<String, String> overrides) {
|
||||
return SceneForm.of("Formation", formationOf(key, overrides), HIDDEN, overrides,
|
||||
List.of(SceneForm.describe(profileOf(key)), "Values typed here change the preview only"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBlocks scene(Engine engine, SceneRequest request) {
|
||||
IrisFormation formation = formationOf(request.key(), request.overrides());
|
||||
return SceneBlocks.ofVariant(formation.getVariantObjects(engine.getData()), request.variant(), "formation");
|
||||
}
|
||||
|
||||
private static IrisFormation formationOf(String key, Map<String, String> overrides) {
|
||||
IrisFormation formation = SceneForm.withOverrides(new IrisFormation(), overrides);
|
||||
formation.setProfile(profileOf(key));
|
||||
return formation;
|
||||
}
|
||||
|
||||
private static IrisFormationProfile profileOf(String key) {
|
||||
try {
|
||||
return IrisFormationProfile.valueOf(key);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
throw new NoSuchElementException("No formation profile " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package art.arcane.iris.generation.decoration.tree;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.studio.scene.SceneBlocks;
|
||||
import art.arcane.iris.studio.scene.SceneEntry;
|
||||
import art.arcane.iris.studio.scene.SceneForm;
|
||||
import art.arcane.iris.studio.scene.SceneRequest;
|
||||
import art.arcane.iris.studio.scene.SceneView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
/** The canopy shape each tree profile gives a procedural tree. */
|
||||
public final class TreeProfileSceneView implements SceneView {
|
||||
private static final Set<String> HIDDEN = Set.of("name", "chance", "density", "variants", "seed", "plausible", "mode",
|
||||
"carvingSupport", "underwater", "profile");
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "treeProfiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Tree profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "The canopy shape each tree profile gives a procedural tree";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneEntry> entries(Engine engine) {
|
||||
int variants = new IrisProceduralTree().getVariants();
|
||||
return Arrays.stream(IrisTreeProfile.values()).map(profile -> SceneEntry.preset(profile, variants)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasForm() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneForm form(Engine engine, String key, Map<String, String> overrides) {
|
||||
return SceneForm.of("Tree", treeOf(key, overrides), HIDDEN, overrides,
|
||||
List.of(SceneForm.describe(profileOf(key)), "Values typed here change the preview only"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBlocks scene(Engine engine, SceneRequest request) {
|
||||
IrisProceduralTree tree = treeOf(request.key(), request.overrides());
|
||||
return SceneBlocks.ofVariant(tree.getVariantObjects(engine.getData()), request.variant(), "tree");
|
||||
}
|
||||
|
||||
private static IrisProceduralTree treeOf(String key, Map<String, String> overrides) {
|
||||
IrisProceduralTree tree = SceneForm.withOverrides(new IrisProceduralTree(), overrides);
|
||||
tree.setProfile(profileOf(key));
|
||||
return tree;
|
||||
}
|
||||
|
||||
private static IrisTreeProfile profileOf(String key) {
|
||||
try {
|
||||
return IrisTreeProfile.valueOf(key);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
throw new NoSuchElementException("No tree profile " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package art.arcane.iris.generation.hydrology.config;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.scene.SceneBlocks;
|
||||
import art.arcane.iris.studio.scene.SceneEntry;
|
||||
import art.arcane.iris.studio.scene.SceneForm;
|
||||
import art.arcane.iris.studio.scene.SceneRequest;
|
||||
import art.arcane.iris.studio.scene.SceneSizes;
|
||||
import art.arcane.iris.studio.scene.SceneView;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
/** The blocks of each named fluid of the dimension's hydrology, in a pool lined with its seam. */
|
||||
public final class FluidProfileSceneView implements SceneView {
|
||||
private static final SceneSizes SIZES = new SceneSizes(List.of(16, 32, 64), 32);
|
||||
private static final int VARIANTS = 4;
|
||||
private static final int VARIANT_SPACING_BLOCKS = 1024;
|
||||
private static final int DEPTH_BLOCKS = 3;
|
||||
private static final String BASIN_BLOCK = "minecraft:stone";
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "fluidProfiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Fluid profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "The blocks of each named fluid of the dimension's hydrology, in a pool lined with its seam";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneSizes sizes() {
|
||||
return SIZES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneEntry> entries(Engine engine) {
|
||||
return fluids(engine).stream().map(fluid -> new SceneEntry(fluid.getName(), fluid.getName(), "Fluids", VARIANTS)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasForm() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneForm form(Engine engine, String key, Map<String, String> overrides) {
|
||||
IrisFluidProfile fluid = fluidOf(engine, key);
|
||||
IrisData data = engine.getData();
|
||||
List<String> notes = new ArrayList<>();
|
||||
notes.add("Blocks: " + String.join(", ", fluid.getPalette().getBlockData(data).stream().map(state -> state.key()).toList()));
|
||||
notes.add("Seam: " + (fluid.getSeam() == null ? "none" : fluid.getSeam()));
|
||||
return new SceneForm("Fluid", List.of(), notes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBlocks scene(Engine engine, SceneRequest request) {
|
||||
IrisData data = engine.getData();
|
||||
IrisFluidProfile fluid = fluidOf(engine, request.key());
|
||||
IrisFluidProfile seam = fluid.getSeam() == null ? null : fluidOf(engine, fluid.getSeam());
|
||||
int size = request.size();
|
||||
int offset = Math.floorMod(request.variant(), VARIANTS) * VARIANT_SPACING_BLOCKS;
|
||||
RNG rng = new RNG(offset + 1L);
|
||||
SceneBlocks scene = new SceneBlocks();
|
||||
for (int z = 0; z < size; z++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
scene.add(x, 0, z, BASIN_BLOCK);
|
||||
boolean wall = x == 0 || z == 0 || x == size - 1 || z == size - 1;
|
||||
boolean seamRing = seam != null && (x == 1 || z == 1 || x == size - 2 || z == size - 2);
|
||||
for (int y = 1; y <= DEPTH_BLOCKS; y++) {
|
||||
IrisFluidProfile filling = seamRing ? seam : fluid;
|
||||
scene.add(x, y, z, wall ? BASIN_BLOCK : filling.getPalette().get(rng, x + offset, y, z, data).key());
|
||||
}
|
||||
}
|
||||
}
|
||||
return scene;
|
||||
}
|
||||
|
||||
private static KList<IrisFluidProfile> fluids(Engine engine) {
|
||||
return engine.getDimension().getHydrology().getFluids();
|
||||
}
|
||||
|
||||
private static IrisFluidProfile fluidOf(Engine engine, String key) {
|
||||
Optional<IrisFluidProfile> found = fluids(engine).stream().filter(fluid -> key.equals(fluid.getName())).findFirst();
|
||||
return found.orElseThrow(() -> new NoSuchElementException("No fluid profile " + key));
|
||||
}
|
||||
}
|
||||
@@ -293,13 +293,13 @@ public final class IrisImageMapRuntime {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
if (region.getLandBiomes().contains(biomeKey)) {
|
||||
if (region.getLandBiomeKeys().contains(biomeKey)) {
|
||||
types.add(InferredType.LAND);
|
||||
}
|
||||
if (region.getSeaBiomes().contains(biomeKey)) {
|
||||
if (region.getSeaBiomeKeys().contains(biomeKey)) {
|
||||
types.add(InferredType.SEA);
|
||||
}
|
||||
if (region.getShoreBiomes().contains(biomeKey)) {
|
||||
if (region.getShoreBiomeKeys().contains(biomeKey)) {
|
||||
types.add(InferredType.SHORE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,16 +71,16 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
Set<String> caveHosts = new HashSet<>();
|
||||
boolean surfaceAllowed = GenerationFindCatalog.hasRetainedSurfaceBiome(engine, key);
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
for (String root : region.getLandBiomes()) {
|
||||
for (String root : region.getLandBiomeKeys()) {
|
||||
surfaceAllowed |= caveBranch(engine, root).contains(key);
|
||||
}
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
for (String root : region.getSeaBiomeKeys()) {
|
||||
surfaceAllowed |= caveBranch(engine, root).contains(key);
|
||||
}
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
for (String root : region.getShoreBiomeKeys()) {
|
||||
surfaceAllowed |= caveBranch(engine, root).contains(key);
|
||||
}
|
||||
for (String root : region.getCaveBiomes()) {
|
||||
for (String root : region.getCaveBiomeKeys()) {
|
||||
Set<String> branch = caveBranch(engine, root);
|
||||
if (branch.contains(key)) {
|
||||
caveHosts.addAll(branch);
|
||||
@@ -122,7 +122,7 @@ public final class BiomeLocator implements Locator<IrisBiome> {
|
||||
}
|
||||
IrisBiome biome = engine.getData().getBiomeLoader().load(candidate);
|
||||
if (biome != null) {
|
||||
pending.addAll(biome.getChildren());
|
||||
pending.addAll(biome.getChildKeys());
|
||||
}
|
||||
}
|
||||
return visited;
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class BiomeSearchFilter {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
for (String key : region.getCaveBiomes()) {
|
||||
for (String key : region.getCaveBiomeKeys()) {
|
||||
if (target(key)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
|
||||
KSet<String> caveRegions = new KSet<>();
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
if (region != null && region.getCaveBiomes().contains(biomeKey)) {
|
||||
if (region != null && region.getCaveBiomeKeys().contains(biomeKey)) {
|
||||
caveRegions.add(region.getLoadKey());
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
KSet<String> caveRegions = new KSet<>();
|
||||
|
||||
for (IrisRegion region : engine.getDimension().getAllRegions(engine)) {
|
||||
if (region != null && region.getCaveBiomes().contains(biomeKey)) {
|
||||
if (region != null && region.getCaveBiomeKeys().contains(biomeKey)) {
|
||||
caveRegions.add(region.getLoadKey());
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
if (!engine.getDimension().getRegions().contains(regionKey)) {
|
||||
if (!engine.getDimension().getRegionKeys().contains(regionKey)) {
|
||||
return SearchPlan.impossible();
|
||||
}
|
||||
|
||||
@@ -482,21 +482,21 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
|
||||
boolean hosted = false;
|
||||
|
||||
for (String root : region.getLandBiomes()) {
|
||||
for (String root : region.getLandBiomeKeys()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
landHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
for (String root : region.getSeaBiomeKeys()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
seaHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
for (String root : region.getShoreBiomeKeys()) {
|
||||
if (source.closurePlacesObject(root, objectKey)) {
|
||||
shoreHosts.add(root);
|
||||
hosted = true;
|
||||
@@ -546,21 +546,21 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
|
||||
boolean hosted = false;
|
||||
|
||||
for (String root : region.getLandBiomes()) {
|
||||
for (String root : region.getLandBiomeKeys()) {
|
||||
if (source.closureContains(root, biomeKeys)) {
|
||||
landHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getSeaBiomes()) {
|
||||
for (String root : region.getSeaBiomeKeys()) {
|
||||
if (source.closureContains(root, biomeKeys)) {
|
||||
seaHosts.add(root);
|
||||
hosted = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String root : region.getShoreBiomes()) {
|
||||
for (String root : region.getShoreBiomeKeys()) {
|
||||
if (source.closureContains(root, biomeKeys)) {
|
||||
shoreHosts.add(root);
|
||||
hosted = true;
|
||||
@@ -689,7 +689,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String child : biome.getChildren()) {
|
||||
for (String child : biome.getChildKeys()) {
|
||||
if (child != null && !visited.contains(child)) {
|
||||
queue.add(child);
|
||||
}
|
||||
@@ -720,7 +720,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
continue;
|
||||
}
|
||||
biomes.add(biome);
|
||||
for (String child : biome.getChildren()) {
|
||||
for (String child : biome.getChildKeys()) {
|
||||
if (child != null && !visited.contains(child)) {
|
||||
queue.add(child);
|
||||
}
|
||||
@@ -755,7 +755,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String child : biome.getChildren()) {
|
||||
for (String child : biome.getChildKeys()) {
|
||||
if (child != null && !visited.contains(child)) {
|
||||
queue.add(child);
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
final class CaveCarveScratch {
|
||||
final int[] columnMaxY = new int[256];
|
||||
final int[] fluidMaxY = new int[256];
|
||||
final int[] surfaceBreakFloorY = new int[256];
|
||||
final boolean[] surfaceBreakColumn = new boolean[256];
|
||||
final boolean[] surfaceCeilingColumn = new boolean[256];
|
||||
final double[] columnThreshold = new double[256];
|
||||
final double[] passThreshold = new double[256];
|
||||
final double[] fullWeights = new double[256];
|
||||
final double[] clampedColumnWeights = new double[256];
|
||||
final int[] activeColumnIndices = new int[256];
|
||||
final int[] activeColumnTopY = new int[256];
|
||||
final int[] planeColumnIndices = new int[256];
|
||||
final double[] planeThresholdLimit = new double[256];
|
||||
final boolean[] planeCarve = new boolean[256];
|
||||
final double[] adaptivePlaneDensity = new double[81];
|
||||
final CaveDensityGrid.Column[] densityColumns = new CaveDensityGrid.Column[16];
|
||||
double[] verticalDensityLower = new double[9];
|
||||
double[] verticalDensityUpper = new double[9];
|
||||
int verticalDensityLowerY = Integer.MIN_VALUE;
|
||||
int verticalDensityUpperY = Integer.MIN_VALUE;
|
||||
int verticalDensityX;
|
||||
int verticalDensityZ;
|
||||
final double[] adaptivePlanePrediction = new double[256];
|
||||
final double[] adaptivePlaneAmbiguity = new double[256];
|
||||
final int[] adaptivePlaneSampleBounds = new int[4];
|
||||
final int[] adaptiveCellX = new int[256];
|
||||
final int[] adaptiveCellZ = new int[256];
|
||||
final int[] adaptiveRow0 = new int[256];
|
||||
final int[] adaptiveRow1 = new int[256];
|
||||
final double[] adaptiveTx = new double[256];
|
||||
final double[] adaptiveTz = new double[256];
|
||||
final boolean[] warpCacheSet = new boolean[256];
|
||||
final int[] warpCacheX = new int[256];
|
||||
final int[] warpCacheY = new int[256];
|
||||
final int[] warpCacheZ = new int[256];
|
||||
final double[] warpCacheA = new double[256];
|
||||
final double[] warpCacheB = new double[256];
|
||||
final int[] tileIndices = new int[4];
|
||||
final int[] tileLocalX = new int[4];
|
||||
final int[] tileLocalZ = new int[4];
|
||||
final int[] tileTopY = new int[4];
|
||||
final long[] rowCarveBits = new long[4];
|
||||
final long[] cellPassBits = new long[4];
|
||||
final CaveDensityLattice cellLattice = new CaveDensityLattice();
|
||||
final double[] cellThresholdMin = new double[4];
|
||||
final double[] cellThresholdMax = new double[4];
|
||||
final double[] cellThresholdMaxBoost = new double[4];
|
||||
final int[] cellBreakFloorMin = new int[4];
|
||||
final int[] cellCeilingFadeStart = new int[4];
|
||||
final int[] cellTopY = new int[4];
|
||||
final int[] cellMinTopY = new int[4];
|
||||
final boolean[] cellProtected = new boolean[4];
|
||||
final int[] columnProtectStartY = new int[256];
|
||||
final int[] columnProtectEndY = new int[256];
|
||||
int[] rowActiveCount = new int[0];
|
||||
long solidCells;
|
||||
long openCells;
|
||||
long mixedCells;
|
||||
long exactRows;
|
||||
CaveFieldModuleState[] activeModules = new CaveFieldModuleState[0];
|
||||
double[] activeModuleRemainingMin = new double[0];
|
||||
double[] activeModuleRemainingMax = new double[0];
|
||||
int activeModulesY = Integer.MIN_VALUE;
|
||||
int activeModuleCount;
|
||||
double[] verticalEdgeFade = new double[0];
|
||||
double[] surfaceClosureThreshold = new double[0];
|
||||
MatterCavern[] matterByY = new MatterCavern[0];
|
||||
Matter[] sectionMatter = new Matter[0];
|
||||
MatterSlice<?>[] sectionSlices = new MatterSlice<?>[0];
|
||||
int adaptiveGeometryStep = -1;
|
||||
int adaptiveGeometryAxisCells = -1;
|
||||
boolean fullWeightsInitialized;
|
||||
|
||||
void releaseReferences() {
|
||||
Arrays.fill(sectionMatter, null);
|
||||
Arrays.fill(sectionSlices, null);
|
||||
Arrays.fill(densityColumns, null);
|
||||
cellLattice.releaseReferences();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
final class CaveCellKernel {
|
||||
static final int NONE = 0;
|
||||
static final int ALL = 1;
|
||||
static final int MIXED = 2;
|
||||
private static final double GUARD_ULPS = 32D;
|
||||
private static final double MAXIMUM_MAGNITUDE = 0x1p500;
|
||||
|
||||
private CaveCellKernel() {
|
||||
}
|
||||
|
||||
static int decide(double d00, double d01, double d10, double d11, double thresholdLow, double thresholdHigh) {
|
||||
double low = Math.min(Math.min(d00, d01), Math.min(d10, d11));
|
||||
double high = Math.max(Math.max(d00, d01), Math.max(d10, d11));
|
||||
double magnitude = Math.max(Math.abs(low), Math.abs(high));
|
||||
if (!(magnitude < MAXIMUM_MAGNITUDE)) {
|
||||
return MIXED;
|
||||
}
|
||||
double guard = Math.ulp(magnitude) * GUARD_ULPS;
|
||||
if (high + guard <= thresholdLow) {
|
||||
return ALL;
|
||||
}
|
||||
if (low - guard > thresholdHigh) {
|
||||
return NONE;
|
||||
}
|
||||
return MIXED;
|
||||
}
|
||||
|
||||
static double threshold(double localThreshold, double normalizationFactor, double inverseNormalization) {
|
||||
return (localThreshold * normalizationFactor) * inverseNormalization;
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -16,11 +16,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.map.components;
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import java.awt.Color;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
/** Takes the carved blocks of a chunk, by their place in it and their height from the dimension's bottom. */
|
||||
@FunctionalInterface
|
||||
public interface Renderer {
|
||||
Color draw(double x, double z);
|
||||
interface CaveCellSink {
|
||||
void set(int localX, int y, int localZ, MatterCavern cell);
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cache.ConcurrentClockCache;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
/**
|
||||
* Shares the adaptive cave planes' 8-block density lattice between neighbouring chunks. Every lattice column on a
|
||||
* chunk edge is sampled by two chunks and every corner by four, with identical coordinates and carver noise, so a
|
||||
* value computed once is reused bit for bit. Racing writers store the same value.
|
||||
*/
|
||||
final class CaveDensityGrid {
|
||||
static final int LATTICE_SHIFT = 3;
|
||||
private static final int SEGMENT_SHIFT = 5;
|
||||
private static final int SEGMENT_SIZE = 1 << SEGMENT_SHIFT;
|
||||
private static final long COORDINATE_MASK = 0xFFFFFFL;
|
||||
private static final VarHandle VALUES = MethodHandles.arrayElementVarHandle(double[].class);
|
||||
private static final AtomicInteger OWNERS = new AtomicInteger();
|
||||
|
||||
private final ConcurrentClockCache<Column> columns;
|
||||
private final ConcurrentClockCache<Column> warpColumns;
|
||||
private final ConcurrentHashMap<Object, Owner> owners = new ConcurrentHashMap<>();
|
||||
|
||||
CaveDensityGrid(int capacity) {
|
||||
columns = new ConcurrentClockCache<>(capacity);
|
||||
warpColumns = new ConcurrentClockCache<>(Math.max(1, capacity >> 2));
|
||||
}
|
||||
|
||||
Owner owner(Object fieldKey) {
|
||||
return owners.computeIfAbsent(fieldKey, ignored -> new Owner(OWNERS.getAndIncrement()));
|
||||
}
|
||||
|
||||
Column column(Owner owner, int height, int latticeX, int latticeZ) {
|
||||
return column(columns, owner, height, latticeX, latticeZ);
|
||||
}
|
||||
|
||||
Column warpColumn(Owner owner, int height, int latticeX, int latticeZ) {
|
||||
return column(warpColumns, owner, height, latticeX, latticeZ);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
columns.clear();
|
||||
warpColumns.clear();
|
||||
owners.clear();
|
||||
}
|
||||
|
||||
private static Column column(ConcurrentClockCache<Column> cache, Owner owner, int height, int latticeX, int latticeZ) {
|
||||
long key = (long) (owner.id & 0xFFFF) << 48 | (latticeX & COORDINATE_MASK) << 24 | (latticeZ & COORDINATE_MASK);
|
||||
Column cached = cache.get(key);
|
||||
if (cached == null) {
|
||||
cached = cache.putIfAbsent(key, new Column(owner, latticeX, latticeZ, height));
|
||||
}
|
||||
return cached.matches(owner, latticeX, latticeZ) ? cached : null;
|
||||
}
|
||||
|
||||
static final class Owner {
|
||||
private final int id;
|
||||
|
||||
private Owner(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Column {
|
||||
private final Owner owner;
|
||||
private final int latticeX;
|
||||
private final int latticeZ;
|
||||
private final AtomicReferenceArray<double[]> segments;
|
||||
|
||||
private Column(Owner owner, int latticeX, int latticeZ, int height) {
|
||||
this.owner = owner;
|
||||
this.latticeX = latticeX;
|
||||
this.latticeZ = latticeZ;
|
||||
segments = new AtomicReferenceArray<>(Math.ceilDiv(Math.max(1, height), SEGMENT_SIZE));
|
||||
}
|
||||
|
||||
boolean matches(Owner owner, int latticeX, int latticeZ) {
|
||||
return this.owner == owner && this.latticeX == latticeX && this.latticeZ == latticeZ;
|
||||
}
|
||||
|
||||
double get(int y) {
|
||||
int segment = y >> SEGMENT_SHIFT;
|
||||
if (segment >= segments.length()) {
|
||||
return Double.NaN;
|
||||
}
|
||||
double[] values = segments.getAcquire(segment);
|
||||
return values == null ? Double.NaN : (double) VALUES.getOpaque(values, y & (SEGMENT_SIZE - 1));
|
||||
}
|
||||
|
||||
void set(int y, double value) {
|
||||
int segment = y >> SEGMENT_SHIFT;
|
||||
if (segment >= segments.length()) {
|
||||
return;
|
||||
}
|
||||
double[] values = segments.getAcquire(segment);
|
||||
if (values == null) {
|
||||
double[] created = new double[SEGMENT_SIZE];
|
||||
Arrays.fill(created, Double.NaN);
|
||||
double[] published = segments.compareAndExchange(segment, null, created);
|
||||
values = published == null ? created : published;
|
||||
}
|
||||
VALUES.setOpaque(values, y & (SEGMENT_SIZE - 1), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
final class CaveDensityLattice {
|
||||
static final int CORNERS = 9;
|
||||
|
||||
final CaveDensityGrid.Column[] densityColumns = new CaveDensityGrid.Column[CORNERS];
|
||||
final CaveDensityGrid.Column[] warpColumns = new CaveDensityGrid.Column[CORNERS];
|
||||
private double[] values = new double[0];
|
||||
private byte[] rowCells = new byte[0];
|
||||
private short[] rowCorners = new short[0];
|
||||
private int minimumY;
|
||||
private int rows;
|
||||
|
||||
void reset(int minimumY, int rows) {
|
||||
this.minimumY = minimumY;
|
||||
this.rows = rows;
|
||||
if (rowCells.length < rows) {
|
||||
rowCells = new byte[rows];
|
||||
rowCorners = new short[rows];
|
||||
}
|
||||
if (values.length < rows * CORNERS) {
|
||||
values = new double[rows * CORNERS];
|
||||
}
|
||||
Arrays.fill(rowCells, 0, rows, (byte) 0);
|
||||
Arrays.fill(rowCorners, 0, rows, (short) 0);
|
||||
}
|
||||
|
||||
void markRow(int y, int cells, int corners) {
|
||||
int row = y - minimumY;
|
||||
rowCells[row] = (byte) cells;
|
||||
rowCorners[row] = (short) corners;
|
||||
}
|
||||
|
||||
int cells(int y) {
|
||||
return rowCells[y - minimumY];
|
||||
}
|
||||
|
||||
boolean needs(int corner, int y) {
|
||||
return (rowCorners[y - minimumY] & (1 << corner)) != 0;
|
||||
}
|
||||
|
||||
double density(int corner, int y) {
|
||||
return values[corner * rows + (y - minimumY)];
|
||||
}
|
||||
|
||||
void store(int corner, int y, double density) {
|
||||
values[corner * rows + (y - minimumY)] = density;
|
||||
}
|
||||
|
||||
void releaseReferences() {
|
||||
Arrays.fill(densityColumns, null);
|
||||
Arrays.fill(warpColumns, null);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.volmlib.util.noise.program.NoiseProgram;
|
||||
import art.arcane.volmlib.util.noise.program.PrimitiveKind;
|
||||
|
||||
record CaveFieldKey(long signature, long probe, NoiseProgram identity) {
|
||||
private static final double[][] PROBE_POINTS = {
|
||||
{0.5D, 3.25D, -7.75D},
|
||||
{-1031.125D, 77.5D, 2049.875D},
|
||||
{16D, 255D, -16D},
|
||||
{123_456.375D, -40.25D, -98_765.625D}
|
||||
};
|
||||
|
||||
static CaveFieldKey of(NoiseProgram program) {
|
||||
if (!shareable(program)) {
|
||||
return new CaveFieldKey(program.structuralSignature(), 0L, program);
|
||||
}
|
||||
long probe = 0xCBF29CE484222325L;
|
||||
for (double[] point : PROBE_POINTS) {
|
||||
probe = (probe ^ Double.doubleToRawLongBits(program.sampleSigned3D(point[0], point[1], point[2]))) * 0x100000001B3L;
|
||||
}
|
||||
return new CaveFieldKey(program.structuralSignature(), probe, null);
|
||||
}
|
||||
|
||||
private static boolean shareable(NoiseProgram program) {
|
||||
for (int node = 0; node < program.nodeCount(); node++) {
|
||||
if (program.nodeOpaque(node) || program.nodeKernel(node).kind() == PrimitiveKind.GENERIC) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.volmlib.util.noise.program.NoiseProgram;
|
||||
|
||||
final class CaveFieldModuleState {
|
||||
final NoiseProgram density;
|
||||
final int minY;
|
||||
final int maxY;
|
||||
final double weight;
|
||||
final double threshold;
|
||||
final boolean invert;
|
||||
final double minContribution;
|
||||
final double maxContribution;
|
||||
|
||||
CaveFieldModuleState(IrisCaveFieldModule module, NoiseProgram density) {
|
||||
IrisRange range = module.getVerticalRange();
|
||||
this.density = density;
|
||||
this.minY = (int) Math.floor(range.getMin());
|
||||
this.maxY = (int) Math.ceil(range.getMax());
|
||||
this.weight = module.getWeight();
|
||||
this.threshold = module.getThreshold();
|
||||
this.invert = module.isInvert();
|
||||
double rawMin = invert ? threshold - 1D : -1D - threshold;
|
||||
double rawMax = invert ? threshold + 1D : 1D - threshold;
|
||||
this.minContribution = rawMin * weight;
|
||||
this.maxContribution = rawMax * weight;
|
||||
}
|
||||
|
||||
double sample(double x, int y, double z) {
|
||||
double sampled = density.sampleSigned3D(x, y, z);
|
||||
return invert ? (threshold - sampled) * weight : (sampled - threshold) * weight;
|
||||
}
|
||||
|
||||
double sample(double x, double y, double z) {
|
||||
double sampled = density.sampleSigned3D(x, y, z);
|
||||
return invert ? (threshold - sampled) * weight : (sampled - threshold) * weight;
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ final class CaveFluidSupportPlan {
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
MatterCavern current = getCavern(chunk, localX, y, localZ);
|
||||
if (current != group.fluid || hasCupSupport(chunk, localX, y, localZ)) {
|
||||
if (!group.fluid.equals(current) || hasCupSupport(chunk, localX, y, localZ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.volmlib.util.noise.program.NoiseScratch;
|
||||
|
||||
final class CaveLatticeBatch {
|
||||
private static final ThreadLocal<CaveLatticeBatch> CURRENT = ThreadLocal.withInitial(CaveLatticeBatch::new);
|
||||
|
||||
final NoiseScratch noise = new NoiseScratch();
|
||||
final int[] cornerStart = new int[CaveDensityLattice.CORNERS + 1];
|
||||
final int[] snapStart = new int[CaveDensityLattice.CORNERS + 1];
|
||||
int[] y = new int[0];
|
||||
int[] snapY = new int[0];
|
||||
boolean[] snapMissing = new boolean[0];
|
||||
double[] warpA = new double[0];
|
||||
double[] warpB = new double[0];
|
||||
double[] warpedX = new double[0];
|
||||
double[] warpedY = new double[0];
|
||||
double[] warpedZ = new double[0];
|
||||
double[] density = new double[0];
|
||||
double[] values = new double[0];
|
||||
double[] pointX = new double[0];
|
||||
double[] pointY = new double[0];
|
||||
double[] pointZ = new double[0];
|
||||
int[] pointIndex = new int[0];
|
||||
private CaveLatticeBatch nested;
|
||||
private boolean active;
|
||||
|
||||
static CaveLatticeBatch acquire() {
|
||||
CaveLatticeBatch batch = CURRENT.get();
|
||||
while (batch.active) {
|
||||
if (batch.nested == null) {
|
||||
batch.nested = new CaveLatticeBatch();
|
||||
}
|
||||
batch = batch.nested;
|
||||
}
|
||||
batch.active = true;
|
||||
return batch;
|
||||
}
|
||||
|
||||
void release() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
void ensure(int size) {
|
||||
if (y.length >= size) {
|
||||
return;
|
||||
}
|
||||
y = new int[size];
|
||||
snapY = new int[size];
|
||||
snapMissing = new boolean[size];
|
||||
warpA = new double[size];
|
||||
warpB = new double[size];
|
||||
warpedX = new double[size];
|
||||
warpedY = new double[size];
|
||||
warpedZ = new double[size];
|
||||
density = new double[size];
|
||||
values = new double[size * 2];
|
||||
pointX = new double[size * 2];
|
||||
pointY = new double[size * 2];
|
||||
pointZ = new double[size * 2];
|
||||
pointIndex = new int[size * 2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cave.field.HeightBand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The caves that carve in one chunk, in the order they were listed: the first cave listed owns a block that several carve.
|
||||
*
|
||||
* @param caves each listed cave with how much each column lists it
|
||||
* @param opensToSurface whether any of the caves cuts through the surface
|
||||
*/
|
||||
record CaveListing(List<ListedColumns> caves, boolean opensToSurface) {
|
||||
boolean isEmpty() {
|
||||
return caves.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cave the cave
|
||||
* @param weight how much each column of the chunk lists the cave, from 0 to 1, indexed as {@code (localX << 4) | localZ}
|
||||
* @param band the heights the cave is limited to, from the dimension's bottom; unlimited unless a carving band lists it
|
||||
*/
|
||||
record ListedColumns(ListedCave cave, double[] weight, HeightBand band) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** What listed cave carving reads of the world around a chunk. */
|
||||
interface CaveTerrain {
|
||||
/** The region, surface biome and cave biome that decide which caves carve at the column. */
|
||||
CavePlace placeAt(int worldX, int worldZ);
|
||||
|
||||
/**
|
||||
* The cave biomes that dimension carving entries put at each column of the chunk, one band of world heights at a
|
||||
* time. Caves a band's biome lists carve only inside that band.
|
||||
*/
|
||||
List<CaveBand> bandsOf(int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* @param region the region of the column
|
||||
* @param surfaceBiome the biome at the surface of the column
|
||||
* @param caveBiome the cave biome the column's caves belong to: the surface biome where the cave is too shallow to
|
||||
* have its own, as {@code caveMinDepthBelowSurface} says
|
||||
*/
|
||||
record CavePlace(IrisRegion region, IrisBiome surfaceBiome, IrisBiome caveBiome) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lowestWorldY lowest world height of the band
|
||||
* @param highestWorldY highest world height of the band, included
|
||||
* @param biomeByColumn the cave biome in each column of the chunk indexed as {@code (localX << 4) | localZ}; null where the entry gives none
|
||||
*/
|
||||
record CaveBand(int lowestWorldY, int highestWorldY, IrisBiome[] biomeByColumn) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
/**
|
||||
* What caves know of the world they carve. Heights count from the dimension's bottom, except
|
||||
* {@code minHeight}, the world height of that bottom.
|
||||
*
|
||||
* @param minHeight world Y of the dimension's lowest block
|
||||
* @param height the dimension's height in blocks
|
||||
* @param carveSeed the seed caves carve with
|
||||
* @param fluidHeight the height the dimension's fluid fills up to
|
||||
* @param caveLavaHeight the height below which caves hold lava
|
||||
*/
|
||||
record CaveWorld(int minHeight, int height, long carveSeed, int fluidHeight, int caveLavaHeight) {
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/** The terrain an engine generates, as listed cave carving reads it: the streams of one {@link IrisComplex}. */
|
||||
final class EngineCaveTerrain implements CaveTerrain {
|
||||
private static final int CHUNK_AREA = 256;
|
||||
/** A column's cave biome is the one the world places this far below its surface (at least at height 1). */
|
||||
private static final int CAVE_SAMPLE_DEPTH_BELOW_SURFACE_BLOCKS = 56;
|
||||
|
||||
private final Engine engine;
|
||||
private final IrisComplex complex;
|
||||
private final IrisDimensionCarvingResolver.State resolverState;
|
||||
|
||||
EngineCaveTerrain(Engine engine, IrisComplex complex, IrisDimensionCarvingResolver.State resolverState) {
|
||||
this.engine = engine;
|
||||
this.complex = complex;
|
||||
this.resolverState = resolverState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CavePlace placeAt(int worldX, int worldZ) {
|
||||
double surfaceHeight = complex.getNaturalHeightStream().getDouble(worldX, worldZ);
|
||||
IrisRegion region = complex.getRegionStream().get(worldX, worldZ);
|
||||
IrisBiome surfaceBiome = complex.getNaturalTrueBiomeStream().get(worldX, worldZ);
|
||||
IrisBiome caveBiome = complex.getCaveBiomeStream().get(worldX, worldZ);
|
||||
return new CavePlace(region, surfaceBiome, caveBiomeOf(worldX, worldZ, surfaceHeight, surfaceBiome, caveBiome));
|
||||
}
|
||||
|
||||
/**
|
||||
* The cave biome of a column: the one a carving entry puts at the height caves are read at, else the cave biome the
|
||||
* world places there, unless it asks to lie deeper than the cave is, in which case the surface biome stands in.
|
||||
*/
|
||||
private IrisBiome caveBiomeOf(int worldX, int worldZ, double surfaceHeight, IrisBiome surfaceBiome, IrisBiome worldCaveBiome) {
|
||||
int sampleY = Math.max(1, (int) Math.round(surfaceHeight) - CAVE_SAMPLE_DEPTH_BELOW_SURFACE_BLOCKS);
|
||||
int worldY = sampleY + engine.getWorld().minHeight();
|
||||
IrisBiome carvingBiome = carvingBiomeAt(worldX, worldY, worldZ);
|
||||
if (carvingBiome != null) {
|
||||
return carvingBiome;
|
||||
}
|
||||
if (worldCaveBiome == null || surfaceBiome == null) {
|
||||
return worldCaveBiome;
|
||||
}
|
||||
int depthBelowSurface = (int) surfaceHeight - sampleY;
|
||||
boolean tooShallow = depthBelowSurface <= 0 || depthBelowSurface < Math.max(0, worldCaveBiome.getCaveMinDepthBelowSurface());
|
||||
return tooShallow ? surfaceBiome : worldCaveBiome;
|
||||
}
|
||||
|
||||
private IrisBiome carvingBiomeAt(int worldX, int worldY, int worldZ) {
|
||||
IrisDimensionCarvingEntry root = IrisDimensionCarvingResolver.resolveRootEntry(engine, worldY, resolverState);
|
||||
if (root == null) {
|
||||
return null;
|
||||
}
|
||||
IrisDimensionCarvingEntry resolved = IrisDimensionCarvingResolver.resolveFromRoot(engine, root, worldX, worldY, worldZ, resolverState);
|
||||
return IrisDimensionCarvingResolver.resolveEntryBiome(engine, resolved, resolverState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CaveBand> bandsOf(int chunkX, int chunkZ) {
|
||||
List<IrisDimensionCarvingEntry> entries = engine.getDimension().getCarving();
|
||||
List<CaveBand> bands = new ArrayList<>();
|
||||
if (entries == null || entries.isEmpty()) {
|
||||
return bands;
|
||||
}
|
||||
TreeSet<Integer> boundaries = boundariesOf(entries);
|
||||
for (IrisDimensionCarvingEntry entry : entries) {
|
||||
if (entry != null && entry.isEnabled()) {
|
||||
addBandsOf(entry, boundaries, chunkX, chunkZ, bands);
|
||||
}
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
private TreeSet<Integer> boundariesOf(List<IrisDimensionCarvingEntry> entries) {
|
||||
int minimumY = engine.getWorld().minHeight();
|
||||
int maximumY = engine.getWorld().maxHeight();
|
||||
TreeSet<Integer> boundaries = new TreeSet<>();
|
||||
boundaries.add(minimumY);
|
||||
boundaries.add(maximumY);
|
||||
for (IrisDimensionCarvingEntry candidate : entries) {
|
||||
if (candidate != null && candidate.getWorldYRange() != null) {
|
||||
boundaries.add(Math.max(minimumY, Math.min(maximumY, (int) Math.ceil(candidate.getWorldYRange().getMin()))));
|
||||
boundaries.add(Math.max(minimumY, Math.min(maximumY, (int) Math.floor(candidate.getWorldYRange().getMax()) + 1)));
|
||||
}
|
||||
}
|
||||
return boundaries;
|
||||
}
|
||||
|
||||
private void addBandsOf(IrisDimensionCarvingEntry entry, TreeSet<Integer> boundaries, int chunkX, int chunkZ, List<CaveBand> bands) {
|
||||
if (IrisDimensionCarvingResolver.resolveEntryBiome(engine, entry, resolverState) == null) {
|
||||
return;
|
||||
}
|
||||
Integer previous = null;
|
||||
for (int boundary : boundaries) {
|
||||
boolean bandStartsInEntry = previous != null && boundary > previous
|
||||
&& (entry.getWorldYRange() == null || entry.getWorldYRange().contains(previous));
|
||||
if (bandStartsInEntry) {
|
||||
addBand(entry, previous, boundary - 1, chunkX, chunkZ, bands);
|
||||
}
|
||||
previous = boundary;
|
||||
}
|
||||
}
|
||||
|
||||
private void addBand(IrisDimensionCarvingEntry entry, int lowestWorldY, int highestWorldY, int chunkX, int chunkZ, List<CaveBand> bands) {
|
||||
int baseX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int baseZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
IrisBiome[] biomeByColumn = new IrisBiome[CHUNK_AREA];
|
||||
boolean any = false;
|
||||
for (int column = 0; column < CHUNK_AREA; column++) {
|
||||
IrisDimensionCarvingEntry resolved = IrisDimensionCarvingResolver.resolveFromRoot(
|
||||
engine, entry, baseX + (column >> 4), lowestWorldY, baseZ + (column & 15), resolverState);
|
||||
biomeByColumn[column] = IrisDimensionCarvingResolver.resolveEntryBiome(engine, resolved, resolverState);
|
||||
any |= biomeByColumn[column] != null;
|
||||
}
|
||||
if (any) {
|
||||
bands.add(new CaveBand(lowestWorldY, highestWorldY, biomeByColumn));
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.cave.field.AquiferPockets;
|
||||
import art.arcane.iris.generation.cave.field.CaveCarver;
|
||||
import art.arcane.iris.generation.cave.field.NoiseFactory;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* One cave of a pack ready to carve one world: its carver, and the cells it writes into the mantle, which hold the
|
||||
* cave's biome. Cells say what fills a carved block: air, fluid from the dimension's palette, lava, or air that no
|
||||
* hydrology may fill.
|
||||
*/
|
||||
final class ListedCave {
|
||||
private static final byte LIQUID_AIR = 0;
|
||||
private static final byte LIQUID_FLUID = 1;
|
||||
private static final byte LIQUID_LAVA = 2;
|
||||
private static final byte LIQUID_FORCED_AIR = 3;
|
||||
|
||||
private final String key;
|
||||
private final IrisCave cave;
|
||||
private final CaveWorld world;
|
||||
private final CaveCarver carver;
|
||||
private final AquiferPockets aquiferPockets;
|
||||
private final MatterCavern air;
|
||||
private final MatterCavern fluid;
|
||||
private final MatterCavern lava;
|
||||
private final MatterCavern forcedAir;
|
||||
|
||||
/**
|
||||
* @param biomeKey the cave biome that paints the cave's walls, or empty to leave them to the cave biome of the place
|
||||
*/
|
||||
ListedCave(String key, IrisCave cave, String biomeKey, CaveWorld world, NoiseFactory noise) {
|
||||
long seed = CaveCarver.seedOf(world.carveSeed(), key);
|
||||
this.key = key;
|
||||
this.cave = cave;
|
||||
this.world = world;
|
||||
this.carver = new CaveCarver(cave, noise, seed, world.minHeight(), world.height());
|
||||
this.aquiferPockets = new AquiferPockets(noise, seed);
|
||||
this.air = new MatterCavern(true, biomeKey, LIQUID_AIR);
|
||||
this.fluid = new MatterCavern(true, biomeKey, LIQUID_FLUID);
|
||||
this.lava = new MatterCavern(true, biomeKey, LIQUID_LAVA);
|
||||
this.forcedAir = new MatterCavern(true, biomeKey, LIQUID_FORCED_AIR);
|
||||
}
|
||||
|
||||
String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
CaveCarver carver() {
|
||||
return carver;
|
||||
}
|
||||
|
||||
MatterCavern air() {
|
||||
return air;
|
||||
}
|
||||
|
||||
MatterCavern fluid() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
boolean fluidNeedsFloor() {
|
||||
return cave.fluidRequiresFloor();
|
||||
}
|
||||
|
||||
/** Fills {@code fluidTopY} with the highest height at which the cave may hold fluid in each column, below the surface. */
|
||||
void fillFluidTops(int[] surfaceY, int[] fluidTopY) {
|
||||
if (!cave.allowFluid()) {
|
||||
Arrays.fill(fluidTopY, Integer.MIN_VALUE);
|
||||
return;
|
||||
}
|
||||
int minDepth = cave.fluidMinDepthBelowSurface();
|
||||
for (int column = 0; column < fluidTopY.length; column++) {
|
||||
fluidTopY[column] = Math.min(world.fluidHeight(), surfaceY[column] - minDepth);
|
||||
}
|
||||
}
|
||||
|
||||
/** What fills the carved block at height {@code y}, which lies at most {@code fluidTopY} up where the cave may hold fluid. */
|
||||
MatterCavern cellAt(int worldX, int y, int worldZ, int fluidTopY) {
|
||||
boolean belowLavaHeight = y <= world.caveLavaHeight();
|
||||
if (belowLavaHeight && cave.allowLava()) {
|
||||
return lava;
|
||||
}
|
||||
if (y <= fluidTopY && aquiferPockets.holdsFluidAt(worldX, y, worldZ, world.fluidHeight())) {
|
||||
return fluid;
|
||||
}
|
||||
return belowLavaHeight ? forcedAir : air;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.cave.field.CaveCarver.ChunkColumns;
|
||||
import art.arcane.iris.generation.cave.field.ChunkLattice;
|
||||
import art.arcane.iris.generation.cave.field.DepthRange;
|
||||
import art.arcane.iris.generation.cave.field.HeightBand;
|
||||
import art.arcane.iris.generation.cave.field.NoiseFactory;
|
||||
import art.arcane.iris.generation.mantle.CaveListing.ListedColumns;
|
||||
import art.arcane.iris.generation.mantle.CaveTerrain.CaveBand;
|
||||
import art.arcane.iris.generation.mantle.CaveTerrain.CavePlace;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Plans one chunk's caves for {@link MantleCarvingComponent}: every cave the dimension, the regions and the biomes around
|
||||
* the chunk list under {@code caves}, and the caves of the cave biomes that carving bands put at some heights. The lists
|
||||
* of a column add up, and a cave narrows to nothing over a few blocks where the columns that list it end. One per
|
||||
* world, keeping a carver per cave.
|
||||
*
|
||||
* <p>A block that several caves carve takes its fluid and biome from the first of them in list order: the dimension's
|
||||
* caves, then the region's, the surface biome's and the cave biome's, then the carving bands'. Caves are carved last to
|
||||
* first, so the first listed writes last.
|
||||
*/
|
||||
final class ListedCaveCarving {
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
|
||||
/** Which caves a column lists is read every fourth block, one ring beyond the chunk, and smoothed between the readings. */
|
||||
private static final int LISTING_STEP_BLOCKS = ChunkLattice.CELL_BLOCKS;
|
||||
private static final int LISTINGS_PER_AXIS = ChunkLattice.CELLS_PER_CHUNK_AXIS + 3;
|
||||
private static final int LISTINGS = LISTINGS_PER_AXIS * LISTINGS_PER_AXIS;
|
||||
private static final int WEIGHTS_PER_AXIS = ChunkLattice.CELLS_PER_CHUNK_AXIS + 1;
|
||||
private static final int LISTINGS_PER_WEIGHT = 9;
|
||||
private static final double[] LISTED_EVERYWHERE = filled(1D);
|
||||
|
||||
/** What listed cave carving reports to the pack's author. */
|
||||
interface Problems {
|
||||
void missingCave(String caveKey);
|
||||
|
||||
void missingCaveBiome(String caveKey, String biomeKey);
|
||||
}
|
||||
|
||||
private final List<String> dimensionCaves;
|
||||
private final boolean onlyDimensionLists;
|
||||
private final CaveWorld world;
|
||||
private final NoiseFactory noise;
|
||||
private final Function<String, IrisCave> caveOf;
|
||||
private final Predicate<String> biomeExists;
|
||||
private final Problems problems;
|
||||
private final Map<String, Optional<ListedCave>> caves = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* @param dimensionCaves the caves the dimension lists
|
||||
* @param onlyDimensionLists whether no region or biome lists a cave, which spares reading the biomes around each chunk
|
||||
* @param caveOf the cave a key names in the pack, or null
|
||||
* @param biomeExists whether the pack has the biome a key names
|
||||
*/
|
||||
ListedCaveCarving(List<String> dimensionCaves, boolean onlyDimensionLists, CaveWorld world, NoiseFactory noise,
|
||||
Function<String, IrisCave> caveOf, Predicate<String> biomeExists, Problems problems) {
|
||||
this.dimensionCaves = List.copyOf(dimensionCaves);
|
||||
this.onlyDimensionLists = onlyDimensionLists;
|
||||
this.world = world;
|
||||
this.noise = noise;
|
||||
this.caveOf = caveOf;
|
||||
this.biomeExists = biomeExists;
|
||||
this.problems = problems;
|
||||
}
|
||||
|
||||
/** The caves that carve in the chunk at chunk coordinates {@code chunkX}, {@code chunkZ}, with how much each column lists them. */
|
||||
CaveListing list(CaveTerrain terrain, int chunkX, int chunkZ) {
|
||||
int originX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int originZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
List<ListedColumns> listed = new ArrayList<>();
|
||||
boolean opensToSurface = false;
|
||||
for (Map.Entry<String, double[]> entry : columnCaves(terrain, originX, originZ).entrySet()) {
|
||||
ListedCave cave = caveOf(entry.getKey());
|
||||
if (cave == null) {
|
||||
continue;
|
||||
}
|
||||
opensToSurface |= cave.carver().opensToSurface();
|
||||
listed.add(new ListedColumns(cave, entry.getValue(), HeightBand.UNLIMITED));
|
||||
}
|
||||
for (ListedColumns inBand : bandCaves(terrain.bandsOf(chunkX, chunkZ))) {
|
||||
opensToSurface |= inBand.cave().carver().opensToSurface();
|
||||
listed.add(inBand);
|
||||
}
|
||||
return new CaveListing(List.copyOf(listed), opensToSurface);
|
||||
}
|
||||
|
||||
/** Carves the listed caves of the chunk into {@code sink}, under the surface and the fluids and ceilings that surround it. */
|
||||
void carve(CaveListing listing, int chunkX, int chunkZ, ChunkSurface surface, CaveCellSink sink, CaveFluidSupportPlan fluidSupport) {
|
||||
boolean[] sealed = sealedColumns(surface.fluidBoundaries());
|
||||
for (ListedColumns listed : firstListedWritesLast(listing)) {
|
||||
ChunkColumns columns = new ChunkColumns(surface.surfaceY(), listed.weight(), sealed, surface.ceilings(), DepthRange.OWN);
|
||||
carveCave(listed.cave(), columns, listed.band(), surface, chunkX, chunkZ, sink, fluidSupport);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Carves the listed caves into the terrain of an upper dimension, which hangs from the top of the world down to
|
||||
* {@code lowestUpperY}: through all heights of the dimension instead of the ones each cave writes, closed under the
|
||||
* top of the world.
|
||||
*/
|
||||
void carveBeneathUpperTerrain(CaveListing listing, int chunkX, int chunkZ, int lowestUpperY, CaveCellSink sink, CaveFluidSupportPlan fluidSupport) {
|
||||
int[] worldTop = new int[CHUNK_AREA];
|
||||
Arrays.fill(worldTop, world.height() - 1);
|
||||
boolean[] sealed = new boolean[CHUNK_AREA];
|
||||
Arrays.fill(sealed, true);
|
||||
ChunkSurface surface = new ChunkSurface(worldTop, null, null);
|
||||
for (ListedColumns listed : firstListedWritesLast(listing)) {
|
||||
HeightBand band = new HeightBand(Math.max(listed.band().lowestY(), lowestUpperY), Math.min(listed.band().highestY(), world.height() - 1));
|
||||
if (band.lowestY() > band.highestY()) {
|
||||
continue;
|
||||
}
|
||||
ChunkColumns columns = new ChunkColumns(worldTop, listed.weight(), sealed, null, DepthRange.WHOLE_DIMENSION);
|
||||
carveCave(listed.cave(), columns, band, surface, chunkX, chunkZ, sink, fluidSupport);
|
||||
}
|
||||
}
|
||||
|
||||
/** A block several caves carve is written by each in turn, so whoever writes last owns it: the first listed. */
|
||||
private static List<ListedColumns> firstListedWritesLast(CaveListing listing) {
|
||||
return listing.caves().reversed();
|
||||
}
|
||||
|
||||
private void carveCave(ListedCave cave, ChunkColumns columns, HeightBand band, ChunkSurface surface, int chunkX, int chunkZ,
|
||||
CaveCellSink sink, CaveFluidSupportPlan fluidSupport) {
|
||||
int originX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int originZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
int[] fluidTopY = new int[CHUNK_AREA];
|
||||
cave.fillFluidTops(surface.surfaceY(), fluidTopY);
|
||||
MatterCavern fluid = cave.fluid();
|
||||
cave.carver().carve(originX, originZ, columns, band, (localX, y, localZ) -> {
|
||||
int column = PowerOfTwoCoordinates.packLocal16(localX, localZ);
|
||||
if (SurfaceFluidBoundaryPlan.protects(surface.fluidBoundaries(), column, y)) {
|
||||
return;
|
||||
}
|
||||
MatterCavern cell = cave.cellAt(originX + localX, y, originZ + localZ, fluidTopY[column]);
|
||||
sink.set(localX, y, localZ, cell);
|
||||
if (cell == fluid && cave.fluidNeedsFloor()) {
|
||||
fluidSupport.add(localX, y, localZ, fluid, cave.air());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Columns whose surface lies under or next to a fluid, where no cave may open the surface. */
|
||||
private static boolean[] sealedColumns(long[] fluidBoundaries) {
|
||||
boolean[] sealed = new boolean[CHUNK_AREA];
|
||||
if (fluidBoundaries == null) {
|
||||
return sealed;
|
||||
}
|
||||
for (int column = 0; column < CHUNK_AREA; column++) {
|
||||
sealed[column] = SurfaceFluidBoundaryPlan.startY(fluidBoundaries[column]) != SurfaceFluidBoundaryPlan.NO_BOUNDARY;
|
||||
}
|
||||
return sealed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The caves any column of the chunk lists, in the order they were first listed, each with how much every column
|
||||
* lists it: 1 well inside the columns that do, 0 well outside, in between across their border.
|
||||
*/
|
||||
private Map<String, double[]> columnCaves(CaveTerrain terrain, int originX, int originZ) {
|
||||
Map<String, double[]> weights = new LinkedHashMap<>();
|
||||
if (onlyDimensionLists) {
|
||||
dimensionCaves.stream().filter(ListedCaveCarving::isKey).forEach(key -> weights.put(key, LISTED_EVERYWHERE));
|
||||
return weights;
|
||||
}
|
||||
Map<String, boolean[]> listedAt = new LinkedHashMap<>();
|
||||
for (int listingX = 0; listingX < LISTINGS_PER_AXIS; listingX++) {
|
||||
int worldX = originX + ((listingX - 1) * LISTING_STEP_BLOCKS);
|
||||
for (int listingZ = 0; listingZ < LISTINGS_PER_AXIS; listingZ++) {
|
||||
int worldZ = originZ + ((listingZ - 1) * LISTING_STEP_BLOCKS);
|
||||
int listing = (listingX * LISTINGS_PER_AXIS) + listingZ;
|
||||
for (String key : listingAt(terrain.placeAt(worldX, worldZ))) {
|
||||
listedAt.computeIfAbsent(key, absent -> new boolean[LISTINGS])[listing] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
listedAt.forEach((key, listed) -> weights.put(key, columnWeights(listed)));
|
||||
return weights;
|
||||
}
|
||||
|
||||
/** Every cave the dimension, the region, the surface biome and the cave biome of a column list between them, once each. */
|
||||
private List<String> listingAt(CavePlace place) {
|
||||
List<String> listed = new ArrayList<>(dimensionCaves);
|
||||
addListed(listed, place.region() == null ? null : place.region().getCaves());
|
||||
addListed(listed, place.surfaceBiome() == null ? null : place.surfaceBiome().getCaves());
|
||||
addListed(listed, place.caveBiome() == null ? null : place.caveBiome().getCaves());
|
||||
return listed.stream().filter(ListedCaveCarving::isKey).distinct().toList();
|
||||
}
|
||||
|
||||
private static void addListed(List<String> listed, KList<String> keys) {
|
||||
if (keys != null) {
|
||||
listed.addAll(keys);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isKey(String key) {
|
||||
return key != null && !key.isBlank();
|
||||
}
|
||||
|
||||
private List<ListedColumns> bandCaves(List<CaveBand> bands) {
|
||||
List<ListedColumns> listed = new ArrayList<>();
|
||||
for (CaveBand band : bands) {
|
||||
HeightBand heights = new HeightBand(band.lowestWorldY() - world.minHeight(), band.highestWorldY() - world.minHeight());
|
||||
for (Map.Entry<String, double[]> entry : bandWeights(band).entrySet()) {
|
||||
ListedCave cave = caveOf(entry.getKey());
|
||||
if (cave != null) {
|
||||
listed.add(new ListedColumns(cave, entry.getValue(), heights));
|
||||
}
|
||||
}
|
||||
}
|
||||
return listed;
|
||||
}
|
||||
|
||||
private static Map<String, double[]> bandWeights(CaveBand band) {
|
||||
Map<String, double[]> weights = new LinkedHashMap<>();
|
||||
for (int column = 0; column < CHUNK_AREA; column++) {
|
||||
IrisBiome biome = band.biomeByColumn()[column];
|
||||
if (biome == null || biome.getCaves() == null) {
|
||||
continue;
|
||||
}
|
||||
for (String key : biome.getCaves()) {
|
||||
if (isKey(key)) {
|
||||
weights.computeIfAbsent(key, absent -> new double[CHUNK_AREA])[column] = 1D;
|
||||
}
|
||||
}
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
|
||||
private static double[] columnWeights(boolean[] listedAt) {
|
||||
if (isAllTrue(listedAt)) {
|
||||
return LISTED_EVERYWHERE;
|
||||
}
|
||||
double[] latticeWeight = new double[WEIGHTS_PER_AXIS * WEIGHTS_PER_AXIS];
|
||||
for (int weightX = 0; weightX < WEIGHTS_PER_AXIS; weightX++) {
|
||||
for (int weightZ = 0; weightZ < WEIGHTS_PER_AXIS; weightZ++) {
|
||||
latticeWeight[(weightX * WEIGHTS_PER_AXIS) + weightZ] = listingsAround(listedAt, weightX, weightZ) / (double) LISTINGS_PER_WEIGHT;
|
||||
}
|
||||
}
|
||||
double[] columnWeight = new double[CHUNK_AREA];
|
||||
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
|
||||
int weightX = localX / LISTING_STEP_BLOCKS;
|
||||
double shareX = (localX % LISTING_STEP_BLOCKS) / (double) LISTING_STEP_BLOCKS;
|
||||
for (int localZ = 0; localZ < CHUNK_SIZE; localZ++) {
|
||||
int weightZ = localZ / LISTING_STEP_BLOCKS;
|
||||
double shareZ = (localZ % LISTING_STEP_BLOCKS) / (double) LISTING_STEP_BLOCKS;
|
||||
double west = between(latticeWeight[(weightX * WEIGHTS_PER_AXIS) + weightZ], latticeWeight[(weightX * WEIGHTS_PER_AXIS) + weightZ + 1], shareZ);
|
||||
double east = between(latticeWeight[((weightX + 1) * WEIGHTS_PER_AXIS) + weightZ], latticeWeight[((weightX + 1) * WEIGHTS_PER_AXIS) + weightZ + 1], shareZ);
|
||||
columnWeight[PowerOfTwoCoordinates.packLocal16(localX, localZ)] = between(west, east, shareX);
|
||||
}
|
||||
}
|
||||
return columnWeight;
|
||||
}
|
||||
|
||||
/** How many of the nine readings on and around a lattice point list the cave. The point's own reading is one ring in. */
|
||||
private static int listingsAround(boolean[] listedAt, int weightX, int weightZ) {
|
||||
int count = 0;
|
||||
for (int listingX = weightX; listingX <= weightX + 2; listingX++) {
|
||||
for (int listingZ = weightZ; listingZ <= weightZ + 2; listingZ++) {
|
||||
if (listedAt[(listingX * LISTINGS_PER_AXIS) + listingZ]) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static double between(double from, double to, double share) {
|
||||
return from + ((to - from) * share);
|
||||
}
|
||||
|
||||
private static boolean isAllTrue(boolean[] values) {
|
||||
for (boolean value : values) {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double[] filled(double value) {
|
||||
double[] values = new double[CHUNK_AREA];
|
||||
Arrays.fill(values, value);
|
||||
return values;
|
||||
}
|
||||
|
||||
/** The cave with this key, ready to carve; null when the pack has no such cave, which is reported once. */
|
||||
private ListedCave caveOf(String key) {
|
||||
return caves.computeIfAbsent(key, this::loadCave).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<ListedCave> loadCave(String key) {
|
||||
IrisCave cave = caveOf.apply(key);
|
||||
if (cave == null) {
|
||||
problems.missingCave(key);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ListedCave(key, cave, wallBiomeKey(key, cave), world, noise));
|
||||
}
|
||||
|
||||
private String wallBiomeKey(String caveKey, IrisCave cave) {
|
||||
String biomeKey = cave.biome();
|
||||
if (biomeKey.isBlank() || biomeExists.test(biomeKey)) {
|
||||
return biomeKey;
|
||||
}
|
||||
problems.missingCaveBiome(caveKey, biomeKey);
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What a chunk's carving is held back by.
|
||||
*
|
||||
* @param surfaceY the height of the surface in each column, indexed as {@code (localX << 4) | localZ}
|
||||
* @param fluidBoundaries per column, the heights over which a surface fluid keeps the carving out; null for none
|
||||
* @param ceilings per column, the highest height caves may carve at, where hydrology keeps cave pools below it; null for none
|
||||
*/
|
||||
record ChunkSurface(int[] surfaceY, long[] fluidBoundaries, int[] ceilings) {
|
||||
}
|
||||
}
|
||||
@@ -118,12 +118,22 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
return null;
|
||||
}
|
||||
long revision = ProvisionalSampling.revision();
|
||||
IrisBiome biome = engine.getCaveBiomeBelowSurface(x, y, z);
|
||||
IrisBiome carvedBiome = carvedBiome(x, y, z);
|
||||
IrisBiome biome = carvedBiome != null ? carvedBiome : engine.getCaveBiomeBelowSurface(x, y, z);
|
||||
IrisRegion region = complex.getRegionStream().get(x, z);
|
||||
requireFinal(revision, x, z);
|
||||
return IrisHydrologyPolicy.inherited(biome == null ? List.of() : List.of(biome), region, dimension, IrisHydrologyPolicy::getFluid);
|
||||
}
|
||||
|
||||
/** The biome the cave that carved the cell paints it with, where that cave names one. */
|
||||
private IrisBiome carvedBiome(int x, int y, int z) {
|
||||
if (existing(x, z)) {
|
||||
return null;
|
||||
}
|
||||
MatterCavern cavern = TerrainMatterView.get(chunk(x, z), x, y, z, MatterCavern.class);
|
||||
return cavern == null ? null : engine.carvedCaveBiome(cavern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean structureNear(int x, int y, int z) {
|
||||
if (dimension.getTerrainTransform() != null) {
|
||||
|
||||
+140
-539
@@ -18,85 +18,77 @@
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlanner;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.UpperDimensionContext;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.cave.field.CngNoiseFactory;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.iris.generation.mantle.ListedCaveCarving.ChunkSurface;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.UpperDimensionContext;
|
||||
import art.arcane.iris.generation.stream.BakedDoubleStream;
|
||||
import art.arcane.iris.generation.stream.BakedStream;
|
||||
import art.arcane.iris.generation.stream.ChunkFillableDoubleStream2D;
|
||||
import art.arcane.iris.generation.simd.SimdSupport;
|
||||
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlanner;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ComponentFlag(ReservedFlag.CARVED)
|
||||
public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
|
||||
private static final int BLEND_RADIUS = 3;
|
||||
private static final int FIELD_SIZE = CHUNK_SIZE + (BLEND_RADIUS * 2);
|
||||
private static final double MIN_WEIGHT = 0.08D;
|
||||
private static final double THRESHOLD_PENALTY = 0.24D;
|
||||
private static final int MAX_POOLED_WEIGHT_BUFFERS = 64;
|
||||
/** Lattice columns kept for neighbouring chunks: about 3 KB each on land, roughly 50 MB when full. */
|
||||
private static final int DENSITY_GRID_COLUMNS = 16_384;
|
||||
private static final int KERNEL_WIDTH = (BLEND_RADIUS * 2) + 1;
|
||||
private static final int KERNEL_SIZE = KERNEL_WIDTH * KERNEL_WIDTH;
|
||||
private static final int[] KERNEL_DX = new int[KERNEL_SIZE];
|
||||
private static final int[] KERNEL_DZ = new int[KERNEL_SIZE];
|
||||
private static final double[] KERNEL_WEIGHT = new double[KERNEL_SIZE];
|
||||
/** Columns read beyond the chunk to find where surface fluids reach, which no cave may open under. */
|
||||
private static final int FLUID_BOUNDARY_PADDING = 3;
|
||||
private static final int FIELD_SIZE = CHUNK_SIZE + (FLUID_BOUNDARY_PADDING * 2);
|
||||
/** Loose rock is swept this far below the surface where a cave opens to it. */
|
||||
private static final int LOOSE_ROCK_SWEEP_DEPTH_BLOCKS = 16;
|
||||
/** An upper dimension's terrain needs this much room under the top of the world to be carved. */
|
||||
private static final int MINIMUM_UPPER_TERRAIN_THICKNESS_BLOCKS = 2;
|
||||
private static final int NEIGHBOURS = 9;
|
||||
private static final int[] NEIGHBOUR_DX = new int[NEIGHBOURS];
|
||||
private static final int[] NEIGHBOUR_DZ = new int[NEIGHBOURS];
|
||||
private static final long[][] NEIGHBOUR_COLUMNS = new long[NEIGHBOURS][4];
|
||||
private static final int[] FIELD_NEIGHBOUR = new int[FIELD_SIZE * FIELD_SIZE];
|
||||
private static final int[] FIELD_COLUMN = new int[FIELD_SIZE * FIELD_SIZE];
|
||||
private static final ThreadLocal<BlendScratch> BLEND_SCRATCH = ThreadLocal.withInitial(BlendScratch::new);
|
||||
private static final ThreadLocal<ChunkScratch> CHUNK_SCRATCH = ThreadLocal.withInitial(ChunkScratch::new);
|
||||
private static final ListedCaveCarving.Problems CAVE_PROBLEMS = new ListedCaveCarving.Problems() {
|
||||
@Override
|
||||
public void missingCave(String caveKey) {
|
||||
IrisLogging.warnOnce("missing-cave:" + caveKey, "Cave '%s' is listed under caves but the pack has no readable caves/%s.json", caveKey, caveKey);
|
||||
}
|
||||
|
||||
private final Object profileCarverLock = new Object();
|
||||
private final CaveDensityGrid densityGrid = new CaveDensityGrid(DENSITY_GRID_COLUMNS);
|
||||
private volatile Map<IrisCaveProfile, IrisCaveCarver3D> profileCarvers = new IdentityHashMap<>();
|
||||
@Override
|
||||
public void missingCaveBiome(String caveKey, String biomeKey) {
|
||||
IrisLogging.warnOnce("missing-cave-biome:" + caveKey + ":" + biomeKey, "Cave '%s' names the biome '%s', which the pack does not have", caveKey, biomeKey);
|
||||
}
|
||||
};
|
||||
|
||||
private final Object caveCarvingLock = new Object();
|
||||
private volatile ListedCaveCarving caveCarving;
|
||||
|
||||
static {
|
||||
int kernelIndex = 0;
|
||||
for (int offsetX = -BLEND_RADIUS; offsetX <= BLEND_RADIUS; offsetX++) {
|
||||
for (int offsetZ = -BLEND_RADIUS; offsetZ <= BLEND_RADIUS; offsetZ++) {
|
||||
KERNEL_DX[kernelIndex] = offsetX;
|
||||
KERNEL_DZ[kernelIndex] = offsetZ;
|
||||
int edgeDistance = Math.max(Math.abs(offsetX), Math.abs(offsetZ));
|
||||
KERNEL_WEIGHT[kernelIndex] = (BLEND_RADIUS + 1D) - edgeDistance;
|
||||
kernelIndex++;
|
||||
}
|
||||
}
|
||||
for (int neighbour = 0; neighbour < NEIGHBOURS; neighbour++) {
|
||||
NEIGHBOUR_DX[neighbour] = (neighbour / 3) - 1;
|
||||
NEIGHBOUR_DZ[neighbour] = (neighbour % 3) - 1;
|
||||
}
|
||||
for (int fieldX = 0; fieldX < FIELD_SIZE; fieldX++) {
|
||||
int offsetX = fieldX - BLEND_RADIUS;
|
||||
int offsetX = fieldX - FLUID_BOUNDARY_PADDING;
|
||||
for (int fieldZ = 0; fieldZ < FIELD_SIZE; fieldZ++) {
|
||||
int offsetZ = fieldZ - BLEND_RADIUS;
|
||||
int offsetZ = fieldZ - FLUID_BOUNDARY_PADDING;
|
||||
int neighbour = ((Math.floorDiv(offsetX, CHUNK_SIZE) + 1) * 3) + Math.floorDiv(offsetZ, CHUNK_SIZE) + 1;
|
||||
int column = ((offsetZ & (CHUNK_SIZE - 1)) << 4) | (offsetX & (CHUNK_SIZE - 1));
|
||||
int fieldIndex = (fieldX * FIELD_SIZE) + fieldZ;
|
||||
@@ -119,12 +111,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
@Override
|
||||
public void hotload() {
|
||||
super.hotload();
|
||||
// Hotload swaps in fresh IrisCaveProfile instances (identity keys), so retained
|
||||
// entries would strand a full carver set pinning the closed IrisData per reload.
|
||||
// Carvers rebuild deterministically from the carve seed, so output is unchanged.
|
||||
synchronized (profileCarverLock) {
|
||||
profileCarvers = new IdentityHashMap<>();
|
||||
densityGrid.clear();
|
||||
// Carvers hold the pack's caves and the closed IrisData of the previous load. They rebuild
|
||||
// deterministically from the carve seed, so output is unchanged.
|
||||
synchronized (caveCarvingLock) {
|
||||
caveCarving = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,10 +124,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
if (!complex.allowsMantleChunkWrite(x, z)) {
|
||||
return;
|
||||
}
|
||||
BlendScratch previous = BLEND_SCRATCH.get();
|
||||
BlendScratch scratch = previous.inUse ? new BlendScratch() : previous;
|
||||
ChunkScratch previous = CHUNK_SCRATCH.get();
|
||||
ChunkScratch scratch = previous.inUse ? new ChunkScratch() : previous;
|
||||
if (scratch != previous) {
|
||||
BLEND_SCRATCH.set(scratch);
|
||||
CHUNK_SCRATCH.set(scratch);
|
||||
}
|
||||
scratch.inUse = true;
|
||||
try {
|
||||
@@ -145,52 +135,59 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
} finally {
|
||||
scratch.release();
|
||||
if (scratch != previous) {
|
||||
BLEND_SCRATCH.set(previous);
|
||||
CHUNK_SCRATCH.set(previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateLayer(MantleWriter writer, int x, int z, ChunkContext context, BlendScratch blendScratch) {
|
||||
private void generateLayer(MantleWriter writer, int x, int z, ChunkContext context, ChunkScratch scratch) {
|
||||
IrisComplex complex = context.getComplex();
|
||||
IrisDimensionCarvingResolver.State resolverState = blendScratch.resolverState;
|
||||
int[] chunkSurfaceHeights = prepareChunkSurfaceHeights(x, z, context, blendScratch.chunkSurfaceHeights);
|
||||
Engine engine = getEngineMantle().getEngine();
|
||||
int[] chunkSurfaceHeights = prepareChunkSurfaceHeights(x, z, context, scratch.chunkSurfaceHeights);
|
||||
int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster,
|
||||
scratch.caveCeilingField, scratch.caveCeilings) ? scratch.caveCeilings : null;
|
||||
ListedCaveCarving carving = caveCarving();
|
||||
PrecisionStopwatch resolveStopwatch = PrecisionStopwatch.start();
|
||||
List<WeightedProfile> weightedProfiles = resolveWeightedProfiles(x, z, complex, resolverState);
|
||||
getEngineMantle().getEngine().getMetrics().getCarveResolve().put(resolveStopwatch.getMilliseconds());
|
||||
long[] surfaceFluidBoundaries = blendScratch.surfaceFluidBoundaries;
|
||||
CaveListing listing = carving.list(new EngineCaveTerrain(engine, complex, scratch.resolverState), x, z);
|
||||
engine.getMetrics().getCarveResolve().put(resolveStopwatch.getMilliseconds());
|
||||
carveListing(carving, listing, writer, x, z, complex, chunkSurfaceHeights, caveCeilings, scratch);
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
}
|
||||
|
||||
private void carveListing(ListedCaveCarving carving, CaveListing listing, MantleWriter writer, int x, int z, IrisComplex complex,
|
||||
int[] chunkSurfaceHeights, int[] caveCeilings, ChunkScratch scratch) {
|
||||
MantleChunk<Matter> chunk = listing.isEmpty() ? null : writer.acquireChunk(x, z);
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
PrecisionStopwatch applyStopwatch = PrecisionStopwatch.start();
|
||||
long[] surfaceFluidBoundaries = fillSurfaceFluidBoundaries(complex, x, z, chunkSurfaceHeights, scratch);
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
CaveCellSink sink = new MantleCaveCellSink(chunk, writer.getMantle().getWorldHeight());
|
||||
carving.carve(listing, x, z, new ChunkSurface(chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings), sink, fluidSupportPlan);
|
||||
UpperDimensionContext upperContext = getEngineMantle().getEngine().getUpperContext();
|
||||
if (upperContext != null && getDimension().isUpperDimensionCarving()) {
|
||||
carveUpperTerrain(upperContext, carving, listing, sink, x, z, fluidSupportPlan);
|
||||
}
|
||||
fluidSupportPlan.resolve(chunk);
|
||||
int sweepDepth = listing.opensToSurface() ? LOOSE_ROCK_SWEEP_DEPTH_BLOCKS : 0;
|
||||
CarveOrphanSweep.sweepChunk(chunk, chunkSurfaceHeights, sweepDepth, writer.getMantle().getWorldHeight() - 1,
|
||||
surfaceFluidBoundaries, caveCeilings);
|
||||
getEngineMantle().getEngine().getMetrics().getCarveApply().put(applyStopwatch.getMilliseconds());
|
||||
}
|
||||
|
||||
private long[] fillSurfaceFluidBoundaries(IrisComplex complex, int x, int z, int[] chunkSurfaceHeights, ChunkScratch scratch) {
|
||||
prefillFluidBoundaryField(complex, x, z, scratch);
|
||||
SurfaceFluidBoundaryPlan.fill(
|
||||
chunkSurfaceHeights,
|
||||
blendScratch.fieldSurfaceHeights,
|
||||
blendScratch.fieldHasFluid,
|
||||
blendScratch.fieldFluidHeights,
|
||||
scratch.fieldSurfaceHeights,
|
||||
scratch.fieldHasFluid,
|
||||
scratch.fieldFluidHeights,
|
||||
FIELD_SIZE,
|
||||
BLEND_RADIUS,
|
||||
surfaceFluidBoundaries
|
||||
FLUID_BOUNDARY_PADDING,
|
||||
scratch.surfaceFluidBoundaries
|
||||
);
|
||||
int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster,
|
||||
blendScratch.caveCeilingField, blendScratch.caveCeilings) ? blendScratch.caveCeilings : null;
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
carveProfile(weightedProfile, writer, x, z, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, fluidSupportPlan);
|
||||
}
|
||||
|
||||
UpperDimensionContext upperCtx = getEngineMantle().getEngine().getUpperContext();
|
||||
if (upperCtx != null && getDimension().isUpperDimensionCarving()) {
|
||||
carveUpperTerrain(upperCtx, weightedProfiles, writer, x, z, fluidSupportPlan);
|
||||
}
|
||||
fluidSupportPlan.resolve(writer.acquireChunk(x, z));
|
||||
|
||||
if (!weightedProfiles.isEmpty()) {
|
||||
CarveOrphanSweep.sweepChunk(
|
||||
writer.acquireChunk(x, z),
|
||||
chunkSurfaceHeights,
|
||||
maxSurfaceBreakDepth(weightedProfiles),
|
||||
writer.getMantle().getWorldHeight() - 1,
|
||||
surfaceFluidBoundaries,
|
||||
caveCeilings
|
||||
);
|
||||
}
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
return scratch.surfaceFluidBoundaries;
|
||||
}
|
||||
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings) {
|
||||
@@ -223,366 +220,74 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
});
|
||||
}
|
||||
|
||||
private static int maxSurfaceBreakDepth(List<WeightedProfile> weightedProfiles) {
|
||||
int maxDepth = 0;
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
maxDepth = Math.max(maxDepth, Math.max(0, weightedProfile.profile.getSurfaceBreakDepth()));
|
||||
}
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void carveProfile(WeightedProfile weightedProfile, MantleWriter writer, int cx, int cz,
|
||||
int[] chunkSurfaceHeights, long[] surfaceFluidBoundaries, int[] caveCeilings,
|
||||
CaveFluidSupportPlan fluidSupportPlan) {
|
||||
IrisCaveCarver3D carver = getCarver(weightedProfile.profile);
|
||||
carver.carve(writer, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
weightedProfile.worldYRange, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, null, fluidSupportPlan);
|
||||
}
|
||||
|
||||
private void carveUpperTerrain(UpperDimensionContext upperCtx, List<WeightedProfile> normalProfiles,
|
||||
MantleWriter writer, int cx, int cz,
|
||||
CaveFluidSupportPlan fluidSupportPlan) {
|
||||
private void carveUpperTerrain(UpperDimensionContext upperContext, ListedCaveCarving carving, CaveListing listing, CaveCellSink sink,
|
||||
int cx, int cz, CaveFluidSupportPlan fluidSupportPlan) {
|
||||
int chunkHeight = getEngineMantle().getEngine().getHeight();
|
||||
int worldMinHeight = getEngineMantle().getEngine().getWorld().minHeight();
|
||||
int baseX = PowerOfTwoCoordinates.chunkToBlock(cx);
|
||||
int baseZ = PowerOfTwoCoordinates.chunkToBlock(cz);
|
||||
|
||||
int minUpperSurfaceY = chunkHeight;
|
||||
int lowestUpperSurfaceY = chunkHeight;
|
||||
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
|
||||
int worldX = baseX + localX;
|
||||
for (int localZ = 0; localZ < CHUNK_SIZE; localZ++) {
|
||||
int worldZ = baseZ + localZ;
|
||||
int upperY = upperCtx.getEffectiveSurfaceY(worldX, worldZ);
|
||||
if (upperY < minUpperSurfaceY) {
|
||||
minUpperSurfaceY = upperY;
|
||||
}
|
||||
lowestUpperSurfaceY = Math.min(lowestUpperSurfaceY, upperContext.getEffectiveSurfaceY(baseX + localX, baseZ + localZ));
|
||||
}
|
||||
}
|
||||
|
||||
if (minUpperSurfaceY >= chunkHeight - 2) {
|
||||
if (lowestUpperSurfaceY >= chunkHeight - MINIMUM_UPPER_TERRAIN_THICKNESS_BLOCKS) {
|
||||
return;
|
||||
}
|
||||
carving.carveBeneathUpperTerrain(listing, cx, cz, lowestUpperSurfaceY, sink, fluidSupportPlan);
|
||||
}
|
||||
|
||||
IrisRange upperYRange = new IrisRange(
|
||||
minUpperSurfaceY + worldMinHeight,
|
||||
chunkHeight - 1 + worldMinHeight
|
||||
);
|
||||
IrisRange fullVerticalRange = new IrisRange(0, chunkHeight);
|
||||
|
||||
int[] ceilingSurfaceHeights = new int[CHUNK_AREA];
|
||||
Arrays.fill(ceilingSurfaceHeights, chunkHeight - 1);
|
||||
|
||||
for (WeightedProfile weightedProfile : normalProfiles) {
|
||||
IrisRange constrainedRange;
|
||||
if (weightedProfile.worldYRange != null) {
|
||||
double min = Math.max(weightedProfile.worldYRange.getMin(), upperYRange.getMin());
|
||||
double max = Math.min(weightedProfile.worldYRange.getMax(), upperYRange.getMax());
|
||||
if (min >= max) {
|
||||
continue;
|
||||
}
|
||||
constrainedRange = new IrisRange(min, max);
|
||||
} else {
|
||||
constrainedRange = upperYRange;
|
||||
private ListedCaveCarving caveCarving() {
|
||||
ListedCaveCarving carving = caveCarving;
|
||||
if (carving != null) {
|
||||
return carving;
|
||||
}
|
||||
synchronized (caveCarvingLock) {
|
||||
if (caveCarving == null) {
|
||||
caveCarving = createCaveCarving();
|
||||
}
|
||||
IrisCaveCarver3D carver = getCarver(weightedProfile.profile);
|
||||
carver.carve(writer, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
constrainedRange, ceilingSurfaceHeights, null, null, fullVerticalRange, fluidSupportPlan);
|
||||
return caveCarving;
|
||||
}
|
||||
}
|
||||
|
||||
private List<WeightedProfile> resolveWeightedProfiles(int chunkX, int chunkZ, IrisComplex complex, IrisDimensionCarvingResolver.State resolverState) {
|
||||
BlendScratch blendScratch = BLEND_SCRATCH.get();
|
||||
IrisCaveProfile[] profileField = blendScratch.profileField;
|
||||
Map<IrisCaveProfile, double[]> columnProfileWeights = blendScratch.columnProfileWeights;
|
||||
List<IrisCaveProfile> profileOrder = blendScratch.profileOrder;
|
||||
IrisCaveProfile[] kernelProfiles = blendScratch.kernelProfiles;
|
||||
double[] kernelProfileWeights = blendScratch.kernelProfileWeights;
|
||||
columnProfileWeights.clear();
|
||||
profileOrder.clear();
|
||||
blendScratch.nextWeightBuffer = 0;
|
||||
fillProfileField(profileField, chunkX, chunkZ, complex, resolverState, blendScratch);
|
||||
|
||||
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
|
||||
for (int localZ = 0; localZ < CHUNK_SIZE; localZ++) {
|
||||
int profileCount = 0;
|
||||
int centerX = localX + BLEND_RADIUS;
|
||||
int centerZ = localZ + BLEND_RADIUS;
|
||||
double totalKernelWeight = 0D;
|
||||
|
||||
for (int kernelIndex = 0; kernelIndex < KERNEL_SIZE; kernelIndex++) {
|
||||
int sampleX = centerX + KERNEL_DX[kernelIndex];
|
||||
int sampleZ = centerZ + KERNEL_DZ[kernelIndex];
|
||||
IrisCaveProfile profile = profileField[(sampleX * FIELD_SIZE) + sampleZ];
|
||||
if (!isProfileEnabled(profile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double kernelWeight = KERNEL_WEIGHT[kernelIndex];
|
||||
int existingIndex = findProfileIndex(kernelProfiles, profileCount, profile);
|
||||
if (existingIndex >= 0) {
|
||||
kernelProfileWeights[existingIndex] += kernelWeight;
|
||||
} else {
|
||||
kernelProfiles[profileCount] = profile;
|
||||
kernelProfileWeights[profileCount] = kernelWeight;
|
||||
profileCount++;
|
||||
}
|
||||
totalKernelWeight += kernelWeight;
|
||||
}
|
||||
|
||||
if (totalKernelWeight <= 0D || profileCount == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(localX, localZ);
|
||||
for (int profileIndex = 0; profileIndex < profileCount; profileIndex++) {
|
||||
IrisCaveProfile profile = kernelProfiles[profileIndex];
|
||||
double kernelWeight = kernelProfileWeights[profileIndex];
|
||||
kernelProfiles[profileIndex] = null;
|
||||
kernelProfileWeights[profileIndex] = 0D;
|
||||
|
||||
double columnWeight = clampWeight(kernelWeight / totalKernelWeight);
|
||||
if (columnWeight < MIN_WEIGHT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double[] weights = columnProfileWeights.get(profile);
|
||||
if (weights == null) {
|
||||
weights = blendScratch.acquireWeights();
|
||||
columnProfileWeights.put(profile, weights);
|
||||
profileOrder.add(profile);
|
||||
}
|
||||
weights[columnIndex] = columnWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<WeightedProfile> columnWeightedProfiles = new ArrayList<>();
|
||||
for (IrisCaveProfile profile : profileOrder) {
|
||||
double[] weights = columnProfileWeights.get(profile);
|
||||
if (weights == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// averageWeight ranks and orders carve passes, so it must be bit-identical across
|
||||
// installations: kernels.sum reassociates FP addition under the vector kernel,
|
||||
// making profile order depend on a JVM flag. max() is order-independent and safe.
|
||||
double maxWeight = SimdSupport.kernels().max(weights, weights.length);
|
||||
|
||||
if (maxWeight < MIN_WEIGHT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double averageWeight = computeAverageWeight(weights);
|
||||
columnWeightedProfiles.add(new WeightedProfile(profile, weights, averageWeight, null, columnWeightedProfiles.size()));
|
||||
}
|
||||
|
||||
columnWeightedProfiles.sort(MantleCarvingComponent::compareByCarveOrder);
|
||||
List<WeightedProfile> resolvedProfiles = resolveDimensionCarvingProfiles(chunkX, chunkZ, resolverState, blendScratch);
|
||||
resolvedProfiles.addAll(columnWeightedProfiles);
|
||||
return resolvedProfiles;
|
||||
}
|
||||
|
||||
private List<WeightedProfile> resolveDimensionCarvingProfiles(int chunkX, int chunkZ, IrisDimensionCarvingResolver.State resolverState, BlendScratch blendScratch) {
|
||||
List<WeightedProfile> weightedProfiles = new ArrayList<>();
|
||||
List<IrisDimensionCarvingEntry> entries = getDimension().getCarving();
|
||||
if (entries == null || entries.isEmpty()) {
|
||||
return weightedProfiles;
|
||||
}
|
||||
|
||||
private ListedCaveCarving createCaveCarving() {
|
||||
Engine engine = getEngineMantle().getEngine();
|
||||
int baseX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int baseZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
|
||||
for (IrisDimensionCarvingEntry entry : entries) {
|
||||
if (entry == null || !entry.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IrisBiome rootBiome = IrisDimensionCarvingResolver.resolveEntryBiome(engine, entry, resolverState);
|
||||
if (rootBiome == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TreeSet<Integer> boundaries = new TreeSet<>();
|
||||
int minimumY = engine.getWorld().minHeight();
|
||||
int maximumY = engine.getWorld().maxHeight();
|
||||
boundaries.add(minimumY);
|
||||
boundaries.add(maximumY);
|
||||
for (IrisDimensionCarvingEntry candidate : entries) {
|
||||
if (candidate != null && candidate.getWorldYRange() != null) {
|
||||
boundaries.add(Math.max(minimumY, Math.min(maximumY, (int) Math.ceil(candidate.getWorldYRange().getMin()))));
|
||||
boundaries.add(Math.max(minimumY, Math.min(maximumY, (int) Math.floor(candidate.getWorldYRange().getMax()) + 1)));
|
||||
}
|
||||
}
|
||||
Integer previous = null;
|
||||
for (int boundary : boundaries) {
|
||||
if (previous != null && boundary > previous
|
||||
&& (entry.getWorldYRange() == null || entry.getWorldYRange().contains(previous))) {
|
||||
Map<IrisCaveProfile, double[]> rootProfileColumnWeights = new IdentityHashMap<>();
|
||||
List<IrisCaveProfile> rootProfileOrder = new ArrayList<>();
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
IrisDimensionCarvingEntry resolvedEntry = IrisDimensionCarvingResolver.resolveFromRoot(
|
||||
engine, entry, baseX + (columnIndex >> 4), previous, baseZ + (columnIndex & 15), resolverState);
|
||||
IrisBiome resolvedBiome = IrisDimensionCarvingResolver.resolveEntryBiome(engine, resolvedEntry, resolverState);
|
||||
IrisCaveProfile profile = resolvedBiome == null ? null : resolvedBiome.getCaveProfile();
|
||||
if (!isProfileEnabled(profile)) {
|
||||
continue;
|
||||
}
|
||||
double[] columnWeights = rootProfileColumnWeights.get(profile);
|
||||
if (columnWeights == null) {
|
||||
columnWeights = blendScratch.acquireWeights();
|
||||
rootProfileColumnWeights.put(profile, columnWeights);
|
||||
rootProfileOrder.add(profile);
|
||||
}
|
||||
columnWeights[columnIndex] = 1D;
|
||||
}
|
||||
IrisRange worldYRange = new IrisRange(previous, boundary - 1);
|
||||
for (IrisCaveProfile profile : rootProfileOrder) {
|
||||
weightedProfiles.add(new WeightedProfile(profile, rootProfileColumnWeights.get(profile), -1D, worldYRange, weightedProfiles.size()));
|
||||
}
|
||||
}
|
||||
previous = boundary;
|
||||
}
|
||||
}
|
||||
|
||||
return weightedProfiles;
|
||||
IrisDimension dimension = getDimension();
|
||||
IrisData data = engine.getData();
|
||||
CaveWorld world = new CaveWorld(engine.getWorld().minHeight(), engine.getHeight(), engine.getSeedManager().getCarve(),
|
||||
dimension.getFluidHeight(), dimension.getCaveLavaHeight());
|
||||
return new ListedCaveCarving(dimension.getCaves(), onlyDimensionListsCaves(dimension, data), world, new CngNoiseFactory(data),
|
||||
key -> data.getCaveLoader().load(key), key -> data.getBiomeLoader().load(key) != null, CAVE_PROBLEMS);
|
||||
}
|
||||
|
||||
private void fillProfileField(IrisCaveProfile[] profileField, int chunkX, int chunkZ, IrisComplex complex, IrisDimensionCarvingResolver.State resolverState, BlendScratch blendScratch) {
|
||||
int startX = PowerOfTwoCoordinates.chunkToBlock(chunkX) - BLEND_RADIUS;
|
||||
int startZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ) - BLEND_RADIUS;
|
||||
prefillProfileFieldSamples(chunkX, chunkZ, startX, startZ, complex, blendScratch);
|
||||
|
||||
for (int fieldX = 0; fieldX < FIELD_SIZE; fieldX++) {
|
||||
int worldX = startX + fieldX;
|
||||
for (int fieldZ = 0; fieldZ < FIELD_SIZE; fieldZ++) {
|
||||
int worldZ = startZ + fieldZ;
|
||||
int fieldIndex = (fieldX * FIELD_SIZE) + fieldZ;
|
||||
profileField[fieldIndex] = resolveColumnProfile(
|
||||
worldX,
|
||||
worldZ,
|
||||
blendScratch.fieldSurfaceHeights[fieldIndex],
|
||||
blendScratch.fieldRegions[fieldIndex],
|
||||
blendScratch.fieldSurfaceBiomes[fieldIndex],
|
||||
blendScratch.fieldCaveBiomes[fieldIndex],
|
||||
resolverState
|
||||
);
|
||||
/** Whether no region and no biome the dimension reaches lists a cave, so every column lists what the dimension lists. */
|
||||
private static boolean onlyDimensionListsCaves(IrisDimension dimension, IrisData data) {
|
||||
for (IrisRegion region : dimension.getAllRegions(() -> data)) {
|
||||
if (region != null && !region.getCaves().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(() -> data)) {
|
||||
if (biome != null && !biome.getCaves().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int findProfileIndex(IrisCaveProfile[] profiles, int size, IrisCaveProfile profile) {
|
||||
for (int index = 0; index < size; index++) {
|
||||
if (profiles[index] == profile) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private IrisCaveProfile resolveColumnProfile(
|
||||
int worldX,
|
||||
int worldZ,
|
||||
double surfaceHeight,
|
||||
IrisRegion region,
|
||||
IrisBiome surfaceBiome,
|
||||
IrisBiome caveBiome,
|
||||
IrisDimensionCarvingResolver.State resolverState
|
||||
) {
|
||||
IrisCaveProfile resolved = null;
|
||||
IrisCaveProfile dimensionProfile = getDimension().getCaveProfile();
|
||||
if (isProfileEnabled(dimensionProfile)) {
|
||||
resolved = dimensionProfile;
|
||||
}
|
||||
|
||||
if (region != null) {
|
||||
IrisCaveProfile regionProfile = region.getCaveProfile();
|
||||
if (isProfileEnabled(regionProfile)) {
|
||||
resolved = regionProfile;
|
||||
}
|
||||
}
|
||||
|
||||
if (surfaceBiome != null) {
|
||||
IrisCaveProfile surfaceProfile = surfaceBiome.getCaveProfile();
|
||||
if (isProfileEnabled(surfaceProfile)) {
|
||||
resolved = surfaceProfile;
|
||||
}
|
||||
}
|
||||
|
||||
int roundedSurfaceY = (int) Math.round(surfaceHeight);
|
||||
int sampleY = Math.max(1, roundedSurfaceY - 56);
|
||||
int worldY = sampleY + getEngineMantle().getEngine().getWorld().minHeight();
|
||||
IrisDimensionCarvingEntry rootCarvingEntry = IrisDimensionCarvingResolver.resolveRootEntry(getEngineMantle().getEngine(), worldY, resolverState);
|
||||
IrisBiome resolvedCarvingBiome = null;
|
||||
if (rootCarvingEntry != null) {
|
||||
IrisDimensionCarvingEntry resolvedCarvingEntry = IrisDimensionCarvingResolver.resolveFromRoot(getEngineMantle().getEngine(), rootCarvingEntry, worldX, worldY, worldZ, resolverState);
|
||||
resolvedCarvingBiome = IrisDimensionCarvingResolver.resolveEntryBiome(getEngineMantle().getEngine(), resolvedCarvingEntry, resolverState);
|
||||
if (resolvedCarvingBiome != null) {
|
||||
caveBiome = resolvedCarvingBiome;
|
||||
}
|
||||
}
|
||||
if (caveBiome != null) {
|
||||
IrisBiome effectiveCaveBiome = caveBiome;
|
||||
if (resolvedCarvingBiome == null && surfaceBiome != null) {
|
||||
if (surfaceBiome != null) {
|
||||
int truncatedSurfaceY = (int) surfaceHeight;
|
||||
int depthBelowSurface = truncatedSurfaceY - sampleY;
|
||||
if (depthBelowSurface <= 0) {
|
||||
effectiveCaveBiome = surfaceBiome;
|
||||
} else {
|
||||
int minDepth = Math.max(0, caveBiome.getCaveMinDepthBelowSurface());
|
||||
if (depthBelowSurface < minDepth) {
|
||||
effectiveCaveBiome = surfaceBiome;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IrisCaveProfile caveProfile = effectiveCaveBiome.getCaveProfile();
|
||||
if (isProfileEnabled(caveProfile)) {
|
||||
resolved = caveProfile;
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private void prefillProfileFieldSamples(int chunkX, int chunkZ, int startX, int startZ, IrisComplex complex, BlendScratch blendScratch) {
|
||||
fillFieldHeights(complex.getNaturalHeightStream(), chunkX, chunkZ, startX, startZ, blendScratch);
|
||||
private void prefillFluidBoundaryField(IrisComplex complex, int chunkX, int chunkZ, ChunkScratch scratch) {
|
||||
int startX = PowerOfTwoCoordinates.chunkToBlock(chunkX) - FLUID_BOUNDARY_PADDING;
|
||||
int startZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ) - FLUID_BOUNDARY_PADDING;
|
||||
fillFieldHeights(complex.getNaturalHeightStream(), chunkX, chunkZ, startX, startZ, scratch);
|
||||
double fluidHeight = complex.getFluidHeight();
|
||||
Arrays.fill(blendScratch.fieldFluidHeights, fluidHeight);
|
||||
fillFieldFluidPresence(complex.getFluidStream(), chunkX, chunkZ, startX, startZ, Math.round(fluidHeight), blendScratch);
|
||||
fillFieldObjects(complex.getRegionStream(), chunkX, chunkZ, startX, startZ, blendScratch.fieldRegions, blendScratch.neighbourObjects);
|
||||
fillFieldObjects(complex.getNaturalTrueBiomeStream(), chunkX, chunkZ, startX, startZ, blendScratch.fieldSurfaceBiomes, blendScratch.neighbourObjects);
|
||||
fillFieldObjects(complex.getCaveBiomeStream(), chunkX, chunkZ, startX, startZ, blendScratch.fieldCaveBiomes, blendScratch.neighbourObjects);
|
||||
Arrays.fill(scratch.fieldFluidHeights, fluidHeight);
|
||||
fillFieldFluidPresence(complex.getFluidStream(), chunkX, chunkZ, startX, startZ, Math.round(fluidHeight), scratch);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> void fillFieldObjects(ProceduralStream<T> stream, int chunkX, int chunkZ, int startX, int startZ, T[] target, Object[][] neighbourObjects) {
|
||||
if (stream instanceof BakedStream<?> baked) {
|
||||
for (int neighbour = 0; neighbour < NEIGHBOURS; neighbour++) {
|
||||
baked.fillColumns(chunkX + NEIGHBOUR_DX[neighbour], chunkZ + NEIGHBOUR_DZ[neighbour],
|
||||
NEIGHBOUR_COLUMNS[neighbour], neighbourObjects[neighbour]);
|
||||
}
|
||||
for (int fieldIndex = 0; fieldIndex < target.length; fieldIndex++) {
|
||||
target[fieldIndex] = (T) neighbourObjects[FIELD_NEIGHBOUR[fieldIndex]][FIELD_COLUMN[fieldIndex]];
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (int fieldX = 0; fieldX < FIELD_SIZE; fieldX++) {
|
||||
int worldX = startX + fieldX;
|
||||
for (int fieldZ = 0; fieldZ < FIELD_SIZE; fieldZ++) {
|
||||
target[(fieldX * FIELD_SIZE) + fieldZ] = stream.get(worldX, startZ + fieldZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillFieldHeights(ProceduralStream<Double> stream, int chunkX, int chunkZ, int startX, int startZ, BlendScratch blendScratch) {
|
||||
double[] target = blendScratch.fieldSurfaceHeights;
|
||||
private void fillFieldHeights(ProceduralStream<Double> stream, int chunkX, int chunkZ, int startX, int startZ, ChunkScratch scratch) {
|
||||
double[] target = scratch.fieldSurfaceHeights;
|
||||
if (stream instanceof BakedDoubleStream baked) {
|
||||
double[][] neighbourHeights = blendScratch.neighbourHeights;
|
||||
double[][] neighbourHeights = scratch.neighbourHeights;
|
||||
for (int neighbour = 0; neighbour < NEIGHBOURS; neighbour++) {
|
||||
baked.fillColumns(chunkX + NEIGHBOUR_DX[neighbour], chunkZ + NEIGHBOUR_DZ[neighbour],
|
||||
NEIGHBOUR_COLUMNS[neighbour], neighbourHeights[neighbour]);
|
||||
@@ -601,11 +306,11 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
private void fillFieldFluidPresence(ProceduralStream<NativeBlockState> stream, int chunkX, int chunkZ, int startX, int startZ,
|
||||
long roundedFluidHeight, BlendScratch blendScratch) {
|
||||
double[] surfaceHeights = blendScratch.fieldSurfaceHeights;
|
||||
boolean[] target = blendScratch.fieldHasFluid;
|
||||
long roundedFluidHeight, ChunkScratch scratch) {
|
||||
double[] surfaceHeights = scratch.fieldSurfaceHeights;
|
||||
boolean[] target = scratch.fieldHasFluid;
|
||||
if (stream instanceof BakedStream<?> baked) {
|
||||
long[][] submerged = blendScratch.neighbourSubmerged;
|
||||
long[][] submerged = scratch.neighbourSubmerged;
|
||||
for (long[] columns : submerged) {
|
||||
Arrays.fill(columns, 0L);
|
||||
}
|
||||
@@ -615,7 +320,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
submerged[FIELD_NEIGHBOUR[fieldIndex]][column >>> 6] |= 1L << (column & 63);
|
||||
}
|
||||
}
|
||||
Object[][] neighbourObjects = blendScratch.neighbourObjects;
|
||||
Object[][] neighbourObjects = scratch.neighbourObjects;
|
||||
for (int neighbour = 0; neighbour < NEIGHBOURS; neighbour++) {
|
||||
long[] columns = submerged[neighbour];
|
||||
if ((columns[0] | columns[1] | columns[2] | columns[3]) != 0L) {
|
||||
@@ -639,30 +344,6 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private IrisCaveCarver3D getCarver(IrisCaveProfile profile) {
|
||||
IrisCaveCarver3D carver = profileCarvers.get(profile);
|
||||
if (carver != null) {
|
||||
return carver;
|
||||
}
|
||||
|
||||
IrisCaveCarver3D createdCarver = new IrisCaveCarver3D(getEngineMantle().getEngine(), profile, densityGrid);
|
||||
synchronized (profileCarverLock) {
|
||||
IrisCaveCarver3D published = profileCarvers.get(profile);
|
||||
if (published != null) {
|
||||
return published;
|
||||
}
|
||||
|
||||
Map<IrisCaveProfile, IrisCaveCarver3D> updated = new IdentityHashMap<>(profileCarvers);
|
||||
updated.put(profile, createdCarver);
|
||||
profileCarvers = updated;
|
||||
return createdCarver;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isProfileEnabled(IrisCaveProfile profile) {
|
||||
return profile != null && profile.isEnabled();
|
||||
}
|
||||
|
||||
protected int computeRadius() {
|
||||
return 1;
|
||||
}
|
||||
@@ -679,7 +360,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
ProceduralStream<Double> naturalHeight = context.getComplex().getNaturalHeightStream();
|
||||
double[] cachedChunkHeights = null;
|
||||
if (naturalHeight instanceof ChunkFillableDoubleStream2D cachedHeightStream) {
|
||||
cachedChunkHeights = BLEND_SCRATCH.get().chunkSurfaceHeightSamples;
|
||||
cachedChunkHeights = CHUNK_SCRATCH.get().chunkSurfaceHeightSamples;
|
||||
cachedHeightStream.fillChunkDoubles(baseX, baseZ, cachedChunkHeights);
|
||||
}
|
||||
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
|
||||
@@ -697,68 +378,11 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
return surfaceHeights;
|
||||
}
|
||||
|
||||
private static int compareByCarveOrder(WeightedProfile a, WeightedProfile b) {
|
||||
int weightOrder = Double.compare(a.averageWeight, b.averageWeight);
|
||||
if (weightOrder != 0) {
|
||||
return weightOrder;
|
||||
}
|
||||
return Integer.compare(a.sequence, b.sequence);
|
||||
}
|
||||
|
||||
private static double computeAverageWeight(double[] weights) {
|
||||
if (weights == null || weights.length == 0) {
|
||||
return 0D;
|
||||
}
|
||||
double sum = 0D;
|
||||
for (double weight : weights) {
|
||||
sum += weight;
|
||||
}
|
||||
return sum / CHUNK_AREA;
|
||||
}
|
||||
|
||||
private static double clampWeight(double value) {
|
||||
if (Double.isNaN(value) || Double.isInfinite(value)) {
|
||||
return 0D;
|
||||
}
|
||||
if (value <= 0D) {
|
||||
return 0D;
|
||||
}
|
||||
if (value >= 1D) {
|
||||
return 1D;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static final class WeightedProfile {
|
||||
private final IrisCaveProfile profile;
|
||||
private final double[] columnWeights;
|
||||
private final double averageWeight;
|
||||
private final IrisRange worldYRange;
|
||||
private final int sequence;
|
||||
|
||||
private WeightedProfile(IrisCaveProfile profile, double[] columnWeights, double averageWeight, IrisRange worldYRange, int sequence) {
|
||||
this.profile = profile;
|
||||
this.columnWeights = columnWeights;
|
||||
this.averageWeight = averageWeight;
|
||||
this.worldYRange = worldYRange;
|
||||
this.sequence = sequence;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BlendScratch {
|
||||
private final IrisCaveProfile[] profileField = new IrisCaveProfile[FIELD_SIZE * FIELD_SIZE];
|
||||
private final IrisCaveProfile[] kernelProfiles = new IrisCaveProfile[KERNEL_SIZE];
|
||||
private final double[] kernelProfileWeights = new double[KERNEL_SIZE];
|
||||
private final IdentityHashMap<IrisCaveProfile, double[]> columnProfileWeights = new IdentityHashMap<>();
|
||||
private final List<double[]> weightBuffers = new ArrayList<>();
|
||||
private final List<IrisCaveProfile> profileOrder = new ArrayList<>();
|
||||
private static final class ChunkScratch {
|
||||
private final double[] fieldSurfaceHeights = new double[FIELD_SIZE * FIELD_SIZE];
|
||||
private final double[] fieldFluidHeights = new double[FIELD_SIZE * FIELD_SIZE];
|
||||
private final boolean[] fieldHasFluid = new boolean[FIELD_SIZE * FIELD_SIZE];
|
||||
private final long[] surfaceFluidBoundaries = new long[CHUNK_AREA];
|
||||
private final IrisRegion[] fieldRegions = new IrisRegion[FIELD_SIZE * FIELD_SIZE];
|
||||
private final IrisBiome[] fieldSurfaceBiomes = new IrisBiome[FIELD_SIZE * FIELD_SIZE];
|
||||
private final IrisBiome[] fieldCaveBiomes = new IrisBiome[FIELD_SIZE * FIELD_SIZE];
|
||||
private final int[] chunkSurfaceHeights = new int[CHUNK_AREA];
|
||||
private final double[] chunkSurfaceHeightSamples = new double[CHUNK_AREA];
|
||||
private final int[] caveCeilingField = new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD];
|
||||
@@ -767,35 +391,12 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
private final Object[][] neighbourObjects = new Object[NEIGHBOURS][CHUNK_AREA];
|
||||
private final long[][] neighbourSubmerged = new long[NEIGHBOURS][4];
|
||||
private final IrisDimensionCarvingResolver.State resolverState = new IrisDimensionCarvingResolver.State();
|
||||
private int nextWeightBuffer;
|
||||
private boolean inUse;
|
||||
|
||||
private double[] acquireWeights() {
|
||||
if (nextWeightBuffer < weightBuffers.size()) {
|
||||
double[] weights = weightBuffers.get(nextWeightBuffer++);
|
||||
Arrays.fill(weights, 0D);
|
||||
return weights;
|
||||
}
|
||||
double[] weights = new double[CHUNK_AREA];
|
||||
if (weightBuffers.size() < MAX_POOLED_WEIGHT_BUFFERS) {
|
||||
weightBuffers.add(weights);
|
||||
nextWeightBuffer++;
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
|
||||
private void release() {
|
||||
Arrays.fill(profileField, null);
|
||||
Arrays.fill(kernelProfiles, null);
|
||||
Arrays.fill(fieldRegions, null);
|
||||
Arrays.fill(fieldSurfaceBiomes, null);
|
||||
Arrays.fill(fieldCaveBiomes, null);
|
||||
for (Object[] objects : neighbourObjects) {
|
||||
Arrays.fill(objects, null);
|
||||
}
|
||||
columnProfileWeights.clear();
|
||||
profileOrder.clear();
|
||||
nextWeightBuffer = 0;
|
||||
inUse = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
|
||||
/** Writes the carved blocks of one chunk into the cavern slices of its mantle sections, keeping the slice of each section it has used. */
|
||||
final class MantleCaveCellSink implements CaveCellSink {
|
||||
private static final int SECTION_HEIGHT_SHIFT = 4;
|
||||
private static final int SECTION_HEIGHT_MASK = (1 << SECTION_HEIGHT_SHIFT) - 1;
|
||||
|
||||
private final MantleChunk<Matter> chunk;
|
||||
private final MatterSlice<MatterCavern>[] slices;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
MantleCaveCellSink(MantleChunk<Matter> chunk, int worldHeight) {
|
||||
this.chunk = chunk;
|
||||
this.slices = new MatterSlice[PowerOfTwoCoordinates.ceilDivPow2(worldHeight, SECTION_HEIGHT_SHIFT)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int localX, int y, int localZ, MatterCavern cell) {
|
||||
sliceOf(y >> SECTION_HEIGHT_SHIFT).set(localX, y & SECTION_HEIGHT_MASK, localZ, cell);
|
||||
}
|
||||
|
||||
private MatterSlice<MatterCavern> sliceOf(int section) {
|
||||
MatterSlice<MatterCavern> slice = slices[section];
|
||||
if (slice == null) {
|
||||
slice = chunk.getOrCreate(section).slice(MatterCavern.class);
|
||||
slices[section] = slice;
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisAxisRotationClamp;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCaveAnchorMode;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
@@ -72,7 +71,6 @@ import art.arcane.iris.generation.block.DataProvider;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -82,6 +80,11 @@ import java.util.function.BiConsumer;
|
||||
|
||||
@ComponentFlag(ReservedFlag.OBJECT)
|
||||
public class MantleObjectComponent extends IrisMantleComponent {
|
||||
/** The anchor a cave object takes when its placement names none. */
|
||||
private static final IrisCaveAnchorMode DEFAULT_CAVE_ANCHOR = IrisCaveAnchorMode.FLOOR;
|
||||
private static final int CAVE_ANCHOR_SCAN_STEP_BLOCKS = 1;
|
||||
private static final int CAVE_ANCHOR_SEARCH_ATTEMPTS = 6;
|
||||
private static final int CAVE_OBJECT_MIN_DEPTH_BELOW_SURFACE_BLOCKS = 6;
|
||||
private static final long CAVE_REJECT_LOG_THROTTLE_MS = 5000L;
|
||||
private static final int BEDROCK_CLEARANCE = 6;
|
||||
static final byte LIQUID_FORCED_AIR = 3;
|
||||
@@ -473,8 +476,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int rejected = 0;
|
||||
int nullObjects = 0;
|
||||
int errors = 0;
|
||||
IrisCaveProfile biomeCaveProfile = resolveCaveProfile(caveBiome.getCaveProfile(), region.getCaveProfile());
|
||||
IrisCaveProfile regionCaveProfile = resolveCaveProfile(region.getCaveProfile(), caveBiome.getCaveProfile());
|
||||
CaveAnchorCache caveAnchorCache = new CaveAnchorCache();
|
||||
|
||||
for (IrisObjectPlacement i : surfaceBiome.getSurfaceObjects()) {
|
||||
@@ -521,7 +522,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
if (chance) {
|
||||
biomeCaveTriggered++;
|
||||
try {
|
||||
ObjectPlacementResult result = placeCaveObject(writer, rng, x, z, i, biomeCaveProfile, complex, traceRegen, x, z, "biome-cave", caveBiome.getLoadKey(), caveAnchorCache);
|
||||
ObjectPlacementResult result = placeCaveObject(writer, rng, x, z, i, complex, traceRegen, x, z, "biome-cave", caveBiome.getLoadKey(), caveAnchorCache);
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
@@ -578,7 +579,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
if (chance) {
|
||||
regionCaveTriggered++;
|
||||
try {
|
||||
ObjectPlacementResult result = placeCaveObject(writer, rng, x, z, i, regionCaveProfile, complex, traceRegen, x, z, "region-cave", null, caveAnchorCache);
|
||||
ObjectPlacementResult result = placeCaveObject(writer, rng, x, z, i, complex, traceRegen, x, z, "region-cave", null, caveAnchorCache);
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
@@ -610,13 +611,10 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeProceduralObjects(ObjectPassPlacer writer, RNG rng, int x, int z, IrisBiome surfaceBiome, IrisBiome caveBiome, IrisRegion region, IrisComplex complex) {
|
||||
IrisCaveProfile surfaceCaveProfile = resolveCaveProfile(surfaceBiome.getCaveProfile(), region.getCaveProfile());
|
||||
IrisCaveProfile regionCaveProfile = resolveCaveProfile(region.getCaveProfile(), caveBiome == null ? null : caveBiome.getCaveProfile());
|
||||
placeProceduralFrom(writer, rng, x, z, surfaceBiome.getProceduralObjects(), surfaceBiome.getName(), surfaceCaveProfile, surfaceBiome.getLoadKey());
|
||||
placeProceduralFrom(writer, rng, x, z, region.getProceduralObjects(), region.getName(), regionCaveProfile, null);
|
||||
placeProceduralFrom(writer, rng, x, z, surfaceBiome.getProceduralObjects(), surfaceBiome.getName(), surfaceBiome.getLoadKey());
|
||||
placeProceduralFrom(writer, rng, x, z, region.getProceduralObjects(), region.getName(), null);
|
||||
if (caveBiome != null && caveBiome != surfaceBiome) {
|
||||
IrisCaveProfile caveProfile = resolveCaveProfile(caveBiome.getCaveProfile(), region.getCaveProfile());
|
||||
placeProceduralFrom(writer, rng, x, z, caveBiome.getProceduralObjects(), caveBiome.getName(), caveProfile, caveBiome.getLoadKey());
|
||||
placeProceduralFrom(writer, rng, x, z, caveBiome.getProceduralObjects(), caveBiome.getName(), caveBiome.getLoadKey());
|
||||
}
|
||||
if (complex.getSubterrainPlanner() != null && !complex.getSubterrainPlanner().isEmpty()) {
|
||||
Set<String> placed = new HashSet<>();
|
||||
@@ -630,8 +628,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
IrisBiome featureBiome = getData().getBiomeLoader().load(plan.biome());
|
||||
if (featureBiome != null) {
|
||||
placeProceduralFrom(writer, rng, x, z, featureBiome.getProceduralObjects(), featureBiome.getName(),
|
||||
resolveCaveProfile(featureBiome.getCaveProfile(), region.getCaveProfile()), featureBiome.getLoadKey());
|
||||
placeProceduralFrom(writer, rng, x, z, featureBiome.getProceduralObjects(), featureBiome.getName(), featureBiome.getLoadKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,7 +642,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int z,
|
||||
IrisProceduralObjects proceduralObjects,
|
||||
String scope,
|
||||
IrisCaveProfile caveProfile,
|
||||
String expectedCaveBiomeKey
|
||||
) {
|
||||
if (proceduralObjects == null || proceduralObjects.isEmpty()) {
|
||||
@@ -672,13 +668,13 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
IrisObjectPlacement placement = p.asPlacement();
|
||||
boolean carving = placement.getCarvingSupport() == CarvingMode.CARVING_ONLY;
|
||||
IrisCaveAnchorMode anchorMode = resolveAnchorMode(placement, caveProfile);
|
||||
IrisCaveAnchorMode anchorMode = resolveAnchorMode(placement);
|
||||
if (placement.getMode() == ObjectPlaceMode.CEILING_HANG) {
|
||||
anchorMode = IrisCaveAnchorMode.CEILING;
|
||||
}
|
||||
int anchorScanStep = resolveAnchorScanStep(caveProfile);
|
||||
int minDepthBelowSurface = resolveObjectMinDepthBelowSurface(caveProfile);
|
||||
int anchorSearchAttempts = resolveAnchorSearchAttempts(caveProfile);
|
||||
int anchorScanStep = CAVE_ANCHOR_SCAN_STEP_BLOCKS;
|
||||
int minDepthBelowSurface = CAVE_OBJECT_MIN_DEPTH_BELOW_SURFACE_BLOCKS;
|
||||
int anchorSearchAttempts = CAVE_ANCHOR_SEARCH_ATTEMPTS;
|
||||
IObjectPlacer basePlacer = p.isPlausible() ? new DecayControlPlacer(writer) : writer;
|
||||
IObjectPlacer placer = golden ? new GoldenDebugObjectPlacer(basePlacer, scope + "/" + p.getName()) : basePlacer;
|
||||
int density = Math.max(1, p.getDensity());
|
||||
@@ -745,7 +741,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
+ " zz=" + zz
|
||||
+ " caveFloorY=" + caveFloorY);
|
||||
}
|
||||
IrisObjectPlacement effectivePlacement = resolveCavePlacement(placement, variant, caveProfile);
|
||||
IrisObjectPlacement effectivePlacement = resolveEffectivePlacement(placement, variant);
|
||||
ContainedPlacementResult contained = placeContainedCaveObject(
|
||||
placer,
|
||||
variant,
|
||||
@@ -849,7 +845,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
? null
|
||||
: writer.getDataIfPresent(candidateX, candidateY, candidateZ, MatterCavern.class);
|
||||
if (candidateY < 0
|
||||
|| caveAnchorBiomeConflicts(candidateX, candidateY, candidateZ, expectedCaveBiomeKey)
|
||||
|| caveAnchorBiomeConflicts(candidateX, candidateY, candidateZ, cavern, expectedCaveBiomeKey)
|
||||
|| !acceptsCaveAnchorAt(candidateX, candidateY, candidateZ, underwater, cavern, hydrology)) {
|
||||
continue;
|
||||
}
|
||||
@@ -1048,12 +1044,13 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private boolean caveAnchorBiomeConflicts(int x, int y, int z, String expectedCaveBiomeKey) {
|
||||
private boolean caveAnchorBiomeConflicts(int x, int y, int z, MatterCavern carvedCell, String expectedCaveBiomeKey) {
|
||||
if (expectedCaveBiomeKey == null) {
|
||||
return false;
|
||||
}
|
||||
Engine engine = getEngineMantle().getEngine();
|
||||
IrisBiome at = engine.getCaveBiome(x, y, z);
|
||||
IrisBiome carvedBiome = engine.carvedCaveBiome(carvedCell);
|
||||
IrisBiome at = carvedBiome != null ? carvedBiome : engine.getCaveBiome(x, y, z);
|
||||
IrisBiome surface = engine.getComplex().getTrueBiomeStream().get(x, z);
|
||||
return caveAnchorBiomeConflicts(at, surface, expectedCaveBiomeKey);
|
||||
}
|
||||
@@ -1078,7 +1075,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
IrisObjectPlacement objectPlacement,
|
||||
IrisCaveProfile caveProfile,
|
||||
IrisComplex complex,
|
||||
boolean traceRegen,
|
||||
int metricChunkX,
|
||||
@@ -1095,13 +1091,13 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int minX = chunkX << 4;
|
||||
int minZ = chunkZ << 4;
|
||||
int density = objectPlacement.getDensity(rng, minX, minZ, getData());
|
||||
IrisCaveAnchorMode anchorMode = resolveAnchorMode(objectPlacement, caveProfile);
|
||||
IrisCaveAnchorMode anchorMode = resolveAnchorMode(objectPlacement);
|
||||
if (objectPlacement.getMode() == ObjectPlaceMode.CEILING_HANG) {
|
||||
anchorMode = IrisCaveAnchorMode.CEILING;
|
||||
}
|
||||
int anchorScanStep = resolveAnchorScanStep(caveProfile);
|
||||
int objectMinDepthBelowSurface = resolveObjectMinDepthBelowSurface(caveProfile);
|
||||
int anchorSearchAttempts = resolveAnchorSearchAttempts(caveProfile);
|
||||
int anchorScanStep = CAVE_ANCHOR_SCAN_STEP_BLOCKS;
|
||||
int objectMinDepthBelowSurface = CAVE_OBJECT_MIN_DEPTH_BELOW_SURFACE_BLOCKS;
|
||||
int anchorSearchAttempts = CAVE_ANCHOR_SEARCH_ATTEMPTS;
|
||||
|
||||
for (int i = 0; i < density; i++) {
|
||||
attempts++;
|
||||
@@ -1174,7 +1170,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
int z = anchor.z();
|
||||
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
IrisObjectPlacement effectivePlacement = resolveCavePlacement(objectPlacement, object, caveProfile);
|
||||
IrisObjectPlacement effectivePlacement = resolveEffectivePlacement(objectPlacement, object);
|
||||
|
||||
try {
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.waterRule());
|
||||
@@ -1513,26 +1509,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
return effectivePlacement;
|
||||
}
|
||||
|
||||
private IrisObjectPlacement resolveCavePlacement(IrisObjectPlacement objectPlacement, IrisObject object, IrisCaveProfile caveProfile) {
|
||||
IrisObjectPlacement resolvedPlacement = resolveEffectivePlacement(objectPlacement, object);
|
||||
if (resolvedPlacement.getMode() != ObjectPlaceMode.CENTER_HEIGHT || caveProfile == null) {
|
||||
return resolvedPlacement;
|
||||
}
|
||||
|
||||
ObjectPlaceMode profileMode = caveProfile.getDefaultObjectPlaceMode();
|
||||
if (profileMode == null) {
|
||||
return resolvedPlacement;
|
||||
}
|
||||
|
||||
String loadKey = object.getLoadKey();
|
||||
if (loadKey == null || loadKey.isBlank()) {
|
||||
resolvedPlacement = resolvedPlacement.toPlacement();
|
||||
} else {
|
||||
resolvedPlacement = resolvedPlacement.toPlacement(loadKey);
|
||||
}
|
||||
resolvedPlacement.setMode(profileMode);
|
||||
return resolvedPlacement;
|
||||
}
|
||||
|
||||
static int proceduralFloorY(IObjectPlacer placer, int x, int scannedY, int z) {
|
||||
int floorY = scannedY;
|
||||
@@ -1633,63 +1609,12 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
};
|
||||
}
|
||||
|
||||
private IrisCaveProfile resolveCaveProfile(IrisCaveProfile preferred, IrisCaveProfile secondary) {
|
||||
IrisCaveProfile dimensionProfile = getDimension().getCaveProfile();
|
||||
if (preferred != null && preferred.isEnabled()) {
|
||||
return preferred;
|
||||
}
|
||||
|
||||
if (secondary != null && secondary.isEnabled()) {
|
||||
return secondary;
|
||||
}
|
||||
|
||||
if (dimensionProfile != null) {
|
||||
return dimensionProfile;
|
||||
}
|
||||
|
||||
return new IrisCaveProfile();
|
||||
}
|
||||
|
||||
private IrisCaveAnchorMode resolveAnchorMode(IrisObjectPlacement objectPlacement, IrisCaveProfile caveProfile) {
|
||||
private IrisCaveAnchorMode resolveAnchorMode(IrisObjectPlacement objectPlacement) {
|
||||
IrisCaveAnchorMode placementMode = objectPlacement.getCaveAnchorMode();
|
||||
if (placementMode != null && !placementMode.equals(IrisCaveAnchorMode.PROFILE_DEFAULT)) {
|
||||
return placementMode;
|
||||
if (placementMode == null || placementMode == IrisCaveAnchorMode.PROFILE_DEFAULT) {
|
||||
return DEFAULT_CAVE_ANCHOR;
|
||||
}
|
||||
|
||||
if (caveProfile == null) {
|
||||
return IrisCaveAnchorMode.FLOOR;
|
||||
}
|
||||
|
||||
IrisCaveAnchorMode profileMode = caveProfile.getDefaultObjectAnchor();
|
||||
if (profileMode == null || profileMode.equals(IrisCaveAnchorMode.PROFILE_DEFAULT)) {
|
||||
return IrisCaveAnchorMode.FLOOR;
|
||||
}
|
||||
|
||||
return profileMode;
|
||||
}
|
||||
|
||||
private int resolveAnchorScanStep(IrisCaveProfile caveProfile) {
|
||||
if (caveProfile == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.max(1, caveProfile.getAnchorScanStep());
|
||||
}
|
||||
|
||||
private int resolveObjectMinDepthBelowSurface(IrisCaveProfile caveProfile) {
|
||||
if (caveProfile == null) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
return Math.max(0, caveProfile.getObjectMinDepthBelowSurface());
|
||||
}
|
||||
|
||||
private int resolveAnchorSearchAttempts(IrisCaveProfile caveProfile) {
|
||||
if (caveProfile == null) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
return Math.max(1, caveProfile.getAnchorSearchAttempts());
|
||||
return placementMode;
|
||||
}
|
||||
|
||||
private boolean isRegenTraceThread() {
|
||||
@@ -1912,14 +1837,12 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
private final DataProvider dataProvider;
|
||||
private final KSet<String> warnedLargeObjects;
|
||||
private final Map<String, PlacementReach.Extent> extents;
|
||||
private final Set<ObjectPlaceMode> caveVacuumModes;
|
||||
|
||||
private ReachScan(IrisDimension dimension, DataProvider dataProvider, KSet<String> warnedLargeObjects) {
|
||||
this.dimension = dimension;
|
||||
this.dataProvider = dataProvider;
|
||||
this.warnedLargeObjects = warnedLargeObjects;
|
||||
this.extents = new HashMap<>();
|
||||
this.caveVacuumModes = caveVacuumModes(dimension, dataProvider);
|
||||
}
|
||||
|
||||
private PlacementReach dimension() {
|
||||
@@ -2038,17 +1961,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
private KList<PlacementReach.Profile> profiles(IrisObjectPlacement placement) {
|
||||
KList<PlacementReach.Profile> profiles = new KList<>(PlacementReach.profile(placement));
|
||||
if (placement.getMode() != ObjectPlaceMode.CENTER_HEIGHT
|
||||
|| placement.getCarvingSupport() == CarvingMode.SURFACE_ONLY) {
|
||||
return profiles;
|
||||
}
|
||||
for (ObjectPlaceMode mode : caveVacuumModes) {
|
||||
IrisObjectPlacement cave = placement.toPlacement(placement.getPlace().toArray(new String[0]));
|
||||
cave.setMode(mode);
|
||||
profiles.add(PlacementReach.profile(cave));
|
||||
}
|
||||
return profiles;
|
||||
return new KList<>(PlacementReach.profile(placement));
|
||||
}
|
||||
|
||||
private PlacementReach.Extent extent(String objectKey) {
|
||||
@@ -2060,32 +1973,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
extents.put(objectKey, extent);
|
||||
return extent;
|
||||
}
|
||||
|
||||
private static Set<ObjectPlaceMode> caveVacuumModes(IrisDimension dimension, DataProvider dataProvider) {
|
||||
Set<ObjectPlaceMode> modes = EnumSet.noneOf(ObjectPlaceMode.class);
|
||||
addCaveVacuumMode(modes, dimension.getCaveProfile());
|
||||
for (IrisRegion region : dimension.getAllRegions(dataProvider)) {
|
||||
if (region != null) {
|
||||
addCaveVacuumMode(modes, region.getCaveProfile());
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(dataProvider)) {
|
||||
if (biome != null) {
|
||||
addCaveVacuumMode(modes, biome.getCaveProfile());
|
||||
}
|
||||
}
|
||||
return modes;
|
||||
}
|
||||
|
||||
private static void addCaveVacuumMode(Set<ObjectPlaceMode> modes, IrisCaveProfile profile) {
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
ObjectPlaceMode mode = profile.getDefaultObjectPlaceMode();
|
||||
if (mode != null && IrisObjectVacuum.isVacuumMode(mode)) {
|
||||
modes.add(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
||||
+38
-24
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.stream.GenerationStreams;
|
||||
import art.arcane.iris.generation.stream.WeightedStream;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -221,14 +222,8 @@ public final class DimensionTerrainContext implements DataProvider {
|
||||
ProceduralStream<Double> regionStyleStream = dimension.getRegionStyle()
|
||||
.create(rng.nextParallelRNG(883), dimensionData).stream()
|
||||
.zoom(dimension.getRegionZoom());
|
||||
KList<IrisRegion> regionPool = new KList<>();
|
||||
for (IrisRegion region : dimensionData.getRegionLoader().loadAll(dimension.getRegions())) {
|
||||
if (!region.isCompatExcluded()) {
|
||||
regionPool.add(region);
|
||||
}
|
||||
}
|
||||
ProceduralStream<IrisRegion> proceduralRegionStream = focusRegion == null
|
||||
? regionStyleStream.selectRarity(regionPool)
|
||||
? selectRegions(dimension, dimensionData, regionStyleStream)
|
||||
: ProceduralStream.of(
|
||||
(x, z) -> focusRegion,
|
||||
Interpolated.of(value -> 0D, value -> focusRegion)
|
||||
@@ -503,6 +498,35 @@ public final class DimensionTerrainContext implements DataProvider {
|
||||
return mappedBlock == null ? proceduralBlock : mappedBlock;
|
||||
}
|
||||
|
||||
static ProceduralStream<IrisRegion> selectRegions(
|
||||
IrisDimension dimension,
|
||||
IrisData data,
|
||||
ProceduralStream<Double> regionStyleStream
|
||||
) {
|
||||
if (dimension.hasWeightedRegions()) {
|
||||
return new WeightedStream<>(regionStyleStream, dimension.getWeightedRegions(data));
|
||||
}
|
||||
KList<IrisRegion> regionPool = new KList<>();
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(dimension.getRegionKeys())) {
|
||||
if (!region.isCompatExcluded()) {
|
||||
regionPool.add(region);
|
||||
}
|
||||
}
|
||||
return regionStyleStream.selectRarity(regionPool);
|
||||
}
|
||||
|
||||
static ProceduralStream<IrisBiome> selectBiomes(
|
||||
ProceduralStream<Double> pickNoise,
|
||||
IrisData data,
|
||||
IrisRegion region,
|
||||
InferredType type
|
||||
) {
|
||||
if (region.hasWeightedBiomes(type)) {
|
||||
return new WeightedStream<>(pickNoise, region.getWeightedBiomes(data, type));
|
||||
}
|
||||
return pickNoise.selectRarity(loadInferredBiomes(data, region.getBiomeKeys(type), type));
|
||||
}
|
||||
|
||||
private static Map<IrisRegion, Map<InferredType, ProceduralStream<IrisBiome>>> compileInferredBiomeStreams(
|
||||
IrisDimension dimension,
|
||||
IrisData data,
|
||||
@@ -535,23 +559,20 @@ public final class DimensionTerrainContext implements DataProvider {
|
||||
InferredType type
|
||||
) {
|
||||
return switch (type) {
|
||||
case LAND -> dimension.getLandBiomeStyle()
|
||||
case LAND -> selectBiomes(dimension.getLandBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.LAND.ordinal()), data).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(dimension.getLandZoom())
|
||||
.zoom(region.getLandBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(data, region.getLandBiomes(), InferredType.LAND));
|
||||
case SEA -> dimension.getSeaBiomeStyle()
|
||||
.zoom(region.getLandBiomeZoom()), data, region, InferredType.LAND);
|
||||
case SEA -> selectBiomes(dimension.getSeaBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SEA.ordinal()), data).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(dimension.getSeaZoom())
|
||||
.zoom(region.getSeaBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(data, region.getSeaBiomes(), InferredType.SEA));
|
||||
case SHORE -> dimension.getShoreBiomeStyle()
|
||||
.zoom(region.getSeaBiomeZoom()), data, region, InferredType.SEA);
|
||||
case SHORE -> selectBiomes(dimension.getShoreBiomeStyle()
|
||||
.create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), data).stream()
|
||||
.zoom(dimension.getBiomeZoom())
|
||||
.zoom(region.getShoreBiomeZoom())
|
||||
.selectRarity(loadInferredBiomes(data, region.getShoreBiomes(), InferredType.SHORE));
|
||||
.zoom(region.getShoreBiomeZoom()), data, region, InferredType.SHORE);
|
||||
default -> throw new IllegalArgumentException("Unsupported stacked terrain biome type: " + type);
|
||||
};
|
||||
}
|
||||
@@ -607,14 +628,7 @@ public final class DimensionTerrainContext implements DataProvider {
|
||||
synchronized (childSelectionPlans) {
|
||||
selectionPlan = childSelectionPlans.get(biome);
|
||||
if (selectionPlan == null) {
|
||||
KList<IrisBiome> options = new KList<>();
|
||||
for (IrisBiome child : biome.getRealChildren(dataProvider)) {
|
||||
if (child != null) {
|
||||
options.add(child);
|
||||
}
|
||||
}
|
||||
options.add(biome);
|
||||
selectionPlan = IrisComplex.ChildSelectionPlan.create(options);
|
||||
selectionPlan = IrisComplex.ChildSelectionPlan.of(biome, dataProvider);
|
||||
childSelectionPlans.put(biome, selectionPlan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,11 +365,12 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
if (featureBiome != null) {
|
||||
return featureBiome;
|
||||
}
|
||||
IrisBiome mantleBiome = customCaveBiome(getMantle().getMantle().get(x, y, z, MatterCavern.class));
|
||||
IrisBiome mantleBiome = carvedCaveBiome(getMantle().getMantle().get(x, y, z, MatterCavern.class));
|
||||
return mantleBiome != null ? mantleBiome : getCaveBiome(x, y, z);
|
||||
}
|
||||
|
||||
private IrisBiome customCaveBiome(MatterCavern cavern) {
|
||||
/** The cave biome a carved cell was painted with by the cave that carved it; null for a cell that names none. */
|
||||
default IrisBiome carvedCaveBiome(MatterCavern cavern) {
|
||||
if (cavern != null && cavern.getCustomBiome() != null && !cavern.getCustomBiome().isEmpty()) {
|
||||
return getData().getBiomeLoader().load(cavern.getCustomBiome());
|
||||
}
|
||||
@@ -428,7 +429,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
cavernChunkResolved = true;
|
||||
}
|
||||
IrisBiome biome = cavernChunk == null || y < 0 || y >= getMantle().getMantle().getWorldHeight()
|
||||
? null : customCaveBiome(cavernChunk.get(x & 15, y, z & 15, MatterCavern.class));
|
||||
? null : carvedCaveBiome(cavernChunk.get(x & 15, y, z & 15, MatterCavern.class));
|
||||
if (biome == null) {
|
||||
biome = resolveConfiguredCaveBiome(x, y, z, null);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import art.arcane.iris.generation.stream.GenerationStreams;
|
||||
import art.arcane.iris.generation.stream.RarityStream;
|
||||
import art.arcane.iris.generation.stream.CachedStream2D;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.stream.WeightedStream;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlanner;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
|
||||
|
||||
@@ -63,6 +64,7 @@ import art.arcane.iris.generation.terrain.InferredType;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeGeneratorLink;
|
||||
import art.arcane.iris.pack.value.IrisRaritySelection;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.generation.noise.IrisGenerator;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.terrain.ContinentGenerator;
|
||||
@@ -368,7 +370,7 @@ public class IrisComplex implements DataProvider {
|
||||
prepareInferredBiomes(focusRegion, preparedRegions);
|
||||
focusRegion.getNaturalBiomes(this).forEach(this::registerGenerators);
|
||||
} else {
|
||||
engine.getDimension().getRegions().forEach(regionKey -> {
|
||||
engine.getDimension().getRegionKeys().forEach(regionKey -> {
|
||||
IrisRegion region = data.getRegionLoader().load(regionKey);
|
||||
if (region == null || region.isCompatExcluded()) {
|
||||
return;
|
||||
@@ -1166,8 +1168,10 @@ public class IrisComplex implements DataProvider {
|
||||
InferredType inferredType,
|
||||
IrisBiome emptyBiome
|
||||
) {
|
||||
ProceduralStream<IrisBiome> picked = new RarityStream<>(biomePickNoiseStream(engine.getDimension(), region, inferredType),
|
||||
loadInferredBiomes(biomeKeys(region, inferredType), inferredType));
|
||||
ProceduralStream<Double> pickNoise = biomePickNoiseStream(engine.getDimension(), region, inferredType);
|
||||
ProceduralStream<IrisBiome> picked = region.hasWeightedBiomes(inferredType)
|
||||
? new WeightedStream<>(pickNoise, region.getWeightedBiomes(data, inferredType))
|
||||
: new RarityStream<>(pickNoise, loadInferredBiomes(biomeKeys(region, inferredType), inferredType));
|
||||
return inferredType == InferredType.CAVE ? picked.onNull(emptyBiome) : picked;
|
||||
}
|
||||
|
||||
@@ -1195,12 +1199,7 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
|
||||
private static KList<String> biomeKeys(IrisRegion region, InferredType inferredType) {
|
||||
return switch (inferredType) {
|
||||
case CAVE -> region.getCaveBiomes();
|
||||
case LAND -> region.getLandBiomes();
|
||||
case SEA -> region.getSeaBiomes();
|
||||
case SHORE -> region.getShoreBiomes();
|
||||
};
|
||||
return region.getBiomeKeys(inferredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1234,7 +1233,7 @@ public class IrisComplex implements DataProvider {
|
||||
*/
|
||||
public KList<IrisRegion> noisePickedRegions() {
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(terrainEngine.getDimension().getRegions())) {
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(terrainEngine.getDimension().getRegionKeys())) {
|
||||
if (!region.isCompatExcluded()) {
|
||||
regions.add(region);
|
||||
}
|
||||
@@ -2256,10 +2255,10 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
|
||||
private void prepareInferredBiomes(IrisRegion region, KList<IrisRegion> preparedRegions) {
|
||||
loadInferredBiomes(region.getLandBiomes(), InferredType.LAND);
|
||||
loadInferredBiomes(region.getCaveBiomes(), InferredType.CAVE);
|
||||
loadInferredBiomes(region.getSeaBiomes(), InferredType.SEA);
|
||||
loadInferredBiomes(region.getShoreBiomes(), InferredType.SHORE);
|
||||
loadInferredBiomes(region.getLandBiomeKeys(), InferredType.LAND);
|
||||
loadInferredBiomes(region.getCaveBiomeKeys(), InferredType.CAVE);
|
||||
loadInferredBiomes(region.getSeaBiomeKeys(), InferredType.SEA);
|
||||
loadInferredBiomes(region.getShoreBiomeKeys(), InferredType.SHORE);
|
||||
preparedRegions.add(region);
|
||||
}
|
||||
|
||||
@@ -2383,8 +2382,8 @@ public class IrisComplex implements DataProvider {
|
||||
Set<IrisBiome> reached = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
ArrayDeque<IrisBiome> pending = new ArrayDeque<>();
|
||||
for (IrisRegion region : regions) {
|
||||
pending.addAll(loadInferredBiomes(region.getLandBiomes(), InferredType.LAND));
|
||||
pending.addAll(loadInferredBiomes(region.getSeaBiomes(), InferredType.SEA));
|
||||
pending.addAll(loadInferredBiomes(region.getLandBiomeKeys(), InferredType.LAND));
|
||||
pending.addAll(loadInferredBiomes(region.getSeaBiomeKeys(), InferredType.SEA));
|
||||
}
|
||||
pending.addAll(imageMapRuntime.getMappedBiomes());
|
||||
while (!pending.isEmpty()) {
|
||||
@@ -2589,16 +2588,7 @@ public class IrisComplex implements DataProvider {
|
||||
return synchronizedPlan;
|
||||
}
|
||||
|
||||
KList<IrisBiome> children = biome.getRealChildren(this);
|
||||
KList<IrisBiome> options = new KList<>();
|
||||
for (IrisBiome child : children) {
|
||||
if (child != null) {
|
||||
options.add(child);
|
||||
}
|
||||
}
|
||||
options.add(biome);
|
||||
|
||||
ChildSelectionPlan createdPlan = ChildSelectionPlan.create(options);
|
||||
ChildSelectionPlan createdPlan = ChildSelectionPlan.of(biome, this);
|
||||
IdentityHashMap<IrisBiome, ChildSelectionPlan> next = new IdentityHashMap<>(childSelectionPlans);
|
||||
next.put(biome, createdPlan);
|
||||
childSelectionPlans = next;
|
||||
@@ -2960,16 +2950,43 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
static final class ChildSelectionPlan {
|
||||
private final IrisRaritySelection<IrisBiome> selection;
|
||||
private final List<Weighted<IrisBiome>> weightedOptions;
|
||||
|
||||
private ChildSelectionPlan(IrisRaritySelection<IrisBiome> selection) {
|
||||
private ChildSelectionPlan(IrisRaritySelection<IrisBiome> selection, List<Weighted<IrisBiome>> weightedOptions) {
|
||||
this.selection = selection;
|
||||
this.weightedOptions = weightedOptions;
|
||||
}
|
||||
|
||||
static ChildSelectionPlan create(KList<IrisBiome> options) {
|
||||
return new ChildSelectionPlan(IrisRaritySelection.create(options));
|
||||
return new ChildSelectionPlan(IrisRaritySelection.create(options), null);
|
||||
}
|
||||
|
||||
static ChildSelectionPlan createWeighted(List<Weighted<IrisBiome>> options) {
|
||||
return new ChildSelectionPlan(null, List.copyOf(options));
|
||||
}
|
||||
|
||||
static ChildSelectionPlan of(IrisBiome biome, DataProvider provider) {
|
||||
if (biome.hasWeightedChildren()) {
|
||||
KList<Weighted<IrisBiome>> weightedChildren = biome.getWeightedChildren(provider);
|
||||
if (!weightedChildren.isEmpty()) {
|
||||
return createWeighted(weightedChildren);
|
||||
}
|
||||
}
|
||||
|
||||
KList<IrisBiome> options = new KList<>();
|
||||
for (IrisBiome child : biome.getRealChildren(provider)) {
|
||||
if (child != null) {
|
||||
options.add(child);
|
||||
}
|
||||
}
|
||||
options.add(biome);
|
||||
return create(options);
|
||||
}
|
||||
|
||||
IrisBiome select(CNG childCell, double x, double z) {
|
||||
if (weightedOptions != null) {
|
||||
return Weighted.pick(weightedOptions, childCell.noiseFast2D(x, z), Weighted.Edge.LATER);
|
||||
}
|
||||
long maximumIndex = selection.size() - 1L;
|
||||
if (maximumIndex <= 0L) {
|
||||
return selection.get(0L);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package art.arcane.iris.generation.stream;
|
||||
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.volmlib.util.stream.BasicStream;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class WeightedStream<T> extends BasicStream<T> {
|
||||
private final ProceduralStream<?> noise;
|
||||
private final List<Weighted<T>> entries;
|
||||
|
||||
public WeightedStream(ProceduralStream<?> noise, List<Weighted<T>> entries) {
|
||||
super();
|
||||
this.noise = Objects.requireNonNull(noise, "Weighted noise");
|
||||
this.entries = List.copyOf(entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
return Weighted.pick(entries, noise.getDouble(x, z), Weighted.Edge.EARLIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double y, double z) {
|
||||
return Weighted.pick(entries, noise.getDouble(x, y, z), Weighted.Edge.EARLIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(T t) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromDouble(double d) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,11 @@ package art.arcane.iris.generation.terrain;
|
||||
import art.arcane.iris.world.entity.IrisSpawnGroup;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeCustom;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.generation.biome.IrisCustomBiomeAliasResolver;
|
||||
import art.arcane.iris.generation.biome.IrisFloatingChildBiomes;
|
||||
import art.arcane.iris.generation.biome.IrisSurfaceLayerFallback;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositVariant;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
@@ -42,6 +43,8 @@ import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.transform.IrisTerrainTransform;
|
||||
import art.arcane.iris.pack.validation.CompatPools;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.pack.value.WeightedReference;
|
||||
import art.arcane.iris.structure.nativegen.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.structure.nativegen.IrisImportedStructureControl;
|
||||
import art.arcane.iris.structure.object.IrisObjectScale;
|
||||
@@ -229,8 +232,10 @@ public class IrisDimension extends IrisRegistrant {
|
||||
@ArrayType(type = IrisSubterrainFeature.class, min = 1)
|
||||
@Description("Deterministic bounded underground features with owned geometry, biome, fluids and room formations.")
|
||||
private KList<IrisSubterrainFeature> subterrainFeatures = new KList<>();
|
||||
@Description("Profile-driven 3D cave configuration")
|
||||
private IrisCaveProfile caveProfile = new IrisCaveProfile();
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
@RegistryListResource(IrisCave.class)
|
||||
@Description("Caves that carve everywhere in this dimension, by their file in the pack's caves folder. The lists of the dimension, region and biomes of a place add up: every cave any of them lists carves there.")
|
||||
private KList<String> caves = new KList<>();
|
||||
@Description("Water that follows how rain drains across the terrain: rivers and streams that step through every elevation, and ponds and lakes at any height.")
|
||||
private IrisHydrology hydrology = null;
|
||||
@Description("Water settings for this dimension: rainfall, pond density, where streams and ponds may form, and the fluid that fills them. Regions and biomes inherit every value they leave unset.")
|
||||
@@ -249,11 +254,10 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private double allObjectScaleFactor = 1D;
|
||||
@Description("The world environment")
|
||||
private IrisEnvironment environment = IrisEnvironment.NORMAL;
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Description("Define all of the regions to include in this dimension. Dimensions -> Regions -> Biomes -> Objects etc")
|
||||
private KList<String> regions = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisRegionEntry.class)
|
||||
@Description("Define all of the regions to include in this dimension, each as a region name or an object with a region and a weight. Dimensions -> Regions -> Biomes -> Objects etc")
|
||||
private KList<IrisRegionEntry> regions = new KList<>();
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1024)
|
||||
@@ -310,11 +314,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
@IntegerOptions({4, 8, 16, 32})
|
||||
@Description("Biome height-bound sampling interval in blocks: 4, 8, 16, or 32. 4 retains the original biome blending. Larger intervals interpolate the configured generator bounds between shared anchors, smoothing small biome-height features. Generator interpolation styles and radii remain active at the anchors. Set before creating a world.")
|
||||
private int biomeBoundsSamplingStep = 4;
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
@IntegerOptions({1, 2, 4, 8})
|
||||
@Description("Vertical cave density sampling interval in blocks: 1, 2, 4, or 8. Larger intervals interpolate density while retaining cave module bounds, surface protection, and fluid rules. Changes cave geometry. Set before creating a world.")
|
||||
private int caveDensitySamplingStep = 1;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(360)
|
||||
@Description("You can rotate the input coordinates by an angle. This can make terrain appear more natural (less sharp corners and lines). This literally rotates the entire dimension by an angle. Hint: Try 12 degrees or something not on a 90 or 45 degree angle.")
|
||||
@@ -598,9 +597,9 @@ public class IrisDimension extends IrisRegistrant {
|
||||
.getBytes(StandardCharsets.UTF_8));
|
||||
IrisData data = provider.getData();
|
||||
IrisRegion region = new IrisRegion();
|
||||
region.getLandBiomes().add(biomeKey);
|
||||
region.getSeaBiomes().add(biomeKey);
|
||||
region.getShoreBiomes().add(biomeKey);
|
||||
region.getLandBiomes().add(IrisBiomeEntry.plain(biomeKey));
|
||||
region.getSeaBiomes().add(IrisBiomeEntry.plain(biomeKey));
|
||||
region.getShoreBiomes().add(IrisBiomeEntry.plain(biomeKey));
|
||||
region.setLoadKey(key);
|
||||
region.setLoader(data);
|
||||
region.setLoadFile(new File(data.getDataFolder(), data.getRegionLoader().getFolderName() + "/" + key + ".json"));
|
||||
@@ -626,8 +625,9 @@ public class IrisDimension extends IrisRegistrant {
|
||||
return regions.v();
|
||||
}
|
||||
|
||||
for (int index = 0; index < getRegions().size(); index++) {
|
||||
String key = getRegions().get(index);
|
||||
KList<String> regionKeys = getRegionKeys();
|
||||
for (int index = 0; index < regionKeys.size(); index++) {
|
||||
String key = regionKeys.get(index);
|
||||
IrisRegion region = data.getRegionLoader().load(key);
|
||||
if (region == null) {
|
||||
continue;
|
||||
@@ -667,7 +667,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
public KList<IrisRegion> getAllAnyRegions() {
|
||||
KList<IrisRegion> r = new KList<>();
|
||||
|
||||
for (String i : getRegions()) {
|
||||
for (String i : getRegionKeys()) {
|
||||
r.add(IrisData.loadAnyRegion(i, getLoader()));
|
||||
}
|
||||
|
||||
@@ -698,12 +698,14 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
Deque<String> pending = new ArrayDeque<>();
|
||||
addReachableBiomeKey(pending, getFocus());
|
||||
addListedCaveBiomeKeys(pending, data, getCaves());
|
||||
KList<IrisRegion> regions = getAllRegions(g);
|
||||
for (IrisRegion region : regions) {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
addReachableBiomeKeys(pending, region.getNaturalBiomeIds());
|
||||
addListedCaveBiomeKeys(pending, data, region.getCaves());
|
||||
}
|
||||
addReachableBiomeKeys(pending, ShoreBiomeLineages.placed(this, regions, g));
|
||||
addReachableBiomeKeys(pending, getImageMapBiomeKeys(g));
|
||||
@@ -726,7 +728,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
}
|
||||
|
||||
Set<String> visited = new HashSet<>();
|
||||
Map<String, IrisDimensionCarvingEntry> carvingEntryIndex = getCarvingEntryIndex();
|
||||
while (!pending.isEmpty()) {
|
||||
String biomeKey = pending.removeFirst();
|
||||
if (!visited.add(biomeKey)) {
|
||||
@@ -748,8 +749,9 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
visited.add(loadKey);
|
||||
biomes.put(loadKey, biome);
|
||||
addReachableBiomeKeys(pending, biome.getChildren());
|
||||
addReachableBiomeKeys(pending, biome.getChildKeys());
|
||||
addReachableBiomeKey(pending, biome.getCarvingBiome());
|
||||
addListedCaveBiomeKeys(pending, data, biome.getCaves());
|
||||
|
||||
KList<IrisFloatingChildBiomes> floatingChildren = biome.getFloatingChildBiomes();
|
||||
if (floatingChildren == null) {
|
||||
@@ -758,10 +760,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
for (IrisFloatingChildBiomes floatingChild : floatingChildren) {
|
||||
if (floatingChild != null) {
|
||||
addReachableBiomeKey(pending, floatingChild.getBiome());
|
||||
String carvingReference = floatingChild.getCarving();
|
||||
IrisDimensionCarvingEntry carvingEntry = carvingEntryIndex.get(carvingReference);
|
||||
addReachableBiomeKey(pending,
|
||||
carvingEntry == null ? carvingReference : carvingEntry.getBiome());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -841,6 +839,19 @@ public class IrisDimension extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
/** The biomes that caves listed by key paint their walls with: a cave's biome is as reachable as the cave is listed. */
|
||||
private void addListedCaveBiomeKeys(Deque<String> pending, IrisData data, Iterable<String> caveKeys) {
|
||||
if (caveKeys == null || data.getCaveLoader() == null) {
|
||||
return;
|
||||
}
|
||||
for (String caveKey : caveKeys) {
|
||||
IrisCave cave = caveKey == null || caveKey.isBlank() ? null : data.getCaveLoader().load(caveKey, false);
|
||||
if (cave != null) {
|
||||
addReachableBiomeKey(pending, cave.biome());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addReachableBiomeKey(Deque<String> pending, String biomeKey) {
|
||||
if (biomeKey != null && !biomeKey.isBlank()) {
|
||||
pending.addLast(biomeKey);
|
||||
@@ -1310,10 +1321,22 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
/** The declared region pool with unloadable and gate-excluded regions removed; drops are reported once. */
|
||||
private KList<IrisRegion> resolveRegionPool(IrisData data, List<CompatFinding> sink) {
|
||||
return CompatPools.load(data == null ? null : data.getRegionLoader(), getRegions(), data,
|
||||
return CompatPools.load(data == null ? null : data.getRegionLoader(), getRegionKeys(), data,
|
||||
"dimension", getLoadKey(), "regions", sink);
|
||||
}
|
||||
|
||||
public KList<String> getRegionKeys() {
|
||||
return WeightedReference.keys(regions);
|
||||
}
|
||||
|
||||
public boolean hasWeightedRegions() {
|
||||
return WeightedReference.anyWrittenAsObject(regions);
|
||||
}
|
||||
|
||||
public KList<Weighted<IrisRegion>> getWeightedRegions(IrisData data) {
|
||||
return CompatPools.loadWeighted(data.getRegionLoader(), regions, data, "dimension", getLoadKey(), "regions", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascade: a dimension whose every region was excluded cannot generate anything. Pack validation turns this into a
|
||||
* blocking error. Loading regions here is safe - regions never load dimensions.
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.biome.IrisBiomeEntry;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositGenerator;
|
||||
import art.arcane.iris.generation.decoration.IrisDepositVariant;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
@@ -27,6 +28,8 @@ import art.arcane.iris.generation.decoration.IrisOreBands;
|
||||
import art.arcane.iris.generation.decoration.IrisProceduralObjects;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.pack.validation.CompatPools;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.pack.value.WeightedReference;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.world.entity.IrisEffect;
|
||||
@@ -143,27 +146,25 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
@MinNumber(0.0001)
|
||||
@Description("How large cave biomes are in this region")
|
||||
private double caveBiomeZoom = 1;
|
||||
@Description("Profile-driven 3D cave configuration")
|
||||
private IrisCaveProfile caveProfile = new IrisCaveProfile();
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
@RegistryListResource(IrisCave.class)
|
||||
@Description("Caves that carve in this region, by their file in the pack's caves folder. They add to the dimension's and the biomes' lists.")
|
||||
private KList<String> caves = new KList<>();
|
||||
@Description("Water settings for this region: rainfall, pond density, where streams and ponds may form, and the fluid that fills them. A value left unset comes from the dimension.")
|
||||
private IrisHydrologyPolicy hydrologyPolicy = null;
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Description("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> landBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Description("A list of root-level sea biomes in this region. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no ocean is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> seaBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Description("A list of root-level shore biomes in this region. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no shoreline is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> shoreBiomes = new KList<>();
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Description("A list of root-level cave biomes in this region, used for carved cave interiors. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<String> caveBiomes = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Description("A list of root-level biomes in this region. Each entry is a biome name or an object with a biome and a weight. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<IrisBiomeEntry> landBiomes = new KList<>();
|
||||
@ArrayType(type = IrisBiomeEntry.class)
|
||||
@Description("A list of root-level sea biomes in this region. Each entry is a biome name or an object with a biome and a weight. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no ocean is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<IrisBiomeEntry> seaBiomes = new KList<>();
|
||||
@ArrayType(type = IrisBiomeEntry.class)
|
||||
@Description("A list of root-level shore biomes in this region. Each entry is a biome name or an object with a biome and a weight. Optional: leave empty for land-only dimensions (flat, island, or fully-land worlds where no shoreline is generated). Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<IrisBiomeEntry> shoreBiomes = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisBiomeEntry.class)
|
||||
@Description("A list of root-level cave biomes in this region, used for carved cave interiors. Each entry is a biome name or an object with a biome and a weight. Don't specify child biomes of other biomes here. Just the root parents.")
|
||||
private KList<IrisBiomeEntry> caveBiomes = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisDepositGenerator.class)
|
||||
@Description("Define regional deposit generators that add onto the global deposit generators")
|
||||
private KList<IrisDepositGenerator> deposits = new KList<>();
|
||||
@@ -305,13 +306,55 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
|
||||
public KSet<String> getNaturalBiomeIds() {
|
||||
KSet<String> names = new KSet<>();
|
||||
names.addAll(landBiomes);
|
||||
names.addAll(caveBiomes);
|
||||
names.addAll(seaBiomes);
|
||||
names.addAll(shoreBiomes);
|
||||
names.addAll(getLandBiomeKeys());
|
||||
names.addAll(getCaveBiomeKeys());
|
||||
names.addAll(getSeaBiomeKeys());
|
||||
names.addAll(getShoreBiomeKeys());
|
||||
return names;
|
||||
}
|
||||
|
||||
public KList<String> getLandBiomeKeys() {
|
||||
return WeightedReference.keys(landBiomes);
|
||||
}
|
||||
|
||||
public KList<String> getSeaBiomeKeys() {
|
||||
return WeightedReference.keys(seaBiomes);
|
||||
}
|
||||
|
||||
public KList<String> getShoreBiomeKeys() {
|
||||
return WeightedReference.keys(shoreBiomes);
|
||||
}
|
||||
|
||||
public KList<String> getCaveBiomeKeys() {
|
||||
return WeightedReference.keys(caveBiomes);
|
||||
}
|
||||
|
||||
public KList<String> getBiomeKeys(InferredType type) {
|
||||
return WeightedReference.keys(getBiomeEntries(type));
|
||||
}
|
||||
|
||||
public KList<IrisBiomeEntry> getBiomeEntries(InferredType type) {
|
||||
return switch (type) {
|
||||
case CAVE -> caveBiomes;
|
||||
case LAND -> landBiomes;
|
||||
case SEA -> seaBiomes;
|
||||
case SHORE -> shoreBiomes;
|
||||
};
|
||||
}
|
||||
|
||||
public boolean hasWeightedBiomes(InferredType type) {
|
||||
return WeightedReference.anyWrittenAsObject(getBiomeEntries(type));
|
||||
}
|
||||
|
||||
public KList<Weighted<IrisBiome>> getWeightedBiomes(IrisData data, InferredType type) {
|
||||
KList<Weighted<IrisBiome>> inferred = new KList<>();
|
||||
for (Weighted<IrisBiome> entry : CompatPools.loadWeighted(data.getBiomeLoader(), getBiomeEntries(type), data,
|
||||
"region", getLoadKey(), type.name().toLowerCase() + "Biomes", null)) {
|
||||
inferred.add(new Weighted<>(entry.value().withInferredType(type), entry.weight()));
|
||||
}
|
||||
return inferred;
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getAllBiomes(IrisDimension dimension, DataProvider g) {
|
||||
return resolveBiomes(g, getAllBiomeIds(dimension, g));
|
||||
}
|
||||
@@ -345,7 +388,7 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
|
||||
names.add(biome.getCarvingBiome());
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
names.addAll(biome.getChildKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,19 +410,19 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealCaveBiomes(DataProvider g) {
|
||||
return realCaveBiomes.aquire(() -> resolvePool(g, getCaveBiomes(), "caveBiomes", null));
|
||||
return realCaveBiomes.aquire(() -> resolvePool(g, getCaveBiomeKeys(), "caveBiomes", null));
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealShoreBiomes(DataProvider g) {
|
||||
return realShoreBiomes.aquire(() -> resolvePool(g, getShoreBiomes(), "shoreBiomes", null));
|
||||
return realShoreBiomes.aquire(() -> resolvePool(g, getShoreBiomeKeys(), "shoreBiomes", null));
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealSeaBiomes(DataProvider g) {
|
||||
return realSeaBiomes.aquire(() -> resolvePool(g, getSeaBiomes(), "seaBiomes", null));
|
||||
return realSeaBiomes.aquire(() -> resolvePool(g, getSeaBiomeKeys(), "seaBiomes", null));
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getRealLandBiomes(DataProvider g) {
|
||||
return realLandBiomes.aquire(() -> resolvePool(g, getLandBiomes(), "landBiomes", null));
|
||||
return realLandBiomes.aquire(() -> resolvePool(g, getLandBiomeKeys(), "landBiomes", null));
|
||||
}
|
||||
|
||||
/** A biome reference pool with unloadable and gate-excluded biomes removed; drops are reported once. */
|
||||
@@ -392,10 +435,7 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
public KList<IrisBiome> getAllAnyBiomes() {
|
||||
KMap<String, IrisBiome> b = new KMap<>();
|
||||
KSet<String> names = new KSet<>();
|
||||
names.addAll(landBiomes);
|
||||
names.addAll(caveBiomes);
|
||||
names.addAll(seaBiomes);
|
||||
names.addAll(shoreBiomes);
|
||||
names.addAll(getNaturalBiomeIds());
|
||||
|
||||
while (!names.isEmpty()) {
|
||||
for (String i : new KList<>(names)) {
|
||||
@@ -413,7 +453,7 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
|
||||
names.add(biome.getCarvingBiome());
|
||||
b.put(biome.getLoadKey(), biome);
|
||||
names.addAll(biome.getChildren());
|
||||
names.addAll(biome.getChildKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,9 +524,9 @@ public class IrisRegion extends IrisRegistrant implements Rarity {
|
||||
"structures[" + index + "].caveBiomes");
|
||||
}
|
||||
|
||||
base = evaluateSurfacePoolCompat(data, base, getLandBiomes(), "land");
|
||||
base = evaluateSurfacePoolCompat(data, base, getSeaBiomes(), "sea");
|
||||
return evaluateSurfacePoolCompat(data, base, getShoreBiomes(), "shore");
|
||||
base = evaluateSurfacePoolCompat(data, base, getLandBiomeKeys(), "land");
|
||||
base = evaluateSurfacePoolCompat(data, base, getSeaBiomeKeys(), "sea");
|
||||
return evaluateSurfacePoolCompat(data, base, getShoreBiomeKeys(), "shore");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.MaxNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.MinNumber;
|
||||
import art.arcane.iris.pack.schema.annotation.RegistryListResource;
|
||||
import art.arcane.iris.pack.schema.annotation.Required;
|
||||
import art.arcane.iris.pack.value.Weighted;
|
||||
import art.arcane.iris.pack.value.WeightedReference;
|
||||
import art.arcane.iris.pack.value.WeightedReferenceAdapter;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.documentation.Description;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Description("A region in the dimension's region list")
|
||||
@Data
|
||||
@JsonAdapter(IrisRegionEntry.Adapter.class)
|
||||
public class IrisRegionEntry implements WeightedReference {
|
||||
@Required
|
||||
@RegistryListResource(IrisRegion.class)
|
||||
@Description("The region (file name without .json)")
|
||||
private String region;
|
||||
@MinNumber(Weighted.MIN_WEIGHT)
|
||||
@MaxNumber(Weighted.MAX_WEIGHT)
|
||||
@Description("A weight of two is just as if this entry were listed twice in a row, making the region more common. The noise picks along the list in the order it is written.")
|
||||
private int weight = 1;
|
||||
private transient boolean writtenAsObject;
|
||||
|
||||
public IrisRegionEntry(String region, int weight, boolean writtenAsObject) {
|
||||
this.region = region;
|
||||
this.weight = weight;
|
||||
this.writtenAsObject = writtenAsObject;
|
||||
}
|
||||
|
||||
public static IrisRegionEntry plain(String region) {
|
||||
return new IrisRegionEntry(region, Weighted.MIN_WEIGHT, false);
|
||||
}
|
||||
|
||||
public static KList<IrisRegionEntry> plainList(String... regions) {
|
||||
KList<IrisRegionEntry> entries = new KList<>();
|
||||
for (String region : regions) {
|
||||
entries.add(plain(region));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReferenceKey() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public static final class Adapter extends WeightedReferenceAdapter<IrisRegionEntry> {
|
||||
public Adapter() {
|
||||
super("region");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IrisRegionEntry create(String key, int weight, boolean writtenAsObject) {
|
||||
return new IrisRegionEntry(key, weight, writtenAsObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.generation.image.IrisImageMapApplication;
|
||||
import art.arcane.iris.generation.stream.RarityStream;
|
||||
import art.arcane.iris.generation.stream.WeightedStream;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.generation.BiomeBuffetLayout;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -19,13 +20,9 @@ public final class RegionSelection {
|
||||
if (options.focused() != null) {
|
||||
return options.focused();
|
||||
}
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
for (IrisRegion region : options.data().getRegionLoader().loadAll(options.dimension().getRegions())) {
|
||||
if (!region.isCompatExcluded()) {
|
||||
regions.add(region);
|
||||
}
|
||||
}
|
||||
ProceduralStream<IrisRegion> selected = new RarityStream<>(options.style(), regions);
|
||||
ProceduralStream<IrisRegion> selected = options.dimension().hasWeightedRegions()
|
||||
? new WeightedStream<>(options.style(), options.dimension().getWeightedRegions(options.data()))
|
||||
: new RarityStream<>(options.style(), rarityRegions(options));
|
||||
if (!options.imageMaps().has(IrisImageMapApplication.REGION)) {
|
||||
return selected;
|
||||
}
|
||||
@@ -35,6 +32,16 @@ public final class RegionSelection {
|
||||
});
|
||||
}
|
||||
|
||||
private static KList<IrisRegion> rarityRegions(Options options) {
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
for (IrisRegion region : options.data().getRegionLoader().loadAll(options.dimension().getRegionKeys())) {
|
||||
if (!region.isCompatExcluded()) {
|
||||
regions.add(region);
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static ProceduralStream<IrisRegion> restore(Snapshot snapshot) {
|
||||
IrisData data = snapshot.data();
|
||||
IrisDimension dimension = snapshot.dimension();
|
||||
|
||||
@@ -68,10 +68,10 @@ public final class ShoreBiomeLineages {
|
||||
|
||||
private static void visitRegion(IrisRegion region, IrisData data, BiConsumer<List<IrisBiome>, IrisRegion> visitor) {
|
||||
List<IrisBiome> roots = new ArrayList<>();
|
||||
for (String key : region.getLandBiomes()) {
|
||||
for (String key : region.getLandBiomeKeys()) {
|
||||
addLoaded(roots, data, key);
|
||||
}
|
||||
for (String key : region.getSeaBiomes()) {
|
||||
for (String key : region.getSeaBiomeKeys()) {
|
||||
addLoaded(roots, data, key);
|
||||
}
|
||||
ArrayDeque<IrisBiome> chain = new ArrayDeque<>();
|
||||
@@ -86,7 +86,7 @@ public final class ShoreBiomeLineages {
|
||||
visitor.accept(List.copyOf(chain), region);
|
||||
if (chain.size() <= IrisBiome.CHILD_HOPS) {
|
||||
List<IrisBiome> children = new ArrayList<>();
|
||||
for (String key : biome.getChildren()) {
|
||||
for (String key : biome.getChildKeys()) {
|
||||
addLoaded(children, data, key);
|
||||
}
|
||||
for (IrisBiome child : children) {
|
||||
|
||||
@@ -78,6 +78,14 @@ public final class RuntimeUiMessages {
|
||||
public static final TextKey DUST_OBJECTS_IN_CHUNK = TextKey.of("iris.runtime.dust.objects_in_chunk", "Objects in chunk: {objects}");
|
||||
public static final TextKey DUST_COPY_BUTTON = TextKey.of("iris.runtime.dust.copy_button", "[Click to copy these stats]");
|
||||
public static final TextKey DUST_COPY_HOVER = TextKey.of("iris.runtime.dust.copy_hover", "Copy block stats to clipboard");
|
||||
public static final TextKey STUDIO_APP_DOWNLOAD_OFF = TextKey.of("iris.runtime.studio.app_download_off", "Studio app download is off: set studio.downloadApp to true in iris.json.");
|
||||
public static final TextKey STUDIO_APP_NO_DISPLAY = TextKey.of("iris.runtime.studio.app_no_display", "This server has no display to open the studio app on.");
|
||||
public static final TextKey STUDIO_APP_DOWNLOADING = TextKey.of("iris.runtime.studio.app_downloading", "Studio app is still downloading; try again in a moment.");
|
||||
public static final TextKey STUDIO_APP_UNAVAILABLE = TextKey.of("iris.runtime.studio.app_unavailable", "Studio app unavailable; see the console.");
|
||||
public static final TextKey STUDIO_APP_NOT_BUILT = TextKey.of("iris.runtime.studio.app_not_built", "Studio app not built: run npm run build in its folder.");
|
||||
public static final TextKey STUDIO_APP_FAILED_TO_START = TextKey.of("iris.runtime.studio.app_failed_to_start", "Studio app failed to start; see the console.");
|
||||
public static final TextKey STUDIO_LINK_COPY_BUTTON = TextKey.of("iris.runtime.studio.link_copy_button", "[Copy studio link]");
|
||||
public static final TextKey STUDIO_LINK_COPY_HOVER = TextKey.of("iris.runtime.studio.link_copy_hover", "Paste it into the studio app's connect screen");
|
||||
public static final TextKey DUST_REVEAL_FAILED = TextKey.of("iris.runtime.dust.reveal_failed", "Object reveal failed; see the console for details.");
|
||||
public static final TextKey DUST_BIOME_LOADING = TextKey.of("iris.runtime.dust.biome_loading", "Saved biome information is loading. Try revealing this block again shortly.");
|
||||
public static final TextKey WHAT_MATERIAL = TextKey.of("iris.runtime.what.material", "Material: {material}");
|
||||
@@ -196,6 +204,14 @@ public final class RuntimeUiMessages {
|
||||
DUST_OBJECTS_IN_CHUNK,
|
||||
DUST_COPY_BUTTON,
|
||||
DUST_COPY_HOVER,
|
||||
STUDIO_APP_DOWNLOAD_OFF,
|
||||
STUDIO_APP_NO_DISPLAY,
|
||||
STUDIO_APP_DOWNLOADING,
|
||||
STUDIO_APP_UNAVAILABLE,
|
||||
STUDIO_APP_NOT_BUILT,
|
||||
STUDIO_APP_FAILED_TO_START,
|
||||
STUDIO_LINK_COPY_BUTTON,
|
||||
STUDIO_LINK_COPY_HOVER,
|
||||
DUST_REVEAL_FAILED,
|
||||
DUST_BIOME_LOADING,
|
||||
WHAT_MATERIAL,
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
final class PackCaveProfileValidator {
|
||||
private static final String CAVE_PROFILE_SNIPPET_FOLDER = "snippet/cave-profile";
|
||||
private static final List<LegacyField> LEGACY_FIELDS = List.of(
|
||||
new LegacyField("allowWater", "allowFluid"),
|
||||
new LegacyField("waterMinDepthBelowSurface", "fluidMinDepthBelowSurface"),
|
||||
new LegacyField("waterRequiresFloor", "fluidRequiresFloor")
|
||||
);
|
||||
|
||||
private PackCaveProfileValidator() {
|
||||
}
|
||||
|
||||
static List<String> validateLegacyFields(File packFolder) {
|
||||
List<String> blockingErrors = new ArrayList<>();
|
||||
if (packFolder == null || !packFolder.isDirectory()) {
|
||||
return blockingErrors;
|
||||
}
|
||||
|
||||
for (String folderName : PackValidator.STRUCTURE_HOST_FOLDERS) {
|
||||
File resourceFolder = new File(packFolder, folderName);
|
||||
if (!resourceFolder.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
List<File> resourceFiles = PackValidationIo.listJsonRecursive(resourceFolder);
|
||||
resourceFiles.sort(Comparator.comparing(File::getPath));
|
||||
String resourceType = PackStructurePlacementValidator.structureHostType(folderName);
|
||||
for (File resourceFile : resourceFiles) {
|
||||
JSONObject resource = PackValidationIo.readJson(resourceFile);
|
||||
if (resource == null) {
|
||||
continue;
|
||||
}
|
||||
JSONObject caveProfile = resource.optJSONObject("caveProfile");
|
||||
if (caveProfile == null) {
|
||||
continue;
|
||||
}
|
||||
String resourceKey = PackValidationIo.deriveKey(resourceFolder, resourceFile);
|
||||
validateFields(resourceType + " '" + resourceKey + "' caveProfile.", "caveProfile.", caveProfile,
|
||||
blockingErrors);
|
||||
}
|
||||
}
|
||||
|
||||
File snippetFolder = new File(packFolder, CAVE_PROFILE_SNIPPET_FOLDER);
|
||||
if (!snippetFolder.isDirectory()) {
|
||||
return blockingErrors;
|
||||
}
|
||||
List<File> snippetFiles = PackValidationIo.listJsonRecursive(snippetFolder);
|
||||
snippetFiles.sort(Comparator.comparing(File::getPath));
|
||||
for (File snippetFile : snippetFiles) {
|
||||
JSONObject caveProfile = PackValidationIo.readJson(snippetFile);
|
||||
if (caveProfile == null) {
|
||||
continue;
|
||||
}
|
||||
String snippetKey = PackValidationIo.deriveKey(snippetFolder, snippetFile);
|
||||
validateFields("Cave-profile snippet '" + snippetKey + "' ", "", caveProfile, blockingErrors);
|
||||
}
|
||||
return blockingErrors;
|
||||
}
|
||||
|
||||
private static void validateFields(String location, String replacementPrefix, JSONObject caveProfile,
|
||||
List<String> blockingErrors) {
|
||||
for (LegacyField field : LEGACY_FIELDS) {
|
||||
if (caveProfile.has(field.oldName())) {
|
||||
blockingErrors.add(location + field.oldName() + " was removed; use " + replacementPrefix
|
||||
+ field.newName()
|
||||
+ ". Cave aquifers use the dimension fluidPalette, which defaults to water.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record LegacyField(String oldName, String newName) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveBounds;
|
||||
import art.arcane.iris.pack.loading.RemovedPackKeys;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Checks a pack's caves: a leftover {@code caveProfile}, which carves nothing any more, the caves that dimensions,
|
||||
* regions and biomes list under {@code caves} against the files of the {@code caves/} folder, and the numbers of each
|
||||
* cave file against what their keys allow.
|
||||
*/
|
||||
final class PackCaveValidator {
|
||||
static final String CAVES_FOLDER = "caves";
|
||||
static final String CAVES_KEY = "caves";
|
||||
static final String REMOVED_PROFILE_KEY = RemovedPackKeys.CAVE_PROFILE;
|
||||
static final String REMOVED_PROFILE_SNIPPET_FOLDER = "snippet/cave-profile";
|
||||
private static final String REMOVED_PROFILE_ADVICE = "was removed and carves no caves; list caves under \"" + CAVES_KEY + "\" instead";
|
||||
|
||||
record Validation(List<String> errors, List<String> warnings) {
|
||||
Validation {
|
||||
errors = List.copyOf(errors);
|
||||
warnings = List.copyOf(warnings);
|
||||
}
|
||||
}
|
||||
|
||||
private PackCaveValidator() {
|
||||
}
|
||||
|
||||
static Validation validate(File packFolder) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
if (packFolder == null || !packFolder.isDirectory()) {
|
||||
return new Validation(errors, warnings);
|
||||
}
|
||||
File cavesFolder = new File(packFolder, CAVES_FOLDER);
|
||||
Set<String> caveKeys = validateCaveFiles(cavesFolder, errors);
|
||||
for (String folderName : PackValidator.STRUCTURE_HOST_FOLDERS) {
|
||||
validateHosts(packFolder, folderName, caveKeys, errors, warnings);
|
||||
}
|
||||
validateRemovedProfileSnippets(packFolder, warnings);
|
||||
return new Validation(errors, warnings);
|
||||
}
|
||||
|
||||
private static Set<String> validateCaveFiles(File cavesFolder, List<String> errors) {
|
||||
Set<String> keys = new HashSet<>();
|
||||
if (!cavesFolder.isDirectory()) {
|
||||
return keys;
|
||||
}
|
||||
List<File> files = PackValidationIo.listJsonRecursive(cavesFolder);
|
||||
files.sort(Comparator.comparing(File::getPath));
|
||||
for (File file : files) {
|
||||
String key = PackValidationIo.deriveKey(cavesFolder, file);
|
||||
keys.add(key);
|
||||
validateCaveFile(key, file, errors);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static void validateCaveFile(String key, File file, List<String> errors) {
|
||||
try {
|
||||
var cave = JsonParser.parseString(Files.readString(file.toPath(), StandardCharsets.UTF_8));
|
||||
if (!cave.isJsonObject()) {
|
||||
errors.add("Cave '" + key + "' must be a JSON object.");
|
||||
return;
|
||||
}
|
||||
CaveBounds.valuesOutOfBounds(cave.getAsJsonObject()).forEach(problem -> errors.add("Cave '" + key + "' " + problem + "."));
|
||||
} catch (IOException | JsonParseException unreadable) {
|
||||
errors.add("Cave '" + key + "' is not valid JSON: " + unreadable.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateHosts(File packFolder, String folderName, Set<String> caveKeys, List<String> errors, List<String> warnings) {
|
||||
File hostFolder = new File(packFolder, folderName);
|
||||
if (!hostFolder.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
List<File> files = PackValidationIo.listJsonRecursive(hostFolder);
|
||||
files.sort(Comparator.comparing(File::getPath));
|
||||
String hostType = PackStructurePlacementValidator.structureHostType(folderName);
|
||||
for (File file : files) {
|
||||
JSONObject host = PackValidationIo.readJson(file);
|
||||
if (host == null) {
|
||||
continue;
|
||||
}
|
||||
String hostLabel = hostType + " '" + PackValidationIo.deriveKey(hostFolder, file) + "'";
|
||||
if (host.has(REMOVED_PROFILE_KEY)) {
|
||||
warnings.add(hostLabel + " still has " + REMOVED_PROFILE_KEY + ", which " + REMOVED_PROFILE_ADVICE + ".");
|
||||
}
|
||||
validateListedCaves(hostLabel, host.optJSONArray(CAVES_KEY), caveKeys, errors);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateListedCaves(String host, JSONArray listed, Set<String> caveKeys, List<String> errors) {
|
||||
if (listed == null) {
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < listed.length(); index++) {
|
||||
Object entry = listed.opt(index);
|
||||
if (!(entry instanceof String key) || key.isBlank()) {
|
||||
errors.add(host + " " + CAVES_KEY + "[" + index + "] must be the name of a file in " + CAVES_FOLDER + "/.");
|
||||
continue;
|
||||
}
|
||||
if (!caveKeys.contains(key)) {
|
||||
errors.add(host + " lists the cave '" + key + "', but the pack has no " + CAVES_FOLDER + "/" + key + ".json.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRemovedProfileSnippets(File packFolder, List<String> warnings) {
|
||||
File snippetFolder = new File(packFolder, REMOVED_PROFILE_SNIPPET_FOLDER);
|
||||
if (!snippetFolder.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
List<File> files = PackValidationIo.listJsonRecursive(snippetFolder);
|
||||
files.sort(Comparator.comparing(File::getPath));
|
||||
for (File file : files) {
|
||||
warnings.add("Snippet '" + REMOVED_PROFILE_SNIPPET_FOLDER + "/" + PackValidationIo.deriveKey(snippetFolder, file)
|
||||
+ "' is a " + REMOVED_PROFILE_KEY + ", which " + REMOVED_PROFILE_ADVICE + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,6 @@ final class PackDimensionValidator {
|
||||
validateDimensionHeights(packFolder, dimensionKey, dimJson, blockingErrors);
|
||||
validateBorrowedDimensionType(dimensionKey, dimJson, borrowedDimensionTypesSupported(), blockingErrors);
|
||||
validateSamplingStep(dimensionKey, dimJson, "terrainSamplingStep", 1, blockingErrors);
|
||||
validateSamplingStep(dimensionKey, dimJson, "caveDensitySamplingStep", 1, blockingErrors);
|
||||
validateSamplingStep(dimensionKey, dimJson, "biomeBoundsSamplingStep", 4, blockingErrors);
|
||||
validateWorldBoundary(dimensionKey, dimJson, blockingErrors);
|
||||
validateStaticObjects(packFolder, dimensionKey, dimJson, blockingErrors);
|
||||
@@ -79,7 +78,7 @@ final class PackDimensionValidator {
|
||||
|
||||
int resolvedRegions = 0;
|
||||
for (int i = 0; i < regionsArray.length(); i++) {
|
||||
String regionKey = regionsArray.optString(i, null);
|
||||
String regionKey = PackValidationIo.referenceKey(regionsArray, i, "region");
|
||||
if (regionKey == null || regionKey.isBlank()) {
|
||||
warnings.add("Dimension '" + dimensionKey + "' has a blank region entry at index " + i + ".");
|
||||
continue;
|
||||
@@ -411,7 +410,7 @@ final class PackDimensionValidator {
|
||||
}
|
||||
int resolved = 0;
|
||||
for (int i = 0; i < arr.length(); i++) {
|
||||
String biomeKey = arr.optString(i, null);
|
||||
String biomeKey = PackValidationIo.referenceKey(arr, i, "biome");
|
||||
if (biomeKey == null || biomeKey.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ final class PackImageMapValidator {
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < values.length(); index++) {
|
||||
if (biomeKey.equals(values.optString(index, null))) {
|
||||
if (biomeKey.equals(PackValidationIo.referenceKey(values, index, "biome"))) {
|
||||
roles.add(role);
|
||||
return;
|
||||
}
|
||||
@@ -561,7 +561,7 @@ final class PackImageMapValidator {
|
||||
) {
|
||||
Set<String> regionKeys = new TreeSet<>();
|
||||
if (dimension.getRegions() != null) {
|
||||
for (String regionKey : dimension.getRegions()) {
|
||||
for (String regionKey : dimension.getRegionKeys()) {
|
||||
String normalized = normalized(regionKey);
|
||||
if (normalized != null) {
|
||||
regionKeys.add(normalized);
|
||||
|
||||
@@ -31,6 +31,7 @@ public final class PackResourceCleanup {
|
||||
"loot",
|
||||
"generators",
|
||||
"expressions",
|
||||
"caves",
|
||||
"markers",
|
||||
"blocks",
|
||||
"mods"
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.Locale;
|
||||
* Catches the shared IrisStyledRange class default (min 16, max 32) leaking into pack content.
|
||||
* The POJO cannot distinguish an empty object from an explicit 16/32 after Gson runs, so the raw
|
||||
* JSON is the only place this mistake is still visible: an objects[].densityStyle of {} places
|
||||
* 16-32 objects per chunk, and a caveProfile.densityThreshold of {} hollows the whole cave range.
|
||||
* 16-32 objects per chunk.
|
||||
*/
|
||||
final class PackStyledRangeDefaultValidator {
|
||||
private static final String STYLE_RANGE_SNIPPET_FOLDER = "snippet/style-range/";
|
||||
@@ -73,7 +73,6 @@ final class PackStyledRangeDefaultValidator {
|
||||
}
|
||||
|
||||
validateObjectPlacements(packFolder, type, key, json, errors, warnings);
|
||||
validateCaveProfileThreshold(packFolder, type, key, json.optJSONObject("caveProfile"), errors, warnings);
|
||||
}
|
||||
}
|
||||
return new Validation(errors, warnings);
|
||||
@@ -97,18 +96,6 @@ final class PackStyledRangeDefaultValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateCaveProfileThreshold(File packFolder, String type, String key, JSONObject caveProfile,
|
||||
List<String> errors, List<String> warnings) {
|
||||
if (caveProfile == null || !caveProfile.has("densityThreshold") || caveProfile.isNull("densityThreshold")) {
|
||||
return;
|
||||
}
|
||||
checkRange(packFolder, caveProfile.opt("densityThreshold"),
|
||||
type + " '" + key + "' caveProfile.densityThreshold",
|
||||
"a carve threshold of 16-32, hollowing the entire vertical range",
|
||||
"remove densityThreshold to keep the cave profile default",
|
||||
errors, warnings);
|
||||
}
|
||||
|
||||
private static void checkRange(File packFolder, Object raw, String path, String consequence, String removal,
|
||||
List<String> errors, List<String> warnings) {
|
||||
JSONObject range = null;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
@@ -46,6 +47,11 @@ public final class PackValidationIo {
|
||||
}
|
||||
}
|
||||
|
||||
static String referenceKey(JSONArray references, int index, String keyField) {
|
||||
JSONObject weighted = references.optJSONObject(index);
|
||||
return weighted == null ? references.optString(index, null) : weighted.optString(keyField, null);
|
||||
}
|
||||
|
||||
static boolean isScannableJsonPath(Path path) {
|
||||
String name = path.getFileName().toString();
|
||||
if (!name.endsWith(".json")) {
|
||||
|
||||
@@ -130,7 +130,9 @@ public final class PackValidator {
|
||||
PackHydrologyValidator.validate(packFolder, dimensionFiles);
|
||||
addDistinct(blockingErrors, hydrologyValidation.errors());
|
||||
addDistinct(warnings, hydrologyValidation.warnings());
|
||||
blockingErrors.addAll(PackCaveProfileValidator.validateLegacyFields(packFolder));
|
||||
PackCaveValidator.Validation caveValidation = PackCaveValidator.validate(packFolder);
|
||||
addDistinct(blockingErrors, caveValidation.errors());
|
||||
addDistinct(warnings, caveValidation.warnings());
|
||||
addDistinct(blockingErrors, PackTerrain3DValidator.validate(packFolder));
|
||||
PackLootValidator.LootGraphIssues lootIssues = PackLootValidator.validateLootGraph(packFolder);
|
||||
addDistinct(blockingErrors, lootIssues.errors());
|
||||
|
||||
+2
-2
@@ -312,12 +312,12 @@ public final class PackCompileContext {
|
||||
}
|
||||
|
||||
private String firstLandBiome() {
|
||||
for (String regionKey : dimension.getRegions()) {
|
||||
for (String regionKey : dimension.getRegionKeys()) {
|
||||
IrisRegion region = data.getRegionLoader().load(regionKey, false);
|
||||
if (region == null || region.isCompatExcluded()) {
|
||||
continue;
|
||||
}
|
||||
for (String biomeKey : region.getLandBiomes()) {
|
||||
for (String biomeKey : region.getLandBiomeKeys()) {
|
||||
IrisBiome biome = biomeKey == null ? null : data.getBiomeLoader().load(biomeKey, false);
|
||||
if (biome != null && !biome.isCompatExcluded()) {
|
||||
return biome.getLoadKey();
|
||||
|
||||
+5
-5
@@ -40,16 +40,16 @@ final class BiomePools {
|
||||
static BiomePools load(IrisDimension dimension, IrisData data) {
|
||||
List<RegionPools> regions = new ArrayList<>();
|
||||
SortedMap<String, IrisBiome> biomes = new TreeMap<>();
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(dimension.getRegions())) {
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(dimension.getRegionKeys())) {
|
||||
if (region.isCompatExcluded()) {
|
||||
continue;
|
||||
}
|
||||
RegionPools pools = new RegionPools(
|
||||
region,
|
||||
pool(data, region.getLandBiomes(), biomes),
|
||||
pool(data, region.getSeaBiomes(), biomes),
|
||||
pool(data, region.getShoreBiomes(), biomes),
|
||||
pool(data, region.getCaveBiomes(), biomes));
|
||||
pool(data, region.getLandBiomeKeys(), biomes),
|
||||
pool(data, region.getSeaBiomeKeys(), biomes),
|
||||
pool(data, region.getShoreBiomeKeys(), biomes),
|
||||
pool(data, region.getCaveBiomeKeys(), biomes));
|
||||
if (pools.land().isEmpty() && pools.sea().isEmpty()) {
|
||||
throw new IllegalStateException("Region '" + region.getLoadKey() + "' has no land or sea biome to export");
|
||||
}
|
||||
|
||||
+6
-96
@@ -1,22 +1,15 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* The aquifer of an exported dimension: dry rock with open water where the surface lies below the fluid height. Cave
|
||||
* fluid and lava are not exported, because the caves they fill are not.
|
||||
*/
|
||||
public final class AquiferCompiler {
|
||||
private static final int LAVA_LIMIT_Y = -10;
|
||||
private static final int LAVA_CENTER_MARGIN = 12;
|
||||
private static final int FLUID_BAND_HEIGHT = 40;
|
||||
private static final int FLUID_BAND_CENTER = 20;
|
||||
private static final double SPREAD_LEVEL_SCALE = 10.0;
|
||||
private static final double LEVEL_ROUNDING_MARGIN = 0.5;
|
||||
private static final int OPEN_WATER_DEPTH = 8;
|
||||
private static final int OPEN_WATER_HEADROOM = 8;
|
||||
@@ -25,41 +18,19 @@ public final class AquiferCompiler {
|
||||
private static final int OPEN_WATER_ESTIMATE_SLACK = 40;
|
||||
private static final Field OPEN_WATER_LIFT = new Field.Const(2.0);
|
||||
private static final Field DRY = new Field.Const(-1.0);
|
||||
private static final Field PARTIAL = new Field.Const(0.6);
|
||||
private static final Field LOW_BARRIER = new Field.Const(-1.0);
|
||||
private static final Field NO_EXCLUSION = new Field.Const(-1.0);
|
||||
private static final Field LAVA = new Field.Const(1.0);
|
||||
private static final Field NO_LAVA = new Field.Const(0.0);
|
||||
private static final Field OUTSIDE_BAND = new Field.Const(0.0);
|
||||
private static final Field INSIDE_BAND = new Field.Const(1.0);
|
||||
|
||||
private final CaveInputs inputs;
|
||||
private final Field blockY;
|
||||
private final int lowFluidBand;
|
||||
private final int highFluidBand;
|
||||
|
||||
public AquiferCompiler(CaveInputs inputs) {
|
||||
this.inputs = Objects.requireNonNull(inputs);
|
||||
this.blockY = inputs.blockY();
|
||||
this.lowFluidBand = Math.floorDiv(inputs.minY(), FLUID_BAND_HEIGHT) - 1;
|
||||
this.highFluidBand = Math.floorDiv(inputs.maxY(), FLUID_BAND_HEIGHT) + 1;
|
||||
}
|
||||
|
||||
public AquiferDef compile(CaveSelection selection) {
|
||||
public AquiferDef compile() {
|
||||
AquiferDef dry = AquiferDef.dry(inputs.aquiferSurface());
|
||||
boolean lavaWanted = any(selection, IrisCaveProfile::isAllowLava);
|
||||
boolean lavaExported = lavaWanted && inputs.lavaY() <= LAVA_LIMIT_Y;
|
||||
if (lavaWanted && !lavaExported) {
|
||||
inputs.diagnostics().add(new ExportDiagnostic(ExportDiagnostic.Severity.WARNING, ExportLimit.LAVA_HEIGHT, inputs.resource(),
|
||||
"Cave lava height Y " + inputs.lavaY() + " is above Y " + LAVA_LIMIT_Y + "; caves export without lava"));
|
||||
}
|
||||
boolean wet = any(selection, IrisCaveProfile::isAllowFluid);
|
||||
if (!lavaExported && !wet) {
|
||||
return new AquiferDef(dry.barrier(), openWater(dry.floodedness()), dry.spread(), dry.lava(), dry.exclusion(), dry.surfaceLevel());
|
||||
}
|
||||
Field spread = lavaExported ? lavaSpread(wet, dry.spread()) : dry.spread();
|
||||
Field lava = lavaExported ? lavaBands() : NO_LAVA;
|
||||
return new AquiferDef(LOW_BARRIER, openWater(floodedness(selection, lavaExported)), spread, lava, NO_EXCLUSION, inputs.aquiferSurface());
|
||||
return new AquiferDef(dry.barrier(), openWater(dry.floodedness()), dry.spread(), dry.lava(), dry.exclusion(), dry.surfaceLevel());
|
||||
}
|
||||
|
||||
private Field openWater(Field caveFlood) {
|
||||
@@ -71,65 +42,4 @@ public final class AquiferCompiler {
|
||||
Field lift = new Field.Gate(aboveFloor, new Field.Gate(lowColumn, OPEN_WATER_LIFT));
|
||||
return new Field.Binary(Field.BinaryOp.ADD, caveFlood, new Field.Gate(nearFluid, new Field.Gate(lowEstimate, lift)));
|
||||
}
|
||||
|
||||
private Field floodedness(CaveSelection selection, boolean lavaExported) {
|
||||
Field flood = selection.profiles().isEmpty() ? DRY : selection.select(source -> flood(source, lavaExported), DRY);
|
||||
for (CaveSource band : selection.bands()) {
|
||||
Field banded = flood(band, lavaExported);
|
||||
if (banded.equals(flood)) {
|
||||
continue;
|
||||
}
|
||||
Field inside = new Field.Partition(blockY, List.of((double) band.minY(), band.maxY() + 1.0), List.of(OUTSIDE_BAND, INSIDE_BAND, OUTSIDE_BAND));
|
||||
flood = new Field.Mux(inside, List.of(flood, banded));
|
||||
}
|
||||
return flood;
|
||||
}
|
||||
|
||||
private Field flood(CaveSource source, boolean lavaExported) {
|
||||
IrisCaveProfile profile = source.profile();
|
||||
int top = Integer.MIN_VALUE;
|
||||
if (lavaExported && profile.isAllowLava()) {
|
||||
top = inputs.lavaY() + LAVA_CENTER_MARGIN;
|
||||
}
|
||||
if (profile.isAllowFluid()) {
|
||||
top = Math.max(top, inputs.fluidHeight());
|
||||
}
|
||||
if (top < inputs.minY()) {
|
||||
return DRY;
|
||||
}
|
||||
if (top >= inputs.maxY()) {
|
||||
return PARTIAL;
|
||||
}
|
||||
return new Field.RangeIf(blockY, inputs.minY(), top + 1.0, PARTIAL, DRY);
|
||||
}
|
||||
|
||||
private Field lavaSpread(boolean wet, Field vanillaSpread) {
|
||||
Field levels = new Field.Coord(Axis.Y, Field.Tiling.CLAMP, lowFluidBand, highFluidBand, spreadAt(lowFluidBand), spreadAt(highFluidBand));
|
||||
return wet ? new Field.RangeIf(fluidBand(), lowFluidBand, lavaBand() + 1.0, levels, vanillaSpread) : levels;
|
||||
}
|
||||
|
||||
private Field lavaBands() {
|
||||
return new Field.RangeIf(fluidBand(), lowFluidBand, lavaBand() + 1.0, LAVA, NO_LAVA);
|
||||
}
|
||||
|
||||
private Field fluidBand() {
|
||||
return new Field.Coord(Axis.Y, Field.Tiling.CLAMP, lowFluidBand, highFluidBand, lowFluidBand, highFluidBand);
|
||||
}
|
||||
|
||||
private int lavaBand() {
|
||||
return Math.floorDiv(inputs.lavaY() + LAVA_CENTER_MARGIN, FLUID_BAND_HEIGHT);
|
||||
}
|
||||
|
||||
private double spreadAt(int band) {
|
||||
return (inputs.lavaY() - FLUID_BAND_CENTER + LEVEL_ROUNDING_MARGIN) / SPREAD_LEVEL_SCALE - band * (FLUID_BAND_HEIGHT / SPREAD_LEVEL_SCALE);
|
||||
}
|
||||
|
||||
private static boolean any(CaveSelection selection, Predicate<IrisCaveProfile> property) {
|
||||
for (CaveSource source : selection.sources()) {
|
||||
if (property.test(source.profile())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.StyleCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class CaveFieldCompiler {
|
||||
static final int CELL_XZ = 4;
|
||||
static final int CELL_Y = 4;
|
||||
static final double WALL_BAND = 0.03125;
|
||||
private static final double MIN_GAIN = 1.0 / 64.0;
|
||||
private static final double MAX_GAIN = 64.0;
|
||||
private static final Field UNCOVERED = new Field.Const(CaveProfileCompiler.SOLID);
|
||||
|
||||
private final CaveProfileCompiler profiles;
|
||||
private final CaveInputs inputs;
|
||||
|
||||
public CaveFieldCompiler(StyleCompiler styles, CaveInputs inputs) {
|
||||
this.profiles = new CaveProfileCompiler(styles, inputs);
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
public Optional<Field> compile(CaveSelection selection) {
|
||||
return union(selection).map(union -> new Field.Grid(union, CELL_XZ, CELL_Y));
|
||||
}
|
||||
|
||||
private Optional<Field> union(CaveSelection selection) {
|
||||
List<Field> parts = new ArrayList<>(selection.bands().size() + 1);
|
||||
if (!selection.profiles().isEmpty()) {
|
||||
parts.add(selection.select(this::normalized, UNCOVERED));
|
||||
}
|
||||
for (CaveSource band : selection.bands()) {
|
||||
parts.add(normalized(band));
|
||||
}
|
||||
if (parts.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Field union = parts.getFirst();
|
||||
for (int index = 1; index < parts.size(); index++) {
|
||||
union = new Field.Binary(Field.BinaryOp.MIN, union, parts.get(index));
|
||||
}
|
||||
return Optional.of(union);
|
||||
}
|
||||
|
||||
private Field normalized(CaveSource source) {
|
||||
return profiles.compile(source, gain(source));
|
||||
}
|
||||
|
||||
private double gain(CaveSource source) {
|
||||
Optional<CaveInterior> interior = profiles.interior(source);
|
||||
if (interior.isEmpty()) {
|
||||
return 1.0;
|
||||
}
|
||||
double band = WallShellCalibrator.band(interior.get(), inputs.noises().byReference(), inputs.capabilities().target());
|
||||
return band > 0.0 ? Math.clamp(WALL_BAND / band, MIN_GAIN, MAX_GAIN) : 1.0;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 625 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user