001/*
002 * This file is part of Baritone.
003 *
004 * Baritone is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Lesser General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * Baritone is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License
015 * along with Baritone.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package baritone.api.cache;
019
020import baritone.api.utils.BlockOptionalMetaLookup;
021import baritone.api.utils.IPlayerContext;
022import net.minecraft.block.Block;
023import net.minecraft.util.math.BlockPos;
024import net.minecraft.util.math.ChunkPos;
025
026import java.util.List;
027
028/**
029 * @author Brady
030 * @since 10/6/2018
031 */
032public interface IWorldScanner {
033
034    /**
035     * Scans the world, up to the specified max chunk radius, for the specified blocks.
036     *
037     * @param ctx             The {@link IPlayerContext} containing player and world info that the scan is based upon
038     * @param filter          The blocks to scan for
039     * @param max             The maximum number of blocks to scan before cutoff
040     * @param yLevelThreshold If a block is found within this Y level, the current result will be returned, if the value
041     *                        is negative, then this condition doesn't apply.
042     * @param maxSearchRadius The maximum chunk search radius
043     * @return The matching block positions
044     */
045    List<BlockPos> scanChunkRadius(IPlayerContext ctx, BlockOptionalMetaLookup filter, int max, int yLevelThreshold, int maxSearchRadius);
046
047    default List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> filter, int max, int yLevelThreshold, int maxSearchRadius) {
048        return scanChunkRadius(ctx, new BlockOptionalMetaLookup(filter.toArray(new Block[0])), max, yLevelThreshold, maxSearchRadius);
049    }
050
051    /**
052     * Scans a single chunk for the specified blocks.
053     *
054     * @param ctx             The {@link IPlayerContext} containing player and world info that the scan is based upon
055     * @param filter          The blocks to scan for
056     * @param pos             The position of the target chunk
057     * @param max             The maximum number of blocks to scan before cutoff
058     * @param yLevelThreshold If a block is found within this Y level, the current result will be returned, if the value
059     *                        is negative, then this condition doesn't apply.
060     * @return The matching block positions
061     */
062    List<BlockPos> scanChunk(IPlayerContext ctx, BlockOptionalMetaLookup filter, ChunkPos pos, int max, int yLevelThreshold);
063
064    /**
065     * Scans a single chunk for the specified blocks.
066     *
067     * @param ctx             The {@link IPlayerContext} containing player and world info that the scan is based upon
068     * @param blocks          The blocks to scan for
069     * @param pos             The position of the target chunk
070     * @param max             The maximum number of blocks to scan before cutoff
071     * @param yLevelThreshold If a block is found within this Y level, the current result will be returned, if the value
072     *                        is negative, then this condition doesn't apply.
073     * @return The matching block positions
074     */
075    default List<BlockPos> scanChunk(IPlayerContext ctx, List<Block> blocks, ChunkPos pos, int max, int yLevelThreshold) {
076        return scanChunk(ctx, new BlockOptionalMetaLookup(blocks), pos, max, yLevelThreshold);
077    }
078
079    /**
080     * Overload of {@link #repack(IPlayerContext, int)} where the value of the {@code range} parameter is {@code 40}.
081     *
082     * @param ctx The player, describing the origin
083     * @return The amount of chunks successfully queued for repacking
084     */
085    int repack(IPlayerContext ctx);
086
087    /**
088     * Queues the chunks in a square formation around the specified player, using the specified
089     * range, which represents 1/2 the square's dimensions, where the player is in the center.
090     *
091     * @param ctx   The player, describing the origin
092     * @param range The range to repack
093     * @return The amount of chunks successfully queued for repacking
094     */
095    int repack(IPlayerContext ctx, int range);
096}