Files
Iris/src/test/java/com/volmit/example/placement/MossModule.java
T
piexel 7143908d4b Batch 2 of the API review: settings stacks, chunk helpers, pack context
- SettingsStack<F> replaces List<Entry<F>> wherever settings stack:
  entries in level order, values(), dimension(), level(Level) and
  mostSpecific().
- com.volmit.config.Level replaces FeatureAttachment.Target;
  FeatureAttachment folds into FeatureDescriptor.targets().
- FeatureSettings.declaredInChunk answers every entry any column of a
  chunk declares, each once.
- ChunkContext gives chunkX/chunkZ, centreX/centreZ and area().
- registerSettings takes several types at once.
- ModuleLifecycle.packLoaded(PackContext) carries resources, settings
  and the module's log.
- TerrainSampler.surfaceHeight gives the surface in whole blocks.
- Stage contexts drop worldSeed() and resources(); world() always
  answers. The scoped world is kept per world and module.
- Javadoc fixes; README, DESIGN and CONTRACTS updated.
2026-10-23 14:17:19 +02:00

52 lines
2.0 KiB
Java

package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleSetup;
import com.volmit.block.BlockState;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.PlacementStage;
import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageRef;
import com.volmit.world.BlockPosition;
import java.util.Optional;
/** Third-party module: turns the ground under the anchor into moss. It requires the core
* anchor height (typed output) and block completion, and runs after snow only if snow exists.
*/
public final class MossModule implements IrisModule {
public static final PlacementStage<Void> SPREAD = Stage.placement("example:moss/spread");
public static final BlockState MOSS = new BlockState("minecraft:moss_block");
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:moss", "Moss", "1.0.0");
}
@Override
public void setup(ModuleSetup setup) {
setup.stages().define(SPREAD)
.when(MossSettings.class)
.requires(AnchorModule.HEIGHT, BlocksModule.COMPLETE)
.softAfter(StageRef.of("iris:snow/finish"))
.run(MossModule::spread);
}
private static void spread(PlacementStageContext context) {
var moss = context.configured(MossSettings.class).mostSpecific().orElseThrow(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT).anchor();
var access = context.access();
int groundY = anchor.y() - 1;
for (int dx = -moss.radius(); dx <= moss.radius(); dx++) {
for (int dz = -moss.radius(); dz <= moss.radius(); dz++) {
int x = anchor.x() + dx;
int z = anchor.z() + dz;
if (!ExampleBlocks.isAir(access.get(x, groundY, z))) {
access.set(new PlacedBlock(new BlockPosition(x, groundY, z), MOSS, Optional.empty()));
}
}
}
}
}