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;
019
020import baritone.api.cache.IWorldScanner;
021import baritone.api.command.ICommand;
022import baritone.api.command.ICommandSystem;
023import baritone.api.schematic.ISchematicSystem;
024import net.minecraft.client.entity.EntityPlayerSP;
025
026import java.util.List;
027import java.util.Objects;
028
029/**
030 * Provides the present {@link IBaritone} instances, as well as non-baritone instance related APIs.
031 *
032 * @author leijurv
033 */
034public interface IBaritoneProvider {
035
036    /**
037     * Returns the primary {@link IBaritone} instance. This instance is persistent, and
038     * is represented by the local player that is created by the game itself, not a "bot"
039     * player through Baritone.
040     *
041     * @return The primary {@link IBaritone} instance.
042     */
043    IBaritone getPrimaryBaritone();
044
045    /**
046     * Returns all of the active {@link IBaritone} instances. This includes the local one
047     * returned by {@link #getPrimaryBaritone()}.
048     *
049     * @return All active {@link IBaritone} instances.
050     * @see #getBaritoneForPlayer(EntityPlayerSP)
051     */
052    List<IBaritone> getAllBaritones();
053
054    /**
055     * Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be
056     * replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when
057     * {@code bot-system} is merged into {@code master}.
058     *
059     * @param player The player
060     * @return The {@link IBaritone} instance.
061     */
062    default IBaritone getBaritoneForPlayer(EntityPlayerSP player) {
063        for (IBaritone baritone : getAllBaritones()) {
064            if (Objects.equals(player, baritone.getPlayerContext().player())) {
065                return baritone;
066            }
067        }
068        return null;
069    }
070
071    /**
072     * Returns the {@link IWorldScanner} instance. This is not a type returned by
073     * {@link IBaritone} implementation, because it is not linked with {@link IBaritone}.
074     *
075     * @return The {@link IWorldScanner} instance.
076     */
077    IWorldScanner getWorldScanner();
078
079    /**
080     * Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
081     * instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
082     *
083     * @return The {@link ICommandSystem} instance.
084     */
085    ICommandSystem getCommandSystem();
086
087    /**
088     * @return The {@link ISchematicSystem} instance.
089     */
090    ISchematicSystem getSchematicSystem();
091}