Merge master into 3D terrain

- Resolve IrisTerrainNormalActuator by keeping master's primitive riverWaterSurfaceStream lookup and primarySurfaceLayerOrNull accessors while retaining the terrain column, span, layer surface and ceiling locals that write air through terrain3D gaps
- Resolve HydrologyFootprintCompiler by keeping the MaterializedSurface planned-surface record with terrain ownership beside master's package-private SurfaceRasterIndex, which retains its ownsTerrain override
- Resolve HydrologyCaveContainmentPlanner by dropping the nested RecordingCaveVoxelView, SurfaceObservations and ViewObservations types that master promoted to their own files
- Port the surface-observation ownership check into CaveSurfaceObservations so cached cave validations replay both height and ownership observations through Observation.matches
- Resolve PackExportClosureTest by keeping master's retirement of the source-text packager guard while retaining the snippet export tests, and restore the Files and Path imports those tests use
- Resolve IrisBiomeLayerSlopeSourceTest by folding the lower-ledge slope palette case into master's lockLayers parameterization
- Recapture the studio schema digest for the terrain3D biome property, its IrisTerrain3D definition, the terrain-3d snippet enumeration and the reworded upperDimensionCarving description, verified by reconstructing the previous digest from the stripped schema
This commit is contained in:
Brian Neumann-Fopiano committed 2026-09-08 13:58:00 -04:00
commit 98e51cba8d
520 files changed
+45623 -40734

No files matched your search

