Search in sources :

Example 11 with CommandInvalidStateException

use of baritone.api.command.exception.CommandInvalidStateException in project Spark-Client by Spark-Client-Development.

the class BuildCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
    if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
        file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension.getValue());
    }
    BetterBlockPos origin = ctx.playerFeet();
    BetterBlockPos buildOrigin;
    if (args.hasAny()) {
        args.requireMax(3);
        buildOrigin = args.getDatatypePost(RelativeBlockPos.INSTANCE, origin);
    } else {
        args.requireMax(0);
        buildOrigin = origin;
    }
    boolean success = baritone.getBuilderProcess().build(file.getName(), file, buildOrigin);
    if (!success) {
        throw new CommandInvalidStateException("Couldn't load the schematic. Make sure to use the FULL file name, including the extension (e.g. blah.schematic).");
    }
    logDirect(String.format("Successfully loaded schematic for building\nOrigin: %s", buildOrigin));
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) File(java.io.File) RelativeFile(baritone.api.command.datatypes.RelativeFile)

Example 12 with CommandInvalidStateException

use of baritone.api.command.exception.CommandInvalidStateException in project Spark-Client by Spark-Client-Development.

the class ETACommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(0);
    IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
    IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
    if (process == null) {
        throw new CommandInvalidStateException("No process in control");
    }
    IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
    logDirect(String.format("Next segment: %.2f\n" + "Goal: %.2f", pathingBehavior.ticksRemainingInSegment().orElse(-1.0), pathingBehavior.estimatedTicksToGoal().orElse(-1.0)));
}
Also used : IPathingControlManager(baritone.api.pathing.calc.IPathingControlManager) IBaritoneProcess(baritone.api.process.IBaritoneProcess) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) IPathingBehavior(baritone.api.behavior.IPathingBehavior)

Example 13 with CommandInvalidStateException

use of baritone.api.command.exception.CommandInvalidStateException in project Spark-Client by Spark-Client-Development.

the class InvertCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(0);
    ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
    Goal goal;
    if ((goal = customGoalProcess.getGoal()) == null) {
        throw new CommandInvalidStateException("No goal");
    }
    if (goal instanceof GoalInverted) {
        goal = ((GoalInverted) goal).origin;
    } else {
        goal = new GoalInverted(goal);
    }
    customGoalProcess.setGoalAndPath(goal);
    logDirect(String.format("Goal: %s", goal.toString()));
}
Also used : Goal(baritone.api.pathing.goals.Goal) ICustomGoalProcess(baritone.api.process.ICustomGoalProcess) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) GoalInverted(baritone.api.pathing.goals.GoalInverted)

Example 14 with CommandInvalidStateException

use of baritone.api.command.exception.CommandInvalidStateException in project Spark-Client by Spark-Client-Development.

the class ProcCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(0);
    IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
    IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
    if (process == null) {
        throw new CommandInvalidStateException("No process in control");
    }
    logDirect(String.format("Class: %s\n" + "Priority: %f\n" + "Temporary: %b\n" + "Display name: %s\n" + "Last command: %s", process.getClass().getTypeName(), process.priority(), process.isTemporary(), process.displayName(), pathingControlManager.mostRecentCommand().map(PathingCommand::toString).orElse("None")));
}
Also used : IPathingControlManager(baritone.api.pathing.calc.IPathingControlManager) IBaritoneProcess(baritone.api.process.IBaritoneProcess) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Example 15 with CommandInvalidStateException

use of baritone.api.command.exception.CommandInvalidStateException in project Spark-Client by Spark-Client-Development.

