Search in sources :

Example 1 with VolumeElement

use of org.spongepowered.api.world.volume.stream.VolumeElement 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 VolumeElement

use of org.spongepowered.api.world.volume.stream.VolumeElement in project SpongeCommon by SpongePowered.

the class AbstractReferentArchetypeVolume method applyTransformationsToStream.

private <T> VolumeStream<ArchetypeVolume, T> applyTransformationsToStream(final Vector3i min, final Vector3i max, final StreamOptions options, final StreamCreator<A, T> streamCreator, final VolumeStreamUtils.TriFunction<VolumeElement<ArchetypeVolume, T>, Supplier<Rotation>, Supplier<Mirror>, T> elementTransform) {
    final Vector3i transformedMin = this.min();
    final Vector3i transformedMax = this.max();
    VolumeStreamUtils.validateStreamArgs(min, max, transformedMin, transformedMax, options);
    final Vector3i minDiff = min.sub(transformedMin);
    final Vector3i maxDiff = transformedMax.sub(max);
    final boolean xMirror = this.transformation.mirror(Axis.X);
    final boolean zMirror = this.transformation.mirror(Axis.Z);
    final Supplier<Mirror> mirror = xMirror ? Mirrors.FRONT_BACK : zMirror ? Mirrors.LEFT_RIGHT : Mirrors.NONE;
    return this.applyReference(a -> streamCreator.createStream(a, a.min().add(minDiff), a.max().sub(maxDiff), options)).transform(e -> VolumeElement.of(this, elementTransform.apply(e, this.transformation::rotation, mirror), this.transformStreamBlockPosition(e.position().add(VolumePositionTranslators.BLOCK_OFFSET)).sub(VolumePositionTranslators.BLOCK_OFFSET)));
}
Also used : FluidState(org.spongepowered.api.fluid.FluidState) BiFunction(java.util.function.BiFunction) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Biome(org.spongepowered.api.world.biome.Biome) Rotation(org.spongepowered.api.util.rotation.Rotation) Mirror(org.spongepowered.api.util.mirror.Mirror) Map(java.util.Map) EntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.entity.EntityArchetypeVolume) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntityArchetype(org.spongepowered.api.block.entity.BlockEntityArchetype) BiomeVolume(org.spongepowered.api.world.volume.biome.BiomeVolume) 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) Axis(org.spongepowered.api.util.Axis) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Collectors(java.util.stream.Collectors) BlockState(org.spongepowered.api.block.BlockState) Mirrors(org.spongepowered.api.util.mirror.Mirrors) Transformation(org.spongepowered.api.util.transformation.Transformation) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) Volume(org.spongepowered.api.world.volume.Volume) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) EntityArchetypeEntry(org.spongepowered.api.world.volume.archetype.entity.EntityArchetypeEntry) MemoizedSupplier(org.spongepowered.common.util.MemoizedSupplier) Optional(java.util.Optional) BlockVolume(org.spongepowered.api.world.volume.block.BlockVolume) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3i(org.spongepowered.math.vector.Vector3i) Mirror(org.spongepowered.api.util.mirror.Mirror)

Example 3 with VolumeElement

use of org.spongepowered.api.world.volume.stream.VolumeElement 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 4 with VolumeElement

use of org.spongepowered.api.world.volume.stream.VolumeElement 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 5 with VolumeElement

use of org.spongepowered.api.world.volume.stream.VolumeElement 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)9 Vector3i (org.spongepowered.math.vector.Vector3i)9 SpongeVolumeStream (org.spongepowered.common.world.volume.SpongeVolumeStream)8 Function (java.util.function.Function)6 Stream (java.util.stream.Stream)6 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)6 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)6 VolumeStreamUtils (org.spongepowered.common.world.volume.VolumeStreamUtils)6 IntStream (java.util.stream.IntStream)5 BlockState (org.spongepowered.api.block.BlockState)5 FluidState (org.spongepowered.api.fluid.FluidState)5 Palette (org.spongepowered.api.world.schematic.Palette)5 Vector3d (org.spongepowered.math.vector.Vector3d)5 Objects (java.util.Objects)4 BlockType (org.spongepowered.api.block.BlockType)4 Collection (java.util.Collection)3 Optional (java.util.Optional)3 Predicate (java.util.function.Predicate)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 Biome (org.spongepowered.api.world.biome.Biome)3