The in_square
placement modifier offsets the position between 0 and 16:
public class InSquarePlacement extends PlacementModifier {
// ...
@Override
public Stream<BlockPos> getPositions(PlacementContext context, RandomSource random, BlockPos pos) {
int x = random.nextInt(16) + pos.getX();
int z = random.nextInt(16) + pos.getZ();
return Stream.of(new BlockPos(x, pos.getY(), z));
}
}
However, if you look at the random_offset
placement modifier, you'll find that it allows you to offset the position between -16 and 16:
public class RandomOffsetPlacement extends PlacementModifier {
public static final MapCodec<RandomOffsetPlacement> CODEC = RecordCodecBuilder.mapCodec(builder -> builder.group(
IntProvider.codec(-16, 16).fieldOf("xz_spread").forGetter(m -> m.xzSpread),
IntProvider.codec(-16, 16).fieldOf("y_spread").forGetter(m -> m.ySpread)
).apply(builder, RandomOffsetPlacement::new));
// ...
}
According to the Feature::place
code that calls WorldgenLevel::ensureCanWrite
, placing blocks is only possible within a 3x3 chunk radius, in other words, in_square
doesn't work correctly, which sometimes causes the “Detected setBlock in a far chunk” error logs
Sorry, but I think I accidentally duplicated my own bug report. I gave a possible fix for MC-248758