use of org.spongepowered.api.world.volume.Volume in project SpongeCommon by SpongePowered.
the class VolumeStreamUtils method generateStream.
public static <R extends Volume, API, MC, Section, KeyReference> VolumeStream<R, API> generateStream(final Vector3i min, final Vector3i max, final StreamOptions options, final R ref, final BiConsumer<KeyReference, MC> identityFunction, final BiFunction<R, ChunkPos, Section> chunkAccessor, final BiFunction<BlockPos, MC, KeyReference> entityToKey, final Function<Section, Stream<Map.Entry<BlockPos, MC>>> entityAccessor, final BiFunction<KeyReference, R, Tuple<BlockPos, MC>> filteredPositionEntityAccessor) {
final Supplier<R> worldSupplier = VolumeStreamUtils.createWeaklyReferencedSupplier(ref, "World");
final BlockPos chunkMin = new BlockPos(min.x() >> 4, 0, min.z() >> 4);
final BlockPos chunkMax = new BlockPos(max.x() >> 4, 0, max.z() >> 4);
// Generate the chunk position stream to iterate on, whether they're accessed immediately
// or lazily is up to the stream options.
final Stream<Section> sectionStream = IntStream.range(chunkMin.getX(), chunkMax.getX() + 1).mapToObj(x -> IntStream.range(chunkMin.getZ(), chunkMax.getZ() + 1).mapToObj(z -> new ChunkPos(x, z))).flatMap(Function.identity()).map(pos -> chunkAccessor.apply(ref, pos));
return VolumeStreamUtils.generateStreamInternal(options, identityFunction, entityToKey, entityAccessor, filteredPositionEntityAccessor, worldSupplier, sectionStream);
}
Aggregations