Search in sources :

Example 1 with SpongeVolumeStream

use of org.spongepowered.common.world.volume.SpongeVolumeStream in project SpongeCommon by SpongePowered.

the class SpongeArchetypeVolume method blockEntityArchetypeStream.

@Override
public VolumeStream<ArchetypeVolume, BlockEntityArchetype> blockEntityArchetypeStream(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 Stream<VolumeElement<ArchetypeVolume, BlockEntityArchetype>> stateStream = this.blockEntities.blockEntityArchetypeStream(min, max, options).toStream().map(element -> VolumeElement.of(this, element::type, element.position()));
    return new SpongeVolumeStream<>(stateStream, () -> this);
}
Also used : Vector3i(org.spongepowered.math.vector.Vector3i) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream)

Example 2 with SpongeVolumeStream

use of org.spongepowered.common.world.volume.SpongeVolumeStream 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 3 with SpongeVolumeStream

use of org.spongepowered.common.world.volume.SpongeVolumeStream in project SpongeCommon by SpongePowered.

the class AbstractMutableBlockEntityBuffer method blockStateStream.

@Override
public VolumeStream<BlockEntityVolume.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<BlockEntityVolume.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((BlockEntityVolume.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 : BlockEntityVolume(org.spongepowered.api.world.volume.block.entity.BlockEntityVolume) 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) 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) BlockEntityVolume(org.spongepowered.api.world.volume.block.entity.BlockEntityVolume) Vector3d(org.spongepowered.math.vector.Vector3d) 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 4 with SpongeVolumeStream

use of org.spongepowered.common.world.volume.SpongeVolumeStream in project SpongeCommon by SpongePowered.

the class ObjectArrayMutableEntityBuffer method blockStateStream.

@Override
public VolumeStream<EntityVolume.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<EntityVolume.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((EntityVolume.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) DataContainer(org.spongepowered.api.data.persistence.DataContainer) FluidState(org.spongepowered.api.fluid.FluidState) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) AABB(org.spongepowered.api.util.AABB) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EntityVolume(org.spongepowered.api.world.volume.entity.EntityVolume) ImmutableList(com.google.common.collect.ImmutableList) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream) StreamSupport(java.util.stream.StreamSupport) Nullable(org.checkerframework.checker.nullness.qual.Nullable) AbstractBlockBuffer(org.spongepowered.common.world.volume.buffer.block.AbstractBlockBuffer) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Palette(org.spongepowered.api.world.schematic.Palette) UUID(java.util.UUID) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) BlockType(org.spongepowered.api.block.BlockType) EntityType(org.spongepowered.api.entity.EntityType) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Vector3i(org.spongepowered.math.vector.Vector3i) EntityVolume(org.spongepowered.api.world.volume.entity.EntityVolume) Vector3d(org.spongepowered.math.vector.Vector3d) 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 5 with SpongeVolumeStream

use of org.spongepowered.common.world.volume.SpongeVolumeStream in project SpongeCommon by SpongePowered.

the class ByteArrayMutableBiomeBuffer method biomeStream.

@Override
public VolumeStream<BiomeVolume.Mutable, Biome> biomeStream(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 byte[] biomes;
    if (options.carbonCopy()) {
        biomes = Arrays.copyOf(this.biomes, this.biomes.length);
    } else {
        biomes = this.biomes;
    }
    final Stream<VolumeElement<BiomeVolume.Mutable, Biome>> 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((BiomeVolume.Mutable) this, () -> {
        final byte biomeId = biomes[this.getIndex(x, y, z)];
        return this.palette.get(biomeId & 255, Sponge.server()).orElseGet(() -> Sponge.server().registry(RegistryTypes.BIOME).value(Biomes.OCEAN));
    }, new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
    return new SpongeVolumeStream<>(stateStream, () -> this);
}
Also used : BiomeVolume(org.spongepowered.api.world.volume.biome.BiomeVolume) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) Sponge(org.spongepowered.api.Sponge) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) Palette(org.spongepowered.api.world.schematic.Palette) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) Function(java.util.function.Function) Biome(org.spongepowered.api.world.biome.Biome) Objects(java.util.Objects) Biomes(org.spongepowered.api.world.biome.Biomes) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) BiomeVolume(org.spongepowered.api.world.volume.biome.BiomeVolume) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream)

Aggregations

VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)8 SpongeVolumeStream (org.spongepowered.common.world.volume.SpongeVolumeStream)8 Vector3i (org.spongepowered.math.vector.Vector3i)8 Function (java.util.function.Function)5 IntStream (java.util.stream.IntStream)5 Stream (java.util.stream.Stream)5 Palette (org.spongepowered.api.world.schematic.Palette)5 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)5 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)5 VolumeStreamUtils (org.spongepowered.common.world.volume.VolumeStreamUtils)5 BlockState (org.spongepowered.api.block.BlockState)4 BlockType (org.spongepowered.api.block.BlockType)4 FluidState (org.spongepowered.api.fluid.FluidState)4 Vector3d (org.spongepowered.math.vector.Vector3d)4 Objects (java.util.Objects)3 AbstractBlockBuffer (org.spongepowered.common.world.volume.buffer.block.AbstractBlockBuffer)3 ArrayMutableBlockBuffer (org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)3 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2