Move the built-in modules to the batch 4 API

- BlocksModule writes through PlacementAccess.set(x, y, z, state) when
  a block has no block entity; WrittenBlocks keeps positions and states.
- Hunk getters renamed to width(), height(), depth().
This commit is contained in:
piexel committed 2026-10-24 04:19:40 +02:00
1 parent 00e1fc1e27
commit 9b94eecae3
17 files changed
+93 -72

No files matched your search

@@ -18,25 +18,44 @@
package art.arcane.iris.builtin.blocks;
import com.volmit.placement.PlacedBlock;
import com.volmit.block.BlockState;
import com.volmit.world.BlockPosition;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
/** The object's own blocks a placement wrote, in world positions, in the order they were written. */
/**
* The object's own blocks a placement wrote, in world positions, in the order they were written. Positions and states
* are kept side by side, so recording a block allocates nothing beyond the position the placement already has.
*/
public final class WrittenBlocks {
private final List<PlacedBlock> blocks = new ArrayList<>();
private final List<BlockPosition> positions = new ArrayList<>();
private final List<BlockState> states = new ArrayList<>();
public void add(PlacedBlock block) {
blocks.add(block);
public void add(BlockPosition position, BlockState state) {
positions.add(position);
states.add(state);
}
public List<PlacedBlock> blocks() {
return Collections.unmodifiableList(blocks);
public List<BlockPosition> positions() {
return Collections.unmodifiableList(positions);
}
/** The written states, each at the index of its position in {@link #positions()}. */
public List<BlockState> states() {
return Collections.unmodifiableList(states);
}
/** Each written block's position and state, in the order they were written. */
public void forEach(BiConsumer<BlockPosition, BlockState> action) {
for (int index = 0; index < positions.size(); index++) {
action.accept(positions.get(index), states.get(index));
}
}
public boolean isEmpty() {
return blocks.isEmpty();
return positions.isEmpty();
}
}
@@ -92,9 +92,9 @@ public final class DecorantModule implements IrisModule, ModuleLifecycle {
int fluidHeight = scene.fluidHeight();
int worldHeight = scene.worldHeight();
for (int i = 0; i < output.getWidth(); i++) {
for (int i = 0; i < output.width(); i++) {
int realX = Math.round(x + i);
for (int j = 0; j < output.getDepth(); j++) {
for (int j = 0; j < output.depth(); j++) {
int realZ = Math.round(z + j);
DecoratedBiome biome = BiomeDecorators.biomeOf(settings, realX, realZ, terrain.surfaceKind(realX, realZ));
if (!decorators.hasDecorators(biome)) {
@@ -103,7 +103,7 @@ public final class DecorantModule implements IrisModule, ModuleLifecycle {
int height = terrain.surfaceHeight(realX, realZ);
if (height >= 0 && height < fluidHeight && scene.isSolid(output.get(i, height, j))
&& height + 1 < output.getHeight() && scene.isWater(output.get(i, height + 1, j))) {
&& height + 1 < output.height() && scene.isWater(output.get(i, height + 1, j))) {
seaSurfaceDecorator.decorate(i, j,
realX, Math.round(i + 1), Math.round(x + i - 1),
realZ, Math.round(z + j + 1), Math.round(z + j - 1),
@@ -120,7 +120,7 @@ public final class DecorantModule implements IrisModule, ModuleLifecycle {
biome, height, worldHeight);
}
if (height >= 0 && height < output.getHeight()) {
if (height >= 0 && height < output.height()) {
surfaceDecorator.decorate(i, j, realX, realZ, biome, height, worldHeight - height);
}
}
@@ -75,7 +75,7 @@ final class TerrainShaper {
/** Fills the 16 x 16 columns of the chunk, one slice along x at a time. */
void shape(ChunkStageContext context) {
Chunk chunk = new Chunk(context);
for (int sliceX = 0; sliceX < chunk.blocks.getWidth(); sliceX++) {
for (int sliceX = 0; sliceX < chunk.blocks.width(); sliceX++) {
shapeSliver(chunk, sliceX);
}
}
@@ -83,8 +83,8 @@ final class TerrainShaper {
/** One plane from the sky to bedrock, one block thick along x. */
private void shapeSliver(Chunk chunk, int xf) {
Hunk<BlockState> h = chunk.blocks;
int chunkHeight = h.getHeight();
int chunkDepth = h.getDepth();
int chunkHeight = h.height();
int chunkDepth = h.depth();
int realX = xf + chunk.originX;
for (int zf = 0; zf < chunkDepth; zf++) {
@@ -192,7 +192,7 @@ final class TerrainShaper {
/** The upper dimension's ground, filled in from the top of the column down to where it ends. */
private void fillUpperDimension(Chunk chunk, UpperDimension upper, int xf, int zf, int realX, int realZ) {
Hunk<BlockState> h = chunk.blocks;
int chunkHeight = h.getHeight();
int chunkHeight = h.height();
OptionalInt upperY = chunk.terrain.upperDimensionY(realX, realZ);
if (upperY.isEmpty()) {
return;
@@ -273,7 +273,7 @@ final class TerrainShaper {
this.settings = context.settings();
this.originX = context.originX();
this.originZ = context.originZ();
this.clampedFluidHeight = Math.min(blocks.getHeight(), terrain.fluidHeight());
this.clampedFluidHeight = Math.min(blocks.height(), terrain.fluidHeight());
int centreX = context.centreX();
int centreZ = context.centreZ();
this.bedrockEnabled = settings.at(BedrockSettings.class, centreX, centreZ).dimension().map(BedrockSettings::bedrock).orElse(true);
@@ -95,7 +95,7 @@ public final class DecorationScene {
/** The height of the chunk's volume. */
public int worldHeight() {
return blocks.getHeight();
return blocks.height();
}
public int fluidHeight() {
@@ -109,7 +109,7 @@ final class DecoratorCore {
int x, int z, int realX, int height, int realZ,
boolean underwater, boolean caveSkipFluid) {
Hunk<BlockState> data = scene.blocks();
if (height < 0 || height >= data.getHeight()) {
if (height < 0 || height >= data.height()) {
return;
}
@@ -154,7 +154,7 @@ final class DecoratorCore {
}
int targetY = height + 1;
if (bd != null && targetY < data.getHeight() && scene.isAir(data.get(x, targetY, z))) {
if (bd != null && targetY < data.height() && scene.isAir(data.get(x, targetY, z))) {
data.set(x, targetY, z, fixFacesForHunk(scene, bd, x, z, realX, targetY, realZ));
}
}
@@ -174,7 +174,7 @@ final class DecoratorCore {
static void placeStackUp(ResolvedDecorator decorator, DecorationScene scene, int x, int z, int realX, int realZ,
int height, int max, PlaceOpts opts) {
Hunk<BlockState> data = scene.blocks();
if (height < 0 || height >= data.getHeight()) {
if (height < 0 || height >= data.height()) {
return;
}
@@ -187,7 +187,7 @@ final class DecoratorCore {
if (stack == 1) {
int targetY = height + 1;
if (targetY >= data.getHeight()) {
if (targetY >= data.height()) {
return;
}
@@ -227,7 +227,7 @@ final class DecoratorCore {
break;
}
if (height + 1 + i >= data.getHeight()) {
if (height + 1 + i >= data.height()) {
break;
}
@@ -249,7 +249,7 @@ final class DecoratorCore {
static void placeStackDown(ResolvedDecorator decorator, DecorationScene scene, int x, int z, int realX, int realZ,
int height, int minHeight, int max, PlaceOpts opts) {
Hunk<BlockState> data = scene.blocks();
if (height < 0 || height >= data.getHeight()) {
if (height < 0 || height >= data.height()) {
return;
}
@@ -323,7 +323,7 @@ final class DecoratorCore {
return;
}
if (max > 1 && height + 1 < data.getHeight()) {
if (max > 1 && height + 1 < data.height()) {
data.set(xf, height + 1, zf, bd);
}
}
@@ -342,7 +342,7 @@ final class DecoratorCore {
int placed = 0;
for (int i = 0; i < stack; i++) {
int h = height + 1 + i;
if (h >= height + max || h >= data.getHeight()) {
if (h >= height + max || h >= data.height()) {
break;
}
double threshold = stack == 1 ? 0.0 : ((double) i) / (stack - 1);
@@ -393,7 +393,7 @@ final class DecoratorCore {
int xx = rX + face.dx();
int zz = rZ + face.dz();
if (xx < 0 || xx > CHUNK_LAST || zz < 0 || zz > CHUNK_LAST || yy < 0 || yy >= hunk.getHeight()) {
if (xx < 0 || xx > CHUNK_LAST || zz < 0 || zz > CHUNK_LAST || yy < 0 || yy >= hunk.height()) {
continue;
}
@@ -430,7 +430,7 @@ final class DecoratorCore {
private static boolean canPlaceTwoBlockPlant(DecorationScene scene, int x, int z,
int lowerY, int upperY, boolean caveSkipFluid) {
Hunk<BlockState> data = scene.blocks();
if (lowerY < 0 || upperY >= data.getHeight()) {
if (lowerY < 0 || upperY >= data.height()) {
return false;
}
@@ -56,7 +56,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
if (stack == 1) {
int targetY = height + 1;
if (targetY >= data.getHeight() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
if (targetY >= data.height() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
return;
}
@@ -60,7 +60,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
if (!decorator.isStacking()) {
int targetY = height + 1;
if (targetY >= data.getHeight()
if (targetY >= data.height()
|| !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
return;
}
@@ -80,7 +80,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
if (stack == 1) {
int targetY = height + 1;
if (targetY >= data.getHeight() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
if (targetY >= data.height() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
return;
}
@@ -94,7 +94,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
for (int i = 0; i < stack; i++) {
int h = height + i;
int targetY = h + 1;
if (targetY >= data.getHeight()
if (targetY >= data.height()
|| !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
break;
}
@@ -273,7 +273,7 @@ public class CaveApplying {
// Surface-break carving must not leave an ore cap suspended across the opening.
for (int columnIndex = 0; columnIndex < surfaceHeights.length; columnIndex++) {
int surfaceY = surfaceHeights[columnIndex];
if (surfaceY <= 0 || surfaceY >= output.getHeight()) {
if (surfaceY <= 0 || surfaceY >= output.height()) {
continue;
}
@@ -540,7 +540,7 @@ public class CaveApplying {
}
private void processZone(CaveZone zone, int rx, int rz, int xx, int zz, Map<String, ResourceId> customBiomeCache) {
int maxY = output.getHeight();
int maxY = output.height();
if (zone.ceiling + 1 < maxY && classes.isDecorant(output.get(rx, zone.ceiling + 1, rz))) {
output.set(rx, zone.ceiling + 1, rz, caveAir);
@@ -138,7 +138,7 @@ final class DepositPlacer {
this.mantle = context.mantle();
this.originX = context.originX();
this.originZ = context.originZ();
this.worldHeight = blocks.getHeight();
this.worldHeight = blocks.height();
this.minWorldY = terrain.minWorldY();
}
@@ -413,9 +413,9 @@ final class DepositPlacer {
}
private static boolean isAirAt(Hunk<BlockState> data, int x, int y, int z, Predicate<BlockState> isAir) {
if (x < 0 || x >= data.getWidth()
|| y < 0 || y >= data.getHeight()
|| z < 0 || z >= data.getDepth()) {
if (x < 0 || x >= data.width()
|| y < 0 || y >= data.height()
|| z < 0 || z >= data.depth()) {
return false;
}
return isAir.test(data.get(x, y, z));
@@ -448,7 +448,7 @@ final class FloatingIslands {
this.originX = context.originX();
this.originZ = context.originZ();
this.output = context.hunk(BlockState.class);
this.height = output.getHeight();
this.height = output.height();
this.blocks = context.world().resources().blocks();
this.settings = context.settings();
this.explosion = PaletteExplosion.of(settings, context.centreX(), context.centreZ());
@@ -57,7 +57,7 @@ public final class MatterModule implements IrisModule {
int originZ = context.originZ();
Hunk<BlockState> blocks = context.hunk(BlockState.class);
int[] limits = upperLimits(context.terrain(), originX, originZ);
BlockBox chunk = new BlockBox(originX, 0, originZ, originX + CHUNK_WIDTH, blocks.getHeight(), originZ + CHUNK_WIDTH);
BlockBox chunk = new BlockBox(originX, 0, originZ, originX + CHUNK_WIDTH, blocks.height(), originZ + CHUNK_WIDTH);
context.mantle().blocks().visit(chunk, (x, y, z, block) -> {
int localX = x - originX;
int localZ = z - originZ;
@@ -77,9 +77,9 @@ public final class PerfectionModule implements IrisModule {
/** {@code hidden} remembers per state instance what it is hidden as, itself for a block that is no ore. */
private static void hideOres(Hunk<BlockState> blocks, Map<BlockState, BlockState> hidden) {
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
for (int y = blocks.getHeight() - 1; y >= 0; y--) {
for (int x = 0; x < blocks.width(); x++) {
for (int z = 0; z < blocks.depth(); z++) {
for (int y = blocks.height() - 1; y >= 0; y--) {
BlockState block = blocks.get(x, y, z);
BlockState shown = hidden.computeIfAbsent(block, state -> ORE_BASES.getOrDefault(state.material(), state));
if (shown != block) {
@@ -98,8 +98,8 @@ public final class PerfectionModule implements IrisModule {
/** One pass over every column; whether it removed anything. */
boolean removeUnsupportedDecorants() {
boolean removed = false;
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
for (int x = 0; x < blocks.width(); x++) {
for (int z = 0; z < blocks.depth(); z++) {
for (int surface : surfaces(x, z)) {
removed |= removeIfUnsupported(x, surface, z);
}
@@ -149,7 +149,7 @@ public final class PerfectionModule implements IrisModule {
}
private int topSolid(int x, int z) {
for (int y = blocks.getHeight() - 1; y >= 0; y--) {
for (int y = blocks.height() - 1; y >= 0; y--) {
if (isSolid(blocks.get(x, y, z))) {
return y;
}
@@ -85,7 +85,7 @@ final class SurfaceSmoothing {
this.postRandom = new RNG(context.world().extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.POST));
this.originX = context.originX();
this.originZ = context.originZ();
this.planeWidth = blocks.getWidth() + 2;
this.planeWidth = blocks.width() + 2;
this.heights = heightPlane();
this.walls = enabled(context, PostProcessingWallsSettings.class, PostProcessingWallsSettings::enabled, PostProcessingWallsSettings.DEFAULT_ENABLED);
this.slabs = enabled(context, PostProcessingSlabsSettings.class, PostProcessingSlabsSettings::enabled, PostProcessingSlabsSettings.DEFAULT_ENABLED);
@@ -98,8 +98,8 @@ final class SurfaceSmoothing {
}
private void smoothColumns() {
for (int i = 0; i < blocks.getWidth(); i++) {
for (int j = 0; j < blocks.getDepth(); j++) {
for (int i = 0; i < blocks.width(); i++) {
for (int j = 0; j < blocks.depth(); j++) {
post(i, j);
}
}
@@ -127,8 +127,8 @@ final class SurfaceSmoothing {
}
private int[] heightPlane() {
int width = blocks.getWidth();
int depth = blocks.getDepth();
int width = blocks.width();
int depth = blocks.depth();
int[] plane = new int[planeWidth * (depth + 2)];
for (int j = -1; j <= depth; j++) {
boolean edge = j == -1 || j == depth;
@@ -346,7 +346,7 @@ final class SurfaceSmoothing {
private void set(int x, int y, int z, BlockState block) {
int localX = x - originX;
int localZ = z - originZ;
if (localX < 0 || localZ < 0 || localX >= blocks.getWidth() || localZ >= blocks.getDepth() || y < 0 || y >= blocks.getHeight()) {
if (localX < 0 || localZ < 0 || localX >= blocks.width() || localZ >= blocks.depth() || y < 0 || y >= blocks.height()) {
return;
}
blocks.set(localX, y, localZ, block);
@@ -358,7 +358,7 @@ final class SurfaceSmoothing {
* opposite edge.
*/
private BlockState get(int x, int y, int z) {
return blocks.get(clamp(x - originX, blocks.getWidth()), clamp(y, blocks.getHeight()), clamp(z - originZ, blocks.getDepth()));
return blocks.get(clamp(x - originX, blocks.width()), clamp(y, blocks.height()), clamp(z - originZ, blocks.depth()));
}
private static int clamp(int value, int size) {
@@ -40,7 +40,6 @@ import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.object.BlockEntityData;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStageContext;
import com.volmit.stage.PlacementStageContext;
import com.volmit.world.BlockPosition;
@@ -133,9 +132,10 @@ public final class BlocksModule implements IrisModule {
if (!shouldWrite(world, data, x, y, z, structurePiece)) {
return;
}
PlacedBlock placed = world.set(x, y, z, data, blockEntity);
placement.objectBlockWritten(placed.position());
written.add(placed);
world.set(x, y, z, data, blockEntity);
BlockPosition position = new BlockPosition(x, y, z);
placement.objectBlockWritten(position);
written.add(position, data);
}
/** The object block as Iris places it: debug air shows where smart boring bored, and leaves never decay where the placer prevents it. */
@@ -230,11 +230,11 @@ public final class BlocksModule implements IrisModule {
private static KList<BlockPosition> candidates(WrittenBlocks written, MarkerRule rule, ObjectPlacement placement) {
KList<BlockPosition> candidates = new KList<>();
for (PlacedBlock block : written.blocks()) {
if (rule.targets().stream().anyMatch(target -> marks(placement, rule, target, block.state()))) {
candidates.add(block.position());
written.forEach((position, state) -> {
if (rule.targets().stream().anyMatch(target -> marks(placement, rule, target, state))) {
candidates.add(position);
}
}
});
return candidates;
}
@@ -50,13 +50,16 @@ final class PlacementWorld {
return has(get(x, y, z), BlockTrait.SOLID);
}
PlacedBlock set(int x, int y, int z, BlockState state) {
return set(x, y, z, state, Optional.empty());
void set(int x, int y, int z, BlockState state) {
access.set(x, y, z, state);
}
PlacedBlock set(int x, int y, int z, BlockState state, Optional<BlockEntityData> blockEntity) {
PlacedBlock block = new PlacedBlock(new BlockPosition(x, y, z), state, blockEntity);
access.set(block);
return block;
/** A block entity needs the record; a plain block takes the write that allocates nothing. */
void set(int x, int y, int z, BlockState state, Optional<BlockEntityData> blockEntity) {
if (blockEntity.isEmpty()) {
access.set(x, y, z, state);
return;
}
access.set(new PlacedBlock(new BlockPosition(x, y, z), state, blockEntity));
}
}
@@ -26,7 +26,6 @@ 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.PlacementStageContext;
import com.volmit.world.BlockPosition;
@@ -76,8 +75,7 @@ public final class SnowModule implements IrisModule {
/** The highest written block of each column, columns in the order they were first written. */
private static Map<Long, BlockPosition> columnTops(WrittenBlocks written) {
Map<Long, BlockPosition> tops = new LinkedHashMap<>();
for (PlacedBlock block : written.blocks()) {
BlockPosition position = block.position();
for (BlockPosition position : written.positions()) {
tops.merge(columnKey(position), position, (current, next) -> next.y() > current.y() ? next : current);
}
return tops;
@@ -33,6 +33,7 @@ import com.volmit.ModuleSetup;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.stage.PlacementStageContext;
import com.volmit.world.BlockPosition;
/**
* Module {@code iris:vacuum}: bends the terrain around an object of a vacuum mode so it meets the object's
@@ -68,8 +69,8 @@ public final class VacuumModule implements IrisModule {
if (!prepared.mode().bendsTerrain() || written.isEmpty() || !prepared.terrain().hasWorld()) {
return;
}
int baseY = written.blocks().stream().mapToInt(block -> block.position().y()).min().orElseThrow();
int topY = written.blocks().stream().mapToInt(block -> block.position().y()).max().orElseThrow();
int baseY = written.positions().stream().mapToInt(BlockPosition::y).min().orElseThrow();
int topY = written.positions().stream().mapToInt(BlockPosition::y).max().orElseThrow();
new Bend(context, prepared).apply(baseY, topY);
}