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 net.minecraft.util.math.BlockPos;
021import net.minecraft.world.chunk.Chunk;
022
023import java.util.ArrayList;
024
025/**
026 * @author Brady
027 * @since 9/24/2018
028 */
029public interface ICachedWorld {
030
031    /**
032     * Returns the region at the specified region coordinates
033     *
034     * @param regionX The region X coordinate
035     * @param regionZ The region Z coordinate
036     * @return The region located at the specified coordinates
037     */
038    ICachedRegion getRegion(int regionX, int regionZ);
039
040    /**
041     * Queues the specified chunk for packing. This entails reading the contents
042     * of the chunk, then packing the data into the 2-bit format, and storing that
043     * in this cached world.
044     *
045     * @param chunk The chunk to pack and store
046     */
047    void queueForPacking(Chunk chunk);
048
049    /**
050     * Returns whether or not the block at the specified X and Z coordinates
051     * is cached in this world.
052     *
053     * @param blockX The block X coordinate
054     * @param blockZ The block Z coordinate
055     * @return Whether or not the specified XZ location is cached
056     */
057    boolean isCached(int blockX, int blockZ);
058
059    /**
060     * Scans the cached chunks for location of the specified special block. The
061     * information that is returned by this method may not be up to date, because
062     * older cached chunks can contain data that is much more likely to have changed.
063     *
064     * @param block               The special block to search for
065     * @param maximum             The maximum number of position results to receive
066     * @param centerX             The x block coordinate center of the search
067     * @param centerZ             The z block coordinate center of the search
068     * @param maxRegionDistanceSq The maximum region distance, squared
069     * @return The locations found that match the special block
070     */
071    ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq);
072
073    /**
074     * Reloads all of the cached regions in this world from disk. Anything that is not saved
075     * will be lost. This operation does not execute in a new thread by default.
076     */
077    void reloadAllFromDisk();
078
079    /**
080     * Saves all of the cached regions in this world to disk. This operation does not execute
081     * in a new thread by default.
082     */
083    void save();
084}