Search in sources :

Example 11 with BlockEntity

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);
    });
}
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 12 with BlockEntity

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);
    });
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) 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) 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)

Aggregations

BlockEntity (org.spongepowered.api.block.entity.BlockEntity)12 BlockPos (net.minecraft.core.BlockPos)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)4 Entity (org.spongepowered.api.entity.Entity)4 Vector3i (org.spongepowered.math.vector.Vector3i)4 Tuple (net.minecraft.util.Tuple)3 Level (net.minecraft.world.level.Level)3 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)3 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)3 ServerLocation (org.spongepowered.api.world.server.ServerLocation)3 Vector3d (org.spongepowered.math.vector.Vector3d)3 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Component (net.kyori.adventure.text.Component)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)2 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)2 EntityType (org.spongepowered.api.entity.EntityType)2 Player (org.spongepowered.api.entity.living.player.Player)2 WorldChunk (org.spongepowered.api.world.chunk.WorldChunk)2