Search in sources :

Example 46 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class VolumeStreamUtils method getBlockEntityStream.

public static <R extends Region<R>> VolumeStream<R, BlockEntity> getBlockEntityStream(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 ObjectArrayMutableBlockEntityBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ObjectArrayMutableBlockEntityBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<R, BlockEntity, net.minecraft.world.level.block.entity.BlockEntity, ChunkAccess, BlockPos>generateStream(min, max, options, // Ref
    (R) reader, // IdentityFunction
    VolumeStreamUtils.getBlockEntityOrCloneToBackingVolume(shouldCarbonCopy, backingVolume, reader instanceof Level ? (Level) reader : null), // ChunkAccessor
    VolumeStreamUtils.getChunkAccessorByStatus(reader, options.loadingStyle().generateArea()), // TileEntity by block pos
    (key, tileEntity) -> key, // TileEntity Accessor
    (chunk) -> chunk instanceof LevelChunk ? ((LevelChunk) chunk).getBlockEntities().entrySet().stream().filter(entry -> VecHelper.inBounds(entry.getKey(), min, max)) : Stream.empty(), // Filtered Position TileEntity Accessor
    (blockPos, world) -> {
        final net.minecraft.world.level.block.entity.@Nullable BlockEntity tileEntity = shouldCarbonCopy ? backingVolume.getTileEntity(blockPos) : ((LevelReader) world).getBlockEntity(blockPos);
        return new Tuple<>(blockPos, tileEntity);
    });
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) ObjectArrayMutableBlockEntityBuffer(org.spongepowered.common.world.volume.buffer.blockentity.ObjectArrayMutableBlockEntityBuffer) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple) BlockEntity(org.spongepowered.api.block.entity.BlockEntity)

Example 47 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class SpongeLocatableBlockBuilder method position.

@Override
public SpongeLocatableBlockBuilder position(final int x, final int y, final int z) {
    final Vector3i position = new Vector3i(x, y, z);
    this.position = () -> position;
    return this;
}
Also used : Vector3i(org.spongepowered.math.vector.Vector3i)

Example 48 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class AbstractReferentArchetypeVolume method addEntity.

@Override
public void addEntity(final EntityArchetypeEntry entry) {
    final Vector3d position = entry.position();
    final Vector3i transformed = this.inverseTransform(position.x(), position.y(), position.z());
    this.consumeReference(a -> a.addEntity(entry.archetype(), transformed.toDouble()));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i)

Example 49 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class AbstractReferentArchetypeVolume method addBlockEntity.

@Override
public void addBlockEntity(final int x, final int y, final int z, final BlockEntityArchetype archetype) {
    final Vector3i transformed = this.inverseTransform(x, y, z);
    this.consumeReference(a -> a.addBlockEntity(transformed.x(), transformed.y(), transformed.z(), archetype));
}
Also used : Vector3i(org.spongepowered.math.vector.Vector3i)

Example 50 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class SpongeArchetypeVolume method entityArchetypeStream.

@Override
public VolumeStream<ArchetypeVolume, EntityArchetype> entityArchetypeStream(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, EntityArchetype>> stateStream = this.entities.entityArchetypeStream(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)

Aggregations

Vector3i (org.spongepowered.math.vector.Vector3i)59 Vector3d (org.spongepowered.math.vector.Vector3d)22 Nullable (org.checkerframework.checker.nullness.qual.Nullable)15 BlockPos (net.minecraft.core.BlockPos)14 BlockState (org.spongepowered.api.block.BlockState)14 Stream (java.util.stream.Stream)13 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)12 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)12 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)11 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)11 Tuple (net.minecraft.util.Tuple)10 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)10 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)10 Function (java.util.function.Function)9 Biome (org.spongepowered.api.world.biome.Biome)9 Collection (java.util.Collection)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8 UUID (java.util.UUID)8 Entity (org.spongepowered.api.entity.Entity)8