mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Unified modded world replace
- Added /iris replace with override and overwrite aliases on Fabric, Forge, and NeoForge using the Paper target, type, and seed arguments - Resolved main, nether, end, level-name aliases, iris: and bare names, and any loaded mod dimension as replacement targets - Kept the saved seed when seed is omitted and stored explicit seeds per replaced dimension - Applied replaced vanilla and mod dimensions through the forced datapack level stem with the configured seed bound at engine creation - Applied staged Iris world replacements at startup by moving their terrain aside and repointing the dimension registry - Refused a second staging while a replacement is pending and checked pack environments for vanilla slots - Added the modded-only off form to cancel a staged replacement or return a replaced dimension to its own generator - Reset the Overworld spawn and moved returning players out of unsafe positions after an Overworld replacement - Renamed the takeover reconciler, model, config key, state file, and recovery folder to replacement names - Removed /iris world takeover and its help entry and localized messages
This commit is contained in:
1 parent
0ca33068f3
commit
a7cf2cac9a
46 files changed
+2663
-1454
No files matched your search
+290
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* 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.OptionalLong;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedDimensionReplacementsTest {
|
||||
@Test
|
||||
public void parsesPackAndPackDimensionReferences() {
|
||||
ModdedDimensionReplacement samePack = replacement("iristest:skylands", "skypack");
|
||||
ModdedDimensionReplacement scoped = ModdedDimensionReplacement.parse("aether:the_aether", "overworld:floating/sky",
|
||||
OptionalLong.of(42L));
|
||||
|
||||
assertEquals("skypack", samePack.pack());
|
||||
assertEquals("skypack", samePack.packDimension());
|
||||
assertEquals("skypack", samePack.packRef());
|
||||
assertEquals(OptionalLong.empty(), samePack.seed());
|
||||
assertEquals("overworld", scoped.pack());
|
||||
assertEquals("floating/sky", scoped.packDimension());
|
||||
assertEquals("overworld:floating/sky", scoped.packRef());
|
||||
assertEquals(OptionalLong.of(42L), scoped.seed());
|
||||
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, () -> replacement(levelKey, "overworld"));
|
||||
}
|
||||
for (String packRef : List.of("", " ", "../overworld", "overworld:", "over world", "overworld:a/../b")) {
|
||||
assertThrows(packRef, IllegalArgumentException.class, () -> replacement("iristest:skylands", packRef));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonRoundTripsTheTypeAndOptionalSeed() {
|
||||
ModdedDimensionReplacement seeded = ModdedDimensionReplacement.parse("minecraft:overworld", "overworld",
|
||||
OptionalLong.of(-7L));
|
||||
ModdedDimensionReplacement unseeded = replacement("examplemod:skylands", "skypack:sky");
|
||||
|
||||
assertEquals("overworld", seeded.toJson().getString("type"));
|
||||
assertEquals(-7L, seeded.toJson().getLong("seed"));
|
||||
assertFalse(unseeded.toJson().has("seed"));
|
||||
assertEquals(seeded, ModdedDimensionReplacement.fromJson("minecraft:overworld", seeded.toJson()));
|
||||
assertEquals(unseeded, ModdedDimensionReplacement.fromJson("examplemod:skylands", unseeded.toJson()));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedDimensionReplacement.fromJson("examplemod:skylands", "skypack"));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedDimensionReplacement.fromJson("examplemod:skylands", new JSONObject("{\"seed\": 1}")));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedDimensionReplacement.fromJson("examplemod:skylands",
|
||||
new JSONObject("{\"type\": \"skypack\", \"seed\": \"abc\"}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelStoragePathFollowsTheDimensionsLayout() {
|
||||
Path worldRoot = Path.of("/srv/world");
|
||||
|
||||
assertEquals(worldRoot.resolve("dimensions").resolve("iristest").resolve("skylands"),
|
||||
replacement("iristest:skylands", "overworld").storageFolder(worldRoot));
|
||||
assertEquals(worldRoot.resolve("dimensions").resolve("aether").resolve("realm").resolve("upper"),
|
||||
replacement("aether:realm/upper", "overworld").storageFolder(worldRoot));
|
||||
assertEquals(worldRoot.resolve("dimensions").resolve("minecraft").resolve("overworld"),
|
||||
ModdedDimensionReplacement.storageFolder(worldRoot, "minecraft:overworld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levelStemUsesTheIrisGeneratorWithThePresetBiomeSourcePlaceholder() {
|
||||
JSONObject stem = new JSONObject(ModdedDimensionReplacements.levelStemJson("iristest:skylands",
|
||||
replacement("iristest:skylands", "overworld:sky")));
|
||||
|
||||
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-replace-stem");
|
||||
try {
|
||||
Path written = ModdedDimensionReplacements.writeLevelStem(datapack,
|
||||
replacement("aether:the_aether", "overworld"), "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 {
|
||||
ModdedReplacementReconcilerTest.deleteTree(datapack);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedLevelsCoverAddedChangedReseededAndRemovedReplacements() {
|
||||
Map<String, ModdedDimensionReplacement> applied = Map.of(
|
||||
"iristest:kept", seeded("iristest:kept", "overworld", 5L),
|
||||
"iristest:unseeded", seeded("iristest:unseeded", "overworld", 5L),
|
||||
"iristest:changed", seeded("iristest:changed", "overworld", 5L),
|
||||
"iristest:reseeded", seeded("iristest:reseeded", "overworld", 5L),
|
||||
"iristest:removed", seeded("iristest:removed", "overworld", 5L));
|
||||
Map<String, ModdedDimensionReplacement> configured = Map.of(
|
||||
"iristest:kept", seeded("iristest:kept", "overworld", 5L),
|
||||
"iristest:unseeded", replacement("iristest:unseeded", "overworld"),
|
||||
"iristest:changed", seeded("iristest:changed", "overworld:sky", 5L),
|
||||
"iristest:reseeded", seeded("iristest:reseeded", "overworld", 6L),
|
||||
"iristest:added", replacement("iristest:added", "overworld"));
|
||||
|
||||
assertEquals(Set.of("iristest:changed", "iristest:reseeded", "iristest:removed", "iristest:added"),
|
||||
ModdedDimensionReplacements.changedLevels(applied, configured));
|
||||
assertEquals(Set.of(), ModdedDimensionReplacements.changedLevels(applied, applied));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fingerprintIsOrderIndependentAndTracksEveryLevelStem() {
|
||||
Map<String, ModdedDimensionReplacement> forward = new LinkedHashMap<>();
|
||||
forward.put("iristest:a", replacement("iristest:a", "overworld"));
|
||||
forward.put("iristest:b", seeded("iristest:b", "overworld:sky", 9L));
|
||||
Map<String, ModdedDimensionReplacement> reversed = new LinkedHashMap<>();
|
||||
reversed.put("iristest:b", seeded("iristest:b", "overworld:sky", 9L));
|
||||
reversed.put("iristest:a", replacement("iristest:a", "overworld"));
|
||||
|
||||
assertEquals(ModdedDimensionReplacements.fingerprint(forward), ModdedDimensionReplacements.fingerprint(reversed));
|
||||
assertNotEquals(ModdedDimensionReplacements.fingerprint(forward),
|
||||
ModdedDimensionReplacements.fingerprint(Map.of("iristest:a", replacement("iristest:a", "overworld"))));
|
||||
assertEquals("", ModdedDimensionReplacements.fingerprint(Map.of()));
|
||||
assertTrue(ModdedDimensionReplacements.fingerprint(forward).contains("iristest:b=overworld:sky"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void installedPackTypeIsStagedForTheReplacement() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-stage-installed");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
ModdedDimensionReplacements.StagedTypes staged = ModdedDimensionReplacements.StagedTypes.create();
|
||||
staged.installed().put("skypack:sky", "irisworldgen:packs/x/dimensions/y/dimension_type");
|
||||
|
||||
ModdedDimensionReplacements.writeLevelStems(datapack,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky")), staged,
|
||||
temporary.resolve("world"));
|
||||
|
||||
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
assertEquals("irisworldgen:packs/x/dimensions/y/dimension_type", stem.getString("type"));
|
||||
assertEquals("skypack:sky", stem.getJSONObject("generator").getString("dimension"));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainedHistoryOfTheLevelStagesTheReplacementWithoutTheInstalledPack() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-stage-retained");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
ModdedDimensionReplacements.StagedTypes staged = ModdedDimensionReplacements.StagedTypes.create();
|
||||
staged.retained().put(worldRoot.resolve("dimensions/aether/the_aether").toAbsolutePath().normalize(),
|
||||
"aether:the_aether");
|
||||
|
||||
ModdedDimensionReplacements.writeLevelStems(datapack,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky")), staged, worldRoot);
|
||||
|
||||
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
assertEquals("aether:the_aether", stem.getString("type"));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableReplacementWithoutAnyRecordIsSkipped() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-stage-skip");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Files.createDirectories(worldRoot);
|
||||
Map<String, ModdedDimensionReplacement> configured =
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky"));
|
||||
|
||||
ModdedDimensionReplacements.writeLevelStems(datapack, configured,
|
||||
ModdedDimensionReplacements.StagedTypes.create(), worldRoot);
|
||||
ModdedDimensionReplacements.writeLevelStems(datapack, configured,
|
||||
ModdedDimensionReplacements.StagedTypes.create(), null);
|
||||
|
||||
assertFalse(Files.exists(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableReplacementOfAnAppliedLevelRefusesStaging() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-stage-applied");
|
||||
try {
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
ModdedReplacementReconciler.writeState(worldRoot, new ModdedReplacementReconciler.State(
|
||||
Map.of("aether:the_aether", seeded("aether:the_aether", "skypack:sky", 5L)), Map.of()));
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> ModdedDimensionReplacements.writeLevelStems(
|
||||
temporary.resolve("datapack"),
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky")),
|
||||
ModdedDimensionReplacements.StagedTypes.create(), worldRoot));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("aether:the_aether"));
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("skypack"));
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("dimensionReplacements"));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableReplacementOfALevelWithIrisHistoryRefusesStaging() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-stage-history");
|
||||
try {
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Files.createDirectories(worldRoot.resolve("dimensions/aether/the_aether/iris/generation"));
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedDimensionReplacements.writeLevelStems(
|
||||
temporary.resolve("datapack"),
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky")),
|
||||
ModdedDimensionReplacements.StagedTypes.create(), worldRoot));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canonicalReplacementFollowsTheInstalledPackFolderCaseAndKeepsTheSeed() throws IOException {
|
||||
Path packsRoot = Files.createTempDirectory("iris-replace-canonical");
|
||||
try {
|
||||
Files.createDirectories(packsRoot.resolve("skypack/dimensions"));
|
||||
Files.writeString(packsRoot.resolve("skypack/dimensions/sky.json"), "{}");
|
||||
boolean caseInsensitive = Files.isDirectory(packsRoot.resolve("SKYPACK"));
|
||||
|
||||
Map<String, ModdedDimensionReplacement> canonical = ModdedDimensionReplacements.canonical(Map.of(
|
||||
"aether:the_aether", seeded("aether:the_aether", "SkyPack:Sky", 3L),
|
||||
"aether:other", replacement("aether:other", "missing:sky")), packsRoot);
|
||||
|
||||
assertEquals(caseInsensitive ? "skypack:sky" : "SkyPack:Sky", canonical.get("aether:the_aether").packRef());
|
||||
assertEquals(OptionalLong.of(3L), canonical.get("aether:the_aether").seed());
|
||||
assertEquals("missing:sky", canonical.get("aether:other").packRef());
|
||||
assertTrue(ModdedDimensionReplacements.installed(replacement("aether:the_aether", "skypack:sky"), packsRoot));
|
||||
assertFalse(ModdedDimensionReplacements.installed(replacement("aether:the_aether", "skypack:void"), packsRoot));
|
||||
} finally {
|
||||
ModdedReplacementReconcilerTest.deleteTree(packsRoot);
|
||||
}
|
||||
}
|
||||
|
||||
static ModdedDimensionReplacement replacement(String levelKey, String type) {
|
||||
return ModdedDimensionReplacement.parse(levelKey, type, OptionalLong.empty());
|
||||
}
|
||||
|
||||
static ModdedDimensionReplacement seeded(String levelKey, String type, long seed) {
|
||||
return ModdedDimensionReplacement.parse(levelKey, type, OptionalLong.of(seed));
|
||||
}
|
||||
}
|
||||
-246
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* 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.assertFalse;
|
||||
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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void installedPackTypeIsStagedForTheTakeover() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-stage-installed");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
ModdedDimensionTakeovers.StagedTypes staged = ModdedDimensionTakeovers.StagedTypes.create();
|
||||
staged.installed().put("skypack:sky", "irisworldgen:packs/x/dimensions/y/dimension_type");
|
||||
|
||||
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"), staged,
|
||||
temporary.resolve("world"));
|
||||
|
||||
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
assertEquals("irisworldgen:packs/x/dimensions/y/dimension_type", stem.getString("type"));
|
||||
assertEquals("skypack:sky", stem.getJSONObject("generator").getString("dimension"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainedHistoryOfTheLevelStagesTheTakeoverWithoutTheInstalledPack() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-stage-retained");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
ModdedDimensionTakeovers.StagedTypes staged = ModdedDimensionTakeovers.StagedTypes.create();
|
||||
staged.retained().put(worldRoot.resolve("dimensions/aether/the_aether").toAbsolutePath().normalize(),
|
||||
"aether:the_aether");
|
||||
|
||||
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"), staged, worldRoot);
|
||||
|
||||
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
assertEquals("aether:the_aether", stem.getString("type"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableTakeoverWithoutAnyRecordIsSkipped() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-stage-skip");
|
||||
try {
|
||||
Path datapack = temporary.resolve("datapack");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"),
|
||||
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot);
|
||||
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"),
|
||||
ModdedDimensionTakeovers.StagedTypes.create(), null);
|
||||
|
||||
assertFalse(Files.exists(datapack.resolve("data/aether/dimension/the_aether.json")));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableTakeoverOfAnAppliedLevelRefusesStaging() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-stage-applied");
|
||||
try {
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("aether:the_aether", "skypack:sky"));
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> ModdedDimensionTakeovers.writeLevelStems(
|
||||
temporary.resolve("datapack"), Map.of("aether:the_aether", "skypack:sky"),
|
||||
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("aether:the_aether"));
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("skypack"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstageableTakeoverOfALevelWithIrisHistoryRefusesStaging() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-stage-history");
|
||||
try {
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Files.createDirectories(worldRoot.resolve("dimensions/aether/the_aether/iris/generation"));
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedDimensionTakeovers.writeLevelStems(
|
||||
temporary.resolve("datapack"), Map.of("aether:the_aether", "skypack:sky"),
|
||||
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canonicalTakeoverFollowsTheInstalledPackFolderCase() throws IOException {
|
||||
Path packsRoot = Files.createTempDirectory("iris-takeover-canonical");
|
||||
try {
|
||||
Files.createDirectories(packsRoot.resolve("skypack/dimensions"));
|
||||
Files.writeString(packsRoot.resolve("skypack/dimensions/sky.json"), "{}");
|
||||
boolean caseInsensitive = Files.isDirectory(packsRoot.resolve("SKYPACK"));
|
||||
|
||||
Map<String, String> canonical = ModdedDimensionTakeovers.canonical(
|
||||
Map.of("aether:the_aether", "SkyPack:Sky", "aether:other", "missing:sky"), packsRoot);
|
||||
|
||||
assertEquals(caseInsensitive ? "skypack:sky" : "SkyPack:Sky", canonical.get("aether:the_aether"));
|
||||
assertEquals("missing:sky", canonical.get("aether:other"));
|
||||
assertEquals("skypack:sky", ModdedDimensionTakeovers.canonical(
|
||||
Map.of("aether:the_aether", "skypack:sky"), packsRoot).get("aether:the_aether"));
|
||||
assertTrue(ModdedDimensionTakeovers.installed(ModdedDimensionTakeover.parse("aether:the_aether", "skypack:sky"), packsRoot));
|
||||
assertFalse(ModdedDimensionTakeovers.installed(ModdedDimensionTakeover.parse("aether:the_aether", "skypack:void"), packsRoot));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(packsRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
-23
@@ -26,64 +26,72 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedModConfigTest {
|
||||
@Test
|
||||
public void validTakeoversLoadWithoutProblems() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": \"overworld:sky\"}}");
|
||||
public void validReplacementsLoadWithoutProblems() throws IOException {
|
||||
Path file = config("{\"dimensionReplacements\": {\"aether:the_aether\": {\"type\": \"overworld:sky\"},"
|
||||
+ " \"minecraft:overworld\": {\"type\": \"overworld\", \"seed\": -42}}}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of("aether:the_aether", "overworld:sky"), config.dimensionTakeovers());
|
||||
assertEquals(List.of(), config.takeoverProblems());
|
||||
assertEquals(Map.of(
|
||||
"aether:the_aether", ModdedDimensionReplacement.parse("aether:the_aether", "overworld:sky", OptionalLong.empty()),
|
||||
"minecraft:overworld", ModdedDimensionReplacement.parse("minecraft:overworld", "overworld", OptionalLong.of(-42L))),
|
||||
config.dimensionReplacements());
|
||||
assertEquals(List.of(), config.replacementProblems());
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
ModdedReplacementReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unparseableConfigReportsAProblemNamingTheFile() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": ");
|
||||
Path file = config("{\"dimensionReplacements\": {\"aether:the_aether\": ");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of(), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains(file.toString()));
|
||||
assertEquals(Map.of(), config.dimensionReplacements());
|
||||
assertEquals(1, config.replacementProblems().size());
|
||||
assertTrue(config.replacementProblems().getFirst(), config.replacementProblems().getFirst().contains(file.toString()));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
ModdedReplacementReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidTakeoverEntryIsReportedInsteadOfSilentlyDropped() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": {\"aether:the_aether\": \"overworld\", \"Broken Key\": \"overworld\"}}");
|
||||
public void invalidReplacementEntriesAreReportedInsteadOfSilentlyDropped() throws IOException {
|
||||
Path file = config("{\"dimensionReplacements\": {\"aether:the_aether\": {\"type\": \"overworld\"},"
|
||||
+ " \"Broken Key\": {\"type\": \"overworld\"}, \"aether:plain\": \"overworld\"}}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of("aether:the_aether", "overworld"), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains("Broken Key"));
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains(file.toString()));
|
||||
assertEquals(Map.of("aether:the_aether", ModdedDimensionReplacement.parse("aether:the_aether", "overworld",
|
||||
OptionalLong.empty())), config.dimensionReplacements());
|
||||
assertEquals(2, config.replacementProblems().size());
|
||||
assertTrue(config.replacementProblems().toString(), config.replacementProblems().get(0).contains("Broken Key"));
|
||||
assertTrue(config.replacementProblems().toString(), config.replacementProblems().get(1).contains("aether:plain"));
|
||||
assertTrue(config.replacementProblems().getFirst(), config.replacementProblems().getFirst().contains(file.toString()));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
ModdedReplacementReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void takeoverSectionThatIsNotAnObjectIsReported() throws IOException {
|
||||
Path file = config("{\"dimensionTakeovers\": [\"aether:the_aether\"]}");
|
||||
public void replacementSectionThatIsNotAnObjectIsReported() throws IOException {
|
||||
Path file = config("{\"dimensionReplacements\": [\"aether:the_aether\"]}");
|
||||
try {
|
||||
ModdedModConfig config = ModdedModConfig.read(file);
|
||||
|
||||
assertEquals(Map.of(), config.dimensionTakeovers());
|
||||
assertEquals(1, config.takeoverProblems().size());
|
||||
assertTrue(config.takeoverProblems().getFirst(), config.takeoverProblems().getFirst().contains("dimensionTakeovers"));
|
||||
assertEquals(Map.of(), config.dimensionReplacements());
|
||||
assertEquals(1, config.replacementProblems().size());
|
||||
assertTrue(config.replacementProblems().getFirst(), config.replacementProblems().getFirst().contains("dimensionReplacements"));
|
||||
} finally {
|
||||
ModdedTakeoverReconcilerTest.deleteTree(file.getParent());
|
||||
ModdedReplacementReconcilerTest.deleteTree(file.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+584
@@ -0,0 +1,584 @@
|
||||
/*
|
||||
* 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.iris.world.history.GenerationEpoch;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationPackFingerprint;
|
||||
import art.arcane.iris.world.lifecycle.WorldReplacementEntryGuard;
|
||||
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.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static art.arcane.iris.modded.ModdedDimensionReplacementsTest.replacement;
|
||||
import static art.arcane.iris.modded.ModdedDimensionReplacementsTest.seeded;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedReplacementReconcilerTest {
|
||||
@Test
|
||||
public void stateRoundTripsAppliedAndPendingEntriesAndDefaultsToEmpty() throws IOException {
|
||||
Path worldRoot = Files.createTempDirectory("iris-replace-state");
|
||||
try {
|
||||
assertEquals(ModdedReplacementReconciler.State.EMPTY, ModdedReplacementReconciler.readState(worldRoot));
|
||||
|
||||
ModdedReplacementReconciler.State state = new ModdedReplacementReconciler.State(
|
||||
Map.of("iristest:skylands", seeded("iristest:skylands", "overworld:sky", 5L)),
|
||||
Map.of("irisworldgen:myworld", seeded("irisworldgen:myworld", "underworld", 9L)));
|
||||
ModdedReplacementReconciler.writeState(worldRoot, state);
|
||||
|
||||
assertEquals(state, ModdedReplacementReconciler.readState(worldRoot));
|
||||
assertTrue(Files.isRegularFile(worldRoot.resolve("data/irisworldgen/dimension-replacements.json")));
|
||||
} finally {
|
||||
deleteTree(worldRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newReplacementQuarantinesOnlyThatLevelsChunkDataAndKeepsPlayerData() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-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"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", replacement("iristest:skylands", "overworld")), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
assertTrue(result.recovery().getFileName().toString().startsWith("replacement-recovery-"));
|
||||
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")));
|
||||
assertTrue(WorldReplacementEntryGuard.load(skylands).isEmpty());
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overworldReplacementGuardsEveryKnownPlayerUntilTheyEnterSafely() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-overworld");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
UUID player = UUID.randomUUID();
|
||||
Path overworld = worldRoot.resolve("dimensions/minecraft/overworld");
|
||||
touch(overworld.resolve("region/r.0.0.mca"));
|
||||
touch(worldRoot.resolve("players/data/" + player + ".dat"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("minecraft:overworld", seeded("minecraft:overworld", "overworld", 123L)), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("minecraft:overworld"), result.quarantinedLevels());
|
||||
assertFalse(Files.exists(overworld.resolve("region")));
|
||||
Optional<WorldReplacementEntryGuard.Entry> guard = WorldReplacementEntryGuard.load(overworld);
|
||||
assertTrue(guard.isPresent());
|
||||
assertEquals(Set.of(player), guard.get().pendingPlayers());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unchangedReplacementIsANoOpAndRemovalQuarantinesTheIrisChunks() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-cycle");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
writeApplied(worldRoot, seeded("iristest:skylands", "overworld", 5L));
|
||||
touch(region);
|
||||
|
||||
ModdedReplacementReconciler.Result unchanged = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", replacement("iristest:skylands", "overworld")), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of(), unchanged.quarantinedLevels());
|
||||
assertNull(unchanged.recovery());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
|
||||
ModdedReplacementReconciler.Result removed = reconcile(worldRoot, Map.of(), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), removed.quarantinedLevels());
|
||||
assertFalse(Files.exists(region));
|
||||
assertTrue(Files.isRegularFile(removed.recovery().resolve("dimensions/iristest/skylands/region/r.0.0.mca")));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newReplacementWithoutChunkDataStaysPendingWithoutARecoveryFolder() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-empty");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "overworld")), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), result.quarantinedLevels());
|
||||
assertNull(result.recovery());
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithRecordedReplacementsRefusesWithoutMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-unreadable");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
Path recoveryParent = temporary.resolve("config");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
writeApplied(worldRoot, seeded("iristest:skylands", "overworld", 5L));
|
||||
touch(region);
|
||||
List<String> problems = List.of("Iris could not read /srv/config/irisworldgen/modded.json: Unterminated object");
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> reconcile(
|
||||
worldRoot, Map.of(), problems, recoveryParent));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("modded.json"));
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Set.of("iristest:skylands"), ModdedReplacementReconciler.readState(worldRoot).applied().keySet());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithAnEmptyStateFileStillRefuses() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-unreadable-empty");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
ModdedReplacementReconciler.writeState(worldRoot, ModdedReplacementReconciler.State.EMPTY);
|
||||
|
||||
assertThrows(IOException.class, () -> reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid replacement entry"), temporary.resolve("config")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithoutRecordedStateProceeds() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-unreadable-fresh");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid replacement entry"), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.quarantinedLevels());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedReplacementKeepsThePreviousStateUntilTheNewPackGenerates() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-change");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
ModdedDimensionReplacement previous = seeded("iristest:skylands", "overworld", 5L);
|
||||
writeApplied(worldRoot, previous);
|
||||
touch(region);
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", replacement("iristest:skylands", "skypack")), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
assertFalse(Files.exists(region));
|
||||
assertEquals(Map.of("iristest:skylands", previous), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingHistoryOfTheConfiguredPackAndSeedIsAdoptedWithoutQuarantine() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-history-match");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("skypack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", seeded("iristest:skylands", "skypack:sky", 5L)), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.adoptedLevels());
|
||||
assertNull(result.recovery());
|
||||
assertTrue(Files.isRegularFile(skylands.resolve("region/r.0.0.mca")));
|
||||
assertEquals(Map.of("iristest:skylands", seeded("iristest:skylands", "skypack:sky", 5L)),
|
||||
ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restagingTheAppliedReplacementRegeneratesItAndKeepsItApplied() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-refresh");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("skypack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
ModdedDimensionReplacement applied = seeded("iristest:skylands", "skypack:sky", 5L);
|
||||
writeApplied(worldRoot, applied);
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, applied);
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, seeded("iristest:unconfigured", "skypack:sky", 5L));
|
||||
touch(worldRoot.resolve("dimensions/iristest/unconfigured/region/r.0.0.mca"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", applied), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
assertEquals(Set.of(), result.adoptedLevels());
|
||||
assertFalse(Files.exists(skylands.resolve("region")));
|
||||
assertFalse(Files.exists(skylands.resolve("iris/generation")));
|
||||
assertTrue(Files.isRegularFile(worldRoot.resolve("dimensions/iristest/unconfigured/region/r.0.0.mca")));
|
||||
assertEquals(ModdedReplacementReconciler.State.EMPTY.pending(),
|
||||
ModdedReplacementReconciler.readState(worldRoot).pending());
|
||||
assertEquals(Map.of("iristest:skylands", applied), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void historyOfAnotherSeedIsQuarantined() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-history-seed");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("skypack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", seeded("iristest:skylands", "skypack:sky", 6L)), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.adoptedLevels());
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
assertFalse(Files.exists(skylands.resolve("region")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void historyOfAnotherPackIsQuarantined() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-history-other");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("otherpack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot,
|
||||
Map.of("iristest:skylands", replacement("iristest:skylands", "skypack:sky")), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.adoptedLevels());
|
||||
assertFalse(Files.exists(skylands.resolve("region")));
|
||||
assertFalse(Files.exists(skylands.resolve("iris")));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedHistoryMatchesOnItsRecordedAliasPack() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-history-borrowed");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path aether = worldRoot.resolve("dimensions/aether/the_aether");
|
||||
createHistory(temporary, aether, "aether:the_aether", "sky",
|
||||
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
|
||||
touch(aether.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedReplacementReconciler.Result other = reconcile(worldRoot,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "otherpack:sky")), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), other.adoptedLevels());
|
||||
assertFalse(Files.exists(aether.resolve("region")));
|
||||
|
||||
createHistory(temporary, aether, "aether:the_aether", "sky",
|
||||
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
|
||||
ModdedReplacementReconciler.Result matching = reconcile(worldRoot,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "skypack:sky")), List.of(),
|
||||
temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), matching.adoptedLevels());
|
||||
assertTrue(Files.isDirectory(aether.resolve("iris")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingIrisWorldReplacementMovesItsTerrainAndRepointsItsRegistryEntry() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-iris-world");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path myworld = worldRoot.resolve("dimensions/irisworldgen/myworld");
|
||||
touch(myworld.resolve("region/r.0.0.mca"));
|
||||
touch(myworld.resolve("iris/generation/manifest.json"));
|
||||
ModdedDimensionRegistryStore.write(registryFile(worldRoot), List.of(
|
||||
new ModdedDimensionRegistryStore.PersistentDimension("irisworldgen:myworld", "overworld", "overworld", 1L),
|
||||
new ModdedDimensionRegistryStore.PersistentDimension("irisworldgen:other", "overworld", "overworld", 2L)));
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, seeded("irisworldgen:myworld", "underworld", 9L));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot, Map.of(), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("irisworldgen:myworld"), result.replacedWorlds());
|
||||
assertFalse(Files.exists(myworld.resolve("region")));
|
||||
assertFalse(Files.exists(myworld.resolve("iris")));
|
||||
assertTrue(Files.isRegularFile(result.recovery().resolve("dimensions/irisworldgen/myworld/region/r.0.0.mca")));
|
||||
assertEquals(List.of(
|
||||
new ModdedDimensionRegistryStore.PersistentDimension("irisworldgen:myworld", "underworld", "underworld", 9L),
|
||||
new ModdedDimensionRegistryStore.PersistentDimension("irisworldgen:other", "overworld", "overworld", 2L)),
|
||||
ModdedDimensionRegistryStore.loadWorldRoot(worldRoot));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).pending());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingReplacementOfARemovedIrisWorldIsDroppedWithoutMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-iris-world-gone");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/irisworldgen/myworld/region/r.0.0.mca");
|
||||
touch(region);
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, seeded("irisworldgen:myworld", "underworld", 9L));
|
||||
|
||||
ModdedReplacementReconciler.Result result = reconcile(worldRoot, Map.of(), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.replacedWorlds());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).pending());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingIrisWorldReplacementsCanBeCancelledBeforeTheRestart() throws IOException {
|
||||
Path worldRoot = Files.createTempDirectory("iris-replace-cancel");
|
||||
try {
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, seeded("irisworldgen:myworld", "underworld", 9L));
|
||||
|
||||
assertTrue(ModdedReplacementReconciler.cancelPending(worldRoot, "irisworldgen:myworld"));
|
||||
assertFalse(ModdedReplacementReconciler.cancelPending(worldRoot, "irisworldgen:myworld"));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).pending());
|
||||
} finally {
|
||||
deleteTree(worldRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordAppliedStoresOnlyReplacementsThatGenerateFromTheirPackAndSeed() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-record");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
writeApplied(worldRoot, seeded("iristest:kept", "overworld", 5L));
|
||||
|
||||
Map<String, ModdedDimensionReplacement> recorded = ModdedReplacementReconciler.recordApplied(worldRoot,
|
||||
Map.of("iristest:kept", replacement("iristest:kept", "overworld"),
|
||||
"iristest:live", replacement("iristest:live", "skypack"),
|
||||
"iristest:seeded", seeded("iristest:seeded", "skypack", 8L),
|
||||
"iristest:wrongseed", seeded("iristest:wrongseed", "skypack", 8L),
|
||||
"iristest:skipped", replacement("iristest:skipped", "skypack")),
|
||||
(String level, String packRef) -> switch (level) {
|
||||
case "iristest:skipped" -> OptionalLong.empty();
|
||||
case "iristest:wrongseed" -> OptionalLong.of(9L);
|
||||
case "iristest:seeded" -> OptionalLong.of(8L);
|
||||
default -> OptionalLong.of(5L);
|
||||
});
|
||||
|
||||
Map<String, ModdedDimensionReplacement> expected = Map.of(
|
||||
"iristest:kept", seeded("iristest:kept", "overworld", 5L),
|
||||
"iristest:live", seeded("iristest:live", "skypack", 5L),
|
||||
"iristest:seeded", seeded("iristest:seeded", "skypack", 8L));
|
||||
assertEquals(expected, recorded);
|
||||
assertEquals(expected, ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordAppliedFailsWhenTheStateCannotBeWritten() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-record-fail");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
touch(worldRoot.resolve("data/irisworldgen/dimension-replacements.json/blocker"));
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedReplacementReconciler.recordApplied(worldRoot,
|
||||
Map.of("iristest:live", replacement("iristest:live", "skypack")),
|
||||
(String level, String packRef) -> OptionalLong.of(1L)));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchingAnAppliedLevelToAnUninstalledPackRefusesBeforeMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-uninstalled-applied");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
writeApplied(worldRoot, seeded("iristest:skylands", "overworld", 5L));
|
||||
touch(region);
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> ModdedReplacementReconciler.reconcile(
|
||||
new ModdedReplacementReconciler.Request(worldRoot,
|
||||
Map.of("iristest:skylands", replacement("iristest:skylands", "missing")), List.of(),
|
||||
(ModdedDimensionReplacement replacement) -> false, temporary.resolve("config"))));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("missing"));
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertEquals(Set.of("iristest:skylands"), ModdedReplacementReconciler.readState(worldRoot).applied().keySet());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newReplacementOfAnUninstalledPackLeavesTheLevelAlone() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-replace-uninstalled-new");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/aether/the_aether/region/r.0.0.mca");
|
||||
touch(region);
|
||||
|
||||
ModdedReplacementReconciler.Result result = ModdedReplacementReconciler.reconcile(
|
||||
new ModdedReplacementReconciler.Request(worldRoot,
|
||||
Map.of("aether:the_aether", replacement("aether:the_aether", "missing")), List.of(),
|
||||
(ModdedDimensionReplacement replacement) -> false, temporary.resolve("config")));
|
||||
|
||||
assertEquals(Set.of(), result.quarantinedLevels());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertEquals(Map.of(), ModdedReplacementReconciler.readState(worldRoot).applied());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingCoversStagedLevelStemsAndIrisWorlds() throws IOException {
|
||||
Path worldRoot = Files.createTempDirectory("iris-replace-pending");
|
||||
try {
|
||||
writeApplied(worldRoot, seeded("minecraft:overworld", "overworld", 5L));
|
||||
ModdedReplacementReconciler.stagePending(worldRoot, seeded("irisworldgen:myworld", "underworld", 9L));
|
||||
Map<String, ModdedDimensionReplacement> configured = Map.of(
|
||||
"minecraft:overworld", seeded("minecraft:overworld", "overworld", 5L),
|
||||
"minecraft:the_nether", seeded("minecraft:the_nether", "underworld", 5L));
|
||||
|
||||
assertFalse(ModdedReplacementReconciler.pending(worldRoot, "minecraft:overworld", configured));
|
||||
assertTrue(ModdedReplacementReconciler.pending(worldRoot, "minecraft:the_nether", configured));
|
||||
assertTrue(ModdedReplacementReconciler.pending(worldRoot, "irisworldgen:myworld", configured));
|
||||
assertFalse(ModdedReplacementReconciler.pending(worldRoot, "minecraft:the_end", configured));
|
||||
} finally {
|
||||
deleteTree(worldRoot);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModdedReplacementReconciler.Result reconcile(Path worldRoot, Map<String, ModdedDimensionReplacement> configured,
|
||||
List<String> problems, Path recoveryParent) throws IOException {
|
||||
return ModdedReplacementReconciler.reconcile(new ModdedReplacementReconciler.Request(
|
||||
worldRoot, configured, problems, (ModdedDimensionReplacement replacement) -> true, recoveryParent));
|
||||
}
|
||||
|
||||
private static void writeApplied(Path worldRoot, ModdedDimensionReplacement applied) throws IOException {
|
||||
ModdedReplacementReconciler.writeState(worldRoot, new ModdedReplacementReconciler.State(
|
||||
Map.of(applied.levelKey(), applied), Map.of()));
|
||||
}
|
||||
|
||||
private static Path registryFile(Path worldRoot) {
|
||||
return worldRoot.resolve("iris").resolve("iris-dimensions.json");
|
||||
}
|
||||
|
||||
private static void createHistory(Path temporary, Path dimensionRoot, String dimensionTypeKey, String dimensionKey,
|
||||
List<String> biomeKeys) throws IOException {
|
||||
Path source = Files.createTempDirectory(temporary, "pack");
|
||||
touch(source.resolve("dimensions/" + dimensionKey + ".json"));
|
||||
GenerationEpoch epoch = ModdedRetainedPackNameTest.epoch(dimensionTypeKey, dimensionKey, biomeKeys);
|
||||
Files.createDirectories(dimensionRoot);
|
||||
GenerationHistory.create(dimensionRoot, source,
|
||||
GenerationPackFingerprint.compute(source, GenerationPackFingerprint.CURRENT_VERSION), 5L,
|
||||
epoch.dimensionContract(), epoch.registryContract());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-386
@@ -1,386 +0,0 @@
|
||||
/*
|
||||
* 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.iris.world.history.GenerationEpoch;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationPackFingerprint;
|
||||
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.assertThrows;
|
||||
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 = reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
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(), 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 = reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of(), unchanged.quarantinedLevels());
|
||||
assertNull(unchanged.recovery());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
|
||||
ModdedTakeoverReconciler.Result removed = reconcile(
|
||||
worldRoot, Map.of(), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), removed.quarantinedLevels());
|
||||
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 newTakeoverWithoutChunkDataStaysPendingWithoutARecoveryFolder() 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 = reconcile(
|
||||
worldRoot, Map.of("aether:the_aether", "overworld"), List.of(), recoveryParent);
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), result.quarantinedLevels());
|
||||
assertNull(result.recovery());
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithRecordedTakeoversRefusesWithoutMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable");
|
||||
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);
|
||||
List<String> problems = List.of("Iris could not read /srv/config/irisworldgen/modded.json: Unterminated object");
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> reconcile(
|
||||
worldRoot, Map.of(), problems, recoveryParent));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("modded.json"));
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertFalse(Files.exists(recoveryParent));
|
||||
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithAnEmptyStateFileStillRefuses() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable-empty");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of());
|
||||
|
||||
assertThrows(IOException.class, () -> reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unreadableConfigWithoutRecordedStateProceeds() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-unreadable-fresh");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Files.createDirectories(worldRoot);
|
||||
|
||||
ModdedTakeoverReconciler.Result result = reconcile(
|
||||
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.quarantinedLevels());
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedTakeoverKeepsThePreviousStateUntilTheNewPackGenerates() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-change");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
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 result = reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "skypack"), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
|
||||
assertFalse(Files.exists(region));
|
||||
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingHistoryOfTheConfiguredPackIsAdoptedWithoutQuarantine() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-history-match");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("skypack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedTakeoverReconciler.Result result = reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "skypack:sky"), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("iristest:skylands"), result.adoptedLevels());
|
||||
assertNull(result.recovery());
|
||||
assertTrue(Files.isRegularFile(skylands.resolve("region/r.0.0.mca")));
|
||||
assertEquals(Map.of("iristest:skylands", "skypack:sky"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void historyOfAnotherPackIsQuarantined() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-history-other");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path skylands = worldRoot.resolve("dimensions/iristest/skylands");
|
||||
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("otherpack", "sky"), "sky", List.of());
|
||||
touch(skylands.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedTakeoverReconciler.Result result = reconcile(
|
||||
worldRoot, Map.of("iristest:skylands", "skypack:sky"), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), result.adoptedLevels());
|
||||
assertFalse(Files.exists(skylands.resolve("region")));
|
||||
assertFalse(Files.exists(skylands.resolve("iris")));
|
||||
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void borrowedHistoryMatchesOnItsRecordedAliasPack() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-history-borrowed");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path aether = worldRoot.resolve("dimensions/aether/the_aether");
|
||||
createHistory(temporary, aether, "aether:the_aether", "sky",
|
||||
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
|
||||
touch(aether.resolve("region/r.0.0.mca"));
|
||||
|
||||
ModdedTakeoverReconciler.Result other = reconcile(
|
||||
worldRoot, Map.of("aether:the_aether", "otherpack:sky"), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of(), other.adoptedLevels());
|
||||
assertFalse(Files.exists(aether.resolve("region")));
|
||||
|
||||
createHistory(temporary, aether, "aether:the_aether", "sky",
|
||||
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
|
||||
ModdedTakeoverReconciler.Result matching = reconcile(
|
||||
worldRoot, Map.of("aether:the_aether", "skypack:sky"), List.of(), temporary.resolve("config"));
|
||||
|
||||
assertEquals(Set.of("aether:the_aether"), matching.adoptedLevels());
|
||||
assertTrue(Files.isDirectory(aether.resolve("iris")));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordAppliedStoresOnlyTakeoversThatGenerateFromTheirPack() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-record");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:kept", "overworld"));
|
||||
|
||||
Map<String, String> recorded = ModdedTakeoverReconciler.recordApplied(worldRoot,
|
||||
Map.of("iristest:kept", "overworld", "iristest:live", "skypack", "iristest:skipped", "skypack"),
|
||||
(String level, String packRef) -> !level.equals("iristest:skipped"));
|
||||
|
||||
Map<String, String> expected = Map.of("iristest:kept", "overworld", "iristest:live", "skypack");
|
||||
assertEquals(expected, recorded);
|
||||
assertEquals(expected, ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordAppliedFailsWhenTheStateCannotBeWritten() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-record-fail");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
touch(worldRoot.resolve("data/irisworldgen/dimension-takeovers.json/blocker"));
|
||||
|
||||
assertThrows(IOException.class, () -> ModdedTakeoverReconciler.recordApplied(worldRoot,
|
||||
Map.of("iristest:live", "skypack"), (String level, String packRef) -> true));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchingAnAppliedLevelToAnUninstalledPackRefusesBeforeMovingAnything() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-uninstalled-applied");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
|
||||
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
|
||||
touch(region);
|
||||
|
||||
IOException refused = assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
|
||||
new ModdedTakeoverReconciler.Request(worldRoot, Map.of("iristest:skylands", "missing"), List.of(),
|
||||
(ModdedDimensionTakeover takeover) -> false, temporary.resolve("config"))));
|
||||
|
||||
assertTrue(refused.getMessage(), refused.getMessage().contains("missing"));
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newTakeoverOfAnUninstalledPackLeavesTheLevelAlone() throws IOException {
|
||||
Path temporary = Files.createTempDirectory("iris-takeover-uninstalled-new");
|
||||
Path worldRoot = temporary.resolve("world");
|
||||
try {
|
||||
Path region = worldRoot.resolve("dimensions/aether/the_aether/region/r.0.0.mca");
|
||||
touch(region);
|
||||
|
||||
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
|
||||
new ModdedTakeoverReconciler.Request(worldRoot, Map.of("aether:the_aether", "missing"), List.of(),
|
||||
(ModdedDimensionTakeover takeover) -> false, temporary.resolve("config")));
|
||||
|
||||
assertEquals(Set.of(), result.quarantinedLevels());
|
||||
assertTrue(Files.isRegularFile(region));
|
||||
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
|
||||
} finally {
|
||||
deleteTree(temporary);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModdedTakeoverReconciler.Result reconcile(Path worldRoot, Map<String, String> configured,
|
||||
List<String> problems, Path recoveryParent) throws IOException {
|
||||
return ModdedTakeoverReconciler.reconcile(new ModdedTakeoverReconciler.Request(
|
||||
worldRoot, configured, problems, (ModdedDimensionTakeover takeover) -> true, recoveryParent));
|
||||
}
|
||||
|
||||
private static void createHistory(Path temporary, Path dimensionRoot, String dimensionTypeKey, String dimensionKey,
|
||||
List<String> biomeKeys) throws IOException {
|
||||
Path source = Files.createTempDirectory(temporary, "pack");
|
||||
touch(source.resolve("dimensions/" + dimensionKey + ".json"));
|
||||
GenerationEpoch epoch = ModdedRetainedPackNameTest.epoch(dimensionTypeKey, dimensionKey, biomeKeys);
|
||||
Files.createDirectories(dimensionRoot);
|
||||
GenerationHistory.create(dimensionRoot, source,
|
||||
GenerationPackFingerprint.compute(source, GenerationPackFingerprint.CURRENT_VERSION), 5L,
|
||||
epoch.dimensionContract(), epoch.registryContract());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -52,6 +52,9 @@ public class IrisModdedCommandParityTest {
|
||||
child(iris, "worlds");
|
||||
child(iris, "accesslist");
|
||||
child(child(iris, "goto"), "unregistered");
|
||||
for (String replace : new String[]{"replace", "override", "overwrite"}) {
|
||||
assertTrue(replace, child(child(iris, replace), "arguments").getChildren().isEmpty());
|
||||
}
|
||||
|
||||
CommandNode<CommandSourceStack> edit = child(iris, "edit");
|
||||
child(edit, "b");
|
||||
@@ -173,7 +176,9 @@ 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("", "replace"));
|
||||
assertTrue(ModdedCommandHelp.documents("", "override"));
|
||||
assertTrue(ModdedCommandHelp.documents("", "overwrite"));
|
||||
assertTrue(ModdedCommandHelp.documents("goto", "unregistered"));
|
||||
assertTrue(ModdedCommandHelp.documents("pack", "compat"));
|
||||
assertTrue(ModdedCommandHelp.documents("pack", "cp"));
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedReplaceArgumentsTest {
|
||||
@Test
|
||||
public void targetAloneUsesTheDefaultTypeAndPreservesTheSeed() {
|
||||
ModdedReplaceArguments arguments = ModdedReplaceArguments.parse("minecraft:overworld");
|
||||
|
||||
assertEquals("minecraft:overworld", arguments.target());
|
||||
assertEquals("default", arguments.type());
|
||||
assertEquals(OptionalLong.empty(), arguments.seed());
|
||||
assertFalse(arguments.off());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionalArgumentsFillTargetTypeAndSeedInOrder() {
|
||||
ModdedReplaceArguments arguments = ModdedReplaceArguments.parse("main overworld 123456789");
|
||||
|
||||
assertEquals("main", arguments.target());
|
||||
assertEquals("overworld", arguments.type());
|
||||
assertEquals(OptionalLong.of(123456789L), arguments.seed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyedArgumentsAcceptThePaperNamesAndAliases() {
|
||||
ModdedReplaceArguments named = ModdedReplaceArguments.parse("target=examplemod:skylands type=skypack:sky seed=-5");
|
||||
ModdedReplaceArguments aliased = ModdedReplaceArguments.parse("world-name=myworld dimension=underworld s=7");
|
||||
ModdedReplaceArguments pack = ModdedReplaceArguments.parse("seed=1 pack=overworld:floating/sky target=nether");
|
||||
|
||||
assertEquals("examplemod:skylands", named.target());
|
||||
assertEquals("skypack:sky", named.type());
|
||||
assertEquals(OptionalLong.of(-5L), named.seed());
|
||||
assertEquals("myworld", aliased.target());
|
||||
assertEquals("underworld", aliased.type());
|
||||
assertEquals(OptionalLong.of(7L), aliased.seed());
|
||||
assertEquals("nether", pack.target());
|
||||
assertEquals("overworld:floating/sky", pack.type());
|
||||
assertEquals(OptionalLong.of(1L), pack.seed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionalTargetMixesWithKeyedTypeAndSeedLikeThePaperCommand() {
|
||||
ModdedReplaceArguments arguments = ModdedReplaceArguments.parse("minecraft:the_nether type=underworld seed=-987654321");
|
||||
|
||||
assertEquals("minecraft:the_nether", arguments.target());
|
||||
assertEquals("underworld", arguments.type());
|
||||
assertEquals(OptionalLong.of(-987654321L), arguments.seed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preserveKeepsTheSavedSeedAndTheFullSignedRangeIsAccepted() {
|
||||
assertEquals(OptionalLong.empty(), ModdedReplaceArguments.parse("main seed=preserve").seed());
|
||||
assertEquals(OptionalLong.empty(), ModdedReplaceArguments.parse("main overworld PRESERVE").seed());
|
||||
assertEquals(OptionalLong.of(Long.MAX_VALUE),
|
||||
ModdedReplaceArguments.parse("main seed=" + Long.MAX_VALUE).seed());
|
||||
assertEquals(OptionalLong.of(Long.MIN_VALUE + 1L),
|
||||
ModdedReplaceArguments.parse("main seed=" + (Long.MIN_VALUE + 1L)).seed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidSeedsAreRejected() {
|
||||
IllegalArgumentException text = assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedReplaceArguments.parse("main seed=random"));
|
||||
IllegalArgumentException reserved = assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedReplaceArguments.parse("main seed=" + Long.MIN_VALUE));
|
||||
|
||||
assertEquals("Seed must be a signed 64-bit integer", text.getMessage());
|
||||
assertTrue(reserved.getMessage(), reserved.getMessage().contains(Long.toString(Long.MIN_VALUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void offTurnsAReplacementOffAndTakesNoSeed() {
|
||||
assertTrue(ModdedReplaceArguments.parse("examplemod:skylands off").off());
|
||||
assertTrue(ModdedReplaceArguments.parse("target=examplemod:skylands type=OFF").off());
|
||||
assertThrows(IllegalArgumentException.class, () -> ModdedReplaceArguments.parse("examplemod:skylands off seed=1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void malformedArgumentListsAreRejected() {
|
||||
for (String raw : List.of("", " ", "type=overworld", "main foo=1", "main type=a pack=b",
|
||||
"main overworld 1 extra", "main type=", "target=main world-name=other")) {
|
||||
assertThrows(raw, IllegalArgumentException.class, () -> ModdedReplaceArguments.parse(raw));
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.command;
|
||||
|
||||
import art.arcane.iris.world.IrisEnvironment;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class ModdedReplaceTargetTest {
|
||||
private static final String LEVEL_NAME = "world";
|
||||
|
||||
@Test
|
||||
public void friendlyNamesResolveToTheVanillaSlots() {
|
||||
for (String overworld : List.of("main", "overworld", "MAIN", " Overworld ")) {
|
||||
assertTarget("minecraft:overworld", ModdedReplaceTarget.Kind.VANILLA_OVERWORLD, overworld);
|
||||
}
|
||||
assertTarget("minecraft:the_nether", ModdedReplaceTarget.Kind.VANILLA_NETHER, "nether");
|
||||
assertTarget("minecraft:the_nether", ModdedReplaceTarget.Kind.VANILLA_NETHER, "the_nether");
|
||||
assertTarget("minecraft:the_end", ModdedReplaceTarget.Kind.VANILLA_END, "end");
|
||||
assertTarget("minecraft:the_end", ModdedReplaceTarget.Kind.VANILLA_END, "the_end");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredLevelNamesResolveToTheVanillaSlotsFirst() {
|
||||
assertTarget("minecraft:overworld", ModdedReplaceTarget.Kind.VANILLA_OVERWORLD, "world");
|
||||
assertTarget("minecraft:the_nether", ModdedReplaceTarget.Kind.VANILLA_NETHER, "world_nether");
|
||||
assertTarget("minecraft:the_end", ModdedReplaceTarget.Kind.VANILLA_END, "WORLD_the_end");
|
||||
assertEquals("minecraft:overworld", ModdedReplaceTarget.resolve("nether", "nether").levelKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactKeysKeepTheirNamespace() {
|
||||
assertTarget("minecraft:overworld", ModdedReplaceTarget.Kind.VANILLA_OVERWORLD, "minecraft:overworld");
|
||||
assertTarget("minecraft:the_end", ModdedReplaceTarget.Kind.VANILLA_END, "MINECRAFT:THE_END");
|
||||
assertTarget("examplemod:skylands", ModdedReplaceTarget.Kind.DIMENSION, "examplemod:skylands");
|
||||
assertTarget("examplemod:realm/upper", ModdedReplaceTarget.Kind.DIMENSION, "examplemod:realm/upper");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherBareNamesResolveToIrisWorlds() {
|
||||
assertTarget("irisworldgen:myworld", ModdedReplaceTarget.Kind.IRIS_WORLD, "myworld");
|
||||
assertTarget("irisworldgen:my_world", ModdedReplaceTarget.Kind.IRIS_WORLD, "My World");
|
||||
assertTarget("irisworldgen:myworld", ModdedReplaceTarget.Kind.IRIS_WORLD, "iris:myworld");
|
||||
assertTarget("irisworldgen:myworld", ModdedReplaceTarget.Kind.IRIS_WORLD, "irisworldgen:myworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaSlotsRequireTheirEnvironment() {
|
||||
assertEquals(IrisEnvironment.NORMAL, ModdedReplaceTarget.Kind.VANILLA_OVERWORLD.environment());
|
||||
assertEquals(IrisEnvironment.NETHER, ModdedReplaceTarget.Kind.VANILLA_NETHER.environment());
|
||||
assertEquals(IrisEnvironment.THE_END, ModdedReplaceTarget.Kind.VANILLA_END.environment());
|
||||
assertNull(ModdedReplaceTarget.Kind.IRIS_WORLD.environment());
|
||||
assertNull(ModdedReplaceTarget.Kind.DIMENSION.environment());
|
||||
|
||||
ModdedReplaceTarget.requireCompatibleEnvironment(ModdedReplaceTarget.Kind.VANILLA_NETHER, IrisEnvironment.NETHER);
|
||||
ModdedReplaceTarget.requireCompatibleEnvironment(ModdedReplaceTarget.Kind.DIMENSION, IrisEnvironment.THE_END);
|
||||
IllegalArgumentException mismatch = assertThrows(IllegalArgumentException.class,
|
||||
() -> ModdedReplaceTarget.requireCompatibleEnvironment(
|
||||
ModdedReplaceTarget.Kind.VANILLA_NETHER, IrisEnvironment.NORMAL));
|
||||
assertEquals("The vanilla_nether slot requires a pack environment of NETHER.", mismatch.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsafeOrMalformedTargetsAreRejected() {
|
||||
for (String target : List.of("", " ", "../world", "a/b", "a\\b", "ns:", ":x", "a:b:c", "bad key:x",
|
||||
"examplemod:sky/../x", "examplemod:/sky")) {
|
||||
assertThrows(target, IllegalArgumentException.class, () -> ModdedReplaceTarget.resolve(target, LEVEL_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertTarget(String levelKey, ModdedReplaceTarget.Kind kind, String requested) {
|
||||
ModdedReplaceTarget target = ModdedReplaceTarget.resolve(requested, LEVEL_NAME);
|
||||
assertEquals(requested, levelKey, target.levelKey());
|
||||
assertEquals(requested, kind, target.kind());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user