Run every mantle stage as a mantle pass of its own, ordered by the stage graph

ModuleMantleComponent now runs one mantle stage. IrisEngineMantle builds one component per stage of the
pack's mantle graph, in resolved order, each its own pass, when first needed after a load or hotload,
so a pack mantle stage can order itself after Iris's objects and structures. A stage's radius is its
reach, worked out from the pack (IrisPackSettings: the dimension, its regions and biomes). Iris's own
stages keep the flags of the components they replace (CARVED, OBJECT, FLOATING_OBJECT, JIGSAW), so
disabledComponents keeps working; pack stages get custom flags in order (MantleStageFlags).

There is one mantle path now: the separately registered object, floating object and structure
components, IrisMantleComponent, the ComponentFlag annotation, registerComponent and
getObjectComponent are gone. Engine.getObjectsAt asks the runtime's ObjectPlacing.
This commit is contained in:
piexel committed 2026-10-08 12:44:43 +02:00
1 parent 0f63a3c59a
commit 0a06d5ff29
25 files changed
+463 -365

No files matched your search

@@ -21,6 +21,8 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.engine.actuator.BiomeModule;
import art.arcane.iris.engine.actuator.DecorantModule;
import art.arcane.iris.engine.actuator.TerrainModule;
import art.arcane.iris.engine.mantle.components.ObjectModule;
import art.arcane.iris.engine.mantle.components.StructureModule;
import art.arcane.iris.engine.modifier.CarveModule;
import art.arcane.iris.engine.modifier.CustomModule;
import art.arcane.iris.engine.modifier.DepositModule;
@@ -65,8 +67,9 @@ public final class IrisModuleHost {
}
private static List<IrisModule> generationModules() {
return List.of(new BiomeModule(), new TerrainModule(), new CarveModule(), new PostModule(), new FloatingModule(),
new DepositModule(), new MatterModule(), new DecorantModule(), new PerfectionModule(), new CustomModule());
return List.of(new BiomeModule(), new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
new PostModule(), new FloatingModule(), new DepositModule(), new MatterModule(), new DecorantModule(),
new PerfectionModule(), new CustomModule());
}
/** Whether {@code type} is one of Iris's own classes that built-in settings may hold. */
@@ -0,0 +1,85 @@
/*
* 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.IrisRegistrant;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.PackSettings;
import java.util.ArrayList;
import java.util.List;
/**
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads: the
* engine's dimension, then every region it can reach, then every biome. Iris's built-in mantle stages size
* their reach from Iris's own pack data instead of module settings; they reach the engine through
* {@link #of(PackSettings)}.
*/
public final class IrisPackSettings implements PackSettings {
private static final String DIMENSION = "dimension";
private static final String REGION = "region";
private static final String BIOME = "biome";
private final Engine engine;
private final PackResourceIds ids;
IrisPackSettings(Engine engine) {
this.engine = engine;
this.ids = new PackResourceIds(engine.getData().getDataFolder());
}
/** Iris's own view of {@code settings}, which Iris hands to every reach it works out. */
public static IrisPackSettings of(PackSettings settings) {
if (!(settings instanceof IrisPackSettings irisSettings)) {
throw new IllegalArgumentException("Built-in reaches are worked out from an Iris engine's pack, not " + settings);
}
return irisSettings;
}
/** The engine whose pack is loading. */
public Engine engine() {
return engine;
}
@Override
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
IrisDimension dimension = engine.getDimension();
List<Entry<F>> entries = new ArrayList<>();
addEntry(entries, featureType, Target.DIMENSION, DIMENSION, dimension);
for (IrisRegion region : dimension.getAllRegions(engine)) {
addEntry(entries, featureType, Target.REGION, REGION, region);
}
for (IrisBiome biome : dimension.getReachableBiomes(engine)) {
addEntry(entries, featureType, Target.BIOME, BIOME, biome);
}
return List.copyOf(entries);
}
private <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Target level, String kind,
IrisRegistrant owner) {
owner.getModuleSettings().find(featureType)
.ifPresent(value -> entries.add(new Entry<>(level, ids.of(kind, owner.getLoadKey()), value)));
}
}
@@ -0,0 +1,80 @@
/*
* 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.builtin.carve.CarveStages;
import art.arcane.iris.builtin.floating.FloatingStages;
import art.arcane.iris.builtin.objects.ObjectStages;
import art.arcane.iris.builtin.structure.StructureStages;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import com.volmit.host.ResolvedStage;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* The mantle flag of each mantle stage: it marks a mantle chunk whose stage has run, and names the stage in a
* dimension's {@code disabledComponents}. Iris's own mantle stages keep the flags their mantle components had,
* so packs that disable {@code CARVED} keep doing so and existing worlds stay marked. Every other stage gets a
* custom flag in resolved order, so adding or removing a pack mantle stage can renumber the stages after it.
*/
public final class MantleStageFlags {
private static final List<BuiltIn> BUILT_IN = List.of(
new BuiltIn(CarveStages.CAVES.id(), ReservedFlag.CARVED),
new BuiltIn(ObjectStages.PLACE.id(), ReservedFlag.OBJECT),
new BuiltIn(FloatingStages.OBJECTS.id(), ReservedFlag.FLOATING_OBJECT),
new BuiltIn(StructureStages.PLACE.id(), ReservedFlag.JIGSAW));
private MantleStageFlags() {
}
/** The flags of Iris's own mantle stages, in their order, which a dimension can list in {@code disabledComponents}. */
public static List<MantleFlag> builtIn() {
return BUILT_IN.stream().map(BuiltIn::flag).toList();
}
/** One flag per stage, in the order of {@code stages}. */
static List<MantleFlag> assign(List<ResolvedStage> stages) {
List<MantleFlag> flags = new ArrayList<>(stages.size());
int nextCustom = MantleFlag.MIN_ORDINAL;
for (ResolvedStage stage : stages) {
Optional<MantleFlag> builtIn = builtInFlag(stage.stage().id());
if (builtIn.isPresent()) {
flags.add(builtIn.get());
continue;
}
if (nextCustom > MantleFlag.MAX_ORDINAL) {
throw new IllegalStateException("The pack has more mantle stages than Iris has mantle flags for; stage "
+ stage.stage().id() + " of module " + stage.module() + " is one too many");
}
flags.add(MantleFlag.of(nextCustom++));
}
return List.copyOf(flags);
}
private static Optional<MantleFlag> builtInFlag(ResourceId stage) {
return BUILT_IN.stream().filter(builtIn -> builtIn.stage().equals(stage)).map(BuiltIn::flag).findFirst();
}
private record BuiltIn(ResourceId stage, MantleFlag flag) {
}
}
@@ -19,74 +19,103 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.mantle.IrisMantleComponent;
import art.arcane.iris.engine.mantle.MantleComponent;
import art.arcane.iris.engine.mantle.MantleWriter;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import com.volmit.host.LoadedPack;
import com.volmit.host.MantleRunner;
import com.volmit.host.ResolvedGraph;
import com.volmit.host.ResolvedStage;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Runs the pack's mantle pipeline, Iris's built-in mantle stages included, as one of Iris's mantle components:
* once for every chunk the mantle prepares around a generating chunk, as far as the pipeline's declared reach.
* It is the first pass, where carving has always run, so Iris's object, floating object and structure passes
* see the caves and whatever else mantle stages wrote. It is disabled while the pack has no mantle stages.
* Runs one mantle stage of the pack, Iris's built-in ones included, as a mantle component of its own: a pass of
* Iris's mantle at the stage's place in the resolved order, so the stage sees everything earlier stages wrote
* into the chunks around it. Its radius is the stage's reach, worked out from the pack when the components are
* built; its flag comes from {@link MantleStageFlags}, so a dimension's {@code disabledComponents} turns it off.
*/
public final class ModuleMantleComponent extends IrisMantleComponent {
/** Marks a mantle chunk whose module stages have run. */
public static final MantleFlag FLAG = MantleFlag.of(MantleFlag.MIN_ORDINAL);
/** The first pass: the carving stage it runs had priority 0 as a component of its own. */
private static final int PRIORITY = 0;
public final class ModuleMantleComponent implements MantleComponent {
private final Engine engine;
private final LoadedPack pack;
private final MantleRunner runner;
private final ResolvedStage stage;
private final MantleFlag flag;
private final int priority;
private final int reachBlocks;
private final boolean enabled;
/** Whether the pack has mantle stages; asked on every chunk, so kept until the next hotload. */
private volatile Boolean hasStages;
private ModuleMantleComponent(Engine engine, LoadedPack pack, MantleRunner runner, ResolvedStage stage,
MantleFlag flag, int priority, int reachBlocks, boolean enabled) {
this.engine = engine;
this.pack = pack;
this.runner = runner;
this.stage = stage;
this.flag = flag;
this.priority = priority;
this.reachBlocks = reachBlocks;
this.enabled = enabled;
}
public ModuleMantleComponent(EngineMantle engineMantle) {
super(engineMantle, FLAG, PRIORITY);
/**
* One component per mantle stage of the engine's pack, in resolved order, each its own pass. A stage whose
* flag is in {@code disabled} is turned off.
*/
public static List<ModuleMantleComponent> forPack(Engine engine, Set<MantleFlag> disabled) {
return forPack(engine, engine.getData().getModules().pack(), disabled);
}
static List<ModuleMantleComponent> forPack(Engine engine, LoadedPack pack, Set<MantleFlag> disabled) {
ResolvedGraph graph = pack.mantle();
MantleRunner runner = new MantleRunner(graph);
IrisPackSettings settings = new IrisPackSettings(engine);
List<MantleFlag> flags = MantleStageFlags.assign(graph.stages());
List<ModuleMantleComponent> components = new ArrayList<>(flags.size());
for (int position = 0; position < flags.size(); position++) {
ResolvedStage stage = graph.stages().get(position);
MantleFlag flag = flags.get(position);
components.add(new ModuleMantleComponent(engine, pack, runner, stage, flag, position,
stage.reachBlocks(settings), !disabled.contains(flag)));
}
return List.copyOf(components);
}
/** The stage this component runs. */
public ResolvedStage stage() {
return stage;
}
@Override
public int getPriority() {
return priority;
}
@Override
public int getRadius() {
return reachBlocks;
}
@Override
public MantleFlag getFlag() {
return flag;
}
@Override
public boolean isEnabled() {
return super.isEnabled() && hasStages();
}
@Override
public void hotload() {
super.hotload();
hasStages = null;
}
@Override
protected int computeRadius() {
return pipeline().reach().blocks();
return enabled;
}
@Override
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
Engine engine = getEngineMantle().getEngine();
IrisMantleChunk chunk = new IrisMantleChunk(engine, writer, x, z, context);
chunk.runBound(() -> generate(engine.getData().getModules().pack(), engine, x, z, getRadius(), writer::acquireChunk));
new IrisMantleChunk(engine, writer, x, z, context).runBound(() -> generate(x, z, writer::acquireChunk));
}
/** Runs the mantle stages of chunk {@code x}, {@code z}, with the mantle chunks within {@code reachBlocks} of it. */
static void generate(LoadedPack pack, Engine engine, int x, int z, int reachBlocks, IrisModuleMantle.Chunks chunks) {
/** Runs the stage for chunk {@code x}, {@code z}, with the mantle chunks within the stage's reach of it. */
void generate(int x, int z, IrisModuleMantle.Chunks chunks) {
IrisMantleGenerationContext inputs = new IrisMantleGenerationContext(engine, x, z, reachBlocks, chunks, pack.catalog().mantle());
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x, z);
new MantleRunner(pack.mantle()).generate(inputs, seed);
}
private boolean hasStages() {
Boolean known = hasStages;
if (known == null) {
known = !pipeline().stages().isEmpty();
hasStages = known;
}
return known;
}
private ResolvedGraph pipeline() {
return getEngineMantle().getEngine().getData().getModules().pack().mantle();
runner.generate(stage.stage(), inputs, ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x, z));
}
}
@@ -47,6 +47,7 @@ import art.arcane.iris.core.nms.container.BlockPos;
import art.arcane.iris.core.nms.container.Pair;
import art.arcane.iris.core.structure.StructureIndexService;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.mantle.components.ObjectModule;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.spi.PlatformBiome;
@@ -386,7 +387,7 @@ public class IrisEngine implements Engine {
@Override
public Set<String> getObjectsAt(int x, int z) {
return getMantle().getObjectComponent().guess(x, z);
return ObjectModule.placing(this).guess(x, z);
}
@Override
@@ -27,16 +27,11 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.mantle.MantleComponent;
import art.arcane.iris.engine.mantle.MantlePass;
import art.arcane.iris.engine.mantle.components.MantleFloatingObjectComponent;
import art.arcane.iris.engine.mantle.components.MantleObjectComponent;
import art.arcane.iris.engine.mantle.components.IrisStructureComponent;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.matter.IrisMatterContext;
import art.arcane.iris.util.project.matter.IrisMatterSupport;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.format.Form;
import art.arcane.volmlib.util.mantle.io.Lz4IOWorkerCodecSupport;
import art.arcane.volmlib.util.mantle.runtime.IOWorker;
@@ -44,7 +39,6 @@ import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.runtime.MantleDataAdapter;
import art.arcane.volmlib.util.mantle.runtime.MantleHooks;
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import art.arcane.iris.util.common.format.C;
import art.arcane.volmlib.util.matter.IrisMatter;
@@ -60,9 +54,7 @@ import lombok.ToString;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
@@ -73,110 +65,61 @@ import java.util.function.Supplier;
public class IrisEngineMantle implements EngineMantle {
private final Engine engine;
private final Mantle<Matter> mantle;
/** The pack's mantle stages, one component each, built when first needed after the pack loads. */
@Getter(AccessLevel.NONE)
private final KMap<Integer, KList<MantleComponent>> components;
private final KMap<MantleFlag, MantleComponent> registeredComponents = new KMap<>();
private final AtomicCache<List<MantlePass>> componentsCache = new AtomicCache<>();
private final AtomicCache<Set<MantleFlag>> disabledFlags = new AtomicCache<>();
private final MantleObjectComponent object;
private final AtomicCache<List<ModuleMantleComponent>> stageComponents = new AtomicCache<>();
@Getter(AccessLevel.NONE)
private final AtomicCache<List<MantlePass>> passes = new AtomicCache<>();
public IrisEngineMantle(Engine engine) {
this.engine = engine;
this.mantle = createMantle(engine);
components = new KMap<>();
object = new MantleObjectComponent(this);
registerComponent(object);
registerComponent(new MantleFloatingObjectComponent(this));
registerComponent(new IrisStructureComponent(this));
registerComponent(new ModuleMantleComponent(this));
}
@Override
public int getRadius() {
if (components.isEmpty()) return 0;
return getComponents().getFirst().passChunkRadius();
List<MantlePass> passes = getComponents();
return passes.isEmpty() ? 0 : passes.getFirst().passChunkRadius();
}
@Override
public int getRealRadius() {
if (components.isEmpty()) return 0;
return getComponents().getLast().passChunkRadius();
List<MantlePass> passes = getComponents();
return passes.isEmpty() ? 0 : passes.getLast().passChunkRadius();
}
/** One pass per mantle stage, in the stage graph's order. */
@Override
public List<MantlePass> getComponents() {
return componentsCache.aquire(() -> {
List<List<MantleComponent>> passes = components.keySet()
.stream()
.sorted()
.map(components::get)
.map(List::<MantleComponent>copyOf)
.filter(pass -> !pass.isEmpty())
.toList();
MantlePass[] built = new MantlePass[passes.size()];
int downstreamBlockRadius = 0;
for (int i = passes.size() - 1; i >= 0; i--) {
List<MantleComponent> pass = passes.get(i);
int passBlockRadius = pass.stream()
.filter(MantleComponent::isEnabled)
.mapToInt(MantleComponent::getRadius)
.max()
.orElse(0);
int passInputRadius = pass.stream()
.filter(MantleComponent::isEnabled)
.mapToInt(MantleComponent::getInputRadius)
.max()
.orElse(0);
int invocationRadius = downstreamBlockRadius + passBlockRadius;
built[i] = new MantlePass(pass, Math.ceilDiv(invocationRadius, 16), downstreamBlockRadius);
downstreamBlockRadius = invocationRadius + passInputRadius;
}
return List.of(built);
});
}
@Override
public Map<MantleFlag, MantleComponent> getRegisteredComponents() {
return Collections.unmodifiableMap(registeredComponents);
}
@Override
public boolean registerComponent(MantleComponent c) {
if (registeredComponents.putIfAbsent(c.getFlag(), c) != null) return false;
c.setEnabled(!getDisabledFlags().contains(c.getFlag()));
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
componentsCache.reset();
return true;
}
@Override
public KList<MantleFlag> getComponentFlags() {
return new KList<>(registeredComponents.keySet());
return passes.aquire(() -> passesOf(stageComponents()));
}
@Override
public void hotload() {
disabledFlags.reset();
for (MantleComponent component : registeredComponents.values()) {
component.hotload();
component.setEnabled(!getDisabledFlags().contains(component.getFlag()));
stageComponents.reset();
passes.reset();
}
private List<ModuleMantleComponent> stageComponents() {
return stageComponents.aquire(() -> ModuleMantleComponent.forPack(engine, Set.copyOf(getDimension().getDisabledComponents())));
}
/**
* Each pass must complete its own reach plus the reach of every later pass, or a later pass reads chunks this
* one never wrote. Disabled components reach nothing.
*/
private static List<MantlePass> passesOf(List<? extends MantleComponent> components) {
MantlePass[] built = new MantlePass[components.size()];
int downstreamBlockRadius = 0;
for (int i = components.size() - 1; i >= 0; i--) {
MantleComponent component = components.get(i);
int passBlockRadius = component.isEnabled() ? component.getRadius() : 0;
int passInputRadius = component.isEnabled() ? component.getInputRadius() : 0;
int invocationRadius = downstreamBlockRadius + passBlockRadius;
built[i] = new MantlePass(List.of(component), Math.ceilDiv(invocationRadius, 16), downstreamBlockRadius);
downstreamBlockRadius = invocationRadius + passInputRadius;
}
componentsCache.reset();
}
private Set<MantleFlag> getDisabledFlags() {
return disabledFlags.aquire(() -> {
KList<MantleFlag> disabled = new KList<>();
disabled.addAll(getDimension().getDisabledComponents());
return Set.copyOf(disabled);
});
}
@Override
public MantleObjectComponent getObjectComponent() {
return object;
return List.of(built);
}
private static Mantle<Matter> createMantle(Engine engine) {
@@ -1,14 +0,0 @@
package art.arcane.iris.engine.mantle;
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ComponentFlag {
ReservedFlag value();
}
@@ -25,7 +25,6 @@ import art.arcane.iris.engine.UpperDimensionContext;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineTarget;
import art.arcane.iris.engine.framework.TreeBlockMaterial;
import art.arcane.iris.engine.mantle.components.MantleObjectComponent;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.volmlib.util.collection.KList;
@@ -46,7 +45,6 @@ import art.arcane.iris.spi.PlatformBlockState;
import org.jetbrains.annotations.UnmodifiableView;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public interface EngineMantle extends MatterGenerator {
@@ -63,14 +61,6 @@ public interface EngineMantle extends MatterGenerator {
@UnmodifiableView
List<MantlePass> getComponents();
@UnmodifiableView
Map<MantleFlag, MantleComponent> getRegisteredComponents();
boolean registerComponent(MantleComponent c);
@UnmodifiableView
KList<MantleFlag> getComponentFlags();
void hotload();
default int getHighest(int x, int z) {
@@ -231,8 +221,6 @@ public interface EngineMantle extends MatterGenerator {
return getMantle().getLoadedRegionCount();
}
MantleObjectComponent getObjectComponent();
default boolean isCovered(int x, int z) {
int s = getRealRadius();
@@ -1,61 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.engine.mantle;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@EqualsAndHashCode(exclude = "engineMantle")
@ToString(exclude = "engineMantle")
public abstract class IrisMantleComponent implements MantleComponent {
private final EngineMantle engineMantle;
private final MantleFlag flag;
private final int priority;
private volatile int radius = -1;
private final Object lock = new Object();
private boolean enabled = true;
protected abstract int computeRadius();
@Override
public void hotload() {
synchronized (lock) {
radius = -1;
}
}
@Override
public final int getRadius() {
int r = radius;
if(r != -1) return r;
synchronized (lock) {
if((r = radius) != -1) {
return r;
}
r = computeRadius();
if(r < 0) r = 0;
return radius = r;
}
}
}
@@ -18,17 +18,16 @@
package art.arcane.iris.engine.mantle;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.volmlib.util.documentation.ChunkCoordinates;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.iris.util.common.parallel.BurstExecutor;
import org.jetbrains.annotations.NotNull;
/**
* One pass of the mantle: {@link MatterGenerator} runs every component of a priority for each chunk within its
* radius plus every later pass's radius around a generating chunk, before the next priority starts. Iris's
* components are the pack's mantle stages, one each ({@code ModuleMantleComponent}).
*/
public interface MantleComponent extends Comparable<MantleComponent> {
int getPriority();
@@ -51,32 +50,6 @@ public interface MantleComponent extends Comparable<MantleComponent> {
return false;
}
default IrisData getData() {
return getEngineMantle().getData();
}
default IrisDimension getDimension() {
return getEngineMantle().getEngine().getDimension();
}
default IrisComplex getComplex() {
return getEngineMantle().getComplex();
}
default long seed() {
return getEngineMantle().getEngine().getSeedManager().getMantle();
}
default BurstExecutor burst() {
return getEngineMantle().getEngine().burst().burst();
}
EngineMantle getEngineMantle();
default Mantle<Matter> getMantle() {
return getEngineMantle().getMantle();
}
MantleFlag getFlag();
default MantleFlag[] getPrerequisiteFlags() {
@@ -87,10 +60,6 @@ public interface MantleComponent extends Comparable<MantleComponent> {
boolean isEnabled();
void setEnabled(boolean b);
void hotload();
@ChunkCoordinates
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);