mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Settings no longer resolve to one value per type. FeatureSettings.at(type, x, z) returns one entry per level that declares the type at that column (dimension, region, surface biome, placement), each with its level, source and value; levels stack and a module decides what several mean. Conditional stage bodies receive every configured entry. Chunk and mantle runners collect a chunk's settings themselves, so a stage runs when any column of the chunk configures it. Work that writes the mantle or reaches beyond its chunk moves to a new MANTLE pipeline (Stage.mantle, MantleRunner) that the host runs around a chunk before it generates. Chunk stages may no longer declare a reach or mantle writes and see the mantle read-only. Built-in settings may hold host types the host describes itself (ModuleHost.describingHostTypesIn, ValueKind.HostKind); pack modules cannot. FeatureSchema.shorthand() names the only option of settings packs may write as a bare value.
94 lines
3.2 KiB
Java
94 lines
3.2 KiB
Java
package com.volmit.host;
|
|
|
|
import com.volmit.host.schema.PackSchema;
|
|
import java.nio.file.Path;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/** One loaded pack: its module jars and everything derived from them together with the host's
|
|
* built-in modules. This is the host's entry point for loading and unloading a pack's modules.
|
|
*
|
|
* <pre>{@code
|
|
* try (var pack = LoadedPack.load(packRoot, host)) {
|
|
* var placer = new PlacementRunner(pack.placement());
|
|
* ...
|
|
* }
|
|
* }</pre>
|
|
*
|
|
* A load either returns a complete pack or throws with nothing left open. Close the pack when it
|
|
* unloads, after the host has stopped using its graphs, catalog and runners: closing releases the
|
|
* pack's class loader and deletes its copies of the module jars. The original jars are never held
|
|
* open, so a module author can rebuild them while the pack is loaded.
|
|
*/
|
|
public final class LoadedPack implements AutoCloseable {
|
|
private final PackModules packModules;
|
|
private final LoadedModules loaded;
|
|
|
|
private LoadedPack(PackModules packModules, LoadedModules loaded) {
|
|
this.packModules = packModules;
|
|
this.loaded = loaded;
|
|
}
|
|
|
|
/** Loads the pack's module jars, installs them with the host's built-in modules and resolves the
|
|
* pipelines. Fails with the first load error, naming the jar or module at fault.
|
|
*/
|
|
public static LoadedPack load(Path packRoot, ModuleHost host) {
|
|
Objects.requireNonNull(host, "host");
|
|
var packModules = PackModules.load(packRoot, host.exposedHostPackages(), host.jarCopyRoot(), host.logger());
|
|
try {
|
|
var loaded = LoadedModules.load(host.withPackModules(packModules.modules()),
|
|
host.reservedHostFields(), host.reservedNamespaces(), host.hostTypePackages());
|
|
return new LoadedPack(packModules, loaded);
|
|
} catch (RuntimeException | Error failure) {
|
|
closeAfterFailure(packModules, failure);
|
|
throw failure;
|
|
}
|
|
}
|
|
|
|
/** The pack's own modules, one per jar, in jar file name order. */
|
|
public List<DiscoveredModule> packModules() {
|
|
return packModules.modules();
|
|
}
|
|
|
|
/** Classes the pack's jars use that nobody has, per jar; see {@link PackModules#missingClasses()}. */
|
|
public List<MissingClasses> missingClasses() {
|
|
return packModules.missingClasses();
|
|
}
|
|
|
|
public FeatureCatalog catalog() {
|
|
return loaded.catalog();
|
|
}
|
|
|
|
/** What the pack's modules, built-in ones included, add to the pack's JSON, for studio's schema
|
|
* and completion. Built with the pack, so a load that returns has a complete description.
|
|
*/
|
|
public PackSchema schema() {
|
|
return loaded.schema();
|
|
}
|
|
|
|
public ResolvedGraph placement() {
|
|
return loaded.placement();
|
|
}
|
|
|
|
public ResolvedGraph chunk() {
|
|
return loaded.chunk();
|
|
}
|
|
|
|
public ResolvedGraph mantle() {
|
|
return loaded.mantle();
|
|
}
|
|
|
|
@Override
|
|
public void close() {
|
|
packModules.close();
|
|
}
|
|
|
|
private static void closeAfterFailure(PackModules packModules, Throwable failure) {
|
|
try {
|
|
packModules.close();
|
|
} catch (RuntimeException exception) {
|
|
failure.addSuppressed(exception);
|
|
}
|
|
}
|
|
}
|