use of net.minecraft.world.chunk.AbstractChunkProvider in project minecolonies by ldtteam.
the class WorldUtil method getEntitiesWithinBuilding.
/**
* Get all entities within a building.
*
* @param world the world to check this for.
* @param clazz the entity class.
* @param building the building to check the range for.
* @param predicate the predicate to check
* @param <T> the type of the predicate.
* @return a list of all within those borders.
*/
public static <T extends Entity> List<T> getEntitiesWithinBuilding(@NotNull final World world, @NotNull final Class<? extends T> clazz, @NotNull final IBuilding building, @Nullable final Predicate<? super T> predicate) {
final Tuple<BlockPos, BlockPos> corners = building.getCorners();
int minX = corners.getA().getX() >> 4;
int maxX = corners.getB().getX() >> 4;
int minZ = corners.getA().getZ() >> 4;
int maxZ = corners.getB().getZ() >> 4;
int minY = Math.max(0, corners.getA().getY()) >> 4;
int maxY = Math.min(corners.getB().getY(), world.getHeight()) >> 4;
List<T> list = Lists.newArrayList();
AbstractChunkProvider abstractchunkprovider = world.getChunkSource();
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
if (isEntityChunkLoaded(world, x, z)) {
Chunk chunk = abstractchunkprovider.getChunkNow(x, z);
if (chunk != null) {
for (int y = minY; y <= maxY; y++) {
for (final T entity : chunk.getEntitySections()[y].find(clazz)) {
if (building.isInBuilding(entity.blockPosition()) && (predicate == null || predicate.test(entity))) {
list.add(entity);
}
}
}
}
}
}
}
return list;
}
Aggregations