Search in sources :

Example 6 with StreamOptions

use of org.spongepowered.api.world.volume.stream.StreamOptions in project SpongeCommon by SpongePowered.

the class AbstractMutableBlockEntityArchetypeBuffer method blockStateStream.

@Override
public VolumeStream<BlockEntityArchetypeVolume.Mutable, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(min, max, this.min(), this.max(), options);
    final ArrayMutableBlockBuffer buffer;
    if (options.carbonCopy()) {
        buffer = this.blockBuffer.copy();
    } else {
        buffer = this.blockBuffer;
    }
    final Stream<VolumeElement<BlockEntityArchetypeVolume.Mutable, BlockState>> stateStream = IntStream.range(min.x(), max.x() + 1).mapToObj(x -> IntStream.range(min.z(), max.z() + 1).mapToObj(z -> IntStream.range(min.y(), max.y() + 1).mapToObj(y -> VolumeElement.of((BlockEntityArchetypeVolume.Mutable) this, () -> buffer.block(x, y, z), new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
    return new SpongeVolumeStream<>(stateStream, () -> this);
}
Also used : IntStream(java.util.stream.IntStream) AbstractBlockBuffer(org.spongepowered.common.world.volume.buffer.block.AbstractBlockBuffer) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) FluidState(org.spongepowered.api.fluid.FluidState) BlockEntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.block.entity.BlockEntityArchetypeVolume) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) Palette(org.spongepowered.api.world.schematic.Palette) Function(java.util.function.Function) BlockState(org.spongepowered.api.block.BlockState) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) BlockType(org.spongepowered.api.block.BlockType) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream) BlockStateBridge(org.spongepowered.common.bridge.world.level.block.state.BlockStateBridge) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3d(org.spongepowered.math.vector.Vector3d) BlockEntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.block.entity.BlockEntityArchetypeVolume) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream)

Example 7 with StreamOptions

use of org.spongepowered.api.world.volume.stream.StreamOptions 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)

Example 8 with StreamOptions

use of org.spongepowered.api.world.volume.stream.StreamOptions in project SpongeCommon by SpongePowered.

the class SpongeArchetypeVolume method blockStateStream.

@Override
public VolumeStream<ArchetypeVolume, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    final Vector3i blockMin = this.min();
    final Vector3i blockMax = this.max();
    VolumeStreamUtils.validateStreamArgs(min, max, blockMin, blockMax, options);
    final ArrayMutableBlockBuffer buffer;
    if (options.carbonCopy()) {
        buffer = this.blocks.copy();
    } else {
        buffer = this.blocks;
    }
    final Stream<VolumeElement<ArchetypeVolume, BlockState>> stateStream = IntStream.range(min.x(), max.x() + 1).mapToObj(x -> IntStream.range(min.z(), max.z() + 1).mapToObj(z -> IntStream.range(min.y(), max.y() + 1).mapToObj(y -> VolumeElement.of((ArchetypeVolume) this, () -> buffer.block(x, y, z), new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
    return new SpongeVolumeStream<>(stateStream, () -> this);
}
Also used : IntStream(java.util.stream.IntStream) NonNull(org.checkerframework.checker.nullness.qual.NonNull) ServerWorld(org.spongepowered.api.world.server.ServerWorld) RegistryHolder(org.spongepowered.api.registry.RegistryHolder) FluidState(org.spongepowered.api.fluid.FluidState) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpawnType(org.spongepowered.api.event.cause.entity.SpawnType) Function(java.util.function.Function) Supplier(java.util.function.Supplier) VolumeApplicators(org.spongepowered.api.world.volume.stream.VolumeApplicators) Biome(org.spongepowered.api.world.biome.Biome) PaletteTypes(org.spongepowered.api.world.schematic.PaletteTypes) AbstractVolumeBuffer(org.spongepowered.common.world.volume.buffer.AbstractVolumeBuffer) Map(java.util.Map) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream) PluginPhase(org.spongepowered.common.event.tracking.phase.plugin.PluginPhase) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) BlockEntityArchetype(org.spongepowered.api.block.entity.BlockEntityArchetype) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) BlockEntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.block.entity.BlockEntityArchetypeVolume) VolumePositionTranslators(org.spongepowered.api.world.volume.stream.VolumePositionTranslators) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Palette(org.spongepowered.api.world.schematic.Palette) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) ObjectArrayMutableEntityArchetypeBuffer(org.spongepowered.common.world.volume.buffer.archetype.entity.ObjectArrayMutableEntityArchetypeBuffer) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) BlockState(org.spongepowered.api.block.BlockState) Transformation(org.spongepowered.api.util.transformation.Transformation) MutableMapBlockEntityArchetypeBuffer(org.spongepowered.common.world.volume.buffer.archetype.blockentity.MutableMapBlockEntityArchetypeBuffer) Objects(java.util.Objects) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) BlockChangeFlags(org.spongepowered.api.world.BlockChangeFlags) BlockType(org.spongepowered.api.block.BlockType) EntityArchetypeEntry(org.spongepowered.api.world.volume.archetype.entity.EntityArchetypeEntry) Optional(java.util.Optional) VolumeCollectors(org.spongepowered.api.world.volume.stream.VolumeCollectors) ByteArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ByteArrayMutableBiomeBuffer) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Vector3i(org.spongepowered.math.vector.Vector3i) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) BlockEntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.block.entity.BlockEntityArchetypeVolume) Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream)

Aggregations

Stream (java.util.stream.Stream)8 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)8 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)8 Vector3d (org.spongepowered.math.vector.Vector3d)8 Vector3i (org.spongepowered.math.vector.Vector3i)8 Function (java.util.function.Function)7 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)7 Objects (java.util.Objects)6 IntStream (java.util.stream.IntStream)6 VolumeStreamUtils (org.spongepowered.common.world.volume.VolumeStreamUtils)6 ArrayMutableBlockBuffer (org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)6 Collection (java.util.Collection)5 Predicate (java.util.function.Predicate)5 BlockState (org.spongepowered.api.block.BlockState)5 Map (java.util.Map)4 Optional (java.util.Optional)4 Nullable (org.checkerframework.checker.nullness.qual.Nullable)4 FluidState (org.spongepowered.api.fluid.FluidState)4 Palette (org.spongepowered.api.world.schematic.Palette)4 SpongeVolumeStream (org.spongepowered.common.world.volume.SpongeVolumeStream)4