From 33fc9adca9e980feadb64b9f7bd4f8cff54dab70 Mon Sep 17 00:00:00 2001 From: piexel Date: Thu, 8 Oct 2026 13:34:26 +0200 Subject: [PATCH] Add PackBiome and PackRegion so modules can look up pack biomes and regions through PackResources --- CONTRACTS.md | 2 +- README.md | 2 ++ .../com/volmit/resource/PackResources.java | 7 ++++-- src/main/java/com/volmit/world/PackBiome.java | 19 ++++++++++++++++ .../java/com/volmit/world/PackRegion.java | 22 +++++++++++++++++++ src/test/java/com/volmit/ApiValuesTest.java | 18 +++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/volmit/world/PackBiome.java create mode 100644 src/main/java/com/volmit/world/PackRegion.java diff --git a/CONTRACTS.md b/CONTRACTS.md index 8787e8994..77e04a87e 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -26,7 +26,7 @@ types that carry them and lists what the Iris adapter still owes. | Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@Snippet`, `@Ref`/`Reference`, `FeatureRegistry.registerSettings`, host `LoadedPack.schema()` (`PackSchema`, `FeatureSchema` with `shorthand()`, `ObjectType`, `SchemaOption`, `ValueKind` with `HostKind`), `ModuleHost.describingHostTypesIn` | | Geometry and mantle registration | `FeatureRegistry`, host `ModuleRegistry`, `FeatureCatalog` | | Block states and palettes | `BlockState`, `BlockRegistry`, `BlockPalette` | -| Pack-scoped resolution | `ResourceId`, `ResourceKey`, `PackResources` | +| Pack-scoped resolution | `ResourceId`, `ResourceKey`, `PackResources`, `PackBiome`, `PackRegion` | | Terrain and settings sampling | `TerrainSampler`, `BiomeSample`, `TerrainSample`, `FeatureSettings` | | Dense chunk output | `Hunk`, `GenerationContext.hunk`, reference `ArrayHunk` | | Sparse geometry and transforms | `ObjectGenerator`, `GeneratedObject`, `ObjectTransform`, `ObjectTransformer` | diff --git a/README.md b/README.md index 0de5049f1..0f60227ae 100644 --- a/README.md +++ b/README.md @@ -423,6 +423,8 @@ and closes the edit in every case. Stages get buffered `PlacementAccess` without - `ResourceId` requires a namespace. `ResourceKey` pairs it with a public type. - `PackResources` serves one immutable pack snapshot; caches must not survive a reload. + It serves pack objects (`GeneratedObject`), biomes (`PackBiome`) and regions (`PackRegion`); the + requested type selects the kind, so `BiomeSample` ids look up directly. - `BlockState` has value equality and sorted properties; `BlockRegistry` checks it against the platform. `BlockPalette` and `NoiseSampler` are typed resources. - `GeneratedObject` is sparse, immutable local geometry. `PlacementRequest` aligns its anchor diff --git a/src/main/java/com/volmit/resource/PackResources.java b/src/main/java/com/volmit/resource/PackResources.java index 5d21e087a..1ac90f40f 100644 --- a/src/main/java/com/volmit/resource/PackResources.java +++ b/src/main/java/com/volmit/resource/PackResources.java @@ -7,8 +7,11 @@ import java.util.UUID; /** Immutable view of one loaded pack snapshot, safe for concurrent reads. * Reload produces a different snapshotId, even for the same pack. Resources must be immutable - * or explicitly thread-safe. Unknown IDs return empty; a known ID with the wrong requested - * type throws IllegalArgumentException. Broken resources fail loading rather than appearing absent. + * or explicitly thread-safe. The requested type selects the kind of resource, so one ID can name + * both a biome and a region. Hosts serve {@code GeneratedObject} (pack objects), + * {@code PackBiome} and {@code PackRegion}; an ID the pack lacks for that kind returns empty, and a + * type the host does not serve throws IllegalArgumentException. Broken resources fail loading + * rather than appearing absent. * The host owns resolution, imports, native handles and caches; no filesystem paths escape. */ public interface PackResources { diff --git a/src/main/java/com/volmit/world/PackBiome.java b/src/main/java/com/volmit/world/PackBiome.java new file mode 100644 index 000000000..d9fbe59ed --- /dev/null +++ b/src/main/java/com/volmit/world/PackBiome.java @@ -0,0 +1,19 @@ +package com.volmit.world; + +import com.volmit.resource.ResourceId; +import java.util.List; +import java.util.Objects; + +/** A biome of the loaded pack, found through {@code PackResources} by the ids a {@link BiomeSample} gives. + * platformBiome is the platform biome the host writes for it. children are the pack biomes that can + * generate inside it. Rarity is relative to the biome's siblings: higher is rarer. + */ +public record PackBiome(ResourceId id, String name, ResourceId platformBiome, int rarity, List children) { + public PackBiome { + Objects.requireNonNull(id, "id"); + Objects.requireNonNull(name, "name"); + Objects.requireNonNull(platformBiome, "platformBiome"); + if (rarity < 1) throw new IllegalArgumentException("Biome rarity must be at least 1: " + rarity); + children = List.copyOf(children); + } +} diff --git a/src/main/java/com/volmit/world/PackRegion.java b/src/main/java/com/volmit/world/PackRegion.java new file mode 100644 index 000000000..2473e20a2 --- /dev/null +++ b/src/main/java/com/volmit/world/PackRegion.java @@ -0,0 +1,22 @@ +package com.volmit.world; + +import com.volmit.resource.ResourceId; +import java.util.List; +import java.util.Objects; + +/** A region of the loaded pack, found through {@code PackResources} by the id a {@link BiomeSample} gives. + * The biome lists name the pack biomes the region generates on land, at sea, on shores and in caves. + * Rarity is relative to the other regions: higher is rarer. + */ +public record PackRegion(ResourceId id, String name, int rarity, List landBiomes, + List seaBiomes, List shoreBiomes, List caveBiomes) { + public PackRegion { + Objects.requireNonNull(id, "id"); + Objects.requireNonNull(name, "name"); + if (rarity < 1) throw new IllegalArgumentException("Region rarity must be at least 1: " + rarity); + landBiomes = List.copyOf(landBiomes); + seaBiomes = List.copyOf(seaBiomes); + shoreBiomes = List.copyOf(shoreBiomes); + caveBiomes = List.copyOf(caveBiomes); + } +} diff --git a/src/test/java/com/volmit/ApiValuesTest.java b/src/test/java/com/volmit/ApiValuesTest.java index a73747256..c660777e0 100644 --- a/src/test/java/com/volmit/ApiValuesTest.java +++ b/src/test/java/com/volmit/ApiValuesTest.java @@ -150,4 +150,22 @@ class ApiValuesTest { assertThrows(IllegalArgumentException.class, () -> new TerrainSample(Double.NaN, OptionalInt.empty(), 0)); assertThrows(IllegalArgumentException.class, () -> new TerrainSample(0, OptionalInt.empty(), -1)); } + + @Test + void packBiomesAndRegionsAreImmutableValues() { + var children = new ArrayList<>(List.of(ResourceId.parse("pack:dunes"))); + var desert = new PackBiome(ResourceId.parse("pack:desert"), "Desert", ResourceId.parse("minecraft:desert"), 2, children); + children.clear(); + assertEquals(List.of(ResourceId.parse("pack:dunes")), desert.children()); + assertThrows(UnsupportedOperationException.class, () -> desert.children().clear()); + assertThrows(IllegalArgumentException.class, + () -> new PackBiome(desert.id(), "Desert", desert.platformBiome(), 0, List.of())); + + var land = List.of(desert.id()); + var arid = new PackRegion(ResourceId.parse("pack:arid"), "Arid", 1, land, List.of(), List.of(), List.of()); + assertEquals(land, arid.landBiomes()); + assertThrows(UnsupportedOperationException.class, () -> arid.caveBiomes().add(desert.id())); + assertThrows(IllegalArgumentException.class, + () -> new PackRegion(arid.id(), "Arid", 0, land, List.of(), List.of(), List.of())); + } }