mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Added dimension takeover
- IrisDimension borrowedDimensionType reuses an existing registered dimension type instead of generating one - Pack validation rejects borrowedDimensionType values that are not namespaced registry keys - Generation contracts record the borrowed type key and capture it as an external registry definition - Borrowed types bind when the pack min equals the type min_y and the pack top fits, with both ranges in the refusal - Studio hotload rejects borrowed type changes and the world check validates borrowed ranges - Forced datapack skips generated types and presets for borrowed dimensions and accepts retained borrowed epochs - modded.json dimensionTakeovers writes a LevelStem per level key using the irisworldgen:iris generator - Takeover changes quarantine the level chunk, entity, POI, and Iris data before load and track applied state per world - Fresh levels adopt generation history with content-addressed biomes instead of legacy aliases - /iris world takeover <dimension> <pack[:dimension]|off> with help and translations in every locale
This commit is contained in:
1 parent
8afb445b1d
commit
5633eec009
52 files changed
+1365
-95
No files matched your search
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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 ModdedDimensionTakeoversTest {
|
||||
@Test
|
||||
public void parsesPackAndPackDimensionReferences() {
|
||||
ModdedDimensionTakeover samePack = ModdedDimensionTakeover.parse("iristest:skylands", "skypack");
|
||||
ModdedDimensionTakeover scoped = ModdedDimensionTakeover.parse("aether:the_aether", "overworld:floating/sky");
|
||||
|
||||
assertEquals("skypack", samePack.pack());
|
||||
assertEquals("skypack", samePack.packDimension());
|
||||
assertEquals("skypack", samePack.packRef());
|
||||
assertEquals("overworld", scoped.pack());
|
||||
assertEquals("floating/sky", scoped.packDimension());
|
||||
assertEquals("overworld:floating/sky", scoped.packRef());
|
||||
assertEquals("aether", scoped.namespace());
|
||||
assertEquals("the_aether", scoped.path());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidLevelKeysAndPackReferences() {
|
||||
for (String levelKey : List.of("skylands", "Iristest:skylands", "iristest:", ":skylands", "iristest:sky/../x", "iristest:/sky")) {
|
||||
assertThrows(levelKey, IllegalArgumentException.class, () -> ModdedDimensionTakeover.parse(levelKey, "overworld"));
|
||||
}
|
||||
for (String packRef : List.of("", " ", "../overworld", "overworld:", "over world", "overworld:a/../b")) {
|
||||
assertThrows(packRef, IllegalArgumentException.class, () -> ModdedDimensionTakeover.parse("iristest:skylands", packRef));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelStoragePathFollowsTheDimensionsLayout() {
|
||||
Path worldRoot = Path.of("/srv/world");
|
||||
|
||||
assertEquals(worldRoot.resolve("dimensions").resolve("iristest").resolve("skylands"),
|
||||
ModdedDimensionTakeover.parse("iristest:skylands", "overworld").storageFolder(worldRoot));
|
||||
assertEquals(worldRoot.resolve("dimensions").resolve("aether").resolve("realm").resolve("upper"),
|
||||
ModdedDimensionTakeover.parse("aether:realm/upper", "overworld").storageFolder(worldRoot));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelStemUsesTheIrisGeneratorWithThePresetBiomeSourcePlaceholder() {
|
||||
ModdedDimensionTakeover takeover = ModdedDimensionTakeover.parse("iristest:skylands", "overworld:sky");
|
||||
|
||||
JSONObject stem = new JSONObject(ModdedDimensionTakeovers.levelStemJson("iristest:skylands", takeover));
|
||||
|
||||
assertEquals("iristest:skylands", stem.getString("type"));
|
||||
JSONObject generator = stem.getJSONObject("generator");
|
||||
assertEquals("irisworldgen:iris", generator.getString("type"));
|
||||
assertEquals("overworld:sky", generator.getString("dimension"));
|
||||
assertEquals("minecraft:fixed", generator.getJSONObject("biome_source").getString("type"));
|
||||
assertEquals("minecraft:plains", generator.getJSONObject("biome_source").getString("biome"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelStemIsWrittenAtTheDatapackDimensionPathOfTheLevelKey() throws IOException {
|
||||
Path datapack = Files.createTempDirectory("iris-takeover-stem");
|
||||
try {
|
||||
ModdedDimensionTakeover takeover = ModdedDimensionTakeover.parse("aether:the_aether", "overworld");
|
||||
|
||||
Path written = ModdedDimensionTakeovers.writeLevelStem(datapack, takeover, "aether:the_aether");
|
||||
|
||||
assertEquals(datapack.resolve("data").resolve("aether").resolve("dimension").resolve("the_aether.json"), written);
|
||||
assertEquals("aether:the_aether", new JSONObject(Files.readString(written)).getString("type"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(datapack);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedLevelsCoverAddedChangedAndRemovedTakeovers() {
|
||||
Map<String, String> applied = Map.of(
|
||||
"iristest:kept", "overworld",
|
||||
"iristest:changed", "overworld",
|
||||
"iristest:removed", "overworld");
|
||||
Map<String, String> configured = Map.of(
|
||||
"iristest:kept", "overworld",
|
||||
"iristest:changed", "overworld:sky",
|
||||
"iristest:added", "overworld");
|
||||
|
||||
assertEquals(Set.of("iristest:changed", "iristest:removed", "iristest:added"),
|
||||
ModdedDimensionTakeovers.changedLevels(applied, configured));
|
||||
assertEquals(Set.of(), ModdedDimensionTakeovers.changedLevels(configured, configured));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fingerprintIsOrderIndependentAndTracksEveryEntry() {
|
||||
Map<String, String> forward = new LinkedHashMap<>();
|
||||
forward.put("iristest:a", "overworld");
|
||||
forward.put("iristest:b", "overworld:sky");
|
||||
Map<String, String> reversed = new LinkedHashMap<>();
|
||||
reversed.put("iristest:b", "overworld:sky");
|
||||
reversed.put("iristest:a", "overworld");
|
||||
|
||||
assertEquals(ModdedDimensionTakeovers.fingerprint(forward), ModdedDimensionTakeovers.fingerprint(reversed));
|
||||
assertNotEquals(ModdedDimensionTakeovers.fingerprint(forward),
|
||||
ModdedDimensionTakeovers.fingerprint(Map.of("iristest:a", "overworld")));
|
||||
assertEquals("", ModdedDimensionTakeovers.fingerprint(Map.of()));
|
||||
assertTrue(ModdedDimensionTakeovers.fingerprint(forward).contains("iristest:b=overworld:sky"));
|
||||
}
|
||||
}
|
||||
+23
@@ -5,6 +5,7 @@ import art.arcane.iris.world.history.GenerationEpochContractFactory;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationPackFingerprint;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContract;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContractFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -28,6 +29,28 @@ public class ModdedGenerationHistoryStorageTest {
|
||||
private static final String DEFINITION_FINGERPRINT = "22".repeat(32);
|
||||
private static final int TRANSITION_WIDTH_BLOCKS = 256;
|
||||
|
||||
@Test
|
||||
public void adoptionRetainsLegacyBiomeAliasesOnlyWhenTheLevelAlreadyHasChunks() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-alias-policy");
|
||||
try {
|
||||
Path fresh = root.resolve("fresh");
|
||||
Path emptyRegion = root.resolve("empty-region");
|
||||
Files.createDirectories(emptyRegion.resolve("region"));
|
||||
Path legacy = root.resolve("legacy");
|
||||
Files.createDirectories(legacy.resolve("region"));
|
||||
Files.writeString(legacy.resolve("region").resolve("r.0.0.mca"), "chunk", StandardCharsets.UTF_8);
|
||||
|
||||
assertEquals(GenerationRegistryContractFactory.CustomBiomeAliasPolicy.CONTENT_ADDRESSED_ONLY,
|
||||
ModdedGenerationHistoryStorage.adoptionAliasPolicy(fresh));
|
||||
assertEquals(GenerationRegistryContractFactory.CustomBiomeAliasPolicy.CONTENT_ADDRESSED_ONLY,
|
||||
ModdedGenerationHistoryStorage.adoptionAliasPolicy(emptyRegion));
|
||||
assertEquals(GenerationRegistryContractFactory.CustomBiomeAliasPolicy.RETAIN_LEGACY_ALIASES,
|
||||
ModdedGenerationHistoryStorage.adoptionAliasPolicy(legacy));
|
||||
} finally {
|
||||
deleteTree(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newDimensionPublishesAnImmutableWorldLocalPack() throws IOException {
|
||||
Path root = Files.createTempDirectory("iris-modded-history-create");
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
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.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedTakeoverReconcilerTest {
|
||||
@Test
|
||||
public void appliedStateRoundTripsAndDefaultsToEmpty() throws IOException {
|
||||
Path worldRoot = Files.createTempDirectory("iris-takeover-state");
|
||||
try {
|
||||
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld:sky"));
|
||||
|
||||
assertEquals(Map.of("iristest:skylands", "overworld:sky"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(worldRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newTakeoverQuarantinesOnlyThatLevelsChunkDataAndKeepsPlayerData() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-reconcile");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
for (String folder : List.of("region", "entities", "poi", "mantle-hydrology", "iris", "data")) {
|
||||
touch(skylands.resolve(folder).resolve("payload.bin"));
|
||||
}
|
||||
touch(worldRoot.resolve("dimensions/minecraft/overworld/region/r.0.0.mca"));
|
||||
touch(worldRoot.resolve("players/data/player.dat"));
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.changedLevels());
|
||||
for (String folder : List.of("region", "entities", "poi", "mantle-hydrology", "iris")) {
|
||||
assertFalse(folder, Files.exists(skylands.resolve(folder)));
|
||||
assertTrue(folder, Files.isRegularFile(result.recovery()
|
||||
.resolve("dimensions/iristest/skylands").resolve(folder).resolve("payload.bin")));
|
||||
}
|
||||
assertTrue(Files.isRegularFile(skylands.resolve("data/payload.bin")));
|
||||
assertTrue(Files.isRegularFile(worldRoot.resolve("dimensions/minecraft/overworld/region/r.0.0.mca")));
|
||||
assertTrue(Files.isRegularFile(worldRoot.resolve("players/data/player.dat")));
|
||||
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unchangedTakeoverIsANoOpAndRemovalQuarantinesTheIrisChunks() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-cycle");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
|
||||
touch(region);
|
||||
|
||||
ModdedTakeoverReconciler.Result unchanged = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), recoveryParent);
|
||||
|
||||
assertEquals(Set.of(), unchanged.changedLevels());
|
||||
assertNull(unchanged.recovery());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
|
||||
ModdedTakeoverReconciler.Result removed = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), removed.changedLevels());
|
||||
assertFalse(Files.exists(region));
|
||||
assertTrue(Files.isRegularFile(removed.recovery().resolve("dimensions/iristest/skylands/region/r.0.0.mca")));
|
||||
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeWithoutChunkDataRecordsStateWithoutARecoveryFolder() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-empty");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
worldRoot, Map.of("aether:the_aether", "overworld"), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), result.changedLevels());
|
||||
assertNull(result.recovery());
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Map.of("aether:the_aether", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
private static void touch(Path file) throws IOException {
|
||||
Files.createDirectories(file.getParent());
|
||||
Files.writeString(file, "x", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -19,6 +20,19 @@ public class ModdedWorldgenIdsTest {
|
||||
ModdedWorldgenIds.dimensionTypeRef("Pack/A-_", "É山")).orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedDimensionTypeReplacesTheScopedGeneratedType() {
|
||||
IrisDimension generated = new IrisDimension();
|
||||
generated.setLoadKey("sky");
|
||||
IrisDimension borrowed = new IrisDimension().setBorrowedDimensionType("iristest:skylands");
|
||||
borrowed.setLoadKey("sky");
|
||||
|
||||
assertEquals(ModdedWorldgenIds.dimensionTypeRef("overworld", "sky"),
|
||||
ModdedWorldgenIds.dimensionTypeRef("overworld", generated));
|
||||
assertEquals("iristest:skylands", ModdedWorldgenIds.dimensionTypeRef("overworld", borrowed));
|
||||
assertTrue(ModdedWorldgenIds.scopedDimensionType("iristest:skylands").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void malformedIdentifiersRetainRejectionBehavior() {
|
||||
assertTrue(ModdedWorldgenIds.scopedDimensionType(
|
||||
|
||||
+1
@@ -173,6 +173,7 @@ public class IrisModdedCommandParityTest {
|
||||
assertTrue(ModdedCommandHelp.documents("studio", "pkg"));
|
||||
assertTrue(ModdedCommandHelp.documents("object", "we"));
|
||||
assertTrue(ModdedCommandHelp.documents("world", "mainworld"));
|
||||
assertTrue(ModdedCommandHelp.documents("world", "takeover"));
|
||||
assertTrue(ModdedCommandHelp.documents("goto", "unregistered"));
|
||||
assertTrue(ModdedCommandHelp.documents("pack", "compat"));
|
||||
assertTrue(ModdedCommandHelp.documents("pack", "cp"));
|
||||
|
||||
Reference in new issue
Block a user