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);
}
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);
});
}
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);
}
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);
}
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);
}
Aggregations