Search in sources :

Example 1 with ArrayMutableBlockBuffer

use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer 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 2 with ArrayMutableBlockBuffer

use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer in project SpongeCommon by SpongePowered.

the class LevelChunkMixin_API method blockStateStream.

@Override
public VolumeStream<WorldChunk, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
    final boolean shouldCarbonCopy = options.carbonCopy();
    final Vector3i size = max.sub(min).add(1, 1, 1);
    @MonotonicNonNull final ArrayMutableBlockBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ArrayMutableBlockBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<WorldChunk, BlockState, net.minecraft.world.level.block.state.BlockState, ChunkAccess, BlockPos>generateStream(options, // Ref
    (WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
    VolumeStreamUtils.getBlockStatesForSections(min, max), // IdentityFunction
    (pos, blockState) -> {
        if (shouldCarbonCopy) {
            backingVolume.setBlock(pos, blockState);
        }
    }, // Biome by block position
    (key, biome) -> key, // Filtered Position Entity Accessor
    (blockPos, world) -> {
        final net.minecraft.world.level.block.state.BlockState tileEntity = shouldCarbonCopy ? backingVolume.getBlock(blockPos) : ((LevelReader) world).getBlockState(blockPos);
        return new Tuple<>(blockPos, tileEntity);
    });
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(org.spongepowered.api.block.BlockState) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) Tuple(net.minecraft.util.Tuple)

Example 3 with ArrayMutableBlockBuffer

use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer 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 ArrayMutableBlockBuffer

use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer in project SpongeCommon by SpongePowered.

the class SpongeBlockVolumeFactory method immutableOf.

@Override
public BlockVolume.Immutable immutableOf(final BlockVolume.Streamable<@NonNull ?> existing) {
    if (existing instanceof ArrayMutableBlockBuffer) {
        return this.createImmutableFromBufferData((ArrayMutableBlockBuffer) existing);
    }
    final ArrayMutableBlockBuffer buffer = new ArrayMutableBlockBuffer(existing.min(), existing.size());
    existing.blockStateStream(existing.min(), existing.max(), StreamOptions.lazily()).apply(VolumeCollectors.of(buffer, VolumePositionTranslators.identity(), VolumeApplicators.applyBlocks()));
    return this.createImmutableFromBufferData(buffer);
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)

Example 5 with ArrayMutableBlockBuffer

use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer 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)

Aggregations

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