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