Host side of ModuleLog: Iris's log carries each module's lines labelled and follows the debug setting, worlds, services, hooks and vanilla structure fits are scoped to the module they are handed to; module signatures that gained a log

This commit is contained in:
piexel committed 2026-10-10 14:25:52 +02:00
1 parent 00a313bd69
commit 95283099fe
31 files changed
+469 -111

No files matched your search

@@ -18,7 +18,11 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import com.volmit.ModuleLog;
import com.volmit.host.ModuleLogs;
import java.text.MessageFormat;
import java.util.ResourceBundle;
@@ -29,20 +33,40 @@ import java.util.ResourceBundle;
* looks up on the system class loader, where a plugin's classes are not.
*/
final class IrisApiLogger implements System.Logger {
private static final String HOST_MODULE_LABEL = "iris";
private static final ModuleLog HOST_LOG = ModuleLogs.labelled(HOST_MODULE_LABEL, new IrisApiLogger(HOST_MODULE_LABEL));
private final String name;
IrisApiLogger(String name) {
this.name = name;
}
/** The log of Iris itself, for the world code that is not any module's. */
static ModuleLog hostLog() {
return HOST_LOG;
}
@Override
public String getName() {
return name;
}
/** Modules' debug lines follow Iris's debug setting, as Iris's own debug lines do. */
@Override
public boolean isLoggable(Level level) {
return level != Level.OFF;
if (level == Level.OFF) {
return false;
}
if (level == Level.DEBUG || level == Level.TRACE) {
return isDebugEnabled();
}
return true;
}
private static boolean isDebugEnabled() {
boolean settingsAvailable = IrisSettings.settings != null || IrisPlatforms.isBound();
return settingsAvailable && IrisSettings.get().getGeneral().isDebug();
}
@Override
@@ -33,6 +33,7 @@ import art.arcane.iris.engine.modifier.FloatingModule;
import art.arcane.iris.engine.object.placement.PlacementModules;
import art.arcane.iris.spi.IrisPlatforms;
import com.volmit.IrisModule;
import com.volmit.ModuleLog;
import com.volmit.host.ModuleHost;
import com.volmit.host.PackModules;
@@ -81,6 +82,11 @@ public final class IrisModuleHost {
new FloatingModule(), new DepositModule(), new DecorantModule(), new CustomModule(), new LootModule(), new SpawnModule());
}
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
public static ModuleLog hostLog() {
return IrisApiLogger.hostLog();
}
/** Whether {@code type} is one of Iris's own classes that built-in settings may hold. */
public static boolean isHostType(Class<?> type) {
return type.getName().startsWith(HOST_TYPE_PACKAGE + ".");
@@ -21,9 +21,12 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
import com.volmit.host.WorldStates;
import com.volmit.world.PackWorld;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
/**
@@ -35,11 +38,21 @@ import java.util.function.Function;
public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
private final Engine engine;
private final IrisPackResources resources;
private final WorldStates states = new WorldStates();
private final WorldStates states;
private final ModuleLog log;
private final Map<ModuleLog, IrisPackWorld> viewsByLog;
IrisPackWorld(Engine engine) {
this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
}
private IrisPackWorld(Engine engine, IrisPackResources resources, WorldStates states, ModuleLog log,
Map<ModuleLog, IrisPackWorld> viewsByLog) {
this.engine = engine;
this.resources = engine.getData().getPackResources();
this.resources = resources;
this.states = states;
this.log = log;
this.viewsByLog = viewsByLog;
}
/** Iris's own view of {@code world}, which Iris hands to every stage, service and lifecycle hook. */
@@ -75,6 +88,17 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
return states.state(type, () -> create.apply(this));
}
@Override
public ModuleLog log() {
return log;
}
/** One view per log, since the services ask for a module's view on every call. */
@Override
public IrisPackWorld withLog(ModuleLog log) {
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
}
@Override
public long seed(IrisSeed seed) {
SeedManager seeds = engine.getSeedManager();
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import com.volmit.host.FeatureCatalog;
import com.volmit.host.ServiceRegistration;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemDrop;
import com.volmit.service.AmbientEffects;
@@ -50,36 +51,60 @@ public final class ModuleServices {
private ModuleServices() {
}
/** One provider of a service and the world as its module sees it, whose log is the module's own. */
private record Provider<S>(S service, PackWorld world) {
}
/** Every provider of {@code service}, in the catalog's order, each with {@code world} scoped to its module. */
private static <S> List<Provider<S>> providers(IrisData data, Class<S> service, PackWorld world) {
List<Provider<S>> providers = new ArrayList<>();
for (ServiceRegistration registration : catalog(data).registrations(service)) {
providers.add(new Provider<>(service.cast(registration.provider()), registration.scope(world)));
}
return providers;
}
private static <S> List<Provider<S>> providers(Engine engine, Class<S> service) {
return providers(engine.getData(), service, engine.getGeneration().world());
}
private static <S> Optional<Provider<S>> firstProvider(Engine engine, Class<S> service) {
List<ServiceRegistration> registrations = catalog(engine.getData()).registrations(service);
if (registrations.isEmpty()) {
return Optional.empty();
}
ServiceRegistration first = registrations.get(0);
return Optional.of(new Provider<>(service.cast(first.provider()), first.scope(engine.getGeneration().world())));
}
/** The pack biome key the module that decides cave biomes puts at the position, whatever the regions say; empty where it overrides nothing. {@code y} is the height above the dimension's bottom. */
public static Optional<String> overriddenCaveBiome(Engine engine, int x, int y, int z) {
return catalog(engine.getData()).service(CaveBiomes.class)
.flatMap(provider -> provider.overriddenBiome(engine.getGeneration().world(), x, y, z));
return firstProvider(engine, CaveBiomes.class)
.flatMap(provider -> provider.service().overriddenBiome(provider.world(), x, y, z));
}
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
public static int caveMinDepthBelowSurface(Engine engine, String biomeKey) {
return catalog(engine.getData()).service(CaveBiomes.class)
.map(provider -> provider.minDepthBelowSurface(engine.getGeneration().world(), biomeKey))
return firstProvider(engine, CaveBiomes.class)
.map(provider -> provider.service().minDepthBelowSurface(provider.world(), biomeKey))
.orElse(0);
}
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
public static Set<String> objectsAt(Engine engine, int chunkX, int chunkZ) {
PackWorld world = engine.getGeneration().world();
Set<String> keys = new LinkedHashSet<>();
for (ObjectsAt provider : catalog(engine.getData()).services(ObjectsAt.class)) {
keys.addAll(provider.objectsAt(world, chunkX, chunkZ));
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
keys.addAll(provider.service().objectsAt(provider.world(), chunkX, chunkZ));
}
return keys;
}
/** The biomes and regions of the engine's layout that every module says place the object {@code objectKey}. */
public static ObjectsAt.PlacedBy objectPlacers(Engine engine, String objectKey) {
PackWorld world = engine.getGeneration().world();
Set<String> biomes = new LinkedHashSet<>();
Set<String> regions = new LinkedHashSet<>();
for (ObjectsAt provider : catalog(engine.getData()).services(ObjectsAt.class)) {
ObjectsAt.PlacedBy placedBy = provider.placedBy(world, objectKey);
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
ObjectsAt.PlacedBy placedBy = provider.service().placedBy(provider.world(), objectKey);
biomes.addAll(placedBy.biomes());
regions.addAll(placedBy.regions());
}
@@ -88,31 +113,28 @@ public final class ModuleServices {
/** The loot tables the modules say the container at {@code site} draws from, in module order. */
public static List<Loot.Source> lootTables(Engine engine, Loot.Site site) {
PackWorld world = engine.getGeneration().world();
List<Loot.Source> tables = new ArrayList<>();
for (Loot provider : catalog(engine.getData()).services(Loot.class)) {
tables.addAll(provider.tables(world, site));
for (Provider<Loot> provider : providers(engine, Loot.class)) {
tables.addAll(provider.service().tables(provider.world(), site));
}
return tables;
}
/** The items loot table {@code key} gives at {@code site}, from the module that knows the table. */
public static List<ItemDrop> lootItems(Engine engine, Loot.Site site, String key) {
PackWorld world = engine.getGeneration().world();
List<ItemDrop> items = new ArrayList<>();
for (Loot provider : catalog(engine.getData()).services(Loot.class)) {
items.addAll(provider.items(world, site, key));
for (Provider<Loot> provider : providers(engine, Loot.class)) {
items.addAll(provider.service().items(provider.world(), site, key));
}
return items;
}
/** What the modules drop for the broken block, put together. */
public static BlockDrops.Result blockDrops(Engine engine, BlockDrops.Broken broken) {
PackWorld world = engine.getGeneration().world();
List<ItemDrop> drops = new ArrayList<>();
boolean replacesVanillaDrops = false;
for (BlockDrops provider : catalog(engine.getData()).services(BlockDrops.class)) {
BlockDrops.Result result = provider.drops(world, broken);
for (Provider<BlockDrops> provider : providers(engine, BlockDrops.class)) {
BlockDrops.Result result = provider.service().drops(provider.world(), broken);
drops.addAll(result.drops());
replacesVanillaDrops |= result.replacesVanillaDrops();
}
@@ -121,9 +143,8 @@ public final class ModuleServices {
/** The tree grown by the first module that grows one for {@code sapling}; empty leaves the growth to the platform. */
public static Optional<SaplingGrowth.Growth> growSapling(Engine engine, SaplingGrowth.Sapling sapling, SaplingGrowth.Surroundings surroundings) {
PackWorld world = engine.getGeneration().world();
for (SaplingGrowth provider : catalog(engine.getData()).services(SaplingGrowth.class)) {
Optional<SaplingGrowth.Growth> growth = provider.grow(world, sapling, surroundings);
for (Provider<SaplingGrowth> provider : providers(engine, SaplingGrowth.class)) {
Optional<SaplingGrowth.Growth> growth = provider.service().grow(provider.world(), sapling, surroundings);
if (growth.isPresent()) {
return growth;
}
@@ -133,11 +154,10 @@ public final class ModuleServices {
/** The objects every module places as trees. */
public static SaplingGrowth.TreeObjects treeObjects(Engine engine) {
PackWorld world = engine.getGeneration().world();
Set<String> objects = new LinkedHashSet<>();
Set<String> procedural = new LinkedHashSet<>();
for (SaplingGrowth provider : catalog(engine.getData()).services(SaplingGrowth.class)) {
SaplingGrowth.TreeObjects trees = provider.treeObjects(world);
for (Provider<SaplingGrowth> provider : providers(engine, SaplingGrowth.class)) {
SaplingGrowth.TreeObjects trees = provider.service().treeObjects(provider.world());
objects.addAll(trees.objects());
procedural.addAll(trees.procedural());
}
@@ -146,11 +166,10 @@ public final class ModuleServices {
/** What the first module with something to spawn at {@code site} plans; empty when none does. */
public static Optional<PlannedSpawn> planSpawn(Engine engine, EntitySpawns.Site site) {
PackWorld world = engine.getGeneration().world();
for (EntitySpawns provider : catalog(engine.getData()).services(EntitySpawns.class)) {
Optional<EntitySpawns.Plan> plan = provider.plan(world, site);
for (Provider<EntitySpawns> provider : providers(engine, EntitySpawns.class)) {
Optional<EntitySpawns.Plan> plan = provider.service().plan(provider.world(), site);
if (plan.isPresent()) {
return Optional.of(new PlannedSpawn(provider, world, plan.get()));
return Optional.of(new PlannedSpawn(provider.service(), provider.world(), plan.get()));
}
}
return Optional.empty();
@@ -158,9 +177,8 @@ public final class ModuleServices {
/** The entity {@code key} as the first module that knows it would spawn it. */
public static Optional<EntitySpec> entity(Engine engine, String key) {
PackWorld world = engine.getGeneration().world();
for (EntitySpawns provider : catalog(engine.getData()).services(EntitySpawns.class)) {
Optional<EntitySpec> entity = provider.entity(world, key);
for (Provider<EntitySpawns> provider : providers(engine, EntitySpawns.class)) {
Optional<EntitySpec> entity = provider.service().entity(provider.world(), key);
if (entity.isPresent()) {
return entity;
}
@@ -170,9 +188,8 @@ public final class ModuleServices {
/** What the first module that knows the marker {@code tag} says it does. */
public static Optional<EntitySpawns.MarkerRule> markerRule(Engine engine, String tag) {
PackWorld world = engine.getGeneration().world();
for (EntitySpawns provider : catalog(engine.getData()).services(EntitySpawns.class)) {
Optional<EntitySpawns.MarkerRule> rule = provider.marker(world, tag);
for (Provider<EntitySpawns> provider : providers(engine, EntitySpawns.class)) {
Optional<EntitySpawns.MarkerRule> rule = provider.service().marker(provider.world(), tag);
if (rule.isPresent()) {
return rule;
}
@@ -182,10 +199,9 @@ public final class ModuleServices {
/** The ambient effects every module says are due for a player standing at {@code at}, in module order. */
public static List<AmbientEffects.Effect> ambientEffects(Engine engine, BlockPosition at) {
PackWorld world = engine.getGeneration().world();
List<AmbientEffects.Effect> effects = new ArrayList<>();
for (AmbientEffects provider : catalog(engine.getData()).services(AmbientEffects.class)) {
effects.addAll(provider.due(world, at));
for (Provider<AmbientEffects> provider : providers(engine, AmbientEffects.class)) {
effects.addAll(provider.service().due(provider.world(), at));
}
return effects;
}
@@ -208,10 +224,9 @@ public final class ModuleServices {
/** The keys of the structures the world's modules place and can locate. */
public static Set<String> locatableStructures(Engine engine) {
PackWorld world = engine.getGeneration().world();
Set<String> keys = new LinkedHashSet<>();
for (StructureLocator provider : catalog(engine.getData()).services(StructureLocator.class)) {
keys.addAll(provider.locatable(world));
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
keys.addAll(provider.service().locatable(provider.world()));
}
return keys;
}
@@ -226,9 +241,8 @@ public final class ModuleServices {
* can locate it, in the world's own coordinates; not found when none can.
*/
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
PackWorld world = engine.getGeneration().world();
LocateResult result = structureLocatorOf(engine, key)
.map(provider -> provider.locate(world, key, fromX, fromZ, maxRadiusChunks))
.map(provider -> provider.service().locate(provider.world(), key, fromX, fromZ, maxRadiusChunks))
.orElse(LocateResult.NOT_FOUND);
return StructureSearch.of(result, engine);
}
@@ -256,14 +270,13 @@ public final class ModuleServices {
}
/** The first provider, in the catalog's order, whose locatable structures hold {@code key}. */
private static Optional<StructureLocator> structureLocatorOf(Engine engine, String key) {
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key) {
if (key == null || key.isBlank()) {
return Optional.empty();
}
PackWorld world = engine.getGeneration().world();
String wanted = normalized(key);
for (StructureLocator provider : catalog(engine.getData()).services(StructureLocator.class)) {
if (provider.locatable(world).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
if (provider.service().locatable(provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
return Optional.of(provider);
}
}
@@ -43,6 +43,7 @@ import com.volmit.vanilla.StructureFit;
import com.volmit.vanilla.StructureStep;
import com.volmit.vanilla.TemplateCells;
import com.volmit.vanilla.TerrainAdaptation;
import com.volmit.ModuleLog;
import com.volmit.world.BlockAccess;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
@@ -96,17 +97,21 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
@Override
public <S> Session beforePieces(NativeFitChunk<S> chunk) {
ChunkFit<S> fit = new ChunkFit<>(chunk, world);
for (ServiceRegistration registration : providers) {
ModuleVanillaStructures.ask(registration, "fitting structures into chunk " + fit.chunkName(), provider -> {
List<ChunkFit<S>> fits = providers.stream()
.<ChunkFit<S>>map(registration -> new ChunkFit<>(chunk, () -> registration.scope(world.get()), registration.module().log()))
.toList();
for (int index = 0; index < providers.size(); index++) {
ChunkFit<S> fit = fits.get(index);
ModuleVanillaStructures.ask(providers.get(index), "fitting structures into chunk " + fit.chunkName(), provider -> {
provider.beforePieces(fit);
return Boolean.TRUE;
});
}
return startIndex -> {
StructureFit.Start placed = fit.starts().get(startIndex);
for (ServiceRegistration registration : providers) {
ModuleVanillaStructures.ask(registration, "fitting " + placed.structure() + " into chunk " + fit.chunkName(),
for (int index = 0; index < providers.size(); index++) {
ChunkFit<S> fit = fits.get(index);
StructureFit.Start placed = fit.starts().get(startIndex);
ModuleVanillaStructures.ask(providers.get(index), "fitting " + placed.structure() + " into chunk " + fit.chunkName(),
provider -> {
provider.afterPieces(fit, placed);
return Boolean.TRUE;
@@ -145,13 +150,15 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
private static final class ChunkFit<S> implements StructureFit {
private final NativeFitChunk<S> chunk;
private final Supplier<PackWorld> world;
private final ModuleLog log;
private final Access<S> blocks;
private final List<StructureFit.Start> starts;
private final Map<Class<?>, Object> states = new HashMap<>();
private ChunkFit(NativeFitChunk<S> chunk, Supplier<PackWorld> world) {
private ChunkFit(NativeFitChunk<S> chunk, Supplier<PackWorld> world, ModuleLog log) {
this.chunk = chunk;
this.world = world;
this.log = log;
this.blocks = new Access<>(chunk);
List<StructureFit.Start> converted = new ArrayList<>(chunk.starts().size());
for (NativeFitStart<S> start : chunk.starts()) {
@@ -169,6 +176,11 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
return world.get();
}
@Override
public ModuleLog log() {
return log;
}
@Override
public long seed() {
return chunk.seed();
@@ -88,11 +88,11 @@ public final class ModuleVanillaStructures {
* as the host's plans: world heights, the platform's jigsaw changes and the modules' memos.
*/
public static List<NativeStructureStartPlan> startsAt(Engine engine, int chunkX, int chunkZ) {
StartContext context = new StartContext(engine.getGeneration().world(),
new IrisTerrainSampler(engine, new PackResourceIds(engine.getData().getDataFolder()),
chunkX << 4, chunkZ << 4, START_TERRAIN_REACH_BLOCKS));
TerrainSampler terrain = new IrisTerrainSampler(engine, new PackResourceIds(engine.getData().getDataFolder()),
chunkX << 4, chunkZ << 4, START_TERRAIN_REACH_BLOCKS);
List<NativeStructureStartPlan> plans = new ArrayList<>();
for (ServiceRegistration registration : providersOf(engine.getData())) {
StartContext context = new StartContext(registration.scope(engine.getGeneration().world()), terrain);
for (VanillaStructureStart start : ask(registration, "placing starts in chunk " + chunkX + "," + chunkZ,
provider -> provider.starts(chunkX, chunkZ, context))) {
plans.add(plan(registration.module(), start, chunkX, chunkZ, engine.getMinHeight()));
@@ -0,0 +1,38 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.StructureAssembler;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.engine.object.value.IrisPosition;
/**
* Structure assembly for Iris's own tools, the commands and studio, which run outside any module's stage, service or hook and so
* log as Iris itself.
*/
public final class StructureAssemblies {
private StructureAssemblies() {
}
/** The assembler of {@code structure}, compiled from the pack {@code data} serves, for a start at {@code origin}. */
public static StructureAssembler forData(IrisData data, IrisStructure structure, IrisPosition origin) {
return StructureAssembler.forData(data, structure, origin, IrisModuleHost.hostLog());
}
}
@@ -2,6 +2,7 @@ package art.arcane.iris.core.service;
import art.arcane.iris.engine.framework.structure.StructureResources;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.StructureAssemblies;
import art.arcane.iris.core.nms.INMS;
import art.arcane.iris.core.runtime.InPlaceChunkRegenerator;
import art.arcane.iris.core.runtime.jigsaw.JigsawPlanarArchetype;
@@ -2476,7 +2477,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
if (structure == null) {
throw new IOException("The active structure resource no longer exists");
}
StructureAssembler assembler = StructureAssembler.forData(
StructureAssembler assembler = StructureAssemblies.forData(
request.source(), structure, origin);
StructureAssemblyResult assembly = assembler.assemble(new RNG(seed));
if (!assembly.hasOutput()) {