Platform starts fit through a neutral bridge to iris:structure

Core asks the pack's VanillaStructures providers (ModuleVanillaStructures) for rules, starts, the shift of each
platform start and every module's reach, and runs the built-in fit through ModuleStructureFitting, which turns the
platform's chunk into the API's StructureFit. minecraft-common's NativeStructureFitBridge hands Bukkit and the modded
loaders' starts, processed template cells, template columns and legacy air to it; the platform helpers that held the
fit (surface fitter, terrain integrator, support and foundation builders, post processor) are gone. The host only
moves, clamps, wraps and places starts.

Ownership records keep their binary layout: the two texts that held the stilts and terrain JSON now hold the start's
memo, which the module writes in the same JSON, so records written before read the same. A recorded reference
envelope only grows when today's reaches are wider.

Tests: the fit's rules are tested in core against stated cells; the bridge and the fit end to end on the NMS harness;
the object place mode and native structure fit pins stay identical.
This commit is contained in:
piexel committed 2026-10-10 03:50:45 +02:00
1 parent 6a1d2564e2
commit 0b3556f09c
90 files changed
+5278 -7051

No files matched your search

@@ -23,23 +23,14 @@ import art.arcane.iris.engine.object.material.IrisMaterialPalette;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.IrisStyledRange;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
import art.arcane.iris.engine.object.structure.IrisStructureYBand;
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.iris.engine.object.value.IrisRange;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.collection.KMap;
import com.google.gson.Gson;
import com.volmit.block.BlockSpec;
import com.volmit.block.PaletteSpec;
import com.volmit.config.Range;
import com.volmit.noise.StyledRange;
import com.volmit.vanilla.JigsawOverrides;
import com.volmit.vanilla.StructureStilts;
import com.volmit.vanilla.StructureTerrain;
import com.volmit.vanilla.YBand;
import com.volmit.world.BlockPosition;
import java.util.Map;
@@ -57,12 +48,7 @@ public final class IrisValues {
Map.entry(com.volmit.noise.NoiseStyle.class.getName(), IrisGeneratorStyle.class),
Map.entry(StyledRange.class.getName(), IrisStyledRange.class),
Map.entry(Range.class.getName(), IrisRange.class),
Map.entry(BlockPosition.class.getName(), IrisPosition.class),
Map.entry(StructureTerrain.class.getName(), IrisStructureTerrain.class),
Map.entry(StructureStilts.class.getName(), IrisStructureStiltSettings.class),
Map.entry(YBand.class.getName(), IrisStructureYBand.class),
Map.entry(JigsawOverrides.class.getName(), IrisJigsawConfiguration.class));
private static final Gson SAME_JSON = new Gson();
Map.entry(BlockPosition.class.getName(), IrisPosition.class));
private IrisValues() {
}
@@ -94,30 +80,6 @@ public final class IrisValues {
return new IrisMaterialPalette().setStyle(generatorStyle(spec.style())).setZoom(spec.zoom()).setPalette(blocks);
}
/** {@code terrain} as the terrain fitting Iris's native structure placement applies. */
public static IrisStructureTerrain structureTerrain(StructureTerrain terrain) {
return sameJson(terrain, IrisStructureTerrain.class);
}
/** {@code stilts} as the foundation columns Iris's native structure placement builds. */
public static IrisStructureStiltSettings structureStilts(StructureStilts stilts) {
return sameJson(stilts, IrisStructureStiltSettings.class);
}
public static IrisStructureYBand yBand(YBand band) {
return sameJson(band, IrisStructureYBand.class);
}
/** {@code overrides} as the jigsaw configuration Iris applies to a platform jigsaw definition. */
public static IrisJigsawConfiguration jigsawConfiguration(JigsawOverrides overrides) {
return sameJson(overrides, IrisJigsawConfiguration.class);
}
/** The structure fit classes are plain values whose JSON is the API type's, so the conversion is a JSON round trip. */
private static <T> T sameJson(Object apiValue, Class<T> irisClass) {
return SAME_JSON.fromJson(SAME_JSON.toJsonTree(apiValue), irisClass);
}
/** Iris's maps hold no null values; a JSON null in a map reads as absent, as it does for Iris's own fields. */
private static KMap<String, Object> irisMap(Map<String, ?> values) {
KMap<String, Object> map = new KMap<>();
@@ -0,0 +1,430 @@
/*
* 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.engine.framework.Engine;
import art.arcane.iris.engine.framework.NativeStartMemo;
import art.arcane.iris.engine.framework.nativefit.NativeFitBlocks;
import art.arcane.iris.engine.framework.nativefit.NativeFitBox;
import art.arcane.iris.engine.framework.nativefit.NativeFitChunk;
import art.arcane.iris.engine.framework.nativefit.NativeFitPiece;
import art.arcane.iris.engine.framework.nativefit.NativeFitStart;
import art.arcane.iris.engine.framework.nativefit.NativeFitTrait;
import art.arcane.iris.engine.framework.nativefit.NativeStructureFitting;
import art.arcane.iris.engine.framework.nativefit.NativeTemplateCells;
import com.volmit.block.BlockFace;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedModules;
import com.volmit.host.ServiceRegistration;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
import com.volmit.service.VanillaStructures;
import com.volmit.vanilla.PieceKind;
import com.volmit.vanilla.StartMemo;
import com.volmit.vanilla.StructureFit;
import com.volmit.vanilla.StructureStep;
import com.volmit.vanilla.TemplateCells;
import com.volmit.vanilla.TerrainAdaptation;
import com.volmit.world.BlockAccess;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
/**
* The pack's {@link VanillaStructures} providers fitting the platform's starts into a chunk: the platform code's view
* of the chunk ({@link NativeFitChunk}) as an API {@link StructureFit}, its native block states translated to API
* states and back through caches, so a provider can read and write blocks without allocating per block.
*/
public final class ModuleStructureFitting implements NativeStructureFitting {
private static final Map<Object, BlockState> API_STATES = new ConcurrentHashMap<>();
private static final Map<BlockState, Object> NATIVE_STATES = new ConcurrentHashMap<>();
private static final Map<Object, Integer> NATIVE_TRAITS = new ConcurrentHashMap<>();
private static final Map<BlockTrait, NativeFitTrait> TRAITS = new EnumMap<>(Map.of(
BlockTrait.AIR, NativeFitTrait.AIR, BlockTrait.SOLID, NativeFitTrait.SOLID,
BlockTrait.FLUID, NativeFitTrait.FLUID, BlockTrait.LOG, NativeFitTrait.LOG,
BlockTrait.LEAVES, NativeFitTrait.LEAVES));
private final List<ServiceRegistration> providers;
private final Supplier<PackWorld> world;
private ModuleStructureFitting(List<ServiceRegistration> providers, Supplier<PackWorld> world) {
this.providers = providers;
this.world = world;
}
public static NativeStructureFitting of(Engine engine) {
return new ModuleStructureFitting(ModuleVanillaStructures.providersOf(engine.getData()),
() -> engine.getGeneration().world());
}
public static NativeStructureFitting builtInModules() {
List<DiscoveredModule> modules = IrisModuleHost.builtInModules().stream().map(DiscoveredModule::builtIn).toList();
LoadedModules loaded = LoadedModules.load(modules, Map.of(), List.of(IrisModuleHost.HOST_TYPE_PACKAGE), List.of());
return new ModuleStructureFitting(loaded.catalog().registrations(VanillaStructures.class), () -> {
throw new IllegalStateException("The built-in modules fit outside a world here: a start needs its memo"
+ " and a fit without palettes");
});
}
@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 -> {
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(),
provider -> {
provider.afterPieces(fit, placed);
return Boolean.TRUE;
});
}
};
}
@SuppressWarnings("unchecked")
private static <S> S nativeState(NativeFitBlocks<S> blocks, BlockState state) {
return (S) NATIVE_STATES.computeIfAbsent(state, key -> blocks.state(key.key()));
}
private static <S> BlockState apiState(NativeFitBlocks<S> blocks, S state) {
BlockState known = API_STATES.get(state);
if (known != null) {
return known;
}
return API_STATES.computeIfAbsent(state, key -> BlockState.parse(PlatformBlockStates.namespaced(blocks.key(state))));
}
private static <S> boolean nativeTrait(NativeFitBlocks<S> blocks, S state, NativeFitTrait trait) {
int traits = NATIVE_TRAITS.computeIfAbsent(state, key -> {
int bits = 0;
for (NativeFitTrait each : NativeFitTrait.values()) {
if (blocks.is(state, each)) {
bits |= 1 << each.ordinal();
}
}
return bits;
});
return (traits & 1 << trait.ordinal()) != 0;
}
/** One chunk's fit in the API's terms: heights above the dimension's bottom, maxima exclusive. */
private static final class ChunkFit<S> implements StructureFit {
private final NativeFitChunk<S> chunk;
private final Supplier<PackWorld> world;
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) {
this.chunk = chunk;
this.world = world;
this.blocks = new Access<>(chunk);
List<StructureFit.Start> converted = new ArrayList<>(chunk.starts().size());
for (NativeFitStart<S> start : chunk.starts()) {
converted.add(new HostStart<>(start, chunk));
}
this.starts = List.copyOf(converted);
}
String chunkName() {
return (chunk.area().minX() >> 4) + "," + (chunk.area().minZ() >> 4);
}
@Override
public PackWorld world() {
return world.get();
}
@Override
public long seed() {
return chunk.seed();
}
@Override
public BlockBox area() {
return apiBox(chunk.area(), chunk.bottomY());
}
@Override
public int bottomY() {
return chunk.bottomY();
}
@Override
public BlockAccess blocks() {
return blocks;
}
@Override
public int surfaceY(int x, int z) {
return chunk.surfaceY().applyAsInt(x, z) - chunk.bottomY();
}
@Override
public BlockState naturalBlock(int y) {
return apiState(chunk.blocks(), chunk.naturalBlock().apply(y + chunk.bottomY()));
}
@Override
public List<StructureFit.Start> starts() {
return starts;
}
@Override
public <T> T state(Class<T> type, Supplier<? extends T> create) {
Object known = states.get(type);
if (known == null) {
known = create.get();
states.put(type, known);
}
return type.cast(known);
}
}
/** The chunk column's blocks: the area's columns from the dimension's bottom to its top. */
private static final class Access<S> implements BlockAccess {
private final NativeFitBlocks<S> blocks;
private final int bottomY;
private final BlockBox bounds;
private final Map<BlockState, S> written = new IdentityHashMap<>();
private Access(NativeFitChunk<S> chunk) {
this.blocks = chunk.blocks();
this.bottomY = chunk.bottomY();
NativeFitBox area = chunk.area();
this.bounds = new BlockBox(area.minX(), 0, area.minZ(), area.maxX() + 1, chunk.topY() - bottomY, area.maxZ() + 1);
}
@Override
public BlockBox bounds() {
return bounds;
}
@Override
public BlockState get(int x, int y, int z) {
requireInside(x, y, z);
return apiState(blocks, blocks.get(x, y + bottomY, z));
}
@Override
public void column(int x, int z, int fromY, BlockState[] into) {
for (int index = 0; index < into.length; index++) {
into[index] = get(x, fromY + index, z);
}
}
@Override
public void set(int x, int y, int z, BlockState state) {
requireInside(x, y, z);
blocks.set(x, y + bottomY, z, nativeOf(state));
}
@Override
public boolean is(BlockState state, BlockTrait trait) {
NativeFitTrait nativeTrait = TRAITS.get(trait);
if (nativeTrait == null) {
throw new UnsupportedOperationException("A structure fit answers only " + TRAITS.keySet() + ", not " + trait);
}
return nativeTrait(blocks, nativeOf(state), nativeTrait);
}
@Override
public boolean inTag(BlockState state, ResourceId tag) {
return blocks.inTag(nativeOf(state), tag.toString());
}
@Override
public boolean sturdy(int x, int y, int z, BlockFace face) {
requireInside(x, y, z);
return blocks.sturdy(x, y + bottomY, z, face.name());
}
@Override
public BlockState fluid(BlockState state) {
return apiState(blocks, blocks.fluid(nativeOf(state)));
}
private S nativeOf(BlockState state) {
S known = written.get(state);
if (known == null) {
known = nativeState(blocks, state);
written.put(state, known);
}
return known;
}
private void requireInside(int x, int y, int z) {
if (!bounds.contains(x, y, z)) {
throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the fitted chunk " + bounds);
}
}
}
private static final class HostStart<S> implements StructureFit.Start {
private final NativeFitStart<S> start;
private final ResourceId structure;
private final List<StructureFit.Piece> pieces;
private HostStart(NativeFitStart<S> start, NativeFitChunk<S> chunk) {
this.start = start;
this.structure = ResourceId.parse(start.structureKey());
List<StructureFit.Piece> converted = new ArrayList<>(start.pieces().size());
for (NativeFitPiece<S> piece : start.pieces()) {
converted.add(new HostPiece<>(piece, chunk));
}
this.pieces = List.copyOf(converted);
}
@Override
public ResourceId structure() {
return structure;
}
@Override
public int chunkX() {
return start.chunkX();
}
@Override
public int chunkZ() {
return start.chunkZ();
}
@Override
public StructureStep step() {
return StructureStep.valueOf(start.step());
}
@Override
public TerrainAdaptation adaptation() {
return TerrainAdaptation.valueOf(start.adaptation());
}
@Override
public Optional<StartMemo> memo() {
NativeStartMemo memo = start.memo();
return memo == null ? Optional.empty() : Optional.of(new StartMemo(memo.terrain(), memo.foundation()));
}
@Override
public List<StructureFit.Piece> pieces() {
return pieces;
}
@Override
public Object key() {
return start.key();
}
}
private static final class HostPiece<S> implements StructureFit.Piece {
private final NativeFitPiece<S> piece;
private final NativeFitChunk<S> chunk;
private final int bottomY;
private HostPiece(NativeFitPiece<S> piece, NativeFitChunk<S> chunk) {
this.piece = piece;
this.chunk = chunk;
this.bottomY = chunk.bottomY();
}
@Override
public BlockBox box() {
return apiBox(piece.box(), bottomY);
}
@Override
public PieceKind kind() {
return PieceKind.valueOf(piece.kind());
}
@Override
public int groundLevelDelta() {
return piece.groundLevelDelta();
}
@Override
public List<BlockPosition> junctions() {
List<BlockPosition> junctions = new ArrayList<>(piece.junctions().size());
for (int[] junction : piece.junctions()) {
junctions.add(new BlockPosition(junction[0], junction[1] - bottomY, junction[2]));
}
return junctions;
}
@Override
public TemplateCells cells(BlockBox region) {
NativeTemplateCells<S> cells = piece.cells(nativeBox(region, bottomY));
if (!cells.resolved()) {
return TemplateCells.UNRESOLVED;
}
int size = cells.states().length;
int[] ys = new int[size];
BlockState[] states = new BlockState[size];
for (int cell = 0; cell < size; cell++) {
ys[cell] = cells.ys()[cell] - bottomY;
S state = cells.states()[cell];
states[cell] = state == null ? null : apiState(chunk.blocks(), state);
}
return TemplateCells.of(cells.xs(), ys, cells.zs(), states, cells.readBlocks());
}
@Override
public void columns(StructureFit.ColumnVisitor visitor) {
piece.columns((x, z, minY, maxY) -> visitor.column(x, z, minY - bottomY, maxY - bottomY));
}
@Override
public List<BlockPosition> legacyAir(BlockBox clip) {
List<int[]> air = piece.legacyAir(nativeBox(clip, bottomY));
List<BlockPosition> positions = new ArrayList<>(air.size());
for (int[] position : air) {
positions.add(new BlockPosition(position[0], position[1] - bottomY, position[2]));
}
return positions;
}
}
private static BlockBox apiBox(NativeFitBox box, int bottomY) {
return new BlockBox(box.minX(), box.minY() - bottomY, box.minZ(), box.maxX() + 1, box.maxY() + 1 - bottomY,
box.maxZ() + 1);
}
private static NativeFitBox nativeBox(BlockBox box, int bottomY) {
return new NativeFitBox(box.minX(), box.minY() + bottomY, box.minZ(), box.maxX() - 1, box.maxY() - 1 + bottomY,
box.maxZ() - 1);
}
}
@@ -20,17 +20,24 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.NativeJigsawOverrides;
import art.arcane.iris.engine.framework.NativeStartMemo;
import art.arcane.iris.engine.framework.NativeStartPlacement;
import art.arcane.iris.engine.framework.NativeStructureReach;
import art.arcane.iris.engine.framework.NativeStructureStartPlan;
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import com.volmit.config.PackSettings;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.VanillaStructureHookRegistration;
import com.volmit.host.ServiceRegistration;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.vanilla.VanillaStructureAdjustment;
import com.volmit.service.VanillaStructures;
import com.volmit.vanilla.JigsawOverrides;
import com.volmit.vanilla.PlatformStart;
import com.volmit.vanilla.StartMemo;
import com.volmit.vanilla.StartReach;
import com.volmit.vanilla.VanillaStructureContext;
import com.volmit.vanilla.VanillaStructureHook;
import com.volmit.vanilla.VanillaStructureRule;
import com.volmit.vanilla.VanillaStructureSetup;
import com.volmit.vanilla.VanillaStructureStart;
@@ -43,31 +50,31 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
/**
* What the pack's modules want for the platform's own structures, asked through their vanilla structure hooks in module
* id order: per structure in one engine's world the combined rule ({@link VanillaStructureRule#and}) and adjustment
* ({@link VanillaStructureAdjustment#then}), kept per engine and pack snapshot so a hotload or a reload of the pack's
* resources asks again; per chunk the starts modules place, converted to the host's plans; and per dimension, before a
* world exists, the combined setup ({@link VanillaStructureSetup#and}). The platform side applies the results on Bukkit
* and the modded platforms alike.
* What the pack's modules want for the platform's own structures, asked through their {@link VanillaStructures}
* providers in module id order: per structure in one engine's world the combined rule ({@link VanillaStructureRule#and}),
* kept per engine and pack snapshot so a hotload or a reload of the pack's resources asks again; per chunk the starts
* modules place, converted to the host's plans; per platform start the shift every module gives it and every module's
* reach; and per dimension, before a world exists, the combined setup ({@link VanillaStructureSetup#and}). The platform
* side applies the results on Bukkit and the modded platforms alike.
*/
public final class ModuleVanillaStructures {
private static final Map<Engine, ModuleVanillaStructures> WORLDS = Collections.synchronizedMap(new WeakHashMap<>());
private static final int START_TERRAIN_REACH_BLOCKS = 8;
private final PackResources snapshot;
private final List<VanillaStructureHookRegistration> hooks;
private final List<ServiceRegistration> providers;
private final VanillaStructureContext world;
private final Map<String, VanillaStructureRule> rules = new ConcurrentHashMap<>();
private final Map<AdjustedStructure, VanillaStructureAdjustment> adjustments = new ConcurrentHashMap<>();
private ModuleVanillaStructures(Engine engine, PackResources snapshot) {
this.snapshot = snapshot;
this.hooks = hooksOf(engine.getData());
this.providers = providersOf(engine.getData());
this.world = new World(snapshot, new IrisPackSettings(engine));
}
@@ -76,45 +83,72 @@ public final class ModuleVanillaStructures {
return of(engine).rule(structureKey);
}
/**
* The combined adjustment of the pack's modules for the platform's own starts of {@code structureKey} in
* {@code engine}'s world; {@code underground} is whether the platform generates it in an underground step.
*/
public static VanillaStructureAdjustment adjustmentFor(Engine engine, String structureKey, boolean underground) {
return of(engine).adjustment(structureKey, underground);
}
/**
* The starts the pack's modules place in chunk {@code chunkX, chunkZ} of {@code engine}'s world, in module id order,
* as the host's plans: world heights, Iris's fit and jigsaw classes.
* 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));
List<NativeStructureStartPlan> plans = new ArrayList<>();
for (VanillaStructureHookRegistration registration : hooksOf(engine.getData())) {
for (ServiceRegistration registration : providersOf(engine.getData())) {
for (VanillaStructureStart start : ask(registration, "placing starts in chunk " + chunkX + "," + chunkZ,
hook -> hook.starts(chunkX, chunkZ, context))) {
provider -> provider.starts(chunkX, chunkZ, context))) {
plans.add(plan(registration.module(), start, chunkX, chunkZ, engine.getMinHeight()));
}
}
return List.copyOf(plans);
}
/** The shifts every module of the pack gives the platform's own start {@code start}, added up. */
public static int shiftOf(Engine engine, NativeStartPlacement start) {
ModuleVanillaStructures structures = of(engine);
Optional<ResourceId> structure = structureId(start.structureKey());
if (structure.isEmpty()) {
return 0;
}
PlatformStart platformStart = new HostPlatformStart(structure.get(), start);
int shift = 0;
for (ServiceRegistration registration : structures.providers) {
shift = Math.addExact(shift, ask(registration, "moving vanilla structure " + structure.get(),
provider -> provider.shift(platformStart, structures.world)));
}
return shift;
}
/** Every module's reach around a start of {@code structureKey}, placed by a module with {@code memo} or by the platform. */
public static List<NativeStructureReach> reachesOf(Engine engine, String structureKey, boolean underground,
NativeStartMemo memo) {
ModuleVanillaStructures structures = of(engine);
Optional<ResourceId> structure = structureId(structureKey);
if (structure.isEmpty()) {
return List.of(NativeStructureReach.PLATFORM);
}
Optional<StartMemo> startMemo = Optional.ofNullable(memo).map(note -> new StartMemo(note.terrain(), note.foundation()));
List<NativeStructureReach> reaches = new ArrayList<>(structures.providers.size());
for (ServiceRegistration registration : structures.providers) {
StartReach reach = ask(registration, "reaching around vanilla structure " + structure.get(),
provider -> provider.reach(structure.get(), underground, startMemo, structures.world));
reaches.add(new NativeStructureReach(reach.platform(), reach.blocks()));
}
return reaches.isEmpty() ? List.of(NativeStructureReach.PLATFORM) : List.copyOf(reaches);
}
/** The combined setup of the pack's modules for {@code dimension} of the pack {@code data} serves, before any world exists. */
public static VanillaStructureSetup setupFor(IrisData data, IrisDimension dimension) {
VanillaStructureContext context = new World(data.getPackResources(), new DimensionSettings(data, dimension));
VanillaStructureSetup combined = VanillaStructureSetup.UNCHANGED;
for (VanillaStructureHookRegistration registration : hooksOf(data)) {
for (ServiceRegistration registration : providersOf(data)) {
combined = combined.and(ask(registration, "setting up the vanilla structures of dimension " + dimension.getLoadKey(),
hook -> hook.setup(context)));
provider -> provider.setup(context)));
}
return combined;
}
private static List<VanillaStructureHookRegistration> hooksOf(IrisData data) {
return data.getModules().pack().catalog().vanillaStructureHooks();
/** The pack's {@link VanillaStructures} providers with the modules that registered them, in module id order. */
static List<ServiceRegistration> providersOf(IrisData data) {
return data.getModules().pack().catalog().registrations(VanillaStructures.class);
}
private static ModuleVanillaStructures of(Engine engine) {
@@ -132,10 +166,6 @@ public final class ModuleVanillaStructures {
return rules.computeIfAbsent(structureKey, this::askRules);
}
private VanillaStructureAdjustment adjustment(String structureKey, boolean underground) {
return adjustments.computeIfAbsent(new AdjustedStructure(structureKey, underground), this::askAdjustments);
}
/** A key that is no resource id names no structure a module could decide over. */
private VanillaStructureRule askRules(String structureKey) {
Optional<ResourceId> structure = structureId(structureKey);
@@ -143,28 +173,14 @@ public final class ModuleVanillaStructures {
return VanillaStructureRule.GENERATE;
}
VanillaStructureRule combined = VanillaStructureRule.GENERATE;
for (VanillaStructureHookRegistration registration : hooks) {
for (ServiceRegistration registration : providers) {
VanillaStructureRule rule = ask(registration, "deciding over vanilla structure " + structure.get(),
hook -> hook.rule(structure.get(), world));
provider -> provider.rule(structure.get(), world));
combined = combined.and(rule);
}
return combined;
}
private VanillaStructureAdjustment askAdjustments(AdjustedStructure adjusted) {
Optional<ResourceId> structure = structureId(adjusted.key());
if (structure.isEmpty()) {
return VanillaStructureAdjustment.NONE;
}
VanillaStructureAdjustment combined = VanillaStructureAdjustment.NONE;
for (VanillaStructureHookRegistration registration : hooks) {
VanillaStructureAdjustment adjustment = ask(registration, "adjusting vanilla structure " + structure.get(),
hook -> hook.adjustment(structure.get(), adjusted.underground(), world));
combined = combined.then(adjustment);
}
return combined;
}
private static Optional<ResourceId> structureId(String structureKey) {
try {
return Optional.of(ResourceId.parse(structureKey));
@@ -173,12 +189,11 @@ public final class ModuleVanillaStructures {
}
}
/** One hook's answer to {@code question}; a hook that throws or answers nothing fails naming its module. */
private static <T> T ask(VanillaStructureHookRegistration registration, String question,
Function<VanillaStructureHook, T> answer) {
/** One provider's answer to {@code question}; a provider that throws or answers nothing fails naming its module. */
static <T> T ask(ServiceRegistration registration, String question, Function<VanillaStructures, T> answer) {
T result;
try {
result = answer.apply(registration.hook());
result = answer.apply((VanillaStructures) registration.provider());
} catch (RuntimeException failure) {
throw new IllegalStateException("Module " + registration.module() + " failed " + question + ": " + failure, failure);
}
@@ -202,18 +217,72 @@ public final class ModuleVanillaStructures {
start.isUnderground(),
start.replacesPlatformStart(),
start.identity(),
start.jigsaw().map(IrisValues::jigsawConfiguration).orElse(null),
start.fit().stilts().map(IrisValues::structureStilts).orElse(null),
start.fit().terrain().map(IrisValues::structureTerrain).orElseGet(IrisStructureTerrain::new));
start.jigsaw().map(ModuleVanillaStructures::jigsaw).orElse(null),
start.memo().map(memo -> new NativeStartMemo(memo.terrain(), memo.foundation())).orElse(null));
}
/** The world the hooks decide for: the engine's pack snapshot and the settings its dimension reaches. */
private static NativeJigsawOverrides jigsaw(JigsawOverrides overrides) {
return new NativeJigsawOverrides(
overrides.startPool(),
overrides.startJigsawName(),
boxed(overrides.maxDepth()),
boxed(overrides.maxDistanceHorizontal()),
boxed(overrides.maxDistanceVertical()),
overrides.useExpansionHack().orElse(null),
overrides.projectStartToHeightmap().name(),
boxed(overrides.dimensionPaddingBottom()),
boxed(overrides.dimensionPaddingTop()),
overrides.liquidSettings().name());
}
private static Integer boxed(OptionalInt value) {
return value.isPresent() ? value.getAsInt() : null;
}
/** The world the providers decide for: the engine's pack snapshot and the settings its dimension reaches. */
private record World(PackResources resources, PackSettings settings) implements VanillaStructureContext {
}
private record StartContext(PackWorld world, TerrainSampler terrain) implements VanillaStructureStartContext {
}
private record AdjustedStructure(String key, boolean underground) {
/** A platform start in the API's heights: above the dimension's bottom, maxima exclusive. */
private record HostPlatformStart(ResourceId structure, NativeStartPlacement start) implements PlatformStart {
@Override
public int chunkX() {
return start.chunkX();
}
@Override
public int chunkZ() {
return start.chunkZ();
}
@Override
public BlockBox bounds() {
int bottom = start.bottomY();
return new BlockBox(start.minX(), start.minY() - bottom, start.minZ(),
start.maxX() + 1, start.maxY() + 1 - bottom, start.maxZ() + 1);
}
@Override
public boolean underground() {
return start.underground();
}
@Override
public boolean aligned() {
return start.aligned();
}
@Override
public int bottomY() {
return start.bottomY();
}
@Override
public int surfaceY(int x, int z) {
return start.surfaceY().applyAsInt(x, z) - start.bottomY();
}
}
}
@@ -0,0 +1,21 @@
package art.arcane.iris.engine.framework;
/**
* Changes a module makes to a jigsaw structure's registered definition before the platform assembles a start of it,
* as the platform code applies them: a blank text or a null value keeps the definition's own. The heightmap and liquid
* settings are the names of the API's {@code JigsawOverrides} constants ({@code SOURCE} keeps the definition's).
*/
public record NativeJigsawOverrides(
String startPool,
String startJigsawName,
Integer maxDepth,
Integer maxDistanceHorizontal,
Integer maxDistanceVertical,
Boolean useExpansionHack,
String projectStartToHeightmap,
Integer dimensionPaddingBottom,
Integer dimensionPaddingTop,
String liquidSettings
) {
public static final String SOURCE = "SOURCE";
}
@@ -0,0 +1,14 @@
package art.arcane.iris.engine.framework;
import java.util.Objects;
/**
* What a module noted about a start it placed, as the host keeps it: two texts in the module's own format, one about
* the start's terrain and one about its foundation. The host never reads them.
*/
public record NativeStartMemo(String terrain, String foundation) {
public NativeStartMemo {
Objects.requireNonNull(terrain, "terrain");
Objects.requireNonNull(foundation, "foundation");
}
}
@@ -0,0 +1,31 @@
package art.arcane.iris.engine.framework;
import java.util.Objects;
import java.util.function.IntBinaryOperator;
/**
* One of the platform's own starts before the host publishes it, as the platform code sees it: its structure, start
* chunk, the box around its pieces in world heights (every bound inclusive), whether the platform generates it in an
* underground step, whether the host aligns it itself (an ocean monument to the sea level, a desert or jungle temple
* to the terrain), the world's bottom height and the terrain's surface height per column in world heights.
*/
public record NativeStartPlacement(
String structureKey,
int chunkX,
int chunkZ,
int minX,
int minY,
int minZ,
int maxX,
int maxY,
int maxZ,
boolean underground,
boolean aligned,
int bottomY,
IntBinaryOperator surfaceY
) {
public NativeStartPlacement {
Objects.requireNonNull(structureKey, "structureKey");
Objects.requireNonNull(surfaceY, "surfaceY");
}
}
@@ -18,44 +18,32 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.core.modules.IrisValues;
import art.arcane.iris.core.modules.ModuleVanillaStructures;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
import com.volmit.vanilla.VanillaStructureAdjustment;
import com.volmit.vanilla.VanillaStructureFit;
import com.volmit.vanilla.VanillaStructureRule;
import java.util.Objects;
/**
* Whether the platform generates one of its own structures in an engine's world, and how its starts are adjusted, the
* same on every platform: the rule and adjustment the pack's modules give the structure through their vanilla
* structure hooks ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a module
* places itself is reported as replaced, so find, goto and verify locate the module's placement.
* Whether the platform generates one of its own structures in an engine's world, the same on every platform: the rule
* the pack's modules give the structure through their {@code VanillaStructures} providers
* ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a module places itself is
* reported as replaced, so find, goto and verify locate the module's placement.
*/
public final class NativeStructureGenerationPolicy {
private NativeStructureGenerationPolicy() {
}
public static IrisNativeStructureDecision resolve(Engine engine, String structureKey,
boolean undergroundStep) {
public static NativeStructureGenerationStatus resolve(Engine engine, String structureKey) {
Engine activeEngine = Objects.requireNonNull(engine, "Native structure policy requires an engine");
if (structureKey == null || structureKey.isBlank()) {
return decision(NativeStructureGenerationStatus.INVALID_REGISTRY_KEY, VanillaStructureAdjustment.NONE);
return NativeStructureGenerationStatus.INVALID_REGISTRY_KEY;
}
VanillaStructureRule rule = ModuleVanillaStructures.ruleFor(activeEngine, structureKey);
VanillaStructureAdjustment adjustment = ModuleVanillaStructures.adjustmentFor(activeEngine, structureKey, undergroundStep);
return decision(status(rule), adjustment);
return status(ModuleVanillaStructures.ruleFor(activeEngine, structureKey));
}
private static IrisNativeStructureDecision decision(NativeStructureGenerationStatus status,
VanillaStructureAdjustment adjustment) {
VanillaStructureFit fit = adjustment.fit();
return new IrisNativeStructureDecision(status, adjustment.yShift(),
adjustment.yBand().map(IrisValues::yBand).orElse(null), adjustment.keepsSourceY(),
fit.stilts().map(IrisValues::structureStilts).orElse(null),
fit.terrain().map(IrisValues::structureTerrain).orElse(null));
/** Whether the platform generates {@code structureKey} itself in {@code engine}'s world. */
public static boolean generates(Engine engine, String structureKey) {
return resolve(engine, structureKey) == NativeStructureGenerationStatus.GENERATE_NATIVE;
}
private static NativeStructureGenerationStatus status(VanillaStructureRule rule) {
@@ -0,0 +1,26 @@
/*
* 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.engine.framework;
public enum NativeStructureGenerationStatus {
GENERATE_NATIVE,
DISABLED_BY_PACK,
REPLACED_BY_IRIS,
INVALID_REGISTRY_KEY
}
@@ -0,0 +1,29 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.core.modules.ModuleVanillaStructures;
import java.util.List;
/**
* Where the platform's own starts sit and how far around their pieces the pack's modules change the terrain, as the
* platform code asks before it publishes a start: the shift every module gives a start, added up, and every module's
* reach.
*/
public final class NativeStructureLayouts {
private NativeStructureLayouts() {
}
/** How far the pack's modules move {@code start} up (negative: down), before the platform keeps it inside the world. */
public static int shift(Engine engine, NativeStartPlacement start) {
return ModuleVanillaStructures.shiftOf(engine, start);
}
/**
* How far every module of the pack changes the terrain around a start of {@code structureKey}: a start a module
* placed, with the {@code memo} it gave it, or one of the platform's own (null memo).
*/
public static List<NativeStructureReach> reaches(Engine engine, String structureKey, boolean underground,
NativeStartMemo memo) {
return ModuleVanillaStructures.reachesOf(engine, structureKey, underground, memo);
}
}
@@ -1,10 +1,5 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
import com.google.gson.Gson;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -32,7 +27,7 @@ public record NativeStructureOwnershipRecord(
int referenceMinChunkZ,
int referenceMaxChunkZ,
String contentFingerprint,
DecisionSnapshot decision
MemoSnapshot memo
) {
public static final int CURRENT_SCHEMA = 2;
public static final int MAX_REFERENCE_DISTANCE_CHUNKS = 8;
@@ -69,7 +64,7 @@ public record NativeStructureOwnershipRecord(
if (!contentFingerprint.matches("[0-9a-f]{64}")) {
throw new IllegalArgumentException("Native structure content fingerprint must be SHA-256 hex");
}
decision = Objects.requireNonNull(decision, "Native structure decision snapshot must not be null");
memo = Objects.requireNonNull(memo, "Native structure memo snapshot must not be null");
}
public static NativeStructureOwnershipRecord create(String structureKey,
@@ -89,7 +84,7 @@ public record NativeStructureOwnershipRecord(
int referenceMinChunkZ,
int referenceMaxChunkZ,
String contentFingerprint,
IrisNativeStructureDecision decision) {
NativeStartMemo memo) {
return new NativeStructureOwnershipRecord(
CURRENT_SCHEMA,
structureKey,
@@ -109,7 +104,7 @@ public record NativeStructureOwnershipRecord(
referenceMinChunkZ,
referenceMaxChunkZ,
contentFingerprint,
DecisionSnapshot.capture(decision)
MemoSnapshot.of(memo)
);
}
@@ -140,7 +135,7 @@ public record NativeStructureOwnershipRecord(
referenceMinChunkZ,
referenceMaxChunkZ,
contentFingerprint,
decision
memo
);
}
@@ -148,8 +143,9 @@ public record NativeStructureOwnershipRecord(
return new OwnershipKey(structureKey, originChunkX, originChunkZ);
}
public IrisNativeStructureDecision restoredDecision() {
return decision.restore();
/** The memo the module gave the start when it placed it; null when it gave none. */
public NativeStartMemo restoredMemo() {
return memo.restore();
}
void write(DataOutputStream output) throws IOException {
@@ -171,7 +167,7 @@ public record NativeStructureOwnershipRecord(
output.writeInt(referenceMinChunkZ);
output.writeInt(referenceMaxChunkZ);
writeString(output, contentFingerprint, MAX_FINGERPRINT_BYTES, "content fingerprint");
decision.write(output);
memo.write(output);
}
static NativeStructureOwnershipRecord read(DataInputStream input) throws IOException {
@@ -199,7 +195,7 @@ public record NativeStructureOwnershipRecord(
input.readInt(),
input.readInt(),
readString(input, MAX_FINGERPRINT_BYTES, "content fingerprint"),
DecisionSnapshot.read(input)
MemoSnapshot.read(input)
);
} catch (IllegalArgumentException exception) {
throw new IOException("Native structure ownership record is invalid", exception);
@@ -251,56 +247,39 @@ public record NativeStructureOwnershipRecord(
}
}
public record DecisionSnapshot(String stiltJson, String terrainJson) {
private static final Gson GSON = new Gson();
private static final int MAX_JSON_BYTES = 65_536;
/**
* The start's memo as the record stores it: the foundation text, then the terrain text. Records written before
* memos existed hold the JSON of the start's stilts and terrain fit in these two places, which is what the module
* writes as its memo, so they read the same. A start without a memo stores two empty texts.
*/
public record MemoSnapshot(String foundation, String terrain) {
private static final int MAX_MEMO_BYTES = 65_536;
private static final MemoSnapshot NONE = new MemoSnapshot("", "");
public DecisionSnapshot {
stiltJson = Objects.requireNonNull(stiltJson, "Native structure stilt snapshot must not be null");
terrainJson = Objects.requireNonNull(terrainJson, "Native structure terrain snapshot must not be null");
requireUtf8Limit(stiltJson, MAX_JSON_BYTES, "stilt snapshot");
requireUtf8Limit(terrainJson, MAX_JSON_BYTES, "terrain snapshot");
public MemoSnapshot {
foundation = Objects.requireNonNull(foundation, "Native structure foundation memo must not be null");
terrain = Objects.requireNonNull(terrain, "Native structure terrain memo must not be null");
requireUtf8Limit(foundation, MAX_MEMO_BYTES, "foundation memo");
requireUtf8Limit(terrain, MAX_MEMO_BYTES, "terrain memo");
}
public static DecisionSnapshot capture(IrisNativeStructureDecision decision) {
IrisNativeStructureDecision resolved = Objects.requireNonNull(
decision, "Native structure decision must not be null");
if (!resolved.generate()) {
throw new IllegalArgumentException("Only generated native structure decisions can be persisted");
}
return new DecisionSnapshot(
GSON.toJson(resolved.stilt()),
GSON.toJson(Objects.requireNonNullElseGet(
resolved.terrain(), IrisStructureTerrain::new))
);
public static MemoSnapshot of(NativeStartMemo memo) {
return memo == null ? NONE : new MemoSnapshot(memo.foundation(), memo.terrain());
}
public IrisNativeStructureDecision restore() {
IrisStructureStiltSettings stilt = "null".equals(stiltJson)
? null : GSON.fromJson(stiltJson, IrisStructureStiltSettings.class);
IrisStructureTerrain terrain = GSON.fromJson(terrainJson, IrisStructureTerrain.class);
if (terrain == null) {
throw new IllegalStateException("Persisted native structure terrain snapshot is null");
}
return new IrisNativeStructureDecision(
NativeStructureGenerationStatus.GENERATE_NATIVE,
0,
null,
false,
stilt,
terrain
);
public NativeStartMemo restore() {
return equals(NONE) ? null : new NativeStartMemo(terrain, foundation);
}
void write(DataOutputStream output) throws IOException {
writeString(output, stiltJson, MAX_JSON_BYTES, "stilt snapshot");
writeString(output, terrainJson, MAX_JSON_BYTES, "terrain snapshot");
writeString(output, foundation, MAX_MEMO_BYTES, "foundation memo");
writeString(output, terrain, MAX_MEMO_BYTES, "terrain memo");
}
static DecisionSnapshot read(DataInputStream input) throws IOException {
return new DecisionSnapshot(
readString(input, MAX_JSON_BYTES, "stilt snapshot"),
readString(input, MAX_JSON_BYTES, "terrain snapshot")
static MemoSnapshot read(DataInputStream input) throws IOException {
return new MemoSnapshot(
readString(input, MAX_MEMO_BYTES, "foundation memo"),
readString(input, MAX_MEMO_BYTES, "terrain memo")
);
}
}
@@ -0,0 +1,10 @@
package art.arcane.iris.engine.framework;
/**
* How far around a start's pieces a module changes the terrain: the area the platform's own terrain adaptation of the
* structure covers ({@link #platform()}), or a number of blocks around the pieces. The platform code hands the start
* to every chunk any module's reach covers.
*/
public record NativeStructureReach(boolean platform, int blocks) {
public static final NativeStructureReach PLATFORM = new NativeStructureReach(true, 0);
}
@@ -1,19 +1,13 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.engine.object.structure.IrisStructureStiltSettings;
import art.arcane.iris.engine.object.structure.IrisStructureTerrain;
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConfiguration;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
import java.util.Objects;
/**
* One start of a platform structure a module places, as the platform code builds it: the structure key, the start
* chunk, the world base Y (the structure's lowest block when underground, the planned surface otherwise), whether it
* takes the chunk from a platform start of the same structure, the identity of what placed it, and Iris's jigsaw,
* stilt and terrain classes for the module's jigsaw overrides and fit. {@code jigsaw} and {@code stilt} may be null;
* {@code terrain} is never null ({@code SOURCE} when the module states none).
* takes the chunk from a platform start of the same structure, the identity of what placed it, the changes to the
* jigsaw definition it is assembled with (null for none), and the memo the module gave it (null for none), which the
* ownership record keeps for every later chunk of the start.
*/
public record NativeStructureStartPlan(
String structureKey,
@@ -23,17 +17,10 @@ public record NativeStructureStartPlan(
boolean underground,
boolean replacesPlatformStart,
long placementIdentity,
IrisJigsawConfiguration jigsaw,
IrisStructureStiltSettings stilt,
IrisStructureTerrain terrain
NativeJigsawOverrides jigsaw,
NativeStartMemo memo
) {
public NativeStructureStartPlan {
Objects.requireNonNull(structureKey, "Native structure start plan requires a structure key");
Objects.requireNonNull(terrain, "Native structure start plan requires a terrain fit");
}
/** The platform decision this start is generated under: generated natively with the start's own fit. */
public IrisNativeStructureDecision decision() {
return new IrisNativeStructureDecision(NativeStructureGenerationStatus.GENERATE_NATIVE, 0, null, false, stilt, terrain);
}
}
@@ -0,0 +1,29 @@
package art.arcane.iris.engine.framework.nativefit;
/**
* The live blocks of the chunk the platform decorates, in the platform's own block states {@code S}, at world
* coordinates, and the questions a structure fit asks about them.
*/
public interface NativeFitBlocks<S> {
S get(int x, int y, int z);
/** Replaces the block without updating neighbours, the way the platform's decoration writes. */
void set(int x, int y, int z, S state);
/** The state's key with its properties, such as {@code minecraft:oak_stairs[facing=east,half=bottom]}. */
String key(S state);
/** The state {@link #key} names. */
S state(String key);
boolean is(S state, NativeFitTrait trait);
/** Whether the state is in the platform's block tag {@code tag}, such as {@code minecraft:logs}. */
boolean inTag(S state, String tag);
/** Whether the block at the position can carry a full block on its face named {@code face} ({@code UP} ...). */
boolean sturdy(int x, int y, int z, String face);
/** The block of the fluid the state holds; air when it holds none. */
S fluid(S state);
}
@@ -0,0 +1,5 @@
package art.arcane.iris.engine.framework.nativefit;
/** A box of world blocks as the platform measures it: world heights, every bound inclusive. */
public record NativeFitBox(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
}
@@ -0,0 +1,31 @@
package art.arcane.iris.engine.framework.nativefit;
import java.util.List;
import java.util.Objects;
import java.util.function.IntBinaryOperator;
import java.util.function.IntFunction;
/**
* One chunk the platform decorates with structure starts, as the platform code hands it to the modules' fit: its live
* blocks, the area it writes ({@code area}, world heights, inclusive), the world's bottom and top heights, the world
* seed, the terrain's surface height per column and the platform's natural block per height (both world heights), and
* the starts in the order the platform places them.
*/
public record NativeFitChunk<S>(
NativeFitBlocks<S> blocks,
NativeFitBox area,
int bottomY,
int topY,
long seed,
IntBinaryOperator surfaceY,
IntFunction<S> naturalBlock,
List<NativeFitStart<S>> starts
) {
public NativeFitChunk {
Objects.requireNonNull(blocks, "blocks");
Objects.requireNonNull(area, "area");
Objects.requireNonNull(surfaceY, "surfaceY");
Objects.requireNonNull(naturalBlock, "naturalBlock");
starts = List.copyOf(starts);
}
}
@@ -0,0 +1,29 @@
package art.arcane.iris.engine.framework.nativefit;
import java.util.List;
/** A piece of a start, as the platform code reads it, in world heights. */
public interface NativeFitPiece<S> {
NativeFitBox box();
/** {@code FIXED}, {@code RIGID} or {@code TERRAIN_MATCHING}, the names of the API's {@code PieceKind}. */
String kind();
int groundLevelDelta();
/** Each jigsaw junction's source X, ground height and Z. */
List<int[]> junctions();
NativeTemplateCells<S> cells(NativeFitBox region);
void columns(ColumnVisitor visitor);
/** The positions ({@code {x, y, z}}) of the legacy template air inside {@code clip}. */
List<int[]> legacyAir(NativeFitBox clip);
/** Receives one vertical span per column, both heights inclusive world heights. */
@FunctionalInterface
interface ColumnVisitor {
void column(int x, int z, int minY, int maxY);
}
}
@@ -0,0 +1,28 @@
package art.arcane.iris.engine.framework.nativefit;
import art.arcane.iris.engine.framework.NativeStartMemo;
import java.util.List;
/** A start the platform places in the chunk it decorates, as the platform code reads it. */
public interface NativeFitStart<S> {
String structureKey();
int chunkX();
int chunkZ();
/** The name of the platform's decoration step, as the API's {@code StructureStep} names it. */
String step();
/** The name of the structure definition's terrain adaptation, as the API's {@code TerrainAdaptation} names it. */
String adaptation();
/** The memo the module that placed the start gave it; null for the platform's own starts. */
NativeStartMemo memo();
List<NativeFitPiece<S>> pieces();
/** The same object for this start every chunk, for as long as the platform keeps the start. */
Object key();
}
@@ -0,0 +1,15 @@
package art.arcane.iris.engine.framework.nativefit;
/** The block questions a structure fit asks the platform about a state. */
public enum NativeFitTrait {
/** Air. */
AIR,
/** What the platform counts as solid. */
SOLID,
/** Holds a fluid: a source, a flowing fluid or a waterlogged block. */
FLUID,
/** A log, wood, stem or hyphae, by tag or by name. */
LOG,
/** Leaves, by tag or by name. */
LEAVES
}
@@ -0,0 +1,32 @@
package art.arcane.iris.engine.framework.nativefit;
import art.arcane.iris.core.modules.ModuleStructureFitting;
import art.arcane.iris.engine.framework.Engine;
/**
* The pack's modules fitting a chunk's structure starts into the terrain, around the platform placing their pieces:
* {@link #beforePieces} once before any piece of the chunk is placed, then {@link Session#afterPieces} after each
* start's pieces, in the order of the chunk's starts.
*/
public interface NativeStructureFitting {
<S> Session beforePieces(NativeFitChunk<S> chunk);
/** The modules of {@code engine}'s pack, fitting in its world. */
static NativeStructureFitting of(Engine engine) {
return ModuleStructureFitting.of(engine);
}
/**
* Iris's built-in modules outside any world, for starts whose fit their memo records and whose fit uses no palette;
* a fit that needs the world or the pack's resources fails. For tools and tests that drive the platform side alone.
*/
static NativeStructureFitting builtInModules() {
return ModuleStructureFitting.builtInModules();
}
/** One chunk's fit, between its starts' placements. */
interface Session {
/** Called after the platform placed the pieces of the chunk's start number {@code startIndex}. */
void afterPieces(int startIndex);
}
}
@@ -0,0 +1,9 @@
package art.arcane.iris.engine.framework.nativefit;
/**
* A piece's processed template blocks inside a region, at world positions: {@code states[i]} is the block at
* {@code (xs[i], ys[i], zs[i])}, null where the processors removed the template's block. {@code resolved} is false for
* a piece without a template. {@code readBlocks} counts the template blocks the platform read and processed.
*/
public record NativeTemplateCells<S>(boolean resolved, int[] xs, int[] ys, int[] zs, S[] states, int readBlocks) {
}
@@ -23,8 +23,7 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.IrisStructureLocator;
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
import art.arcane.iris.engine.framework.StructureReachability;
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
import art.arcane.iris.engine.framework.NativeStructureGenerationStatus;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformStructureHooks;
import art.arcane.iris.util.common.director.DirectorParameterHandler;
@@ -116,27 +115,27 @@ public class StructureHandler implements DirectorParameterHandler<String> {
private static boolean isEligibleRegisteredKey(Engine engine, String key, String normalizedKey,
Set<String> reachableKeys, boolean nativeGenerationEnabled) {
IrisNativeStructureDecision decision = NativeStructureGenerationPolicy.resolve(engine, key, false);
NativeStructureGenerationStatus status = NativeStructureGenerationPolicy.resolve(engine, key);
boolean nativePlacement = IrisStructureLocator.hasNativePlacement(engine, key);
boolean locatableNativePlacement = nativePlacement
&& IrisStructureLocator.hasLocatableNativePlacement(engine, key);
boolean locatableEditableReplacement = !nativePlacement
&& decision.status() == NativeStructureGenerationStatus.REPLACED_BY_IRIS
&& status == NativeStructureGenerationStatus.REPLACED_BY_IRIS
&& ModuleServices.canLocateStructure(engine, key);
return isEligibleRegisteredKey(
decision, nativePlacement, locatableNativePlacement, locatableEditableReplacement,
status, nativePlacement, locatableNativePlacement, locatableEditableReplacement,
reachableKeys.contains(normalizedKey), nativeGenerationEnabled);
}
static boolean isEligibleRegisteredKey(IrisNativeStructureDecision decision, boolean nativePlacement,
static boolean isEligibleRegisteredKey(NativeStructureGenerationStatus status, boolean nativePlacement,
boolean locatableNativePlacement,
boolean locatableEditableReplacement,
boolean reachable, boolean nativeGenerationEnabled) {
if (decision.status() == NativeStructureGenerationStatus.REPLACED_BY_IRIS) {
if (status == NativeStructureGenerationStatus.REPLACED_BY_IRIS) {
return locatableEditableReplacement
|| nativeGenerationEnabled && nativePlacement && locatableNativePlacement;
}
return nativeGenerationEnabled && decision.generate()
return nativeGenerationEnabled && status == NativeStructureGenerationStatus.GENERATE_NATIVE
&& (reachable || (nativePlacement && locatableNativePlacement));
}