mojira.dev
MC-295656

Incorrect logic of the `in_square` placement modifier

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

Comments 2

Sorry, but I think I accidentally duplicated my own bug report. I gave a possible fix for MC-248758

What is the ingame impact of this? is there any way to see the impact of this ingame?

Maity

(Unassigned)

Unconfirmed

(Unassigned)

1.21.4, 1.21.5 Pre-Release 3

Retrieved