the class WaypointsCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST;
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    BiFunction<IWaypoint, Action, ITextComponent> toComponent = (waypoint, _action) -> {
        ITextComponent component = new TextComponentString("");
        ITextComponent tagComponent = new TextComponentString(waypoint.getTag().name() + " ");
        tagComponent.getStyle().setColor(TextFormatting.GRAY);
        String name = waypoint.getName();
        ITextComponent nameComponent = new TextComponentString(!name.isEmpty() ? name : "<empty>");
        nameComponent.getStyle().setColor(!name.isEmpty() ? TextFormatting.GRAY : TextFormatting.DARK_GRAY);
        ITextComponent timestamp = new TextComponentString(" @ " + new Date(waypoint.getCreationTimestamp()));
        timestamp.getStyle().setColor(TextFormatting.DARK_GRAY);
        component.appendSibling(tagComponent);
        component.appendSibling(nameComponent);
        component.appendSibling(timestamp);
        component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to select"))).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s %s %s @ %d", FORCE_COMMAND_PREFIX, label, _action.names[0], waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
        return component;
    };
    Function<IWaypoint, ITextComponent> transform = waypoint -> toComponent.apply(waypoint, action == Action.LIST ? Action.INFO : action);
    if (action == Action.LIST) {
        IWaypoint.Tag tag = args.hasAny() ? IWaypoint.Tag.getByName(args.peekString()) : null;
        if (tag != null) {
            args.get();
        }
        IWaypoint[] waypoints = tag != null ? ForWaypoints.getWaypointsByTag(this.baritone, tag) : ForWaypoints.getWaypoints(this.baritone);
        if (waypoints.length > 0) {
            args.requireMax(1);
            Paginator.paginate(args, waypoints, () -> logDirect(tag != null ? String.format("All waypoints by tag %s:", tag.name()) : "All waypoints:"), transform, String.format("%s%s %s%s", FORCE_COMMAND_PREFIX, label, action.names[0], tag != null ? " " + tag.getName() : ""));
        } else {
            args.requireMax(0);
            throw new CommandInvalidStateException(tag != null ? "No waypoints found by that tag" : "No waypoints found");
        }
    } else if (action == Action.SAVE) {
        IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
        if (tag == null) {
            throw new CommandInvalidStateException(String.format("'%s' is not a tag ", args.consumedString()));
        }
        String name = args.hasAny() ? args.getString() : "";
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, ctx.playerFeet()) : ctx.playerFeet();
        args.requireMax(0);
        IWaypoint waypoint = new Waypoint(name, tag, pos);
        ForWaypoints.waypoints(this.baritone).addWaypoint(waypoint);
        ITextComponent component = new TextComponentString("Waypoint added: ");
        component.getStyle().setColor(TextFormatting.GRAY);
        component.appendSibling(toComponent.apply(waypoint, Action.INFO));
        logDirect(component);
    } else if (action == Action.CLEAR) {
        args.requireMax(1);
        IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
        IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(this.baritone, tag);
        for (IWaypoint waypoint : waypoints) {
            ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
        }
        logDirect(String.format("Cleared %d waypoints", waypoints.length));
    } else {
        IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
        IWaypoint waypoint = null;
        if (args.hasAny() && args.peekString().equals("@")) {
            args.requireExactly(2);
            args.get();
            long timestamp = args.getAs(Long.class);
            for (IWaypoint iWaypoint : waypoints) {
                if (iWaypoint.getCreationTimestamp() == timestamp) {
                    waypoint = iWaypoint;
                    break;
                }
            }
            if (waypoint == null) {
                throw new CommandInvalidStateException("Timestamp was specified but no waypoint was found");
            }
        } else {
            switch(waypoints.length) {
                case 0:
                    throw new CommandInvalidStateException("No waypoints found");
                case 1:
                    waypoint = waypoints[0];
                    break;
                default:
                    break;
            }
        }
        if (waypoint == null) {
            args.requireMax(1);
            Paginator.paginate(args, waypoints, () -> logDirect("Multiple waypoints were found:"), transform, String.format("%s%s %s %s", FORCE_COMMAND_PREFIX, label, action.names[0], args.consumedString()));
        } else {
            if (action == Action.INFO) {
                logDirect(transform.apply(waypoint));
                logDirect(String.format("Position: %s", waypoint.getLocation()));
                ITextComponent deleteComponent = new TextComponentString("Click to delete this waypoint");
                deleteComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s delete %s @ %d", FORCE_COMMAND_PREFIX, label, waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
                ITextComponent goalComponent = new TextComponentString("Click to set goal to this waypoint");
                goalComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s goal %s @ %d", FORCE_COMMAND_PREFIX, label, waypoint.getTag().getName(), waypoint.getCreationTimestamp())));
                ITextComponent backComponent = new TextComponentString("Click to return to the waypoints list");
                backComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s list", FORCE_COMMAND_PREFIX, label)));
                logDirect(deleteComponent);
                logDirect(goalComponent);
                logDirect(backComponent);
            } else if (action == Action.DELETE) {
                ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
                logDirect("That waypoint has successfully been deleted");
            } else if (action == Action.GOAL) {
                Goal goal = new GoalBlock(waypoint.getLocation());
                baritone.getCustomGoalProcess().setGoal(goal);
                logDirect(String.format("Goal: %s", goal));
            } else if (action == Action.GOTO) {
                Goal goal = new GoalBlock(waypoint.getLocation());
                baritone.getCustomGoalProcess().setGoalAndPath(goal);
                logDirect(String.format("Going to: %s", goal));
            }
        }
    }
}
Also used : java.util(java.util) TabCompleteHelper(baritone.api.command.helpers.TabCompleteHelper) Command(baritone.api.command.Command) BiFunction(java.util.function.BiFunction) ClickEvent(net.minecraft.util.text.event.ClickEvent) Waypoint(baritone.api.cache.Waypoint) IArgConsumer(baritone.api.command.argument.IArgConsumer) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) IBaritone(baritone.api.IBaritone) IWaypoint(baritone.api.cache.IWaypoint) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) ForWaypoints(baritone.api.command.datatypes.ForWaypoints) CommandException(baritone.api.command.exception.CommandException) TextFormatting(net.minecraft.util.text.TextFormatting) Paginator(baritone.api.command.helpers.Paginator) GoalBlock(baritone.api.pathing.goals.GoalBlock) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) FORCE_COMMAND_PREFIX(baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) Stream(java.util.stream.Stream) HoverEvent(net.minecraft.util.text.event.HoverEvent) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) HoverEvent(net.minecraft.util.text.event.HoverEvent) GoalBlock(baritone.api.pathing.goals.GoalBlock) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) Goal(baritone.api.pathing.goals.Goal) IWaypoint(baritone.api.cache.IWaypoint) BetterBlockPos(baritone.api.utils.BetterBlockPos) Waypoint(baritone.api.cache.Waypoint) IWaypoint(baritone.api.cache.IWaypoint) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Aggregations

CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)22 BetterBlockPos (baritone.api.utils.BetterBlockPos)9 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)7 CommandException (baritone.api.command.exception.CommandException)5 BlockPos (net.minecraft.util.math.BlockPos)5 IWaypoint (baritone.api.cache.IWaypoint)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 RelativeFile (baritone.api.command.datatypes.RelativeFile)4 IPathingControlManager (baritone.api.pathing.calc.IPathingControlManager)4 Goal (baritone.api.pathing.goals.Goal)4 GoalBlock (baritone.api.pathing.goals.GoalBlock)4 IBaritoneProcess (baritone.api.process.IBaritoneProcess)4 File (java.io.File)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 IBaritone (baritone.api.IBaritone)3 Command (baritone.api.command.Command)3 FORCE_COMMAND_PREFIX (baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX)3 IArgConsumer (baritone.api.command.argument.IArgConsumer)3 Paginator (baritone.api.command.helpers.Paginator)3 TabCompleteHelper (baritone.api.command.helpers.TabCompleteHelper)3