From 64d1daf5880a8a7b050f284b768c60b19cd3adce Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 14 Nov 2026 20:37:34 +0100 Subject: [PATCH] Add caves resource kind with listing keys Caves load from caves/ and dimensions, regions and biomes list them under caves --- .../modded/command/ModdedStudioCommands.java | 7 + .../iris/generation/biome/IrisBiome.java | 5 + .../iris/generation/cave/CaveBounds.java | 101 +++++++++++ .../iris/generation/cave/CaveCavern.java | 89 ++++++++++ .../iris/generation/cave/CaveDepth.java | 42 +++++ .../arcane/iris/generation/cave/CaveJson.java | 150 +++++++++++++++++ .../iris/generation/cave/CavePillars.java | 81 +++++++++ .../iris/generation/cave/CaveTunnel.java | 90 ++++++++++ .../generation/cave/CaveTunnelCoverage.java | 83 +++++++++ .../generation/cave/CaveTunnelSpacing.java | 48 ++++++ .../iris/generation/cave/CaveValue.java | 109 ++++++++++++ .../arcane/iris/generation/cave/IrisCave.java | 157 ++++++++++++++++++ .../generation/terrain/IrisDimension.java | 5 + .../iris/generation/terrain/IrisRegion.java | 5 + .../arcane/iris/pack/PackResourceCleanup.java | 1 + .../arcane/iris/pack/loading/IrisData.java | 3 + .../pack/schema/SchemaPropertyBuilder.java | 27 ++- .../schema/annotation/AcceptsPlainNumber.java | 34 ++++ .../studio/workspace/IrisPackageCompiler.java | 12 ++ .../generation/cave/IrisCaveLoadingTest.java | 97 +++++++++++ .../iris/generation/cave/TestSettings.java | 22 +++ .../iris/pack/schema/IrisCaveSchemaTest.java | 89 ++++++++++ .../schema/SchemaBuilderIdentityTest.java | 11 +- .../purity/PackTypeBukkitPurityGateTest.java | 1 + 24 files changed, 1266 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveBounds.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveCavern.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveDepth.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveJson.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CavePillars.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveTunnel.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelCoverage.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelSpacing.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/CaveValue.java create mode 100644 core/src/main/java/art/arcane/iris/generation/cave/IrisCave.java create mode 100644 core/src/main/java/art/arcane/iris/pack/schema/annotation/AcceptsPlainNumber.java create mode 100644 core/src/test/java/art/arcane/iris/generation/cave/IrisCaveLoadingTest.java create mode 100644 core/src/test/java/art/arcane/iris/generation/cave/TestSettings.java create mode 100644 core/src/test/java/art/arcane/iris/pack/schema/IrisCaveSchemaTest.java diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java index ea415b719..74312e267 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java @@ -964,6 +964,7 @@ public final class ModdedStudioCommands { LinkedHashSet entityKeys = new LinkedHashSet<>(); LinkedHashSet spawnerKeys = new LinkedHashSet<>(); LinkedHashSet generatorKeys = new LinkedHashSet<>(); + LinkedHashSet caveKeys = new LinkedHashSet<>(); LinkedHashSet lootKeys = new LinkedHashSet<>(); LinkedHashSet objectKeys = new LinkedHashSet<>(); LinkedHashSet markerKeys = new LinkedHashSet<>(); @@ -987,6 +988,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 +1000,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 +1013,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 +1070,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))); diff --git a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiome.java b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiome.java index e60073b90..782f298f3 100644 --- a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiome.java +++ b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiome.java @@ -18,6 +18,7 @@ package art.arcane.iris.generation.biome; +import art.arcane.iris.generation.cave.IrisCave; import art.arcane.iris.generation.cave.IrisCaveProfile; import art.arcane.iris.generation.decoration.IrisDecorationPart; import art.arcane.iris.generation.decoration.IrisDecorator; @@ -162,6 +163,10 @@ public class IrisBiome extends IrisRegistrant implements Rarity { 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 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) diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveBounds.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveBounds.java new file mode 100644 index 000000000..5be1f5ab1 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveBounds.java @@ -0,0 +1,101 @@ +/* + * 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 . + */ + +package art.arcane.iris.generation.cave; + +import art.arcane.iris.pack.schema.annotation.MaxNumber; +import art.arcane.iris.pack.schema.annotation.MinNumber; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +/** + * The numbers a cave writes outside what their keys allow, read from the {@link MinNumber} and {@link MaxNumber} of + * each key. A {@link CaveValue} is not a plain number, so the schema cannot bound its ends: this does. + */ +public final class CaveBounds { + private static final String CAVE_PACKAGE = IrisCave.class.getPackageName(); + + private CaveBounds() { + } + + /** Each value of the cave outside the numbers its key allows, such as {@code fade is 200; it must be at most 128}. */ + public static List valuesOutOfBounds(IrisCave cave) { + List problems = new ArrayList<>(); + collect(cave, "", problems); + return problems; + } + + private static void collect(Object holder, String path, List problems) { + for (Field field : holder.getClass().getDeclaredFields()) { + if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) { + continue; + } + Object value = valueOf(field, holder); + if (value == null) { + continue; + } + String fieldPath = path.isEmpty() ? field.getName() : path + "." + field.getName(); + if (value instanceof CaveValue caveValue) { + requireWithin(field, caveValue, fieldPath, problems); + } else if (value instanceof Number number) { + requireWithin(field, number.doubleValue(), fieldPath, problems); + } else if (isCaveSetting(value)) { + collect(value, fieldPath, problems); + } + } + } + + private static boolean isCaveSetting(Object value) { + return value.getClass().getPackageName().equals(CAVE_PACKAGE) && !(value instanceof IrisCave); + } + + private static Object valueOf(Field field, Object holder) { + try { + field.setAccessible(true); + return field.get(holder); + } catch (ReflectiveOperationException | RuntimeException failure) { + throw new IllegalStateException("Cannot read " + holder.getClass().getSimpleName() + "." + field.getName(), failure); + } + } + + private static void requireWithin(Field field, CaveValue value, String path, List problems) { + if (!value.varies()) { + requireWithin(field, value.min(), path, problems); + return; + } + requireWithin(field, value.min(), path + ".min", problems); + requireWithin(field, value.max(), path + ".max", problems); + } + + private static void requireWithin(Field field, double value, String path, List 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); + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveCavern.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveCavern.java new file mode 100644 index 000000000..81d90410b --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveCavern.java @@ -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 . + */ + +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. Default 56. 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. Default 22. 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. Default 0.1. 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. Default 0.3. 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 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 pillars() { + return Optional.ofNullable(pillars); + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveDepth.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveDepth.java new file mode 100644 index 000000000..0d8f68ea3 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveDepth.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +package art.arcane.iris.generation.cave; + +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. Default 16.") + private CaveValue min = CaveValue.of(16); + + @Description("Highest world Y. A range changes over about " + IrisCave.VALUE_CHANGE_BLOCKS + " blocks. Default 32.") + private CaveValue max = CaveValue.of(32); + + public CaveDepth() { + } + + public CaveValue min() { + return min; + } + + public CaveValue max() { + return max; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveJson.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveJson.java new file mode 100644 index 000000000..0ad4a1c26 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveJson.java @@ -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 . + */ + +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 VALUE_MEMBERS = Set.of(MIN, MAX, STYLE); + private static final Set 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, JsonSerializer { + @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, JsonSerializer { + @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 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; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CavePillars.java b/core/src/main/java/art/arcane/iris/generation/cave/CavePillars.java new file mode 100644 index 000000000..20c48fa0a --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CavePillars.java @@ -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 . + */ + +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. Default 22. 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. Default 4. 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. Default 4. 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 vertical() { + return Optional.ofNullable(vertical); + } + + /** The noise that places the pillars; empty where the pack wrote none. */ + public Optional style() { + return Optional.ofNullable(style); + } + + public CaveValue spacing() { + return spacing; + } + + public CaveValue thickness() { + return thickness; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnel.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnel.java new file mode 100644 index 000000000..bd5d01452 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnel.java @@ -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 . + */ + +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. Default {min 4, max 7}. 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. Default 0.5. 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 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 warp() { + return Optional.ofNullable(warp); + } + + public CaveValue verticalWarp() { + return verticalWarp; + } + + public CaveTunnelCoverage coverage() { + return coverage == null ? CaveTunnelCoverage.EVERYWHERE : coverage; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelCoverage.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelCoverage.java new file mode 100644 index 000000000..1cedf81a1 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelCoverage.java @@ -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 . + */ + +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. Default 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. Default " + DEFAULT_SOFTNESS + ".") + 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 style() { + return Optional.ofNullable(style); + } + + boolean isWrittenAsShareOnly() { + return style == null && softness.min() == DEFAULT_SOFTNESS && !softness.varies(); + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelSpacing.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelSpacing.java new file mode 100644 index 000000000..e6100b307 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveTunnelSpacing.java @@ -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 . + */ + +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; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/CaveValue.java b/core/src/main/java/art/arcane/iris/generation/cave/CaveValue.java new file mode 100644 index 000000000..af84d162a --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/CaveValue.java @@ -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 . + */ + +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 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) + "}"; + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/cave/IrisCave.java b/core/src/main/java/art/arcane/iris/generation/cave/IrisCave.java new file mode 100644 index 000000000..400bab8c2 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/cave/IrisCave.java @@ -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 . + */ + +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. Default 12. 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. Default 8. 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. Default 8. 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 tunnel() { + return Optional.ofNullable(tunnel); + } + + public Optional cavern() { + return Optional.ofNullable(cavern); + } + + public Optional 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); + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/terrain/IrisDimension.java b/core/src/main/java/art/arcane/iris/generation/terrain/IrisDimension.java index 27c89264a..60fc8b20d 100644 --- a/core/src/main/java/art/arcane/iris/generation/terrain/IrisDimension.java +++ b/core/src/main/java/art/arcane/iris/generation/terrain/IrisDimension.java @@ -24,6 +24,7 @@ import art.arcane.iris.generation.biome.IrisBiomeCustom; 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.IrisCave; import art.arcane.iris.generation.cave.IrisCaveProfile; import art.arcane.iris.generation.decoration.IrisDepositGenerator; import art.arcane.iris.generation.decoration.IrisDepositVariant; @@ -231,6 +232,10 @@ public class IrisDimension extends IrisRegistrant { private KList 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 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.") diff --git a/core/src/main/java/art/arcane/iris/generation/terrain/IrisRegion.java b/core/src/main/java/art/arcane/iris/generation/terrain/IrisRegion.java index 8d4e565c9..e12f0d636 100644 --- a/core/src/main/java/art/arcane/iris/generation/terrain/IrisRegion.java +++ b/core/src/main/java/art/arcane/iris/generation/terrain/IrisRegion.java @@ -19,6 +19,7 @@ package art.arcane.iris.generation.terrain; import art.arcane.iris.generation.biome.IrisBiome; +import art.arcane.iris.generation.cave.IrisCave; import art.arcane.iris.generation.cave.IrisCaveProfile; import art.arcane.iris.generation.decoration.IrisDepositGenerator; import art.arcane.iris.generation.decoration.IrisDepositVariant; @@ -145,6 +146,10 @@ public class IrisRegion extends IrisRegistrant implements Rarity { 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 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) diff --git a/core/src/main/java/art/arcane/iris/pack/PackResourceCleanup.java b/core/src/main/java/art/arcane/iris/pack/PackResourceCleanup.java index 5081df4fc..706d79ca7 100644 --- a/core/src/main/java/art/arcane/iris/pack/PackResourceCleanup.java +++ b/core/src/main/java/art/arcane/iris/pack/PackResourceCleanup.java @@ -31,6 +31,7 @@ public final class PackResourceCleanup { "loot", "generators", "expressions", + "caves", "markers", "blocks", "mods" diff --git a/core/src/main/java/art/arcane/iris/pack/loading/IrisData.java b/core/src/main/java/art/arcane/iris/pack/loading/IrisData.java index d7e26f680..2bca6f404 100644 --- a/core/src/main/java/art/arcane/iris/pack/loading/IrisData.java +++ b/core/src/main/java/art/arcane/iris/pack/loading/IrisData.java @@ -49,6 +49,7 @@ import art.arcane.iris.structure.authoring.StructureRecoveryResult; import art.arcane.iris.structure.authoring.StructureTransactionWriter; import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.biome.IrisBiomeCustom; +import art.arcane.iris.generation.cave.IrisCave; import art.arcane.iris.spi.PlatformGenerationRegistry; import art.arcane.iris.generation.block.IrisBlockData; import art.arcane.iris.generation.terrain.IrisDimension; @@ -135,6 +136,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { private ResourceLoader modLoader; private ResourceLoader blockLoader; private ResourceLoader expressionLoader; + private ResourceLoader caveLoader; private ResourceLoader objectLoader; private ResourceLoader matterLoader; private ResourceLoader imageLoader; @@ -726,6 +728,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { this.markerLoader = registerLoader(IrisMarker.class, replacement); this.blockLoader = registerLoader(IrisBlockData.class, replacement); this.expressionLoader = registerLoader(IrisExpression.class, replacement); + this.caveLoader = registerLoader(IrisCave.class, replacement); this.objectLoader = registerLoader(IrisObject.class, replacement); this.imageLoader = registerLoader(IrisImage.class, replacement); this.imageMapLoader = registerLoader(IrisImageMap.class, replacement); diff --git a/core/src/main/java/art/arcane/iris/pack/schema/SchemaPropertyBuilder.java b/core/src/main/java/art/arcane/iris/pack/schema/SchemaPropertyBuilder.java index 0f997ac9d..1ca6ea4c0 100644 --- a/core/src/main/java/art/arcane/iris/pack/schema/SchemaPropertyBuilder.java +++ b/core/src/main/java/art/arcane/iris/pack/schema/SchemaPropertyBuilder.java @@ -19,6 +19,7 @@ package art.arcane.iris.pack.schema; import art.arcane.iris.spi.IrisLogging; +import art.arcane.iris.pack.schema.annotation.AcceptsPlainNumber; import art.arcane.iris.pack.schema.annotation.ArrayType; import art.arcane.iris.pack.schema.annotation.MaxNumber; import art.arcane.iris.pack.schema.annotation.MinNumber; @@ -65,7 +66,29 @@ final class SchemaPropertyBuilder { default -> unexpectedType(type, k, cl); }; - return describeProperty(k, cl, prop, type, fancyType, description); + JSONObject described = describeProperty(k, cl, prop, type, fancyType, description); + if (k.getType().isAnnotationPresent(AcceptsPlainNumber.class)) { + acceptPlainNumber(k, described); + } + return described; + } + + private void acceptPlainNumber(Field k, JSONObject prop) { + JSONObject number = new JSONObject(); + number.put("type", "number"); + if (k.isAnnotationPresent(MinNumber.class)) { + number.put("minimum", k.getDeclaredAnnotation(MinNumber.class).value()); + } + if (k.isAnnotationPresent(MaxNumber.class)) { + number.put("maximum", k.getDeclaredAnnotation(MaxNumber.class).value()); + } + JSONObject object = new JSONObject(); + object.put("$ref", prop.remove("$ref")); + prop.remove("type"); + JSONArray alternatives = new JSONArray(); + alternatives.put(number); + alternatives.put(object); + prop.put("oneOf", alternatives); } private String integerProperty(Field k, JSONObject prop, KList description) { @@ -264,6 +287,8 @@ final class SchemaPropertyBuilder { } if (value instanceof List) { d.add(SchemaBuilder.SYMBOL_LIMIT__N + " Default Value is an empty list"); + } else if (k.getType().isAnnotationPresent(AcceptsPlainNumber.class)) { + d.add(SchemaBuilder.SYMBOL_LIMIT__N + " Default Value is " + value); } else if (!k.getType().isPrimitive() && !(value instanceof Number) && !(value instanceof String) && !(value instanceof Enum) && !SchemaKeyedTypes.isKeyed(k.getType())) { d.add(SchemaBuilder.SYMBOL_LIMIT__N + " Default Value is a default object (create this object to see default properties)"); } else { diff --git a/core/src/main/java/art/arcane/iris/pack/schema/annotation/AcceptsPlainNumber.java b/core/src/main/java/art/arcane/iris/pack/schema/annotation/AcceptsPlainNumber.java new file mode 100644 index 000000000..abd57df7c --- /dev/null +++ b/core/src/main/java/art/arcane/iris/pack/schema/annotation/AcceptsPlainNumber.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ + +package art.arcane.iris.pack.schema.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Marks an object type that a pack may also write as a single number. The schema of a field of this type accepts + * either the number, within the field's {@link MinNumber} and {@link MaxNumber}, or the object. + */ +@Retention(RUNTIME) +@Target({TYPE}) +public @interface AcceptsPlainNumber { +} diff --git a/core/src/main/java/art/arcane/iris/studio/workspace/IrisPackageCompiler.java b/core/src/main/java/art/arcane/iris/studio/workspace/IrisPackageCompiler.java index 8d2b6f377..9c3ec15bb 100644 --- a/core/src/main/java/art/arcane/iris/studio/workspace/IrisPackageCompiler.java +++ b/core/src/main/java/art/arcane/iris/studio/workspace/IrisPackageCompiler.java @@ -30,6 +30,7 @@ import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.block.IrisBlockData; import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.world.entity.IrisEntity; +import art.arcane.iris.generation.cave.IrisCave; import art.arcane.iris.generation.noise.IrisExpression; import art.arcane.iris.generation.noise.IrisGenerator; import art.arcane.iris.world.loot.IrisLootTable; @@ -144,6 +145,10 @@ public class IrisPackageCompiler { biomes.forEach((i) -> i.getGenerators().forEach((j) -> addIfPresent(generators, j.getCachedGenerator(() -> dm)))); biomes.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, dm.getLootLoader().load(i)))); biomes.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, dm.getSpawnerLoader().load(sp)))); + KSet caves = new KSet<>(); + dimensions.forEach((exportedDimension) -> exportedDimension.getCaves().forEach((key) -> addIfPresent(caves, dm.getCaveLoader().load(key)))); + regions.forEach((r) -> r.getCaves().forEach((key) -> addIfPresent(caves, dm.getCaveLoader().load(key)))); + biomes.forEach((r) -> r.getCaves().forEach((key) -> addIfPresent(caves, dm.getCaveLoader().load(key)))); KList allPlacements = new KList<>(); regions.forEach((r) -> allPlacements.addAll(r.getObjects())); biomes.forEach((i) -> allPlacements.addAll(i.getObjects())); @@ -270,6 +275,13 @@ public class IrisPackageCompiler { b.append(IO.hash(a)); } + for (IrisCave i : caves.stream() + .sorted(Comparator.comparing(IrisCave::getLoadKey)).toList()) { + a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4); + IO.writeAll(new File(folder, "caves/" + i.getLoadKey() + ".json"), a); + b.append(IO.hash(a)); + } + c.append(IO.hash(b.toString())); b = new StringBuilder(); diff --git a/core/src/test/java/art/arcane/iris/generation/cave/IrisCaveLoadingTest.java b/core/src/test/java/art/arcane/iris/generation/cave/IrisCaveLoadingTest.java new file mode 100644 index 000000000..69da01b9d --- /dev/null +++ b/core/src/test/java/art/arcane/iris/generation/cave/IrisCaveLoadingTest.java @@ -0,0 +1,97 @@ +package art.arcane.iris.generation.cave; + +import art.arcane.iris.configuration.IrisSettings; +import art.arcane.iris.generation.runtime.PreservationRegistry; +import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.spi.IrisServices; +import art.arcane.iris.testsupport.PlatformLeakGuard; +import com.google.gson.Gson; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +public class IrisCaveLoadingTest { + @ClassRule + public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean(); + + @Rule + public final TemporaryFolder temporary = new TemporaryFolder(); + + private IrisData data; + private IrisSettings previousSettings; + + @Before + public void registerServices() { + previousSettings = IrisSettings.settings; + IrisSettings.settings = new IrisSettings(); + IrisServices.register(PreservationRegistry.class, mock(PreservationRegistry.class)); + } + + @After + public void closeData() { + if (data != null) { + data.close(); + } + IrisServices.remove(PreservationRegistry.class); + IrisSettings.settings = previousSettings; + } + + @Test + public void aPackLoadsItsCavesFromTheCavesFolderWithEveryFormOfValue() throws Exception { + Path root = temporary.newFolder("pack").toPath(); + Files.createDirectories(root.resolve("caves")); + Files.writeString(root.resolve("caves/halls.json"), """ + {"cavern": {"size": 110, "coverage": {"min": 0.1, "max": 0.3, "style": {"style": "SIMPLEX", "zoom": 2}}, + "pillars": {"spacing": 26}}, + "tunnel": {"coverage": 0.4}, + "depth": {"min": -64, "max": 10}, "fade": 14, "biome": "grotto", "allowLava": false} + """); + data = IrisData.get(root.toFile()); + + IrisCave halls = data.getCaveLoader().load("halls"); + + assertEquals(List.of("halls"), List.of(data.getCaveLoader().getPossibleKeys())); + assertEquals("caves", halls.getFolderName()); + assertEquals(110D, halls.cavern().orElseThrow().size().min(), 0D); + assertTrue(halls.cavern().orElseThrow().coverage().varies()); + assertEquals(2D, halls.cavern().orElseThrow().coverage().style().orElseThrow().getZoom(), 0D); + assertEquals(26D, halls.cavern().orElseThrow().pillars().orElseThrow().spacing().min(), 0D); + assertEquals(0.4D, halls.tunnel().orElseThrow().coverage().share().min(), 0D); + assertEquals(-64D, halls.depth().orElseThrow().min().min(), 0D); + assertEquals(14D, halls.fade().min(), 0D); + assertEquals("grotto", halls.biome()); + assertFalse(halls.allowLava()); + assertTrue(halls.allowFluid()); + assertEquals(12, halls.fluidMinDepthBelowSurface()); + } + + @Test + public void aCaveReadsBackAsItWasWritten() { + Gson gson = TestSettings.gson(); + IrisCave written = TestSettings.of(IrisCave.class, """ + {"tunnel": {"width": {"min": 3, "max": 6}, "coverage": {"share": 0.5, "softness": 0.2}}, "fade": 9} + """); + + IrisCave read = gson.fromJson(gson.toJson(written), IrisCave.class); + + assertEquals(written.tunnel().orElseThrow().width().min(), read.tunnel().orElseThrow().width().min(), 0D); + assertEquals(written.tunnel().orElseThrow().width().max(), read.tunnel().orElseThrow().width().max(), 0D); + assertEquals(0.5D, read.tunnel().orElseThrow().coverage().share().min(), 0D); + assertEquals(0.2D, read.tunnel().orElseThrow().coverage().softness().min(), 0D); + assertEquals(9D, read.fade().min(), 0D); + assertNull(read.cavern().orElse(null)); + } +} diff --git a/core/src/test/java/art/arcane/iris/generation/cave/TestSettings.java b/core/src/test/java/art/arcane/iris/generation/cave/TestSettings.java new file mode 100644 index 000000000..89c37c9bd --- /dev/null +++ b/core/src/test/java/art/arcane/iris/generation/cave/TestSettings.java @@ -0,0 +1,22 @@ +package art.arcane.iris.generation.cave; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** Reads cave settings from the JSON a pack writes, the way a pack's loader does. */ +public final class TestSettings { + private static final Gson GSON = gson(); + + private TestSettings() { + } + + public static T of(Class type, String json) { + return GSON.fromJson(json, type); + } + + public static Gson gson() { + GsonBuilder builder = new GsonBuilder().setLenient(); + CaveJson.register(builder); + return builder.create(); + } +} diff --git a/core/src/test/java/art/arcane/iris/pack/schema/IrisCaveSchemaTest.java b/core/src/test/java/art/arcane/iris/pack/schema/IrisCaveSchemaTest.java new file mode 100644 index 000000000..459694165 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/pack/schema/IrisCaveSchemaTest.java @@ -0,0 +1,89 @@ +package art.arcane.iris.pack.schema; + +import art.arcane.iris.generation.biome.IrisBiome; +import art.arcane.iris.generation.cave.IrisCave; +import art.arcane.iris.generation.terrain.IrisDimension; +import art.arcane.iris.generation.terrain.IrisRegion; +import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.pack.loading.IrisRegistrant; +import art.arcane.iris.pack.loading.ResourceLoader; +import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.collection.KMap; +import art.arcane.volmlib.util.json.JSONArray; +import art.arcane.volmlib.util.json.JSONObject; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class IrisCaveSchemaTest { + private static final String CAVE_VALUE_DEFINITION = "obj-art-arcane-iris-generation-cave-cavevalue"; + + @Test + public void aCaveValueIsANumberWithinItsBoundsOrAnObject() { + JSONObject schema = new SchemaBuilder(IrisCave.class, schemaData()).construct(); + + JSONObject fade = schema.getJSONObject("properties").getJSONObject("fade"); + JSONArray alternatives = fade.getJSONArray("oneOf"); + + assertFalse(fade.has("type")); + assertEquals(2, alternatives.length()); + assertEquals("number", alternatives.getJSONObject(0).getString("type")); + assertEquals(0D, alternatives.getJSONObject(0).getDouble("minimum"), 0D); + assertEquals(128D, alternatives.getJSONObject(0).getDouble("maximum"), 0D); + assertEquals("#/definitions/" + CAVE_VALUE_DEFINITION, alternatives.getJSONObject(1).getString("$ref")); + } + + @Test + public void theObjectFormOfACaveValueOffersMinMaxAndStyle() { + JSONObject definition = new SchemaBuilder(IrisCave.class, schemaData()).construct() + .getJSONObject("definitions").getJSONObject(CAVE_VALUE_DEFINITION); + + JSONObject properties = definition.getJSONObject("properties"); + + assertTrue(properties.has("min")); + assertTrue(properties.has("max")); + assertTrue(properties.has("style")); + assertEquals("min", definition.getJSONArray("required").getString(0)); + } + + @Test + public void aTunnelCoverageIsAShareOrAnObject() { + JSONObject schema = new SchemaBuilder(IrisCave.class, schemaData()).construct(); + + JSONObject tunnel = schema.getJSONObject("definitions").getJSONObject("obj-art-arcane-iris-generation-cave-cavetunnel"); + JSONObject coverage = tunnel.getJSONObject("properties").getJSONObject("coverage"); + + assertEquals(2, coverage.getJSONArray("oneOf").length()); + assertEquals("number", coverage.getJSONArray("oneOf").getJSONObject(0).getString("type")); + } + + @Test + public void dimensionsRegionsAndBiomesOfferTheCavesOfThePackToList() throws Exception { + for (Class listing : new Class[]{IrisDimension.class, IrisRegion.class, IrisBiome.class}) { + SchemaBuilder builder = new SchemaBuilder(listing, schemaData()); + + JSONObject caves = new SchemaPropertyBuilder(builder).buildProperty(listing.getDeclaredField("caves"), listing); + + assertEquals(listing.getSimpleName(), "#/definitions/erzcaves", caves.getJSONObject("items").getString("$ref")); + assertEquals(listing.getSimpleName(), "tunnels", builder.definitions.get("erzcaves").getJSONArray("enum").getString(0)); + } + } + + private static IrisData schemaData() { + IrisData data = mock(IrisData.class); + ResourceLoader caveLoader = mock(ResourceLoader.class); + KMap, ResourceLoader> loaders = new KMap<>(); + loaders.put(IrisCave.class, caveLoader); + when(data.getLoaders()).thenReturn(loaders); + when(data.getPossibleSnippets(anyString())).thenReturn(new KList()); + when(caveLoader.getPossibleKeys()).thenReturn(new String[]{"tunnels", "caverns"}); + when(caveLoader.getFolderName()).thenReturn("caves"); + when(caveLoader.getResourceTypeName()).thenReturn("Cave"); + return data; + } +} diff --git a/core/src/test/java/art/arcane/iris/pack/schema/SchemaBuilderIdentityTest.java b/core/src/test/java/art/arcane/iris/pack/schema/SchemaBuilderIdentityTest.java index 2ac84d437..51b0cce16 100644 --- a/core/src/test/java/art/arcane/iris/pack/schema/SchemaBuilderIdentityTest.java +++ b/core/src/test/java/art/arcane/iris/pack/schema/SchemaBuilderIdentityTest.java @@ -22,6 +22,7 @@ import art.arcane.iris.pack.loading.IrisData; import art.arcane.iris.pack.loading.IrisRegistrant; import art.arcane.iris.pack.loading.ResourceLoader; import art.arcane.iris.generation.biome.IrisBiome; +import art.arcane.iris.generation.cave.IrisCave; import art.arcane.iris.generation.block.IrisBlockData; import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.generation.subterrain.IrisSubterrainFeature; @@ -84,7 +85,7 @@ public class SchemaBuilderIdentityTest { @ClassRule public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean(); - private static final String EXPECTED_SCHEMA_DIGEST = "89641e077a85bec8a27681f2ce6166150cc37277bc6f58793081b669432782f2"; + private static final String EXPECTED_SCHEMA_DIGEST = "3f8aa1e56a2bd9e68c6b4d0036da22a9d5f3b64542ab6c90044d98ba3e5705c5"; private static final List> SCHEMA_ROOTS = List.of( IrisDimension.class, @@ -101,7 +102,8 @@ public class SchemaBuilderIdentityTest { IrisLootTable.class, IrisBlockData.class, IrisImageMap.class, - IrisExpression.class); + IrisExpression.class, + IrisCave.class); private IrisPlatform previous; @@ -249,8 +251,13 @@ public class SchemaBuilderIdentityTest { ResourceLoader pieceLoader = mock(ResourceLoader.class); ResourceLoader expressionLoader = mock(ResourceLoader.class); ResourceLoader blockLoader = mock(ResourceLoader.class); + ResourceLoader caveLoader = mock(ResourceLoader.class); KMap, ResourceLoader> loaders = new KMap<>(); loaders.put(IrisExpression.class, expressionLoader); + loaders.put(IrisCave.class, caveLoader); + when(caveLoader.getPossibleKeys()).thenReturn(new String[]{"pack/tunnels", "pack/caverns"}); + when(caveLoader.getFolderName()).thenReturn("caves"); + when(caveLoader.getResourceTypeName()).thenReturn("Cave"); when(data.getStructureLoader()).thenReturn(structureLoader); when(data.getJigsawPieceLoader()).thenReturn(pieceLoader); when(data.getBlockLoader()).thenReturn(blockLoader); diff --git a/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java b/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java index 8812b54de..412bc417c 100644 --- a/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java +++ b/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java @@ -95,6 +95,7 @@ public class PackTypeBukkitPurityGateTest { "art.arcane.iris.world.entity.IrisMarker", "art.arcane.iris.generation.block.IrisBlockData", "art.arcane.iris.generation.noise.IrisExpression", + "art.arcane.iris.generation.cave.IrisCave", "art.arcane.iris.structure.object.IrisObject", "art.arcane.iris.generation.image.IrisImage", "art.arcane.iris.generation.image.IrisImageMap",