mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Hotload custom biome edits and flag the pending restart
New biomes generate as their vanilla derivative until restart
This commit is contained in:
1 parent
53376816d7
commit
3e0ad6cb31
39 files changed
+818
-83
No files matched your search
+15
@@ -40,6 +40,12 @@ 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 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 +105,15 @@ public final class BukkitEnginePlatformHooks implements EnginePlatformHooks {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void announceStudioRestartRequirement(Engine engine, StudioRestartRequirement requirement) {
|
||||
MessageArgument biomes = MessageArgument.untrusted("value", requirement.biomeSummary());
|
||||
for (Player player : BukkitWorldBinding.world(engine.getWorld()).getPlayers()) {
|
||||
J.runEntity(player, () -> new VolmitSender(player).sendMessage(
|
||||
IrisLanguage.text(RuntimeUiMessages.STUDIO_HOTLOADED_RESTART_NEEDED, biomes)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireHotloadEvent(Engine engine) {
|
||||
IrisPlatforms.get().callEvent(new IrisEngineHotloadEvent(engine));
|
||||
|
||||
+4
-3
@@ -983,7 +983,8 @@ public final class ModdedForcedDatapack {
|
||||
if (retainedContract == null) {
|
||||
return currentPhysicalResourceKey;
|
||||
}
|
||||
return dimension.getLoader().customBiomeResourceKey(dimension, customBiome);
|
||||
return GenerationRegistryContractFactory.retainedCustomBiomeResourceKey(
|
||||
retainedContract, dimension, customBiome, currentPhysicalResourceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1027,8 +1028,8 @@ public final class ModdedForcedDatapack {
|
||||
if (retainedContract == null) {
|
||||
return currentSource;
|
||||
}
|
||||
PhysicalResourceKey key = new PhysicalResourceKey(registryKey, resourceKey);
|
||||
return GenerationRegistryContractFactory.renderGeneratedSource(retainedContract, key, fixer);
|
||||
return GenerationRegistryContractFactory.retainedGeneratedSource(
|
||||
retainedContract, registryKey, resourceKey, currentSource, fixer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -28,6 +28,7 @@ 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.generation.mantle.CustomBlockOwnership;
|
||||
import art.arcane.iris.modded.api.ModdedCustomContentRegistry;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPoint;
|
||||
@@ -388,13 +389,18 @@ 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);
|
||||
throw new IllegalStateException("Iris studio hotload failed for " + dimensionId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String restartSuffix(StudioRestartRequirement requirement) {
|
||||
return requirement.isPending() ? " restart needed: " + requirement.biomeSummary() : "";
|
||||
}
|
||||
|
||||
static boolean hasDatapackImports(Iterable<IrisDimension> dimensions) {
|
||||
if (dimensions == null) {
|
||||
return false;
|
||||
|
||||
+2
@@ -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,9 @@ 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.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 +285,9 @@ 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.pending(update.pendingBiomes());
|
||||
publishRestartRequirement(requirement);
|
||||
broadcastStudioHotload(false, restartNote(requirement));
|
||||
} catch (Throwable failure) {
|
||||
if (previous != null) {
|
||||
synchronized (engine.lifecycleLock) {
|
||||
@@ -330,6 +335,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("value", 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> pendingBiomes
|
||||
) 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.pendingBiomes());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom biomes a Studio world generates without their latest definition until the server restarts: edited biomes
|
||||
* keep the definition the server loaded, new biomes generate as their vanilla derivative.
|
||||
*/
|
||||
public record StudioRestartRequirement(List<String> biomes) {
|
||||
private static final StudioRestartRequirement NONE = new StudioRestartRequirement(List.of());
|
||||
private static final int LISTED_BIOME_LIMIT = 3;
|
||||
|
||||
public StudioRestartRequirement {
|
||||
biomes = List.copyOf(biomes);
|
||||
}
|
||||
|
||||
public static StudioRestartRequirement none() {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static StudioRestartRequirement pending(List<String> biomes) {
|
||||
return biomes.isEmpty() ? NONE : new StudioRestartRequirement(biomes);
|
||||
}
|
||||
|
||||
public boolean isPending() {
|
||||
return !biomes.isEmpty();
|
||||
}
|
||||
|
||||
public String biomeSummary() {
|
||||
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,8 @@ 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: {value}");
|
||||
public static final TextKey STUDIO_HOTLOADED_RESTART_NEEDED = TextKey.of("iris.runtime.studio.hotloaded_restart_needed", C.YELLOW + "Studio hotloaded · restart needed: {value}");
|
||||
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 +151,8 @@ public final class RuntimeUiMessages {
|
||||
MODDED_NO_DIMENSION_MATCH,
|
||||
TELEPORTED_TO_WORLD,
|
||||
ENGINE_HOTLOADED,
|
||||
STUDIO_RESTART_NEEDED,
|
||||
STUDIO_HOTLOADED_RESTART_NEEDED,
|
||||
JOB_COMPLETED,
|
||||
JOB_SCANNING_SELECTION,
|
||||
JOB_SEARCHED_CHUNKS,
|
||||
|
||||
@@ -1047,7 +1047,8 @@ public final class IrisDatapackCompiler {
|
||||
if (retainedContract == null) {
|
||||
return currentPhysicalResourceKey;
|
||||
}
|
||||
return dimension.getLoader().customBiomeResourceKey(dimension, customBiome);
|
||||
return GenerationRegistryContractFactory.retainedCustomBiomeResourceKey(
|
||||
retainedContract, dimension, customBiome, currentPhysicalResourceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1082,8 +1083,8 @@ public final class IrisDatapackCompiler {
|
||||
if (retainedContract == null) {
|
||||
return currentSource;
|
||||
}
|
||||
PhysicalResourceKey key = new PhysicalResourceKey(registryKey, resourceKey);
|
||||
return GenerationRegistryContractFactory.renderGeneratedSource(retainedContract, key, fixer);
|
||||
return GenerationRegistryContractFactory.retainedGeneratedSource(
|
||||
retainedContract, registryKey, resourceKey, currentSource, fixer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ 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.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 +1099,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("value", requirement.biomeSummary()));
|
||||
}
|
||||
|
||||
private static String packKeyOf(Engine activeEngine) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.TreeSet;
|
||||
import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Objects;
|
||||
@@ -35,27 +36,33 @@ public final class GenerationRegistryContract {
|
||||
private static final int MAX_TOTAL_GENERATED_SOURCE_BYTES = 8 * 1024 * 1024;
|
||||
private static final Pattern RESOURCE_KEY_PATTERN = Pattern.compile("[a-z0-9_.-]+:[a-z0-9/._-]+");
|
||||
private static final Pattern SHA_256_PATTERN = Pattern.compile("[0-9a-f]{64}");
|
||||
private static final String BIOME_REGISTRY = "minecraft:worldgen/biome";
|
||||
private static final String CUSTOM_BIOME_STAND_INS_FIELD = "customBiomeStandIns";
|
||||
|
||||
private final int fingerprintSchema;
|
||||
private final String fingerprint;
|
||||
private final NavigableMap<PhysicalResourceKey, String> definitions;
|
||||
private final NavigableMap<PhysicalResourceKey, GeneratedSource> generatedSources;
|
||||
private final NavigableMap<String, List<String>> biomeTags;
|
||||
private final NavigableMap<String, String> customBiomeStandIns;
|
||||
|
||||
private GenerationRegistryContract(
|
||||
int fingerprintSchema,
|
||||
String fingerprint,
|
||||
NavigableMap<PhysicalResourceKey, String> definitions,
|
||||
NavigableMap<PhysicalResourceKey, GeneratedSource> generatedSources,
|
||||
Map<String, ? extends Collection<String>> biomeTags
|
||||
Map<String, ? extends Collection<String>> biomeTags,
|
||||
Map<String, String> customBiomeStandIns
|
||||
) {
|
||||
requireSupportedFingerprintSchema(fingerprintSchema);
|
||||
this.fingerprintSchema = fingerprintSchema;
|
||||
this.definitions = immutableDefinitions(definitions);
|
||||
this.generatedSources = immutableGeneratedSources(generatedSources, this.definitions);
|
||||
this.biomeTags = canonicalBiomeTags(biomeTags, this.definitions);
|
||||
this.customBiomeStandIns = canonicalCustomBiomeStandIns(customBiomeStandIns, this.definitions);
|
||||
this.fingerprint = requireSha256(fingerprint, "Registry contract fingerprint");
|
||||
String expectedFingerprint = fingerprint(fingerprintSchema, this.definitions, this.generatedSources, this.biomeTags);
|
||||
String expectedFingerprint = fingerprint(
|
||||
fingerprintSchema, this.definitions, this.generatedSources, this.biomeTags, this.customBiomeStandIns);
|
||||
if (!this.fingerprint.equals(expectedFingerprint)) {
|
||||
throw new IllegalArgumentException("Registry contract fingerprint does not match its definitions.");
|
||||
}
|
||||
@@ -100,9 +107,10 @@ public final class GenerationRegistryContract {
|
||||
);
|
||||
return new GenerationRegistryContract(
|
||||
fingerprintSchema,
|
||||
fingerprint(fingerprintSchema, canonicalDefinitions, canonicalSources, new TreeMap<>()),
|
||||
fingerprint(fingerprintSchema, canonicalDefinitions, canonicalSources, new TreeMap<>(), new TreeMap<>()),
|
||||
canonicalDefinitions,
|
||||
canonicalSources,
|
||||
Map.of(),
|
||||
Map.of()
|
||||
);
|
||||
}
|
||||
@@ -110,14 +118,29 @@ public final class GenerationRegistryContract {
|
||||
public GenerationRegistryContract withBiomeTags(Map<String, ? extends Collection<String>> tags) {
|
||||
NavigableMap<String, List<String>> canonical = canonicalBiomeTags(tags, definitions);
|
||||
return new GenerationRegistryContract(fingerprintSchema,
|
||||
fingerprint(fingerprintSchema, definitions, generatedSources, canonical),
|
||||
definitions, generatedSources, canonical);
|
||||
fingerprint(fingerprintSchema, definitions, generatedSources, canonical, customBiomeStandIns),
|
||||
definitions, generatedSources, canonical, customBiomeStandIns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Records, per custom biome logical key, the platform biome that generates in its place because the running
|
||||
* server never loaded the custom biome's registry entry.
|
||||
*/
|
||||
public GenerationRegistryContract withCustomBiomeStandIns(Map<String, String> standIns) {
|
||||
NavigableMap<String, String> canonical = canonicalCustomBiomeStandIns(standIns, definitions);
|
||||
return new GenerationRegistryContract(fingerprintSchema,
|
||||
fingerprint(fingerprintSchema, definitions, generatedSources, biomeTags, canonical),
|
||||
definitions, generatedSources, biomeTags, canonical);
|
||||
}
|
||||
|
||||
public NavigableMap<String, List<String>> biomeTags() {
|
||||
return biomeTags;
|
||||
}
|
||||
|
||||
public NavigableMap<String, String> customBiomeStandIns() {
|
||||
return customBiomeStandIns;
|
||||
}
|
||||
|
||||
public int fingerprintSchema() {
|
||||
return fingerprintSchema;
|
||||
}
|
||||
@@ -186,19 +209,22 @@ public final class GenerationRegistryContract {
|
||||
tags.add(entry.getKey(), values);
|
||||
}
|
||||
json.add("biomeTags", tags);
|
||||
if (!customBiomeStandIns.isEmpty()) {
|
||||
JsonObject standIns = new JsonObject();
|
||||
customBiomeStandIns.forEach(standIns::addProperty);
|
||||
json.add(CUSTOM_BIOME_STAND_INS_FIELD, standIns);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
static GenerationRegistryContract fromJson(JsonObject json) {
|
||||
GenerationManifest.JsonSchema.requireFields(
|
||||
json,
|
||||
"registry contract",
|
||||
"fingerprintSchema",
|
||||
"fingerprint",
|
||||
"definitions",
|
||||
"generatedSources",
|
||||
"biomeTags"
|
||||
);
|
||||
boolean hasStandIns = json.has(CUSTOM_BIOME_STAND_INS_FIELD);
|
||||
List<String> fields = new ArrayList<>(List.of(
|
||||
"fingerprintSchema", "fingerprint", "definitions", "generatedSources", "biomeTags"));
|
||||
if (hasStandIns) {
|
||||
fields.add(CUSTOM_BIOME_STAND_INS_FIELD);
|
||||
}
|
||||
GenerationManifest.JsonSchema.requireFields(json, "registry contract", fields.toArray(String[]::new));
|
||||
int fingerprintSchema = GenerationManifest.JsonSchema.requireInt(
|
||||
json,
|
||||
"fingerprintSchema",
|
||||
@@ -237,7 +263,23 @@ public final class GenerationRegistryContract {
|
||||
}
|
||||
tags.put(entry.getKey(), names);
|
||||
}
|
||||
return new GenerationRegistryContract(fingerprintSchema, fingerprint, definitions, generatedSources, tags);
|
||||
Map<String, String> standIns = hasStandIns ? parseCustomBiomeStandIns(json) : Map.of();
|
||||
return new GenerationRegistryContract(
|
||||
fingerprintSchema, fingerprint, definitions, generatedSources, tags, standIns);
|
||||
}
|
||||
|
||||
private static Map<String, String> parseCustomBiomeStandIns(JsonObject json) {
|
||||
JsonObject encoded = GenerationManifest.JsonSchema.requireObject(
|
||||
json.get(CUSTOM_BIOME_STAND_INS_FIELD), "registry custom biome stand-ins");
|
||||
Map<String, String> standIns = new TreeMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : encoded.entrySet()) {
|
||||
JsonElement value = entry.getValue();
|
||||
if (!value.isJsonPrimitive() || !value.getAsJsonPrimitive().isString()) {
|
||||
throw new IllegalArgumentException("Registry custom biome stand-ins must map to resource keys.");
|
||||
}
|
||||
standIns.put(entry.getKey(), value.getAsString());
|
||||
}
|
||||
return standIns;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,12 +294,14 @@ public final class GenerationRegistryContract {
|
||||
&& fingerprint.equals(contract.fingerprint)
|
||||
&& definitions.equals(contract.definitions)
|
||||
&& generatedSources.equals(contract.generatedSources)
|
||||
&& biomeTags.equals(contract.biomeTags);
|
||||
&& biomeTags.equals(contract.biomeTags)
|
||||
&& customBiomeStandIns.equals(contract.customBiomeStandIns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(fingerprintSchema, fingerprint, definitions, generatedSources, biomeTags);
|
||||
return Objects.hash(fingerprintSchema, fingerprint, definitions, generatedSources, biomeTags,
|
||||
customBiomeStandIns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -503,14 +547,41 @@ public final class GenerationRegistryContract {
|
||||
return Collections.unmodifiableNavigableMap(normalized);
|
||||
}
|
||||
|
||||
private static NavigableMap<String, String> canonicalCustomBiomeStandIns(
|
||||
Map<String, String> values,
|
||||
Map<PhysicalResourceKey, String> definitions
|
||||
) {
|
||||
Map<String, String> required = Objects.requireNonNull(values, "customBiomeStandIns");
|
||||
if (required.size() > MAX_DEFINITIONS) {
|
||||
throw new IllegalArgumentException("Registry custom biome stand-ins contain too many biomes.");
|
||||
}
|
||||
TreeMap<String, String> normalized = new TreeMap<>();
|
||||
for (Map.Entry<String, String> entry : required.entrySet()) {
|
||||
String logicalKey = Objects.requireNonNull(entry.getKey(), "custom biome stand-in logical key");
|
||||
if (logicalKey.isBlank() || logicalKey.indexOf(':') < 1
|
||||
|| !logicalKey.equals(logicalKey.toLowerCase(Locale.ROOT))) {
|
||||
throw new IllegalArgumentException("Invalid custom biome stand-in logical key: " + logicalKey);
|
||||
}
|
||||
PhysicalResourceKey standIn = new PhysicalResourceKey(BIOME_REGISTRY, entry.getValue());
|
||||
if (!definitions.containsKey(standIn)) {
|
||||
throw new IllegalArgumentException("Custom biome stand-in has no matching biome definition: "
|
||||
+ entry.getValue());
|
||||
}
|
||||
normalized.put(logicalKey, standIn.resourceKey());
|
||||
}
|
||||
return Collections.unmodifiableNavigableMap(normalized);
|
||||
}
|
||||
|
||||
private static String fingerprint(
|
||||
int fingerprintSchema,
|
||||
NavigableMap<PhysicalResourceKey, String> definitions,
|
||||
NavigableMap<PhysicalResourceKey, GeneratedSource> generatedSources,
|
||||
NavigableMap<String, List<String>> biomeTags
|
||||
NavigableMap<String, List<String>> biomeTags,
|
||||
NavigableMap<String, String> customBiomeStandIns
|
||||
) {
|
||||
return switch (fingerprintSchema) {
|
||||
case FINGERPRINT_SCHEMA_VERSION_ONE -> fingerprintVersionOne(definitions, generatedSources, biomeTags);
|
||||
case FINGERPRINT_SCHEMA_VERSION_ONE ->
|
||||
fingerprintVersionOne(definitions, generatedSources, biomeTags, customBiomeStandIns);
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Unsupported generation registry fingerprint schema " + fingerprintSchema + "."
|
||||
);
|
||||
@@ -520,7 +591,8 @@ public final class GenerationRegistryContract {
|
||||
private static String fingerprintVersionOne(
|
||||
NavigableMap<PhysicalResourceKey, String> definitions,
|
||||
NavigableMap<PhysicalResourceKey, GeneratedSource> generatedSources,
|
||||
NavigableMap<String, List<String>> biomeTags
|
||||
NavigableMap<String, List<String>> biomeTags,
|
||||
NavigableMap<String, String> customBiomeStandIns
|
||||
) {
|
||||
MessageDigest digest = sha256();
|
||||
updateString(digest, FINGERPRINT_DOMAIN);
|
||||
@@ -550,6 +622,15 @@ public final class GenerationRegistryContract {
|
||||
updateString(digest, tag);
|
||||
}
|
||||
}
|
||||
// Contracts without stand-ins keep the fingerprint they had before stand-ins existed.
|
||||
if (!customBiomeStandIns.isEmpty()) {
|
||||
updateString(digest, CUSTOM_BIOME_STAND_INS_FIELD);
|
||||
updateInt(digest, customBiomeStandIns.size());
|
||||
for (Map.Entry<String, String> entry : customBiomeStandIns.entrySet()) {
|
||||
updateString(digest, entry.getKey());
|
||||
updateString(digest, entry.getValue());
|
||||
}
|
||||
}
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
}
|
||||
|
||||
|
||||
+218
-50
@@ -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");
|
||||
@@ -164,6 +208,7 @@ public final class GenerationRegistryContractFactory {
|
||||
Map<GenerationRegistryContract.PhysicalResourceKey, GenerationRegistryContract.GeneratedSource>
|
||||
generatedSources = new LinkedHashMap<>();
|
||||
Map<String, Set<String>> biomeTags = new TreeMap<>();
|
||||
Map<String, String> customBiomeStandIns = new TreeMap<>();
|
||||
String packName = requiredData.getDataFolder().getName();
|
||||
List<IrisBiome> reachableBiomes = new ArrayList<>(requiredDimension.getReachableBiomes(() -> requiredData));
|
||||
for (IrisDimension registryDimension : registryDimensions(requiredData, requiredDimension)) {
|
||||
@@ -201,7 +246,9 @@ public final class GenerationRegistryContractFactory {
|
||||
requiredFixer,
|
||||
requiredGenerationRegistry,
|
||||
requiredAliasPolicy,
|
||||
biomeTags
|
||||
biomeSelection,
|
||||
biomeTags,
|
||||
customBiomeStandIns
|
||||
);
|
||||
}
|
||||
addNativeStructures(
|
||||
@@ -214,7 +261,9 @@ public final class GenerationRegistryContractFactory {
|
||||
ReferencedPlatformKeys referenced = referencedPlatformKeys(packRoot, requiredRegistries);
|
||||
addPlatformDefinitions(definitions, BLOCK_REGISTRY, referenced.blockKeys(), requiredGenerationRegistry);
|
||||
addPlatformDefinitions(definitions, ENTITY_TYPE_REGISTRY, referenced.entityKeys(), requiredGenerationRegistry);
|
||||
GenerationRegistryContract captured = contract(definitions, generatedSources, requiredGenerationRegistry).withBiomeTags(biomeTags);
|
||||
GenerationRegistryContract captured = contract(definitions, generatedSources, requiredGenerationRegistry)
|
||||
.withBiomeTags(biomeTags)
|
||||
.withCustomBiomeStandIns(customBiomeStandIns);
|
||||
String actualPackFingerprint = GenerationPackFingerprint.compute(
|
||||
packRoot,
|
||||
GenerationPackFingerprint.CURRENT_VERSION
|
||||
@@ -379,30 +428,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 +451,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,7 +813,9 @@ public final class GenerationRegistryContractFactory {
|
||||
IDataFixer fixer,
|
||||
PlatformGenerationRegistry registry,
|
||||
CustomBiomeAliasPolicy aliasPolicy,
|
||||
Map<String, Set<String>> biomeTags
|
||||
CustomBiomeSelection biomeSelection,
|
||||
Map<String, Set<String>> biomeTags,
|
||||
Map<String, String> customBiomeStandIns
|
||||
) throws IOException {
|
||||
TreeSet<String> platformBiomeKeys = new TreeSet<>();
|
||||
Map<String, String> customResourceKeys = new LinkedHashMap<>();
|
||||
@@ -764,13 +833,21 @@ 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),
|
||||
biome.getVanillaDerivativeKey()
|
||||
);
|
||||
String logicalKey = dimensionKey.toLowerCase(Locale.ROOT)
|
||||
+ ":" + customBiomeId.toLowerCase(Locale.ROOT);
|
||||
if (selected.isStandIn()) {
|
||||
platformBiomeKeys.add(selected.standInKey());
|
||||
customBiomeStandIns.put(logicalKey, selected.standInKey());
|
||||
customResourceKeys.putIfAbsent(logicalKey, selected.standInKey());
|
||||
continue;
|
||||
}
|
||||
CustomBiomeDefinition generated = selected.definition();
|
||||
putGeneratedDefinition(
|
||||
definitions,
|
||||
generatedSources,
|
||||
@@ -782,20 +859,11 @@ 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);
|
||||
customResourceKeys.merge(
|
||||
logicalKey,
|
||||
generated.physicalKey().resourceKey(),
|
||||
@@ -844,6 +912,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 +1129,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 +1712,32 @@ 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() + ".");
|
||||
String standIn = contract.customBiomeStandIns()
|
||||
.get(dimension + ":" + requiredBiome.getId().toLowerCase(Locale.ROOT));
|
||||
if (standIn != null) {
|
||||
dimensionKeys.put(requiredBiome, standIn);
|
||||
return standIn;
|
||||
}
|
||||
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 +1772,70 @@ public final class GenerationRegistryContractFactory {
|
||||
|
||||
private record ReferencedPlatformKeys(Set<String> blockKeys, Set<String> entityKeys) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The registry key a retained epoch's datapack emits for a custom biome. A biome the epoch generates through a
|
||||
* stand-in has no recorded entry, so the datapack emits its current definition for the server to load.
|
||||
*/
|
||||
public static String retainedCustomBiomeResourceKey(
|
||||
GenerationRegistryContract retained,
|
||||
IrisDimension dimension,
|
||||
IrisBiomeCustom customBiome,
|
||||
String currentResourceKey
|
||||
) {
|
||||
String logicalKey = dimension.getLoadKey().toLowerCase(Locale.ROOT)
|
||||
+ ":" + customBiome.getId().toLowerCase(Locale.ROOT);
|
||||
if (retained.customBiomeStandIns().containsKey(logicalKey)) {
|
||||
return currentResourceKey;
|
||||
}
|
||||
return dimension.getLoader().customBiomeResourceKey(dimension, customBiome);
|
||||
}
|
||||
|
||||
public static String retainedGeneratedSource(
|
||||
GenerationRegistryContract retained,
|
||||
String registryKey,
|
||||
String resourceKey,
|
||||
String currentSource,
|
||||
IDataFixer fixer
|
||||
) throws IOException {
|
||||
GenerationRegistryContract.PhysicalResourceKey key = key(registryKey, resourceKey);
|
||||
boolean standInSource = BIOME_REGISTRY.equals(registryKey)
|
||||
&& !retained.customBiomeStandIns().isEmpty()
|
||||
&& !retained.definitions().containsKey(key);
|
||||
return standInSource ? currentSource : renderGeneratedSource(retained, key, fixer);
|
||||
}
|
||||
|
||||
interface CustomBiomeSelection {
|
||||
CustomBiomeSelection CURRENT =
|
||||
(dimensionKey, customBiomeId, current, standInKey) -> SelectedCustomBiome.current(current);
|
||||
|
||||
SelectedCustomBiome select(
|
||||
String dimensionKey,
|
||||
String customBiomeId,
|
||||
CustomBiomeDefinition current,
|
||||
String standInKey
|
||||
) throws IOException;
|
||||
}
|
||||
|
||||
record SelectedCustomBiome(CustomBiomeDefinition definition, Collection<String> loadedTags, String standInKey) {
|
||||
static SelectedCustomBiome current(CustomBiomeDefinition definition) {
|
||||
return new SelectedCustomBiome(definition, null, null);
|
||||
}
|
||||
|
||||
static SelectedCustomBiome loaded(CustomBiomeDefinition definition, Collection<String> tags) {
|
||||
return new SelectedCustomBiome(definition, List.copyOf(tags), null);
|
||||
}
|
||||
|
||||
static SelectedCustomBiome standIn(String platformBiomeKey) {
|
||||
return new SelectedCustomBiome(null, null, requireText(platformBiomeKey, "Stand-in biome key"));
|
||||
}
|
||||
|
||||
boolean retainsLoadedDefinition() {
|
||||
return loadedTags != null;
|
||||
}
|
||||
|
||||
boolean isStandIn() {
|
||||
return standInKey != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
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.
|
||||
* A biome with neither generates as its vanilla derivative until the server restarts and loads it.
|
||||
*/
|
||||
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> standIns = 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,
|
||||
String standInKey
|
||||
) 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) {
|
||||
return standIn(identity, standInKey);
|
||||
}
|
||||
GenerationRegistryContract.PhysicalResourceKey loadedKey = loadedKeys.getFirst();
|
||||
CustomBiomeDefinition loaded = loadedDefinition(loadedKey, identity);
|
||||
if (!isLoaded(loaded)) {
|
||||
return standIn(identity, standInKey);
|
||||
}
|
||||
deferred.put(identity.logicalKey(), identity);
|
||||
return SelectedCustomBiome.loaded(
|
||||
loaded,
|
||||
loadedContract.biomeTags().getOrDefault(loadedKey.resourceKey(), List.of())
|
||||
);
|
||||
}
|
||||
|
||||
private SelectedCustomBiome standIn(BiomeIdentity identity, String standInKey) throws IOException {
|
||||
if (standInKey == null || standInKey.isBlank()) {
|
||||
throw new IOException("Custom biome '" + identity.logicalKey() + "' is not loaded and has no vanilla derivative.");
|
||||
}
|
||||
standIns.add(identity.label());
|
||||
return SelectedCustomBiome.standIn(platformBiomeKey(standInKey));
|
||||
}
|
||||
|
||||
private static String platformBiomeKey(String key) {
|
||||
String normalized = key.trim().toLowerCase(Locale.ROOT);
|
||||
return normalized.indexOf(':') < 0 ? "minecraft:" + normalized : normalized;
|
||||
}
|
||||
|
||||
StudioRegistryCapture finish(GenerationRegistryContract contract) throws IOException {
|
||||
TreeSet<String> pending = new TreeSet<>(standIns);
|
||||
for (BiomeIdentity identity : deferred.values()) {
|
||||
if (recordedKeys(contract, identity).size() != 1) {
|
||||
throw new IOException("Custom biome '" + identity.logicalKey()
|
||||
+ "' has more than one definition in this Studio update.");
|
||||
}
|
||||
pending.add(identity.label());
|
||||
}
|
||||
return new StudioRegistryCapture(contract, List.copyOf(pending));
|
||||
}
|
||||
|
||||
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,15 @@
|
||||
package art.arcane.iris.world.history;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A Studio update's registry contract and the custom biomes that wait for a server restart to generate with their
|
||||
* latest definition.
|
||||
*/
|
||||
public record StudioRegistryCapture(GenerationRegistryContract contract, List<String> pendingBiomes) {
|
||||
public StudioRegistryCapture {
|
||||
contract = Objects.requireNonNull(contract, "contract");
|
||||
pendingBiomes = List.copyOf(pendingBiomes);
|
||||
}
|
||||
}
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " fehlgeschlagen {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bÖFFNET"
|
||||
restart_needed = "Neustart nötig: {value}"
|
||||
hotloaded_restart_needed = "§eStudio neu geladen · Neustart nötig: {value}"
|
||||
opening_progress = "§6Studio §bÖFFNET§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFEHLGESCHLAGEN§7 {percent}%"
|
||||
ready_progress = "§6Studio §aBEREIT§7 100%"
|
||||
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " fallidos {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bABRIENDO"
|
||||
restart_needed = "reinicio necesario: {value}"
|
||||
hotloaded_restart_needed = "§eStudio recargado en caliente · reinicio necesario: {value}"
|
||||
opening_progress = "§6Studio §bABRIENDO§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFALLÓ§7 {percent}%"
|
||||
ready_progress = "§6Studio §aLISTO§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " epäonnistui {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bAVATAAN"
|
||||
restart_needed = "uudelleenkäynnistys tarvitaan: {value}"
|
||||
hotloaded_restart_needed = "§eStudio ladattu uudelleen · uudelleenkäynnistys tarvitaan: {value}"
|
||||
opening_progress = "§6Studio §bAVATAAN§7 {percent}%"
|
||||
failed_progress = "§6Studio §cEPÄONNISTUI§7 {percent}%"
|
||||
ready_progress = "§6Studio §aVALMIS§7 100%"
|
||||
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " échecs {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bOUVERTURE"
|
||||
restart_needed = "redémarrage nécessaire : {value}"
|
||||
hotloaded_restart_needed = "§eStudio rechargé à chaud · redémarrage nécessaire : {value}"
|
||||
opening_progress = "§6Studio §bOUVERTURE§7 {percent}%"
|
||||
failed_progress = "§6Studio §cÉCHEC§7 {percent}%"
|
||||
ready_progress = "§6Studio §aPRÊT§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " נכשל {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bנפתח"
|
||||
restart_needed = "נדרשת הפעלה מחדש: {value}"
|
||||
hotloaded_restart_needed = "§eStudio נטען מחדש · נדרשת הפעלה מחדש: {value}"
|
||||
opening_progress = "§6Studio §bנפתח§7 {percent}%"
|
||||
failed_progress = "§6Studio §cנכשל§7 {percent}%"
|
||||
ready_progress = "§6Studio §aמוכן§7 100%"
|
||||
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " non riusciti {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bAPERTURA"
|
||||
restart_needed = "riavvio necessario: {value}"
|
||||
hotloaded_restart_needed = "§eStudio ricaricato a caldo · riavvio necessario: {value}"
|
||||
opening_progress = "§6Studio §bAPERTURA§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNON RIUSCITO§7 {percent}%"
|
||||
ready_progress = "§6Studio §aPRONTO§7 100%"
|
||||
|
||||
@@ -1586,6 +1586,8 @@ failed_fragment = " 失敗 {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bオープン中"
|
||||
restart_needed = "再起動が必要: {value}"
|
||||
hotloaded_restart_needed = "§eStudio をホットリロード · 再起動が必要: {value}"
|
||||
opening_progress = "§6Studio §bオープン中§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失敗§7 {percent}%"
|
||||
ready_progress = "§6Studio §a準備完了§7 100%"
|
||||
|
||||
@@ -1586,6 +1586,8 @@ failed_fragment = " 실패 {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §b여는 중"
|
||||
restart_needed = "재시작 필요: {value}"
|
||||
hotloaded_restart_needed = "§eStudio 핫 리로드 완료 · 재시작 필요: {value}"
|
||||
opening_progress = "§6Studio §b여는 중§7 {percent}%"
|
||||
failed_progress = "§6Studio §c실패§7 {percent}%"
|
||||
ready_progress = "§6Studio §a준비 완료§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " nepavyko {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bATIDAROMA"
|
||||
restart_needed = "reikia paleisti iš naujo: {value}"
|
||||
hotloaded_restart_needed = "§eStudio įkelta iš naujo · reikia paleisti iš naujo: {value}"
|
||||
opening_progress = "§6Studio §bATIDAROMA§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNEPAVYKO§7 {percent}%"
|
||||
ready_progress = "§6Studio §aPARUOŠTA§7 100%"
|
||||
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " mislukt {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bOPENEN"
|
||||
restart_needed = "herstart nodig: {value}"
|
||||
hotloaded_restart_needed = "§eStudio opnieuw geladen · herstart nodig: {value}"
|
||||
opening_progress = "§6Studio §bOPENEN§7 {percent}%"
|
||||
failed_progress = "§6Studio §cMISLUKT§7 {percent}%"
|
||||
ready_progress = "§6Studio §aGEREED§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " nieudane {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bOTWIERANIE"
|
||||
restart_needed = "wymagany restart: {value}"
|
||||
hotloaded_restart_needed = "§eStudio ponownie wczytane · wymagany restart: {value}"
|
||||
opening_progress = "§6Studio §bOTWIERANIE§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNIEPOWODZENIE§7 {percent}%"
|
||||
ready_progress = "§6Studio §aGOTOWE§7 100%"
|
||||
|
||||
@@ -1583,6 +1583,8 @@ failed_fragment = " falhou {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bA ABRIR"
|
||||
restart_needed = "reinício necessário: {value}"
|
||||
hotloaded_restart_needed = "§eStudio recarregado · reinício necessário: {value}"
|
||||
opening_progress = "§6Studio §bA ABRIR§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFALHOU§7 {percent}%"
|
||||
ready_progress = "§6Studio §aPRONTO§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " ошибок {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bОТКРЫТИЕ"
|
||||
restart_needed = "нужен перезапуск: {value}"
|
||||
hotloaded_restart_needed = "§eStudio перезагружена · нужен перезапуск: {value}"
|
||||
opening_progress = "§6Studio §bОТКРЫТИЕ§7 {percent}%"
|
||||
failed_progress = "§6Studio §cОШИБКА§7 {percent}%"
|
||||
ready_progress = "§6Studio §aГОТОВО§7 100%"
|
||||
|
||||
@@ -1588,6 +1588,8 @@ failed_fragment = " başarısız {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bAÇILIYOR"
|
||||
restart_needed = "yeniden başlatma gerekli: {value}"
|
||||
hotloaded_restart_needed = "§eStudio yeniden yüklendi · yeniden başlatma gerekli: {value}"
|
||||
opening_progress = "§6Studio §bAÇILIYOR§7 {percent}%"
|
||||
failed_progress = "§6Studio §cBAŞARISIZ§7 {percent}%"
|
||||
ready_progress = "§6Studio §aHAZIR§7 100%"
|
||||
|
||||
@@ -1586,6 +1586,8 @@ failed_fragment = " lỗi {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §bĐANG MỞ"
|
||||
restart_needed = "cần khởi động lại: {value}"
|
||||
hotloaded_restart_needed = "§eĐã tải lại Studio · cần khởi động lại: {value}"
|
||||
opening_progress = "§6Studio §bĐANG MỞ§7 {percent}%"
|
||||
failed_progress = "§6Studio §cTHẤT BẠI§7 {percent}%"
|
||||
ready_progress = "§6Studio §aSẴN SÀNG§7 100%"
|
||||
|
||||
@@ -1586,6 +1586,8 @@ failed_fragment = " 失败 {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §b正在打开"
|
||||
restart_needed = "需要重启:{value}"
|
||||
hotloaded_restart_needed = "§eStudio 已热重载 · 需要重启:{value}"
|
||||
opening_progress = "§6Studio §b正在打开§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失败§7 {percent}%"
|
||||
ready_progress = "§6Studio §a就绪§7 100%"
|
||||
|
||||
@@ -1586,6 +1586,8 @@ failed_fragment = " 失敗 {failed}"
|
||||
|
||||
[iris.runtime.studio]
|
||||
opening = "§6Studio §b正在開啟"
|
||||
restart_needed = "需要重新啟動:{value}"
|
||||
hotloaded_restart_needed = "§eStudio 已熱重載 · 需要重新啟動:{value}"
|
||||
opening_progress = "§6Studio §b正在開啟§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失敗§7 {percent}%"
|
||||
ready_progress = "§6Studio §a就緒§7 100%"
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
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 noPendingBiomesMeansNothingIsPending() {
|
||||
assertFalse(StudioRestartRequirement.pending(List.of()).isPending());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void summaryListsTheFirstBiomesAndCountsTheRest() {
|
||||
StudioRestartRequirement requirement = StudioRestartRequirement.pending(List.of("ash", "dunes", "fog", "mist"));
|
||||
|
||||
assertTrue(requirement.isPending());
|
||||
assertEquals("ash, dunes, fog +1", requirement.biomeSummary());
|
||||
}
|
||||
}
|
||||
+3
@@ -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));
|
||||
|
||||
+2
@@ -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);
|
||||
|
||||
+132
@@ -977,6 +977,138 @@ 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.pendingBiomes());
|
||||
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.pendingBiomes());
|
||||
assertNotEquals(loadedKey, fixture.resolve(current.contract(), edited));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioUpdateGeneratesABiomeTheServerNeverLoadedAsItsVanillaDerivative() 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);
|
||||
String vanillaDerivative = fixture.vanillaDerivativeKey();
|
||||
|
||||
StudioRegistryCapture update = fixture.captureStudioUpdate(active, editedMist, ash);
|
||||
|
||||
assertEquals(List.of("ash", "mist"), update.pendingBiomes());
|
||||
assertEquals(Map.of("overworld:ash", vanillaDerivative), update.contract().customBiomeStandIns());
|
||||
assertTrue(update.contract().definitions().containsKey(
|
||||
key(GenerationRegistryContractFactory.BIOME_REGISTRY, vanillaDerivative)));
|
||||
assertEquals(vanillaDerivative, fixture.resolve(update.contract(), ash));
|
||||
assertEquals(fixture.resolve(active, mist), fixture.resolve(update.contract(), editedMist));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainedDatapackEmitsTheCurrentDefinitionOfAStandInBiome() throws Exception {
|
||||
StudioPackFixture fixture = new StudioPackFixture(temporary.newFolder("studio-stand-in-datapack"));
|
||||
GenerationRegistryContract active = fixture.capture(new IrisBiomeCustom().setId("mist").setTemperature(0.5D));
|
||||
fixture.loadIntoServer(active);
|
||||
GenerationRegistryContract update = fixture.captureStudioUpdate(active,
|
||||
new IrisBiomeCustom().setId("mist").setTemperature(0.5D),
|
||||
new IrisBiomeCustom().setId("ash").setTemperature(1.5D)).contract();
|
||||
GenerationRegistryContract.PhysicalResourceKey recorded = update.generatedSources().firstKey();
|
||||
|
||||
assertEquals("current", GenerationRegistryContractFactory.retainedGeneratedSource(
|
||||
update, GenerationRegistryContractFactory.BIOME_REGISTRY, "test:biomes/ash-current", "current",
|
||||
fixture.fixer));
|
||||
assertEquals(GenerationRegistryContractFactory.renderGeneratedSource(update, recorded, fixture.fixer),
|
||||
GenerationRegistryContractFactory.retainedGeneratedSource(
|
||||
update, recorded.registryKey(), recorded.resourceKey(), "current", fixture.fixer));
|
||||
assertThrows(IOException.class, () -> GenerationRegistryContractFactory.retainedGeneratedSource(
|
||||
active, GenerationRegistryContractFactory.BIOME_REGISTRY, "test:biomes/ash-current", "current",
|
||||
fixture.fixer));
|
||||
}
|
||||
|
||||
@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 String vanillaDerivativeKey() {
|
||||
return biome.getVanillaDerivativeKey();
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceLoader<IrisDimension> stubDimensions(IrisData data, IrisDimension dimension) {
|
||||
ResourceLoader<IrisDimension> loader = mock(ResourceLoader.class);
|
||||
String dimensionKey = dimension.getLoadKey();
|
||||
|
||||
@@ -65,6 +65,25 @@ public class GenerationRegistryContractTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> base.withBiomeTags(Map.of("iris:missing", List.of("iris:humid"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customBiomeStandInsArePersistedAndFingerprintProtectedOnlyWhenPresent() {
|
||||
GenerationRegistryContract base = GenerationRegistryContract.fromDefinitions(
|
||||
Map.of(key("minecraft:worldgen/biome", "minecraft:plains"), DEFINITION_A));
|
||||
GenerationRegistryContract unchanged = base.withCustomBiomeStandIns(Map.of());
|
||||
assertEquals(base.fingerprint(), unchanged.fingerprint());
|
||||
assertEquals(false, unchanged.toJson().has("customBiomeStandIns"));
|
||||
|
||||
GenerationRegistryContract standIn = base.withCustomBiomeStandIns(Map.of("overworld:ash", "minecraft:plains"));
|
||||
assertEquals(Map.of("overworld:ash", "minecraft:plains"), standIn.customBiomeStandIns());
|
||||
assertNotEquals(base.fingerprint(), standIn.fingerprint());
|
||||
assertEquals(standIn, GenerationRegistryContract.fromJson(standIn.toJson()));
|
||||
JsonObject tampered = standIn.toJson();
|
||||
tampered.getAsJsonObject("customBiomeStandIns").addProperty("overworld:ash", "minecraft:desert");
|
||||
assertThrows(IllegalArgumentException.class, () -> GenerationRegistryContract.fromJson(tampered));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> base.withCustomBiomeStandIns(Map.of("overworld:ash", "minecraft:desert")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void derivesStableFingerprintIndependentOfMapIterationOrder() {
|
||||
GenerationRegistryContract.PhysicalResourceKey plains = key(
|
||||
|
||||
Reference in new issue
Block a user