Add PackBiome and PackRegion so modules can look up pack biomes and regions through PackResources

This commit is contained in:
piexel committed 2026-10-08 13:34:26 +02:00
1 parent 50f51db8b2
commit 33fc9adca9
6 files changed
+67 -3

No files matched your search

+1 -1
View File
@@ -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<T>`, `PackResources` |
| Pack-scoped resolution | `ResourceId`, `ResourceKey<T>`, `PackResources`, `PackBiome`, `PackRegion` |
| Terrain and settings sampling | `TerrainSampler`, `BiomeSample`, `TerrainSample`, `FeatureSettings` |
| Dense chunk output | `Hunk<T>`, `GenerationContext.hunk`, reference `ArrayHunk<T>` |
| Sparse geometry and transforms | `ObjectGenerator`, `GeneratedObject`, `ObjectTransform`, `ObjectTransformer` |
+2
View File
@@ -423,6 +423,8 @@ and closes the edit in every case. Stages get buffered `PlacementAccess` without
- `ResourceId` requires a namespace. `ResourceKey<T>` 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
@@ -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 {
@@ -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<ResourceId> 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);
}
}
@@ -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<ResourceId> landBiomes,
List<ResourceId> seaBiomes, List<ResourceId> shoreBiomes, List<ResourceId> 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);
}
}
@@ -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()));
}
}