Add native biome families, desert vegetation, static sky controls and Seamless views
Build and smoke / changes (push) Waiting to run

This commit is contained in:
dnorberg committed 2026-11-17 18:12:07 -05:00
1 parent 90e4a98a7a
commit d199ac253e
92 files changed
+2520 -224

No files matched your search

@@ -1,6 +1,7 @@
package net.dnorberg.rivencraft.book;
import java.util.ArrayList;
import net.dnorberg.rivencraft.shared.NativeBiomeKind;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -23,14 +24,39 @@ import net.minecraft.world.level.biome.MultiNoiseBiomeSource;
import net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList;
/** Frozen biome pool and controller for an authored Age. Repeated IDs are intentional weights. */
public record AgeBiomeSelection(AgeTraits.BiomeDistribution distribution, List<ResourceLocation> biomes) {
public record AgeBiomeSelection(AgeTraits.BiomeDistribution distribution, List<ResourceLocation> biomes, NativeBiomeKind nativeKind) {
public static final TagKey<Biome> CAVE_BIOMES = TagKey.create(Registries.BIOME,
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "cave_biomes"));
public AgeBiomeSelection(AgeTraits.BiomeDistribution distribution, List<ResourceLocation> biomes) {
this(distribution, biomes, NativeBiomeKind.TERRAIN);
}
public AgeBiomeSelection {
java.util.Objects.requireNonNull(nativeKind, "nativeKind");
if (distribution == null) throw new IllegalArgumentException("Missing biome distribution");
biomes = List.copyOf(biomes);
if (biomes.isEmpty()) throw new IllegalArgumentException("An Age biome pool cannot be empty");
if (nativeKind != NativeBiomeKind.TERRAIN && distribution != AgeTraits.BiomeDistribution.NATIVE)
throw new IllegalArgumentException("A native family requires Native distribution");
}
public net.minecraft.nbt.CompoundTag save() {
var tag = new net.minecraft.nbt.CompoundTag();
tag.putString("Distribution", distribution.name());
tag.putString("NativeKind", nativeKind.name());
var ids = new net.minecraft.nbt.ListTag();
biomes.forEach(id -> ids.add(net.minecraft.nbt.StringTag.valueOf(id.toString())));
tag.put("Ids", ids);
return tag;
}
public static AgeBiomeSelection load(net.minecraft.nbt.CompoundTag tag) {
var ids = tag.getList("Ids", net.minecraft.nbt.Tag.TAG_STRING);
var biomes = new ArrayList<ResourceLocation>();
for (int i = 0; i < ids.size(); i++) biomes.add(ResourceLocation.parse(ids.getString(i)));
return new AgeBiomeSelection(AgeTraits.BiomeDistribution.valueOf(tag.getString("Distribution")), biomes,
tag.contains("NativeKind") ? NativeBiomeKind.valueOf(tag.getString("NativeKind")) : NativeBiomeKind.TERRAIN);
}
public static AgeBiomeSelection compile(WritingGrammar.Result writing, AgeTraits traits,
@@ -48,8 +74,10 @@ public record AgeBiomeSelection(AgeTraits.BiomeDistribution distribution, List<R
.filter(symbol -> symbol.semantics().role() == SymbolSemantics.Role.BIOME_CONTROLLER)
.map(symbol -> ((SymbolSemantics.ChoiceValue) symbol.semantics().value()).id())
.findFirst();
NativeBiomeKind nativeKind = controller.map(NativeBiomeKind::controller).orElse(NativeBiomeKind.TERRAIN);
AgeTraits.BiomeDistribution distribution = controller
.map(value -> AgeTraits.BiomeDistribution.valueOf(value.toUpperCase(java.util.Locale.ROOT)))
.map(value -> NativeBiomeKind.isController(value) ? AgeTraits.BiomeDistribution.NATIVE
: AgeTraits.BiomeDistribution.valueOf(value.toUpperCase(java.util.Locale.ROOT)))
.orElse(traits.biomeDistribution());
if (profile.terrain() == AgeRuntimeProfile.Terrain.VOID && controller.isEmpty() && authored.isEmpty()) {
distribution = AgeTraits.BiomeDistribution.SINGLE;
@@ -63,6 +91,12 @@ public record AgeBiomeSelection(AgeTraits.BiomeDistribution distribution, List<R
: AgeTraits.BiomeDistribution.MEDIUM;
}
}
if (distribution == AgeTraits.BiomeDistribution.NATIVE
&& (nativeKind != NativeBiomeKind.TERRAIN || isCave(profile))) {
if (!authored.isEmpty()) throw new IllegalArgumentException("Native biome distribution cannot use biome pages");
NativeBiomeKind family = nativeKind == NativeBiomeKind.TERRAIN ? NativeBiomeKind.CAVES : nativeKind;
return new AgeBiomeSelection(distribution, NativeBiomePools.pool(registries, family), family);
}
var registry = registries.lookupOrThrow(Registries.BIOME);
boolean cave = isCave(profile);
for (ResourceLocation id : authored) {
@@ -24,13 +24,15 @@ public record AgeDefinition(
List<AgeFeatureSelection.Choice> randomFeatures,
AgeInstability instability,
AgeInstabilityPlan instabilityPlan,
RandomPagePolicy randomPagePolicy
RandomPagePolicy randomPagePolicy,
@Nullable AgeBiomeSelection randomBiomes
) {
public static final ResourceLocation RANDOM_VANILLA_PROFILE = ResourceLocation.fromNamespaceAndPath(
Rivencraft.MOD_ID, "random_vanilla"
);
public static final int LEGACY_GENERATOR_CUTOFF = 16;
public static final int CURRENT_GENERATION_VERSION = AgeSkyProfile.RANDOM_SKY_GENERATION_VERSION;
public static final int NATIVE_CAVE_GENERATION_VERSION = 18;
public static final int CURRENT_GENERATION_VERSION = NATIVE_CAVE_GENERATION_VERSION;
public AgeDefinition {
Objects.requireNonNull(id, "id");
@@ -100,6 +102,15 @@ public record AgeDefinition(
instabilityPlan, RandomPagePolicy.UNRESTRICTED);
}
public AgeDefinition(UUID id, String name, long seed, ResourceLocation generationProfile,
int generationVersion, long createdGameTime, ResourceLocation dimensionId,
BlockPos spawn, AgeTraits traits, AgeGenerationPlan plan, AgeSeasonMode seasonMode,
List<AgeFeatureSelection.Choice> randomFeatures, AgeInstability instability,
AgeInstabilityPlan instabilityPlan, RandomPagePolicy randomPagePolicy) {
this(id, name, seed, generationProfile, generationVersion, createdGameTime, dimensionId, spawn,
traits, plan, seasonMode, randomFeatures, instability, instabilityPlan, randomPagePolicy, null);
}
public static ResourceLocation dimensionId(UUID ageId) {
return ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "age/" + ageId);
}
@@ -129,7 +140,7 @@ public record AgeDefinition(
public AgeDefinition withSpawn(BlockPos spawn) {
return new AgeDefinition(id, name, seed, generationProfile, generationVersion,
createdGameTime, dimensionId, spawn.immutable(), traits, plan, seasonMode,
randomFeatures, instability, instabilityPlan, randomPagePolicy);
randomFeatures, instability, instabilityPlan, randomPagePolicy, randomBiomes);
}
/** A frozen authored profile takes precedence over the profile ID on old books. */
@@ -489,11 +489,19 @@ public final class AgeDimensionService {
}
AgeBiomeSelection selection = age.plan() != null && age.plan().biomeSelection() != null
? age.plan().biomeSelection()
: age.randomBiomes() != null ? age.randomBiomes()
: age.generationVersion() < AgeDefinition.NATIVE_CAVE_GENERATION_VERSION
&& AgeBiomeSelection.isCave(profile)
&& age.traits().biomeDistribution() == AgeTraits.BiomeDistribution.NATIVE
? new AgeBiomeSelection(AgeTraits.BiomeDistribution.NATIVE,
AgeBiomeSelection.eligible(server.registryAccess(), profile))
: AgeBiomeSelection.compile(net.dnorberg.rivencraft.writing.WritingGrammar.parse(OrderedWriting.EMPTY),
age.traits(), profile, age.seed(), server.registryAccess(), age.randomPagePolicy());
var registry = server.registryAccess().lookupOrThrow(Registries.BIOME);
List<Holder<Biome>> biomes = new ArrayList<>();
List<ResourceLocation> fallbacks = AgeBiomeSelection.eligible(server.registryAccess(), profile);
List<ResourceLocation> fallbacks = selection.nativeKind() == net.dnorberg.rivencraft.shared.NativeBiomeKind.TERRAIN
? AgeBiomeSelection.eligible(server.registryAccess(), profile)
: NativeBiomePools.pool(server.registryAccess(), selection.nativeKind());
Set<ResourceLocation> present = new LinkedHashSet<>();
for (ResourceLocation id : selection.biomes()) {
var holder = registry.get(ResourceKey.create(Registries.BIOME, id));
@@ -514,7 +522,9 @@ public final class AgeDimensionService {
ResourceKey.create(Registries.BIOME, fallback)));
}
AgeTraits.BiomeDistribution distribution = selection.distribution();
if (distribution == AgeTraits.BiomeDistribution.NATIVE && !AgeBiomeSelection.isCave(profile)
if (distribution == AgeTraits.BiomeDistribution.NATIVE
&& selection.nativeKind() == net.dnorberg.rivencraft.shared.NativeBiomeKind.TERRAIN
&& !AgeBiomeSelection.isCave(profile)
&& profile.terrain() == AgeRuntimeProfile.Terrain.NOISE) {
var parameters = server.registryAccess()
.lookupOrThrow(Registries.MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST);
@@ -160,12 +160,7 @@ public record AgeGenerationPlan(int version, long ageSeed, OrderedWriting writin
profile.putString("Dimension", runtimeProfile.dimensionType().toString());
tag.put("RuntimeProfile", profile);
if (biomeSelection != null) {
CompoundTag biomeTag = new CompoundTag();
biomeTag.putString("Distribution", biomeSelection.distribution().name());
ListTag biomeIds = new ListTag();
biomeSelection.biomes().forEach(id -> biomeIds.add(StringTag.valueOf(id.toString())));
biomeTag.put("Ids", biomeIds);
tag.put("BiomeSelection", biomeTag);
tag.put("BiomeSelection", biomeSelection.save());
}
return tag;
}
@@ -199,14 +194,7 @@ public record AgeGenerationPlan(int version, long ageSeed, OrderedWriting writin
CompoundTag profile = tag.getCompound("RuntimeProfile");
AgeBiomeSelection selection = null;
if (version >= 2) {
CompoundTag biomeTag = tag.getCompound("BiomeSelection");
ListTag biomeIds = biomeTag.getList("Ids", CompoundTag.TAG_STRING);
List<ResourceLocation> ids = new ArrayList<>();
for (int index = 0; index < biomeIds.size(); index++) {
ids.add(ResourceLocation.parse(biomeIds.getString(index)));
}
selection = new AgeBiomeSelection(AgeTraits.BiomeDistribution.valueOf(
biomeTag.getString("Distribution")), ids);
selection = AgeBiomeSelection.load(tag.getCompound("BiomeSelection"));
}
List<Integer> activeIndices = version >= 3
? java.util.Arrays.stream(tag.getIntArray("ActiveSymbolIndices")).boxed().toList()
@@ -167,7 +167,7 @@ public final class AgeRegistrySavedData extends SavedData {
previous.generationProfile(), previous.generationVersion(), previous.createdGameTime(),
previous.dimensionId(), previous.spawn(), previous.traits(), plan, previous.seasonMode(),
previous.randomFeatures(), previous.instability(), previous.instabilityPlan(),
previous.randomPagePolicy());
previous.randomPagePolicy(), previous.randomBiomes());
if (AgeDimensionService.unload(server, previous) == AgeDimensionService.UnloadResult.FAILED)
return false;
ages.put(ageId, changed);
@@ -217,7 +217,12 @@ public final class AgeRegistrySavedData extends SavedData {
AgeRuntimeProfiles.resolve(seedProfile), registries, policy) : List.of(),
instability,
instabilityPlan,
plan == null ? policy : RandomPagePolicy.UNRESTRICTED
plan == null ? policy : RandomPagePolicy.UNRESTRICTED,
plan == null && effectiveTraits.biomeDistribution() == AgeTraits.BiomeDistribution.NATIVE
&& AgeBiomeSelection.isCave(AgeRuntimeProfiles.resolve(seedProfile))
? AgeBiomeSelection.compile(net.dnorberg.rivencraft.writing.WritingGrammar.parse(OrderedWriting.EMPTY),
effectiveTraits, AgeRuntimeProfiles.resolve(seedProfile), seed, registries, policy)
: null
);
ages.put(created.id(), created);
setDirty();
@@ -287,7 +292,9 @@ public final class AgeRegistrySavedData extends SavedData {
instabilityPlan,
entry.contains(RANDOM_PAGE_POLICY_TAG, CompoundTag.TAG_COMPOUND)
? RandomPagePolicy.load(entry.getCompound(RANDOM_PAGE_POLICY_TAG))
: RandomPagePolicy.UNRESTRICTED
: RandomPagePolicy.UNRESTRICTED,
entry.contains("RandomBiomes", CompoundTag.TAG_COMPOUND)
? AgeBiomeSelection.load(entry.getCompound("RandomBiomes")) : null
));
}
return data;
@@ -321,6 +328,7 @@ public final class AgeRegistrySavedData extends SavedData {
traits.putFloat(CELESTIAL_PHASE_TAG, age.traits().celestialPhase());
entry.put(TRAITS_TAG, traits);
if (age.plan() != null) entry.put(PLAN_TAG, age.plan().save());
if (age.randomBiomes() != null) entry.put("RandomBiomes", age.randomBiomes().save());
if (!age.randomFeatures().isEmpty()) {
ListTag featureTags = new ListTag();
for (AgeFeatureSelection.Choice choice : age.randomFeatures()) {
@@ -1,6 +1,7 @@
package net.dnorberg.rivencraft.book;
import java.util.ArrayList;
import net.dnorberg.rivencraft.shared.StaticSkyResolution;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
@@ -9,12 +10,18 @@ import net.dnorberg.rivencraft.writing.SymbolSemantics;
import net.minecraft.resources.ResourceLocation;
/** The ordered, deterministic sky specification for an Age. No client data is trusted here. */
public record AgeSkyProfile(Style style, int color, List<Body> bodies) {
public record AgeSkyProfile(Style style, int color, List<Body> bodies, int staticResolution) {
public static final int RANDOM_SKY_GENERATION_VERSION = 17;
private static final int[] COLORS = {0xB74A50, 0xD9834B, 0xDBC574, 0x5AAB80,
0x6FA8DF, 0x9870B9, 0xD5DBE1, 0x252531};
public AgeSkyProfile(Style style, int color, List<Body> bodies) {
this(style, color, bodies, StaticSkyResolution.DEFAULT);
}
public AgeSkyProfile {
staticResolution = style == Style.STATIC ? StaticSkyResolution.clamp(staticResolution)
: StaticSkyResolution.DEFAULT;
bodies = List.copyOf(bodies);
long suns = bodies.stream().filter(body -> body.kind() == Kind.SUN).count();
long moons = bodies.size() - suns;
@@ -137,7 +144,22 @@ public record AgeSkyProfile(Style style, int color, List<Body> bodies) {
symbol.semantics().role() == SymbolSemantics.Role.CELESTIAL)) {
bodies.addAll(random(plan.ageSeed(), seeded).bodies());
}
return new AgeSkyProfile(style, color, bodies);
return new AgeSkyProfile(style, color, bodies, staticResolution(plan));
}
public static int staticResolution(AgeGenerationPlan plan) {
if (plan == null) return StaticSkyResolution.DEFAULT;
return StaticSkyResolution.requested(plan.symbols().stream()
.sorted(java.util.Comparator.comparingInt(AgeGenerationPlan.ResolvedSymbol::index))
.map(symbol -> {
var semantics = symbol.semantics();
if (semantics.role() == SymbolSemantics.Role.COLOR_NUMBER)
return (int) ((SymbolSemantics.NumberValue) semantics.value()).amount();
if (semantics.role() == SymbolSemantics.Role.SKY)
return ((SymbolSemantics.ChoiceValue) semantics.value()).id().equals("static")
? StaticSkyResolution.STATIC : StaticSkyResolution.OTHER_SKY;
return StaticSkyResolution.OTHER;
}).toList());
}
public static int mixColors(List<Integer> colors) {
@@ -0,0 +1,53 @@
package net.dnorberg.rivencraft.book;
import java.util.List;
import java.util.stream.Stream;
import net.dnorberg.rivencraft.shared.NativeBiomeKind;
import net.dnorberg.rivencraft.compat.TerraBlenderBiomes;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.Biome;
/** Family pools are resolved only when binding new writing, never re-filtered on load. */
public final class NativeBiomePools {
private NativeBiomePools() {}
public static final TagKey<Biome> CAVES = TagKey.create(Registries.BIOME,
ResourceLocation.fromNamespaceAndPath("rivencraft", "cave_biomes"));
public static List<ResourceLocation> pool(net.minecraft.core.RegistryAccess registries, NativeBiomeKind kind) {
var biomes = registries.lookupOrThrow(Registries.BIOME);
var nether = java.util.Set.copyOf(TerraBlenderBiomes.nether(registries));
java.util.function.Predicate<Holder.Reference<Biome>> isNether =
biome -> biome.is(BiomeTags.IS_NETHER) || nether.contains(biome.key().location());
var selected = biomes.listElements()
.filter(biome -> !biome.key().location().equals(ResourceLocation.parse("terrablender:deferred_placeholder")))
.filter(biome -> switch (kind) {
case CAVES -> biome.is(CAVES) && !isNether.test(biome);
case NETHER -> isNether.test(biome);
case END -> biome.is(BiomeTags.IS_END);
case TERRAIN -> throw new IllegalArgumentException("Terrain Native uses its own preset");
}).map(biome -> biome.key().location()).toList();
// Built-in family members remain recognizable if a data pack replaces the broad tags.
List<String> vanilla = switch (kind) {
case CAVES -> List.of("lush_caves", "dripstone_caves", "deep_dark");
case NETHER -> List.of("nether_wastes", "soul_sand_valley", "crimson_forest", "warped_forest", "basalt_deltas");
case END -> List.of("the_end", "end_highlands", "end_midlands", "small_end_islands", "end_barrens");
default -> List.of();
};
var fallback = vanilla.stream().map(ResourceLocation::withDefaultNamespace)
.filter(id -> biomes.get(ResourceKey.create(Registries.BIOME, id))
.filter(biome -> kind != NativeBiomeKind.CAVES || !isNether.test(biome)).isPresent());
var result = Stream.concat(selected.stream(), fallback).distinct().sorted().toList();
if (!result.isEmpty()) return result; // A one-biome family becomes a safe FixedBiomeSource.
var safe = kind == NativeBiomeKind.CAVES ? biomes.listElements().filter(biome -> !isNether.test(biome)
&& !biome.key().location().equals(ResourceLocation.parse("terrablender:deferred_placeholder")))
.map(biome -> biome.key().location()).sorted().findFirst()
: java.util.Optional.<ResourceLocation>empty();
return safe.map(List::of).orElseThrow(() -> new IllegalArgumentException("No usable " + kind + " biomes"));
}
}
@@ -56,7 +56,7 @@ public record RandomPagePolicy(Set<ResourceLocation> allowlist, Set<ResourceLoca
private static String category(ResourceLocation id) {
String path = id.getPath();
if (path.startsWith("biome/") && java.util.Set.of("native", "single", "tiled", "grid",
if (path.startsWith("biome/") && java.util.Set.of("native", "native_caves", "native_nether", "native_end", "single", "tiled", "grid",
"tiny", "small", "medium", "large", "huge").contains(path.substring("biome/".length())))
return "biome_distribution";
return path.substring(0, path.indexOf('/') < 0 ? path.length() : path.indexOf('/'));
@@ -23,7 +23,6 @@ import net.minecraft.resources.ResourceLocation;
/** An authored sky can use vanilla celestial rendering or Legacy-style moving TV static. */
public final class RivencraftSkyEffects extends DimensionSpecialEffects {
private static final int GRID = 16;
private static final int STATIC_GRID = 48;
private static final float RADIUS = 100.0F;
private static final ResourceLocation SUN = ResourceLocation.withDefaultNamespace("textures/environment/sun.png");
private static final ResourceLocation MOON = ResourceLocation.withDefaultNamespace("textures/environment/moon_phases.png");
@@ -74,7 +73,7 @@ public final class RivencraftSkyEffects extends DimensionSpecialEffects {
FogRenderer.setupNoFog();
BufferBuilder vertices = Tesselator.getInstance().begin(
VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
int grid = sky.style() == AgeSkyProfile.Style.STATIC ? STATIC_GRID : GRID;
int grid = sky.style() == AgeSkyProfile.Style.STATIC ? sky.staticResolution() : GRID;
for (int axis = 0; axis < 3; axis++) {
for (int sign : new int[]{-1, 1}) {
for (int x = 0; x < grid; x++) {
@@ -23,6 +23,7 @@ public record AgeCelestialAnglePayload(ResourceKey<Level> dimension, float angle
buffer.writeFloat(payload.angle());
buffer.writeEnum(payload.sky().style());
buffer.writeInt(payload.sky().color());
buffer.writeVarInt(payload.sky().staticResolution());
buffer.writeVarInt(payload.sky().bodies().size());
for (AgeSkyProfile.Body body : payload.sky().bodies()) {
buffer.writeEnum(body.kind());
@@ -39,6 +40,7 @@ public record AgeCelestialAnglePayload(ResourceKey<Level> dimension, float angle
float angle = buffer.readFloat();
AgeSkyProfile.Style style = buffer.readEnum(AgeSkyProfile.Style.class);
int color = buffer.readInt();
int resolution = buffer.readVarInt();
int count = buffer.readVarInt();
if (count < 0 || count > 20) throw new IllegalArgumentException("Invalid celestial body count");
java.util.List<AgeSkyProfile.Body> bodies = new java.util.ArrayList<>(count);
@@ -47,7 +49,7 @@ public record AgeCelestialAnglePayload(ResourceKey<Level> dimension, float angle
buffer.readFloat(), buffer.readFloat(), buffer.readDouble(), buffer.readFloat(),
buffer.readBoolean()));
return new AgeCelestialAnglePayload(dimension, angle,
new AgeSkyProfile(style, color, bodies));
new AgeSkyProfile(style, color, bodies, resolution));
}
);
@@ -61,7 +61,7 @@ public final class ModNetworking {
}
public static void register(RegisterPayloadHandlersEvent event) {
PayloadRegistrar registrar = event.registrar("18");
PayloadRegistrar registrar = event.registrar("19");
registrar.playToServer(RequestDescriptiveBookScreenPayload.TYPE, RequestDescriptiveBookScreenPayload.STREAM_CODEC,
ModNetworking::requestDescriptiveBookScreen);
registrar.playToClient(OpenDescriptiveBookScreenPayload.TYPE, OpenDescriptiveBookScreenPayload.STREAM_CODEC,
@@ -246,9 +246,8 @@ public final class AgeFeatureChunkGenerator extends NoiseBasedChunkGenerator {
continue;
}
if (AgeFeatureSelection.surfaceVegetation(choice.id())) {
int surface = chunk.getHeight(Heightmap.Types.WORLD_SURFACE_WG, 8, 8);
if (!AgeFeatureSelection.supportsSurfaceVegetation(
level.getBiome(new BlockPos(x + 8, surface, z + 8)))) continue;
AgeSurfaceVegetation.place(level, this, chunk, choice, ageSeed, occurrence);
continue;
}
ResourceLocation key = AgeFeatureSelection.placedFeature(choice.id());
if (key == null) continue; // Carvers are applied before decoration.
@@ -150,7 +150,12 @@ public final class AgeFlatChunkGenerator extends ChunkGenerator {
super.applyBiomeDecoration(level, chunk, structures);
int spikeOccurrence = 0;
int obeliskOccurrence = 0;
Map<AgeFeatureSelection.Choice, Integer> vegetationOccurrences = new HashMap<>();
for (AgeFeatureSelection.Choice choice : features) {
if (AgeFeatureSelection.surfaceVegetation(choice.id())) {
int occurrence = vegetationOccurrences.merge(choice, 1, Integer::sum) - 1;
AgeSurfaceVegetation.place(level, this, chunk, choice, ageSeed, occurrence);
}
if (AgeFeatureSelection.spikes(choice.id()))
SpikesFeature.generate(level, chunk, ageSeed, choice, spikeOccurrence++);
if (AgeFeatureSelection.obelisks(choice.id()))
@@ -0,0 +1,102 @@
package net.dnorberg.rivencraft.world;
import java.util.Optional;
import net.dnorberg.rivencraft.book.AgeFeatureSelection;
import java.util.stream.Stream;
import net.dnorberg.rivencraft.shared.DesertVegetation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
import net.minecraft.world.level.levelgen.placement.PlacementContext;
/** Routes only the three generic plant pages by the actual candidate biome. */
public final class AgeSurfaceVegetation {
public static final TagKey<Biome> DESERTS = TagKey.create(Registries.BIOME,
ResourceLocation.fromNamespaceAndPath("rivencraft", "desert_vegetation"));
private AgeSurfaceVegetation() {}
public static boolean isDesert(Holder<Biome> biome) {
return biome.is(DESERTS) && AgeFeatureSelection.supportsSurfaceVegetation(biome);
}
public static void place(WorldGenLevel level, ChunkGenerator generator, ChunkAccess chunk,
AgeFeatureSelection.Choice choice, long ageSeed, int occurrence) {
int x = chunk.getPos().getMinBlockX();
int z = chunk.getPos().getMinBlockZ();
long seed = ageSeed ^ (long) x * 341873128712L ^ (long) z * 132897987541L
^ (long) choice.hashCode() * 0x9E3779B97F4A7C15L
^ (long) occurrence * 0xD1B54A32D192ED03L;
place(level, generator, chunk, choice.id().getPath(),
AgeFeatureSelection.placedFeature(choice.id()), RandomSource.create(seed));
}
private static void place(WorldGenLevel level, ChunkGenerator generator, ChunkAccess chunk,
String page, ResourceLocation placedId, RandomSource random) {
DesertVegetation.Kind kind = switch (page) {
case "flowers" -> DesertVegetation.Kind.FLOWERS;
case "trees" -> DesertVegetation.Kind.TREES;
case "huge_trees" -> DesertVegetation.Kind.HUGE_TREES;
default -> throw new IllegalArgumentException("Not a generic vegetation page: " + page);
};
int x = chunk.getPos().getMinBlockX();
int z = chunk.getPos().getMinBlockZ();
// Separate streams keep ordinary non-desert placement independent of desert attempts.
RandomSource desertRandom = RandomSource.create(random.nextLong());
DesertVegetation.place(new DesertVegetation.World() {
public int surfaceY(int px, int pz) {
return level.getHeight(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, px, pz);
}
public int maxY() { return level.getMaxBuildHeight(); }
public boolean desert(int px, int py, int pz) {
return isDesert(level.getBiome(new BlockPos(px, py, pz)));
}
public DesertVegetation.Ground ground(int px, int py, int pz) {
var state = level.getBlockState(new BlockPos(px, py, pz));
if (state.is(Blocks.SAND) || state.is(Blocks.RED_SAND)) return DesertVegetation.Ground.SAND;
return state.is(BlockTags.DIRT)
&& level.getBlockState(new BlockPos(px, py - 1, pz)).isFaceSturdy(
level, new BlockPos(px, py - 1, pz), net.minecraft.core.Direction.UP)
? DesertVegetation.Ground.SOIL : DesertVegetation.Ground.OTHER;
}
public boolean air(int px, int py, int pz) {
return level.getBlockState(new BlockPos(px, py, pz)).isAir();
}
public void set(int px, int py, int pz, DesertVegetation.Plant plant) {
var block = switch (plant) {
case SAND -> Blocks.SAND;
case CACTUS -> Blocks.CACTUS;
case DEAD_BUSH -> Blocks.DEAD_BUSH;
};
level.setBlock(new BlockPos(px, py, pz), block.defaultBlockState(), 2);
}
}, kind, x, z, desertRandom::nextInt);
var vanilla = level.registryAccess().lookupOrThrow(Registries.PLACED_FEATURE)
.getOrThrow(ResourceKey.create(Registries.PLACED_FEATURE, placedId)).value();
var context = new PlacementContext(level, generator, Optional.empty());
Stream<BlockPos> positions = Stream.of(new BlockPos(x, level.getMinBuildHeight(), z));
for (var modifier : vanilla.placement()) {
if (!(modifier instanceof BiomeFilter))
positions = positions.flatMap(pos -> modifier.getPositions(context, random, pos));
}
// Keep vanilla count/height/ground rules, but never add generic flowers/oaks/spruces in deserts.
positions.forEach(pos -> {
Holder<Biome> biome = level.getBiome(pos);
if (AgeFeatureSelection.supportsSurfaceVegetation(biome) && !isDesert(biome))
vanilla.feature().value().place(level, generator, random, pos);
});
}
}
@@ -74,7 +74,7 @@ public record SymbolSemantics(Role role, Value value) {
public enum Role {
TERRAIN("terrain", Kind.RESOURCE),
BIOME_CONTROLLER("biome_controller", Kind.CHOICE,
"native", "single", "tiled", "grid", "tiny", "small", "medium", "large", "huge"),
"native", "native_caves", "native_nether", "native_end", "single", "tiled", "grid", "tiny", "small", "medium", "large", "huge"),
BIOME("biome", Kind.RESOURCE),
LIGHTING("lighting", Kind.CHOICE, "normal", "dark", "bright"),
SKY("sky", Kind.CHOICE, "overworld", "nether", "end", "static"),
@@ -74,16 +74,16 @@ public final class WritingGrammar {
Role role = semantics.orElseThrow().role();
ParsedSymbol parsed = new ParsedSymbol(index, reference, semantics.orElseThrow());
symbols.add(parsed);
if (pendingNumber != null && !numberTarget(role) && role != Role.COLOR_NUMBER) {
if (pendingNumber != null && !numberTarget(role, semantics.orElseThrow()) && role != Role.COLOR_NUMBER) {
diagnostics.add(new Diagnostic(Code.MISPLACED_MODIFIER, pendingNumber.index(),
"A number page must be immediately followed by a color, celestial modifier or Flooded page"));
"A number page must be immediately followed by a color, celestial modifier, Static Sky or Flooded page"));
pendingNumber = null;
}
if (role == Role.COLOR_NUMBER) {
if (pendingNumber != null && !numberRunTargetsFlooded(writing, index, resolver)) diagnostics.add(new Diagnostic(Code.MISPLACED_MODIFIER,
pendingNumber.index(), "A number page must be immediately followed by a color, celestial modifier or Flooded page"));
if (pendingNumber != null && !numberRunTargetsInteger(writing, index, resolver)) diagnostics.add(new Diagnostic(Code.MISPLACED_MODIFIER,
pendingNumber.index(), "A number page must be immediately followed by a color, celestial modifier, Static Sky or Flooded page"));
pendingNumber = parsed;
} else if (numberTarget(role)) {
} else if (numberTarget(role, semantics.orElseThrow())) {
pendingNumber = null;
}
if (modifier(role)) {
@@ -147,7 +147,7 @@ public final class WritingGrammar {
ParsedSymbol controller = singular.get(Role.BIOME_CONTROLLER);
if (controller != null && controller.semantics().value() instanceof ChoiceValue choice
&& choice.id().equals("native") && biomeCount > 0) {
&& net.dnorberg.rivencraft.shared.NativeBiomeKind.isController(choice.id()) && biomeCount > 0) {
diagnostics.add(new Diagnostic(Code.CONFLICT, controller.index(),
"Native biome distribution cannot use authored biome pages"));
} else if (controller != null && controller.semantics().value() instanceof ChoiceValue choice
@@ -167,7 +167,7 @@ public final class WritingGrammar {
int minimum = switch (choice.id()) {
case "single" -> 1;
case "tiled", "grid" -> 2;
case "native" -> 0;
case "native", "native_caves", "native_nether", "native_end" -> 0;
default -> 2;
};
if (biomeCount < minimum) diagnostics.add(new Diagnostic(Code.INCOMPLETE, -1,
@@ -189,7 +189,7 @@ public final class WritingGrammar {
|| role == Role.CELESTIAL_COLOR || role == Role.DIRECTION_MODIFIER;
}
private static boolean numberRunTargetsFlooded(OrderedWriting writing, int index,
private static boolean numberRunTargetsInteger(OrderedWriting writing, int index,
Function<SymbolReference, Optional<SymbolDefinition>> resolver) {
for (int next = index + 1; next < writing.entries().size(); next++) {
var reference = writing.entries().get(next).symbol();
@@ -197,15 +197,17 @@ public final class WritingGrammar {
var semantics = resolver.apply(reference.get()).flatMap(SymbolDefinition::semantics);
if (semantics.isEmpty()) return false;
Role role = semantics.get().role();
if (role != Role.COLOR_NUMBER) return role == Role.FLOODING;
if (role != Role.COLOR_NUMBER) return role == Role.FLOODING
|| role == Role.SKY && ((SymbolSemantics.ChoiceValue) semantics.get().value()).id().equals("static");
}
return false;
}
private static boolean numberTarget(Role role) {
private static boolean numberTarget(Role role, SymbolSemantics semantics) {
return role == Role.COLOR || role == Role.PERIOD_MODIFIER
|| role == Role.ANGLE_MODIFIER || role == Role.PHASE_MODIFIER
|| role == Role.SIZE_MODIFIER || role == Role.FLOODING;
|| role == Role.SIZE_MODIFIER || role == Role.FLOODING
|| role == Role.SKY && ((SymbolSemantics.ChoiceValue) semantics.value()).id().equals("static");
}
private static int stage(Role role) {
@@ -307,7 +309,7 @@ public final class WritingGrammar {
active.sort(Comparator.comparingInt(symbol -> stage(symbol.semantics().role())));
ParsedSymbol controller = lastChoice.get(Role.BIOME_CONTROLLER);
if (controller != null && controller.semantics().value() instanceof ChoiceValue choice) {
if (choice.id().equals("native")) {
if (net.dnorberg.rivencraft.shared.NativeBiomeKind.isController(choice.id())) {
active.removeIf(symbol -> symbol.semantics().role() == Role.BIOME);
} else if (choice.id().equals("single")) {
boolean retained = false;
@@ -169,7 +169,7 @@
"symbol.rivencraft.terrain.amplified": "Amplified Terrain",
"symbol.rivencraft.terrain.amplified.description": "Tall, sharply varied Overworld terrain.",
"symbol.rivencraft.terrain.cave": "Cave Terrain",
"symbol.rivencraft.terrain.cave.description": "An enclosed cave-shaped world with a sheltered arrival.",
"symbol.rivencraft.terrain.cave.description": "An enclosed cave-shaped world with a sheltered arrival. Native selects non-Nether cave biomes; other controllers can author Nether biomes explicitly.",
"symbol.rivencraft.terrain.island": "Island Terrain",
"symbol.rivencraft.terrain.island.description": "Floating-island terrain above the void.",
"symbol.rivencraft.terrain.flat": "Flat Terrain",
@@ -177,7 +177,7 @@
"symbol.rivencraft.terrain.void": "Void Terrain",
"symbol.rivencraft.terrain.void.description": "An empty world with a safe arrival platform.",
"symbol.rivencraft.biome.native": "Native Biomes",
"symbol.rivencraft.biome.native.description": "Use the terrain profile's native biome climate.",
"symbol.rivencraft.biome.native.description": "Use the terrain’s Native biome distribution. Cave terrain selects non-Nether cave biomes; explicit Native family pages work on any terrain.",
"symbol.rivencraft.biome.the_end": "The End Biome",
"symbol.rivencraft.biome.the_end.description": "Use the End biome in a written Age, including sky islands.",
"symbol.rivencraft.biome.lush_caves": "Lush Caves Biome",
@@ -224,7 +224,7 @@
"symbol.rivencraft.sky.end": "End Sky",
"symbol.rivencraft.sky.end.description": "Use the End sky and dark preview background.",
"symbol.rivencraft.sky.static": "Static Sky",
"symbol.rivencraft.sky.static.description": "Fill the sky with shifting television static.",
"symbol.rivencraft.sky.static.description": "Fill the sky with shifting television static. Adjacent Number Pages set cells per face in base 25 (1-128); default 48.",
"symbol.rivencraft.color.red": "Red Color",
"symbol.rivencraft.color.red.description": "Add red to the next Sky, Sun, or Moon. A number page directly before this page sets its strength.",
"symbol.rivencraft.color.green": "Green Color",
@@ -260,7 +260,7 @@
"symbol.rivencraft.number.22": "D'ni 22",
"symbol.rivencraft.number.23": "D'ni 23",
"symbol.rivencraft.number.24": "D'ni 24",
"symbol.rivencraft.number.description": "Set the next color page to this number × 10, Angle or Phase to × 15°, Length to × 0.08, or Celestial Size from 0.25× to 3×. A number page affects only the immediately following page.",
"symbol.rivencraft.number.description": "Set the next color page to this number × 10, Angle or Phase to × 15°, Length to × 0.08, or Celestial Size from 0.25× to 3×. Adjacent Number Pages before Flooded or Static Sky form a base-25 height or resolution; other targets use one immediately preceding number.",
"symbol.rivencraft.weather.normal": "Normal Weather",
"symbol.rivencraft.weather.normal.description": "Use the normal weather cycle.",
"symbol.rivencraft.weather.fast": "Fast Weather",
@@ -329,13 +329,13 @@
"symbol.rivencraft.feature.caves.description": "Add extra caves to the chosen noise terrain.",
"symbol.rivencraft.block.generated.description": "Place before a compatible feature page, or let the Age choose a compatible feature.",
"symbol.rivencraft.feature.flowers": "Flowers",
"symbol.rivencraft.feature.flowers.description": "Add vanilla flower patches to surface terrain.",
"symbol.rivencraft.feature.flowers.description": "Add flower patches to surface terrain, or dead bushes in tagged deserts. Repeated pages add more attempts.",
"symbol.rivencraft.feature.trees": "Trees",
"symbol.rivencraft.feature.trees.description": "Add vanilla plains trees to surface terrain.",
"symbol.rivencraft.feature.trees.description": "Add plains trees to surface terrain, or cacti in tagged deserts. Repeated pages add more attempts.",
"symbol.rivencraft.feature.rocks": "Rocks",
"symbol.rivencraft.feature.rocks.description": "Add boulders using a random solid material, or specify one with a block page.",
"symbol.rivencraft.feature.huge_trees": "Huge Trees",
"symbol.rivencraft.feature.huge_trees.description": "Add vanilla old-growth spruce trees to surface terrain.",
"symbol.rivencraft.feature.huge_trees.description": "Add old-growth spruce trees to surface terrain, or tall cacti in tagged deserts. Repeated pages add more attempts.",
"symbol.rivencraft.feature.surface_lakes": "Surface Lakes",
"symbol.rivencraft.feature.surface_lakes.description": "Add surface lakes using a random fluid, or specify one with a fluid page.",
"symbol.rivencraft.feature.deep_lakes": "Deep Lakes",
@@ -475,5 +475,11 @@
"advancement.rivencraft.open_portal.title": "A Window Between Ages",
"advancement.rivencraft.open_portal.description": "Activate a Crystal Portal with a bound book.",
"symbol.rivencraft.environment.flooded": "Flooded",
"symbol.rivencraft.environment.flooded.description": "Fill open space with water up to Y=63, or the base-25 Number Pages immediately before this page. Works in Cave terrain. Last Flooded wins; heights are bounded for safe arrival."
"symbol.rivencraft.environment.flooded.description": "Fill open space with water up to Y=63, or the base-25 Number Pages immediately before this page. Works in Cave terrain. Last Flooded wins; heights are bounded for safe arrival.",
"symbol.rivencraft.biome.native_caves": "Native Caves",
"symbol.rivencraft.biome.native_caves.description": "Use recognized non-Nether cave biomes in seeded regions on any terrain. Native controllers choose their own pool; individual biome pages are not used.",
"symbol.rivencraft.biome.native_nether": "Native Nether",
"symbol.rivencraft.biome.native_nether.description": "Use recognized Nether biomes, including TerraBlender Nether regions, on any terrain. Native controllers choose their own pool; individual biome pages are not used.",
"symbol.rivencraft.biome.native_end": "Native End",
"symbol.rivencraft.biome.native_end.description": "Use recognized End biomes in seeded regions on any terrain. Native controllers choose their own pool; individual biome pages are not used."
}
@@ -0,0 +1,11 @@
{
"schema_version": 2,
"name": "symbol.rivencraft.biome.native_caves",
"description": "symbol.rivencraft.biome.native_caves.description",
"category": "rivencraft:biome",
"semantics": {
"role": "biome_controller",
"value": "native_caves"
},
"poem": "Constraint Nature Void Sustain"
}
@@ -0,0 +1,11 @@
{
"schema_version": 2,
"name": "symbol.rivencraft.biome.native_end",
"description": "symbol.rivencraft.biome.native_end.description",
"category": "rivencraft:biome",
"semantics": {
"role": "biome_controller",
"value": "native_end"
},
"poem": "Constraint Nature Celestial Sustain"
}
@@ -0,0 +1,11 @@
{
"schema_version": 2,
"name": "symbol.rivencraft.biome.native_nether",
"description": "symbol.rivencraft.biome.native_nether.description",
"category": "rivencraft:biome",
"semantics": {
"role": "biome_controller",
"value": "native_nether"
},
"poem": "Constraint Nature Dynamic Flux"
}
@@ -3,6 +3,10 @@
"values": [
"minecraft:lush_caves",
"minecraft:dripstone_caves",
"minecraft:deep_dark"
"minecraft:deep_dark",
{
"id": "#c:is_cave",
"required": false
}
]
}
@@ -0,0 +1,10 @@
{
"replace": false,
"values": [
"minecraft:desert",
{
"id": "#c:is_desert",
"required": false
}
]
}