mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Merged generation history
- Immutable generation epochs now coexist with dimension stacks - Historical terrain, biomes, structures, and locate behavior remain stable across updates - Versioned generation kernels preserve the combined runtime contract
This commit is contained in:
commit
56b5f4dd0b
263 files changed
+39624
-1849
No files matched your search
+4
-2
@@ -18,6 +18,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -267,10 +268,11 @@ public class IrisModdedStructureParityTest {
|
||||
.setInferredType(InferredType.SEA);
|
||||
|
||||
Set<String> keys = ModdedDimensionMetadata.collectConfiguredBiomeKeys(
|
||||
List.of(ocean, custom, shore, unsafeSea), "OverWorld");
|
||||
List.of(ocean, custom, shore, unsafeSea),
|
||||
customBiome -> "iris:biomes/" + customBiome.getId().toLowerCase(Locale.ROOT));
|
||||
|
||||
assertEquals(Set.of("minecraft:deep_ocean", "minecraft:forest", "minecraft:beach",
|
||||
"minecraft:the_void", "overworld:aurora"), keys);
|
||||
"minecraft:the_void", "iris:biomes/aurora"), keys);
|
||||
assertFalse(keys.contains("minecraft:desert"));
|
||||
assertFalse(keys.contains("minecraft:plains"));
|
||||
|
||||
|
||||
+31
@@ -52,6 +52,19 @@ public class ModdedForcedDatapackTest {
|
||||
assertEquals("iris:overworld", ModdedWorldgenIds.generatorIdentity("overworld"));
|
||||
assertEquals("iris:other/overworld",
|
||||
ModdedWorldgenIds.generatorIdentity("other:overworld"));
|
||||
assertEquals(
|
||||
new ModdedWorldgenIds.ScopedDimension("overworld", "overworld"),
|
||||
ModdedWorldgenIds.scopedDimensionType(
|
||||
ModdedWorldgenIds.dimensionTypeRef("overworld", "overworld")
|
||||
).orElseThrow()
|
||||
);
|
||||
assertEquals(
|
||||
List.of(
|
||||
ModdedWorldgenIds.biomeRef("overworld", "overworld", "mist"),
|
||||
"overworld:mist"
|
||||
),
|
||||
ModdedWorldgenIds.legacyBiomeRefs("overworld", "overworld", "mist")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,6 +161,24 @@ public class ModdedForcedDatapackTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsConflictingRegistryDefinitionsDuringMerge() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-forced-pack-conflict");
|
||||
try {
|
||||
Path source = Files.createDirectories(root.resolve("source/data/iris/worldgen/biome"));
|
||||
Path destination = Files.createDirectories(root.resolve("destination/data/iris/worldgen/biome"));
|
||||
Files.writeString(source.resolve("shared.json"), "{\"temperature\":1}", StandardCharsets.UTF_8);
|
||||
Files.writeString(destination.resolve("shared.json"), "{\"temperature\":2}", StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(
|
||||
IOException.class,
|
||||
() -> ModdedForcedDatapack.mergeDirectory(root.resolve("source"), root.resolve("destination"))
|
||||
);
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> directoryEntries(Path root) throws IOException {
|
||||
try (Stream<Path> entries = Files.list(root)) {
|
||||
return entries.map((Path path) -> path.getFileName().toString())
|
||||
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedGenerationHistoryRoutingContractTest {
|
||||
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
|
||||
|
||||
@Test
|
||||
public void startupPublishesOnlyAnImmutableHistoryBoundRuntime() throws IOException {
|
||||
String source = source("ModdedWorldEngines.java");
|
||||
String create = method(source, "private static Engine create(");
|
||||
String createHistoryEngine = method(source, "private static Engine createHistoryEngine(");
|
||||
String buildEngine = method(source, "private static IrisEngine buildEngine(");
|
||||
|
||||
assertTrue(create.contains("ModdedGenerationHistoryStorage.openOrAdopt("));
|
||||
assertFalse(create.contains("resolvePack("));
|
||||
assertTrue(createHistoryEngine.contains("candidate.attachGenerationHistory("));
|
||||
assertTrue(createHistoryEngine.contains("IrisBoundarySignatureSampler.INSTANCE"));
|
||||
assertTrue(createHistoryEngine.contains("getGenerationTransitionWidthBlocks()"));
|
||||
assertTrue(createHistoryEngine.contains("router.preloadActiveRuntimes();"));
|
||||
assertBefore(createHistoryEngine, "close(candidate);", "ModdedGenerationHistoryStorage.resolveActive(history)");
|
||||
assertTrue(createHistoryEngine.contains("GenerationHistoryRuntimeRouter.attach("));
|
||||
assertTrue(buildEngine.contains("active.packRoot().toFile()"));
|
||||
assertTrue(buildEngine.contains("history.paths().activationMantleRoot(activation.activationId())"));
|
||||
assertTrue(buildEngine.contains("epoch.kernelVersion()"));
|
||||
assertTrue(buildEngine.contains("transitionPlan"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyExplicitTransientStudioEnginesBypassHistory() throws IOException {
|
||||
String manager = source("ModdedDimensionManager.java");
|
||||
String transientCreate = method(manager, "public static Handle createTransientStudio(");
|
||||
String persistentCreate = method(manager, "public static Handle createPersistent(");
|
||||
String engines = source("ModdedWorldEngines.java");
|
||||
String studio = method(engines, "private static IrisEngine createTransientStudioEngine(");
|
||||
String generator = source("IrisModdedChunkGenerator.java");
|
||||
String bypass = method(generator, "boolean allowsGenerationHistoryBypass(");
|
||||
String route = method(generator, "private GenerationHistoryRuntimeRouter.RuntimeRoute openHistoryRoute(");
|
||||
|
||||
assertTrue(transientCreate.contains("ModdedGenerationMode.TRANSIENT_STUDIO"));
|
||||
assertTrue(persistentCreate.contains("ModdedGenerationMode.PERSISTENT_CREATE"));
|
||||
assertTrue(studio.contains("IrisData.openRuntime(packDir)"));
|
||||
assertTrue(studio.contains("IrisEngine.InitializationMode.STUDIO"));
|
||||
assertFalse(studio.contains("ModdedGenerationHistoryStorage"));
|
||||
assertFalse(studio.contains("attachGenerationHistory("));
|
||||
assertTrue(bypass.contains("generationMode != ModdedGenerationMode.TRANSIENT_STUDIO"));
|
||||
assertTrue(bypass.contains("irisEngine.isStudio()"));
|
||||
assertTrue(bypass.contains("Only an explicitly transient Iris Studio engine"));
|
||||
assertBefore(route, "allowsGenerationHistoryBypass(current)", "requireHistoryRouter(current, operation)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyCoordinateBearingChunkStageOpensItsRoutedRuntime() throws IOException {
|
||||
String source = source("IrisModdedChunkGenerator.java");
|
||||
|
||||
assertRuntimeRoute(source, "public Pair<BlockPos, Holder<Structure>> findNearestMapStructure(");
|
||||
assertCoordinateRoute(source, "public WeightedList<MobSpawnSettings.SpawnerData> getMobsAt(");
|
||||
assertRuntimeRoute(source, "public CompletableFuture<ChunkAccess> createBiomes(");
|
||||
assertRuntimeRoute(source, "public void applyCarvers(");
|
||||
assertRuntimeRoute(source, "public void buildSurface(");
|
||||
assertRuntimeRoute(source, "public void applyBiomeDecoration(");
|
||||
assertRuntimeRoute(source, "public void createStructures(");
|
||||
assertRuntimeRoute(source, "public void createReferences(");
|
||||
assertRuntimeRoute(source, "public void spawnOriginalMobs(");
|
||||
assertCoordinateRoute(source, "public int getBaseHeight(");
|
||||
assertCoordinateRoute(source, "public NoiseColumn getBaseColumn(");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncTerrainKeepsTheRouteUntilDurableSemanticClaim() throws IOException {
|
||||
String source = source("IrisModdedChunkGenerator.java");
|
||||
String fill = method(source, "public CompletableFuture<ChunkAccess> fillFromNoise(");
|
||||
String terrain = method(source, "private ChunkAccess generateTerrain(");
|
||||
String completion = method(source, "private static CompletableFuture<ChunkAccess> closeRouteOnCompletion(");
|
||||
|
||||
assertBefore(fill, "openHistoryRoute(", "CompletableFuture.supplyAsync(");
|
||||
assertTrue(fill.contains("generateTerrain(chunk, generationEngine, pos, air, route)"));
|
||||
assertTrue(fill.contains("return closeRouteOnCompletion(pipeline, route);"));
|
||||
assertTrue(terrain.contains("openHistoryRuntimeScope(route)"));
|
||||
assertBefore(terrain, "generationEngine.generate(", "route.claimGeneratedSemantics();");
|
||||
assertBefore(terrain, "route.claimGeneratedSemantics();", "return chunk;");
|
||||
assertTrue(completion.contains("pipeline.whenComplete("));
|
||||
assertTrue(completion.contains("route.close();"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeQueriesRouteEachCoordinateAndKeepRuntimeSpecificCaches() throws IOException {
|
||||
String source = source("IrisModdedBiomeSource.java");
|
||||
String structure = method(source, "public Holder<Biome> getNoiseBiome(");
|
||||
String visible = method(source, "Holder<Biome> getVisibleNoiseBiome(");
|
||||
String batch = method(source, "public Set<Holder<Biome>> getBiomesWithin(");
|
||||
String resolution = method(source, "private Holder<Biome> resolveVisibleBiome(");
|
||||
|
||||
assertTrue(structure.contains("openHistoryCoordinateScope("));
|
||||
assertTrue(visible.contains("openHistoryCoordinateScope("));
|
||||
assertTrue(batch.contains("quartX << 2, quartZ << 2"));
|
||||
assertTrue(source.contains("int runtimeIdentity = engine.getCacheID();"));
|
||||
assertTrue(source.contains("cache.get(runtimeIdentity, key)"));
|
||||
assertTrue(source.contains("cache.put(runtimeIdentity, key, resolved)"));
|
||||
assertBefore(resolution, "historicalPhysicalBiomeKeyAt(", "ModdedWorldgenIds.biomeRef(engine");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discreteStagesResumeIncompleteHistoricalChunksAndRejectTransitionOwnership() throws IOException {
|
||||
String generator = source("IrisModdedChunkGenerator.java");
|
||||
String discrete = method(generator, "private boolean allowsRoutedDiscreteGeneration(");
|
||||
String decoration = method(generator, "public void applyBiomeDecoration(");
|
||||
String structures = method(generator, "public void createStructures(");
|
||||
String mobs = method(generator, "public void spawnOriginalMobs(");
|
||||
String nativeStage = source("ModdedNativeStructureStage.java");
|
||||
String adjust = method(nativeStage, "void adjustGeneratedStructures(");
|
||||
String place = method(nativeStage, "void placeVanillaStructures(");
|
||||
|
||||
assertTrue(discrete.contains("chunk.getPersistedStatus().isOrAfter(stage)"));
|
||||
assertFalse(discrete.contains("router.history().activeActivation().activationId()"));
|
||||
assertFalse(discrete.contains("return true;"));
|
||||
assertTrue(discrete.contains("allowsNewGenerationChunk("));
|
||||
assertTrue(decoration.contains("ChunkStatus.FEATURES"));
|
||||
assertTrue(structures.contains("ChunkStatus.STRUCTURE_STARTS"));
|
||||
assertTrue(mobs.contains("ChunkStatus.SPAWN"));
|
||||
assertBefore(decoration, "allowsRoutedDiscreteGeneration(", "nativeStructures.placeVanillaStructures(");
|
||||
assertBefore(structures, "allowsRoutedDiscreteGeneration(", "super.createStructures(");
|
||||
assertBefore(mobs, "allowsRoutedDiscreteGeneration(", "NaturalSpawner.spawnMobsForChunkGeneration(");
|
||||
assertBefore(adjust, "allowsNewGenerationFootprint(", "recordWorldCheckStructureShift(");
|
||||
assertTrue(place.contains("allowsNewGenerationFootprint("));
|
||||
}
|
||||
|
||||
private static void assertRuntimeRoute(String source, String signature) {
|
||||
String body = method(source, signature);
|
||||
assertTrue(signature + " must open a generation-history route", body.contains("openHistoryRoute("));
|
||||
assertTrue(signature + " must open its routed runtime", body.contains("openHistoryRuntimeScope(route)"));
|
||||
}
|
||||
|
||||
private static void assertCoordinateRoute(String source, String signature) {
|
||||
String body = method(source, signature);
|
||||
assertTrue(signature + " must route its coordinate", body.contains("openHistoryCoordinateScope("));
|
||||
}
|
||||
|
||||
private static void assertBefore(String source, String first, String second) {
|
||||
int firstIndex = source.indexOf(first);
|
||||
int secondIndex = source.indexOf(second);
|
||||
assertTrue("Missing source contract token: " + first, firstIndex >= 0);
|
||||
assertTrue("Missing source contract token: " + second, secondIndex >= 0);
|
||||
assertTrue(first + " must occur before " + second, firstIndex < secondIndex);
|
||||
}
|
||||
|
||||
private static String source(String fileName) throws IOException {
|
||||
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
|
||||
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY,
|
||||
sourceRoot != null && !sourceRoot.isBlank());
|
||||
return Files.readString(Path.of(sourceRoot, "art", "arcane", "iris", "modded", fileName));
|
||||
}
|
||||
|
||||
private static String method(String source, String signature) {
|
||||
int start = source.indexOf(signature);
|
||||
assertTrue("Missing source contract signature: " + signature, start >= 0);
|
||||
int openBrace = source.indexOf('{', start);
|
||||
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
|
||||
int depth = 0;
|
||||
for (int index = openBrace; index < source.length(); index++) {
|
||||
char current = source.charAt(index);
|
||||
if (current == '{') {
|
||||
depth++;
|
||||
} else if (current == '}') {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
return source.substring(start, index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
|
||||
}
|
||||
}
|
||||
+362
@@ -0,0 +1,362 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.history.GenerationEpoch;
|
||||
import art.arcane.iris.engine.history.GenerationEpochContractFactory;
|
||||
import art.arcane.iris.engine.history.GenerationHistory;
|
||||
import art.arcane.iris.engine.history.GenerationPackFingerprint;
|
||||
import art.arcane.iris.engine.history.GenerationRegistryContract;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedGenerationHistoryStorageTest {
|
||||
private static final String DIMENSION_FINGERPRINT = "11".repeat(32);
|
||||
private static final String DEFINITION_FINGERPRINT = "22".repeat(32);
|
||||
private static final int TRANSITION_WIDTH_BLOCKS = 256;
|
||||
|
||||
@Test
|
||||
public void newDimensionPublishesAnImmutableWorldLocalPack() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-create");
|
||||
try {
|
||||
Path source = pack(root.resolve("global-pack"), "first");
|
||||
ModdedGenerationHistoryStorage.Candidate candidate = candidate(source, registryContract());
|
||||
GenerationHistory history = ModdedGenerationHistoryStorage.createOrStage(
|
||||
root.resolve("world-dimension"),
|
||||
source,
|
||||
41L,
|
||||
candidate,
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
|
||||
Path activePack = history.activePackRoot();
|
||||
assertEquals("first", Files.readString(activePack.resolve("content.txt"), StandardCharsets.UTF_8));
|
||||
Files.writeString(source.resolve("content.txt"), "mutated", StandardCharsets.UTF_8);
|
||||
assertEquals("first", Files.readString(activePack.resolve("content.txt"), StandardCharsets.UTF_8));
|
||||
assertEquals(candidate.packFingerprint(), history.activeEpoch().packFingerprint());
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingDimensionAdoptsItsSelectedPackOnlyOnce() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-adopt");
|
||||
try {
|
||||
Path source = pack(root.resolve("global-pack"), "adopted");
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
AtomicInteger sourceReads = new AtomicInteger();
|
||||
ModdedGenerationHistoryStorage.AdoptionSourceSupplier supplier = () -> {
|
||||
sourceReads.incrementAndGet();
|
||||
return new ModdedGenerationHistoryStorage.AdoptionSource(
|
||||
source,
|
||||
candidate(source, registryContract())
|
||||
);
|
||||
};
|
||||
|
||||
GenerationHistory adopted = ModdedGenerationHistoryStorage.restoreOrAdopt(
|
||||
dimensionRoot,
|
||||
91L,
|
||||
supplier,
|
||||
ModdedGenerationHistoryStorageTest::union
|
||||
);
|
||||
String epochId = adopted.activeEpoch().epochId();
|
||||
Files.writeString(source.resolve("content.txt"), "changed", StandardCharsets.UTF_8);
|
||||
GenerationHistory restored = ModdedGenerationHistoryStorage.restoreOrAdopt(
|
||||
dimensionRoot,
|
||||
91L,
|
||||
supplier,
|
||||
ModdedGenerationHistoryStorageTest::union
|
||||
);
|
||||
|
||||
assertEquals(1, sourceReads.get());
|
||||
assertEquals(epochId, restored.activeEpoch().epochId());
|
||||
assertEquals("adopted", Files.readString(
|
||||
restored.activePackRoot().resolve("content.txt"),
|
||||
StandardCharsets.UTF_8
|
||||
));
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectedUpdateStagesWithoutReplacingTheActivePack() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-stage");
|
||||
try {
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
Path first = pack(root.resolve("first-pack"), "first");
|
||||
GenerationHistory created = ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
first,
|
||||
5L,
|
||||
candidate(first, registryContract()),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
String activeEpoch = created.activeEpoch().epochId();
|
||||
Path second = pack(root.resolve("second-pack"), "second");
|
||||
GenerationHistory staged = ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
second,
|
||||
5L,
|
||||
candidate(second, registryContract()),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
|
||||
assertEquals(activeEpoch, staged.activeEpoch().epochId());
|
||||
assertTrue(staged.pendingActivation().isPresent());
|
||||
assertNotEquals(activeEpoch, staged.pendingActivation().orElseThrow().epochId());
|
||||
assertEquals("first", Files.readString(
|
||||
staged.activePackRoot().resolve("content.txt"),
|
||||
StandardCharsets.UTF_8
|
||||
));
|
||||
assertEquals("second", Files.readString(
|
||||
staged.packRoot(staged.pendingActivation().orElseThrow().activationId()).resolve("content.txt"),
|
||||
StandardCharsets.UTF_8
|
||||
));
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unavailableUpdateRegistryDoesNotCreatePendingActivation() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-stage-registry");
|
||||
try {
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
Path first = pack(root.resolve("first-pack"), "first");
|
||||
GenerationHistory history = ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
first,
|
||||
63L,
|
||||
candidate(first, registryContract()),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
Path second = pack(root.resolve("second-pack"), "second");
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
second,
|
||||
63L,
|
||||
candidate(second, registryContract()),
|
||||
contracts -> GenerationRegistryContract.empty(),
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
));
|
||||
|
||||
assertTrue(history.pendingActivation().isEmpty());
|
||||
assertEquals("first", Files.readString(
|
||||
history.activePackRoot().resolve("content.txt"),
|
||||
StandardCharsets.UTF_8
|
||||
));
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWithANewCustomBiomeKeyStagesBeforeThatKeyIsRegistered() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-new-biome");
|
||||
try {
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
Path first = pack(root.resolve("first-pack"), "first");
|
||||
GenerationRegistryContract activeContract = registryContract("minecraft:plains");
|
||||
ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
first,
|
||||
71L,
|
||||
candidate(first, activeContract),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
Path second = pack(root.resolve("second-pack"), "second");
|
||||
GenerationRegistryContract candidateContract = registryContract(
|
||||
"iris:biomes/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
);
|
||||
AtomicInteger validationCalls = new AtomicInteger();
|
||||
|
||||
GenerationHistory staged = ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
second,
|
||||
71L,
|
||||
candidate(second, candidateContract),
|
||||
contracts -> {
|
||||
validationCalls.incrementAndGet();
|
||||
assertEquals(1, contracts.size());
|
||||
assertEquals(activeContract, contracts.iterator().next());
|
||||
return union(contracts);
|
||||
},
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
|
||||
assertEquals(1, validationCalls.get());
|
||||
assertTrue(staged.pendingActivation().isPresent());
|
||||
assertEquals(
|
||||
candidateContract,
|
||||
staged.manifest()
|
||||
.epoch(staged.pendingActivation().orElseThrow().epochId())
|
||||
.orElseThrow()
|
||||
.registryContract()
|
||||
);
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreRejectsASeedMismatchBeforeConsultingTheGlobalPack() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-seed");
|
||||
try {
|
||||
Path source = pack(root.resolve("global-pack"), "seeded");
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
source,
|
||||
123L,
|
||||
candidate(source, registryContract()),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
AtomicInteger sourceReads = new AtomicInteger();
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedGenerationHistoryStorage.restoreOrAdopt(
|
||||
dimensionRoot,
|
||||
124L,
|
||||
() -> {
|
||||
sourceReads.incrementAndGet();
|
||||
return new ModdedGenerationHistoryStorage.AdoptionSource(
|
||||
source,
|
||||
candidate(source, registryContract())
|
||||
);
|
||||
},
|
||||
ModdedGenerationHistoryStorageTest::union
|
||||
));
|
||||
assertEquals(0, sourceReads.get());
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreRejectsUnavailableRetainedRegistryDefinitions() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-registry");
|
||||
try {
|
||||
Path source = pack(root.resolve("global-pack"), "registry");
|
||||
Path dimensionRoot = root.resolve("world-dimension");
|
||||
ModdedGenerationHistoryStorage.createOrStage(
|
||||
dimensionRoot,
|
||||
source,
|
||||
12L,
|
||||
candidate(source, registryContract()),
|
||||
ModdedGenerationHistoryStorageTest::union,
|
||||
TRANSITION_WIDTH_BLOCKS
|
||||
);
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedGenerationHistoryStorage.restoreOrAdopt(
|
||||
dimensionRoot,
|
||||
12L,
|
||||
() -> {
|
||||
throw new AssertionError("Existing history consulted the global pack");
|
||||
},
|
||||
contracts -> GenerationRegistryContract.empty()
|
||||
));
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModdedGenerationHistoryStorage.Candidate candidate(
|
||||
Path source,
|
||||
GenerationRegistryContract registryContract
|
||||
) throws IOException {
|
||||
return new ModdedGenerationHistoryStorage.Candidate(
|
||||
GenerationPackFingerprint.compute(source, GenerationPackFingerprint.CURRENT_VERSION),
|
||||
dimensionContract(),
|
||||
registryContract
|
||||
);
|
||||
}
|
||||
|
||||
private static GenerationEpoch.DimensionContract dimensionContract() {
|
||||
return new GenerationEpoch.DimensionContract(
|
||||
"surface",
|
||||
"irisworldgen:packs/7061636b/dimensions/73757266616365/dimension_type",
|
||||
"NORMAL",
|
||||
"OVERWORLD",
|
||||
127,
|
||||
-64,
|
||||
384,
|
||||
384,
|
||||
1D,
|
||||
false,
|
||||
"none",
|
||||
0,
|
||||
"0".repeat(64),
|
||||
GenerationEpochContractFactory.CURRENT_DIMENSION_TYPE_FINGERPRINT_SCHEMA,
|
||||
DIMENSION_FINGERPRINT
|
||||
);
|
||||
}
|
||||
|
||||
private static GenerationRegistryContract registryContract() {
|
||||
return registryContract("minecraft:stone");
|
||||
}
|
||||
|
||||
private static GenerationRegistryContract registryContract(String resourceKey) {
|
||||
return GenerationRegistryContract.fromDefinitions(Map.of(
|
||||
new GenerationRegistryContract.PhysicalResourceKey(
|
||||
resourceKey.startsWith("iris:biomes/")
|
||||
? "minecraft:worldgen/biome"
|
||||
: "minecraft:block",
|
||||
resourceKey
|
||||
),
|
||||
DEFINITION_FINGERPRINT
|
||||
));
|
||||
}
|
||||
|
||||
private static GenerationRegistryContract union(Collection<GenerationRegistryContract> contracts)
|
||||
throws IOException {
|
||||
TreeMap<GenerationRegistryContract.PhysicalResourceKey, String> definitions = new TreeMap<>();
|
||||
for (GenerationRegistryContract contract : contracts) {
|
||||
for (Map.Entry<GenerationRegistryContract.PhysicalResourceKey, String> entry
|
||||
: contract.definitions().entrySet()) {
|
||||
String previous = definitions.putIfAbsent(entry.getKey(), entry.getValue());
|
||||
if (previous != null && !previous.equals(entry.getValue())) {
|
||||
throw new IOException("Conflicting registry definition");
|
||||
}
|
||||
}
|
||||
}
|
||||
return GenerationRegistryContract.fromDefinitions(definitions);
|
||||
}
|
||||
|
||||
private static Path pack(Path root, String content) throws IOException {
|
||||
Files.createDirectories(root);
|
||||
Files.writeString(root.resolve("content.txt"), content, StandardCharsets.UTF_8);
|
||||
return root;
|
||||
}
|
||||
|
||||
private static void deleteTree(Path root) throws IOException {
|
||||
if (!Files.exists(root)) {
|
||||
return;
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
for (Path path : walk.sorted(Comparator.reverseOrder()).toList()) {
|
||||
Files.deleteIfExists(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -26,7 +26,9 @@ public class ModdedGenerationLeaseContractTest {
|
||||
assertTrue(source.contains("catch (GenerationSessionException e)"));
|
||||
assertTrue(source.contains("e.isExpectedTeardown()"));
|
||||
assertTrue(source.contains("Iris structure biome key lookup was rejected during an engine transition"));
|
||||
assertTrue(source.contains("source.clearCache()"));
|
||||
assertTrue(source.contains("int runtimeIdentity = engine.getCacheID();"));
|
||||
assertTrue(source.contains("cache.get(runtimeIdentity, key)"));
|
||||
assertTrue(source.contains("cache.put(runtimeIdentity, key, resolved)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,7 +205,7 @@ public class ModdedGenerationLeaseContractTest {
|
||||
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
|
||||
String start = method(jobSource, "public static boolean start(");
|
||||
int taskConstruction = start.indexOf("PregenTask task = PregenTask.builder()");
|
||||
int profileMutation = start.indexOf("PregenPerformanceProfile.apply(engine);");
|
||||
int profileMutation = start.indexOf("PregenPerformanceProfile.apply(engine)");
|
||||
|
||||
assertTrue(taskConstruction >= 0);
|
||||
assertTrue(profileMutation > taskConstruction);
|
||||
|
||||
+36
-21
@@ -14,15 +14,16 @@ public class ModdedLifecycleFailureContractTest {
|
||||
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
|
||||
|
||||
@Test
|
||||
public void existingDimensionRepointBindsBeforeHandlePublication() throws IOException {
|
||||
public void existingDimensionStagesWithoutReplacingTheLiveEngine() throws IOException {
|
||||
String managerSource = source("ModdedDimensionManager.java");
|
||||
String create = method(managerSource, "public static Handle create(");
|
||||
String create = method(managerSource, "private static Handle create(");
|
||||
int existingStart = requiredIndex(create, "if (existing != null");
|
||||
int presentStart = requiredIndex(create, "if (serverAccess.hasLevel(server, key))", existingStart + 1);
|
||||
int injectionStart = requiredIndex(create, "try {", presentStart);
|
||||
|
||||
assertRepointBeforePublication(create.substring(existingStart, presentStart));
|
||||
assertRepointBeforePublication(create.substring(presentStart, injectionStart));
|
||||
assertFalse(create.substring(existingStart, presentStart).contains("repointAndBind("));
|
||||
assertFalse(create.substring(presentStart, injectionStart).contains("repointAndBind("));
|
||||
assertBefore(create, "ModdedGenerationHistoryStorage.createOrStage(", "if (existing != null");
|
||||
|
||||
String generatorSource = source("IrisModdedChunkGenerator.java");
|
||||
String repointAndBind = method(generatorSource, "void repointAndBind(");
|
||||
@@ -40,6 +41,31 @@ public class ModdedLifecycleFailureContractTest {
|
||||
assertFalse(installReplacement.contains("catch ("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistentPackUpdatesUseAnExplicitRestartBoundPath() throws IOException {
|
||||
String managerSource = source("ModdedDimensionManager.java");
|
||||
String createPersistent = method(managerSource, "public static Handle createPersistent(");
|
||||
String update = method(managerSource, "public static UpdateResult stagePersistentUpdate(");
|
||||
|
||||
assertBefore(createPersistent, "if (previous != null)", "ModdedDimensionRegistryStore.put(");
|
||||
assertTrue(createPersistent.contains("Use the Iris world update command"));
|
||||
assertTrue(update.contains("ModdedGenerationHistoryStorage.createOrStage("));
|
||||
assertTrue(update.contains("active.history().pendingActivation()"));
|
||||
assertTrue(update.contains("restartRequired()"));
|
||||
assertFalse(update.contains("inject("));
|
||||
assertFalse(update.contains("repointAndBind("));
|
||||
assertBefore(update, "ModdedDimensionRegistryStore.put(server, updated);",
|
||||
"ModdedGenerationHistoryStorage.createOrStage(");
|
||||
assertTrue(update.contains("ModdedDimensionRegistryStore.put(server, previous);"));
|
||||
|
||||
String commandsSource = source("command/ModdedWorldCommands.java");
|
||||
assertTrue(commandsSource.contains("root.then(updateTree());"));
|
||||
String command = method(commandsSource, "private static int update(");
|
||||
assertTrue(command.contains("ModdedDimensionManager.stagePersistentUpdate("));
|
||||
assertTrue(command.contains("Restart the server to activate it"));
|
||||
assertTrue(command.contains("running world remains on its current pack"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectionBindsBeforeRegistrationAndRollsBackEveryFailure() throws IOException {
|
||||
String source = source("ModdedDimensionManager.java");
|
||||
@@ -110,18 +136,13 @@ public class ModdedLifecycleFailureContractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packDimensionLoadingNeverSuppressesTheFailureAsNull() throws IOException {
|
||||
String source = source("ModdedDimensionManager.java");
|
||||
String loading = method(source, "private static IrisDimension loadPackDimension(");
|
||||
public void persistentRestoreOpensHistoryBeforeConsultingTheGlobalPack() throws IOException {
|
||||
String source = source("ModdedGenerationHistoryStorage.java");
|
||||
String restore = method(source, "static GenerationHistory restoreOrAdopt(");
|
||||
|
||||
assertFalse(loading.contains("return null;"));
|
||||
assertFalse(loading.contains("e.toString()"));
|
||||
int catchIndex = loading.indexOf("catch (");
|
||||
if (catchIndex >= 0) {
|
||||
String failure = blockAt(loading, requiredIndex(loading, "{", catchIndex));
|
||||
assertTrue(failure.contains("throw "));
|
||||
assertTrue(failure.contains(", e);") || failure.contains("throw e;"));
|
||||
}
|
||||
assertBefore(restore, "GenerationHistory.openIfPresent(", "sourceSupplier\").get();");
|
||||
assertTrue(restore.contains("if (existing.isPresent())"));
|
||||
assertBefore(restore, "requireRegistryDefinitions(existing.get()", "return existing.get();");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -249,12 +270,6 @@ public class ModdedLifecycleFailureContractTest {
|
||||
assertBefore(failure, "rollback.restore(failure);", "throw ");
|
||||
}
|
||||
|
||||
private static void assertRepointBeforePublication(String branch) {
|
||||
assertBefore(branch, "repointAndBind(", "new Handle(");
|
||||
assertBefore(branch, "repointAndBind(", "HANDLES.put(");
|
||||
assertBefore(branch, "repointAndBind(", "return ");
|
||||
}
|
||||
|
||||
private static void assertBefore(String source, String first, String second) {
|
||||
int firstIndex = requiredIndex(source, first);
|
||||
int secondIndex = requiredIndex(source, second);
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class ModdedRiverLocateContractTest {
|
||||
@Test
|
||||
public void riverLookupMergesRecordedAndEligibleActiveFeatures() throws IOException {
|
||||
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"))
|
||||
.resolve("art/arcane/iris/modded/command/ModdedLocateCommands.java");
|
||||
String source = Files.readString(sourcePath);
|
||||
int methodStart = source.indexOf("static int gotoRiver(");
|
||||
int methodEnd = source.indexOf("static int gotoStructure(", methodStart);
|
||||
String method = source.substring(methodStart, methodEnd);
|
||||
|
||||
assertTrue(method.contains("GenerationSemanticQueries.nearestRiver("));
|
||||
assertTrue(method.contains("runtime == null"));
|
||||
assertTrue(method.contains("feature.y() + 2"));
|
||||
assertFalse(method.contains("runtime.nearestFeature("));
|
||||
assertFalse(method.contains("feature.y() + engine.getDimension().getMinHeight()"));
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class ModdedStructureHistoryContractTest {
|
||||
@Test
|
||||
public void retainedStructureNamesReachTheSemanticSearchOnBothAdmissionBranches() throws IOException {
|
||||
Path root = Path.of(System.getProperty("iris.moddedCommonSources"));
|
||||
String source = Files.readString(root.resolve("art/arcane/iris/modded/command/ModdedLocateCommands.java"));
|
||||
int start = source.indexOf("static int gotoStructure(");
|
||||
int end = source.indexOf("static String registeredStructureUnavailableMessage(", start);
|
||||
String admission = source.substring(start, end);
|
||||
String retainedCheck = "GenerationFindCatalog.hasRetainedStructurePlacement(engine, key)";
|
||||
int firstCheck = admission.indexOf(retainedCheck);
|
||||
assertTrue(firstCheck >= 0);
|
||||
assertTrue(admission.indexOf(retainedCheck, firstCheck + retainedCheck.length()) >= 0);
|
||||
|
||||
int locateStart = source.indexOf("private static void locateIrisStructure(");
|
||||
int locateEnd = source.indexOf("private static void runNativeStructureLocate(", locateStart);
|
||||
String locate = source.substring(locateStart, locateEnd);
|
||||
assertTrue(locate.contains("GenerationSemanticQueries.nearestStructure("));
|
||||
assertFalse(locate.contains("IrisStructureLocator.locate("));
|
||||
|
||||
String suggestions = Files.readString(root.resolve("art/arcane/iris/modded/command/ModdedCommandSuggestions.java"));
|
||||
assertTrue(suggestions.contains("GenerationFindCatalog.retainedStructureKeys(engine)"));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -21,8 +21,8 @@ public class ModdedStudioTeleportContractTest {
|
||||
assertTrue(open.contains("TRANSITIONS.submit("));
|
||||
assertFalse(open.contains("orTimeout("));
|
||||
assertFalse(open.contains("deadlineNanos"));
|
||||
assertBefore(execute, "replaceExistingStudio(", "ModdedDimensionManager.create(");
|
||||
assertBefore(execute, "ModdedDimensionManager.create(", "ModdedDimensionManager.teleportAsync(");
|
||||
assertBefore(execute, "replaceExistingStudio(", "ModdedDimensionManager.createTransientStudio(");
|
||||
assertBefore(execute, "ModdedDimensionManager.createTransientStudio(", "ModdedDimensionManager.teleportAsync(");
|
||||
assertFalse(execute.contains("deadlineNanos"));
|
||||
assertFalse(source.contains("player.teleportTo(studio"));
|
||||
}
|
||||
|
||||
+9
@@ -8,6 +8,7 @@ import art.arcane.iris.engine.framework.NativeStructureOwnershipBundle;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipRecord;
|
||||
import art.arcane.iris.engine.framework.NativeStructureOwnershipStore;
|
||||
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
|
||||
import art.arcane.iris.engine.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.engine.object.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.IrisNativeStructureDecision;
|
||||
@@ -429,6 +430,14 @@ public class NativeStructureReferenceRepairTest {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationHistoryRuntimeRouter.CoordinateScope openGenerationHistoryCoordinateScope(
|
||||
int blockX,
|
||||
int blockZ
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosing() {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user