Search in sources :

Example 1 with VolumeStream

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

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

the class LevelChunkMixin_API method biomeStream.

@Override
public VolumeStream<WorldChunk, Biome> biomeStream(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 ObjectArrayMutableBiomeBuffer backingVolume;
    if (shouldCarbonCopy) {
        final Registry<net.minecraft.world.level.biome.Biome> biomeRegistry = this.level.registryAccess().registry(Registry.BIOME_REGISTRY).map(wr -> ((Registry<net.minecraft.world.level.biome.Biome>) wr)).orElse(BuiltinRegistries.BIOME);
        backingVolume = new ObjectArrayMutableBiomeBuffer(min, size, VolumeStreamUtils.nativeToSpongeRegistry(biomeRegistry));
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<WorldChunk, Biome, net.minecraft.world.level.biome.Biome, ChunkAccess, BlockPos>generateStream(options, // Ref
    (WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
    VolumeStreamUtils.getBiomesForChunkByPos((LevelReader) (Object) this, min, max), // IdentityFunction
    (pos, biome) -> {
        if (shouldCarbonCopy) {
            backingVolume.setBiome(pos, biome);
        }
    }, // Biome by block position
    (key, biome) -> key, // Filtered Position Entity Accessor
    (blockPos, world) -> {
        final net.minecraft.world.level.biome.Biome biome = shouldCarbonCopy ? backingVolume.getNativeBiome(blockPos.getX(), blockPos.getY(), blockPos.getZ()) : ((LevelReader) world.world()).getBiome(blockPos);
        return new Tuple<>(blockPos, biome);
    });
}
Also used : Arrays(java.util.Arrays) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Registry(net.minecraft.core.Registry) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Biome(org.spongepowered.api.world.biome.Biome) Mixin(org.spongepowered.asm.mixin.Mixin) ChunkBiomeContainerAccessor(org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor) Map(java.util.Map) DifficultyInstance(net.minecraft.world.DifficultyInstance) BuiltinRegistries(net.minecraft.data.BuiltinRegistries) ObjectArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ObjectArrayMutableBiomeBuffer) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Remap(org.spongepowered.asm.mixin.Interface.Remap) UUID(java.util.UUID) LevelReader(net.minecraft.world.level.LevelReader) Final(org.spongepowered.asm.mixin.Final) Collectors(java.util.stream.Collectors) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) EntityUtil(org.spongepowered.common.entity.EntityUtil) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) BlockPos(net.minecraft.core.BlockPos) ChunkBiomeContainer(net.minecraft.world.level.chunk.ChunkBiomeContainer) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) HeightTypes(org.spongepowered.api.world.HeightTypes) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Level(net.minecraft.world.level.Level) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) NonNull(org.checkerframework.checker.nullness.qual.NonNull) DataContainer(org.spongepowered.api.data.persistence.DataContainer) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) AABB(org.spongepowered.api.util.AABB) ClassInstanceMultiMap(net.minecraft.util.ClassInstanceMultiMap) ArrayList(java.util.ArrayList) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) ImmutableList(com.google.common.collect.ImmutableList) ObjectArrayMutableBlockEntityBuffer(org.spongepowered.common.world.volume.buffer.blockentity.ObjectArrayMutableBlockEntityBuffer) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Ticks(org.spongepowered.api.util.Ticks) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Tuple(net.minecraft.util.Tuple) Entity(org.spongepowered.api.entity.Entity) WorldLike(org.spongepowered.api.world.WorldLike) ChunkPos(net.minecraft.world.level.ChunkPos) Implements(org.spongepowered.asm.mixin.Implements) SpongeChunkLayout(org.spongepowered.common.world.storage.SpongeChunkLayout) Vector3d(org.spongepowered.math.vector.Vector3d) Heightmap(net.minecraft.world.level.levelgen.Heightmap) VecHelper(org.spongepowered.common.util.VecHelper) EntityType(org.spongepowered.api.entity.EntityType) SpongeTicks(org.spongepowered.common.util.SpongeTicks) Collections(java.util.Collections) Interface(org.spongepowered.asm.mixin.Interface) Intrinsic(org.spongepowered.asm.mixin.Intrinsic) Vector3i(org.spongepowered.math.vector.Vector3i) ObjectArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ObjectArrayMutableBiomeBuffer) LevelReader(net.minecraft.world.level.LevelReader) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Biome(org.spongepowered.api.world.biome.Biome) 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 VolumeStream

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

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

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

Stream (java.util.stream.Stream)8 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)8 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)8 Vector3d (org.spongepowered.math.vector.Vector3d)8 Vector3i (org.spongepowered.math.vector.Vector3i)8 Function (java.util.function.Function)7 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)7 Objects (java.util.Objects)6 IntStream (java.util.stream.IntStream)6 VolumeStreamUtils (org.spongepowered.common.world.volume.VolumeStreamUtils)6 ArrayMutableBlockBuffer (org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer)6 Collection (java.util.Collection)5 Predicate (java.util.function.Predicate)5 BlockState (org.spongepowered.api.block.BlockState)5 Map (java.util.Map)4 Optional (java.util.Optional)4 Nullable (org.checkerframework.checker.nullness.qual.Nullable)4 FluidState (org.spongepowered.api.fluid.FluidState)4 Palette (org.spongepowered.api.world.schematic.Palette)4 SpongeVolumeStream (org.spongepowered.common.world.volume.SpongeVolumeStream)4