use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer in project SpongeCommon by SpongePowered.
the class VolumeStreamUtils method generateBlockStream.
public static <W extends Region<W>> VolumeStream<W, org.spongepowered.api.block.BlockState> generateBlockStream(final LevelReader reader, 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.<W, org.spongepowered.api.block.BlockState, net.minecraft.world.level.block.state.BlockState, ChunkAccess, BlockPos>generateStream(min, max, options, // Ref
(W) reader, // IdentityFunction
VolumeStreamUtils.getOrCopyBlockState(shouldCarbonCopy, backingVolume), // ChunkAccessor
VolumeStreamUtils.getChunkAccessorByStatus(reader, options.loadingStyle().generateArea()), // Biome by block position
(key, biome) -> key, // Entity Accessor
VolumeStreamUtils.getBlockStatesForSections(min, max), // Filtered Position Entity Accessor
VolumeStreamUtils.getBlockStateFromThisOrCopiedVolume(shouldCarbonCopy, backingVolume));
}
use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer 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);
}
use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer in project SpongeCommon by SpongePowered.
the class SpongeBlockVolumeFactory method copy.
@Override
public BlockVolume.Mutable copy(final BlockVolume.Streamable<@NonNull ?> 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 buffer;
}
use of org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer in project SpongeCommon by SpongePowered.
the class SpongeBlockVolumeFactory method copyFromRange.
@Override
public BlockVolume.Mutable copyFromRange(final BlockVolume.Streamable<@NonNull ?> existing, final Vector3i newMin, final Vector3i newMax) {
final ArrayMutableBlockBuffer buffer = new ArrayMutableBlockBuffer(newMin, newMax.sub(newMin).add(Vector3i.ONE));
existing.blockStateStream(newMin, newMax, StreamOptions.lazily()).apply(VolumeCollectors.of(buffer, VolumePositionTranslators.identity(), VolumeApplicators.applyBlocks()));
return buffer;
}
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, final Vector3i newMin, final Vector3i newMax) {
final ArrayMutableBlockBuffer buffer = new ArrayMutableBlockBuffer(newMin, newMax.sub(newMin).add(Vector3i.ONE));
existing.blockStateStream(newMin, newMax, StreamOptions.lazily()).apply(VolumeCollectors.of(buffer, VolumePositionTranslators.identity(), VolumeApplicators.applyBlocks()));
return this.createImmutableFromBufferData(buffer);
}
Aggregations