Search in sources :

Example 6 with AbstractChunkProvider

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;
}
Also used : NIGHT(com.minecolonies.api.util.constant.CitizenConstants.NIGHT) AbstractChunkProvider(net.minecraft.world.chunk.AbstractChunkProvider) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

AbstractChunkProvider (net.minecraft.world.chunk.AbstractChunkProvider)6 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)4 NIGHT (com.minecolonies.api.util.constant.CitizenConstants.NIGHT)2 BlockPos (net.minecraft.util.math.BlockPos)2 Chunk (net.minecraft.world.chunk.Chunk)2 DynmapChunk (org.dynmap.DynmapChunk)2 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 AbstractWorld (com.sk89q.worldedit.world.AbstractWorld)1 File (java.io.File)1 IOException (java.io.IOException)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 World (net.minecraft.world.World)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 SaveHandler (net.minecraft.world.storage.SaveHandler)1