Merge branch 'v3/lane-engine' into v3/lane-studio

This commit is contained in:
piexel committed 2026-11-10 13:51:55 +01:00
commit 1e44f45a34
95 files changed
+2134 -1186

No files matched your search

+1 -1
View File
@@ -36,7 +36,7 @@ types that carry them and lists what the Iris adapter still owes.
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
| Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` |
| Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `DecorationStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` |
| Pack-scoped resolution | `ResourceId` (`ofPackKey`, `ofPlatformKey`), `ContentKey`, `PackResources` (`find(kind, id)`, `require`, `ids(kind)`, `idOf`; kinds `BIOMES`, `REGIONS`, `OBJECTS`, `EXPRESSIONS`, `IMAGE_MAPS`), `PackBiome`, `PackRegion`, `PackExpression`, `PackImageMap` |
| Pack-scoped resolution | `ResourceId` (`ofPackKey`, `ofPlatformKey`), `ContentKey`, `PackResources` (`find(kind, id)`, `require`, `ids(kind)`, `idOf`; kinds `BIOMES`, `REGIONS`, `OBJECTS`, `EXPRESSIONS`, `IMAGE_MAPS`), `PackBiome`, `PackRegion` (their children and biome lists are `Weighted` entries; `Weighted.pick` walks them the way the host does), `PackExpression`, `PackImageMap` |
| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@ResourceRef`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` |
| Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` |
| Per-world module state | `PackWorld` (`state`), `InvocationContext.world()`, host `WorldStates` |
@@ -7,21 +7,21 @@ 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. vanillaBiome is the biome vanilla's own rules see it as,
* such as which structures may start in it: the platform biome unless the pack says otherwise. children are the pack
* biomes that can generate inside it. Rarity is relative to the biome's siblings: higher is rarer.
* biomes that can generate inside it, in the order the child noise walks them; the biome itself is listed among them
* where it stays itself.
*/
public record PackBiome(ResourceId id, String name, ResourceId platformBiome, ResourceId vanillaBiome, int rarity,
List<ResourceId> children) {
public record PackBiome(ResourceId id, String name, ResourceId platformBiome, ResourceId vanillaBiome,
List<Weighted<ResourceId>> children) {
public PackBiome {
Objects.requireNonNull(id, "id");
Objects.requireNonNull(name, "name");
Objects.requireNonNull(platformBiome, "platformBiome");
Objects.requireNonNull(vanillaBiome, "vanillaBiome");
if (rarity < 1) throw new IllegalArgumentException("Biome rarity must be at least 1: " + rarity);
children = List.copyOf(children);
}
/** A biome that vanilla's rules see as its platform biome. */
public PackBiome(ResourceId id, String name, ResourceId platformBiome, int rarity, List<ResourceId> children) {
this(id, name, platformBiome, platformBiome, rarity, children);
public PackBiome(ResourceId id, String name, ResourceId platformBiome, List<Weighted<ResourceId>> children) {
this(id, name, platformBiome, platformBiome, children);
}
}
@@ -5,15 +5,15 @@ 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.
* The biome lists name the pack biomes the region generates on land, at sea, on shores and in caves, in the order
* the biome noise walks them.
*/
public record PackRegion(ResourceId id, String name, int rarity, List<ResourceId> landBiomes,
List<ResourceId> seaBiomes, List<ResourceId> shoreBiomes, List<ResourceId> caveBiomes) {
public record PackRegion(ResourceId id, String name, List<Weighted<ResourceId>> landBiomes,
List<Weighted<ResourceId>> seaBiomes, List<Weighted<ResourceId>> shoreBiomes,
List<Weighted<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);
@@ -0,0 +1,59 @@
package com.volmit.world;
import java.util.List;
import java.util.Objects;
/** A list entry that counts as {@code weight} copies of itself in a row, as biome, region and child lists write it.
* {@link #pick} walks such a list with a noise from 0 to 1, so a module that picks among a pack's weighted lists
* (a region's biomes, a biome's children) lands on the same entry the host does.
*/
public record Weighted<T>(T value, int weight) {
public static final int MIN_WEIGHT = 1;
public static final int MAX_WEIGHT = 1000;
/** Which entry gets noise lying exactly on the edge between two. Cellular noise sits on such edges over whole cells,
* so this decides real patches of terrain. A region's biome list gives edges to the earlier entry and children to the
* later one.
*/
public enum Edge {
EARLIER,
LATER
}
public Weighted {
Objects.requireNonNull(value, "value");
if (weight < MIN_WEIGHT || weight > MAX_WEIGHT) {
throw new IllegalArgumentException("Weight must be from " + MIN_WEIGHT + " to " + MAX_WEIGHT + ": " + weight);
}
}
/** Picks along the list as if every entry were written out {@code weight} times: the noise from 0 to 1 is split into
* equal slots, one per copy, in list order. Noise below 0 picks the first entry, noise above 1 the last; an empty list
* picks nothing.
*/
public static <T> T pick(List<Weighted<T>> entries, double noise, Edge edge) {
if (entries.isEmpty()) {
return null;
}
double slotPosition = noise * totalWeight(entries);
int slotsUpToHere = 0;
for (Weighted<T> entry : entries) {
slotsUpToHere += entry.weight();
boolean inThisEntry = edge == Edge.EARLIER ? slotPosition <= slotsUpToHere : slotPosition < slotsUpToHere;
if (inThisEntry) {
return entry.value();
}
}
return entries.getLast().value();
}
public static int totalWeight(List<? extends Weighted<?>> entries) {
int total = 0;
for (Weighted<?> entry : entries) {
total += entry.weight();
}
return total;
}
}
@@ -160,24 +160,20 @@ class ApiValuesTest {
@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);
var children = new ArrayList<>(List.of(new Weighted<>(ResourceId.parse("pack:dunes"), 2)));
var desert = new PackBiome(ResourceId.parse("pack:desert"), "Desert", ResourceId.parse("minecraft:desert"), children);
children.clear();
assertEquals(List.of(ResourceId.parse("pack:dunes")), desert.children());
assertEquals(List.of(new Weighted<>(ResourceId.parse("pack:dunes"), 2)), desert.children());
assertThrows(UnsupportedOperationException.class, () -> desert.children().clear());
assertThrows(IllegalArgumentException.class,
() -> new PackBiome(desert.id(), "Desert", desert.platformBiome(), 0, List.of()));
assertEquals(desert.platformBiome(), desert.vanillaBiome(), "vanilla sees the platform biome unless a pack says otherwise");
var mesa = new PackBiome(ResourceId.parse("pack:mesa"), "Mesa", ResourceId.parse("minecraft:desert"),
ResourceId.parse("minecraft:badlands"), 1, List.of());
ResourceId.parse("minecraft:badlands"), List.of());
assertEquals(ResourceId.parse("minecraft:badlands"), mesa.vanillaBiome());
var land = List.of(desert.id());
var arid = new PackRegion(ResourceId.parse("pack:arid"), "Arid", 1, land, List.of(), List.of(), List.of());
var land = List.of(new Weighted<>(desert.id(), 1));
var arid = new PackRegion(ResourceId.parse("pack:arid"), "Arid", 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()));
assertThrows(UnsupportedOperationException.class, () -> arid.caveBiomes().add(new Weighted<>(desert.id(), 1)));
}
static final class Keep {}
@@ -0,0 +1,45 @@
package com.volmit;
import com.volmit.world.Weighted;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class WeightedTest {
@Test
void weightedEntriesCountAsCopiesOfThemselvesInARow() {
assertThrows(IllegalArgumentException.class, () -> new Weighted<>("plains", 0));
assertThrows(IllegalArgumentException.class, () -> new Weighted<>("plains", Weighted.MAX_WEIGHT + 1));
assertThrows(NullPointerException.class, () -> new Weighted<String>(null, 1));
var entries = List.of(new Weighted<>("barren", 3), new Weighted<>("forest", 1));
assertEquals("barren", Weighted.pick(entries, 0.74, Weighted.Edge.EARLIER));
assertEquals("forest", Weighted.pick(entries, 0.76, Weighted.Edge.EARLIER));
assertEquals("barren", Weighted.pick(entries, -0.5, Weighted.Edge.EARLIER));
assertEquals("forest", Weighted.pick(entries, 1.5, Weighted.Edge.LATER));
assertNull(Weighted.pick(List.<Weighted<String>>of(), 0.5, Weighted.Edge.EARLIER));
}
@Test
void anEdgeGoesWhereTheRuleSays() {
var entries = List.of(new Weighted<>("first", 1), new Weighted<>("second", 1));
assertEquals("first", Weighted.pick(entries, 0.5, Weighted.Edge.EARLIER));
assertEquals("second", Weighted.pick(entries, 0.5, Weighted.Edge.LATER));
assertEquals("second", Weighted.pick(entries, Math.nextUp(0.5), Weighted.Edge.EARLIER));
}
@Test
void halfSlotWeightsMatchTheOldRoundedChildPick() {
var oldSlots = List.of("barren", "barren", "barren", "forest", "barren", "barren");
var converted = List.of(new Weighted<>("barren", 5), new Weighted<>("forest", 2), new Weighted<>("barren", 3));
for (int step = 0; step <= 1000; step++) {
double noise = step / 1000D;
String oldPick = oldSlots.get((int) Math.round(noise * (oldSlots.size() - 1)));
assertEquals(oldPick, Weighted.pick(converted, noise, Weighted.Edge.LATER), "noise " + noise);
}
}
}