@@ -32,6 +32,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import java.util.function.IntConsumer;
import static org.junit.Assert.assertEquals;
@@ -218,7 +219,7 @@ public class NativeStructureVolumeIndexTest {
if (cleared) {
break;
}
Thread.sleep(1);
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10L));
}
assertTrue("Origin eviction did not complete before the query cache lock", cleared);
resolver.release();
@@ -6,6 +6,7 @@ import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.iris.testsupport.PlatformLeakGuard;
import net.minecraft.SharedConstants;
import net.minecraft.core.Direction;
import net.minecraft.server.Bootstrap;
@@ -16,6 +17,7 @@ import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.levelgen.Heightmap;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.MockedStatic;
@@ -30,6 +32,9 @@ import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
public final class NativeTransitionColumnTest {
@Rule
public final PlatformLeakGuard leakGuard = PlatformLeakGuard.clean();
@BeforeClass
public static void bootstrap() {
SharedConstants.tryDetectVersion();
+1 -8
View File
@@ -22,6 +22,7 @@ dependencies {
testImplementation(libs.paper.api)
testImplementation(libs.bstats)
testImplementation(project(':core'))
testImplementation(testFixtures(project(':core')))
testImplementation(volmLibCoordinate) {
transitive = false
}
@@ -59,12 +60,4 @@ tasks.named('jar', Jar).configure {
}
tasks.named('test').configure {
systemProperty('iris.pregeneratorJobSource', rootProject.file('core/src/main/java/art/arcane/iris/core/gui/PregeneratorJob.java').absolutePath)
systemProperty('iris.bukkitEnginePlatformHooksSource', file('src/main/java/art/arcane/iris/core/runtime/BukkitEnginePlatformHooks.java').absolutePath)
systemProperty('iris.engineSvcSource', file('src/main/java/art/arcane/iris/core/service/IrisEngineSVC.java').absolutePath)
systemProperty('iris.terrainSvcSource', file('src/main/java/art/arcane/iris/core/service/IrisTerrainSVC.java').absolutePath)
systemProperty('iris.apiEventSvcSource', file('src/main/java/art/arcane/iris/core/service/IrisApiEventSVC.java').absolutePath)
systemProperty('iris.worldInfoFactorySource', file('src/main/java/art/arcane/iris/core/service/terrain/IrisWorldInfoFactory.java').absolutePath)
systemProperty('iris.startupSource', file('src/main/java/art/arcane/iris/Iris.java').absolutePath)
systemProperty('iris.readmeSource', rootProject.file('README.md').absolutePath)
}
@@ -39,6 +39,7 @@ import art.arcane.iris.core.SettingsHotloadWatch;
import art.arcane.iris.core.ServerConfigurator;
import art.arcane.iris.core.datapack.DatapackIngestService;
import art.arcane.iris.core.datapack.DatapackIngestService.StartupValidationOutcome;
import art.arcane.iris.core.lifecycle.IrisRuntimeStatics;
import art.arcane.iris.core.lifecycle.ManagedWorldLoader;
import art.arcane.iris.core.lifecycle.MissingWorldStorageLog;
import art.arcane.iris.core.lifecycle.PaperLibBootstrap;
@@ -87,6 +88,7 @@ import art.arcane.iris.engine.framework.PreservationRegistry;
import art.arcane.iris.engine.framework.TreeBlockMaterial;
import art.arcane.iris.engine.object.IrisCompat;
import art.arcane.iris.core.safeguard.IrisSafeguard;
import art.arcane.iris.core.safeguard.RuntimeLockNotice;
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
import art.arcane.iris.platform.bukkit.BukkitPlatform;
import art.arcane.iris.spi.IrisLogging;
@@ -147,6 +149,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -159,6 +162,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@SuppressWarnings("CanBeFinal")
public class Iris extends VolmitPlugin implements Listener, ReloadAware {
@@ -215,16 +219,23 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
private volatile ServerShutdownBoundary serverShutdownBoundary;
public static VolmitSender getSender() {
if (sender == null) {
sender = new VolmitSender(Bukkit.getConsoleSender());
sender.setTag(instance.getTag());
VolmitSender current = sender;
if (current == null) {
Iris plugin = instance;
current = new VolmitSender(Bukkit.getConsoleSender());
current.setTag(plugin == null ? IrisSafeguard.mode().tag("") : plugin.getTag());
sender = current;
}
return sender;
return current;
}
@SuppressWarnings("unchecked")
public static <T> T service(Class<T> c) {
return (T) instance.services.get(c);
Iris plugin = instance;
if (plugin == null || plugin.services == null) {
throw new IllegalStateException("Iris is disabled; " + c.getSimpleName() + " is unavailable");
}
return (T) plugin.services.get(c);
}
public static void callEvent(Event e) {
@@ -263,7 +274,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
}
public static File getTemp() {
return instance.getDataFolder("cache", "temp");
Iris plugin = instance;
if (plugin == null) {
throw new IllegalStateException("Iris is disabled; the temp folder is unavailable");
}
return plugin.getDataFolder("cache", "temp");
}
public static void msg(String string) {
@@ -305,10 +320,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
return;
}
StackWalker.StackFrame frame = null;
StackWalker.StackFrame frame;
try {
frame = DEBUG_STACK_WALKER.walk(stream -> stream.skip(1).findFirst().orElse(null));
} catch (Throwable ignored) {
} catch (Throwable unavailable) {
frame = null;
}
if (frame == null) {
@@ -444,7 +460,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
try {
IrisSettings currentSettings = IrisSettings.settings != null ? IrisSettings.settings : IrisSettings.get();
debug = currentSettings != null && currentSettings.getGeneral().isDebug();
} catch (Throwable ignored) {
} catch (Throwable unreadable) {
debug = false;
}
}
@@ -541,11 +557,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
Iris::msg,
Iris::reportError,
(event) -> Iris.callEvent((org.bukkit.event.Event) event),
() -> Iris.instance.getDataFolder(),
(path) -> Iris.instance.getDataFile(path),
() -> Iris.instance.getJarFile(),
() -> Iris.instance.getIrisVersion(),
() -> Iris.instance.getMCVersion()));
this::getDataFolder,
this::getDataFile,
this::getJarFile,
this::getIrisVersion,
this::getMCVersion));
SlimJar.load();
}
@@ -612,6 +628,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
J.s(() -> Bukkit.getPluginManager().disablePlugin(this), 1);
return false;
}
EnableTimings timings = new EnableTimings();
alreadyDrained.set(false);
postStopFinisherStarted.set(false);
serverStopTeardownDeferred.set(false);
@@ -625,12 +642,15 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
MultiBurst.burst.reopen();
MultiBurst.ioBurst.reopen();
IrisLanguage.initialize();
debugDump = BukkitDebugDump.create(this);
debugDump = BukkitDebugDump.create(this, new BukkitDebugDump.Options(
() -> true,
() -> IrisSafeguard::debugReport));
languageSwitcher = BukkitLanguageSwitcher.register(this, IrisLanguage.selections(),
new BukkitLanguageSwitcher.Options("iris", "iris.all",
DirectorMiniMenu.Theme.irisGreen(), IrisLanguage.directorResolver(), IrisLanguage.editorOptions()));
PaperLibBootstrap.install();
SimdSupport.install();
timings.mark("bootstrap");
services = new KMap<>();
BukkitPlatform.hostHud(new HudActionBar(this), new HudBossBarLane());
// Explicit, ordered service list: the previous reflective jar scan gave hash-ordered
@@ -669,9 +689,13 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
IrisServices.register(PreservationRegistry.class, services.get(PreservationSVC.class));
compat = IrisCompat.configured(getDataFile("compat.json"));
IrisServices.register(IrisCompat.class, compat);
timings.mark("services");
ServerConfigurator.configure();
timings.mark("serverConfig");
StartupValidationOutcome datapackValidation = DatapackIngestService.validateOnStartup();
timings.mark("datapacks");
IrisSafeguard.execute();
timings.mark("safeguard");
getSender().setTag(getTag());
// A cosmetic banner must never abort the bootstrap.
J.attempt(this::splash);
@@ -680,6 +704,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
// Paper's bootstrap runs before any plugin logger exists, so orphan-storage warnings raised there
// never reach logs/latest.log. Replay them once now that the platform log is up.
MissingWorldStorageLog.replayToPlatformLog();
timings.mark("splash");
tickets = new ChunkTickets();
linkMultiverseCore = new MultiverseCoreLink();
IrisServices.register(MultiverseCoreLink.class, linkMultiverseCore);
@@ -692,18 +717,21 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
IrisServices.register(ManagedWorldLoader.class, (ManagedWorldLoader) this::loadManagedWorld);
SettingsHotloadWatch watch = new SettingsHotloadWatch(getDataFile("iris.json"));
settingsHotloadWatch = watch;
// Stale-temp cleanup must complete before services enable: StudioSVC.onEnable downloads
// packs through cache/temp on an async thread, and a concurrent delete of that folder
// truncated pack imports mid-copy (partial packs/<key> without dimensions/).
IO.delete(getTemp());
StudioSVC.gateDownloadsOnStaleTempCleanup(MultiBurst.ioBurst.completeValueAsync(() -> {
IO.delete(getTemp());
return null;
}));
timings.mark("tempSweep");
// One throwing service must not abort the bootstrap: the steps after this loop
// (listeners, shutdown hook, replacement journals) are the safety-critical ones.
// Only services that actually enabled get listeners and a later onDisable.
enabledServices.clear();
for (IrisService service : orderedServices) {
long serviceStartedAt = System.nanoTime();
try {
service.onEnable();
enabledServices.add(service);
timings.markService(service.getClass().getSimpleName(), serviceStartedAt);
} catch (Throwable e) {
// A service failure is NOT a datapack validation failure: the admission gate
// must never lock every login over a broken cosmetic service. Log loudly,
@@ -724,10 +752,12 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
Iris.reportError("Failed to register listener for " + service.getClass().getSimpleName() + ".", e);
}
}
timings.mark("serviceEnable");
if (datapackValidation == StartupValidationOutcome.READY) {
IrisServices.get(ExternalDataSVC.class).setContentChangeListener(generatorResolver::requestExternalContentRefresh);
generatorResolver.validateAllPacks();
}
timings.mark("packValidation");
addShutdownHook();
pendingWorldReplacements.processPendingStartupReplacements();
pendingWorldDeletes.processPendingStartupWorldDeletes();
@@ -755,9 +785,46 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
// match a slice type; the block-state slice is deliberately never retainable (regenerable, huge).
IrisToolbelt.retainMantleDataForSlice(TreeBlockMaterial.class.getCanonicalName());
});
timings.mark("startupTasks");
timings.report();
return true;
}
private static final class EnableTimings {
private static final int REPORTED_SERVICES = 3;
private final long startedAt = System.nanoTime();
private final StringBuilder phases = new StringBuilder();
private final Map<String, Long> serviceMillis = new LinkedHashMap<>();
private long lastMark = startedAt;
private void mark(String phase) {
long now = System.nanoTime();
if (!phases.isEmpty()) {
phases.append(' ');
}
phases.append(phase).append('=').append(TimeUnit.NANOSECONDS.toMillis(now - lastMark)).append("ms");
lastMark = now;
}
private void markService(String service, long serviceStartedAt) {
serviceMillis.put(service, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - serviceStartedAt));
}
private void report() {
IrisLogging.notice("Enabled in %dms (%s)",
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startedAt), phases);
String slowest = serviceMillis.entrySet().stream()
.sorted(Map.Entry.<String, Long>comparingByValue().reversed())
.limit(REPORTED_SERVICES)
.map(entry -> entry.getKey() + "=" + entry.getValue() + "ms")
.collect(Collectors.joining(" "));
if (!slowest.isBlank()) {
IrisLogging.notice("Slowest services: %s", slowest);
}
}
}
private void reconcileStartupWorlds() {
generatorResolver.startupWorldsReady().whenComplete((ignored, failure) -> {
if (failure != null) {
@@ -866,6 +933,25 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
.orElse("Iris startup validation requires a restart.");
startupBoundaryRestart.set(true);
ServerConfigurator.restartAtStartupBoundary(restartReason);
return;
}
reportLockedRuntime();
}
private static void reportLockedRuntime() {
String denial = IrisStartupValidation.denialReason().orElse(null);
if (denial == null) {
return;
}
boolean managedStorage;
try {
managedStorage = IrisWorldStorage.hasManagedWorldStorage(IrisWorldStorage.levelRoot());
} catch (Throwable unavailable) {
Iris.reportError("Could not inspect Iris world storage while reporting the locked runtime.", unavailable);
managedStorage = false;
}
for (String line : RuntimeLockNotice.compose(denial, managedStorage)) {
Iris.error(line);
}
}
@@ -1027,10 +1113,19 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
Iris.reportError("Failed to close Iris I/O workers.", failure);
}
clearQueues();
IrisServices.clear();
IrisRuntimeStatics.reset();
releaseStatics();
}
}
private static void releaseStatics() {
linkMultiverseCore = null;
compat = null;
tickets = null;
sender = null;
instance = null;
}
private void quiesceRuntimeForServerShutdown(String reason) {
serverStopTeardownDeferred.set(true);
INMS.get().deferPluginClassLoaderClose();
@@ -1173,6 +1268,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
failure.printStackTrace(SHUTDOWN_ERRORS);
}
}
BukkitPlatform.releaseHost();
}
}
@@ -1367,7 +1463,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
}
public int getIrisVersion() {
String input = Iris.instance.getDescription().getVersion();
String input = getDescription().getVersion();
int hyphenIndex = input.indexOf('-');
if (hyphenIndex != -1) {
String result = input.substring(0, hyphenIndex);
@@ -30,6 +30,7 @@ import art.arcane.iris.core.pack.PackValidationCache;
import art.arcane.iris.core.pack.PackValidationRegistry;
import art.arcane.iris.core.pack.PackValidationResult;
import art.arcane.iris.core.pack.PackValidator;
import art.arcane.iris.core.runtime.RuntimeInjection;
import art.arcane.iris.core.service.ExternalDataSVC;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
@@ -486,17 +487,20 @@ public final class IrisWorldGeneratorResolver {
Iris.debug("Generator discovery probe for loaded world " + worldName);
return IrisFailClosedChunkGenerator.discoveryProbe(worldName);
}
Optional<String> startupDenial = IrisStartupValidation.denialReason();
if (startupDenial.isPresent()) {
Iris.warn("Keeping configured Iris world '" + worldName
+ "' generation-locked: " + startupDenial.get());
return IrisFailClosedChunkGenerator.startupLock(worldName, startupDenial.get());
ChunkGenerator startupLock = startupLockedGenerator(worldName);
if (startupLock != null) {
return startupLock;
}
ChunkGenerator stagedGenerator = WorldLifecycleStaging.consumeGenerator(worldName);
if (stagedGenerator != null) {
Iris.debug("Using staged runtime generator for " + worldName);
return stagedGenerator;
}
RuntimeInjection.installIfDeferred();
startupLock = startupLockedGenerator(worldName);
if (startupLock != null) {
return startupLock;
}
Iris.debug("Default World Generator Called for " + worldName + " using ID: " + id);
if (id == null || id.isEmpty()) id = IrisSettings.get().getGenerator().getDefaultWorldType();
Iris.debug("Generator ID: " + id + " requested by bukkit/plugin");
@@ -516,6 +520,17 @@ public final class IrisWorldGeneratorResolver {
}
}
@Nullable
private static ChunkGenerator startupLockedGenerator(String worldName) {
Optional<String> startupDenial = IrisStartupValidation.denialReason();
if (startupDenial.isEmpty()) {
return null;
}
Iris.warn("Keeping configured Iris world '" + worldName
+ "' generation-locked: " + startupDenial.get());
return IrisFailClosedChunkGenerator.startupLock(worldName, startupDenial.get());
}
private static boolean isPlotSquaredGeneratorDiscoveryProbe(String worldName, String id) {
return PLOT_SQUARED_DISCOVERY_WORLD.equals(worldName) && id != null && id.isEmpty();
}
@@ -1104,7 +1104,8 @@ public final class PendingWorldReplacementManager implements Listener {
Iris.instance.getServer().getAllowEnd()
);
} catch (Throwable failure) {
Iris.debug("Could not capture vanilla-slot availability yet: " + detail(failure));
Iris.reportError("Could not capture vanilla-slot availability at startup;"
+ " world replacement staging will resolve it on demand.", failure);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,424 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.Iris;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.structure.authoring.StructureKey;
import art.arcane.iris.core.structure.authoring.StructureOwnershipManifest;
import art.arcane.iris.core.structure.authoring.StructureTransactionWriter;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionDiagnostic;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionInputKind;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionPlan;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionRequest;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionResult;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionService;
import art.arcane.iris.core.structure.conversion.IrisStructureAdoptionStrategy;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.iris.util.common.format.C;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.DirectorParameterHandler;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@Director(name = "adopt", description = "Inspect and apply safe ownership adoption plans",
origin = DirectorOrigin.PLAYER)
public class CommandJigsawAdopt implements DirectorExecutor {
private static final Map<UUID, AdoptionPlanBinding> ADOPTION_PLANS = new ConcurrentHashMap<>();
private static final Map<Path, IrisStructureAdoptionService> ADOPTION_SERVICES = new ConcurrentHashMap<>();
@Director(description = "Inspect an Iris graph for safe Studio ownership adoption", sync = true,
origin = DirectorOrigin.PLAYER)
public void inspect(
@Param(description = "Pack dimension") IrisDimension dimension,
@Param(description = "Existing Iris structure key") String source,
@Param(description = "New owned Iris key, or auto", defaultValue = "auto") String target,
@Param(description = "auto, in-place, or clone", defaultValue = "auto",
customHandler = JigsawAdoptionStrategyHandler.class) String strategy
) {
VolmitSender commandSender = sender();
IrisData data = CommandJigsaw.requireData(dimension, commandSender);
if (data == null) {
return;
}
String sourceKey;
Optional<StructureKey> targetKey;
IrisStructureAdoptionStrategy adoptionStrategy;
Path root;
try {
sourceKey = parseAdoptionSource(source);
targetKey = parseAdoptionTarget(target);
adoptionStrategy = parseAdoptionStrategy(strategy);
root = canonicalAdoptionRoot(data.getDataFolder().toPath());
} catch (IOException | IllegalArgumentException exception) {
CommandJigsaw.sendError(commandSender, "Could not inspect adoption source: " + exception.getMessage());
return;
}
Player targetPlayer = player();
UUID ownerId = targetPlayer.getUniqueId();
commandSender.sendMessage(C.GRAY + "Inspecting Jigsaw adoption source '" + sourceKey
+ "' asynchronously...");
try {
J.a(() -> runAdoptionInspect(
targetPlayer,
commandSender,
ownerId,
dimension,
data,
root,
sourceKey,
targetKey,
adoptionStrategy));
} catch (RuntimeException exception) {
Iris.reportError("Failed to schedule Jigsaw adoption inspection for '"
+ sourceKey + "'.", exception);
CommandJigsaw.sendError(commandSender, "Jigsaw adoption inspection could not be scheduled: "
+ exception.getMessage());
}
}
@Director(description = "Apply one inspected adoption plan without overwriting", sync = true,
origin = DirectorOrigin.PLAYER)
public void apply(
@Param(description = "Plan UUID returned by adopt inspect",
customHandler = JigsawAdoptionPlanHandler.class) String planId
) {
VolmitSender commandSender = sender();
UUID parsedPlanId;
try {
parsedPlanId = UUID.fromString(planId);
} catch (IllegalArgumentException exception) {
CommandJigsaw.sendError(commandSender, "Adoption plan ID must be a UUID.");
return;
}
if (CommandJigsaw.studioIsActiveOrOpening()) {
CommandJigsaw.sendError(commandSender,
"Close the active or opening Jigsaw Studio before applying an adoption plan.");
return;
}
pruneAdoptionPlanBindings();
AdoptionPlanBinding binding = ADOPTION_PLANS.get(parsedPlanId);
UUID playerId = player().getUniqueId();
if (binding == null || !binding.ownerId().equals(playerId)) {
CommandJigsaw.sendError(commandSender, "No active adoption plan '" + parsedPlanId
+ "' belongs to your player session. Run adopt inspect again.");
return;
}
if (binding.service().plan(parsedPlanId).isEmpty()) {
ADOPTION_PLANS.remove(parsedPlanId, binding);
CommandJigsaw.sendError(commandSender, "Adoption plan '" + parsedPlanId
+ "' expired or was already consumed. Run adopt inspect again.");
return;
}
if (!ADOPTION_PLANS.remove(parsedPlanId, binding)) {
CommandJigsaw.sendError(commandSender, "Adoption plan '" + parsedPlanId + "' is already being applied.");
return;
}
Player targetPlayer = player();
commandSender.sendMessage(C.GRAY + "Applying adoption plan '" + parsedPlanId
+ "' asynchronously without overwrite...");
try {
J.a(() -> runAdoptionApply(targetPlayer, commandSender, parsedPlanId, binding));
} catch (RuntimeException exception) {
ADOPTION_PLANS.putIfAbsent(parsedPlanId, binding);
Iris.reportError("Failed to schedule Jigsaw adoption plan '" + parsedPlanId + "'.", exception);
CommandJigsaw.sendError(commandSender, "Jigsaw adoption could not be scheduled: " + exception.getMessage());
}
}
private static void pruneAdoptionPlanBindings() {
for (Map.Entry<UUID, AdoptionPlanBinding> entry : ADOPTION_PLANS.entrySet()) {
AdoptionPlanBinding binding = entry.getValue();
if (binding.service().plan(entry.getKey()).isEmpty()) {
ADOPTION_PLANS.remove(entry.getKey(), binding);
}
}
}
private static void runAdoptionApply(
Player targetPlayer,
VolmitSender commandSender,
UUID planId,
AdoptionPlanBinding binding
) {
if (CommandJigsaw.studioIsActiveOrOpening()) {
ADOPTION_PLANS.putIfAbsent(planId, binding);
J.runEntity(targetPlayer, () -> CommandJigsaw.sendError(commandSender,
"Close the active or opening Jigsaw Studio before applying an adoption plan."));
return;
}
IrisStructureAdoptionResult result;
Throwable failure = null;
try {
result = binding.service().apply(binding.plan());
} catch (Throwable throwable) {
result = null;
failure = throwable;
Iris.reportError("Failed to apply Jigsaw adoption plan '" + planId + "'.", throwable);
}
IrisStructureAdoptionResult completedResult = result;
Throwable completedFailure = failure;
J.runEntity(targetPlayer, () -> finishAdoptionApply(
targetPlayer,
commandSender,
binding,
completedResult,
completedFailure));
}
private static void runAdoptionInspect(
Player targetPlayer,
VolmitSender commandSender,
UUID ownerId,
IrisDimension dimension,
IrisData data,
Path root,
String sourceKey,
Optional<StructureKey> targetKey,
IrisStructureAdoptionStrategy strategy
) {
IrisStructureAdoptionService service = null;
IrisStructureAdoptionPlan plan = null;
Throwable failure = null;
try {
IrisStructureAdoptionInputKind inputKind = adoptionInputKind(root, sourceKey);
service = ADOPTION_SERVICES.computeIfAbsent(root, IrisStructureAdoptionService::new);
plan = service.inspect(new IrisStructureAdoptionRequest(
sourceKey,
targetKey,
strategy,
inputKind));
} catch (Throwable throwable) {
failure = throwable;
Iris.reportError("Failed to inspect Jigsaw adoption source '" + sourceKey + "'.", throwable);
}
IrisStructureAdoptionService completedService = service;
IrisStructureAdoptionPlan completedPlan = plan;
Throwable completedFailure = failure;
J.runEntity(targetPlayer, () -> finishAdoptionInspect(
commandSender,
ownerId,
dimension,
data,
completedService,
completedPlan,
completedFailure));
}
private static void finishAdoptionInspect(
VolmitSender commandSender,
UUID ownerId,
IrisDimension dimension,
IrisData data,
IrisStructureAdoptionService service,
IrisStructureAdoptionPlan plan,
Throwable failure
) {
if (failure != null || service == null || plan == null) {
CommandJigsaw.sendError(commandSender, "Jigsaw adoption inspection failed: "
+ (failure == null ? "no result" : failure.getMessage()));
return;
}
pruneAdoptionPlanBindings();
if (service.plan(plan.planId()).isPresent()) {
ADOPTION_PLANS.put(plan.planId(), new AdoptionPlanBinding(
ownerId, dimension, data, service, plan));
}
reportAdoptionPlan(commandSender, plan);
}
private static void finishAdoptionApply(
Player targetPlayer,
VolmitSender commandSender,
AdoptionPlanBinding binding,
IrisStructureAdoptionResult result,
Throwable failure
) {
if (failure != null || result == null) {
CommandJigsaw.sendError(commandSender, "Jigsaw adoption failed: "
+ (failure == null ? "no result" : failure.getMessage()));
return;
}
reportAdoptionResult(commandSender, result);
if (!result.successful()) {
return;
}
StructureKey target = result.receipt().orElseThrow().targetStructure();
binding.data().invalidateStructureResources();
CommandJigsawOpen.openProject(targetPlayer, commandSender, binding.dimension(), target.path(), CommandJigsaw.DEFAULT_STUDIO_SEED);
}
private static void reportAdoptionPlan(VolmitSender commandSender, IrisStructureAdoptionPlan plan) {
C statusColor = plan.canApply() ? C.GREEN : C.RED;
commandSender.sendMessage(statusColor + "Adoption plan " + plan.planId() + " -> "
+ plan.disposition() + " for " + plan.targetStructure().value() + ".");
commandSender.sendMessage(C.GRAY + "Resources=" + plan.resourceCount()
+ ", bytes=" + plan.totalSourceBytes()
+ ", errors=" + plan.errorCount()
+ ", warnings=" + plan.warningCount() + ".");
for (IrisStructureAdoptionDiagnostic diagnostic : plan.diagnostics()) {
commandSender.sendMessage(adoptionColor(diagnostic).toString() + diagnostic.summary());
}
if (plan.canApply()) {
commandSender.sendMessage(C.AQUA + "Apply with /iris jigsaw adopt apply " + plan.planId());
}
}
private static void reportAdoptionResult(VolmitSender commandSender, IrisStructureAdoptionResult result) {
commandSender.sendMessage((result.successful() ? C.GREEN : C.RED)
+ "Adoption plan " + result.planId() + ": " + result.status() + ".");
for (IrisStructureAdoptionDiagnostic diagnostic : result.diagnostics()) {
commandSender.sendMessage(adoptionColor(diagnostic).toString() + diagnostic.summary());
}
}
private static C adoptionColor(IrisStructureAdoptionDiagnostic diagnostic) {
return switch (diagnostic.severity()) {
case ERROR -> C.RED;
case WARNING -> C.YELLOW;
case INFO -> C.GRAY;
};
}
static String parseAdoptionSource(String value) {
String normalized = Objects.requireNonNull(value, "Adoption source").trim()
.toLowerCase(Locale.ROOT);
StructureKey source = StructureKey.parse(normalized, "iris");
if (!"iris".equals(source.namespace())) {
throw new IllegalArgumentException("Adoption sources must use the iris namespace.");
}
return source.path();
}
static Optional<StructureKey> parseAdoptionTarget(String value) {
String normalized = Objects.requireNonNull(value, "Adoption target").trim()
.toLowerCase(Locale.ROOT);
if (normalized.isEmpty() || "auto".equals(normalized)) {
return Optional.empty();
}
StructureKey target = StructureKey.parse(normalized, "iris");
if (!"iris".equals(target.namespace())) {
throw new IllegalArgumentException("Adoption targets must use the iris namespace.");
}
return Optional.of(target);
}
private static IrisStructureAdoptionStrategy parseAdoptionStrategy(String value) {
return switch (Objects.requireNonNull(value, "Adoption strategy").trim().toLowerCase(Locale.ROOT)) {
case "auto" -> IrisStructureAdoptionStrategy.AUTO;
case "in-place", "in_place", "inplace", "claim" -> IrisStructureAdoptionStrategy.IN_PLACE;
case "clone", "copy" -> IrisStructureAdoptionStrategy.CLONE;
default -> throw new IllegalArgumentException("Adoption strategy must be auto, in-place, or clone.");
};
}
static IrisStructureAdoptionInputKind adoptionInputKind(Path packRoot, String source) throws IOException {
Path root = canonicalAdoptionRoot(packRoot);
StructureKey sourceKey = new StructureKey("iris", parseAdoptionSource(source));
Path manifestPath = new StructureTransactionWriter(root).ownershipManifestPath(sourceKey);
if (!Files.exists(manifestPath, LinkOption.NOFOLLOW_LINKS)) {
return IrisStructureAdoptionInputKind.UNOWNED_IRIS;
}
if (!Files.isRegularFile(manifestPath, LinkOption.NOFOLLOW_LINKS)) {
throw new IOException("Ownership manifest is not a regular file: " + manifestPath);
}
StructureOwnershipManifest manifest;
try {
manifest = StructureOwnershipManifest.fromJson(Files.readAllBytes(manifestPath));
} catch (RuntimeException exception) {
throw new IOException("Invalid ownership manifest at " + manifestPath, exception);
}
if (!manifest.structure().equals(sourceKey)) {
throw new IOException("Ownership manifest at " + manifestPath
+ " belongs to " + manifest.structure().value());
}
return manifest.provenance().origin() == StructureOwnershipManifest.Origin.MANAGED_DATAPACK
? IrisStructureAdoptionInputKind.MANAGED_DATAPACK
: IrisStructureAdoptionInputKind.UNOWNED_IRIS;
}
private static Path canonicalAdoptionRoot(Path packRoot) throws IOException {
Path normalized = Objects.requireNonNull(packRoot, "Adoption pack root").toAbsolutePath().normalize();
return Files.exists(normalized, LinkOption.NOFOLLOW_LINKS) ? normalized.toRealPath() : normalized;
}
private record AdoptionPlanBinding(
UUID ownerId,
IrisDimension dimension,
IrisData data,
IrisStructureAdoptionService service,
IrisStructureAdoptionPlan plan
) {
}
public static final class JigsawAdoptionStrategyHandler implements DirectorParameterHandler<String> {
@Override
public KList<String> getPossibilities() {
return new KList<>("auto", "in-place", "clone");
}
@Override
public String toString(String value) {
return value == null ? "" : value;
}
@Override
public String parse(String input, boolean force) throws DirectorParsingException {
try {
return switch (parseAdoptionStrategy(input)) {
case AUTO -> "auto";
case IN_PLACE -> "in-place";
case CLONE -> "clone";
};
} catch (IllegalArgumentException exception) {
throw new DirectorParsingException(exception.getMessage());
}
}
@Override
public boolean supports(Class<?> type) {
return type == String.class;
}
}
public static final class JigsawAdoptionPlanHandler implements DirectorParameterHandler<String> {
@Override
public KList<String> getPossibilities() {
return new KList<>();
}
@Override
public String toString(String value) {
return value == null ? "" : value;
}
@Override
public String parse(String input, boolean force) throws DirectorParsingException {
try {
return UUID.fromString(input).toString();
} catch (IllegalArgumentException exception) {
throw new DirectorParsingException("Adoption plan ID must be a UUID.");
}
}
@Override
public boolean supports(Class<?> type) {
return type == String.class;
}
}
}
@@ -0,0 +1,84 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBay;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCellDimensions;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioGraphEditor;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioVariant;
import art.arcane.iris.engine.object.IrisObject;
import art.arcane.iris.engine.object.IrisPosition;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.Jigsaw;
@Director(name = "connector", description = "Inspect and configure targeted jigsaw connectors",
origin = DirectorOrigin.PLAYER)
public class CommandJigsawConnector implements DirectorExecutor {
@Director(description = "Set the Iris-only channel on the targeted jigsaw marker", sync = true,
origin = DirectorOrigin.PLAYER)
public void channel(
@Param(description = "Exact channel, or none to clear") String channel
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
Block target = player().getTargetBlockExact(8);
if (target == null || !(target.getBlockData() instanceof Jigsaw)) {
CommandJigsaw.sendError(this, "Look directly at a jigsaw marker within eight blocks.");
return;
}
JigsawStudioBay bay = context.session().layout().findAt(
target.getX(), target.getY(), target.getZ());
JigsawStudioVariant activeVariant = bay == null
? null
: context.session().activeVariant(bay.stableId()).orElse(null);
if (activeVariant == null) {
CommandJigsaw.sendError(this, "The targeted marker must be inside a workcell with an active variant.");
return;
}
if (!activeVariant.owned()) {
CommandJigsaw.sendError(this, "The active variant is read-only. Adopt it into this project before editing it.");
return;
}
IrisObject object = context.request().source().getObjectLoader().load(activeVariant.objectKey());
if (object == null) {
CommandJigsaw.sendError(this, "The active variant object '" + activeVariant.objectKey() + "' is missing.");
return;
}
IrisPosition canonicalPosition = new IrisPosition(
target.getX() - bay.bounds().originX(),
target.getY() - bay.bounds().originY(),
target.getZ() - bay.bounds().originZ());
IrisPosition position;
try {
position = activeVariant.canonicalToSourcePosition(
canonicalPosition,
new JigsawStudioCellDimensions(object.getW(), object.getH(), object.getD()));
} catch (IllegalArgumentException exception) {
CommandJigsaw.sendError(this, "Connector channel update failed: " + exception.getMessage());
return;
}
String normalized = channel == null || channel.isBlank() || "none".equalsIgnoreCase(channel)
? "none"
: channel.trim();
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioGraphEditor.updateConnectorChannel(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
activeVariant.pieceKey(),
position,
channel);
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Persisted connector channel '" + normalized + "' on piece '"
+ activeVariant.pieceKey() + "' at " + position.getX() + "," + position.getY()
+ "," + position.getZ() + ".");
});
}
}
@@ -0,0 +1,159 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.Iris;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.core.structure.export.VanillaJigsawDatapackExporter;
import art.arcane.iris.core.structure.export.VanillaJigsawExportDiagnostic;
import art.arcane.iris.core.structure.export.VanillaJigsawExportFormat;
import art.arcane.iris.core.structure.export.VanillaJigsawExportRequest;
import art.arcane.iris.core.structure.export.VanillaJigsawExportResult;
import art.arcane.iris.util.common.format.C;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import org.bukkit.entity.Player;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
final class CommandJigsawExports {
private static final Pattern EXPORT_OUTPUT_NAME = Pattern.compile("[a-zA-Z0-9_-][a-zA-Z0-9._-]{0,127}");
private static final Set<UUID> EXPORTING_PLAYERS = ConcurrentHashMap.newKeySet();
private static final Set<Path> EXPORT_DESTINATIONS = ConcurrentHashMap.newKeySet();
private CommandJigsawExports() {
}
static String exportStartError(JigsawStudioService.ExportStart exportStart) {
Objects.requireNonNull(exportStart, "Jigsaw Studio export start status");
return switch (exportStart) {
case NOT_ACTIVE -> "The active Jigsaw Studio is no longer available.";
case NOT_OWNER -> "Only the Jigsaw Studio owner can export this project.";
case DIRTY -> "Wait for the pending autosave or discard the edits before exporting the on-disk graph.";
case CLOSING -> "The active Jigsaw Studio is closing and cannot be exported.";
case SAVE_IN_PROGRESS -> "Wait for the current Jigsaw Studio save to finish before exporting.";
case OPERATION_IN_PROGRESS -> "Wait for the current Jigsaw Studio operation to finish before exporting.";
case IN_PROGRESS -> "A Jigsaw Studio export is already in progress.";
case STARTED -> throw new IllegalArgumentException("STARTED is not an export failure");
};
}
static boolean beginExport(UUID playerId, Path destination) {
Objects.requireNonNull(playerId);
Path normalizedDestination = Objects.requireNonNull(destination).toAbsolutePath().normalize();
if (!EXPORTING_PLAYERS.add(playerId)) {
return false;
}
if (EXPORT_DESTINATIONS.add(normalizedDestination)) {
return true;
}
EXPORTING_PLAYERS.remove(playerId);
return false;
}
static void finishExport(UUID playerId, Path destination) {
EXPORTING_PLAYERS.remove(Objects.requireNonNull(playerId));
EXPORT_DESTINATIONS.remove(Objects.requireNonNull(destination).toAbsolutePath().normalize());
}
static void runExport(ExportOperation operation) {
VanillaJigsawExportResult result = null;
Throwable failure = null;
try {
result = new VanillaJigsawDatapackExporter().export(operation.request());
} catch (Throwable throwable) {
failure = throwable;
Iris.reportError("Vanilla Jigsaw export failed for '" + operation.structureKey() + "'.", throwable);
} finally {
operation.lease().release();
}
VanillaJigsawExportResult completedResult = result;
Throwable completedFailure = failure;
Runnable response = () -> reportExport(operation, completedResult, completedFailure);
J.runEntity(operation.player(), response);
}
private static void reportExport(
ExportOperation operation,
VanillaJigsawExportResult result,
Throwable failure
) {
if (failure != null || result == null) {
operation.sender().sendMessage(C.RED + "Background vanilla export for '"
+ operation.structureKey() + "' failed: "
+ (failure == null ? "no result" : failure.getMessage()));
return;
}
for (VanillaJigsawExportDiagnostic diagnostic : result.diagnostics()) {
C color = diagnostic.isBlocking() ? C.RED : C.YELLOW;
operation.sender().sendMessage(color.toString() + diagnostic.code() + ": " + diagnostic.message());
}
CommandJigsaw.ActiveContext current = CommandJigsaw.active(operation.player());
boolean sameSession = current != null
&& current.request().requestId().equals(operation.requestId());
String contextLabel = sameSession ? "Vanilla export" : "Background vanilla export for '"
+ operation.structureKey() + "'";
operation.sender().sendMessage((result.isSuccess() ? C.GREEN : C.RED) + contextLabel + " "
+ result.status() + ": " + result.output());
}
static VanillaJigsawExportFormat parseFormat(String value) {
return switch (value.trim().toLowerCase(Locale.ROOT)) {
case "zip" -> VanillaJigsawExportFormat.ZIP;
case "directory", "dir", "folder" -> VanillaJigsawExportFormat.DIRECTORY;
default -> throw new IllegalArgumentException("Export format must be directory or zip.");
};
}
static Path resolveExportDestination(
Path exportRoot,
String output,
VanillaJigsawExportFormat format
) {
Path root = Objects.requireNonNull(exportRoot, "Jigsaw export root").toAbsolutePath().normalize();
String requested = Objects.requireNonNull(output, "Jigsaw export output name");
String name = requested.trim();
if (!name.equals(requested) || !EXPORT_OUTPUT_NAME.matcher(name).matches()) {
throw new IllegalArgumentException(
"Export output must be one file name using letters, numbers, '.', '_', or '-'.");
}
String fileName = format == VanillaJigsawExportFormat.ZIP && !name.endsWith(".zip")
? name + ".zip" : name;
Path destination = root.resolve(fileName).normalize();
if (destination.equals(root) || !root.equals(destination.getParent())) {
throw new IllegalArgumentException("Export output must be one artifact inside the Studio exports folder.");
}
return destination;
}
record ExportOperation(
Player player,
VolmitSender sender,
UUID requestId,
String structureKey,
VanillaJigsawExportRequest request,
ExportLease lease
) {
}
static final class ExportLease {
private final Runnable release;
private final AtomicBoolean released;
ExportLease(Runnable release) {
this.release = Objects.requireNonNull(release, "Jigsaw export lease release action");
this.released = new AtomicBoolean();
}
void release() {
if (released.compareAndSet(false, true)) {
release.run();
}
}
}
}
@@ -0,0 +1,251 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.Iris;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.pack.BrokenPackException;
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
import art.arcane.iris.core.runtime.StudioOpenCoordinator;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioActivation;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBay;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioGraphMapper;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioLayout;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioSession;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.core.service.StudioSVC;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.iris.engine.object.IrisStructure;
import art.arcane.iris.platform.bukkit.BukkitPlatform;
import art.arcane.iris.util.common.format.C;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.concurrent.CompletionException;
final class CommandJigsawOpen {
private CommandJigsawOpen() {
}
static void openProject(
Player targetPlayer,
VolmitSender commandSender,
IrisDimension dimension,
String structure,
long seed
) {
UUID playerId = targetPlayer.getUniqueId();
UUID ownerId = JigsawStudioActivation.activeOwnerId();
if (ownerId != null && !ownerId.equals(playerId)) {
CommandJigsaw.sendError(commandSender, "Jigsaw Studio is already owned by another player session.");
return;
}
UUID openingOwner = JigsawStudioActivation.openingOwnerId();
if (openingOwner != null) {
CommandJigsaw.sendError(commandSender, openingOwner.equals(playerId)
? "Your Jigsaw Studio is already opening."
: "Jigsaw Studio is already opening for another player.");
return;
}
CommandJigsaw.ActiveContext previous = CommandJigsaw.active(targetPlayer);
if (ownerId != null && previous == null) {
CommandJigsaw.sendError(commandSender, "Your active Jigsaw Studio binding is unavailable. Close it before opening another project.");
return;
}
CommandJigsaw.ActiveContext dirty = CommandJigsaw.findDirtyContext();
if (dirty != null) {
CommandJigsaw.sendError(commandSender,
"The current Jigsaw Studio is waiting for autosave. Wait for it to finish or close with discard=true.");
return;
}
IrisData data = CommandJigsaw.requireData(dimension, commandSender);
if (data == null) {
return;
}
IrisStructure irisStructure = data.load(IrisStructure.class, structure, false);
if (irisStructure == null) {
CommandJigsaw.sendError(commandSender, "No Iris jigsaw structure '" + structure + "' exists in this pack.");
return;
}
JigsawStudioLayout layout;
try {
layout = JigsawStudioGraphMapper.map(data, irisStructure);
} catch (RuntimeException exception) {
Iris.reportError("Failed to map Jigsaw Studio graph '" + structure + "'.", exception);
CommandJigsaw.sendError(commandSender, "Could not map this jigsaw graph: " + exception.getMessage());
return;
}
String packKey = dimension.getLoadKey();
if (!JigsawStudioActivation.tryBeginOpen(playerId)) {
CommandJigsaw.sendError(commandSender,
"Jigsaw Studio began opening for another player. Try again after it finishes.");
return;
}
JigsawStudioService studioService = JigsawStudioService.get();
UUID closingRequestId = previous == null ? null : previous.request().requestId();
if (closingRequestId != null) {
JigsawStudioService.CloseStart closeStart = studioService.tryBeginClose(
closingRequestId,
playerId,
false);
if (closeStart != JigsawStudioService.CloseStart.STARTED) {
JigsawStudioActivation.finishOpen(playerId);
CommandJigsaw.sendError(commandSender, closeStart == JigsawStudioService.CloseStart.SAVE_IN_PROGRESS
? "The current Jigsaw Studio is saving. Wait for it to finish before opening another project."
: closeStart == JigsawStudioService.CloseStart.OPERATION_IN_PROGRESS
? "The current Jigsaw Studio is loading a variant. Wait for it to finish before opening another project."
: closeStart == JigsawStudioService.CloseStart.DIRTY
? "The current Jigsaw Studio is waiting for autosave. Wait for it to finish before opening another project."
: "The current Jigsaw Studio could not be reserved for replacement.");
return;
}
}
JigsawStudioActivation.StagedActivation staged;
try {
staged = JigsawStudioActivation.stage(
packKey,
structure,
layout.mode(),
CommandJigsaw.compatibilityOf(irisStructure),
layout.cellDimensions(),
data,
layout,
playerId,
closingRequestId);
} catch (RuntimeException exception) {
JigsawStudioActivation.finishOpen(playerId);
studioService.cancelClose(closingRequestId);
Iris.reportError("Failed to stage Jigsaw Studio for '" + structure + "'.", exception);
CommandJigsaw.sendError(commandSender, "Jigsaw Studio staging failed: " + exception.getMessage());
return;
}
commandSender.sendMessage(C.GREEN + "Opening transient Jigsaw Studio for '" + structure + "' with "
+ layout.bays().size() + " workcells.");
try {
Iris.service(StudioSVC.class).openTracked(
commandSender,
seed,
packKey,
CommandJigsaw.STUDIO_OPEN_KIND,
() -> beginStagedOpen(staged),
world -> finishOpen(targetPlayer, world, staged, studioService))
.whenComplete((result, throwable) -> J.s(() -> finishOpenAttempt(
commandSender,
playerId,
structure,
closingRequestId,
studioService,
staged,
result,
throwable)));
} catch (Throwable exception) {
JigsawStudioActivation.finishOpen(playerId);
studioService.cancelClose(closingRequestId);
JigsawStudioActivation.rollback(staged);
Iris.reportError("Failed to open Jigsaw Studio for '" + structure + "'.", exception);
CommandJigsaw.sendError(commandSender, "Jigsaw Studio open failed: " + exception.getMessage());
}
}
private static void beginStagedOpen(JigsawStudioActivation.StagedActivation staged) {
if (!JigsawStudioActivation.beginStagedGeneration(staged)) {
throw new IllegalStateException("The staged Jigsaw Studio activation is no longer current");
}
}
private static void finishOpenAttempt(
VolmitSender commandSender,
UUID playerId,
String structureKey,
UUID closingRequestId,
JigsawStudioService studioService,
JigsawStudioActivation.StagedActivation staged,
StudioOpenCoordinator.StudioOpenResult result,
Throwable throwable
) {
JigsawStudioActivation.finishOpen(playerId);
if (throwable == null && result != null) {
studioService.cancelClose(closingRequestId);
return;
}
studioService.cancelClose(closingRequestId);
JigsawStudioActivation.rollback(staged);
Throwable failure = unwrapCompletionFailure(throwable == null
? new IllegalStateException("Studio open completed without a result")
: throwable);
if (isExpectedOpenDenial(failure)) {
Iris.warn("Jigsaw Studio open for '%s' was denied: %s",
structureKey, failure.getMessage());
return;
}
Iris.reportError("Failed to open Jigsaw Studio for '" + structureKey + "'.", failure);
CommandJigsaw.sendError(commandSender, "Jigsaw Studio open failed: " + failure.getMessage());
}
private static void finishOpen(
Player targetPlayer,
World world,
JigsawStudioActivation.StagedActivation staged,
JigsawStudioService studioService
) {
if (world == null) {
throw new IllegalStateException("Jigsaw Studio opened without a world");
}
JigsawStudioActivation.Request request = staged.request();
JigsawStudioSession session = staged.session();
try {
WorldRuntimeControlService.get().applyObjectStudioWorldRules(world);
} catch (Throwable exception) {
Iris.reportError("Failed to apply Jigsaw Studio world rules for '" + world.getName() + "'.", exception);
}
JigsawStudioBay destination = initialBay(session.layout());
Location target = destination == null
? new Location(world, 0.5D, 66D, 0.5D)
: new Location(
world,
destination.bounds().originX() + destination.bounds().dimensions().width() / 2.0D,
destination.bounds().maxY() + 2.0D,
destination.bounds().originZ() + destination.bounds().dimensions().depth() / 2.0D);
if (destination != null) {
session.selectBay(destination.stableId());
}
if (!JigsawStudioActivation.commit(staged)) {
throw new IllegalStateException("The staged Jigsaw Studio activation could not be committed");
}
studioService.activationCommitted(world, request.requestId());
CommandJigsaw.PLAYER_PACKS.put(targetPlayer.getUniqueId(), new CommandJigsaw.SessionBinding(
request.packKey(), request.requestId()));
try {
J.runEntity(targetPlayer, () -> BukkitPlatform.teleportAsync(targetPlayer, target)
.thenRun(() -> J.runEntity(targetPlayer, () -> targetPlayer.setGameMode(GameMode.CREATIVE))));
} catch (RuntimeException exception) {
Iris.reportError("Failed to move the player to the committed Jigsaw Studio workcell.", exception);
}
}
private static JigsawStudioBay initialBay(JigsawStudioLayout layout) {
for (JigsawStudioBay bay : layout.bays()) {
if (layout.defaultVariant(bay).isPresent()) {
return bay;
}
}
return layout.bays().isEmpty() ? null : layout.bays().getFirst();
}
private static Throwable unwrapCompletionFailure(Throwable failure) {
Throwable current = failure;
while (current instanceof CompletionException && current.getCause() != null) {
current = current.getCause();
}
return current;
}
static boolean isExpectedOpenDenial(Throwable failure) {
return unwrapCompletionFailure(failure) instanceof BrokenPackException;
}
}
@@ -0,0 +1,238 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawPlanarTopology;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBay;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCellDimensions;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCompatibilityTarget;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioGraphEditor;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioLayout;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioMode;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioPoolEditor;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioVariant;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.engine.object.IrisJigsawPiece;
import art.arcane.iris.engine.object.IrisObject;
import art.arcane.iris.engine.object.IrisPosition;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
import org.bukkit.Location;
import java.io.IOException;
@Director(name = "piece", description = "Manage contextual Studio pieces", origin = DirectorOrigin.PLAYER)
public class CommandJigsawPiece implements DirectorExecutor {
@Director(description = "Create an owned piece from the selected Studio topology", sync = true,
origin = DirectorOrigin.PLAYER)
public void create(
@Param(description = "Owned pool resource key") String poolKey,
@Param(description = "New owned piece and object key") String pieceKey,
@Param(description = "Positive selection weight", defaultValue = "1") int weight
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawPlanarTopology topology = null;
JigsawStudioBay targetWorkcell = context.session().layout().get(JigsawStudioLayout.SPATIAL_WORKCELL_ID);
if (context.session().layout().mode() == JigsawStudioMode.PLANAR_JIGSAW) {
Location location = player().getLocation();
JigsawStudioBay contextual = context.session().layout().findAt(
location.getBlockX(), location.getBlockY(), location.getBlockZ());
if (contextual == null) {
contextual = CommandJigsaw.selectedBay(context);
} else {
context.session().selectBay(contextual.stableId());
}
if (contextual == null || contextual.topology().isEmpty()) {
CommandJigsaw.sendError(this, "Stand in or select a planar topology workcell before creating a variant.");
return;
}
topology = contextual.topology().get();
targetWorkcell = contextual;
}
if (targetWorkcell == null) {
CommandJigsaw.sendError(this, "The selected Jigsaw Studio workcell is no longer available.");
return;
}
JigsawPlanarTopology selectedTopology = topology;
String activationWorkcellId = targetWorkcell.stableId();
JigsawStudioCellDimensions dimensions = targetWorkcell.capacity();
String topologyText = selectedTopology == null ? "blank spatial" : selectedTopology.name();
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioGraphEditor.createPiece(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
pieceKey,
weight,
dimensions,
selectedTopology);
return CommandJigsaw.mappedMutationResult(
context,
activationWorkcellId,
pieceKey,
"Created owned " + topologyText + " piece '" + pieceKey
+ "' and added it to pool '" + poolKey + "' atomically.");
});
}
@Director(description = "Add an existing jigsaw piece to an owned pool transactionally", sync = true,
origin = DirectorOrigin.PLAYER)
public void add(
@Param(description = "Owned pool resource key") String poolKey,
@Param(description = "Existing jigsaw piece key") String pieceKey,
@Param(description = "Positive selection weight", defaultValue = "1") int weight
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
IrisJigsawPiece piece = context.request().source().getJigsawPieceLoader().load(pieceKey);
if (piece == null) {
CommandJigsaw.sendError(this, "No jigsaw piece '" + pieceKey + "' exists in this pack.");
return;
}
if (piece.getObject() == null || piece.getObject().isBlank()) {
CommandJigsaw.sendError(this, "Jigsaw piece '" + pieceKey + "' does not declare an object.");
return;
}
IrisObject object = context.request().source().getObjectLoader().load(piece.getObject());
if (object == null) {
CommandJigsaw.sendError(this, "Jigsaw piece '" + pieceKey + "' has no loadable object.");
return;
}
CommandJigsaw.PieceWorkcellResolution resolution;
try {
resolution = CommandJigsaw.resolvePieceWorkcell(context.session().layout(), piece, object);
} catch (IllegalArgumentException exception) {
CommandJigsaw.sendError(this, "Jigsaw piece '" + pieceKey + "' cannot be assigned to a Studio workcell: "
+ exception.getMessage());
return;
}
if (!resolution.fits()) {
IrisPosition required = resolution.requiredDimensions();
JigsawStudioCellDimensions capacity = resolution.workcell().capacity();
CommandJigsaw.sendError(this, "Jigsaw piece '" + pieceKey + "' requires " + required.getX() + "x"
+ required.getY() + "x" + required.getZ() + " in " + resolution.workcell().displayName()
+ ", but that workcell capacity is " + capacity.width() + "x" + capacity.height()
+ "x" + capacity.depth() + ".");
return;
}
String objectKey = piece.getObject();
CommandJigsaw.runGraphMutation(player(), context, () -> {
if (!JigsawStudioGraphEditor.ownsPiece(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
pieceKey,
objectKey)) {
throw new IOException("Piece add accepts only piece/object resources already owned by this project; "
+ "use piece create for a new owned piece");
}
JigsawStudioPoolEditor.PoolUpdate update = JigsawStudioPoolEditor.addPiece(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
pieceKey,
weight);
if (!update.changed()) {
throw new IOException("The owned pool is missing or already references '" + pieceKey + "'");
}
JigsawStudioLayout layout = CommandJigsaw.loadPersistedLayout(context);
String activationWorkcellId = CommandJigsaw.workcellIdForVariant(layout, pieceKey);
return new JigsawStudioService.CommandGraphMutationResult(
layout,
activationWorkcellId,
pieceKey,
"Added '" + pieceKey + "' to pool '" + poolKey + "' in one graph transaction.");
});
}
@Director(description = "Remove the selected piece from an owned pool transactionally", sync = true,
origin = DirectorOrigin.PLAYER)
public void remove(
@Param(description = "Owned pool resource key") String poolKey
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioVariant selected = CommandJigsaw.selectedVariant(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before removing its pool entry.");
return;
}
String pieceKey = selected.pieceKey();
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioPoolEditor.PoolUpdate update = JigsawStudioPoolEditor.removePiece(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
pieceKey);
if (!update.changed()) {
throw new IOException("The owned pool does not reference selected piece '" + pieceKey + "'");
}
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Removed '" + pieceKey + "' from pool '" + poolKey + "' in one graph transaction.");
});
}
@Director(description = "Allow or forbid cardinal rotation of the selected piece", sync = true,
origin = DirectorOrigin.PLAYER)
public void rotatable(
@Param(description = "Whether the selected piece may rotate") boolean rotatable
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioVariant selected = CommandJigsaw.selectedVariant(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before changing rotation.");
return;
}
if (!rotatable
&& context.request().compatibilityTarget()
== JigsawStudioCompatibilityTarget.VANILLA_PORTABLE) {
CommandJigsaw.sendError(this, "Vanilla-portable pieces must remain rotatable.");
return;
}
String pieceKey = selected.pieceKey();
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioGraphEditor.updateRotatable(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
pieceKey,
rotatable);
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Persisted piece '" + pieceKey + "' rotatable=" + rotatable + ".");
});
}
@Director(description = "Resize the selected piece object exactly to workcell capacity", sync = true,
origin = DirectorOrigin.PLAYER)
public void expand() {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay workcell = CommandJigsaw.selectedBay(context);
if (workcell == null) {
CommandJigsaw.sendError(this, "Select a workcell before expanding its active variant.");
return;
}
JigsawStudioService.get().expandVariantToCell(player(), workcell.stableId());
}
}
@@ -0,0 +1,38 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioGraphEditor;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
@Director(name = "pool", description = "Manage owned jigsaw pools", origin = DirectorOrigin.PLAYER)
public class CommandJigsawPool implements DirectorExecutor {
@Director(description = "Create an empty owned jigsaw pool", sync = true,
origin = DirectorOrigin.PLAYER)
public void create(
@Param(description = "New owned pool resource key") String poolKey,
@Param(description = "Owned fallback pool key, or none", defaultValue = "none")
String fallbackPoolKey
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
String fallback = "none".equalsIgnoreCase(fallbackPoolKey) ? "" : fallbackPoolKey;
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioGraphEditor.createPool(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
fallback);
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Created owned pool '" + poolKey + "' with fallback '"
+ (fallback.isBlank() ? "none" : fallback) + "'.");
});
}
}
@@ -0,0 +1,26 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
@Director(name = "preview", description = "Assemble a read-only jigsaw preview",
origin = DirectorOrigin.PLAYER)
public class CommandJigsawPreview implements DirectorExecutor {
@Director(name = "goto", aliases = "teleport", description = "Teleport to the live seed-1337 preview",
sync = true, origin = DirectorOrigin.PLAYER)
public void gotoPreview() {
JigsawStudioService.get().goToPreview(player());
}
@Director(description = "Assemble a deterministic preview at your location", sync = true,
origin = DirectorOrigin.PLAYER)
public void assemble(
@Param(description = "Assembly seed", defaultValue = "1337") long seed
) {
JigsawStudioService.get().previewStudio(player(), seed);
}
}
@@ -0,0 +1,74 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCompatibilityTarget;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioPoolEditor;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioStructureEditor;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
@Director(name = "rules", aliases = "rule", description = "Manage structure-wide jigsaw rules",
origin = DirectorOrigin.PLAYER)
public class CommandJigsawRules implements DirectorExecutor {
@Director(description = "Set maximum expansion depth and horizontal radius", sync = true,
origin = DirectorOrigin.PLAYER)
public void limits(
@Param(description = "Maximum expansion depth") int maxDepth,
@Param(description = "Maximum radius in chunks") int maxSizeChunks
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
if (context.request().compatibilityTarget() == JigsawStudioCompatibilityTarget.VANILLA_PORTABLE
&& (maxDepth > 20 || maxSizeChunks > 8)) {
CommandJigsaw.sendError(this, "Vanilla-portable rules require maxDepth <= 20 and maxSizeChunks <= 8.");
return;
}
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioStructureEditor.updateLimits(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
maxDepth,
maxSizeChunks);
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Persisted jigsaw limits: maxDepth=" + maxDepth
+ ", maxSizeChunks=" + maxSizeChunks + ".");
});
}
@Director(description = "Set or clear one owned pool's direct fallback", sync = true,
origin = DirectorOrigin.PLAYER)
public void fallback(
@Param(description = "Owned pool resource key") String poolKey,
@Param(description = "Owned fallback pool key, or none") String fallbackPoolKey
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
String fallback = "none".equalsIgnoreCase(fallbackPoolKey) ? "" : fallbackPoolKey;
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioPoolEditor.PoolUpdate update = JigsawStudioPoolEditor.updateFallback(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
fallback);
if (!update.changed()) {
return CommandJigsaw.mappedMutationResult(context, "", "", "Pool fallback is unchanged.");
}
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Persisted pool '" + poolKey + "' fallback as '"
+ (fallback.isBlank() ? "none" : fallback) + "'.");
});
}
}
@@ -0,0 +1,169 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBay;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCellDimensions;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioPoolEditor;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioVariant;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
import java.io.IOException;
@Director(name = "variant", description = "Manage selected jigsaw variants", origin = DirectorOrigin.PLAYER)
public class CommandJigsawVariant implements DirectorExecutor {
@Director(description = "Set the selected piece weight in a pool", sync = true,
origin = DirectorOrigin.PLAYER)
public void weight(
@Param(description = "Pool resource key") String poolKey,
@Param(description = "Positive selection weight") int weight
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioVariant selected = CommandJigsaw.selectedVariant(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before changing its weight.");
return;
}
String pieceKey = selected.pieceKey();
CommandJigsaw.runGraphMutation(player(), context, () -> {
JigsawStudioPoolEditor.WeightUpdate update = JigsawStudioPoolEditor.updateWeight(
context.request().source().getDataFolder().toPath(),
context.request().structureKey(),
poolKey,
pieceKey,
weight);
if (!update.changed()) {
throw new IOException("Pool '" + poolKey + "' does not reference selected piece '"
+ pieceKey + "'");
}
return CommandJigsaw.mappedMutationResult(
context,
"",
"",
"Updated " + update.changedEntries() + " pool entry weight atomically in "
+ update.poolPath() + ".");
});
}
@Director(description = "Resize only the active variant object within workcell capacity", sync = true,
origin = DirectorOrigin.PLAYER)
public void resize(
@Param(description = "Variant width") int width,
@Param(description = "Variant height") int height,
@Param(description = "Variant depth") int depth
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selectedWorkcell = CommandJigsaw.selectedBay(context);
JigsawStudioVariant selectedVariant = CommandJigsaw.selectedVariant(context);
if (selectedWorkcell == null || selectedVariant == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before resizing it.");
return;
}
JigsawStudioCellDimensions dimensions;
try {
dimensions = new JigsawStudioCellDimensions(width, height, depth);
} catch (IllegalArgumentException exception) {
CommandJigsaw.sendError(this, exception.getMessage());
return;
}
JigsawStudioService.get().resizeVariant(
player(),
selectedWorkcell.stableId(),
selectedVariant.pieceKey(),
dimensions);
}
@Director(description = "Set the active variant's author-facing label", sync = true,
origin = DirectorOrigin.PLAYER)
public void label(
@Param(description = "Display label; quote labels containing spaces") String displayName
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selectedWorkcell = CommandJigsaw.selectedBay(context);
JigsawStudioVariant selectedVariant = CommandJigsaw.selectedVariant(context);
if (selectedWorkcell == null || selectedVariant == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before renaming it.");
return;
}
JigsawStudioService.get().updateVariantDisplayName(
player(),
selectedWorkcell.stableId(),
selectedVariant.pieceKey(),
displayName);
}
@Director(name = "label-reset", aliases = "reset-label",
description = "Reset the active variant to its resource-key label", sync = true,
origin = DirectorOrigin.PLAYER)
public void labelReset() {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selectedWorkcell = CommandJigsaw.selectedBay(context);
JigsawStudioVariant selectedVariant = CommandJigsaw.selectedVariant(context);
if (selectedWorkcell == null || selectedVariant == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before resetting its label.");
return;
}
JigsawStudioService.get().updateVariantDisplayName(
player(),
selectedWorkcell.stableId(),
selectedVariant.pieceKey(),
"");
}
@Director(description = "Duplicate the active variant in only this workcell", sync = true,
origin = DirectorOrigin.PLAYER)
public void duplicate() {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selected = CommandJigsaw.selectedBay(context);
if (selected == null || CommandJigsaw.selectedVariant(context) == null) {
CommandJigsaw.sendError(this, "Select a workcell with an active variant before duplicating it.");
return;
}
JigsawStudioService.get().createVariant(player(), selected.stableId(), true);
}
@Director(name = "duplicate-family", aliases = "family",
description = "Duplicate every enabled workcell's active variant as one coherent family",
sync = true, origin = DirectorOrigin.PLAYER)
public void duplicateFamily(
@Param(description = "Family key or next", defaultValue = "next") String themeKey
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
String selectedTheme = themeKey;
if ("next".equalsIgnoreCase(themeKey)) {
try {
selectedTheme = CommandJigsaw.nextThemeKey(context);
} catch (IOException | ArithmeticException exception) {
CommandJigsaw.sendError(this, exception.getMessage());
return;
}
}
JigsawStudioService.get().duplicateActiveFamily(player(), selectedTheme);
}
}
@@ -0,0 +1,81 @@
package art.arcane.iris.core.commands;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioBay;
import art.arcane.iris.core.runtime.jigsaw.JigsawStudioCellDimensions;
import art.arcane.iris.core.service.JigsawStudioService;
import art.arcane.iris.util.common.director.DirectorExecutor;
import art.arcane.volmlib.util.director.DirectorOrigin;
import art.arcane.volmlib.util.director.annotations.Director;
import art.arcane.volmlib.util.director.annotations.Param;
@Director(name = "workcell", aliases = "cell", description = "Manage the selected Studio workcell",
origin = DirectorOrigin.PLAYER)
public class CommandJigsawWorkcell implements DirectorExecutor {
@Director(description = "Set capacity without resizing any variant object", sync = true,
origin = DirectorOrigin.PLAYER)
public void capacity(
@Param(description = "Capacity width") int width,
@Param(description = "Capacity height") int height,
@Param(description = "Capacity depth") int depth
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selected = CommandJigsaw.selectedBay(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell before changing its capacity.");
return;
}
JigsawStudioCellDimensions dimensions;
try {
dimensions = new JigsawStudioCellDimensions(width, height, depth);
} catch (IllegalArgumentException exception) {
CommandJigsaw.sendError(this, exception.getMessage());
return;
}
JigsawStudioService.get().updateWorkcellDimensions(
player(),
selected.stableId(),
dimensions);
}
@Director(description = "Set the selected workcell's author-facing label", sync = true,
origin = DirectorOrigin.PLAYER)
public void label(
@Param(description = "Display label; quote labels containing spaces") String displayName
) {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selected = CommandJigsaw.selectedBay(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell before renaming it.");
return;
}
JigsawStudioService.get().updateWorkcellDisplayName(
player(),
selected.stableId(),
displayName);
}
@Director(name = "label-reset", aliases = "reset-label",
description = "Reset the selected workcell to its canonical solver label", sync = true,
origin = DirectorOrigin.PLAYER)
public void labelReset() {
CommandJigsaw.ActiveContext context = CommandJigsaw.active(player());
if (context == null) {
CommandJigsaw.sendError(this, "Open a Jigsaw Studio project first.");
return;
}
JigsawStudioBay selected = CommandJigsaw.selectedBay(context);
if (selected == null) {
CommandJigsaw.sendError(this, "Select a workcell before resetting its label.");
return;
}
JigsawStudioService.get().updateWorkcellDisplayName(player(), selected.stableId(), "");
}
}
@@ -75,8 +75,8 @@ public class WandSVC implements IrisService {
private static final int MS_PER_TICK = Integer.parseInt(System.getProperty("iris.ms_per_tick", "30"));
private static final int PLAYER_RESCAN_INTERVAL_TICKS = 100;
private static ItemStack dust;
private static ItemStack wand;
private static volatile ItemStack dust;
private static volatile ItemStack wand;
private final Map<UUID, Player> activePlayers = new ConcurrentHashMap<>();
private final AtomicBoolean playerRescanScheduled = new AtomicBoolean(false);
@@ -374,12 +374,14 @@ public class WandSVC implements IrisService {
@Override
public void onEnable() {
wand = createWand();
dust = createDust();
enabled = true;
activePlayers.clear();
ticksUntilPlayerRescan = 0;
taskId = J.ar(this::tickAll, 1);
J.s(() -> {
wand = createWand();
dust = createDust();
});
}
@Override
@@ -389,6 +391,8 @@ public class WandSVC implements IrisService {
J.car(taskId);
taskId = -1;
}
wand = null;
dust = null;
activePlayers.clear();
playerRescanScheduled.set(false);
}
@@ -607,7 +611,8 @@ public class WandSVC implements IrisService {
return false;
}
Byte marker = is.getItemMeta().getPersistentDataContainer().get(dustKey(), PersistentDataType.BYTE);
return (marker != null && marker == (byte) 1) || is.isSimilar(dust);
ItemStack template = dust;
return (marker != null && marker == (byte) 1) || (template != null && is.isSimilar(template));
}
private static NamespacedKey wandKey() {
@@ -3,14 +3,10 @@ package art.arcane.iris;
import art.arcane.iris.spi.LogLevel;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Level;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Core states a severity on every message it logs and the modded adapters honour it. Bukkit must preserve
@@ -33,58 +29,4 @@ public class IrisDiagnosticLogLevelTest {
public void lifecycleNoticesReachThePluginLoggerAtInfo() {
assertEquals(Level.INFO, Iris.diagnosticLevel(LogLevel.NOTICE));
}
@Test
public void adapterSideWarningsCarryTheSameSeverityAsCoreWarnings() throws Exception {
String source = Files.readString(Path.of("src/main/java/art/arcane/iris/Iris.java")).replace("\r\n", "\n");
String warn = method(source, "public static void warn(String format, Object... objs)");
assertTrue(warn, warn.contains("diagnostic(Level.WARNING"));
assertFalse(warn, warn.contains("msg("));
String error = method(source, "public static void error(String format, Object... objs)");
assertTrue(error, error.contains("diagnostic(Level.SEVERE"));
assertFalse(error, error.contains("msg("));
}
@Test
public void theCoreLogBridgeRoutesDiagnosticsToThePluginLogger() throws Exception {
String source = Files.readString(Path.of("src/main/java/art/arcane/iris/Iris.java")).replace("\r\n", "\n");
String bridge = method(source, "private static void bridgeLog(LogLevel level, String message)");
assertTrue(bridge, bridge.contains("diagnosticLevel(target)"));
assertTrue(bridge, bridge.contains("diagnostic(diagnostic, message)"));
String diagnostic = method(source, "private static void diagnostic(Level level, String message)");
assertTrue(diagnostic, diagnostic.contains("ComponentLog.log("));
assertTrue(diagnostic, diagnostic.contains("ComponentText.literal(line)"));
}
@Test
public void informationalMessagesUseTheSharedComponentLogger() throws Exception {
String source = Files.readString(Path.of("src/main/java/art/arcane/iris/Iris.java")).replace("\r\n", "\n");
String message = method(source, "public static void msg(String string)");
assertTrue(message, message.contains("ComponentLog.logMarkup("));
assertTrue(message, message.contains("logPrefix(plugin)"));
assertFalse(message, message.contains("getSender().sendMessage"));
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue("method not found: " + signature, start >= 0);
int open = source.indexOf('{', start);
int depth = 0;
for (int i = open; i < source.length(); i++) {
char c = source.charAt(i);
if (c == '{') {
depth++;
} else if (c == '}') {
depth--;
if (depth == 0) {
return source.substring(start, i + 1);
}
}
}
throw new AssertionError("unterminated method: " + signature);
}
}
@@ -1,72 +0,0 @@
package art.arcane.iris.core;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertTrue;
public class IrisStartupOrderingTest {
@Test
public void admissionGateIsRegisteredBeforeStartupValidationBegins() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.startupSource")));
String onEnable = section(source, "public void onEnable()", "public void onDisable()");
assertOrdered(onEnable,
"IrisStartupValidation.begin();",
"registerEvents(new IrisStartupAdmissionListener(), this);",
"enable();");
}
@Test
public void externalDatapacksValidateBeforeDimensionPacks() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.startupSource")));
String enable = section(source, "private boolean enable()", "public void addShutdownHook()");
assertOrdered(enable,
"DatapackIngestService.validateOnStartup();",
"generatorResolver.validateAllPacks();");
}
@Test
public void externalProvidersEnableBeforePackValidation() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.startupSource")));
String enable = section(source, "private boolean enable()", "public void addShutdownHook()");
assertOrdered(enable,
"service.onEnable();",
"setContentChangeListener(generatorResolver::requestExternalContentRefresh)",
"generatorResolver.validateAllPacks();");
}
@Test
public void restartRequiredStartupTerminatesAfterPluginInitialization() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.startupSource")));
String onEnable = section(source, "public void onEnable()", "public void onDisable()");
assertOrdered(onEnable,
"BukkitGuiHost.install();",
"super.onEnable();",
"IrisStartupValidation.isRestartRequired()",
"ServerConfigurator.restartAtStartupBoundary(restartReason);");
}
private static String section(String source, String startMarker, String endMarker) {
int start = source.indexOf(startMarker);
int end = source.indexOf(endMarker, start);
assertTrue("Missing source section starting with " + startMarker, start >= 0);
assertTrue("Missing source section ending with " + endMarker, end > start);
return source.substring(start, end);
}
private static void assertOrdered(String source, String... markers) {
int previous = -1;
for (String marker : markers) {
int current = source.indexOf(marker);
assertTrue("Missing source marker " + marker, current >= 0);
assertTrue("Source marker is out of order: " + marker, current > previous);
previous = current;
}
}
}
@@ -140,23 +140,6 @@ public class IrisWorldGeneratorResolverTest {
}
}
@Test
public void startupValidationPublishesFingerprintBoundExactRootResults() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/IrisWorldGeneratorResolver.java")).replace("\r\n", "\n");
int validateAll = source.indexOf("public void validateAllPacks()");
int snapshot = source.indexOf("ServerConfigurator.computePackContentSnapshot(packsRoot)", validateAll);
int perPackFingerprint = source.indexOf("contentSnapshot.packContents()", snapshot);
int exactRootPublish = source.indexOf(
"PackValidationRegistry.publish(packDirectory.toPath(), result, packFingerprint)",
perPackFingerprint);
assertTrue(validateAll >= 0);
assertTrue(snapshot > validateAll);
assertTrue(perPackFingerprint > snapshot);
assertTrue(exactRootPublish > perPackFingerprint);
}
@Test
public void paperStartupAliasResolvesToCanonicalRuntimeKey() throws Exception {
File levelRoot = ownedLevelRoot("startup-alias", "moon");
@@ -251,87 +234,6 @@ public class IrisWorldGeneratorResolverTest {
return levelRoot;
}
@Test
public void configuredWorldResolutionUsesOnlyActiveImmutableGenerationPack() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/IrisWorldGeneratorResolver.java")).replace("\r\n", "\n");
int resolverStart = source.indexOf("private ChunkGenerator resolveFrozenWorldGenerator(");
int resolverEnd = source.indexOf("private record FreshValidation", resolverStart);
String resolver = source.substring(resolverStart, resolverEnd);
int dimensionRoot = resolver.indexOf("IrisWorldStorage.requireFrozenDimensionRoot(");
int currentPlatformRoot = resolver.indexOf("WorldCreatorCompat.persistentDimensionRoot(worldKey)");
int layoutRefusal = resolver.indexOf(
"Frozen Iris world storage does not match the current platform layout",
currentPlatformRoot
);
int history = resolver.indexOf("requireGenerationHistory(dimensionRoot, id, worldSeed)");
int snapshotRoot = resolver.indexOf("requireActivePack(history)", history);
int validation = resolver.indexOf("requireSnapshotLoadable(snapshotRoot)");
int exactLoad = resolver.indexOf("requireHistoricalDimension(history, snapshotRoot, id)");
int canonicalIdentity = resolver.indexOf(".platformIdentity(worldKey.toString())");
int historicalSeed = resolver.indexOf(".seed(history.activeEpoch().worldSeed())");
int resolvedStorage = resolver.indexOf(".worldFolder(dimensionRoot)");
assertTrue(dimensionRoot >= 0);
assertTrue(currentPlatformRoot > dimensionRoot);
assertTrue(layoutRefusal > currentPlatformRoot);
assertTrue(history > layoutRefusal);
assertTrue(snapshotRoot > history);
assertTrue(validation > snapshotRoot);
assertTrue(exactLoad > validation);
assertTrue(canonicalIdentity > exactLoad);
assertTrue(historicalSeed > canonicalIdentity);
assertTrue(resolvedStorage > historicalSeed);
assertFalse(resolver.contains("loadDimension("));
assertFalse(resolver.contains("loadAnyDimension("));
assertFalse(resolver.contains("replaceIntoWorld("));
assertFalse(resolver.contains("installIntoWorld("));
assertFalse(resolver.contains(".seed(1337)"));
assertTrue(resolver.contains("GenerationHistory.openIfPresent(root, worldSeed)"));
assertTrue(resolver.contains("GenerationHistory.adoptLegacyPack("));
assertTrue(resolver.contains("GenerationRegistryContractFactory.captureRequiredDefinitions("));
}
@Test
public void ownedWorldSnapshotFailureStopsStartupAndRethrows() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/IrisWorldGeneratorResolver.java")).replace("\r\n", "\n");
int resolverStart = source.indexOf("public ChunkGenerator resolveDefaultWorldGenerator(");
int resolverEnd = source.indexOf("private ChunkGenerator resolveFrozenWorldGenerator(", resolverStart);
String resolver = source.substring(resolverStart, resolverEnd);
int plotSquaredProbe = resolver.indexOf("isPlotSquaredGeneratorDiscoveryProbe(worldName, id)");
int probe = resolver.indexOf("isGeneratorDiscoveryProbe(worldName, id)", plotSquaredProbe);
int denial = resolver.indexOf("IrisStartupValidation.denialReason()", probe);
int failClosed = resolver.indexOf("IrisFailClosedChunkGenerator.startupLock(", denial);
int staged = resolver.indexOf("WorldLifecycleStaging.consumeGenerator(worldName)", failClosed);
int duplicateGuard = resolver.indexOf("requireWorldKeyAvailable(worldName, worldKey)");
int ownership = resolver.indexOf("requireOwnedWorld(worldName, levelRoot, worldKey)");
int frozen = resolver.indexOf("return resolveFrozenWorldGenerator(", ownership);
int failureCapture = resolver.indexOf("catch (RuntimeException failure)", frozen);
int report = resolver.indexOf("Iris.reportError(", failureCapture);
int shutdown = resolver.indexOf("Bukkit.shutdown()", report);
int rethrow = resolver.indexOf("throw failure", shutdown);
assertTrue(plotSquaredProbe >= 0);
assertTrue(probe > plotSquaredProbe);
assertTrue(denial > probe);
assertTrue(failClosed > denial);
assertTrue(staged > failClosed);
assertTrue(duplicateGuard > staged);
assertTrue(ownership > duplicateGuard);
assertTrue(frozen > ownership);
assertTrue(failureCapture > frozen);
assertTrue(report > failureCapture);
assertTrue(shutdown > report);
assertTrue(rethrow > shutdown);
String shutdownScope = "the fail-fast shutdown must stay scoped to the frozen snapshot of an owned world";
assertEquals(shutdownScope, resolverStart + shutdown, source.indexOf("Bukkit.shutdown()"));
assertEquals(shutdownScope, resolverStart + shutdown, source.lastIndexOf("Bukkit.shutdown()"));
}
@Test
public void plotSquaredDiscoveryProbeIsIgnoredQuietly() {
try (MockedStatic<Bukkit> bukkit = mockStatic(Bukkit.class);
@@ -1,26 +0,0 @@
package art.arcane.iris.core.commands;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class CommandDeveloperGenerationHistoryTest {
@Test
public void updateWorldStagesThePackWithTheLiveWorldSeed() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandDeveloper.java"
)).replace("\r\n", "\n");
int updateStart = source.indexOf("public void updateWorld(");
int updateEnd = source.indexOf("@Director(description = \"Test\"", updateStart);
String update = source.substring(updateStart, updateEnd);
assertTrue(update.contains(
"replaceIntoWorld(sender(), pack, folder, world.getSeed())"
));
assertFalse(update.contains("iris/pack"));
}
}
@@ -7,8 +7,6 @@ import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
@@ -73,26 +71,4 @@ public class CommandIrisCreateOverwriteContractTest {
assertEquals(Long.valueOf(Long.MAX_VALUE), handler.parse(Long.toString(Long.MAX_VALUE), false));
assertThrows(DirectorParsingException.class, () -> handler.parse("9223372036854775808", false));
}
@Test
public void createAndReplaceUseLocalizedStyledMissingDimensionFeedback() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandIris.java"
)).replace("\r\n", "\n");
assertEquals(2, occurrences(source, "COMMAND_IRIS_DIMENSION_NOT_FOUND"));
assertEquals(2, occurrences(source, "COMMAND_IRIS_INSTALL_PACK_AND_RESTART"));
assertFalse(source.contains("sendMessage(\"Could not find dimension"));
assertFalse(source.contains("sendMessage(\"Install its pack with"));
}
private static int occurrences(String value, String match) {
int count = 0;
int offset = 0;
while ((offset = value.indexOf(match, offset)) >= 0) {
count++;
offset += match.length();
}
return count;
}
}
@@ -5,13 +5,10 @@ import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@@ -47,20 +44,6 @@ public class CommandIrisDownloadContractTest {
assertThrows(Exception.class, () -> handler.parse("custom", false));
}
@Test
public void commandDelegatesAcceptedDownloadsWithoutRawPreamble() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandIris.java"
)).replace("\r\n", "\n");
String download = method(source, "public void download(");
assertTrue(download.contains("downloadBuiltIn(sender(), builtInPack)"));
assertTrue(download.contains("downloadUrl(sender(), directLink)"));
assertFalse(download.contains("Downloading built-in Iris pack"));
assertFalse(download.contains("Downloading Iris pack from"));
assertFalse(download.contains("sendMessage(directLink"));
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue(start >= 0);
@@ -108,28 +108,13 @@ public class CommandJigsawContractTest {
BrokenPackException failure = new BrokenPackException(
"overworld", List.of("Biome 'broken' has no resolvable regions."));
assertTrue(CommandJigsaw.isExpectedOpenDenial(failure));
assertTrue(CommandJigsaw.isExpectedOpenDenial(
assertTrue(CommandJigsawOpen.isExpectedOpenDenial(failure));
assertTrue(CommandJigsawOpen.isExpectedOpenDenial(
new CompletionException(failure)));
assertFalse(CommandJigsaw.isExpectedOpenDenial(
assertFalse(CommandJigsawOpen.isExpectedOpenDenial(
new IllegalStateException("Unexpected Studio failure")));
}
@Test
public void committedActivationStartsInitialEvaluationBeforePlayerBinding() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandJigsaw.java")).replace("\r\n", "\n");
int commit = source.indexOf("JigsawStudioActivation.commit(staged)");
int evaluation = source.indexOf(
"studioService.activationCommitted(world, request.requestId())",
commit);
int binding = source.indexOf("PLAYER_PACKS.put", evaluation);
assertTrue(commit >= 0);
assertTrue(evaluation > commit);
assertTrue(binding > evaluation);
}
@Test
public void convertIsAddOnlyWorkflowWithAliasesAndDefaults() throws Exception {
Method convert = CommandJigsaw.class.getDeclaredMethod(
@@ -153,20 +138,20 @@ public class CommandJigsawContractTest {
@Test
public void adoptionCommandsExposeTwoStepPlanContract() throws Exception {
Method inspect = CommandJigsaw.CommandJigsawAdopt.class.getDeclaredMethod(
Method inspect = CommandJigsawAdopt.class.getDeclaredMethod(
"inspect", IrisDimension.class, String.class, String.class, String.class);
Method apply = CommandJigsaw.CommandJigsawAdopt.class.getDeclaredMethod("apply", String.class);
Method apply = CommandJigsawAdopt.class.getDeclaredMethod("apply", String.class);
Parameter[] inspectParameters = inspect.getParameters();
assertNotNull(inspect.getAnnotation(Director.class));
assertNotNull(apply.getAnnotation(Director.class));
assertParameter(inspectParameters[2], "auto", null);
assertParameter(inspectParameters[3], "auto", CommandJigsaw.JigsawAdoptionStrategyHandler.class);
assertEquals(CommandJigsaw.JigsawAdoptionPlanHandler.class,
assertParameter(inspectParameters[3], "auto", CommandJigsawAdopt.JigsawAdoptionStrategyHandler.class);
assertEquals(CommandJigsawAdopt.JigsawAdoptionPlanHandler.class,
apply.getParameters()[0].getAnnotation(Param.class).customHandler());
CommandJigsaw.JigsawAdoptionStrategyHandler strategyHandler =
new CommandJigsaw.JigsawAdoptionStrategyHandler();
CommandJigsawAdopt.JigsawAdoptionStrategyHandler strategyHandler =
new CommandJigsawAdopt.JigsawAdoptionStrategyHandler();
assertEquals(List.of("auto", "in-place", "clone"), strategyHandler.getPossibilities());
assertEquals("in-place", strategyHandler.parse("claim", false));
assertEquals("clone", strategyHandler.parse("copy", false));
@@ -178,14 +163,14 @@ public class CommandJigsawContractTest {
Path root = temporaryFolder.newFolder("adoption-provenance").toPath();
assertEquals(IrisStructureAdoptionInputKind.UNOWNED_IRIS,
CommandJigsaw.adoptionInputKind(root, "unowned"));
CommandJigsawAdopt.adoptionInputKind(root, "unowned"));
writeManifest(root, "datapack-created", StructureSource.Kind.DATAPACK,
StructureOwnershipManifest.Provenance.created());
assertEquals(IrisStructureAdoptionInputKind.UNOWNED_IRIS,
CommandJigsaw.adoptionInputKind(root, "datapack-created"));
CommandJigsawAdopt.adoptionInputKind(root, "datapack-created"));
writeManifest(root, "managed-provenance", StructureSource.Kind.IRIS, managedProvenance());
assertEquals(IrisStructureAdoptionInputKind.MANAGED_DATAPACK,
CommandJigsaw.adoptionInputKind(root, "managed-provenance"));
CommandJigsawAdopt.adoptionInputKind(root, "managed-provenance"));
}
@Test
@@ -290,88 +275,74 @@ public class CommandJigsawContractTest {
@Test
public void exposesNestedPieceVariantAndPreviewCommands() throws Exception {
assertNotNull(CommandJigsaw.CommandJigsawPool.class
assertNotNull(CommandJigsawPool.class
.getDeclaredMethod("create", String.class, String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawConnector.class
assertNotNull(CommandJigsawConnector.class
.getDeclaredMethod("channel", String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPiece.class
assertNotNull(CommandJigsawPiece.class
.getDeclaredMethod("create", String.class, String.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPiece.class
assertNotNull(CommandJigsawPiece.class
.getDeclaredMethod("add", String.class, String.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPiece.class
assertNotNull(CommandJigsawPiece.class
.getDeclaredMethod("remove", String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPiece.class
assertNotNull(CommandJigsawPiece.class
.getDeclaredMethod("rotatable", boolean.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPiece.class
assertNotNull(CommandJigsawPiece.class
.getDeclaredMethod("expand")
.getAnnotation(Director.class));
assertEquals("Resize the selected piece object exactly to workcell capacity",
CommandJigsaw.CommandJigsawPiece.class
CommandJigsawPiece.class
.getDeclaredMethod("expand")
.getAnnotation(Director.class)
.description());
assertNotNull(CommandJigsaw.CommandJigsawVariant.class
assertNotNull(CommandJigsawVariant.class
.getDeclaredMethod("weight", String.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawVariant.class
assertNotNull(CommandJigsawVariant.class
.getDeclaredMethod("resize", int.class, int.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawVariant.class
assertNotNull(CommandJigsawVariant.class
.getDeclaredMethod("label", String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawVariant.class
assertNotNull(CommandJigsawVariant.class
.getDeclaredMethod("labelReset")
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawVariant.class
assertNotNull(CommandJigsawVariant.class
.getDeclaredMethod("duplicate")
.getAnnotation(Director.class));
Method duplicateFamily = CommandJigsaw.CommandJigsawVariant.class
Method duplicateFamily = CommandJigsawVariant.class
.getDeclaredMethod("duplicateFamily", String.class);
assertNotNull(duplicateFamily.getAnnotation(Director.class));
assertParameter(duplicateFamily.getParameters()[0], "next", null);
assertNotNull(CommandJigsaw.CommandJigsawWorkcell.class
assertNotNull(CommandJigsawWorkcell.class
.getDeclaredMethod("capacity", int.class, int.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawWorkcell.class
assertNotNull(CommandJigsawWorkcell.class
.getDeclaredMethod("label", String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawWorkcell.class
assertNotNull(CommandJigsawWorkcell.class
.getDeclaredMethod("labelReset")
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawRules.class
assertNotNull(CommandJigsawRules.class
.getDeclaredMethod("limits", int.class, int.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawRules.class
assertNotNull(CommandJigsawRules.class
.getDeclaredMethod("fallback", String.class, String.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPreview.class
assertNotNull(CommandJigsawPreview.class
.getDeclaredMethod("assemble", long.class)
.getAnnotation(Director.class));
assertNotNull(CommandJigsaw.CommandJigsawPreview.class
assertNotNull(CommandJigsawPreview.class
.getDeclaredMethod("gotoPreview")
.getAnnotation(Director.class));
}
@Test
public void pieceCreateUsesResolvedWorkcellCapacityInsteadOfLayoutDefault() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandJigsaw.java")).replace("\r\n", "\n");
int pieceCommands = source.indexOf("public static class CommandJigsawPiece");
int create = source.indexOf("public void create(", pieceCommands);
int add = source.indexOf("public void add(", create);
String createSource = source.substring(create, add);
assertTrue(createSource.contains("targetWorkcell = contextual;"));
assertTrue(createSource.contains("JigsawStudioCellDimensions dimensions = targetWorkcell.capacity();"));
assertFalse(createSource.contains("layout().cellDimensions()"));
}
@Test
public void pieceAddUsesCanonicalAxesForRotatedRectangularPlanarWorkcells() {
JigsawStudioLayout layout = nonuniformPlanarLayout();
@@ -422,14 +393,14 @@ public class CommandJigsawContractTest {
public void everyExecutableCommandRejectsNonPlayerOrigins() {
Class<?>[] commandTypes = {
CommandJigsaw.class,
CommandJigsaw.CommandJigsawConnector.class,
CommandJigsaw.CommandJigsawPool.class,
CommandJigsaw.CommandJigsawPiece.class,
CommandJigsaw.CommandJigsawVariant.class,
CommandJigsaw.CommandJigsawWorkcell.class,
CommandJigsaw.CommandJigsawRules.class,
CommandJigsaw.CommandJigsawPreview.class,
CommandJigsaw.CommandJigsawAdopt.class
CommandJigsawConnector.class,
CommandJigsawPool.class,
CommandJigsawPiece.class,
CommandJigsawVariant.class,
CommandJigsawWorkcell.class,
CommandJigsawRules.class,
CommandJigsawPreview.class,
CommandJigsawAdopt.class
};
for (Class<?> commandType : commandTypes) {
@@ -446,17 +417,17 @@ public class CommandJigsawContractTest {
public void exportOutputIsOneSafeChildArtifact() {
Path root = Path.of("build", "jigsaw-exports").toAbsolutePath().normalize();
assertEquals(root.resolve("village.zip"), CommandJigsaw.resolveExportDestination(
assertEquals(root.resolve("village.zip"), CommandJigsawExports.resolveExportDestination(
root, "village", VanillaJigsawExportFormat.ZIP));
assertEquals(root.resolve("village"), CommandJigsaw.resolveExportDestination(
assertEquals(root.resolve("village"), CommandJigsawExports.resolveExportDestination(
root, "village", VanillaJigsawExportFormat.DIRECTORY));
assertThrows(IllegalArgumentException.class, () -> CommandJigsaw.resolveExportDestination(
assertThrows(IllegalArgumentException.class, () -> CommandJigsawExports.resolveExportDestination(
root, "", VanillaJigsawExportFormat.DIRECTORY));
assertThrows(IllegalArgumentException.class, () -> CommandJigsaw.resolveExportDestination(
assertThrows(IllegalArgumentException.class, () -> CommandJigsawExports.resolveExportDestination(
root, ".", VanillaJigsawExportFormat.DIRECTORY));
assertThrows(IllegalArgumentException.class, () -> CommandJigsaw.resolveExportDestination(
assertThrows(IllegalArgumentException.class, () -> CommandJigsawExports.resolveExportDestination(
root, "../all-exports", VanillaJigsawExportFormat.DIRECTORY));
assertThrows(IllegalArgumentException.class, () -> CommandJigsaw.resolveExportDestination(
assertThrows(IllegalArgumentException.class, () -> CommandJigsawExports.resolveExportDestination(
root, "nested/export", VanillaJigsawExportFormat.DIRECTORY));
}
@@ -467,42 +438,42 @@ public class CommandJigsawContractTest {
Path firstDestination = Path.of("build", "jigsaw-exports", "first.zip");
Path secondDestination = Path.of("build", "jigsaw-exports", "second.zip");
assertEquals(true, CommandJigsaw.beginExport(firstPlayer, firstDestination));
assertEquals(true, CommandJigsawExports.beginExport(firstPlayer, firstDestination));
try {
assertEquals(false, CommandJigsaw.beginExport(firstPlayer, secondDestination));
assertEquals(false, CommandJigsaw.beginExport(secondPlayer, firstDestination));
assertEquals(false, CommandJigsawExports.beginExport(firstPlayer, secondDestination));
assertEquals(false, CommandJigsawExports.beginExport(secondPlayer, firstDestination));
} finally {
CommandJigsaw.finishExport(firstPlayer, firstDestination);
CommandJigsawExports.finishExport(firstPlayer, firstDestination);
}
assertEquals(true, CommandJigsaw.beginExport(secondPlayer, firstDestination));
CommandJigsaw.finishExport(secondPlayer, firstDestination);
assertEquals(true, CommandJigsawExports.beginExport(secondPlayer, firstDestination));
CommandJigsawExports.finishExport(secondPlayer, firstDestination);
}
@Test
public void exportStartFailuresHavePreciseOperatorMessages() {
assertEquals("The active Jigsaw Studio is no longer available.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.NOT_ACTIVE));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.NOT_ACTIVE));
assertEquals("Only the Jigsaw Studio owner can export this project.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.NOT_OWNER));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.NOT_OWNER));
assertEquals("Wait for the pending autosave or discard the edits before exporting the on-disk graph.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.DIRTY));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.DIRTY));
assertEquals("The active Jigsaw Studio is closing and cannot be exported.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.CLOSING));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.CLOSING));
assertEquals("Wait for the current Jigsaw Studio save to finish before exporting.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.SAVE_IN_PROGRESS));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.SAVE_IN_PROGRESS));
assertEquals("Wait for the current Jigsaw Studio operation to finish before exporting.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.OPERATION_IN_PROGRESS));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.OPERATION_IN_PROGRESS));
assertEquals("A Jigsaw Studio export is already in progress.",
CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.IN_PROGRESS));
CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.IN_PROGRESS));
assertThrows(IllegalArgumentException.class,
() -> CommandJigsaw.exportStartError(JigsawStudioService.ExportStart.STARTED));
() -> CommandJigsawExports.exportStartError(JigsawStudioService.ExportStart.STARTED));
}
@Test
public void exportLeaseReleaseActionRunsExactlyOnce() {
AtomicInteger releases = new AtomicInteger();
CommandJigsaw.ExportLease lease = new CommandJigsaw.ExportLease(releases::incrementAndGet);
CommandJigsawExports.ExportLease lease = new CommandJigsawExports.ExportLease(releases::incrementAndGet);
lease.release();
lease.release();
@@ -510,25 +481,6 @@ public class CommandJigsawContractTest {
assertEquals(1, releases.get());
}
@Test
public void exportSourceAcquiresStudioLeaseBeforeStaticLeaseAndReleasesBothPaths() throws Exception {
String source = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandJigsaw.java")).replace("\r\n", "\n");
int serviceLease = source.indexOf("studioService.tryBeginExport(requestId, playerId)");
int staticLease = source.indexOf("beginExport(playerId, destination)", serviceLease);
int dispatch = source.indexOf("J.a(() -> runExport(operation))", staticLease);
int schedulingRelease = source.indexOf("operation.lease().release()", dispatch);
int exporter = source.indexOf("new VanillaJigsawDatapackExporter().export(operation.request())", dispatch);
int completionRelease = source.indexOf("operation.lease().release()", exporter);
assertTrue(serviceLease >= 0);
assertTrue(staticLease > serviceLease);
assertTrue(dispatch > staticLease);
assertTrue(schedulingRelease > dispatch);
assertTrue(exporter > schedulingRelease);
assertTrue(completionRelease > exporter);
}
private static void assertCommand(String name, Class<?>... parameterTypes) throws Exception {
Method method = CommandJigsaw.class.getDeclaredMethod(name, parameterTypes);
assertNotNull(method.getAnnotation(Director.class));
@@ -7,10 +7,8 @@ import art.arcane.iris.core.pack.PackValidationResult;
import art.arcane.volmlib.util.director.compat.DirectorAnnotationCompatibility;
import art.arcane.volmlib.util.director.runtime.DirectorNodeDescriptor;
import art.arcane.volmlib.util.director.runtime.DirectorParameterDescriptor;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import org.junit.After;
import org.junit.Before;
import art.arcane.iris.testsupport.PlatformLeakGuard;
import org.junit.Rule;
import org.junit.Test;
import java.util.List;
@@ -20,22 +18,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class CommandPackCompatTest {
private IrisPlatform previousPlatform;
/** The persisted Minecraft version is only used when no platform is bound, so pin that here. */
@Before
public void unbindPlatform() {
previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
IrisPlatforms.unbind();
}
@After
public void rebindPlatform() {
IrisPlatforms.unbind();
if (previousPlatform != null) {
IrisPlatforms.bind(previousPlatform);
}
}
@Rule
public final PlatformLeakGuard leakGuard = PlatformLeakGuard.clean();
private static CompatFinding block(CompatAction action, String subjectKey) {
return new CompatFinding(
@@ -7,8 +7,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@@ -212,20 +210,6 @@ public class IrisPapiExpansionTest {
assertTrue(expansion.persist());
}
@Test
public void theReadmeDocumentsEveryPublishedKeyAndEveryRetiredOne() throws Exception {
String readme = Files.readString(Path.of(System.getProperty("iris.readmeSource")));
for (String key : PUBLISHED_KEYS) {
assertTrue("README must document %iris_" + key + "%", readme.contains("%iris_" + key + "%"));
}
for (String retired : RETIRED_KEYS) {
assertTrue("README must carry the migration row for %iris_" + retired + "%",
readme.contains("%iris_" + retired + "%"));
}
}
@Test
public void theTerrainServiceIsTheOnlyDoorIntoIris() {
IrisTerrainService service = new FakeIrisTerrainService();
@@ -1,137 +0,0 @@
package art.arcane.iris.core.link;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class IrisPapiLifecycleTest {
private static final Path PLUGIN_SOURCE = Path.of("src/main/java/art/arcane/iris/Iris.java");
private static final String SETUP = "private void setupPapi() {";
private static final String TEARDOWN = "private void teardownPapi() {";
private static String source() throws Exception {
// The assertions below match against literals written with \n, so a CRLF checkout has to
// be folded first or every multi-line expectation misses.
return Files.readString(PLUGIN_SOURCE).replace("\r\n", "\n");
}
private static String body(String declaration) throws Exception {
String source = source();
int start = source.indexOf(declaration);
assertTrue("Iris.java must declare " + declaration, start >= 0);
int open = source.indexOf('{', start);
int depth = 0;
for (int index = open; index < source.length(); index++) {
char character = source.charAt(index);
if (character == '{') {
depth++;
continue;
}
if (character != '}') {
continue;
}
depth--;
if (depth == 0) {
return source.substring(open + 1, index);
}
}
throw new AssertionError(declaration + " is not brace balanced");
}
@Test
public void registrationIsGatedOnPlaceholderApiBeingEnabled() throws Exception {
assertTrue("setupPapi must bail out when PlaceholderAPI is absent",
body(SETUP).contains("if (!PlaceholderRegistration.isPlaceholderApiEnabled()) {"));
}
@Test
public void theRegistrationTheListenerAndTheStateAreAllRetained() throws Exception {
String source = source();
assertTrue(source.contains("private volatile PlaceholderRegistration papiRegistration;"));
assertTrue(source.contains("private volatile IrisPapiListener papiListener;"));
assertTrue(source.contains("private volatile IrisPapiState papiState;"));
}
@Test
public void teardownUnregistersTheExpansionTheListenerAndClearsTheState() throws Exception {
String teardown = body(TEARDOWN);
assertTrue("the retained registration must be unregistered inside teardownPapi",
teardown.contains("registration.unregister();"));
assertTrue("the retained listener must be detached inside teardownPapi",
teardown.contains("HandlerList.unregisterAll(listener);"));
assertTrue("the retained state must drop every held world reference inside teardownPapi",
teardown.contains("state.clear();"));
assertTrue("teardownPapi must drop the retained listener", teardown.contains("papiListener = null;"));
assertTrue("teardownPapi must drop the retained registration", teardown.contains("papiRegistration = null;"));
assertTrue("teardownPapi must drop the retained state", teardown.contains("papiState = null;"));
}
@Test
public void bothDisablePathsTearThePlaceholderSurfaceDown() throws Exception {
String disable = body("public void onDisable() {");
String preUnload = body("public void onPreUnload(ReloadAware.PreUnloadReason reason) {");
int disableTeardown = disable.indexOf("teardownPapi();");
int preUnloadTeardown = preUnload.indexOf("teardownPapi();");
assertTrue("onDisable must tear the expansion down before branching into runtime shutdown",
disableTeardown >= 0 && disableTeardown < disable.indexOf("IrisToolbelt.isServerStopping()"));
assertTrue("the BileTools pre-unload hook must tear the expansion down before any shutdown branch",
preUnloadTeardown >= 0 && preUnloadTeardown < preUnload.indexOf("IrisToolbelt.isServerStopping()"));
}
@Test
public void aFailedListenerAttachDoesNotLeaveTheExpansionRegistered() throws Exception {
String setup = body(SETUP);
int attach = setup.indexOf("registerEvents(listener, this)");
assertTrue("the listener must be attached inside setupPapi", attach >= 0);
int rescue = setup.indexOf("} catch (Throwable failure) {", attach);
assertTrue("the attach must be guarded inside setupPapi", rescue > attach);
int rollback = setup.indexOf("registration.unregister();", rescue);
assertTrue("a failed attach must roll the registration back inside setupPapi", rollback > rescue);
int bail = setup.indexOf("return;", rollback);
assertTrue("a failed attach must leave setupPapi", bail > rollback);
int retained = setup.indexOf("papiRegistration = registration;");
assertTrue("setupPapi must retain the registration", retained > 0);
assertTrue("the registration may only be retained after a successful attach", retained > bail);
}
@Test
public void theExpansionIsNeverConstructedFromAPluginStatic() throws Exception {
String setup = body(SETUP);
assertFalse("the plugin class must not construct the expansion: that forces PlaceholderExpansion to load during enable and crashes a server without PlaceholderAPI",
setup.contains("new IrisPapiExpansion("));
assertTrue("the expansion takes its state as a constructor argument, built inside the installer",
installerSource().contains("new IrisPapiExpansion(state, logger)"));
assertFalse("the hand rolled PlaceholderAPI presence check must be gone",
source().contains("isPluginEnabled(\"PlaceholderAPI\")"));
}
private static String installerSource() throws Exception {
return java.nio.file.Files.readString(java.nio.file.Path.of(
"src/main/java/art/arcane/iris/core/link/IrisPapiInstaller.java")).replace("\r\n", "\n");
}
}
@@ -1,53 +0,0 @@
package art.arcane.iris.core.runtime;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class StudioPlayerModeContractTest {
@Test
public void autoStartedStudioUsesSpectatorMode() throws IOException {
String plugin = Files.readString(Path.of("src/main/java/art/arcane/iris/Iris.java")).replace("\r\n", "\n");
String commands = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandStudio.java")).replace("\r\n", "\n");
assertFalse(plugin.contains("GameMode.CREATIVE"));
assertFalse(commands.contains("GameMode.CREATIVE"));
assertTrue(plugin.contains("GameMode.SPECTATOR"));
}
@Test
public void tpStudioUsesThePreparedCoordinatorEntry() throws IOException {
String commands = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandStudio.java")).replace("\r\n", "\n");
int methodStart = commands.indexOf("public void tpstudio()");
int methodEnd = commands.indexOf("\n @Director", methodStart);
String method = commands.substring(methodStart, methodEnd);
assertTrue(method.contains("StudioSVC studioService = Iris.service(StudioSVC.class)"));
assertTrue(method.contains("studioService.teleportToActiveProject(player)"));
assertFalse(method.contains("setGameMode("));
assertFalse(method.contains("getActiveProject()"));
assertFalse(method.contains("BukkitPlatform.teleportAsync"));
assertFalse(method.contains("BukkitWorldBinding.spawnLocation"));
}
@Test
public void editingStudiosRemainCreative() throws IOException {
String objectCommands = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandObject.java")).replace("\r\n", "\n");
String jigsawCommands = Files.readString(Path.of(
"src/main/java/art/arcane/iris/core/commands/CommandJigsaw.java")).replace("\r\n", "\n");
assertTrue(objectCommands.contains("GameMode.CREATIVE"));
assertTrue(objectCommands.contains("StudioOpenCoordinator.StudioOpenKind.OBJECT"));
assertTrue(jigsawCommands.contains("GameMode.CREATIVE"));
assertFalse(objectCommands.contains("GameMode.SPECTATOR"));
assertFalse(jigsawCommands.contains("GameMode.SPECTATOR"));
}
}
@@ -1,195 +0,0 @@
package art.arcane.iris.core.service;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class IrisApiWiringContractTest {
@Test
public void theTerrainServiceRegistersOnBothRegistriesAndReleasesBoth() throws IOException {
String source = source("iris.terrainSvcSource");
String onEnable = method(source, "public void onEnable()");
String onDisable = method(source, "public void onDisable()");
assertTrue(onEnable.contains("Bukkit.getServicesManager().register("));
assertTrue(onEnable.contains("IrisTerrainService.class"));
assertTrue(onEnable.contains("IrisServices.register(IrisTerrainService.class, this)"));
assertTrue(onDisable.contains("Bukkit.getServicesManager().unregister(IrisTerrainService.class, this)"));
assertTrue(onDisable.contains("IrisServices.remove(IrisTerrainService.class)"));
assertBefore(onDisable, "serviceEnabled.set(false)", "Bukkit.getServicesManager().unregister(");
}
@Test
public void theTerrainServiceNeverForcesEngineInitialisationOrLoadsTheMantle() throws IOException {
String source = source("iris.terrainSvcSource");
assertFalse("isIrisWorld must not touch the generator", source.contains("IrisToolbelt"));
assertFalse("isIrisWorld must not touch the generator", source.contains(".touch("));
assertFalse("terrain queries must not load mantle chunks", source.contains("getMantle()"));
assertFalse("terrain queries must not load mantle chunks", source.contains("getObjectsAt("));
assertFalse("terrain queries must not load mantle chunks", source.contains("getPOIsAt("));
assertFalse("terrain queries must not load mantle chunks", source.contains("getCaveOrMantleBiome("));
assertFalse("terrain queries must never block", source.contains(".join()"));
assertFalse("terrain queries must never block", source.contains("synchronized"));
assertFalse("terrain queries must never block", source.contains("J.sfut("));
}
@Test
public void sampleColumnsBoundsTheQueryBeforeItWalksAndTreatsAThrowingSinkAsARefusal() throws IOException {
String sampleColumns = method(source("iris.terrainSvcSource"),
"public boolean sampleColumns(World world, IrisColumnQuery query, IrisColumnSink sink)");
assertBefore(sampleColumns, "IrisSampleLimits.withinLimits(", "IrisColumnWalk.walk(");
assertBefore(sampleColumns, "IrisColumnWalk.walk(", "catch (Throwable error)");
assertTrue(sampleColumns.contains("reportSinkFault(world, error)"));
assertTrue(sampleColumns.contains("return false;"));
assertTrue("the walk must abort when the engine closes underneath it",
sampleColumns.contains("engine.isClosed()"));
}
@Test
public void thePregeneratorDispatchesPhasesFromItsExistingTickAndNeverBlocksOnTheSink() throws IOException {
String source = source("iris.pregeneratorJobSource");
String dispatch = method(source, "private void dispatchApiPhases(List<PregenApiPhase> phases)");
assertTrue(dispatch.contains("IrisServices.getOrNull(PregenApiSink.class)"));
assertTrue(dispatch.contains("catch (Throwable error)"));
assertBefore(dispatch, "sink.pregen(phase, progress)", "catch (Throwable error)");
assertFalse(dispatch.contains(".join()"));
assertTrue(method(source, "public void onTick(").contains("dispatchApiPhases(apiPhases.onTick(paused()))"));
assertTrue(method(source, "public void onSaving()").contains("dispatchApiPhases(apiPhases.onSaving())"));
assertTrue(method(source, "public void onClose()").contains("dispatchApiPhases(apiPhases.onClose(reachedTotal()))"));
}
@Test
public void worldPhasesAreFiredOutsideTheRegistrationLock() throws IOException {
String source = source("iris.engineSvcSource");
String add = method(source, "private void add(World world)");
assertBefore(add, "catch (RejectedExecutionException exception)", "phases.ready(world)");
assertBefore(add, "registered = true;", "phases.ready(world)");
String remove = method(source,
"private boolean remove(World world, CompletionStage<Boolean> unloadBoundary)");
assertBefore(remove, "registered = worlds.remove(world)", "phases.closing(world)");
assertBefore(remove, "phases.closing(world)",
"deferCloseUntilWorldUnload(world, registered, closing, unloadBoundary)");
}
@Test
public void everyRegisteredWorldIsAnnouncedClosingWhenTheServiceShutsDown() throws IOException {
String onDisable = method(source("iris.engineSvcSource"), "public void onDisable()");
assertTrue("service shutdown must announce ENGINE_CLOSING for every registered world",
onDisable.contains("phases.closing(teardown.world())"));
assertBefore(onDisable, "worlds.clear()", "phases.closing(teardown.world())");
assertBefore(onDisable, "phases.closing(teardown.world())", "shutdownAndDrain(activeService)");
assertBefore(onDisable, "phases.closing(teardown.world())",
"startClose(teardown.registered(), teardown.closing())");
}
@Test
public void aReplacedEngineIsAnnouncedClosingBeforeTheRetryReRegistersTheWorld() throws IOException {
String add = method(source("iris.engineSvcSource"), "private void add(World world)");
assertBefore(add, "catch (RejectedExecutionException exception)", "phases.closing(world)");
assertBefore(add, "phases.closing(world)", "retryRegistrationAfterClose(world, retryAfter)");
assertBefore(add, "phases.closing(world)", "startClose(replaced, replacementClose)");
}
@Test
public void aWorldPhaseIsNeverConditionalOnAnotherServicesRegistration() throws IOException {
String source = source("iris.apiEventSvcSource");
String fire = method(source, "public static void fireWorldPhase(World world, IrisWorldPhase phase)");
assertFalse("world lifecycle must not resolve a swappable service to build its payload",
fire.contains("IrisServices"));
assertFalse("world lifecycle must not resolve a swappable service to build its payload",
fire.contains("IrisTerrainService"));
assertTrue(fire.contains("deliver(new IrisWorldEngineEvent(world, phase, describe(world, phase)))"));
String describe = method(source, "private static IrisWorldInfo describe(World world, IrisWorldPhase phase)");
assertTrue(describe.contains("IrisWorldInfoFactory.forWorld(world)"));
assertTrue("an undescribable world must be reported, not swallowed",
describe.contains("IrisLogging.reportError("));
assertTrue("an undescribable world must still deliver the phase", describe.contains("return null;"));
}
@Test
public void aWorldPhaseRaisedFromAServerThreadIsDeliveredBeforeThatThreadMovesOn() throws IOException {
String deliver = method(source("iris.apiEventSvcSource"), "private static void deliver(Event event)");
assertBefore(deliver, "Bukkit.isPrimaryThread()", "Bukkit.getPluginManager().callEvent(event)");
assertBefore(deliver, "Bukkit.getPluginManager().callEvent(event)", "Iris.callEvent(event)");
}
@Test
public void theWorldInfoFactoryNeverForcesEngineInitialisationOrLoadsTheMantle() throws IOException {
String source = source("iris.worldInfoFactorySource");
assertFalse("the factory must not touch the generator", source.contains("IrisToolbelt"));
assertFalse("the factory must not touch the generator", source.contains(".touch("));
assertFalse("the factory must not load mantle chunks", source.contains("getMantle()"));
assertFalse("the factory must never block", source.contains(".join()"));
assertFalse("the factory must never block", source.contains("synchronized"));
assertTrue("the factory must refuse a closed engine", source.contains("engine.isClosed()"));
}
@Test
public void theHotloadHookStillFiresTheLegacyEventAlongsideTheApiEvent() throws IOException {
String hook = method(source("iris.bukkitEnginePlatformHooksSource"), "public void fireHotloadEvent(Engine engine)");
assertBefore(hook, "new IrisEngineHotloadEvent(engine)",
"IrisApiEventSVC.fireWorldPhase(BukkitWorldBinding.world(engine.getWorld()), IrisWorldPhase.ENGINE_HOTLOADED)");
}
@Test
public void theEventServiceNeverLetsAThirdPartyFailureEscapeALifecyclePath() throws IOException {
String fire = method(source("iris.apiEventSvcSource"),
"public static void fireWorldPhase(World world, IrisWorldPhase phase)");
assertTrue(fire.contains("catch (Throwable error)"));
assertTrue(fire.contains("IrisLogging.reportError("));
assertFalse(fire.contains("printStackTrace"));
}
private static String source(String property) throws IOException {
String path = System.getProperty(property);
assertTrue("missing source property " + property, path != null && !path.isBlank());
return Files.readString(Path.of(path));
}
private static void assertBefore(String source, String first, String second) {
int firstIndex = source.indexOf(first);
int secondIndex = source.indexOf(second);
assertTrue("Missing source contract token: " + first, firstIndex >= 0);
assertTrue("Missing source contract token: " + second, secondIndex >= 0);
assertTrue(first + " must occur before " + second, firstIndex < secondIndex);
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue("Missing source contract signature: " + signature, start >= 0);
int openBrace = source.indexOf('{', start);
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
int depth = 0;
for (int index = openBrace; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}
+1 -1
View File
@@ -141,6 +141,7 @@ dependencies {
implementation("net.fabricmc:fabric-loader:${fabricLoaderVersion}")
testImplementation('junit:junit:4.13.2')
testImplementation('org.mockito:mockito-core:5.23.0')
testImplementation(testFixtures('art.arcane:core'))
testImplementation(libs.spigot) {
transitive = false
}
@@ -207,7 +208,6 @@ tasks.named('compileJava', JavaCompile).configure {
}
tasks.named('test').configure {
systemProperty('iris.moddedCommonSources', file('../modded-common/src/main/java').absolutePath)
}
loom {
+1 -1
View File
@@ -158,6 +158,7 @@ dependencies {
implementation minecraft.dependency("net.minecraftforge:forge:${forgeVersion}")
testImplementation('junit:junit:4.13.2')
testImplementation('org.mockito:mockito-core:5.23.0')
testImplementation(testFixtures('art.arcane:core'))
testImplementation(libs.spigot) {
transitive = false
}
@@ -240,7 +241,6 @@ tasks.named('compileJava', JavaCompile).configure {
}
tasks.named('test').configure {
systemProperty('iris.moddedCommonSources', file('../modded-common/src/main/java').absolutePath)
}
processResources {
@@ -73,15 +73,9 @@ public class IrisModLanguageAssetsTest {
private Set<String> resourceFiles() throws Exception {
URL resource = IrisModLanguageAssetsTest.class.getClassLoader().getResource(ROOT);
Path directory;
if (resource != null && "file".equals(resource.getProtocol())) {
directory = Path.of(resource.toURI());
} else {
String sources = System.getProperty("iris.moddedCommonSources");
assertNotNull("Missing mod language resource directory and source root", sources);
directory = Path.of(sources).getParent()
.resolve("resources").resolve(ROOT);
}
assertNotNull("Missing mod language resource directory: " + ROOT, resource);
assertEquals("Mod language resources must resolve to a directory on disk", "file", resource.getProtocol());
Path directory = Path.of(resource.toURI());
try (Stream<Path> paths = Files.list(directory)) {
return paths
.filter(Files::isRegularFile)
@@ -9,13 +9,9 @@ import net.minecraft.world.level.biome.MobSpawnSettings;
import org.junit.Test;
import org.junit.BeforeClass;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class IrisModdedChunkGeneratorSpawnTest {
@BeforeClass
@@ -48,21 +44,4 @@ public class IrisModdedChunkGeneratorSpawnTest {
assertEquals(explicitCow, entries.get(2).value());
assertEquals(3, entries.get(2).weight());
}
@Test
public void vanillaChunkGenerationMobsUseTheVisibleBiomesVanillaDerivative() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedChunkGenerator.java");
String source = Files.readString(sourcePath);
int spawnStart = source.indexOf("public void spawnOriginalMobs");
int spawnEnd = source.indexOf("@Override", spawnStart + 1);
String spawn = source.substring(spawnStart, spawnEnd);
assertTrue(spawn.contains("spawnTables.initializeVanillaSpawnBiomes(registry)"));
assertTrue(spawn.contains("structureBiomeSource.getVisibleSurfaceBiome("));
assertTrue(spawn.contains("spawnTables.vanillaSpawnBiome(visibleBiome.value())"));
assertTrue(spawn.contains("NaturalSpawner.spawnMobsForChunkGeneration("));
assertTrue(spawn.contains("new LegacyRandomSource(RandomSupport.generateUniqueSeed())"));
assertTrue(spawn.contains("random.setDecorationSeed(region.getSeed()"));
}
}
@@ -14,9 +14,6 @@ import net.minecraft.server.Bootstrap;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@@ -64,16 +61,10 @@ public class IrisModdedStructureParityTest {
}
@Test
public void strongholdRingSearchSamplesOneQuartColumnPerChunk() throws IOException {
public void strongholdRingSearchSamplesOneQuartColumnPerChunk() {
assertEquals(4, IrisModdedBiomeSource.horizontalBiomeSearchQuartStep(0, 112));
assertEquals(1, IrisModdedBiomeSource.horizontalBiomeSearchQuartStep(1, 112));
assertEquals(1, IrisModdedBiomeSource.horizontalBiomeSearchQuartStep(0, 111));
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
assertTrue(source.contains("x, y, z, searchRadius, quartStep, allowed, random, false, sampler"));
assertTrue(source.contains(
"return super.findBiomeHorizontal(x, y, z, searchRadius, allowed, random, sampler)"));
}
@Test
@@ -130,126 +121,12 @@ public class IrisModdedStructureParityTest {
}
@Test
public void visibleBiomeResolutionSelectsStackOwnershipBeforeHostCaves() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
int resolutionStart = source.indexOf("private BiomeResolution resolveBiomeResolution(");
int resolutionEnd = source.indexOf("private Holder<Biome> resolveRequiredStructureBiome(", resolutionStart);
assertTrue(resolutionStart >= 0);
assertTrue(resolutionEnd > resolutionStart);
String resolution = source.substring(resolutionStart, resolutionEnd);
assertTrue(resolution.contains("resolveDimensionStackLayer("));
assertTrue(resolution.contains("!stackLayer.terrainContext().isSelfReferencing()"));
assertTrue(resolution.indexOf("resolveDimensionStackLayer(")
< resolution.indexOf("boolean underground"));
assertTrue(resolution.contains("includeDimensionStack"));
assertTrue(resolution.contains(
"return resolveBiomeResolution(engine, quartX, quartY, quartZ, false)"));
assertTrue(source.contains("resolution.packName(), resolution.dimension(), customBiome.getId()"));
int helperStart = source.indexOf("private static IrisBiome resolveSurfaceStructureBiome(");
int helperEnd = source.indexOf("private static Set<String> registeredBiomeKeys(", helperStart);
String helper = source.substring(helperStart, helperEnd);
assertTrue(helper.contains("engine.getComplex().getTrueBiomeStream().get(blockX, blockZ)"));
assertFalse(helper.contains("getDimensionStackContext()"));
assertFalse(helper.contains("getSurfaceBiome("));
}
@Test
public void stackBiomesAreVisibleButExcludedFromStructureReachability() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
assertTrue(source.contains("return biomeKeySets().structureRequired()"));
assertTrue(source.contains("generatedBiomeKeys.addAll(keys.visibleRequired())"));
assertTrue(source.contains("collectStructureBiomeKeys("));
assertTrue(source.contains("dimension.getReachableBiomes(() -> data)"));
}
@Test
public void biomeLocatorSearchesTheVisibleStack() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
int start = source.indexOf("public Pair<BlockPos, Holder<Biome>> findClosestBiome3d(");
int end = source.indexOf("private Holder<Biome> getNoiseBiome(", start);
String method = source.substring(start, end);
assertTrue(method.contains("modded_locate_visible_biome"));
assertTrue(method.contains("return super.findClosestBiome3d("));
assertTrue(method.contains("collectVisibleBiomeHolders()"));
assertTrue(method.contains("QuartPos.toBlock(quartX), QuartPos.toBlock(quartZ)"));
assertTrue(method.contains("resolveVisibleBiome("));
assertFalse(method.contains("Holder<Biome> structureBiome = getNoiseBiome("));
assertTrue(method.indexOf("tryAcquireGenerationLease(engine, \"modded_locate_visible_biome\")")
< method.indexOf("engine.getDimensionStackContext()"));
}
@Test
public void surfaceSpawnBiomeUsesTheVisibleQuartCell() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
int start = source.indexOf("Holder<Biome> getVisibleSurfaceBiome(");
int end = source.indexOf("boolean isStructureReachable(", start);
String method = source.substring(start, end);
assertTrue(method.contains("QuartPos.fromBlock(blockX)"));
assertTrue(method.contains("QuartPos.toBlock(quartX)"));
assertTrue(method.contains("QuartPos.fromBlock(internalY + engine.getMinHeight())"));
assertTrue(method.contains("stackContext.getLayout(sampleX, sampleZ).surfaceLayer()"));
assertTrue(method.contains("visibleBiomeCache"));
assertTrue(method.contains("isBiomeCacheable(engine, sampleX, sampleZ)"));
assertTrue(method.indexOf("boolean cacheable = isBiomeCacheable(engine, sampleX, sampleZ)")
< method.indexOf("Engine.hostHeight(engine, sampleX, sampleZ, true)"));
assertCacheGuarded(method, "visibleBiomeCache");
}
@Test
public void temporaryNaturalBiomeAnswersAreNotMemoized() throws IOException {
public void temporaryNaturalBiomeAnswersAreNotMemoized() {
Engine engine = mock(Engine.class);
when(engine.answersFromNaturalTerrain(12, -8)).thenReturn(true);
assertFalse(IrisModdedBiomeSource.isBiomeCacheable(engine, 12, -8));
when(engine.answersFromNaturalTerrain(12, -8)).thenReturn(false);
assertTrue(IrisModdedBiomeSource.isBiomeCacheable(engine, 12, -8));
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
int structureStart = source.indexOf("private Holder<Biome> getNoiseBiome(Engine engine");
int structureEnd = source.indexOf("Holder<Biome> getVisibleNoiseBiome(", structureStart);
String structure = source.substring(structureStart, structureEnd);
assertTrue(structure.contains("QuartPos.toBlock(quartX)"));
assertTrue(structure.contains("QuartPos.toBlock(quartZ)"));
assertCacheGuarded(structure, "structureBiomeCache");
int visibleStart = source.indexOf(
"private Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(");
int visibleEnd = source.indexOf("Holder<Biome> getVisibleSurfaceBiome(", visibleStart);
String visible = source.substring(visibleStart, visibleEnd);
assertTrue(visible.contains("QuartPos.toBlock(quartX)"));
assertTrue(visible.contains("QuartPos.toBlock(quartZ)"));
assertCacheGuarded(visible, "visibleBiomeCache");
int predicateStart = source.indexOf("static boolean isBiomeCacheable(");
int predicateEnd = source.indexOf("static boolean isMonumentSurfaceBiomeQuery(", predicateStart);
String predicate = source.substring(predicateStart, predicateEnd);
assertTrue(predicate.contains("return !engine.answersFromNaturalTerrain(blockX, blockZ)"));
assertFalse(predicate.contains("getDimensionStackContext()"));
}
@Test
public void importedFeaturesCollectOnlyHostOwnedStackCells() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedImportedFeatureStage.java"));
assertTrue(source.contains("stackContext.getLayerAt("));
assertTrue(source.contains("layer.terrainContext().isSelfReferencing()"));
assertTrue(source.contains("section.getBiomes().get(quartX, quartY, quartZ)"));
}
@Test
@@ -281,17 +158,6 @@ public class IrisModdedStructureParityTest {
assertTrue(recursiveKeys.contains("layers:sky/aurora"));
}
@Test
public void biomeWriterDerivativeFallbackMatchesCanonicalRecursiveKeys() throws IOException {
String source = Files.readString(Path.of(
System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedBiomeWriter.java"));
assertTrue(source.contains(
"key.equalsIgnoreCase(dimension.getCustomBiomeKey(custom.getId()))"));
assertFalse(source.contains("String dimensionLoadKey = key.substring(0, colon)"));
}
@Test
public void structureStateRejectsBiomesOutsideThePackContract() {
Set<String> generated = Set.of("minecraft:deep_ocean", "minecraft:dark_forest");
@@ -410,21 +276,4 @@ public class IrisModdedStructureParityTest {
public void initialEntitySpawnsUseThePaperCompletionMarker() {
assertSame(MantleFlag.INITIAL_SPAWNED_MARKER, ModdedWorldManager.INITIAL_SPAWN_COMPLETION_FLAG);
}
private static void assertCacheGuarded(String method, String cacheName) {
int predicate = method.indexOf("boolean cacheable = isBiomeCacheable(");
int cache = method.indexOf("BiomeHolderTable cache = " + cacheName, predicate);
int read = method.indexOf("cache.get(", predicate);
int readGuard = method.lastIndexOf("if (cacheable)", read);
int write = method.indexOf("cache.put(", read);
int writeGuard = method.lastIndexOf("if (cacheable)", write);
assertTrue(predicate >= 0);
assertTrue(cache >= 0);
assertTrue(read > predicate);
assertTrue(readGuard >= predicate);
assertTrue(write > read);
assertTrue(writeGuard > read);
}
}
@@ -1,91 +0,0 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertTrue;
public class ModdedDynamicLevelLifecycleContractTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void sharedManagerPublishesDynamicLoadAndUnloadAroundRegistration() throws IOException {
String manager = commonSource("ModdedDimensionManager.java");
String loader = commonSource("ModdedLoader.java");
String injection = method(manager, "private static Handle inject(");
String removal = method(manager, "public static boolean remove(");
String injectionRollback = method(manager, "private static void rollbackInjection(");
String removalRollback = method(manager, "private static void rollbackRemoval(");
assertTrue(loader.contains("void fireDynamicLevelLoad(MinecraftServer server, ServerLevel level);"));
assertTrue(loader.contains("void fireDynamicLevelUnload(MinecraftServer server, ServerLevel level);"));
assertBefore(injection, "serverAccess.putLevelIfAbsent(server, key, level);",
"fireDynamicLevelLoad(server, level);");
assertBefore(removal, "fireDynamicLevelUnload(server, level);",
"serverAccess.removeLevel(server, key);");
assertTrue(injectionRollback.contains("fireDynamicLevelUnload(server, level);"));
assertTrue(removalRollback.contains("fireDynamicLevelLoad(server, level);"));
}
@Test
public void everyLoaderUsesItsNativeLifecycleBus() throws IOException {
String fabric = loaderSource("fabric", "art/arcane/iris/fabric/FabricModdedLoader.java");
String forge = loaderSource("forge", "art/arcane/iris/forge/ForgeModdedLoader.java");
String neoForge = loaderSource("neoforge", "art/arcane/iris/neoforge/NeoForgeModdedLoader.java");
assertTrue(fabric.contains("ServerLevelEvents.LOAD.invoker().onLevelLoad(server, level);"));
assertTrue(fabric.contains("ServerLevelEvents.UNLOAD.invoker().onLevelUnload(server, level);"));
assertTrue(forge.contains("LevelEvent.Load.BUS.post(new LevelEvent.Load(level));"));
assertTrue(forge.contains("LevelEvent.Unload.BUS.post(new LevelEvent.Unload(level));"));
assertTrue(neoForge.contains("NeoForge.EVENT_BUS.post(new LevelEvent.Load(level));"));
assertTrue(neoForge.contains("NeoForge.EVENT_BUS.post(new LevelEvent.Unload(level));"));
}
private static String commonSource(String file) throws IOException {
return Files.readString(commonRoot().resolve("art/arcane/iris/modded").resolve(file))
.replace("\r\n", "\n");
}
private static String loaderSource(String loader, String relative) throws IOException {
Path adaptersRoot = commonRoot().getParent().getParent().getParent().getParent();
return Files.readString(adaptersRoot.resolve(loader).resolve("src/main/java").resolve(relative))
.replace("\r\n", "\n");
}
private static Path commonRoot() {
String root = System.getProperty(SOURCE_ROOT_PROPERTY);
if (root == null || root.isBlank()) {
throw new IllegalStateException("Missing test property " + SOURCE_ROOT_PROPERTY);
}
return Path.of(root);
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
if (start < 0) {
throw new IllegalArgumentException("Missing source method " + signature);
}
int open = source.indexOf('{', start);
int depth = 0;
for (int index = open; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}' && --depth == 0) {
return source.substring(start, index + 1);
}
}
throw new IllegalArgumentException("Unclosed source method " + signature);
}
private static void assertBefore(String source, String first, String second) {
int firstIndex = source.indexOf(first);
int secondIndex = source.indexOf(second);
assertTrue("Missing source token " + first, firstIndex >= 0);
assertTrue("Missing source token " + second, secondIndex >= 0);
assertTrue(first + " must precede " + second, firstIndex < secondIndex);
}
}
@@ -7,12 +7,8 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.ChunkGenerator;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
@@ -24,8 +20,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ModdedGenerationBootstrapBindingTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void publishedLevelRequiresCurrentGeneratorIdentity() {
IrisModdedChunkGenerator generator = mock(IrisModdedChunkGenerator.class, CALLS_REAL_METHODS);
@@ -89,62 +83,4 @@ public class ModdedGenerationBootstrapBindingTest {
assertSame(dynamicLevel, generator.resolveBoundLevel(server, List.of(dynamicLevel)));
verify(server, never()).getLevel(Level.OVERWORLD);
}
@Test
public void firstGenerationStagesProvideAuthoritativeLevelContext() throws IOException {
String source = source("IrisModdedChunkGenerator.java");
String structures = method(source, "public void createStructures(");
String references = method(source, "public void createReferences(");
assertTrue(structures.contains("Engine current = engine(levelKey);"));
assertTrue(references.contains("Engine current = engine(level.getLevel());"));
String publishedBinding = method(source, "private Engine engine(ResourceKey<Level> levelKey)");
assertTrue(publishedBinding.contains("requirePublishedLevel(ModdedEngineBootstrap.currentServer(), levelKey)"));
assertTrue(publishedBinding.contains("return bindGenerationLevel(level);"));
assertFalse(publishedBinding.contains("ModdedServerLevels.level("));
String fullBinding = method(source, "private Engine bindGenerationLevel(ServerLevel level)");
assertTrue(fullBinding.contains("bindLevel(level);"));
assertTrue(fullBinding.contains("Engine bound = readyEngine();"));
String genericBinding = method(source, "Engine engine()");
assertTrue(genericBinding.contains("return bindGenerationLevel(level);"));
}
@Test
public void constructorMixinIsNotPartOfGenerationBootstrap() throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue(sourceRoot != null && !sourceRoot.isBlank());
Path root = Path.of(sourceRoot);
assertFalse(Files.exists(root.resolve(Path.of("art", "arcane", "iris", "modded", "mixin",
"ServerLevelBindingMixin.java"))));
String mixinConfig = Files.readString(root.getParent().resolve("resources/irisworldgen.entity.mixins.json"));
assertFalse(mixinConfig.contains("ServerLevelBindingMixin"));
}
private String source(String fileName) throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue(sourceRoot != null && !sourceRoot.isBlank());
return Files.readString(Path.of(sourceRoot, "art", "arcane", "iris", "modded", fileName));
}
private String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue(start >= 0);
int body = source.indexOf('{', start);
assertTrue(body >= 0);
int depth = 0;
for (int index = body; index < source.length(); index++) {
char token = source.charAt(index);
if (token == '{') {
depth++;
} else if (token == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}
@@ -1,203 +0,0 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedGenerationHistoryRoutingContractTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void startupPublishesOnlyAnImmutableHistoryBoundRuntime() throws IOException {
String source = source("ModdedWorldEngines.java");
String create = method(source, "private static Engine create(");
String createHistoryEngine = method(source, "private static Engine createHistoryEngine(");
String buildEngine = method(source, "private static IrisEngine buildEngine(");
assertTrue(create.contains("ModdedGenerationHistoryStorage.openOrAdopt("));
assertFalse(create.contains("resolvePack("));
assertTrue(createHistoryEngine.contains("candidate.attachGenerationHistory("));
assertTrue(createHistoryEngine.contains("IrisBoundarySignatureSampler.INSTANCE"));
assertTrue(createHistoryEngine.contains("getGenerationTransitionWidthBlocks()"));
assertTrue(createHistoryEngine.contains("router.preloadActiveRuntimes();"));
assertBefore(createHistoryEngine, "history.prepareCurrentGenerator(",
"opened = ModdedGenerationHistoryStorage.resolveActive(history)");
assertBefore(createHistoryEngine, "opened = ModdedGenerationHistoryStorage.resolveActive(history)",
"IrisEngine candidate = buildEngine(level, seed, opened)");
String promoted = method(createHistoryEngine,
"if (history.activeActivation().activationId() != openedActivationId)");
assertBefore(promoted, "close(candidate);", "ModdedGenerationHistoryStorage.resolveActive(history)");
assertBefore(promoted, "ModdedGenerationHistoryStorage.resolveActive(history)",
"candidate = buildEngine(level, seed, promoted)");
assertTrue(createHistoryEngine.contains("GenerationHistoryRuntimeRouter.attach("));
assertTrue(buildEngine.contains("active.packRoot().toFile()"));
assertTrue(buildEngine.contains("history.paths().activationMantleRoot(activation.activationId())"));
assertTrue(buildEngine.contains("epoch.kernelVersion()"));
assertTrue(buildEngine.contains("transitionPlan"));
}
@Test
public void onlyExplicitTransientStudioEnginesBypassHistory() throws IOException {
String manager = source("ModdedDimensionManager.java");
String transientCreate = method(manager, "public static Handle createTransientStudio(");
String persistentCreate = method(manager, "public static Handle createPersistent(");
String engines = source("ModdedWorldEngines.java");
String studio = method(engines, "private static IrisEngine createTransientStudioEngine(");
String generator = source("IrisModdedChunkGenerator.java");
String bypass = method(generator, "boolean allowsGenerationHistoryBypass(");
String route = method(generator, "private GenerationHistoryRuntimeRouter.RuntimeRoute openHistoryRoute(");
assertTrue(transientCreate.contains("ModdedGenerationMode.TRANSIENT_STUDIO"));
assertTrue(persistentCreate.contains("ModdedGenerationMode.PERSISTENT_CREATE"));
assertTrue(studio.contains("IrisData.openRuntime(packDir)"));
assertTrue(studio.contains("IrisEngine.InitializationMode.STUDIO"));
assertFalse(studio.contains("ModdedGenerationHistoryStorage"));
assertFalse(studio.contains("attachGenerationHistory("));
assertTrue(bypass.contains("generationMode != ModdedGenerationMode.TRANSIENT_STUDIO"));
assertTrue(bypass.contains("irisEngine.isStudio()"));
assertTrue(bypass.contains("Only an explicitly transient Iris Studio engine"));
assertBefore(route, "allowsGenerationHistoryBypass(current)", "requireHistoryRouter(current, operation)");
}
@Test
public void everyCoordinateBearingChunkStageOpensItsRoutedRuntime() throws IOException {
String source = source("IrisModdedChunkGenerator.java");
assertRuntimeRoute(source, "public Pair<BlockPos, Holder<Structure>> findNearestMapStructure(");
assertCoordinateRoute(source, "public WeightedList<MobSpawnSettings.SpawnerData> getMobsAt(");
assertRuntimeRoute(source, "public CompletableFuture<ChunkAccess> createBiomes(");
assertRuntimeRoute(source, "public void applyCarvers(");
assertRuntimeRoute(source, "public void buildSurface(");
assertRuntimeRoute(source, "public void applyBiomeDecoration(");
assertRuntimeRoute(source, "public void createStructures(");
assertRuntimeRoute(source, "public void createReferences(");
assertRuntimeRoute(source, "public void spawnOriginalMobs(");
assertCoordinateRoute(source, "public int getBaseHeight(");
assertCoordinateRoute(source, "public NoiseColumn getBaseColumn(");
}
@Test
public void asyncTerrainKeepsTheRouteUntilDurableSemanticClaim() throws IOException {
String source = source("IrisModdedChunkGenerator.java");
String fill = method(source, "public CompletableFuture<ChunkAccess> fillFromNoise(");
String terrain = method(source, "private ChunkAccess generateTerrain(");
String completion = method(source, "private static CompletableFuture<ChunkAccess> closeRouteOnCompletion(");
assertBefore(fill, "openHistoryRoute(", "CompletableFuture.supplyAsync(");
assertTrue(fill.contains("generateTerrain(chunk, generationEngine, pos, air, route)"));
assertTrue(fill.contains("return closeRouteOnCompletion(pipeline, route);"));
assertTrue(terrain.contains("openHistoryRuntimeScope(route)"));
assertBefore(terrain, "generationEngine.generate(", "writeBlocks(chunk, blocks, dimMinY, height)");
assertBefore(terrain, "writeBlocks(chunk, blocks, dimMinY, height)", "route.claimGeneratedSemantics(");
assertTrue(terrain.contains("chunk.getBlockState(position.set(x, dimMinY + y, z))"));
assertTrue(terrain.contains("state.isAir() || state.liquid()"));
assertBefore(terrain, "route.claimGeneratedSemantics(", "ModdedNativeTerrainReceipts.persist(chunk, route)");
assertBefore(terrain, "ModdedNativeTerrainReceipts.persist(chunk, route)", "return chunk;");
assertTrue(completion.contains("pipeline.whenComplete("));
assertTrue(completion.contains("route.close();"));
assertBefore(completion, "pipeline.whenComplete(", "route.detachThread()");
assertBefore(completion, "route.detachThread()", "return completion;");
}
@Test
public void biomeQueriesRouteEachCoordinateAndKeepRuntimeSpecificCaches() throws IOException {
String source = source("IrisModdedBiomeSource.java");
String structure = method(source, "public Holder<Biome> getNoiseBiome(");
String visible = method(source, "Holder<Biome> getVisibleNoiseBiome(");
String batch = method(source, "public Set<Holder<Biome>> getBiomesWithin(");
String resolution = method(source, "private Holder<Biome> resolveVisibleBiome(");
assertTrue(structure.contains("openHistoryCoordinateScope("));
assertTrue(visible.contains("openHistoryCoordinateScope("));
assertTrue(batch.contains("quartX << 2, quartZ << 2"));
assertTrue(source.contains("int runtimeIdentity = engine.getCacheID();"));
assertTrue(source.contains("cache.get(runtimeIdentity, key)"));
assertTrue(source.contains("cache.put(runtimeIdentity, key, resolved)"));
assertBefore(resolution, "historicalPhysicalBiomeKeyAt(", "ModdedWorldgenIds.biomeRef(engine");
}
@Test
public void pendingNativeStagesPreserveSavedStartsAndGuardNewFeatureFootprints() throws IOException {
String generator = source("IrisModdedChunkGenerator.java");
String discrete = method(generator, "private boolean allowsRoutedDiscreteGeneration(");
String decoration = method(generator, "public void applyBiomeDecoration(");
String structures = method(generator, "public void createStructures(");
String mobs = method(generator, "public void spawnOriginalMobs(");
String nativeStage = source("ModdedNativeStructureStage.java");
String adjust = method(nativeStage, "void adjustGeneratedStructures(");
String place = method(nativeStage, "void placeVanillaStructures(");
String savedStart = method(nativeStage, "private boolean isHistoricalStructureStart(");
assertTrue(discrete.contains("chunk.getPersistedStatus().isOrAfter(stage)"));
assertFalse(discrete.contains("router.history().activeActivation().activationId()"));
assertFalse(discrete.contains("return true;"));
assertTrue(discrete.contains("allowsNewGenerationChunk("));
assertTrue(discrete.contains("NativeGenerationWriteGuard.allowsPendingStage(current, chunk, stage)"));
assertTrue(decoration.contains("ChunkStatus.FEATURES"));
assertTrue(structures.contains("ChunkStatus.STRUCTURE_STARTS"));
assertTrue(mobs.contains("ChunkStatus.SPAWN"));
assertBefore(decoration, "chunk.getPersistedStatus().isOrAfter(ChunkStatus.FEATURES)",
"nativeStructures.placeVanillaStructures(");
assertBefore(decoration, "nativeStructures.placeVanillaStructures(", "allowsRoutedDiscreteGeneration(");
assertBefore(decoration, "allowsRoutedDiscreteGeneration(", "importedFeatures.run(");
assertBefore(decoration, "NativeGenerationWriteGuard.allowsDecoration(", "importedFeatures.run(");
assertBefore(structures, "allowsRoutedDiscreteGeneration(", "super.createStructures(");
assertBefore(mobs, "allowsRoutedDiscreteGeneration(", "NaturalSpawner.spawnMobsForChunkGeneration(");
assertBefore(adjust, "allowsNewGenerationFootprint(", "recordWorldCheckStructureShift(");
assertBefore(place, "!isHistoricalStructureStart(current, world, start)", "allowsNewGenerationFootprint(");
assertTrue(savedStart.contains("world.getChunk(origin.x(), origin.z(), ChunkStatus.EMPTY, false)"));
assertTrue(savedStart.contains("ModdedNativeTerrainReceipts.structureActivation(source)"));
assertBefore(structures, "super.createStructures(", "ModdedNativeTerrainReceipts.persistStructureActivation(");
}
private static void assertRuntimeRoute(String source, String signature) {
String body = method(source, signature);
assertTrue(signature + " must open a generation-history route", body.contains("openHistoryRoute("));
assertTrue(signature + " must open its routed runtime", body.contains("openHistoryRuntimeScope(route)"));
}
private static void assertCoordinateRoute(String source, String signature) {
String body = method(source, signature);
assertTrue(signature + " must route its coordinate", body.contains("openHistoryCoordinateScope("));
}
private static void assertBefore(String source, String first, String second) {
int firstIndex = source.indexOf(first);
int secondIndex = source.indexOf(second);
assertTrue("Missing source contract token: " + first, firstIndex >= 0);
assertTrue("Missing source contract token: " + second, secondIndex >= 0);
assertTrue(first + " must occur before " + second, firstIndex < secondIndex);
}
private static String source(String fileName) throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY,
sourceRoot != null && !sourceRoot.isBlank());
return Files.readString(Path.of(sourceRoot, "art", "arcane", "iris", "modded", fileName));
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue("Missing source contract signature: " + signature, start >= 0);
int openBrace = source.indexOf('{', start);
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
int depth = 0;
for (int index = openBrace; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}
@@ -1,244 +0,0 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedGenerationLeaseContractTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void biomeRuntimeReadsAreGenerationLeased() throws IOException {
String source = source("art/arcane/iris/modded/IrisModdedBiomeSource.java");
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_structure_biome\")"));
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_visible_biome\")"));
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_biomes_within\")"));
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_structure_reachability\")"));
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_structure_state_biome\")"));
assertTrue(source.contains("tryAcquireGenerationLease(engine, \"modded_structure_biome_keys\")"));
assertTrue(source.contains("engine == null || engine.isClosed()"));
assertTrue(source.contains("catch (GenerationSessionException e)"));
assertTrue(source.contains("e.isExpectedTeardown()"));
assertTrue(source.contains("Iris structure biome key lookup was rejected during an engine transition"));
assertTrue(source.contains("int runtimeIdentity = engine.getCacheID();"));
assertTrue(source.contains("cache.get(runtimeIdentity, key)"));
assertTrue(source.contains("cache.put(runtimeIdentity, key, resolved)"));
}
@Test
public void terrainAndHeightQueriesShareGenerationSessions() throws IOException {
String source = source("art/arcane/iris/modded/IrisModdedChunkGenerator.java");
assertTrue(source.contains("generationEngine.acquireGenerationLease(\"modded_chunk_pipeline\")"));
assertTrue(source.contains("current.acquireGenerationLease(\"modded_base_height\")"));
assertTrue(source.contains("current.acquireGenerationLease(\"modded_base_column\")"));
assertTrue(source.contains("current.acquireGenerationLease(\"modded_configured_biome_keys\")"));
assertTrue(source.contains("generationEngine.isClosing() || e.isExpectedTeardown()"));
String terrain = method(source, "private ChunkAccess generateTerrain(");
int sessionFailure = terrain.indexOf("catch (GenerationSessionException e)");
int generalFailure = terrain.indexOf("catch (Throwable e)", sessionFailure);
String sessionHandler = terrain.substring(sessionFailure, generalFailure);
assertTrue(sessionHandler.contains("throw new IllegalStateException"));
assertFalse(sessionHandler.contains("return chunk;"));
String references = method(source, "public void createReferences(");
assertTrue(references.contains("requireGenerationLease(current, \"modded_create_references\")"));
assertTrue(references.contains("IrisContext.open(current, lease.sessionId(), null)"));
assertTrue(references.contains("NativeStructureReferenceRepair.createReferences("));
assertFalse(references.contains("super.createReferences(level, structureManager, chunk);"));
}
@Test
public void preservationDereferencesSharedPackData() throws IOException {
String source = source("art/arcane/iris/modded/service/ModdedPreservationService.java");
int dereference = source.indexOf("public void dereference()");
int irisData = source.indexOf("IrisData.dereference();", dereference);
int trackedResources = source.indexOf("threads.removeIf", dereference);
assertTrue(dereference >= 0);
assertTrue(irisData > dereference);
assertTrue(trackedResources > irisData);
}
@Test
public void hotloadShutdownOnlyTargetsItsOwnWorld() throws IOException {
String source = source("art/arcane/iris/modded/service/ModdedStudioHotloadService.java");
int shutdown = source.indexOf("public void shutdownPregenerator(Engine engine)");
int nextMethod = source.indexOf("private boolean throttled", shutdown);
String method = source.substring(shutdown, nextMethod);
assertTrue(method.contains("ModdedPregenJob.shutdownForWorld(world.identity());"));
assertFalse(method.contains("PregeneratorJob.shutdownInstance();"));
}
@Test
public void maintenanceOwnsOneGenerationSessionUntilWorkCompletes() throws IOException {
String source = source("art/arcane/iris/modded/service/ModdedEngineMaintenanceService.java");
String maintain = method(source, "private void maintain(Engine engine, long scheduledAt)");
assertTrue(maintain.contains("engine.acquireGenerationLease(\"modded_engine_maintenance\")"));
assertTrue(maintain.contains("IrisContext.open(engine, lease.sessionId(), null)"));
assertTrue(maintain.contains("exception.isExpectedTeardown()"));
assertTrue(source.contains("active.awaitTermination(INTERRUPT_DRAIN_TIMEOUT_SECONDS, TimeUnit.SECONDS)"));
}
@Test
public void packDownloadAdmissionPrecedesAsyncDispatch() throws IOException {
String source = source("art/arcane/iris/modded/command/IrisModdedCommands.java");
String download = method(source, "static int download(CommandSourceStack source, String rawRequest)");
int admission = download.indexOf("LifecycleOperationCoordinator.get().acquire(");
int executionTracking = download.indexOf("new PackDownloadExecution(");
int dispatch = download.indexOf("scheduler.asyncIfRunning(execution, execution::cancel)");
assertTrue(admission >= 0);
assertTrue(executionTracking > admission);
assertTrue(dispatch > admission);
assertTrue(download.contains("execution.cancel();"));
String execution = method(source, "private static void executeDownload(");
assertTrue(execution.contains("PackDownloader.DownloadCancellation cancellation"));
assertTrue(execution.contains("catch (PackDownloader.PackDownloadCancelledException error)"));
assertTrue(execution.contains("dispatchDownloadFeedback(source,"));
assertFalse(execution.contains("scheduler.global("));
assertFalse(execution.contains("lease.close();"));
String feedback = method(source, "private static void dispatchDownloadFeedback(");
assertTrue(feedback.contains("source.getServer().execute(feedback);"));
}
@Test
public void packDownloadsDrainBeforeModdedSchedulerShutdown() throws IOException {
String commands = source("art/arcane/iris/modded/command/IrisModdedCommands.java");
String shutdownDownloads = method(commands, "public static void shutdownDownloads()");
assertTrue(shutdownDownloads.contains("downloadAdmissionOpen = false;"));
assertTrue(shutdownDownloads.contains("execution.cancel();"));
assertTrue(shutdownDownloads.contains("execution.await("));
String bootstrap = source("art/arcane/iris/modded/ModdedEngineBootstrap.java");
String stop = method(bootstrap, "public static void stop()");
int downloads = stop.indexOf("IrisModdedCommands::shutdownDownloads");
int scheduler = stop.indexOf("scheduler::shutdown");
assertTrue(downloads >= 0);
assertTrue(scheduler > downloads);
}
@Test
public void moddedSchedulerRejectsAndCancelsAbandonedDownloadSubmissions() throws IOException {
String scheduler = source("art/arcane/iris/modded/ModdedScheduler.java");
String dispatch = method(scheduler, "public boolean asyncIfRunning(Runnable task, Runnable rejection)");
assertTrue(dispatch.contains("RejectionAwareTask"));
assertTrue(dispatch.contains("Objects.requireNonNull(rejection"));
String shutdown = method(scheduler, "public void shutdown()");
assertTrue(shutdown.contains("asyncExecutor.shutdownNow()"));
assertTrue(shutdown.contains("rejectAbandonedTasks(abandonedTasks);"));
String reset = method(scheduler, "public void reset()");
assertTrue(reset.contains("asyncExecutor.getQueue().drainTo(abandonedTasks);"));
assertTrue(reset.contains("rejectAbandonedTasks(abandonedTasks);"));
String rejection = method(scheduler, "private static void rejectAbandonedTasks(");
assertTrue(rejection.contains("rejectionAwareTask.reject();"));
}
@Test
public void blockingPregenShutdownDefersItsFinalSaveToTheServerThread() throws IOException {
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
String shutdown = method(jobSource, "private static boolean shutdownAndSave(");
assertTrue(shutdown.contains("deferFinalSaveToServerThread()"));
assertTrue(shutdown.contains("completeDeferredFinalSave()"));
assertTrue(shutdown.contains("cancelDeferredFinalSave()"));
String methodSource = source("art/arcane/iris/modded/command/ModdedPregenMethod.java");
String close = method(methodSource, "public void close()");
assertTrue(close.contains("deferFinalSaveIfRequested()"));
String await = method(methodSource, "private void awaitFinalSave(");
assertTrue(await.contains("FINAL_SAVE_POLL_MILLIS"));
assertTrue(await.contains("deferFinalSaveIfRequested()"));
String complete = method(methodSource, "void completeDeferredFinalSave()");
int cancel = complete.indexOf("cancelQueuedFinalSave();");
int directSave = complete.indexOf("saveLevelOnServerThread();");
assertTrue(cancel >= 0);
assertTrue(directSave > cancel);
String queuedSave = method(methodSource, "private void executeFinalSave(");
assertTrue(queuedSave.contains("if (!request.claim())"));
String cancelRequest = method(methodSource, "private void cancelQueuedFinalSave()");
assertTrue(cancelRequest.contains("request.cancel();"));
String pending = method(methodSource, "boolean hasPendingFinalSave()");
assertTrue(pending.contains("queuedFinalSave.get() != null"));
}
@Test
public void firstPregenChunkFailureRetainsItsFullCause() throws IOException {
String methodSource = source("art/arcane/iris/modded/command/ModdedPregenMethod.java");
String logFailure = method(methodSource, "private void logChunkFailure(");
assertTrue(methodSource.contains("AtomicBoolean failureDetailLogged"));
assertTrue(logFailure.contains("unwrap(failure)"));
assertTrue(logFailure.contains("failureDetailLogged.compareAndSet(false, true)"));
assertTrue(logFailure.contains("x, z, cause);"));
assertTrue(logFailure.contains("cause.toString()"));
}
@Test
public void pregenReportsOnlyCleanupCallbacksFromCoveredTargets() throws IOException {
String source = source("art/arcane/iris/modded/command/ModdedPregenMethod.java");
String cleanup = method(source, "private void cleanupMantleChunksCoveredBy(");
assertTrue(source.contains("cleanupMantleChunksCoveredBy(x, z, listener);"));
assertFalse(source.contains("cleanupMantleChunk(x, z);"));
assertTrue(cleanup.contains("cleanupChunksCoveredBy(x, z, true, listener::onChunkCleaned)"));
assertFalse(cleanup.contains("forceCleanupChunk"));
}
@Test
public void invalidPregenBoundsFailBeforeRuntimeMutation() throws IOException {
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
String start = method(jobSource, "public static boolean start(");
int taskConstruction = start.indexOf("PregenTask task = PregenTask.builder()");
int profileMutation = start.indexOf("PregenPerformanceProfile.apply(engine)");
assertTrue(taskConstruction >= 0);
assertTrue(profileMutation > taskConstruction);
String commandSource = source("art/arcane/iris/modded/command/ModdedPregenCommands.java");
String command = method(commandSource, "static int pregenStart(");
assertTrue(command.contains("catch (IllegalArgumentException failure)"));
assertTrue(command.contains("IrisModdedCommands.fail(source, failure.getMessage())"));
}
private static String source(String relativePath) throws IOException {
String root = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY, root != null && !root.isBlank());
return Files.readString(Path.of(root, relativePath));
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue("Missing source contract signature: " + signature, start >= 0);
int openBrace = source.indexOf('{', start);
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
int depth = 0;
for (int index = openBrace; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}
@@ -2,32 +2,9 @@ package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* The level router is a switch statement, which the compiler does not check for exhaustiveness. A level added
* to {@link art.arcane.iris.spi.LogLevel} with no arm here would compile and then drop every message at that
* level without a trace, so the fallback arm is what keeps a new level visible on the modded loaders.
*/
public class ModdedIrisLogLevelCoverageTest {
@Test
public void everyLogLevelReachesTheLoggerIncludingOnesAddedLater() throws IOException {
String source = Files.readString(Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedIrisLog.java"));
int router = source.indexOf("public static void log(LogLevel level, String message)");
assertTrue("log(LogLevel, String) not found", router >= 0);
String body = source.substring(router, source.indexOf("public static void debug(", router));
assertTrue(body, body.contains("default -> info(message);"));
}
@Test
public void slf4jStyleArgumentsAndTrailingThrowableArePreserved() {
RuntimeException failure = new RuntimeException("broken");
@@ -37,39 +14,4 @@ public class ModdedIrisLogLevelCoverageTest {
assertEquals("chunk 4,9 failed", rendered.message());
assertEquals(failure, rendered.error());
}
@Test
public void formattedDebugThrowableUsesTheVisibleDebugRouteWhenEnabled() throws IOException {
String source = Files.readString(Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedIrisLog.java"));
int start = source.indexOf("public static void debug(String format, Object... arguments)");
int end = source.indexOf("public static void info(String message)", start);
assertTrue("formatted debug overload not found", start >= 0);
assertTrue("formatted debug overload boundary not found", end > start);
String body = source.substring(start, end);
assertTrue(body, body.contains("if (!debugEnabled())"));
assertTrue(body, body.contains("LOGGER.info(\"[Iris/DEBUG] \" + clean(rendered.message()), rendered.error())"));
}
@Test
public void moddedProductionUsesTheIrisLogFrontDoor() throws IOException {
Path root = Path.of(System.getProperty("iris.moddedCommonSources"));
try (Stream<Path> files = Files.walk(root)) {
List<Path> bypasses = files
.filter(path -> path.toString().endsWith(".java"))
.filter(path -> !path.getFileName().toString().equals("ModdedIrisLog.java"))
.filter(path -> {
try {
String source = Files.readString(path);
return source.contains("LoggerFactory.getLogger")
|| source.contains("private static final Logger LOGGER");
} catch (IOException unreadable) {
throw new IllegalStateException(unreadable);
}
})
.toList();
assertTrue(bypasses.toString(), bypasses.isEmpty());
}
}
}
@@ -2,10 +2,6 @@ package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@@ -48,25 +44,6 @@ public class ModdedLevelDataAttachmentTest {
assertNull(failure.getCause());
}
@Test
public void initializesLevelDataBeforeBindingAndPublication() throws IOException {
String source = Files.readString(sourcePath("ModdedDimensionManager.java"));
int construction = source.indexOf("ServerLevel level = new ServerLevel(");
int initialization = source.indexOf("serverAccess.initializeLevelData(server, level);", construction);
int binding = source.indexOf("generator.bindLevel(level);", initialization);
int publication = source.indexOf("serverAccess.putLevelIfAbsent(server, key, level);", binding);
assertTrue(construction >= 0);
assertTrue(initialization > construction);
assertTrue(binding > initialization);
assertTrue(publication > binding);
}
private static Path sourcePath(String fileName) {
return Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded", fileName);
}
public static final class AttachedLevelData {
private RootData rootData;
private DimensionKey dimensionKey;
@@ -1,436 +0,0 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedLifecycleFailureContractTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void existingDimensionStagesWithoutReplacingTheLiveEngine() throws IOException {
String managerSource = source("ModdedDimensionManager.java");
String create = method(managerSource, "private static Handle create(");
int existingStart = requiredIndex(create, "if (existing != null");
int presentStart = requiredIndex(create, "if (serverAccess.hasLevel(server, key))", existingStart + 1);
int injectionStart = requiredIndex(create, "try {", presentStart);
assertFalse(create.substring(existingStart, presentStart).contains("repointAndBind("));
assertFalse(create.substring(presentStart, injectionStart).contains("repointAndBind("));
assertBefore(create, "ModdedGenerationHistoryStorage.createOrStage(", "if (existing != null");
String generatorSource = source("IrisModdedChunkGenerator.java");
String repointAndBind = method(generatorSource, "void repointAndBind(");
assertBefore(repointAndBind, "ModdedWorldEngines.prepareReplacement(",
"ModdedWorldEngines.installReplacement(");
assertBefore(repointAndBind, "ModdedWorldEngines.installReplacement(", "this.activePack = pack;");
String failure = catchBlock(repointAndBind);
assertTrue(failure.contains("ModdedWorldEngines.closeUnregistered(replacement);"));
assertTrue(failure.contains("addSuppressed("));
String worldEnginesSource = source("ModdedWorldEngines.java");
String installReplacement = method(worldEnginesSource, "static void installReplacement(");
assertTrue(installReplacement.contains("ENGINES.compute("));
assertBefore(installReplacement, "close(current);", "return activeReplacement;");
assertFalse(installReplacement.contains("catch ("));
}
@Test
public void persistentPackUpdatesUseAnExplicitRestartBoundPath() throws IOException {
String managerSource = source("ModdedDimensionManager.java");
String createPersistent = method(managerSource, "public static Handle createPersistent(");
String update = method(managerSource, "public static UpdateResult stagePersistentUpdate(");
assertBefore(createPersistent, "if (previous != null)", "ModdedDimensionRegistryStore.put(");
assertTrue(createPersistent.contains("Use the Iris world update command"));
assertTrue(update.contains("ModdedGenerationHistoryStorage.createOrStage("));
assertTrue(update.contains("active.history().pendingActivation()"));
assertTrue(update.contains("restartRequired()"));
assertFalse(update.contains("inject("));
assertFalse(update.contains("repointAndBind("));
assertBefore(update, "ModdedDimensionRegistryStore.put(server, updated);",
"ModdedGenerationHistoryStorage.createOrStage(");
assertTrue(update.contains("ModdedDimensionRegistryStore.put(server, previous);"));
String commandsSource = source("command/ModdedWorldCommands.java");
assertTrue(commandsSource.contains("root.then(updateTree());"));
String command = method(commandsSource, "private static int update(");
assertTrue(command.contains("ModdedDimensionManager.stagePersistentUpdate("));
assertTrue(command.contains("Restart the server to activate it"));
assertTrue(command.contains("running world remains on its current pack"));
}
@Test
public void injectionBindsBeforeRegistrationAndRollsBackEveryFailure() throws IOException {
String source = source("ModdedDimensionManager.java");
String injection = method(source, "private static Handle inject(");
assertBefore(injection, "generator.bindLevel(level);", "serverAccess.putLevelIfAbsent(server, key, level);");
assertBefore(injection, "serverAccess.putLevelIfAbsent(server, key, level);",
"server.getPlayerList().addWorldborderListener(level);");
assertFalse(injection.contains("serverAccess.putLevel(server, key, previous);"));
String failure = catchBlock(injection);
assertBefore(failure, "rollbackInjection(", "throw ");
String rollback = method(source, "void rollbackInjection(");
assertBefore(rollback, "serverAccess.hasLevel(server, key)", "serverAccess.removeLevel(server, key);");
assertTrue(rollback.contains("generator.unbindEngine("));
assertTrue(rollback.contains("level.close();"));
assertTrue(rollback.contains("addSuppressed("));
}
@Test
public void persistentReinjectionQuarantinesBrokenEntriesAndContinues() throws IOException {
String source = source("ModdedStartup.java");
String reinjection = method(source, "private static void reinjectPersistentDimensions(");
String failure = catchBlock(reinjection);
assertTrue(failure.contains("ModdedIrisLog.error("));
assertFalse(failure.contains("e.toString()"));
assertFalse(failure.contains("throw new IllegalStateException("));
assertTrue(reinjection.contains("injected++;"));
}
@Test
public void persistentReinjectionWaitsForPlayerServicesAndServerStarted() throws IOException {
String bootstrapSource = source("ModdedEngineBootstrap.java");
String start = method(bootstrapSource, "public static void start(");
String serverAboutToStart = method(bootstrapSource, "public static void serverAboutToStart(");
String serverStarted = method(bootstrapSource, "public static void serverStarted(");
assertFalse(start.contains("ModdedStartup.runOnce(server);"));
assertFalse(serverAboutToStart.contains("ModdedStartup.runOnce(server);"));
assertEquals(1, occurrences(serverStarted, "ModdedStartup.runOnce(server);"));
assertBefore(serverStarted, "bindWorldGenerators(server);", "ModdedStartup.runOnce(server);");
assertBefore(serverStarted, "ModdedStartup.runOnce(server);", "reconcileSpawn(server);");
String startupSource = source("ModdedStartup.java");
String runOnce = method(startupSource, "public static void runOnce(");
assertBefore(runOnce, "server.getPlayerList() == null", "STARTED.compareAndSet(false, true)");
}
@Test
public void dynamicLevelMutationsInvalidateLoaderTickCaches() throws IOException {
String levelsSource = source("ModdedServerLevels.java");
String put = method(levelsSource, "public ServerLevel putLevel(");
String putIfAbsent = method(levelsSource, "public ServerLevel putLevelIfAbsent(");
String remove = method(levelsSource, "public ServerLevel removeLevel(");
assertBefore(put, "server.levels.put(key, level);", "levelCacheInvalidator.accept(server);");
assertTrue(put.contains("if (previous != level)"));
assertBefore(putIfAbsent, "server.levels.putIfAbsent(key, level);", "levelCacheInvalidator.accept(server);");
assertTrue(putIfAbsent.contains("if (previous == null)"));
assertBefore(remove, "server.levels.remove(key);", "levelCacheInvalidator.accept(server);");
assertTrue(remove.contains("if (removed != null)"));
String loaderSource = source("ModdedLoader.java");
assertTrue(loaderSource.contains("void invalidateLevelCache(MinecraftServer server);"));
String bootstrapSource = source("ModdedEngineBootstrap.java");
assertTrue(bootstrapSource.contains("new ModdedServerLevels(boundLoader::invalidateLevelCache)"));
}
@Test
public void persistentRestoreOpensHistoryBeforeConsultingTheGlobalPack() throws IOException {
String source = source("ModdedGenerationHistoryStorage.java");
String restore = method(source, "static GenerationHistory restoreOrAdopt(");
assertBefore(restore, "GenerationHistory.openIfPresent(", "sourceSupplier\").get();");
assertTrue(restore.contains("if (existing.isPresent())"));
assertBefore(restore, "requireRegistryDefinitions(existing.get()", "return existing.get();");
}
@Test
public void productionPackResolutionNeverUsesTheParityProbeAsData() throws IOException {
String source = source("ModdedWorldEngines.java");
String resolvePack = method(source, "static File resolvePack(");
assertFalse(source.contains("System.getProperty(\"iris.parity\")"));
assertFalse(source.contains("parityPack"));
assertFalse(source.contains("falling back to parity pack"));
assertTrue(resolvePack.contains("throw new IllegalStateException("));
}
@Test
public void engineBootstrapResetsStartupExactlyOnceDuringStop() throws IOException {
String source = source("ModdedEngineBootstrap.java");
String stop = method(source, "public static void stop(");
assertEquals(1, occurrences(stop, "ModdedStartup::reset"));
}
@Test
public void engineBootstrapAttemptsEveryShutdownStageAndAggregatesFailures() throws IOException {
String source = source("ModdedEngineBootstrap.java");
String stop = method(source, "public static void stop(");
assertBefore(stop, "\"services\"", "\"world engines\"");
assertBefore(stop, "\"world engines\"", "\"dimension manager\"");
assertBefore(stop, "\"server state\"", "if (failure != null)");
assertFalse(stop.contains("throw"));
assertTrue(stop.contains("ModdedIrisLog.error(\"Iris modded shutdown completed with failures\", failure);"));
String runStage = method(source, "private static Throwable runStopStage(");
assertTrue(runStage.contains("catch (Throwable stageFailure)"));
assertTrue(runStage.contains("failure.addSuppressed(stageFailure);"));
}
@Test
public void worldShutdownRemovesOnlySuccessfullyClosedMappings() throws IOException {
String source = source("ModdedWorldEngines.java");
String shutdown = method(source, "public static void shutdown()");
assertTrue(shutdown.contains("new ArrayList<>(ENGINES.entrySet())"));
assertFalse(shutdown.contains("ENGINES.clear()"));
// Bound generators must go through unbindEngine (latch unloading, then strict evict) so a
// late chunk-system drain cannot rebuild an engine nothing closes again.
assertTrue(shutdown.contains("generator.unbindEngine(level);"));
assertBefore(shutdown, "close(engine);", "ENGINES.remove(level, engine)");
assertTrue(shutdown.contains("ENGINES.containsKey(level)"));
assertTrue(shutdown.contains("failure.addSuppressed(e);"));
assertTrue(shutdown.contains("failed mappings were retained"));
}
@Test
public void engineEvictionRetainsTheMappingUntilCloseSucceeds() throws IOException {
String source = source("ModdedWorldEngines.java");
String eviction = method(source, "static void evictOrThrow(");
assertTrue(eviction.contains("ENGINES.computeIfPresent("));
assertFalse(eviction.contains("ENGINES.remove("));
assertBefore(eviction, "close(current);", "return null;");
}
@Test
public void generatorUnbindRetainsOwnershipWhenEvictionFails() throws IOException {
String source = source("IrisModdedChunkGenerator.java");
String unbind = method(source, "synchronized void unbindEngine(ServerLevel level)");
assertFalse(unbind.contains("finally"));
assertBefore(unbind, "unloading = true;", "ModdedWorldEngines.evictOrThrow(level);");
assertBefore(unbind, "ModdedWorldEngines.evictOrThrow(level);", "clearEngineBinding();");
String binding = method(source, "private Engine bindEngine(ServerLevel level)");
assertTrue(binding.contains("requireBindingAllowed();"));
assertTrue(binding.contains("requireCompletedShutdown(cached);"));
String bindLevel = method(source, "synchronized void bindLevel(ServerLevel level)");
assertBefore(bindLevel, "requireCompletedShutdown(engine);", "unloading = false;");
String boundEngine = method(source, "public Engine engineIfBound()");
assertTrue(boundEngine.contains("unloading || current == null || current.isClosing() || current.isClosed()"));
}
@Test
public void loaderUnloadSurfacesCloseFailureAndDynamicRemovalUsesStrictEviction() throws IOException {
String bootstrapSource = source("ModdedEngineBootstrap.java");
String unload = method(bootstrapSource, "public static void levelUnloaded(ServerLevel level)");
String failure = catchBlock(unload);
assertTrue(failure.contains("ModdedIrisLog.error("));
assertTrue(failure.contains("throw "));
String managerSource = source("ModdedDimensionManager.java");
String remove = method(managerSource, "public static boolean remove(MinecraftServer server, String dimensionId, boolean wipeStorage)");
assertTrue(remove.contains("ModdedWorldEngines.evictOrThrow(level);"));
assertFalse(remove.contains("ModdedWorldEngines.evict(level);"));
assertTrue(remove.contains("unloadEventStarted = true;"));
assertTrue(remove.contains("rollbackRemoval(server, serverAccess, key, level, generator, unloadEventStarted, e);"));
String rollback = method(managerSource, "private static void rollbackRemoval(");
assertTrue(rollback.contains("serverAccess.hasLevel(server, key)"));
assertTrue(rollback.contains("generator.bindLevel(level);"));
assertTrue(rollback.contains("failure.addSuppressed(rollbackFailure);"));
assertTrue(rollback.contains("ModdedIrisLog.error("));
}
@Test
public void engineBootstrapRollsBackEveryPublishedBindingBeforeRethrowing() throws IOException {
String source = source("ModdedEngineBootstrap.java");
String bind = method(source, "public static ModdedPlatform bind(");
String failure = catchBlock(bind);
assertBefore(bind, "createdServices.enableAll();", "runtime = new BoundRuntime(");
assertTrue(bind.contains("rollback.add(() -> GuiHost.suppressDesktop("));
assertTrue(bind.contains("rollback.add(() -> restorePlatform("));
assertTrue(bind.contains("rollback.add(() -> ModdedDimensionManager.restoreAccess("));
assertTrue(bind.contains("rollback.add(() -> IrisObjectRotation.restorePlatformRotator("));
assertTrue(bind.contains("rollback.add(() -> BlockDataMergeSupport.restorePlatformMerger("));
assertTrue(bind.contains("rollback.add(() -> TileData.restorePlatformReader("));
assertTrue(bind.contains("rollback.add(() -> TileData.restorePlatformFactory("));
assertTrue(bind.contains("rollback.add(() -> GuiHost.set("));
assertTrue(bind.contains("rollback.add(() -> DecoratorPlatformHooks.restore("));
assertTrue(bind.contains("bindService(PreservationRegistry.class"));
assertTrue(bind.contains("bindService(EngineEffectsProvider.class"));
assertTrue(bind.contains("bindService(EnginePlatformHooks.class"));
assertTrue(bind.contains("bindService(EngineWorldManagerProvider.class"));
assertTrue(bind.contains("rollback.add(customContentDiscovery::rollback);"));
assertBefore(failure, "createdServices.rollback(failure);", "rollback.restore(failure);");
assertBefore(failure, "rollback.restore(failure);", "throw ");
}
private static void assertBefore(String source, String first, String second) {
int firstIndex = requiredIndex(source, first);
int secondIndex = requiredIndex(source, second);
assertTrue(first + " must occur before " + second, firstIndex < secondIndex);
}
private static int requiredIndex(String source, String needle) {
return requiredIndex(source, needle, 0);
}
private static int requiredIndex(String source, String needle, int start) {
int index = source.indexOf(needle, start);
assertTrue("Missing source contract token: " + needle, index >= 0);
return index;
}
private static String source(String fileName) throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY,
sourceRoot != null && !sourceRoot.isBlank());
Path sourcePath = Path.of(sourceRoot, "art", "arcane", "iris", "modded", fileName);
return Files.readString(sourcePath);
}
private static String method(String source, String signature) {
int start = requiredIndex(source, signature);
int openBrace = openingBrace(source, start);
return source.substring(start, matchingBrace(source, openBrace) + 1);
}
/**
* Returns the block of the shallowest catch in the method, i.e. the one attached to the
* method's outermost try. Textual first-match would return a nested catch instead, and a
* nested catch handles a different failure than the one these contracts pin.
*/
private static String catchBlock(String source) {
int bodyStart = openingBrace(source, 0);
int depth = 0;
int bestDepth = Integer.MAX_VALUE;
int catchIndex = -1;
int i = bodyStart;
while (i < source.length()) {
int skipped = skipNonCode(source, i);
if (skipped > i) {
i = skipped;
continue;
}
char current = source.charAt(i);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
break;
}
} else if (current == 'c' && depth < bestDepth && source.startsWith("catch (", i)) {
bestDepth = depth;
catchIndex = i;
}
i++;
}
assertTrue("Missing source contract token: catch (", catchIndex >= 0);
return blockAt(source, openingBrace(source, catchIndex));
}
private static String blockAt(String source, int openBrace) {
return source.substring(openBrace, matchingBrace(source, openBrace) + 1);
}
private static int openingBrace(String source, int start) {
int i = start;
while (i < source.length()) {
int skipped = skipNonCode(source, i);
if (skipped > i) {
i = skipped;
continue;
}
if (source.charAt(i) == '{') {
return i;
}
i++;
}
throw new IllegalArgumentException("No source block after offset " + start);
}
private static int matchingBrace(String source, int openBrace) {
int depth = 0;
int i = openBrace;
while (i < source.length()) {
int skipped = skipNonCode(source, i);
if (skipped > i) {
i = skipped;
continue;
}
char current = source.charAt(i);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
return i;
}
}
i++;
}
throw new IllegalArgumentException("Unclosed source block");
}
/**
* Advances past a comment, string, char or text block starting at the index, otherwise returns
* the index unchanged. Comments must be skipped: an apostrophe in prose ("generator's") would
* otherwise open a char literal and swallow the rest of the file.
*/
private static int skipNonCode(String source, int index) {
char current = source.charAt(index);
if (current == '/' && index + 1 < source.length()) {
char next = source.charAt(index + 1);
if (next == '/') {
int end = source.indexOf('\n', index);
return end < 0 ? source.length() : end + 1;
}
if (next == '*') {
int end = source.indexOf("*/", index + 2);
return end < 0 ? source.length() : end + 2;
}
return index;
}
if (current == '"' && source.startsWith("\"\"\"", index)) {
int end = source.indexOf("\"\"\"", index + 3);
return end < 0 ? source.length() : end + 3;
}
if (current == '"' || current == '\'') {
return endOfLiteral(source, index, current);
}
return index;
}
private static int endOfLiteral(String source, int index, char terminator) {
for (int i = index + 1; i < source.length(); i++) {
char current = source.charAt(i);
if (current == '\\') {
i++;
continue;
}
if (current == terminator) {
return i + 1;
}
}
return source.length();
}
private static int occurrences(String source, String needle) {
int count = 0;
int offset = 0;
while (true) {
int index = source.indexOf(needle, offset);
if (index < 0) {
return count;
}
count++;
offset = index + needle.length();
}
}
}
@@ -5,13 +5,9 @@ import art.arcane.iris.engine.object.IrisEntitySpawn;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedSpawnerRarityParityTest {
private static IrisEntitySpawn spawn(int rarity) {
@@ -39,37 +35,4 @@ public class ModdedSpawnerRarityParityTest {
assertEquals(1, IRare.get(spawn(-5)));
assertEquals(3, IRare.get(spawn(3)));
}
@Test
public void perPositionSpawnLoopsDoNotRerollEntryRarity() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedWorldManager.java"));
for (String method : List.of("private int spawnEntry(", "private int spawnEntryAt(")) {
String body = methodBody(source, method);
assertFalse(method + " must not re-roll rarity per position; rarityPick already weighted the pool",
body.contains("getRarity()"));
assertTrue(method + " must keep the min/max spawn-count roll",
body.contains("LootResolver.inclusive("));
}
}
private static String methodBody(String source, String declaration) {
int start = source.indexOf(declaration);
assertTrue("ModdedWorldManager must declare " + declaration, start >= 0);
int open = source.indexOf('{', start);
int depth = 0;
for (int index = open; index < source.length(); index++) {
char character = source.charAt(index);
if (character == '{') {
depth++;
} else if (character == '}') {
depth--;
if (depth == 0) {
return source.substring(open + 1, index);
}
}
}
throw new AssertionError(declaration + " is not brace balanced");
}
}
@@ -1,30 +0,0 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedStructurePlacementFailureContractTest {
@Test
public void structurePlacementPropagatesRuntimeFailuresWithContext() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedStructureHooks.java");
String source = Files.readString(sourcePath);
int methodStart = source.indexOf("public int[] placeStructure(");
int methodEnd = source.indexOf("\n @Override", methodStart + 1);
String method = source.substring(methodStart, methodEnd);
int catchStart = method.indexOf("catch (RuntimeException error)");
assertTrue(catchStart >= 0);
String failurePath = method.substring(catchStart);
assertTrue(failurePath.contains("throw NativeStructureGenerationException.failure("));
assertTrue(failurePath.contains("\"capture placement\", structureKey, chunkX, chunkZ, error"));
assertFalse(failurePath.contains("return null;"));
assertFalse(failurePath.contains("catch (Throwable"));
}
}
@@ -4,8 +4,6 @@ import org.junit.Test;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -64,14 +62,9 @@ public class ModdedStructureTemplateCacheTest {
config = new String(input.readAllBytes(), StandardCharsets.UTF_8);
}
assertTrue(config.contains("\"StructureTemplatePaletteConcurrencyMixin\""));
Path source = Path.of(System.getProperty("iris.moddedCommonSources"))
.resolve("art/arcane/iris/modded/mixin/StructureTemplatePaletteConcurrencyMixin.java");
String mixin = Files.readString(source);
assertTrue(mixin.contains("@Mixin(StructureTemplate.Palette.class)"));
assertTrue(mixin.contains("@Shadow\n @Final\n @Mutable"));
assertTrue(mixin.contains("private Map<Block, List<StructureTemplate.StructureBlockInfo>> cache;"));
assertTrue(mixin.contains("@Inject(method = \"<init>(Ljava/util/List;)V\", at = @At(\"RETURN\"))"));
assertTrue(mixin.contains("cache = new ConcurrentHashMap<>();"));
assertNotNull(Class.forName(
"art.arcane.iris.modded.mixin.StructureTemplatePaletteConcurrencyMixin",
false,
ModdedStructureTemplateCacheTest.class.getClassLoader()));
}
}
@@ -5,9 +5,6 @@ import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -26,32 +23,6 @@ public class ModdedWorldCheckTest {
assertTrue(thread.isDaemon());
}
@Test
public void poiAuditRunsInASecondServerTaskAfterVillageGeneration() throws IOException {
Path sourceRoot = Path.of(System.getProperty("iris.moddedCommonSources"));
String source = Files.readString(sourceRoot.resolve("art/arcane/iris/modded/ModdedWorldCheck.java"));
String auditSource = Files.readString(
sourceRoot.resolve("art/arcane/iris/modded/WorldCheckStructureAudit.java"));
int preparationSubmit = source.indexOf(
"WorldCheckPreparation preparation = serverRef.submit(() -> run(serverRef))");
int completionSubmit = source.indexOf(
"exitCode = serverRef.submit(() -> runAndRequestStop(", preparationSubmit);
int completionMethod = source.indexOf("private static boolean completeWorldCheck");
int deferredAudit = source.indexOf(
"PoiAudit poi = WorldCheckStructureAudit.auditStructurePois", completionMethod);
int structureMethod = auditSource.indexOf("private static StructureCheckResult checkNativeStructure");
int structureMethodEnd = auditSource.indexOf("private static StructureStart resolveStructureStart",
structureMethod);
String structureSource = auditSource.substring(structureMethod, structureMethodEnd);
assertTrue(preparationSubmit >= 0);
assertTrue(completionSubmit > preparationSubmit);
assertTrue(deferredAudit > completionMethod);
assertFalse(structureSource.contains("auditStructurePois"));
assertFalse(source.contains("prepareDeferredAudits"));
assertFalse(auditSource.contains("prepareDeferredAudits"));
}
@Test
public void validStructureStartIsGenerationEvidence() {
assertTrue(WorldCheckPredicates.hasNativeStructureEvidence(true, 0));
@@ -6,11 +6,6 @@ import net.minecraft.server.Bootstrap;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@@ -22,25 +17,6 @@ public class NativeStructureFailureContractTest {
Bootstrap.bootStrap();
}
@Test
public void structureLocateDoesNotCatchAndFallThroughToAnotherImplementation() throws IOException {
String source = moddedSource("IrisModdedChunkGenerator.java");
int locateStart = source.indexOf("public Pair<BlockPos, Holder<Structure>> findNearestMapStructure");
int locateEnd = source.indexOf("public boolean isNativeStructureReachable", locateStart);
String locate = source.substring(locateStart, locateEnd);
String stage = moddedSource("ModdedNativeStructureStage.java");
int filterStart = stage.indexOf("HolderSet<Structure> filterReachableNativeStructures");
int filterEnd = stage.indexOf("void adjustGeneratedStructures", filterStart);
String filter = stage.substring(filterStart, filterEnd);
assertTrue(locate.contains("Engine current = engine();"));
assertFalse(locate.contains("catch (Throwable"));
assertFalse(locate.contains("return null;\n } catch"));
assertTrue(filter.contains("unregistered structure holder"));
assertFalse(filter.contains("catch (Throwable"));
assertFalse(filter.contains("failed closed"));
}
@Test
public void globalStructureDisableRefusesGeneratorBinding() {
IrisModdedChunkGenerator.requireGlobalStructureGeneration(true, "overworld:overworld");
@@ -56,66 +32,6 @@ public class NativeStructureFailureContractTest {
assertTrue(error.getMessage().contains("importedStructures.disabledExact"));
}
@Test
public void structureVegetationCleanupPrecedesTerrainPreparationAndPlacement() throws IOException {
String source = moddedSource("ModdedNativeStructureStage.java");
int placementStart = source.indexOf("void placeVanillaStructures");
int placementEnd = source.indexOf("private static String nativeStructureBatchContext", placementStart);
String placement = source.substring(placementStart, placementEnd);
assertTrue(placement.contains("\"terrain integration\""));
assertTrue(placement.contains("\"terrain preparation\""));
assertTrue(placement.contains("\"foundation repair\""));
assertFalse(placement.contains("\"terrain carving\""));
assertTrue(placement.contains("visitExistingPois(chunk"));
assertTrue(placement.contains("level.updatePOIOnBlockStateChange("));
assertTrue(placement.contains("Blocks.AIR.defaultBlockState(), state"));
assertTrue(placement.indexOf("visitExistingPois(chunk")
< placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement("));
assertTrue(placement.contains("prepareSurfaceStructures"));
assertTrue(placement.contains("clearIntersectingVegetation"));
assertTrue(placement.indexOf("clearIntersectingVegetation")
< placement.indexOf("prepareSurfaceStructures"));
assertTrue(placement.indexOf("prepareSurfaceStructures")
< placement.indexOf("for (NativePlacementGroup group"));
assertTrue(placement.indexOf("repairVacuumFoundations")
> placement.indexOf("for (NativePlacementGroup group"));
}
@Test
public void structurePlacementPrimesNeighbourWorldgenHeightmapsBeforeTerrainPreparation() throws IOException {
String source = moddedSource("ModdedNativeStructureStage.java");
int placementStart = source.indexOf("void placeVanillaStructures");
int placementEnd = source.indexOf("private static String nativeStructureBatchContext", placementStart);
String placement = source.substring(placementStart, placementEnd);
assertTrue(source.contains("import art.arcane.iris.nativegen.WorldgenTerrainHeightmaps;"));
assertTrue(placement.contains("WorldgenTerrainHeightmaps.primeStructurePlacement("));
assertTrue(placement.contains("\"heightmap priming\""));
assertTrue(placement.contains("heightmapStarts.add(start);"));
assertTrue(placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement(")
< placement.indexOf("prepareSurfaceStructures"));
assertTrue(source.contains("Engine.hostHeight(generationEngine, x, z, false) + runtimeMinY + 1"));
assertTrue(source.contains("Engine.hostHeight(generationEngine, x, z, true) + runtimeMinY + 1"));
assertTrue(placement.contains("current.getDimensionStackContext() != null"));
assertTrue(source.contains("int minY = chunk.getMinY() + 1;"));
}
@Test
public void nativeStructurePostProcessingUsesBoundedWorldgenAccess() throws IOException {
String source = moddedSource("ModdedNativeStructureStage.java");
int placementStart = source.indexOf("void placeVanillaStructures");
int placementEnd = source.indexOf("private List<List<Structure>> structuresByStep", placementStart);
String placement = source.substring(placementStart, placementEnd);
assertTrue(placement.contains("ModdedNativeStructureWorldgenAccess.create("));
assertTrue(placement.contains("nativeStructureProtection(current, staticObjects)"));
assertTrue(placement.contains("Engine.hostHeight(current, x, z, true)"));
assertTrue(placement.contains("placeVanillaStructure(boundedWorld, structureManager"));
assertFalse(placement.contains("NativeStructurePostProcessor.place(world,"));
assertTrue(placement.contains("world.setCurrentlyGenerating(null);"));
}
@Test
public void structureFailurePreservesPhaseIdentityChunkAndCause() {
IllegalArgumentException cause = new IllegalArgumentException("broken placement");
@@ -128,10 +44,4 @@ public class NativeStructureFailureContractTest {
assertTrue(error.getMessage().contains("12,-8"));
assertTrue(error.getMessage().contains("aborted"));
}
private static String moddedSource(String fileName) throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art", "arcane", "iris", "modded", fileName);
return Files.readString(sourcePath);
}
}
@@ -7,9 +7,6 @@ import com.mojang.datafixers.util.Pair;
import net.minecraft.core.BlockPos;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -48,30 +45,6 @@ public class IrisModdedStructureCommandTest {
assertEquals(1, nativeReferences.get());
}
@Test
public void gotoStructureSupportsIrisAndNativeRegistryTargets() throws IOException {
String source = source("ModdedLocateCommands.java");
String suggestions = source("ModdedCommandSuggestions.java");
assertTrue(source.contains("IrisStructureLocator.hasLocatableEditablePlacement(engine, key)"));
assertTrue(source.contains("registry.get(identifier)"));
assertTrue(source.contains("getPlacementsForStructure(holder)"));
assertTrue(source.contains("generator.findNearestMapStructure("));
assertTrue(source.contains("NATIVE_STRUCTURE_LOCATE_RADIUS = 100"));
assertTrue(source.contains("HolderSet.direct(target.holder())"));
assertFalse(source.contains("NativeStructureLocateCapability"));
assertTrue(source.contains("boolean teleported = player.teleportTo("));
assertTrue(suggestions.contains("combineStructureKeys(unregisteredIrisKeys, nativeKeys)"));
assertTrue(source.contains("irisGenerator.isNativeStructureReachable(holder)"));
assertTrue(source.contains("LocateStatus.SEARCH_LIMIT_REACHED"));
assertTrue(source.contains("IRIS_MODDED_COMMANDS_UNABLE_LOCATE_IRIS_PLACED_STRUCTURE_DENSITY_SEARCH_SAFETY_LIMIT_WAS"));
assertTrue(source.contains("int targetX = result.originX()"));
assertTrue(source.contains("int targetY = result.baseY() + 2"));
assertTrue(source.contains("int targetZ = result.originZ()"));
assertFalse(source.contains("at[0] + 8"));
assertFalse(source.contains("at[2] + 8"));
}
@Test
public void registeredStructureEligibilityMatchesGotoAndSuggestions() {
IrisNativeStructureDecision nativeDecision = decision(NativeStructureGenerationStatus.GENERATE_NATIVE);
@@ -175,162 +148,6 @@ public class IrisModdedStructureCommandTest {
.contains("non-positive density or a Y band outside"));
}
@Test
public void unregisteredCommandUsesGotoEligibilityAndPrintsToConsole() throws IOException {
String command = source("ModdedUnregisteredStructures.java");
String tree = source("ModdedCommandTree.java");
assertTrue(tree.contains("Commands.literal(\"unregistered\")"));
assertTrue(tree.contains("ModdedUnregisteredStructures.print(context.getSource())"));
assertTrue(command.contains("ModdedCommandSuggestions.isEligibleRegisteredStructure("));
assertTrue(command.contains("ModdedLocateCommands.registeredStructureUnavailableMessage("));
assertTrue(command.contains("engine.getData().getStructureLoader().getPossibleKeys()"));
assertTrue(command.contains("IrisStructureLocator.hasLocatableEditablePlacement(engine, key)"));
assertTrue(command.contains("ModdedIrisLog.info(\"[Iris goto unregistered] [{}] {} - {}\""));
assertTrue(command.contains("UNREGISTERED(\"unregistered\")"));
assertFalse(command.contains("DatapackIngestService"));
}
@Test
public void structureSuggestionsUseActiveLevelAvailability() throws IOException {
String suggestions = source("ModdedCommandSuggestions.java");
int methodStart = suggestions.indexOf("static CompletableFuture<Suggestions> suggestStructureKeys(");
int methodEnd = suggestions.indexOf("static boolean isEligibleRegisteredStructure(", methodStart);
String method = suggestions.substring(methodStart, methodEnd);
assertTrue(method.contains("ServerLevel level = source.getLevel()"));
assertTrue(method.contains("Engine engine = IrisModdedCommands.engineFor(level)"));
assertFalse(method.contains("IrisStructureLocator.locatableKeys(engine)"));
assertTrue(method.contains("IrisStructureLocator.locatableEditableKeys(engine)"));
assertTrue(method.contains("StructureReachability.reachableKeys(engine)"));
assertTrue(method.contains("NativeStructureGenerationPolicy.resolve(engine, key, false)"));
assertTrue(method.contains("IrisStructureLocator.hasLocatableNativePlacement(engine, key)"));
assertTrue(method.contains("IrisStructureLocator.hasLocatableEditablePlacement(engine, key)"));
assertTrue(method.contains("reachableNativeKeys.contains(normalizeKey(key))"));
assertTrue(method.contains("nativeGenerationEnabled"));
assertTrue(method.contains("eligibleUnregisteredEditableKeys("));
assertTrue(method.contains("IrisStructureLocator.hasNativePlacement(engine, candidate)"));
assertFalse(method.contains("NativeStructureGenerationKeys.active(level)"));
assertFalse(method.contains("getPlacementsForStructure"));
}
@Test
public void generatorLocateUsesEveryIrisPlacedNativeStructure() throws IOException {
String source = moddedSource("ModdedNativeStructureStage.java");
int methodStart = source.indexOf("Pair<BlockPos, Holder<Structure>> findNearestIrisStructure(");
int methodEnd = source.indexOf("HolderSet<Structure> filterReachableNativeStructures(", methodStart);
String method = source.substring(methodStart, methodEnd);
int registryLookup = method.indexOf("level.registryAccess().lookupOrThrow(Registries.STRUCTURE)");
int placedCheck = method.indexOf(
"if (!IrisStructureLocator.hasNativePlacement(current, structureId))");
int irisLocate = method.indexOf("NativeStructureLocatePersistence.search(", placedCheck);
int nearestSelection = method.indexOf(
"NativeStructureLocateResults.nearest(pos, predicted, nativeLocated)", irisLocate);
int selectedVerification = method.indexOf("bestSearch.search().verify(bestResult)", nearestSelection);
int selectedReference = method.indexOf(
"selectedSearch.search().reference(selectedStart)", selectedVerification);
assertTrue(registryLookup >= 0);
assertTrue(placedCheck > registryLookup);
assertTrue(irisLocate > placedCheck);
assertTrue(nearestSelection > irisLocate);
assertTrue(selectedVerification > nearestSelection);
assertTrue(selectedReference > selectedVerification);
assertTrue(method.contains("NativeStructureLocatePersistence.probe("));
assertTrue(method.contains("findUnexplored"));
assertTrue(method.contains("LocateStatus.SEARCH_LIMIT_REACHED"));
assertTrue(method.contains("verified.ownership().locatorY()"));
assertTrue(method.contains("selectedSearch.search().reference(selectedStart)"));
assertTrue(method.contains("NativeStructureLocateResults.selectAndReference("));
assertFalse(method.contains("NativeStructureLocateCapability"));
assertTrue(source.contains("structureBiomeSource.isStructureReachable(holder)"));
assertFalse(source.contains("isPaperUnavailable"));
String generator = moddedSource("IrisModdedChunkGenerator.java");
assertTrue(generator.contains("NativeStructureVanillaLocator.predict("));
assertFalse(generator.contains("super.findNearestMapStructure(level, reachable"));
}
@Test
public void commandResolvesNativePolicyBeforeAnyVanillaAliasLookup() throws IOException {
String source = source("ModdedLocateCommands.java");
int methodStart = source.indexOf("static int gotoStructure(");
int methodEnd = source.indexOf("private static void locateIrisStructure(", methodStart);
String method = source.substring(methodStart, methodEnd);
int nativeResolution = method.indexOf("resolveNativeStructure(source, level, engine, key)");
int editableIrisLookup = method.indexOf(
"IrisStructureLocator.hasLocatableEditablePlacement(engine, key)", nativeResolution);
int policyResolution = method.indexOf(
"NativeStructureGenerationPolicy.resolve(engine, target.key(), false)", editableIrisLookup);
int eligibilityCheck = method.indexOf(
"ModdedCommandSuggestions.isEligibleRegisteredStructure(", policyResolution);
int replacementLocate = method.indexOf(
"locateIrisStructure(source, level, engine, player, target.key())", eligibilityCheck);
int nativeLocate = method.indexOf("runNativeStructureLocate(source, level, player, target)",
replacementLocate);
assertTrue(nativeResolution >= 0);
assertTrue(editableIrisLookup > nativeResolution);
assertTrue(policyResolution > editableIrisLookup);
assertTrue(eligibilityCheck > policyResolution);
assertTrue(replacementLocate > eligibilityCheck);
assertTrue(nativeLocate > replacementLocate);
assertTrue(method.contains("IrisStructureLocator.hasLocatableNativePlacement(engine, target.key())"));
assertTrue(method.contains("IrisStructureLocator.hasLocatableEditablePlacement(engine, target.key())"));
assertTrue(method.contains("!IrisStructureLocator.hasNativePlacement(engine, key)"));
assertTrue(method.contains("StructureReachability.isReachable(engine, target.key())"));
assertTrue(method.contains("getWorldGenSettings().options().generateStructures()"));
assertFalse(method.contains("IrisStructureLocator.isPlaced(engine, key)"));
}
@Test
public void verifyResolvesRegisteredNativeBeforeGenericIrisAliases() throws IOException {
String source = source("ModdedLocateCommands.java");
int methodStart = source.indexOf("private static int verifyStructure(");
int methodEnd = source.indexOf("private static Optional<NativeStructureTarget> resolveNativeStructure(",
methodStart);
String method = source.substring(methodStart, methodEnd);
int nativeResolution = method.indexOf("resolveNativeStructure(source, level, engine, key)");
int genericIrisLookup = method.indexOf("IrisStructureLocator.isPlaced(engine, key)", nativeResolution);
assertTrue(nativeResolution >= 0);
assertTrue(genericIrisLookup > nativeResolution);
assertTrue(method.contains("NativeStructureAvailability.IRIS_SUPPRESSED"));
}
@Test
public void structureVerificationNoLongerClaimsNativeGenerationIsMissing() throws IOException {
String source = source("ModdedStructureCommands.java");
assertTrue(source.contains("verifyTree(\"verify\")"));
assertTrue(source.contains("verifyTree(\"locateall\")"));
assertTrue(source.contains("IrisModdedCommands.verifyStructures("));
assertFalse(source.contains("Vanilla structure locate is meaningless here"));
}
private String source(String fileName) throws IOException {
Path source = commonSourceRoot().resolve("art/arcane/iris/modded/command/")
.resolve(fileName)
.normalize();
return Files.readString(source);
}
private String moddedSource(String fileName) throws IOException {
Path source = commonSourceRoot().resolve("art/arcane/iris/modded/")
.resolve(fileName)
.normalize();
return Files.readString(source);
}
private Path commonSourceRoot() {
String configuredRoot = System.getProperty("iris.moddedCommonSources");
if (configuredRoot != null && !configuredRoot.isBlank()) {
return Path.of(configuredRoot);
}
return Path.of(System.getProperty("user.dir"))
.resolve("../modded-common/src/main/java")
.normalize();
}
private IrisNativeStructureDecision decision(NativeStructureGenerationStatus status) {
return new IrisNativeStructureDecision(status, 0, null, false, null, null);
}
@@ -1,28 +0,0 @@
package art.arcane.iris.modded.command;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class ModdedRiverLocateContractTest {
@Test
public void riverLookupMergesRecordedAndEligibleActiveFeatures() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"))
.resolve("art/arcane/iris/modded/command/ModdedLocateCommands.java");
String source = Files.readString(sourcePath);
int methodStart = source.indexOf("static int gotoRiver(");
int methodEnd = source.indexOf("static int gotoStructure(", methodStart);
String method = source.substring(methodStart, methodEnd);
assertTrue(method.contains("GenerationSemanticQueries.nearestRiver("));
assertTrue(method.contains("runtime == null"));
assertTrue(method.contains("feature.y() + 2"));
assertFalse(method.contains("runtime.nearestFeature("));
assertFalse(method.contains("feature.y() + engine.getDimension().getMinHeight()"));
}
}
@@ -1,34 +0,0 @@
package art.arcane.iris.modded.command;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class ModdedStructureHistoryContractTest {
@Test
public void retainedStructureNamesReachTheSemanticSearchOnBothAdmissionBranches() throws IOException {
Path root = Path.of(System.getProperty("iris.moddedCommonSources"));
String source = Files.readString(root.resolve("art/arcane/iris/modded/command/ModdedLocateCommands.java"));
int start = source.indexOf("static int gotoStructure(");
int end = source.indexOf("static String registeredStructureUnavailableMessage(", start);
String admission = source.substring(start, end);
String retainedCheck = "GenerationFindCatalog.hasRetainedStructurePlacement(engine, key)";
int firstCheck = admission.indexOf(retainedCheck);
assertTrue(firstCheck >= 0);
assertTrue(admission.indexOf(retainedCheck, firstCheck + retainedCheck.length()) >= 0);
int locateStart = source.indexOf("private static void locateIrisStructure(");
int locateEnd = source.indexOf("private static void runNativeStructureLocate(", locateStart);
String locate = source.substring(locateStart, locateEnd);
assertTrue(locate.contains("GenerationSemanticQueries.nearestStructure("));
assertFalse(locate.contains("IrisStructureLocator.locate("));
String suggestions = Files.readString(root.resolve("art/arcane/iris/modded/command/ModdedCommandSuggestions.java"));
assertTrue(suggestions.contains("GenerationFindCatalog.retainedStructureKeys(engine)"));
}
}
@@ -1,89 +0,0 @@
package art.arcane.iris.modded.command;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedStudioTeleportContractTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void studioOpenSerializesReplacementAndWaitsForTheNativePath() throws IOException {
String source = source("command/ModdedStudioCommands.java");
String open = method(source, "private static int open(");
String execute = method(source, "private static void executeStudioOpen(");
assertTrue(open.contains("TRANSITIONS.submit("));
assertFalse(open.contains("orTimeout("));
assertFalse(open.contains("deadlineNanos"));
assertBefore(execute, "replaceExistingStudio(", "ModdedDimensionManager.createTransientStudio(");
assertBefore(execute, "ModdedDimensionManager.createTransientStudio(", "ModdedDimensionManager.teleportAsync(");
assertFalse(execute.contains("deadlineNanos"));
assertFalse(source.contains("player.teleportTo(studio"));
}
@Test
public void studioTeleportAndVisionShareWarmFutureSemantics() throws IOException {
String studio = source("command/ModdedStudioCommands.java");
String vision = source("command/ModdedVisionOverlay.java");
String dimensions = source("ModdedDimensionManager.java");
assertTrue(studio.contains("private static CompletableFuture<Void> teleportToStudio("));
assertTrue(studio.contains("ModdedDimensionManager.teleportAsync("));
assertTrue(dimensions.contains("TELEPORT_WARM_RADIUS = 0"));
assertTrue(dimensions.contains("addTicketAndLoadWithRadius(\n"
+ " TELEPORT_WARM_TICKET,\n"
+ " chunkPos,\n"
+ " TELEPORT_WARM_RADIUS)"));
assertTrue(dimensions.contains("removeTicketWithRadius(\n"
+ " TELEPORT_WARM_TICKET,\n"
+ " chunkPos,\n"
+ " TELEPORT_WARM_RADIUS)"));
assertTrue(vision.contains("Math.floor(worldX)"));
assertTrue(vision.contains("Math.floor(worldZ)"));
assertTrue(vision.contains("if (opener != null)"));
assertTrue(vision.contains("ModdedDimensionManager.teleportAsync("));
assertFalse(vision.contains("level.getHeight("));
assertFalse(vision.contains("player.teleportTo("));
}
private static String source(String relative) throws IOException {
String root = System.getProperty(SOURCE_ROOT_PROPERTY);
if (root == null || root.isBlank()) {
throw new IllegalStateException("Missing test property " + SOURCE_ROOT_PROPERTY);
}
return Files.readString(Path.of(root).resolve("art/arcane/iris/modded").resolve(relative))
.replace("\r\n", "\n");
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
if (start < 0) {
throw new IllegalArgumentException("Missing source method " + signature);
}
int open = source.indexOf('{', start);
int depth = 0;
for (int index = open; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}' && --depth == 0) {
return source.substring(start, index + 1);
}
}
throw new IllegalArgumentException("Unclosed source method " + signature);
}
private static void assertBefore(String source, String first, String second) {
int firstIndex = source.indexOf(first);
int secondIndex = source.indexOf(second);
assertTrue("Missing source token " + first, firstIndex >= 0);
assertTrue("Missing source token " + second, secondIndex >= 0);
assertTrue(first + " must precede " + second, firstIndex < secondIndex);
}
}
@@ -2,6 +2,7 @@ package art.arcane.iris.modded.localization;
import art.arcane.iris.core.localization.IrisLanguage;
import art.arcane.iris.core.localization.IrisMessages;
import art.arcane.iris.testsupport.ProjectPaths;
import art.arcane.volmlib.util.localization.MessageKey;
import art.arcane.volmlib.util.localization.VolmitLocales;
import com.google.gson.JsonObject;
@@ -27,7 +28,7 @@ public class ModdedMessageContributorTest {
@Test
public void completeLoaderCatalogStillMatchesEveryDownloadableLocale() throws Exception {
Path sourceRoot = Path.of("../../core/src/main/resources/languages");
Path sourceRoot = ProjectPaths.repositoryFile("core/src/main/resources/languages");
for (String locale : VolmitLocales.nonEnglish()) {
JsonObject document = JsonParser.parseString(Files.readString(sourceRoot.resolve(locale + ".json")))
.getAsJsonObject();
+1 -1
View File
@@ -132,6 +132,7 @@ configurations.testRuntimeClasspath.extendsFrom(configurations.runtimeClasspath,
dependencies {
testImplementation('junit:junit:4.13.2')
testImplementation('org.mockito:mockito-core:5.23.0')
testImplementation(testFixtures('art.arcane:core'))
testImplementation(libs.spigot) {
transitive = false
}
@@ -222,7 +223,6 @@ tasks.named('compileJava', JavaCompile).configure {
tasks.named('test').configure {
useJUnitPlatform()
systemProperty('iris.moddedCommonSources', file('../modded-common/src/main/java').absolutePath)
}
processResources {