Search in sources :

Example 1 with ObjectArrayMutableEntityBuffer

use of org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer in project SpongeCommon by SpongePowered.

the class LevelChunkMixin_API method entityStream.

@Override
public VolumeStream<WorldChunk, Entity> entityStream(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 ObjectArrayMutableEntityBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ObjectArrayMutableEntityBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<WorldChunk, Entity, net.minecraft.world.entity.Entity, LevelChunk, UUID>generateStream(options, this, (LevelChunk) (Object) this, // Entity Accessor
    (chunk) -> VolumeStreamUtils.getEntitiesFromChunk(min, max, chunk), // Entity Identity Function
    VolumeStreamUtils.getOrCloneEntityWithVolume(shouldCarbonCopy, backingVolume, this.level), (key, entity) -> entity.getUUID(), // Filtered Position Entity Accessor
    (entityUuid, chunk) -> {
        final net.minecraft.world.entity.@Nullable Entity entity = shouldCarbonCopy ? (net.minecraft.world.entity.Entity) backingVolume.entity(entityUuid).orElse(null) : (net.minecraft.world.entity.Entity) chunk.world().entity(entityUuid).orElse(null);
        if (entity == null) {
            return null;
        }
        return new Tuple<>(entity.blockPosition(), entity);
    });
}
Also used : BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Vector3i(org.spongepowered.math.vector.Vector3i) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) UUID(java.util.UUID) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple)

Example 2 with ObjectArrayMutableEntityBuffer

use of org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer in project SpongeCommon by SpongePowered.

the class LevelMixin_API method entityStream.

@SuppressWarnings("unchecked")
@Override
public VolumeStream<W, Entity> entityStream(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 ObjectArrayMutableEntityBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ObjectArrayMutableEntityBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<W, Entity, net.minecraft.world.entity.Entity, ChunkAccess, UUID>generateStream(min, max, options, // Ref
    (W) this, // IdentityFunction
    VolumeStreamUtils.getOrCloneEntityWithVolume(shouldCarbonCopy, backingVolume, (Level) (Object) this), // ChunkAccessor
    VolumeStreamUtils.getChunkAccessorByStatus((LevelReader) (Object) this, options.loadingStyle().generateArea()), // Entity -> UniqueID
    (key, entity) -> entity.getUUID(), // Entity Accessor
    (chunk) -> chunk instanceof LevelChunk ? VolumeStreamUtils.getEntitiesFromChunk(min, max, (LevelChunk) chunk) : Stream.empty(), // Filtered Position Entity Accessor
    (entityUuid, world) -> {
        final net.minecraft.world.entity.@Nullable Entity entity = shouldCarbonCopy ? (net.minecraft.world.entity.Entity) backingVolume.entity(entityUuid).orElse(null) : (net.minecraft.world.entity.Entity) ((WorldLike) world).entity(entityUuid).orElse(null);
        if (entity == null) {
            return null;
        }
        return new Tuple<>(entity.blockPosition(), entity);
    });
}
Also used : HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) LevelReader(net.minecraft.world.level.LevelReader) 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) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) Level(net.minecraft.world.level.Level) UUID(java.util.UUID) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple)

Aggregations

UUID (java.util.UUID)2 Tuple (net.minecraft.util.Tuple)2 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)2 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)2 Entity (org.spongepowered.api.entity.Entity)2 ObjectArrayMutableEntityBuffer (org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer)2 Vector3i (org.spongepowered.math.vector.Vector3i)2 Level (net.minecraft.world.level.Level)1 LevelReader (net.minecraft.world.level.LevelReader)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 WorldChunk (org.spongepowered.api.world.chunk.WorldChunk)1 HumanEntity (org.spongepowered.common.entity.living.human.HumanEntity)1