Files
Iris/src/test/java/com/volmit/example/chunk/GrassModule.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

46 lines
1.6 KiB
Java

package com.volmit.example.chunk;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleSetup;
import com.volmit.block.BlockState;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.Stage;
/** Third-party decoration: tops terrain columns using the terrain module's typed output. It runs where any
* column of the chunk has grass and reads the settings per column, so a biome border inside the chunk
* keeps grass on its own side.
*/
public final class GrassModule implements IrisModule {
public static final ChunkStage<Void> TOP = Stage.chunk("example:grass/top");
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:grass", "Grass", "1.0.0");
}
@Override
public void setup(ModuleSetup setup) {
setup.stages().define(TOP)
.when(GrassSettings.class)
.requires(TerrainModule.SURFACE)
.run(GrassModule::cover);
}
private static void cover(ChunkStageContext context) {
var heights = context.output(TerrainModule.SURFACE);
var blocks = context.hunk(BlockState.class);
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
var here = context.settings().at(GrassSettings.class, context.originX() + x, context.originZ() + z).mostSpecific();
int height = heights.at(x, z);
if (here.isEmpty() || height <= 0) {
continue;
}
blocks.set(x, height - 1, z, here.get().block());
}
}
}
}