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.schematic;
019
020import java.util.List;
021import net.minecraft.core.Direction;
022import net.minecraft.world.level.block.state.BlockState;
023
024/**
025 * Basic representation of a schematic. Provides the dimensions and the desired state for a given position relative to
026 * the origin.
027 *
028 * @author leijurv
029 */
030public interface ISchematic {
031
032    /**
033     * Does the block at this coordinate matter to the schematic?
034     * <p>
035     * Normally just a check for if the coordinate is in the cube.
036     * <p>
037     * However, in the case of something like a map art, anything that's below the level of the map art doesn't matter,
038     * so this function should return false in that case. (i.e. it doesn't really have to be air below the art blocks)
039     *
040     * @param x            The x position of the block, relative to the origin
041     * @param y            The y position of the block, relative to the origin
042     * @param z            The z position of the block, relative to the origin
043     * @param currentState The current state of that block in the world, or null
044     * @return Whether or not the specified position is within the bounds of this schematic
045     */
046    default boolean inSchematic(int x, int y, int z, BlockState currentState) {
047        return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ();
048    }
049
050    default int size(Direction.Axis axis) {
051        switch (axis) {
052            case X:
053                return widthX();
054            case Y:
055                return heightY();
056            case Z:
057                return lengthZ();
058            default:
059                throw new UnsupportedOperationException(axis + "");
060        }
061    }
062
063    /**
064     * Returns the desired block state at a given (X, Y, Z) position relative to the origin (0, 0, 0).
065     *
066     * @param x               The x position of the block, relative to the origin
067     * @param y               The y position of the block, relative to the origin
068     * @param z               The z position of the block, relative to the origin
069     * @param current         The current state of that block in the world, or null
070     * @param approxPlaceable The list of blockstates estimated to be placeable
071     * @return The desired block state at the specified position
072     */
073    BlockState desiredState(int x, int y, int z, BlockState current, List<BlockState> approxPlaceable);
074
075    /**
076     * Resets possible caches to avoid wrong behavior when moving the schematic around
077     */
078    default void reset() {}
079
080    /**
081     * @return The width (X axis length) of this schematic
082     */
083    int widthX();
084
085    /**
086     * @return The height (Y axis length) of this schematic
087     */
088    int heightY();
089
090    /**
091     * @return The length (Z axis length) of this schematic
092     */
093    int lengthZ();
094}