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