Search in sources :

Example 1 with Biomes

use of org.spongepowered.api.world.biome.Biomes 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

Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Sponge (org.spongepowered.api.Sponge)1 RegistryTypes (org.spongepowered.api.registry.RegistryTypes)1 Biome (org.spongepowered.api.world.biome.Biome)1 Biomes (org.spongepowered.api.world.biome.Biomes)1 Palette (org.spongepowered.api.world.schematic.Palette)1 BiomeVolume (org.spongepowered.api.world.volume.biome.BiomeVolume)1 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)1 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)1 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)1 SpongeVolumeStream (org.spongepowered.common.world.volume.SpongeVolumeStream)1 VolumeStreamUtils (org.spongepowered.common.world.volume.VolumeStreamUtils)1 Vector3d (org.spongepowered.math.vector.Vector3d)1 Vector3i (org.spongepowered.math.vector.Vector3i)1