use of org.spongepowered.api.block.entity.BlockEntity 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.api.block.entity.BlockEntity in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method blockEntityStream.
@Override
public VolumeStream<WorldChunk, BlockEntity> blockEntityStream(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.<WorldChunk, BlockEntity, net.minecraft.world.level.block.entity.BlockEntity, ChunkAccess, BlockPos>generateStream(options, // Ref
(WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
this::impl$getBlockEntitiesStream, // IdentityFunction
VolumeStreamUtils.getBlockEntityOrCloneToBackingVolume(shouldCarbonCopy, backingVolume, this.level), // Biome by block position
(key, biome) -> key, // Filtered Position Entity Accessor
(blockPos, world) -> {
final net.minecraft.world.level.block.entity.@Nullable BlockEntity tileEntity = shouldCarbonCopy ? (net.minecraft.world.level.block.entity.BlockEntity) backingVolume.blockEntity(blockPos.getX(), blockPos.getY(), blockPos.getZ()).orElse(null) : ((LevelReader) world).getBlockEntity(blockPos);
return new Tuple<>(blockPos, tileEntity);
});
}
Aggregations