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