Using Fabric for Minecraft modding (but it should not be relevant for this problem).
Trying to use Streams to filter a number of BlockPos Objects down to a list.
When iterating in the stream via .forEach and printing the .toString() to the console, I get the correct output, different BlockPos Objects which have different X,Y,Z fields.
As soon as I run toList(), toArray() or even build a Collection manually using the very same forEach on the stream (see below), I suddenly only get the first Object (or at least its X,Y,Z values) duplicated in my output. What gives? 😦
Set<BlockPos> natureBlocks = new HashSet<>();
BlockPos.stream(player.getBoundingBox().expand(BONUS_RADIUS))
.filter(pos -> isInSphericalRange(pos, player.getBlockPos(), BONUS_RADIUS))
.filter(pos -> isInTags(world, pos))
.forEach(natureBlocks::add);
natureBlocks.forEach(System.out::println); //duplicates
//Same deal with .toList(), .toArray()