Search in sources :

Example 1 with Volume

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);
}
Also used : Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) Registry(net.minecraft.core.Registry) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) ChunkBiomeContainerAccessor(org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor) Map(java.util.Map) ImposterProtoChunk(net.minecraft.world.level.chunk.ImposterProtoChunk) BlockEntityArchetype(org.spongepowered.api.block.entity.BlockEntityArchetype) BlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.BlockEntityAccessor) BuiltinRegistries(net.minecraft.data.BuiltinRegistries) ObjectArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ObjectArrayMutableBiomeBuffer) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Set(java.util.Set) UUID(java.util.UUID) LevelReader(net.minecraft.world.level.LevelReader) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Objects(java.util.Objects) CompoundTag(net.minecraft.nbt.CompoundTag) Stream(java.util.stream.Stream) BlockPos(net.minecraft.core.BlockPos) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) ChunkBiomeContainer(net.minecraft.world.level.chunk.ChunkBiomeContainer) Volume(org.spongepowered.api.world.volume.Volume) Level(net.minecraft.world.level.Level) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) IntStream(java.util.stream.IntStream) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) NonNull(org.checkerframework.checker.nullness.qual.NonNull) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) ProtoChunk(net.minecraft.world.level.chunk.ProtoChunk) BlockState(net.minecraft.world.level.block.state.BlockState) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) Biome(net.minecraft.world.level.biome.Biome) Region(org.spongepowered.api.world.volume.game.Region) Function(java.util.function.Function) Supplier(java.util.function.Supplier) BiConsumer(java.util.function.BiConsumer) ObjectArrayMutableBlockEntityBuffer(org.spongepowered.common.world.volume.buffer.blockentity.ObjectArrayMutableBlockEntityBuffer) WeakReference(java.lang.ref.WeakReference) Nullable(org.checkerframework.checker.nullness.qual.Nullable) LinkedHashSet(java.util.LinkedHashSet) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) Tuple(net.minecraft.util.Tuple) Entity(org.spongepowered.api.entity.Entity) ChunkPos(net.minecraft.world.level.ChunkPos) AbstractMap(java.util.AbstractMap) Vector3d(org.spongepowered.math.vector.Vector3d) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) VecHelper(org.spongepowered.common.util.VecHelper) ChunkStatus(net.minecraft.world.level.chunk.ChunkStatus) Mth(net.minecraft.util.Mth) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) ChunkPos(net.minecraft.world.level.ChunkPos) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 AbstractMap (java.util.AbstractMap)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 BiConsumer (java.util.function.BiConsumer)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 BlockPos (net.minecraft.core.BlockPos)1 Registry (net.minecraft.core.Registry)1 BuiltinRegistries (net.minecraft.data.BuiltinRegistries)1 CompoundTag (net.minecraft.nbt.CompoundTag)1