Hotload edited biomes and flag the pending restart

Loaded biome definitions stay until restart
This commit is contained in:
piexel committed 2026-11-23 23:42:54 +01:00
1 parent 53376816d7
commit 82b2b3403e
20 files changed
+651 -56

No files matched your search

@@ -54,6 +54,7 @@ import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.generation.noise.NoiseStyle;
import art.arcane.iris.platform.generation.EngineBukkitOps;
import art.arcane.iris.platform.generation.PlatformChunkGenerator;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.collection.KSet;
@@ -229,7 +230,7 @@ public class CommandStudio implements DirectorExecutor {
UUID audience = LanguageAudience.current();
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessages.COMMAND_STUDIO_HOTLOADING));
generator.hotloadAsync().whenComplete((ignored, failure) ->
LanguageAudience.run(audience, () -> sendHotloadResult(commandSender, failure)));
LanguageAudience.run(audience, () -> sendHotloadResult(commandSender, generator, failure)));
}
@Director(name = "regen", aliases = {"rg"}, description = "Delete and regenerate nearby chunks in place using Iris generation", descriptionKey = "iris.director.commanddeveloper.director.delete_regenerate_nearby_chunks_place_using_iris_generation", origin = DirectorOrigin.PLAYER)
@@ -785,7 +786,12 @@ public class CommandStudio implements DirectorExecutor {
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_DONE, MessageArgument.untrusted("value", report.getPath())));
}
private void sendHotloadResult(VolmitSender commandSender, Throwable failure) {
private void sendHotloadResult(VolmitSender commandSender, PlatformChunkGenerator generator, Throwable failure) {
if (RegistryRestartRequiredException.inCauseChain(failure)) {
commandSender.sendMessage(IrisLanguage.text(RuntimeUiMessages.STUDIO_HOTLOAD_BLOCKED_RESTART_NEEDED,
MessageArgument.untrusted("biomes", generator.getEngine().getStudioRestartRequirement().biomeSummary())));
return;
}
if (failure != null) {
Iris.reportError(failure);
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessages.COMMAND_STUDIO_HOTLOAD_FAILED,
@@ -40,6 +40,13 @@ import art.arcane.iris.world.history.SavedTerrainChunk;
import java.util.concurrent.CompletableFuture;
import art.arcane.iris.generation.runtime.EngineMode;
import art.arcane.iris.generation.runtime.EnginePlatformHooks;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.localization.IrisLanguage;
import art.arcane.iris.localization.RuntimeUiMessages;
import art.arcane.iris.platform.bukkit.plugin.VolmitSender;
import art.arcane.volmlib.util.localization.MessageArgument;
import art.arcane.volmlib.util.localization.TextKey;
import org.bukkit.entity.Player;
import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.IrisDimensionRuntimeContract;
@@ -99,6 +106,17 @@ public final class BukkitEnginePlatformHooks implements EnginePlatformHooks {
}
}
@Override
public void announceStudioRestartRequirement(Engine engine, StudioRestartRequirement requirement) {
TextKey message = requirement.blocksHotload()
? RuntimeUiMessages.STUDIO_HOTLOAD_BLOCKED_RESTART_NEEDED
: RuntimeUiMessages.STUDIO_HOTLOADED_RESTART_NEEDED;
MessageArgument biomes = MessageArgument.untrusted("biomes", requirement.biomeSummary());
for (Player player : BukkitWorldBinding.world(engine.getWorld()).getPlayers()) {
J.runEntity(player, () -> new VolmitSender(player).sendMessage(IrisLanguage.text(message, biomes)));
}
}
@Override
public void fireHotloadEvent(Engine engine) {
IrisPlatforms.get().callEvent(new IrisEngineHotloadEvent(engine));
@@ -28,6 +28,8 @@ import art.arcane.iris.modded.ModdedSavedTerrainCapture;
import java.util.concurrent.CompletableFuture;
import art.arcane.iris.generation.runtime.EnginePlatformHooks;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import art.arcane.iris.generation.mantle.CustomBlockOwnership;
import art.arcane.iris.modded.api.ModdedCustomContentRegistry;
import art.arcane.volmlib.nativelib.terrain.NativeBlockPoint;
@@ -366,7 +368,7 @@ public final class ModdedStudioHotloadService implements ModdedTickableService,
watch.engine = engine;
watch.folder = new ReactiveFolder(
engine.getData().getDataFolder(),
(KList<File> created, KList<File> changed, KList<File> deleted) -> hotload(dimensionId, engine),
(KList<File> created, KList<File> changed, KList<File> deleted) -> hotloadFromWatcher(dimensionId, engine),
new KList<>(".iob", ".json"),
new KList<>(".iris"),
new KList<>());
@@ -388,13 +390,30 @@ public final class ModdedStudioHotloadService implements ModdedTickableService,
throw new IllegalStateException("The Studio world is closing or closed.");
}
engine.hotloadSilently();
ModdedIrisLog.info("Iris studio hotload {} pack={} {}ms", dimensionId, engine.getDimension().getLoadKey(), System.currentTimeMillis() - start);
ModdedIrisLog.info("Iris studio hotload {} pack={} {}ms{}", dimensionId, engine.getDimension().getLoadKey(),
System.currentTimeMillis() - start, restartSuffix(engine.getStudioRestartRequirement()));
} catch (Throwable e) {
ModdedIrisLog.error("Iris studio hotload failed for {}", dimensionId, e);
if (!RegistryRestartRequiredException.inCauseChain(e)) {
ModdedIrisLog.error("Iris studio hotload failed for {}", dimensionId, e);
}
throw new IllegalStateException("Iris studio hotload failed for " + dimensionId, e);
}
}
private void hotloadFromWatcher(String dimensionId, Engine engine) {
try {
hotload(dimensionId, engine);
} catch (IllegalStateException failure) {
if (!RegistryRestartRequiredException.inCauseChain(failure)) {
throw failure;
}
}
}
private static String restartSuffix(StudioRestartRequirement requirement) {
return requirement.isPending() ? " restart needed: " + requirement.biomeSummary() : "";
}
static boolean hasDatapackImports(Iterable<IrisDimension> dimensions) {
if (dimensions == null) {
return false;
@@ -1,6 +1,7 @@
package art.arcane.iris.modded.service;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.modded.ModdedScheduler;
import art.arcane.volmlib.util.collection.KList;
@@ -218,6 +219,7 @@ public class ModdedStudioHotloadServiceTest {
Engine engine = mock(Engine.class);
when(engine.isStudio()).thenReturn(true);
when(engine.getDimension()).thenReturn(new IrisDimension());
when(engine.getStudioRestartRequirement()).thenReturn(StudioRestartRequirement.none());
return engine;
}
@@ -747,6 +747,10 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
boolean isStudio();
default StudioRestartRequirement getStudioRestartRequirement() {
return StudioRestartRequirement.none();
}
default IrisBiome getBiome(int x, int y, int z) {
IrisBiome featureBiome = getSubterrainBiome(x, y, z);
if (featureBiome != null) {
@@ -31,6 +31,10 @@ import art.arcane.iris.world.history.GenerationHistory;
import art.arcane.iris.world.history.IrisBoundarySignatureSampler;
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
import art.arcane.iris.world.history.GenerationManifest;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import art.arcane.iris.localization.IrisLanguage;
import art.arcane.iris.localization.RuntimeUiMessages;
import art.arcane.volmlib.util.localization.MessageArgument;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisServices;
import art.arcane.iris.generation.context.IrisContext;
@@ -282,7 +286,16 @@ final class EngineHotloader {
elapsedMillis(startedAt, preparedAt), elapsedMillis(preparedAt, drainedAt),
elapsedMillis(drainedAt, checkpointedAt), elapsedMillis(checkpointedAt, stagedAt),
elapsedMillis(stagedAt, promotedAt), elapsedMillis(promotedAt, completedAt));
broadcastStudioHotload(false, "");
StudioRestartRequirement requirement = StudioRestartRequirement.deferring(update.deferredBiomes());
publishRestartRequirement(requirement);
broadcastStudioHotload(false, restartNote(requirement));
} catch (RegistryRestartRequiredException restart) {
StudioRestartRequirement requirement = StudioRestartRequirement.blockedBy(restart);
publishRestartRequirement(requirement);
IrisLogging.warn("Studio update for '%s' needs a restart: %s",
engine.getWorld().name(), restart.getMessage());
broadcastStudioHotload(true, restartNote(requirement));
throw EngineShutdownSequence.propagate(restart);
} catch (Throwable failure) {
if (previous != null) {
synchronized (engine.lifecycleLock) {
@@ -330,6 +343,21 @@ final class EngineHotloader {
}
}
private void publishRestartRequirement(StudioRestartRequirement requirement) {
engine.studioRestartRequirement = requirement;
if (requirement.isPending()) {
engine.getPlatformHooks().announceStudioRestartRequirement(engine, requirement);
}
}
private static String restartNote(StudioRestartRequirement requirement) {
if (!requirement.isPending()) {
return "";
}
return IrisLanguage.plain(RuntimeUiMessages.STUDIO_RESTART_NEEDED,
MessageArgument.untrusted("biomes", requirement.biomeSummary()));
}
private static long elapsedMillis(long startedAt, long completedAt) {
return TimeUnit.NANOSECONDS.toMillis(completedAt - startedAt);
}
@@ -64,6 +64,9 @@ public interface EnginePlatformHooks {
default void fireHotloadEvent(Engine engine) {
}
default void announceStudioRestartRequirement(Engine engine, StudioRestartRequirement requirement) {
}
default void validateDimensionHotload(Engine engine, IrisDimension replacement) {
}
@@ -110,6 +110,8 @@ public class IrisEngine implements Engine {
private final boolean studio;
@Setter(AccessLevel.NONE)
private volatile Path studioGenerationSource;
@Setter(AccessLevel.NONE)
volatile StudioRestartRequirement studioRestartRequirement = StudioRestartRequirement.none();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
boolean studioGenerationTransition;
@@ -11,6 +11,7 @@ import art.arcane.iris.world.history.GenerationPackFingerprint;
import art.arcane.iris.world.history.GenerationPackRepository;
import art.arcane.iris.world.history.GenerationRegistryContract;
import art.arcane.iris.world.history.GenerationRegistryContractFactory;
import art.arcane.iris.world.history.StudioRegistryCapture;
import art.arcane.iris.generation.terrain.IrisDimension;
import java.io.IOException;
@@ -23,7 +24,8 @@ record StudioGenerationUpdate(
Path source,
String fingerprint,
GenerationEpoch.DimensionContract dimensionContract,
GenerationRegistryContract registryContract
GenerationRegistryContract registryContract,
List<String> deferredBiomes
) implements AutoCloseable {
static StudioGenerationUpdate prepare(IrisEngine engine, GenerationHistory history) throws IOException {
Path source = engine.getStudioGenerationSource().toRealPath();
@@ -73,9 +75,13 @@ record StudioGenerationUpdate(
if (!active.dimensionContract().hasSameLayout(contract)) {
throw new IOException("Studio pack update changes the world's immutable dimension layout.");
}
GenerationRegistryContract registry = GenerationRegistryContractFactory.create(data, replacement, fingerprint);
registry.requireDefinitionsAvailableIn(GenerationRegistryContractFactory.captureRequiredDefinitions(List.of(registry)));
return new StudioGenerationUpdate(stagingRoot, source, fingerprint, contract, registry);
StudioRegistryCapture registry = GenerationRegistryContractFactory.createRetainingLoadedBiomes(
data, replacement, fingerprint, active.registryContract());
GenerationRegistryContract registryContract = registry.contract();
registryContract.requireDefinitionsAvailableIn(
GenerationRegistryContractFactory.captureRequiredDefinitions(List.of(registryContract)));
return new StudioGenerationUpdate(stagingRoot, source, fingerprint, contract, registryContract,
registry.deferredBiomes());
} finally {
data.close();
}
@@ -0,0 +1,49 @@
package art.arcane.iris.generation.runtime;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import java.util.LinkedHashSet;
import java.util.List;
/**
* What a Studio world still needs a server restart for. Deferred biomes hotloaded with the definition the server
* loaded; blocking biomes have no loaded definition, so their update waits for the restart.
*/
public record StudioRestartRequirement(List<String> deferredBiomes, List<String> blockingBiomes) {
private static final StudioRestartRequirement NONE = new StudioRestartRequirement(List.of(), List.of());
private static final int LISTED_BIOME_LIMIT = 3;
public StudioRestartRequirement {
deferredBiomes = List.copyOf(deferredBiomes);
blockingBiomes = List.copyOf(blockingBiomes);
}
public static StudioRestartRequirement none() {
return NONE;
}
public static StudioRestartRequirement deferring(List<String> deferredBiomes) {
return deferredBiomes.isEmpty() ? NONE : new StudioRestartRequirement(deferredBiomes, List.of());
}
public static StudioRestartRequirement blockedBy(RegistryRestartRequiredException restart) {
return new StudioRestartRequirement(restart.deferredBiomes(), restart.blockingBiomes());
}
public boolean isPending() {
return !deferredBiomes.isEmpty() || !blockingBiomes.isEmpty();
}
public boolean blocksHotload() {
return !blockingBiomes.isEmpty();
}
public String biomeSummary() {
LinkedHashSet<String> biomes = new LinkedHashSet<>(blockingBiomes);
biomes.addAll(deferredBiomes);
List<String> listed = biomes.stream().limit(LISTED_BIOME_LIMIT).toList();
int hidden = biomes.size() - listed.size();
String summary = String.join(", ", listed);
return hidden > 0 ? summary + " +" + hidden : summary;
}
}
@@ -29,6 +29,9 @@ public final class RuntimeUiMessages {
public static final TextKey MODDED_NO_DIMENSION_MATCH = TextKey.of("iris.runtime.modded.no_dimension_match", "No Iris dimension matches '{filter}'.");
public static final TextKey TELEPORTED_TO_WORLD = TextKey.of("iris.runtime.teleport.world", "You have been teleported to {world}.");
public static final TextKey ENGINE_HOTLOADED = TextKey.of("iris.runtime.engine.hotloaded", "Engine Hotloaded");
public static final TextKey STUDIO_RESTART_NEEDED = TextKey.of("iris.runtime.studio.restart_needed", "restart needed: {biomes}");
public static final TextKey STUDIO_HOTLOADED_RESTART_NEEDED = TextKey.of("iris.runtime.studio.hotloaded_restart_needed", C.YELLOW + "Studio hotloaded · restart needed: {biomes}");
public static final TextKey STUDIO_HOTLOAD_BLOCKED_RESTART_NEEDED = TextKey.of("iris.runtime.studio.hotload_blocked_restart_needed", C.RED + "Studio hotload blocked · restart needed: {biomes}");
public static final TextKey JOB_COMPLETED = TextKey.of("iris.runtime.job.completed", "Completed {job} in {duration}");
public static final TextKey JOB_SCANNING_SELECTION = TextKey.of("iris.runtime.job.scanning_selection", "Scanning Selection");
public static final TextKey JOB_SEARCHED_CHUNKS = TextKey.of("iris.runtime.job.searched_chunks", "Searched {chunks} Chunks");
@@ -149,6 +152,9 @@ public final class RuntimeUiMessages {
MODDED_NO_DIMENSION_MATCH,
TELEPORTED_TO_WORLD,
ENGINE_HOTLOADED,
STUDIO_RESTART_NEEDED,
STUDIO_HOTLOADED_RESTART_NEEDED,
STUDIO_HOTLOAD_BLOCKED_RESTART_NEEDED,
JOB_COMPLETED,
JOB_SCANNING_SELECTION,
JOB_SEARCHED_CHUNKS,
@@ -46,6 +46,11 @@ import art.arcane.iris.generation.runtime.IrisWorldManager;
import art.arcane.volmlib.util.cache.AtomicCache;
import art.arcane.iris.generation.chunk.TerrainChunk;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import art.arcane.iris.localization.IrisLanguage;
import art.arcane.iris.localization.RuntimeUiMessages;
import art.arcane.volmlib.util.localization.MessageArgument;
import art.arcane.iris.generation.runtime.EngineTarget;
import art.arcane.iris.generation.runtime.GenerationSessionException;
import art.arcane.iris.generation.runtime.GenerationSessionLease;
@@ -1095,7 +1100,16 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
Engine activeEngine = getEngine();
long started = M.ms();
activeEngine.hotload();
IrisLogging.info("Hotloaded " + packKeyOf(activeEngine) + " in " + (M.ms() - started) + "ms");
IrisLogging.info("Hotloaded " + packKeyOf(activeEngine) + " in " + (M.ms() - started) + "ms"
+ restartSuffix(activeEngine.getStudioRestartRequirement()));
}
private static String restartSuffix(StudioRestartRequirement requirement) {
if (!requirement.isPending()) {
return "";
}
return " · " + IrisLanguage.plain(RuntimeUiMessages.STUDIO_RESTART_NEEDED,
MessageArgument.untrusted("biomes", requirement.biomeSummary()));
}
private static String packKeyOf(Engine activeEngine) {
@@ -1147,6 +1161,9 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
Thread.currentThread().interrupt();
throw new CancellationException("Studio hotload watcher interrupted.");
} catch (ExecutionException failure) {
if (RegistryRestartRequiredException.inCauseChain(failure)) {
return;
}
throw new CompletionException(failure.getCause());
} finally {
watcherHotload.compareAndSet(pending, null);
@@ -145,6 +145,50 @@ public final class GenerationRegistryContractFactory {
PlatformRegistries registries,
PlatformGenerationRegistry generationRegistry,
CustomBiomeAliasPolicy aliasPolicy
) throws IOException {
return capture(data, dimension, packFingerprint, fixer, registries, generationRegistry, aliasPolicy,
CustomBiomeSelection.CURRENT);
}
/**
* Captures a Studio update's registry contract, keeping the server's loaded definition for every custom
* biome whose edited definition only a restart can load. Biomes the server never loaded block the update.
*/
public static StudioRegistryCapture createRetainingLoadedBiomes(
IrisData data,
IrisDimension dimension,
String packFingerprint,
GenerationRegistryContract loadedContract
) throws IOException {
PlatformRegistries registries = IrisPlatforms.get().registries();
return createRetainingLoadedBiomes(data, dimension, packFingerprint, loadedContract,
DataVersion.getRuntime().get(), registries, registries.generationRegistry());
}
public static StudioRegistryCapture createRetainingLoadedBiomes(
IrisData data,
IrisDimension dimension,
String packFingerprint,
GenerationRegistryContract loadedContract,
IDataFixer fixer,
PlatformRegistries registries,
PlatformGenerationRegistry generationRegistry
) throws IOException {
LoadedCustomBiomeRetention retention = new LoadedCustomBiomeRetention(loadedContract, fixer, generationRegistry);
GenerationRegistryContract contract = capture(data, dimension, packFingerprint, fixer, registries,
generationRegistry, CustomBiomeAliasPolicy.CONTENT_ADDRESSED_ONLY, retention);
return retention.finish(contract);
}
private static GenerationRegistryContract capture(
IrisData data,
IrisDimension dimension,
String packFingerprint,
IDataFixer fixer,
PlatformRegistries registries,
PlatformGenerationRegistry generationRegistry,
CustomBiomeAliasPolicy aliasPolicy,
CustomBiomeSelection biomeSelection
) throws IOException {
IrisData requiredData = Objects.requireNonNull(data, "data");
IrisDimension requiredDimension = Objects.requireNonNull(dimension, "dimension");
@@ -201,6 +245,7 @@ public final class GenerationRegistryContractFactory {
requiredFixer,
requiredGenerationRegistry,
requiredAliasPolicy,
biomeSelection,
biomeTags
);
}
@@ -379,30 +424,21 @@ public final class GenerationRegistryContractFactory {
generationRegistry,
"generationRegistry"
);
String selectedKey = null;
for (Map.Entry<GenerationRegistryContract.PhysicalResourceKey, GenerationRegistryContract.GeneratedSource>
entry : requiredContract.generatedSources().entrySet()) {
GenerationRegistryContract.GeneratedSource source = entry.getValue();
if (!entry.getKey().registryKey().equals(BIOME_REGISTRY)
|| !source.sourceSchema().equals(CUSTOM_BIOME_EFFECTIVE_SOURCE_SCHEMA)) {
continue;
}
String identity = fingerprintCustomBiomeIdentity(
source.semanticSha256(),
dimensionKey,
customBiomeId
List<GenerationRegistryContract.PhysicalResourceKey> recordedKeys = recordedCustomBiomeKeys(
requiredContract,
dimensionKey,
customBiomeId,
registry::customBiomeResourceKey
);
for (GenerationRegistryContract.PhysicalResourceKey recordedKey : recordedKeys) {
requireGeneratedSemanticFingerprint(
recordedKey,
requiredContract.generatedSources().get(recordedKey),
requiredContract.definitions().get(recordedKey)
);
String expectedResourceKey = registry.customBiomeResourceKey(identity);
if (!entry.getKey().resourceKey().equals(expectedResourceKey)) {
continue;
}
String expectedDefinition = requiredContract.definitions().get(entry.getKey());
requireGeneratedSemanticFingerprint(entry.getKey(), source, expectedDefinition);
if (selectedKey == null || expectedResourceKey.compareTo(selectedKey) < 0) {
selectedKey = expectedResourceKey;
}
}
if (selectedKey != null) {
if (!recordedKeys.isEmpty()) {
String selectedKey = recordedKeys.getFirst().resourceKey();
registerCustomBiomeName(dimensionKey, customBiomeId, selectedKey);
return selectedKey;
}
@@ -411,6 +447,33 @@ public final class GenerationRegistryContractFactory {
+ requireText(customBiomeId, "Custom biome ID") + ".");
}
/**
* Every custom biome definition the contract records for one dimension's biome id, in key order. Several
* exist when a pack gives two custom biomes the same id.
*/
static List<GenerationRegistryContract.PhysicalResourceKey> recordedCustomBiomeKeys(
GenerationRegistryContract contract,
String dimensionKey,
String customBiomeId,
UnaryOperator<String> resourceKeyFactory
) {
List<GenerationRegistryContract.PhysicalResourceKey> keys = new ArrayList<>();
for (Map.Entry<GenerationRegistryContract.PhysicalResourceKey, GenerationRegistryContract.GeneratedSource>
entry : contract.generatedSources().entrySet()) {
GenerationRegistryContract.GeneratedSource source = entry.getValue();
if (!entry.getKey().registryKey().equals(BIOME_REGISTRY)
|| !source.sourceSchema().equals(CUSTOM_BIOME_EFFECTIVE_SOURCE_SCHEMA)) {
continue;
}
String identity = fingerprintCustomBiomeIdentity(source.semanticSha256(), dimensionKey, customBiomeId);
if (entry.getKey().resourceKey().equals(resourceKeyFactory.apply(identity))) {
keys.add(entry.getKey());
}
}
keys.sort(null);
return keys;
}
public static String fingerprintCustomBiomeAuthoredDefinition(IrisBiomeCustom customBiome) {
return fingerprintCustomBiomeEffectiveDefinition(customBiome, null);
}
@@ -746,6 +809,7 @@ public final class GenerationRegistryContractFactory {
IDataFixer fixer,
PlatformGenerationRegistry registry,
CustomBiomeAliasPolicy aliasPolicy,
CustomBiomeSelection biomeSelection,
Map<String, Set<String>> biomeTags
) throws IOException {
TreeSet<String> platformBiomeKeys = new TreeSet<>();
@@ -764,13 +828,12 @@ public final class GenerationRegistryContractFactory {
continue;
}
String customBiomeId = requireText(customBiome.getId(), "Custom biome ID");
CustomBiomeDefinition generated = customBiomeDefinition(
data,
dimension,
customBiome,
fixer,
registry
SelectedCustomBiome selected = biomeSelection.select(
dimensionKey,
customBiomeId,
customBiomeDefinition(data, dimension, customBiome, fixer, registry)
);
CustomBiomeDefinition generated = selected.definition();
putGeneratedDefinition(
definitions,
generatedSources,
@@ -782,17 +845,10 @@ public final class GenerationRegistryContractFactory {
generated.definition()
);
Set<String> tags = biomeTags.computeIfAbsent(generated.physicalKey().resourceKey(), ignored -> new TreeSet<>());
for (String rawTag : customBiome.getEffectiveTags(biome.getVanillaDerivativeKey())) {
if (rawTag == null || rawTag.isBlank()) {
continue;
}
String tag = rawTag.trim().toLowerCase(Locale.ROOT);
if (tag.indexOf(':') < 0) {
tag = "minecraft:" + tag;
}
if (tag.matches("[a-z0-9_.-]+:[a-z0-9/._-]+")) {
tags.add(tag);
}
if (selected.retainsLoadedDefinition()) {
tags.addAll(selected.loadedTags());
} else {
addEffectiveTags(tags, customBiome, biome);
}
String logicalKey = dimensionKey.toLowerCase(Locale.ROOT)
+ ":" + customBiomeId.toLowerCase(Locale.ROOT);
@@ -844,6 +900,21 @@ public final class GenerationRegistryContractFactory {
addPlatformDefinitions(definitions, BIOME_REGISTRY, platformBiomeKeys, registry);
}
private static void addEffectiveTags(Set<String> tags, IrisBiomeCustom customBiome, IrisBiome biome) {
for (String rawTag : customBiome.getEffectiveTags(biome.getVanillaDerivativeKey())) {
if (rawTag == null || rawTag.isBlank()) {
continue;
}
String tag = rawTag.trim().toLowerCase(Locale.ROOT);
if (tag.indexOf(':') < 0) {
tag = "minecraft:" + tag;
}
if (tag.matches("[a-z0-9_.-]+:[a-z0-9/._-]+")) {
tags.add(tag);
}
}
}
private static void addNativeStructures(
Map<GenerationRegistryContract.PhysicalResourceKey, PlatformGenerationRegistry.Definition> definitions,
IrisDimension dimension,
@@ -1046,7 +1117,7 @@ public final class GenerationRegistryContractFactory {
&& parseJson(left.semanticJson()).equals(parseJson(right.semanticJson()));
}
private static PlatformGenerationRegistry.Definition canonicalGeneratedDefinition(
static PlatformGenerationRegistry.Definition canonicalGeneratedDefinition(
GenerationRegistryContract.PhysicalResourceKey key,
GenerationRegistryContract.GeneratedSource source,
IDataFixer fixer,
@@ -1629,13 +1700,26 @@ public final class GenerationRegistryContractFactory {
GenerationRegistryContract.PhysicalResourceKey physicalKey = key(BIOME_REGISTRY, resourceKey);
GenerationRegistryContract.GeneratedSource source = contract.generatedSources().get(physicalKey);
if (source == null || !semanticFingerprint.equals(source.semanticSha256())) {
throw new IOException("Historical generation registry contract has no exact custom biome definition for "
+ dimension + ":" + requiredBiome.getId() + ".");
physicalKey = requireSoleRecordedKey(dimension, requiredBiome.getId());
source = contract.generatedSources().get(physicalKey);
}
requireGeneratedSemanticFingerprint(physicalKey, source, contract.definitions().get(physicalKey));
registerCustomBiomeName(dimension, requiredBiome.getId(), resourceKey);
dimensionKeys.put(requiredBiome, resourceKey);
return resourceKey;
registerCustomBiomeName(dimension, requiredBiome.getId(), physicalKey.resourceKey());
dimensionKeys.put(requiredBiome, physicalKey.resourceKey());
return physicalKey.resourceKey();
}
// A Studio update keeps the server's loaded definition for an edited biome until restart, so its epoch
// records that definition instead of the pack's. The biome id then names exactly one recorded definition.
private GenerationRegistryContract.PhysicalResourceKey requireSoleRecordedKey(String dimension, String biomeId)
throws IOException {
List<GenerationRegistryContract.PhysicalResourceKey> recorded = recordedCustomBiomeKeys(
contract, dimension, biomeId, resourceKeyFactory);
if (recorded.size() != 1) {
throw new IOException("Historical generation registry contract has no exact custom biome definition for "
+ dimension + ":" + biomeId + ".");
}
return recorded.getFirst();
}
}
@@ -1670,4 +1754,25 @@ public final class GenerationRegistryContractFactory {
private record ReferencedPlatformKeys(Set<String> blockKeys, Set<String> entityKeys) {
}
interface CustomBiomeSelection {
CustomBiomeSelection CURRENT = (dimensionKey, customBiomeId, current) -> SelectedCustomBiome.current(current);
SelectedCustomBiome select(String dimensionKey, String customBiomeId, CustomBiomeDefinition current)
throws IOException;
}
record SelectedCustomBiome(CustomBiomeDefinition definition, Collection<String> loadedTags) {
static SelectedCustomBiome current(CustomBiomeDefinition definition) {
return new SelectedCustomBiome(definition, null);
}
static SelectedCustomBiome loaded(CustomBiomeDefinition definition, Collection<String> tags) {
return new SelectedCustomBiome(definition, List.copyOf(tags));
}
boolean retainsLoadedDefinition() {
return loadedTags != null;
}
}
}
@@ -0,0 +1,133 @@
package art.arcane.iris.world.history;
import art.arcane.iris.pack.datapack.IDataFixer;
import art.arcane.iris.spi.PlatformGenerationRegistry;
import art.arcane.iris.world.history.GenerationRegistryContractFactory.CustomBiomeDefinition;
import art.arcane.iris.world.history.GenerationRegistryContractFactory.CustomBiomeSelection;
import art.arcane.iris.world.history.GenerationRegistryContractFactory.SelectedCustomBiome;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Picks, for each custom biome of a Studio update, a definition the running server has loaded: the edited one
* when the server already has it, otherwise the definition the active epoch recorded for the same biome id.
* Biomes with neither are collected and block the update.
*/
final class LoadedCustomBiomeRetention implements CustomBiomeSelection {
private static final String GENERATED_RENDERER = "generated";
private final GenerationRegistryContract loadedContract;
private final IDataFixer fixer;
private final PlatformGenerationRegistry registry;
private final Map<String, BiomeIdentity> deferred = new TreeMap<>();
private final TreeSet<String> blocking = new TreeSet<>();
LoadedCustomBiomeRetention(
GenerationRegistryContract loadedContract,
IDataFixer fixer,
PlatformGenerationRegistry registry
) {
this.loadedContract = Objects.requireNonNull(loadedContract, "loadedContract");
this.fixer = Objects.requireNonNull(fixer, "fixer");
this.registry = Objects.requireNonNull(registry, "registry");
}
@Override
public SelectedCustomBiome select(String dimensionKey, String customBiomeId, CustomBiomeDefinition current)
throws IOException {
if (isLoaded(current)) {
return SelectedCustomBiome.current(current);
}
BiomeIdentity identity = new BiomeIdentity(dimensionKey, customBiomeId);
List<GenerationRegistryContract.PhysicalResourceKey> loadedKeys = recordedKeys(loadedContract, identity);
if (loadedKeys.size() != 1) {
blocking.add(identity.label());
return SelectedCustomBiome.current(current);
}
GenerationRegistryContract.PhysicalResourceKey loadedKey = loadedKeys.getFirst();
CustomBiomeDefinition loaded = loadedDefinition(loadedKey, identity);
if (!isLoaded(loaded)) {
blocking.add(identity.label());
return SelectedCustomBiome.current(current);
}
deferred.put(identity.logicalKey(), identity);
return SelectedCustomBiome.loaded(
loaded,
loadedContract.biomeTags().getOrDefault(loadedKey.resourceKey(), List.of())
);
}
StudioRegistryCapture finish(GenerationRegistryContract contract) throws RegistryRestartRequiredException {
TreeSet<String> deferredLabels = new TreeSet<>();
for (BiomeIdentity identity : deferred.values()) {
if (recordedKeys(contract, identity).size() == 1) {
deferredLabels.add(identity.label());
} else {
blocking.add(identity.label());
}
}
if (!blocking.isEmpty()) {
throw new RegistryRestartRequiredException(List.copyOf(blocking), List.copyOf(deferredLabels));
}
return new StudioRegistryCapture(contract, List.copyOf(deferredLabels));
}
private List<GenerationRegistryContract.PhysicalResourceKey> recordedKeys(
GenerationRegistryContract contract,
BiomeIdentity identity
) {
return GenerationRegistryContractFactory.recordedCustomBiomeKeys(
contract, identity.dimensionKey(), identity.biomeId(), registry::customBiomeResourceKey);
}
private CustomBiomeDefinition loadedDefinition(
GenerationRegistryContract.PhysicalResourceKey key,
BiomeIdentity identity
) throws IOException {
GenerationRegistryContract.GeneratedSource source = loadedContract.generatedSources().get(key);
PlatformGenerationRegistry.Definition definition =
GenerationRegistryContractFactory.canonicalGeneratedDefinition(key, source, fixer, registry);
return new CustomBiomeDefinition(
key,
GenerationRegistryContractFactory.fingerprintCustomBiomeIdentity(
source.semanticSha256(), identity.dimensionKey(), identity.biomeId()),
source.semanticSha256(),
source.semanticJson(),
GenerationRegistryContractFactory.fingerprintCustomBiomeDefinition(definition.value()),
definition.value(),
definition
);
}
private boolean isLoaded(CustomBiomeDefinition definition) {
GenerationRegistryContract.PhysicalResourceKey key = definition.physicalKey();
PlatformGenerationRegistry.Definition live;
try {
live = registry.generatedDefinition(key.registryKey(), key.resourceKey());
} catch (RuntimeException missing) {
return false;
}
if (live == null || live.encoding() != PlatformGenerationRegistry.Encoding.JSON) {
return false;
}
return GenerationRegistryContractFactory.fingerprintDefinition(key, live, GENERATED_RENDERER)
.equals(GenerationRegistryContractFactory.fingerprintDefinition(
key, definition.definition(), GENERATED_RENDERER));
}
private record BiomeIdentity(String dimensionKey, String biomeId) {
String logicalKey() {
return dimensionKey.toLowerCase(Locale.ROOT) + ":" + biomeId.toLowerCase(Locale.ROOT);
}
String label() {
return biomeId.toLowerCase(Locale.ROOT);
}
}
}
@@ -0,0 +1,36 @@
package art.arcane.iris.world.history;
import java.io.IOException;
import java.util.List;
/**
* A Studio update references custom biomes the running server has no definition for, so only a restart can
* apply it.
*/
public final class RegistryRestartRequiredException extends IOException {
private final List<String> blockingBiomes;
private final List<String> deferredBiomes;
public RegistryRestartRequiredException(List<String> blockingBiomes, List<String> deferredBiomes) {
super("Restart needed to load biomes: " + String.join(", ", blockingBiomes));
this.blockingBiomes = List.copyOf(blockingBiomes);
this.deferredBiomes = List.copyOf(deferredBiomes);
}
public static boolean inCauseChain(Throwable failure) {
for (Throwable cause = failure; cause != null; cause = cause.getCause()) {
if (cause instanceof RegistryRestartRequiredException) {
return true;
}
}
return false;
}
public List<String> blockingBiomes() {
return blockingBiomes;
}
public List<String> deferredBiomes() {
return deferredBiomes;
}
}
@@ -0,0 +1,14 @@
package art.arcane.iris.world.history;
import java.util.List;
import java.util.Objects;
/**
* A Studio update's registry contract and the custom biomes it keeps at their loaded definition until restart.
*/
public record StudioRegistryCapture(GenerationRegistryContract contract, List<String> deferredBiomes) {
public StudioRegistryCapture {
contract = Objects.requireNonNull(contract, "contract");
deferredBiomes = List.copyOf(deferredBiomes);
}
}
@@ -0,0 +1,39 @@
package art.arcane.iris.generation.runtime;
import art.arcane.iris.world.history.RegistryRestartRequiredException;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class StudioRestartRequirementTest {
@Test
public void noDeferredBiomesMeansNothingIsPending() {
StudioRestartRequirement requirement = StudioRestartRequirement.deferring(List.of());
assertFalse(requirement.isPending());
assertFalse(requirement.blocksHotload());
}
@Test
public void summaryListsBlockingBiomesFirstAndCountsTheRest() {
StudioRestartRequirement requirement = StudioRestartRequirement.blockedBy(
new RegistryRestartRequiredException(List.of("ash"), List.of("mist", "dunes", "fog", "ash")));
assertTrue(requirement.isPending());
assertTrue(requirement.blocksHotload());
assertEquals("ash, mist, dunes +1", requirement.biomeSummary());
}
@Test
public void deferredBiomesHotloadWithoutBlocking() {
StudioRestartRequirement requirement = StudioRestartRequirement.deferring(List.of("mist"));
assertTrue(requirement.isPending());
assertFalse(requirement.blocksHotload());
assertEquals("mist", requirement.biomeSummary());
}
}
@@ -1,6 +1,7 @@
package art.arcane.iris.platform.generation;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.platform.generation.BukkitChunkGenerator.GenerationStageGate;
import art.arcane.iris.world.task.J;
import org.junit.Test;
@@ -19,6 +20,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class BukkitChunkGeneratorManualHotloadTest {
@Test
@@ -89,6 +91,7 @@ public class BukkitChunkGeneratorManualHotloadTest {
private final AtomicReference<Runnable> queued = new AtomicReference<>();
private Fixture() throws Exception {
when(engine.getStudioRestartRequirement()).thenReturn(StudioRestartRequirement.none());
generator.setEngine(engine);
setField(generator, "studio", true);
setField(generator, "loadLock", new GenerationStageGate(1, () -> false));
@@ -3,6 +3,7 @@ package art.arcane.iris.platform.generation;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.runtime.IrisEngine;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.StudioRestartRequirement;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.studio.StudioMode;
@@ -339,6 +340,7 @@ public class BukkitChunkGeneratorSpawnHydrologyTest {
generator.setEngine(engine);
doReturn(false).when(generator).usesFlatStudioTerrain();
when(engine.getComplex()).thenReturn(complex);
when(engine.getStudioRestartRequirement()).thenReturn(StudioRestartRequirement.none());
when(complex.getHydrologyRuntime()).thenReturn(hydrology);
IrisDimension dimension = mock(IrisDimension.class);
when(engine.getDimension()).thenReturn(dimension);
@@ -977,6 +977,109 @@ public class GenerationRegistryContractFactoryTest {
}
@SuppressWarnings("unchecked")
@Test
public void studioUpdateKeepsTheLoadedDefinitionOfAnEditedBiomeUntilTheServerLoadsTheEdit() throws Exception {
StudioPackFixture fixture = new StudioPackFixture(temporary.newFolder("studio-edit"));
IrisBiomeCustom loaded = new IrisBiomeCustom().setId("mist").setTemperature(0.5D);
GenerationRegistryContract active = fixture.capture(loaded);
fixture.loadIntoServer(active);
String loadedKey = fixture.resolve(active, loaded);
IrisBiomeCustom edited = new IrisBiomeCustom().setId("mist").setTemperature(0.7D);
StudioRegistryCapture deferred = fixture.captureStudioUpdate(active, edited);
assertEquals(List.of("mist"), deferred.deferredBiomes());
assertTrue(deferred.contract().definitions().containsKey(
key(GenerationRegistryContractFactory.BIOME_REGISTRY, loadedKey)));
assertEquals(loadedKey, fixture.resolve(deferred.contract(), edited));
deferred.contract().requireDefinitionsAvailableIn(GenerationRegistryContractFactory.captureRequiredDefinitions(
Set.of(deferred.contract()), fixture.fixer, fixture.registry));
fixture.loadIntoServer(fixture.capture(edited));
StudioRegistryCapture current = fixture.captureStudioUpdate(active, edited);
assertEquals(List.of(), current.deferredBiomes());
assertNotEquals(loadedKey, fixture.resolve(current.contract(), edited));
}
@Test
public void studioUpdateWithABiomeTheServerNeverLoadedNeedsARestart() throws Exception {
StudioPackFixture fixture = new StudioPackFixture(temporary.newFolder("studio-new-biome"));
IrisBiomeCustom mist = new IrisBiomeCustom().setId("mist").setTemperature(0.5D);
GenerationRegistryContract active = fixture.capture(mist);
fixture.loadIntoServer(active);
IrisBiomeCustom editedMist = new IrisBiomeCustom().setId("mist").setTemperature(0.7D);
IrisBiomeCustom ash = new IrisBiomeCustom().setId("ash").setTemperature(1.5D);
RegistryRestartRequiredException restart = assertThrows(RegistryRestartRequiredException.class,
() -> fixture.captureStudioUpdate(active, editedMist, ash));
assertEquals(List.of("ash"), restart.blockingBiomes());
assertEquals(List.of("mist"), restart.deferredBiomes());
}
@Test
public void resolverWithoutAnEditedBiomeOrItsSoleRecordedDefinitionStaysStrict() throws Exception {
StudioPackFixture fixture = new StudioPackFixture(temporary.newFolder("studio-strict"));
GenerationRegistryContract active = fixture.capture(new IrisBiomeCustom().setId("mist").setTemperature(0.5D));
assertThrows(IOException.class,
() -> fixture.resolve(active, new IrisBiomeCustom().setId("fog").setTemperature(0.5D)));
}
private static final class StudioPackFixture {
private final File pack;
private final IrisData data = mock(IrisData.class);
private final IrisBiome biome = new IrisBiome();
private final IrisDimension dimension = spy(new IrisDimension());
private final PlatformRegistries registries = mock(PlatformRegistries.class);
private final FakeGenerationRegistry registry = new FakeGenerationRegistry("studio-runtime");
private final IDataFixer fixer = new TaggedBiomeFixer("studio");
private StudioPackFixture(File pack) {
this.pack = pack;
when(data.getDataFolder()).thenReturn(pack);
when(data.getContentGate()).thenReturn(new ContentGate(null, Map.of(), null));
dimension.setLoadKey("overworld");
stubDimensions(data, dimension);
doReturn(new KList<>(biome)).when(dimension).getAllBiomes(any());
doReturn(new KList<>(biome)).when(dimension).getReachableBiomes(any());
doReturn(new KList<>()).when(dimension).getAllRegions(any());
when(registries.blockTypeKeys()).thenReturn(List.of());
when(registries.entityKeys()).thenReturn(List.of());
}
private GenerationRegistryContract capture(IrisBiomeCustom... customBiomes) throws IOException {
biome.setCustomDerivitives(new KList<>(customBiomes));
return GenerationRegistryContractFactory.create(data, dimension, packFingerprint(), fixer, registries, registry);
}
private StudioRegistryCapture captureStudioUpdate(
GenerationRegistryContract active,
IrisBiomeCustom... customBiomes
) throws IOException {
biome.setCustomDerivitives(new KList<>(customBiomes));
return GenerationRegistryContractFactory.createRetainingLoadedBiomes(
data, dimension, packFingerprint(), active, fixer, registries, registry);
}
private void loadIntoServer(GenerationRegistryContract contract) throws IOException {
for (GenerationRegistryContract.PhysicalResourceKey generated : contract.generatedSources().keySet()) {
registry.put(generated, PlatformGenerationRegistry.Definition.exactJson(
GenerationRegistryContractFactory.renderGeneratedSource(contract, generated, fixer)));
}
}
private String resolve(GenerationRegistryContract contract, IrisBiomeCustom customBiome) throws IOException {
return new GenerationRegistryContractFactory.CustomBiomeResourceResolver(
contract, registry::customBiomeResourceKey).resolve("overworld", customBiome);
}
private String packFingerprint() throws IOException {
return GenerationPackFingerprint.compute(pack.toPath(), GenerationPackFingerprint.CURRENT_VERSION);
}
}
private static ResourceLoader<IrisDimension> stubDimensions(IrisData data, IrisDimension dimension) {
ResourceLoader<IrisDimension> loader = mock(ResourceLoader.class);
String dimensionKey = dimension.getLoadKey();