mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
A pack that cannot load stops the server only when a world uses it
The startup datapack compile used to fail on any pack whose modules or dimensions could not load, so one broken pack nobody used stopped the whole server. Now a pack that cannot load stops the compile only when a world uses it: a pack copied into a world's folder belongs to that world, and an installed pack is used by every configured world that selects one of its dimensions and has no copy of its own (PackUse). The message names the pack, why it cannot load, and the worlds using it. A pack no world uses is left out with a warning, and the server starts. The pinned registry requirements leave out the same packs, so the plugin no longer reports "Unable to pin loaded Iris datapack registry requirements" for them. The dimension type folder is always created, so a datapack built only from left-out packs still reads as complete.
This commit is contained in:
1 parent
8aa07403e7
commit
91b251b352
4 files changed
+293
-24
No files matched your search
@@ -4,7 +4,7 @@ import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.BuildConstants;
|
||||
import art.arcane.iris.core.lifecycle.BukkitWorldConfiguration.IrisGeneratorBinding;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.core.nms.datapack.DataVersion;
|
||||
import art.arcane.iris.core.nms.datapack.IDataFixer;
|
||||
import art.arcane.iris.core.pack.AtomicDirectoryPublisher;
|
||||
@@ -48,6 +48,7 @@ public final class IrisDatapackCompiler {
|
||||
private static final int INPUT_FINGERPRINT_SCHEMA = 2;
|
||||
private static final int INPUT_BUFFER_BYTES = 64 * 1024;
|
||||
private static final int WORLD_PACK_SCAN_DEPTH = 8;
|
||||
private static final String DIMENSION_TYPE_FOLDER = "data/iris/dimension_type";
|
||||
private static final Pattern REGISTRY_KEY_PATTERN = Pattern.compile("[a-z0-9_.-]+:[a-z0-9/._-]+");
|
||||
private static final List<String> INPUT_DIRECTORIES = List.of("dimensions", "biomes", "snippet");
|
||||
private static final String FLAT_VOID_LEVEL_STEM = """
|
||||
@@ -186,16 +187,7 @@ public final class IrisDatapackCompiler {
|
||||
}
|
||||
IrisData data = IrisData.openDatapackCompiler(packRoot);
|
||||
try {
|
||||
ResourceLoader<IrisDimension> loader = data.getDimensionLoader();
|
||||
String[] possibleKeys = loader.getPossibleKeys();
|
||||
if (possibleKeys == null || possibleKeys.length == 0) {
|
||||
throw new IOException("Iris pack has no dimension definitions: " + packRoot);
|
||||
}
|
||||
for (String possibleKey : possibleKeys) {
|
||||
IrisDimension dimension = loader.load(possibleKey);
|
||||
if (dimension == null) {
|
||||
throw new IOException("Unable to load Iris dimension '" + possibleKey + "' from " + packRoot);
|
||||
}
|
||||
for (IrisDimension dimension : loadPack(packRoot, data).dimensions()) {
|
||||
collectRegistryRequirements(
|
||||
requirements,
|
||||
installedBiomeKeys,
|
||||
@@ -315,6 +307,7 @@ public final class IrisDatapackCompiler {
|
||||
DimensionHeight height = new DimensionHeight(fixer);
|
||||
Map<String, KSet<String>> biomes = new LinkedHashMap<>();
|
||||
Map<String, List<DimensionCandidate>> dimensions = new LinkedHashMap<>();
|
||||
PackUse packUse = new PackUse(packRoots, normalizedBindings);
|
||||
int packCount = 0;
|
||||
int dimensionCount = 0;
|
||||
for (File packRoot : packRoots) {
|
||||
@@ -324,18 +317,8 @@ public final class IrisDatapackCompiler {
|
||||
}
|
||||
IrisData data = IrisData.openDatapackCompiler(packRoot);
|
||||
try {
|
||||
ResourceLoader<IrisDimension> loader = data.getDimensionLoader();
|
||||
String[] possibleKeys = loader.getPossibleKeys();
|
||||
if (possibleKeys == null || possibleKeys.length == 0) {
|
||||
throw new IOException("Iris pack has no dimension definitions: " + packRoot);
|
||||
}
|
||||
|
||||
int installedDimensions = 0;
|
||||
for (String possibleKey : possibleKeys) {
|
||||
IrisDimension dimension = loader.load(possibleKey);
|
||||
if (dimension == null) {
|
||||
throw new IOException("Unable to load Iris dimension '" + possibleKey + "' from " + packRoot);
|
||||
}
|
||||
for (IrisDimension dimension : dimensionsOfUsedPack(packRoot, loadPack(packRoot, data), packUse)) {
|
||||
IrisLogging.debug(" Compiling Dimension " + dimension.getLoadFile().getPath());
|
||||
height.merge(dimension);
|
||||
dimensions.computeIfAbsent(dimension.getLoadKey(), ignored -> new ArrayList<>())
|
||||
@@ -359,11 +342,86 @@ public final class IrisDatapackCompiler {
|
||||
}
|
||||
|
||||
IrisDimension.writeShared(datapackRoots, height, adjustVanillaHeight);
|
||||
createDimensionTypeFolders(datapackRoots);
|
||||
installLevelStemBindings(normalizedBindings, dimensions, datapackRoots);
|
||||
validateOutputs(datapackRoots, dimensionCount, normalizedBindings.size());
|
||||
return new CompilationResult(packCount, dimensionCount, countBiomes(biomes));
|
||||
}
|
||||
|
||||
/**
|
||||
* The dimensions of the pack at {@code packRoot}. A pack that cannot load stops the compile when a world uses it,
|
||||
* so the server never starts that world without its dimension; a pack no world uses is left out, with a warning.
|
||||
*/
|
||||
private static List<IrisDimension> dimensionsOfUsedPack(File packRoot, LoadedPack pack, PackUse packUse)
|
||||
throws IOException {
|
||||
if (pack.loads()) {
|
||||
return pack.dimensions();
|
||||
}
|
||||
List<String> users = packUse.worldsUsing(packRoot, pack.dimensionKeys());
|
||||
if (!users.isEmpty()) {
|
||||
throw new IOException("Iris pack " + packRoot + " cannot load (" + pack.refusal() + ") and world(s) "
|
||||
+ String.join(", ", users) + " use it. Fix the pack, then start the server again.");
|
||||
}
|
||||
IrisLogging.warn("Iris pack %s cannot load (%s). No world uses it, so it is left out and the server starts.",
|
||||
packRoot, pack.refusal());
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every dimension of the pack, or none with the reason when its modules or any of its dimensions cannot load. A
|
||||
* pack that cannot load is left out of the datapack as a whole, never in part.
|
||||
*/
|
||||
private static LoadedPack loadPack(File packRoot, IrisData data) throws IOException {
|
||||
String[] dimensionKeys = data.getDimensionLoader().getPossibleKeys();
|
||||
if (dimensionKeys == null || dimensionKeys.length == 0) {
|
||||
throw new IOException("Iris pack has no dimension definitions: " + packRoot);
|
||||
}
|
||||
List<String> keys = List.of(dimensionKeys);
|
||||
String refusal = moduleRefusal(data);
|
||||
if (refusal != null) {
|
||||
return LoadedPack.refused(keys, refusal);
|
||||
}
|
||||
List<IrisDimension> loaded = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
IrisDimension dimension = data.getDimensionLoader().load(key);
|
||||
if (dimension == null) {
|
||||
return LoadedPack.refused(keys, "its dimension '" + key + "' failed to load; the error above says why");
|
||||
}
|
||||
loaded.add(dimension);
|
||||
}
|
||||
return new LoadedPack(keys, List.copyOf(loaded), null);
|
||||
}
|
||||
|
||||
private record LoadedPack(List<String> dimensionKeys, List<IrisDimension> dimensions, String refusal) {
|
||||
static LoadedPack refused(List<String> dimensionKeys, String refusal) {
|
||||
return new LoadedPack(dimensionKeys, List.of(), refusal);
|
||||
}
|
||||
|
||||
boolean loads() {
|
||||
return refusal == null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Why the pack's modules cannot load, or null when they load. */
|
||||
private static String moduleRefusal(IrisData data) {
|
||||
try {
|
||||
data.getModules().pack();
|
||||
return null;
|
||||
} catch (PackModulesException failure) {
|
||||
return failure.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The folder of Iris's dimension types exists in every compiled datapack, also when every pack was left out, so a
|
||||
* datapack that compiled no type still reads as complete.
|
||||
*/
|
||||
private static void createDimensionTypeFolders(Collection<File> datapackRoots) throws IOException {
|
||||
for (File datapackRoot : datapackRoots) {
|
||||
Files.createDirectories(datapackRoot.toPath().resolve(DIMENSION_TYPE_FOLDER));
|
||||
}
|
||||
}
|
||||
|
||||
private static void installLevelStemBindings(
|
||||
List<IrisGeneratorBinding> bindings,
|
||||
Map<String, List<DimensionCandidate>> dimensions,
|
||||
@@ -637,7 +695,7 @@ public final class IrisDatapackCompiler {
|
||||
if (!Files.isRegularFile(root.resolve("pack.mcmeta"))) {
|
||||
throw new IOException("Iris datapack metadata was not generated at " + root);
|
||||
}
|
||||
if (dimensionCount > 0 && !Files.isDirectory(root.resolve("data/iris/dimension_type"))) {
|
||||
if (dimensionCount > 0 && !Files.isDirectory(root.resolve(DIMENSION_TYPE_FOLDER))) {
|
||||
throw new IOException("Iris dimension types were not generated at " + root);
|
||||
}
|
||||
if (levelStemCount > 0 && !Files.isDirectory(root.resolve("data/iris/dimension"))) {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import art.arcane.iris.core.lifecycle.BukkitWorldConfiguration.IrisGeneratorBinding;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Which worlds use a pack the startup datapack is compiled from. A pack copied into a world's folder
|
||||
* ({@code <level>/dimensions/<namespace>/<world>/iris/pack}) belongs to that world, configured or not. A pack installed
|
||||
* in Iris's own folder is used by every configured world that selects one of its dimensions and has no copy of its own.
|
||||
*/
|
||||
final class PackUse {
|
||||
private static final String DIMENSIONS_FOLDER = "dimensions";
|
||||
private static final String WORLD_IRIS_FOLDER = "iris";
|
||||
private static final String WORLD_PACK_FOLDER = "pack";
|
||||
|
||||
private final Set<WorldSlotKey> worldsWithOwnPack;
|
||||
private final List<IrisGeneratorBinding> bindings;
|
||||
|
||||
PackUse(Collection<File> packRoots, List<IrisGeneratorBinding> bindings) {
|
||||
this.worldsWithOwnPack = packRoots.stream()
|
||||
.map(root -> worldOwning(root.toPath()))
|
||||
.flatMap(Optional::stream)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
this.bindings = List.copyOf(bindings);
|
||||
}
|
||||
|
||||
/** The names of the worlds that use the pack at {@code packRoot}, which defines {@code dimensions}. */
|
||||
List<String> worldsUsing(File packRoot, Collection<String> dimensions) {
|
||||
Optional<WorldSlotKey> owner = worldOwning(packRoot.toPath());
|
||||
if (owner.isPresent()) {
|
||||
return List.of(nameOf(owner.get()));
|
||||
}
|
||||
return bindings.stream()
|
||||
.filter(binding -> dimensions.contains(binding.dimension()))
|
||||
.filter(binding -> !worldsWithOwnPack.contains(binding.worldKey()))
|
||||
.map(IrisGeneratorBinding::configuredWorldName)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private String nameOf(WorldSlotKey world) {
|
||||
return bindings.stream()
|
||||
.filter(binding -> binding.worldKey().equals(world))
|
||||
.map(IrisGeneratorBinding::configuredWorldName)
|
||||
.findFirst()
|
||||
.orElse(world.toString());
|
||||
}
|
||||
|
||||
/** The world whose folder holds the pack at {@code packRoot}, or empty for a pack installed outside any world. */
|
||||
static Optional<WorldSlotKey> worldOwning(Path packRoot) {
|
||||
Path irisFolder = packRoot.toAbsolutePath().normalize().getParent();
|
||||
if (!WORLD_PACK_FOLDER.equals(nameOf(packRoot)) || irisFolder == null || !WORLD_IRIS_FOLDER.equals(nameOf(irisFolder))) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Path worldFolder = irisFolder.getParent();
|
||||
for (Path namespace = parentOf(worldFolder); namespace != null; namespace = namespace.getParent()) {
|
||||
if (DIMENSIONS_FOLDER.equals(nameOf(namespace.getParent()))) {
|
||||
return slotKey(nameOf(namespace), namespace.relativize(worldFolder));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<WorldSlotKey> slotKey(String namespace, Path world) {
|
||||
try {
|
||||
return Optional.of(new WorldSlotKey(namespace, world.toString().replace(File.separatorChar, '/')));
|
||||
} catch (IllegalArgumentException notAWorldKey) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static Path parentOf(Path path) {
|
||||
return path == null ? null : path.getParent();
|
||||
}
|
||||
|
||||
private static String nameOf(Path path) {
|
||||
return path == null || path.getFileName() == null ? null : path.getFileName().toString();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -313,6 +314,113 @@ public class IrisDatapackCompilerTest {
|
||||
assertTrue(Files.isRegularFile(datapackRoot.resolve("data/iris/dimension/moon.json")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackThatCannotLoadAndNoWorldUsesIsLeftOut() throws Exception {
|
||||
Path dataDirectory = temporaryFolder.newFolder("unused-refused-data").toPath();
|
||||
Path serverRoot = temporaryFolder.newFolder("unused-refused-server").toPath();
|
||||
createPack(dataDirectory.resolve("packs/healthy"), "healthy", "healthy_custom");
|
||||
createRefusedPack(dataDirectory.resolve("packs/refused"), "refused");
|
||||
Path datapackRoot = temporaryFolder.newFolder("unused-refused-datapack").toPath();
|
||||
|
||||
IrisDatapackCompiler.CompilationResult result = IrisDatapackCompiler.compile(
|
||||
IrisDatapackCompiler.collectPackRoots(dataDirectory, serverRoot),
|
||||
new KList<File>().qadd(datapackRoot.toFile()),
|
||||
List.of(binding("main", "healthy")),
|
||||
new DataFixerV1217(),
|
||||
false
|
||||
);
|
||||
|
||||
assertEquals(1, result.packCount());
|
||||
assertTrue(Files.isRegularFile(datapackRoot.resolve("data/iris/dimension_type/healthy.json")));
|
||||
assertFalse(Files.exists(datapackRoot.resolve("data/iris/dimension_type/refused.json")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackThatCannotLoadAddsNoRegistryRequirements() throws Exception {
|
||||
Path healthyPack = temporaryFolder.newFolder("registry-healthy-pack").toPath();
|
||||
Path refusedPack = temporaryFolder.newFolder("registry-refused-pack").toPath();
|
||||
createPack(healthyPack, "healthy", "healthy_custom");
|
||||
createRefusedPack(refusedPack, "refused");
|
||||
DataFixerV1217 fixer = new DataFixerV1217();
|
||||
|
||||
Map<String, String> healthyOnly = IrisDatapackCompiler.computeRegistryRequirements(
|
||||
List.of(healthyPack.toFile()),
|
||||
fixer);
|
||||
Map<String, String> withRefused = IrisDatapackCompiler.computeRegistryRequirements(
|
||||
List.of(healthyPack.toFile(), refusedPack.toFile()),
|
||||
fixer);
|
||||
|
||||
assertEquals(healthyOnly, withRefused);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyPacksThatCannotLoadStillGiveACompleteDatapack() throws Exception {
|
||||
Path packRoot = temporaryFolder.newFolder("only-refused-pack").toPath();
|
||||
createRefusedPack(packRoot, "refused");
|
||||
Path datapackRoot = temporaryFolder.newFolder("only-refused-datapack").toPath();
|
||||
|
||||
IrisDatapackCompiler.CompilationResult result = IrisDatapackCompiler.compile(
|
||||
List.of(packRoot.toFile()),
|
||||
new KList<File>().qadd(datapackRoot.toFile()),
|
||||
List.of(),
|
||||
new DataFixerV1217(),
|
||||
false
|
||||
);
|
||||
|
||||
assertEquals(0, result.dimensionCount());
|
||||
assertTrue(Files.isDirectory(datapackRoot.resolve("data/iris/dimension_type")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackThatCannotLoadStopsTheCompileWhenAConfiguredWorldSelectsIt() throws Exception {
|
||||
Path packRoot = temporaryFolder.newFolder("selected-refused-pack").toPath();
|
||||
createRefusedPack(packRoot, "refused");
|
||||
Path datapackRoot = temporaryFolder.newFolder("selected-refused-datapack").toPath();
|
||||
|
||||
IOException failure = assertThrows(IOException.class, () -> IrisDatapackCompiler.compile(
|
||||
List.of(packRoot.toFile()),
|
||||
new KList<File>().qadd(datapackRoot.toFile()),
|
||||
List.of(binding("moon", "refused")),
|
||||
new DataFixerV1217(),
|
||||
false
|
||||
));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("cannot load"));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("world_iris_moon"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWorldsOwnPackThatCannotLoadStopsTheCompileEvenWhenNoWorldIsConfigured() throws Exception {
|
||||
Path dataDirectory = temporaryFolder.newFolder("world-refused-data").toPath();
|
||||
Path serverRoot = temporaryFolder.newFolder("world-refused-server").toPath();
|
||||
createRefusedPack(serverRoot.resolve("dimensions/iris/old_world/iris/pack"), "overworld");
|
||||
Path datapackRoot = temporaryFolder.newFolder("world-refused-datapack").toPath();
|
||||
|
||||
IOException failure = assertThrows(IOException.class, () -> IrisDatapackCompiler.compile(
|
||||
IrisDatapackCompiler.collectPackRoots(dataDirectory, serverRoot),
|
||||
new KList<File>().qadd(datapackRoot.toFile()),
|
||||
List.of(),
|
||||
new DataFixerV1217(),
|
||||
false
|
||||
));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("iris:old_world"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackInAWorldsFolderBelongsToThatWorld() {
|
||||
assertEquals(Optional.of(new WorldSlotKey("iris", "old_world")),
|
||||
PackUse.worldOwning(Path.of("/server/world/dimensions/iris/old_world/iris/pack")));
|
||||
assertEquals(Optional.empty(), PackUse.worldOwning(Path.of("/server/plugins/Iris/packs/overworld")));
|
||||
}
|
||||
|
||||
/** A pack whose modules cannot load: its {@code modules} folder holds a file that is no jar. */
|
||||
private static void createRefusedPack(Path root, String dimensionKey) throws Exception {
|
||||
createPack(root, dimensionKey, dimensionKey + "_custom");
|
||||
Files.createDirectories(root.resolve("modules"));
|
||||
Files.writeString(root.resolve("modules/broken.jar"), "not a jar", StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static void createPack(Path root, String dimensionKey, String biomeId) throws Exception {
|
||||
createPack(root, dimensionKey, biomeId, "NORMAL");
|
||||
}
|
||||
|
||||
+1
-1
@@ -560,7 +560,7 @@ public class DefaultPackBootstrapProvisionerTest {
|
||||
byte[] metadata = Files.readAllBytes(first.datapackRoot().resolve("pack.mcmeta"));
|
||||
byte[] originalOverworld = Files.readAllBytes(dataDirectory.resolve("packs/overworld/biomes/local.json"));
|
||||
byte[] originalUnderworld = Files.readAllBytes(dataDirectory.resolve("packs/underworld/biomes/local.json"));
|
||||
Path invalidPack = dataDirectory.resolve("packs/invalid");
|
||||
Path invalidPack = root.resolve("dimensions/iris/broken_world/iris/pack");
|
||||
Files.createDirectories(invalidPack.resolve("dimensions"));
|
||||
Files.writeString(invalidPack.resolve("dimensions/broken.json"), "{", StandardCharsets.UTF_8);
|
||||
updateServer = server(
|
||||
|
||||
Reference in new issue
Block a user