Search in sources :

Example 6 with ArrayMutableBlockBuffer

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));
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(net.minecraft.world.level.block.state.BlockState) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos)

Example 7 with ArrayMutableBlockBuffer

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

Example 8 with ArrayMutableBlockBuffer

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;
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)

Example 9 with ArrayMutableBlockBuffer

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;
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)

Example 10 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, 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);
}
Also used : ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)

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