Files
Iris/src/test/java/com/volmit/example/placement/StiltModule.java
T
piexel 1677f4414b Batch 1 of the API review: one setup entry point, per-pipeline definitions
- IrisModule.setup(ModuleSetup) replaces install(StageGraph) and
  register(FeatureRegistry); ModuleSetups.run is the host entry point.
- The conditional definition variants are gone: a stage body reads the
  settings it is conditioned on through ctx.configured(Type.class).
- Placement, block, chunk and mantle stages each get their own
  definition interface; chunk definitions offer neither reach nor
  writesMantle. MantleStage is no longer generic.
- softAfter/softBefore take stage constants as well as StageRefs.
- A producer that rejected the attempt may return null.
- PlacementRunner, ChunkRunner and MantleRunner all take StageTimings.
- ConfiguredSettings groups entries by the type that declares @Feature.
- README, DESIGN and CONTRACTS updated, with the edge choice table.
2026-10-23 13:00:07 +02:00

59 lines
2.4 KiB
Java

package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleSetup;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStage;
import com.volmit.stage.PlacementStage;
import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.Stage;
import com.volmit.world.BlockPosition;
import java.util.Optional;
/** Port of PlacementModuleStilt: collect the lowest layer per block, then fill down after writes. */
public final class StiltModule implements IrisModule {
public static final BlockStage<StiltBounds> BOUNDS = Stage.placementBlock("iris:stilt/bounds", StiltBounds.class);
public static final PlacementStage<Void> FILL = Stage.placement("iris:stilt/fill");
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:stilt", "Stilts", "test");
}
@Override
public void setup(ModuleSetup setup) {
var stages = setup.stages();
stages.define(BOUNDS)
.when(StiltSettings.class)
.requires(PrepareModule.ROTATE, AnchorModule.HEIGHT)
.accumulate(StiltBounds::new, (context, bounds) -> bounds.include(context.block()));
stages.define(FILL)
.when(StiltSettings.class)
.requires(BOUNDS, BlocksModule.COMPLETE)
.run(StiltModule::fill);
}
private static void fill(PlacementStageContext context) {
var stilt = context.configured(StiltSettings.class).getFirst().value(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT);
for (var block : context.output(BOUNDS).lowestLayer()) {
var bottom = anchor.worldPosition(context.request(), block.position());
fillColumnBelow(context, bottom, block, stilt.maxDepth());
}
}
private static void fillColumnBelow(PlacementStageContext context, BlockPosition bottom,
ObjectBlock source, int maxDepth) {
var access = context.access();
for (int depth = 1; depth <= maxDepth; depth++) {
int y = bottom.y() - depth;
if (y < access.bounds().minY() || !ExampleBlocks.isAir(access.get(bottom.x(), y, bottom.z()))) {
return;
}
access.set(new PlacedBlock(new BlockPosition(bottom.x(), y, bottom.z()), source.state(), Optional.empty()));
}
}
}