diff --git a/docs/INSTABILITY_SCORE.md b/docs/INSTABILITY_SCORE.md index 93b58ee..de5d188 100644 --- a/docs/INSTABILITY_SCORE.md +++ b/docs/INSTABILITY_SCORE.md @@ -2,7 +2,7 @@ Every newly created Age now gets a version-1 `Instability` compound inside its server-owned `rivencraft_ages` saved definition. It contains the total `Score` and an ordered `Breakdown` of reason, original page index (zero-based, or -1 for an Age-wide cause), points, and explanation. `AgeRegistrySavedData.instability(UUID)` is the read-only server query. No client tooltip or live data-pack lookup is needed to read a saved score. -The baseline is explicitly zero for page-free and Link-Panel-only random Ages, and for authored Ages. Incomplete writing receives seed-based completion and a zero-point explanatory entry. Supported writing defects use the provisional Milestone 6 grammar costs: duplicate/conflicting single-choice pages +500, out-of-order or misplaced pages +100. Legacy's audited Bright Lighting symbol adds +500 for every occurrence, including a seed-generated controller. Mineshafts, Nether Fortresses, Strongholds, and Villages add +100 for the fourth and every later occurrence. By project balance decision, Bastions, Trial Chambers, Ancient Cities, Shipwrecks, Ocean Ruins, Pillager Outposts, Ruined Portals, Nether Fossils, Buried Treasure, and Trail Ruins follow that same rule. The first three occurrences and all other audited Legacy feature symbols have no direct page cost. An authored structure may override its vanilla biome eligibility; every structure-page occurrence forced into an unsupported selected biome adds +100. Seed completion still prefers compatible biomes and therefore avoids that cost when it can. Other modern-only features remain neutral. The frozen score selects a deterministic, persisted provider plan through the Milestone 6 runtime. Registered handlers apply that plan only inside loaded Rivencraft Ages and remain subject to the documented scheduler and effect-specific safety bounds. +The baseline is explicitly zero for page-free and Link-Panel-only random Ages, and for authored Ages. Incomplete writing receives seed-based completion and a zero-point explanatory entry. Supported writing defects use the provisional Milestone 6 grammar costs: duplicate/conflicting single-choice pages +500, out-of-order or misplaced pages +100. Legacy's audited Bright Lighting symbol adds +500 for every occurrence, including a seed-generated controller. Mineshafts, Nether Fortresses, Strongholds, and Villages add +100 for the fourth and every later occurrence. By project balance decision, Bastions, Trial Chambers, Ancient Cities, Shipwrecks, Ocean Ruins, Pillager Outposts, Ruined Portals, Nether Fossils, Buried Treasure, and Trail Ruins follow that same rule. The first three occurrences and all other audited Legacy feature symbols have no direct page cost. An authored structure may override its vanilla biome eligibility; every structure-page occurrence adds +100 if **any** selected biome is unsupported, even when another selected biome is compatible. Seed completion still prefers compatible biomes and therefore avoids that cost when it can. Other modern-only features remain neutral. The frozen score selects a deterministic, persisted provider plan through the Milestone 6 runtime. Registered handlers apply that plan only inside loaded Rivencraft Ages and remain subject to the documented scheduler and effect-specific safety bounds. The score is calculated after the Age plan and effective traits are chosen, then saved with the Age identity before its dimension is generated. The same UUID returns the existing definition, including the same score, on repeated use. Spawn updates preserve it. Reload only deserializes the frozen breakdown; it never reruns the current grammar or catalog. An older Age definition without `Instability` is migrated to a persisted version-1 neutral score of zero, rather than retroactively scoring its writing. A future scoring-rule change must introduce an explicit new schema/migration policy, not silently reinterpret existing Ages. Issue #66 added the frozen provider selection; issues #67–#70 added the current handlers. See the [runtime policy](INSTABILITY_RUNTIME.md). diff --git a/docs/WRITING_GRAMMAR.md b/docs/WRITING_GRAMMAR.md index 1cceaee..8ceae78 100644 --- a/docs/WRITING_GRAMMAR.md +++ b/docs/WRITING_GRAMMAR.md @@ -8,7 +8,7 @@ The supported order follows the representable subset of the [Legacy grammar audi Missing terrain, controller, weather, lighting, celestial, or the controller's minimum biome count is an **incomplete** warning, not an error: the compiler retains seed-selected traits for missing branches. An omitted terrain page uses a seed-selected profile compatible with authored feature pages, so changing the Age name cannot accidentally select Flat, Void, or Cave terrain for Rocks or Lakes. If no profile can support the writing, binding still rejects it. Native consumes no authored biome pages; Single consumes one; Tiled/Grid and Tiny–Huge require two, with seeded filler when pages are missing. From 0.5.1.0, known misplaced or repeated pages no longer block creation: the book keeps its original order, while the server repairs category order, uses the last single-choice controller, and stores a writing-instability score in the Age plan. A conflicting/repeated choice adds 500; an out-of-order page or misplaced modifier adds 100. Native ignores surplus authored biome pages and Single uses the first, with the conflict recorded as instability. Audited Legacy symbol modifiers also add 500 for each Bright Lighting page and 100 for each Mineshafts, Nether Fortresses, Strongholds, or Villages occurrence after the third. Modern structures configured with the same rule are Bastions, Trial Chambers, Ancient Cities, Shipwrecks, Ocean Ruins, Pillager Outposts, Ruined Portals, Nether Fossils, Buried Treasure, and Trail Ruins. Every repeated structure page increases that structure's placement rate: probability-based structures multiply their chance, grid-based structures use a denser grid, and Strongholds add more positions to each ring and more positions overall. One page retains the vanilla placement rate. Authored structures can generate outside their vanilla biome set; each structure-page occurrence that requires this override adds 100 instability. Seed completion selects compatible biomes where possible. Other feature pages have no direct symbol cost. Incorrectly placed pages are **not** red-highlighted; their warning remains available as a tooltip. Unknown IDs, schema-v1 display-only symbols, unavailable dependencies/profiles, unsupported semantic effects or feature/material pairs, missing/extra Link Panels, and oversized writing still reject a new Age. The Binder disables output for those fatal errors and shows a red page indication where applicable. Rejected inputs remain removable. -The plan stores the original writing order, the authoritative semantic value of each resolved symbol, the active repaired-page indexes, the writing-instability score, the Age seed, and a copy of the selected runtime profile. An explicit terrain page overrides random terrain selection; an omitted terrain uses a seed-selected compatible profile. The built-in Standard, Amplified, Cave, Island, Flat, and Void terrain pages select their matching generation resources. Age loading uses the frozen runtime profile and does not need the original symbol definition or runtime-profile JSON, though its referenced noise, biome-preset, and dimension-type registry entries must remain available. Existing bound books without plans are not reinterpreted. Page-free and Link-Panel-only books keep the pre-existing random path. Biome and environment pages affect new Ages, and the supported feature subset below is compiled into the same frozen plan. Runtime effects for a nonzero writing-instability score are not implemented yet. +The plan stores the original writing order, the authoritative semantic value of each resolved symbol, the active repaired-page indexes, the writing-instability score, the Age seed, and a copy of the selected runtime profile. An explicit terrain page overrides random terrain selection; an omitted terrain uses a seed-selected compatible profile. The built-in Standard, Amplified, Cave, Island, Flat, and Void terrain pages select their matching generation resources. Age loading uses the frozen runtime profile and does not need the original symbol definition or runtime-profile JSON, though its referenced noise, biome-preset, and dimension-type registry entries must remain available. Existing bound books without plans are not reinterpreted. Page-free and Link-Panel-only books keep the pre-existing random path. Biome and environment pages affect new Ages, and the supported feature subset below is compiled into the same frozen plan. Nonzero instability can select a persisted provider plan; status effects, decay, lightning, explosions, meteors, burning, and test-enabled erosion run through the bounded Age-scoped scheduler described in [the runtime policy](INSTABILITY_RUNTIME.md). ## Supported feature pages (issue #35) diff --git a/gradle.properties b/gradle.properties index 7f2f5b8..31ba19c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -36,7 +36,7 @@ mod_name=Rivencraft # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=LGPL-3.0-or-later # The mod version. Rivencraft uses the x.y.z.b policy documented in README.md. -mod_version=0.5.8.4 +mod_version=0.5.8.7 immersive_portals_version=6.0.7 terrablender_version=4.1.0.8 serene_seasons_version_id=B6nTjh4b diff --git a/src/main/java/net/dnorberg/rivencraft/book/AgeInstability.java b/src/main/java/net/dnorberg/rivencraft/book/AgeInstability.java index 7ff8b8f..32c2700 100644 --- a/src/main/java/net/dnorberg/rivencraft/book/AgeInstability.java +++ b/src/main/java/net/dnorberg/rivencraft/book/AgeInstability.java @@ -97,7 +97,7 @@ public record AgeInstability(int version, int score, List breakdow String name = COUNTED_STRUCTURES.get(resource.id()); if (name == null) continue; int count = structureCounts.merge(resource.id(), 1, Integer::sum); - if (!AgeStructureSelection.biomeCompatible(resource.id(), plan.biomeSelection(), registries)) { + if (AgeStructureSelection.requiresBiomeOverride(resource.id(), plan.biomeSelection(), registries)) { contributions.add(new Contribution("forced_biome_" + resource.id().getPath(), symbol.index(), FORCED_STRUCTURE_BIOME_COST, name + " occurrence " + count + " is forced into an unsupported biome")); diff --git a/src/main/java/net/dnorberg/rivencraft/book/AgeStructureGameTests.java b/src/main/java/net/dnorberg/rivencraft/book/AgeStructureGameTests.java index 4dede11..3615521 100644 --- a/src/main/java/net/dnorberg/rivencraft/book/AgeStructureGameTests.java +++ b/src/main/java/net/dnorberg/rivencraft/book/AgeStructureGameTests.java @@ -9,6 +9,9 @@ import net.dnorberg.rivencraft.writing.OrderedWriting; import net.dnorberg.rivencraft.writing.SymbolReference; import net.dnorberg.rivencraft.writing.WritingEntry; import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.FixedBiomeSource; +import net.minecraft.world.level.chunk.ChunkGeneratorStructureState; import net.minecraft.gametest.framework.GameTest; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.resources.ResourceKey; @@ -165,6 +168,88 @@ public final class AgeStructureGameTests { helper.succeed(); } + @GameTest(template = "empty") + public static void mixedEndAndTaigaVillagesChargeForEndPortion(GameTestHelper helper) { + for (String firstBiome : List.of("the_end", "plains")) { + var writing = new OrderedWriting(List.of(WritingEntry.linkPanel(), + page("terrain/standard"), page("biome/" + firstBiome), page("biome/taiga"), + page("biome/tiled"), page("lighting/normal"), + page("feature/villages"), page("feature/villages"))); + var age = AgeRegistrySavedData.resolveOrCreate(helper.getLevel(), + new AgeReference(java.util.UUID.randomUUID(), "Mixed " + firstBiome), writing); + int expected = firstBiome.equals("the_end") ? 200 : 0; + helper.assertValueEqual(age.instability().score(), expected, + "Each Village page must charge 100 if any selected biome needs the override"); + helper.assertValueEqual(age.instability().breakdown().stream() + .filter(part -> part.reason().equals("forced_biome_villages")).count(), + firstBiome.equals("the_end") ? 2L : 0L, + "Compatible Taiga must not erase the End portion's forced-biome charges"); + } + helper.succeed(); + } + + @GameTest(template = "empty") + public static void forcedVillageSurvivesStructureStateBiomeGate(GameTestHelper helper) { + var registries = helper.getLevel().registryAccess(); + var sets = registries.lookupOrThrow(Registries.STRUCTURE_SET); + var end = new FixedBiomeSource(registries.lookupOrThrow(Registries.BIOME).getOrThrow(Biomes.THE_END)); + var villages = repeated("villages", 1); + var random = helper.getLevel().getChunkSource().randomState(); + var baseline = ChunkGeneratorStructureState.createForNormal(random, 42L, end, + AgeStructureSelection.filteredLookup(sets, villages, end)); + helper.assertTrue(baseline.possibleStructureSets().stream() + .noneMatch(holder -> holder.unwrapKey().filter(BuiltinStructureSets.VILLAGES::equals).isPresent()), + "Vanilla rejects a Village structure set in a single End biome before the biome mixin runs"); + + var planned = ChunkGeneratorStructureState.createForNormal(random, 42L, + AgeStructureSelection.planningBiomes(end, sets, villages), + AgeStructureSelection.filteredLookup(sets, villages, end)); + helper.assertTrue(planned.possibleStructureSets().stream() + .anyMatch(holder -> holder.unwrapKey().filter(BuiltinStructureSets.VILLAGES::equals).isPresent()), + "The authored Village must survive the structure-state biome gate"); + var village = sets.getOrThrow(BuiltinStructureSets.VILLAGES).value().structures().getFirst().structure(); + helper.assertTrue(!planned.getPlacementsForStructure(village).isEmpty(), + "The forced Village must have an actual placement in the Age structure state"); + helper.assertTrue(planned.possibleStructureSets().stream().noneMatch(holder -> holder.unwrapKey() + .filter(BuiltinStructureSets.DESERT_PYRAMIDS::equals).isPresent()), + "Planning biomes must not enable unrelated desert structures in the End Age"); + helper.assertTrue(end.possibleBiomes().size() == 1 && end.possibleBiomes().contains( + registries.lookupOrThrow(Registries.BIOME).getOrThrow(Biomes.THE_END)), + "The actual Age biome source must remain End-only"); + helper.succeed(); + } + + @GameTest(template = "empty") + public static void otherAuthoredStructuresOverrideBiomeWithInstability(GameTestHelper helper) { + var registries = helper.getLevel().registryAccess(); + var sets = registries.lookupOrThrow(Registries.STRUCTURE_SET); + var end = new FixedBiomeSource(registries.lookupOrThrow(Registries.BIOME).getOrThrow(Biomes.THE_END)); + var random = helper.getLevel().getChunkSource().randomState(); + for (var entry : Map.of("shipwrecks", BuiltinStructureSets.SHIPWRECKS, + "trial_chambers", BuiltinStructureSets.TRIAL_CHAMBERS).entrySet()) { + String feature = entry.getKey(); + var choices = repeated(feature, 1); + var planned = ChunkGeneratorStructureState.createForNormal(random, 42L, + AgeStructureSelection.planningBiomes(end, sets, choices), + AgeStructureSelection.filteredLookup(sets, choices, end)); + helper.assertTrue(planned.possibleStructureSets().stream() + .anyMatch(holder -> holder.unwrapKey().filter(entry.getValue()::equals).isPresent()), + "Authored " + feature + " must survive the structure-state biome gate"); + var structure = sets.getOrThrow(entry.getValue()).value().structures().getFirst().structure(); + helper.assertTrue(!planned.getPlacementsForStructure(structure).isEmpty(), + "Authored " + feature + " must have a placement in the End Age"); + + var writing = new OrderedWriting(List.of(WritingEntry.linkPanel(), + page("terrain/standard"), page("biome/the_end"), page("biome/single"), + page("feature/" + feature))); + var age = AgeRegistrySavedData.resolveOrCreate(helper.getLevel(), + new AgeReference(java.util.UUID.randomUUID(), "Forced " + feature), writing); + helper.assertValueEqual(age.instability().score(), 100, + "An authored " + feature + " outside its normal biomes must add 100 instability"); + } + helper.succeed(); + } + private static List repeated(String feature, int count) { return java.util.stream.IntStream.range(0, count) .mapToObj(ignored -> new AgeFeatureSelection.Choice(id(feature), Optional.empty())) diff --git a/src/main/java/net/dnorberg/rivencraft/book/AgeStructureSelection.java b/src/main/java/net/dnorberg/rivencraft/book/AgeStructureSelection.java index 0c93e48..738cdf8 100644 --- a/src/main/java/net/dnorberg/rivencraft/book/AgeStructureSelection.java +++ b/src/main/java/net/dnorberg/rivencraft/book/AgeStructureSelection.java @@ -1,5 +1,6 @@ package net.dnorberg.rivencraft.book; +import com.mojang.serialization.MapCodec; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,6 +19,9 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.levelgen.structure.BuiltinStructureSets; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureSet; @@ -133,6 +137,13 @@ public final class AgeStructureSelection { return compatible.isEmpty() || biomes.biomes().stream().anyMatch(compatible::contains); } + /** A mixed pool still needs the authored override wherever its structure is not normally allowed. */ + public static boolean requiresBiomeOverride(ResourceLocation feature, AgeBiomeSelection biomes, + RegistryAccess registries) { + Set compatible = compatibleBiomes(feature, registries); + return !compatible.isEmpty() && biomes.biomes().stream().anyMatch(biome -> !compatible.contains(biome)); + } + /** True when this exact registered structure belongs to an authored structure page. */ public static boolean authoredStructure(Structure structure, RegistryAccess registries, List choices) { @@ -177,22 +188,38 @@ public final class AgeStructureSelection { public static Stream> allowedSets(Stream> sets, List choices) { + return allowedSets(sets, choices, null); + } + + public static Stream> allowedSets(Stream> sets, + List choices, + BiomeSource actualBiomes) { Map enabled = enabledSets(choices); return sets.filter(holder -> holder.unwrapKey() - .map(key -> allowed(key.location(), enabled.keySet())).orElse(false)) + .map(key -> allowed(key.location(), enabled.keySet()) + && (actualBiomes == null || enabled.containsKey(key.location()) + || hasActualBiome(holder.value(), actualBiomes))).orElse(false)) .map(holder -> scaledHolder(holder, enabled)); } public static HolderLookup filteredLookup(HolderLookup lookup, List choices) { + return filteredLookup(lookup, choices, null); + } + + public static HolderLookup filteredLookup(HolderLookup lookup, + List choices, + BiomeSource actualBiomes) { Map enabled = enabledSets(choices); Map, Holder.Reference> scaled = new HashMap<>(); return new HolderLookup<>() { @Override public Optional> get(ResourceKey key) { if (!allowed(key.location(), enabled.keySet())) return Optional.empty(); - return lookup.get(key).map(holder -> scaled.computeIfAbsent(key, - ignored -> scaledReference(holder, enabled.getOrDefault(key.location(), 1)))); + return lookup.get(key).filter(holder -> actualBiomes == null || enabled.containsKey(key.location()) + || hasActualBiome(holder.value(), actualBiomes)) + .map(holder -> scaled.computeIfAbsent(key, + ignored -> scaledReference(holder, enabled.getOrDefault(key.location(), 1)))); } @Override @@ -204,6 +231,8 @@ public final class AgeStructureSelection { public Stream> listElements() { return lookup.listElements() .filter(holder -> allowed(holder.key().location(), enabled.keySet())) + .filter(holder -> actualBiomes == null || enabled.containsKey(holder.key().location()) + || hasActualBiome(holder.value(), actualBiomes)) .map(holder -> scaled.computeIfAbsent(holder.key(), ignored -> scaledReference(holder, enabled.getOrDefault(holder.key().location(), 1)))); @@ -220,6 +249,50 @@ public final class AgeStructureSelection { return !CONTROLLED_SETS.contains(set) || enabled.contains(set); } + private static boolean hasActualBiome(StructureSet set, BiomeSource actualBiomes) { + Set> present = actualBiomes.possibleBiomes(); + return set.structures().stream().flatMap(entry -> entry.structure().value().biomes().stream()) + .anyMatch(present::contains); + } + + /** Only the structure planner sees these extra biomes; terrain and weather keep the real source. */ + public static BiomeSource planningBiomes(BiomeSource actual, HolderLookup sets, + List choices) { + Set enabled = enabledSets(choices).keySet(); + List> structureBiomes = enabled.stream() + .map(id -> sets.get(ResourceKey.create(Registries.STRUCTURE_SET, id))) + .flatMap(Optional::stream) + .flatMap(holder -> holder.value().structures().stream()) + .flatMap(entry -> entry.structure().value().biomes().stream()) + .distinct().toList(); + return structureBiomes.isEmpty() ? actual : new PlanningBiomeSource(actual, structureBiomes); + } + + private static final class PlanningBiomeSource extends BiomeSource { + private final BiomeSource actual; + private final List> structureBiomes; + + private PlanningBiomeSource(BiomeSource actual, List> structureBiomes) { + this.actual = actual; + this.structureBiomes = structureBiomes; + } + + @Override + protected MapCodec codec() { + throw new UnsupportedOperationException("Structure-planning biome sources are never serialized"); + } + + @Override + protected Stream> collectPossibleBiomes() { + return Stream.concat(actual.possibleBiomes().stream(), structureBiomes.stream()); + } + + @Override + public Holder getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) { + return actual.getNoiseBiome(x, y, z, sampler); + } + } + private static Holder scaledHolder(Holder holder, Map enabled) { int occurrences = holder.unwrapKey().map(key -> enabled.getOrDefault(key.location(), 1)).orElse(1); diff --git a/src/main/java/net/dnorberg/rivencraft/world/AgeFeatureChunkGenerator.java b/src/main/java/net/dnorberg/rivencraft/world/AgeFeatureChunkGenerator.java index de8f165..11fb865 100644 --- a/src/main/java/net/dnorberg/rivencraft/world/AgeFeatureChunkGenerator.java +++ b/src/main/java/net/dnorberg/rivencraft/world/AgeFeatureChunkGenerator.java @@ -110,8 +110,10 @@ public final class AgeFeatureChunkGenerator extends NoiseBasedChunkGenerator { @Override public ChunkGeneratorStructureState createState(HolderLookup sets, RandomState random, long seed) { - return ChunkGeneratorStructureState.createForNormal(random, seed, getBiomeSource(), - AgeStructureSelection.filteredLookup(sets, features)); + BiomeSource actual = getBiomeSource(); + return ChunkGeneratorStructureState.createForNormal(random, seed, + AgeStructureSelection.planningBiomes(actual, sets, features), + AgeStructureSelection.filteredLookup(sets, features, actual)); } @Override diff --git a/src/main/java/net/dnorberg/rivencraft/world/AgeFlatChunkGenerator.java b/src/main/java/net/dnorberg/rivencraft/world/AgeFlatChunkGenerator.java index 1a86e90..528f9bb 100644 --- a/src/main/java/net/dnorberg/rivencraft/world/AgeFlatChunkGenerator.java +++ b/src/main/java/net/dnorberg/rivencraft/world/AgeFlatChunkGenerator.java @@ -72,8 +72,9 @@ public final class AgeFlatChunkGenerator extends ChunkGenerator { Stream> entries = settings.structureOverrides() .map(HolderSet::stream) .orElseGet(() -> structures.listElements().map(holder -> (Holder) holder)); - return ChunkGeneratorStructureState.createForFlat(random, seed, biomeSource, - AgeStructureSelection.allowedSets(entries, features)); + return ChunkGeneratorStructureState.createForFlat(random, seed, + AgeStructureSelection.planningBiomes(biomeSource, structures, features), + AgeStructureSelection.allowedSets(entries, features, biomeSource)); } @Override