Waypoints command
This commit is contained in:
parent
287615b0a1
commit
ce329d7fb3
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package baritone.api.cache;
|
package baritone.api.cache;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -60,7 +60,7 @@ public interface IWaypoint {
|
|||||||
*
|
*
|
||||||
* @return The block position of this waypoint
|
* @return The block position of this waypoint
|
||||||
*/
|
*/
|
||||||
BlockPos getLocation();
|
BetterBlockPos getLocation();
|
||||||
|
|
||||||
enum Tag {
|
enum Tag {
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public interface IWaypoint {
|
|||||||
/**
|
/**
|
||||||
* The names for the tag, anything that the tag can be referred to as.
|
* The names for the tag, anything that the tag can be referred to as.
|
||||||
*/
|
*/
|
||||||
private final String[] names;
|
public final String[] names;
|
||||||
|
|
||||||
Tag(String... names) {
|
Tag(String... names) {
|
||||||
this.names = names;
|
this.names = names;
|
||||||
|
10
src/api/java/baritone/api/cache/Waypoint.java
vendored
10
src/api/java/baritone/api/cache/Waypoint.java
vendored
@ -32,9 +32,9 @@ public class Waypoint implements IWaypoint {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final Tag tag;
|
private final Tag tag;
|
||||||
private final long creationTimestamp;
|
private final long creationTimestamp;
|
||||||
private final BlockPos location;
|
private final BetterBlockPos location;
|
||||||
|
|
||||||
public Waypoint(String name, Tag tag, BlockPos location) {
|
public Waypoint(String name, Tag tag, BetterBlockPos location) {
|
||||||
this(name, tag, location, System.currentTimeMillis());
|
this(name, tag, location, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class Waypoint implements IWaypoint {
|
|||||||
* @param location The waypoint location
|
* @param location The waypoint location
|
||||||
* @param creationTimestamp When the waypoint was created
|
* @param creationTimestamp When the waypoint was created
|
||||||
*/
|
*/
|
||||||
public Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {
|
public Waypoint(String name, Tag tag, BetterBlockPos location, long creationTimestamp) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
@ -56,7 +56,7 @@ public class Waypoint implements IWaypoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return name.hashCode() * tag.hashCode() * location.hashCode(); //lol
|
return name.hashCode() ^ tag.hashCode() ^ location.hashCode() ^ Long.hashCode(creationTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,7 +75,7 @@ public class Waypoint implements IWaypoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos getLocation() {
|
public BetterBlockPos getLocation() {
|
||||||
return this.location;
|
return this.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe
|
|||||||
}
|
}
|
||||||
if (msg.startsWith("save")) {
|
if (msg.startsWith("save")) {
|
||||||
String name = msg.substring(4).trim();
|
String name = msg.substring(4).trim();
|
||||||
BlockPos pos = ctx.playerFeet();
|
BetterBlockPos pos = ctx.playerFeet();
|
||||||
if (name.contains(" ")) {
|
if (name.contains(" ")) {
|
||||||
logDirect("Name contains a space, assuming it's in the format 'save waypointName X Y Z'");
|
logDirect("Name contains a space, assuming it's in the format 'save waypointName X Y Z'");
|
||||||
String[] parts = name.split(" ");
|
String[] parts = name.split(" ");
|
||||||
@ -584,7 +584,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
pos = new BlockPos(Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]));
|
pos = new BetterBlockPos(Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]));
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
logDirect("Unable to parse coordinate integers");
|
logDirect("Unable to parse coordinate integers");
|
||||||
return true;
|
return true;
|
||||||
|
@ -39,6 +39,19 @@ public class DefaultArgParsers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LongArgumentParser extends ArgParser<Long> implements IArgParser.Stateless<Long> {
|
||||||
|
public static final LongArgumentParser INSTANCE = new LongArgumentParser();
|
||||||
|
|
||||||
|
public LongArgumentParser() {
|
||||||
|
super(Long.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long parseArg(CommandArgument arg) throws RuntimeException {
|
||||||
|
return Long.parseLong(arg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class FloatArgumentParser extends ArgParser<Float> implements IArgParser.Stateless<Float> {
|
public static class FloatArgumentParser extends ArgParser<Float> implements IArgParser.Stateless<Float> {
|
||||||
public static final FloatArgumentParser INSTANCE = new FloatArgumentParser();
|
public static final FloatArgumentParser INSTANCE = new FloatArgumentParser();
|
||||||
|
|
||||||
@ -103,6 +116,7 @@ public class DefaultArgParsers {
|
|||||||
|
|
||||||
public static final List<ArgParser<?>> all = Collections.unmodifiableList(asList(
|
public static final List<ArgParser<?>> all = Collections.unmodifiableList(asList(
|
||||||
IntArgumentParser.INSTANCE,
|
IntArgumentParser.INSTANCE,
|
||||||
|
LongArgumentParser.INSTANCE,
|
||||||
FloatArgumentParser.INSTANCE,
|
FloatArgumentParser.INSTANCE,
|
||||||
DoubleArgumentParser.INSTANCE,
|
DoubleArgumentParser.INSTANCE,
|
||||||
BooleanArgumentParser.INSTANCE
|
BooleanArgumentParser.INSTANCE
|
||||||
|
@ -0,0 +1,108 @@
|
|||||||
|
package baritone.api.utils.command.datatypes;
|
||||||
|
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.cache.IWaypoint;
|
||||||
|
import baritone.api.cache.IWaypointCollection;
|
||||||
|
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||||
|
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
|
||||||
|
private final IWaypoint[] waypoints;
|
||||||
|
|
||||||
|
public ForWaypoints() {
|
||||||
|
waypoints = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForWaypoints(String arg) {
|
||||||
|
IWaypoint.Tag tag = getTagByName(arg);
|
||||||
|
waypoints = tag == null ? getWaypointsByName(arg) : getWaypointsByTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForWaypoints(ArgConsumer consumer) {
|
||||||
|
this(consumer.getString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWaypoint[] get() {
|
||||||
|
return waypoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||||
|
return new TabCompleteHelper()
|
||||||
|
.append(getWaypointNames())
|
||||||
|
.sortAlphabetically()
|
||||||
|
.prepend(getTagNames())
|
||||||
|
.filterPrefix(consumer.getString())
|
||||||
|
.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWaypointCollection waypoints() {
|
||||||
|
return BaritoneAPI.getProvider()
|
||||||
|
.getPrimaryBaritone()
|
||||||
|
.getWorldProvider()
|
||||||
|
.getCurrentWorld()
|
||||||
|
.getWaypoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getTagNames() {
|
||||||
|
Set<String> names = new HashSet<>();
|
||||||
|
|
||||||
|
for (IWaypoint.Tag tag : IWaypoint.Tag.values()) {
|
||||||
|
names.addAll(asList(tag.names));
|
||||||
|
}
|
||||||
|
|
||||||
|
return names.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWaypoint.Tag getTagByName(String name) {
|
||||||
|
for (IWaypoint.Tag tag : IWaypoint.Tag.values()) {
|
||||||
|
for (String alias : tag.names) {
|
||||||
|
if (alias.equalsIgnoreCase(name)) {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWaypoint[] getWaypoints() {
|
||||||
|
return waypoints().getAllWaypoints().stream()
|
||||||
|
.sorted(Comparator.comparingLong(IWaypoint::getCreationTimestamp).reversed())
|
||||||
|
.toArray(IWaypoint[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getWaypointNames() {
|
||||||
|
return Arrays.stream(getWaypoints())
|
||||||
|
.map(IWaypoint::getName)
|
||||||
|
.filter(name -> !name.equals(""))
|
||||||
|
.toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWaypoint[] getWaypointsByTag(IWaypoint.Tag tag) {
|
||||||
|
return waypoints().getByTag(tag).stream()
|
||||||
|
.sorted(Comparator.comparingLong(IWaypoint::getCreationTimestamp).reversed())
|
||||||
|
.toArray(IWaypoint[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWaypoint[] getWaypointsByName(String name) {
|
||||||
|
Set<IWaypoint> found = new HashSet<>();
|
||||||
|
|
||||||
|
for (IWaypoint waypoint : getWaypoints()) {
|
||||||
|
if (waypoint.getName().equalsIgnoreCase(name)) {
|
||||||
|
found.add(waypoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found.toArray(new IWaypoint[0]);
|
||||||
|
}
|
||||||
|
}
|
@ -42,11 +42,9 @@ public class RelativeBlockPos implements IDatatypePost<BetterBlockPos, BetterBlo
|
|||||||
}
|
}
|
||||||
|
|
||||||
consumer.get();
|
consumer.get();
|
||||||
|
|
||||||
if (!consumer.has(2)) {
|
|
||||||
return consumer.tabCompleteDatatype(RelativeCoordinate.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return consumer.tabCompleteDatatype(RelativeCoordinate.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Stream.empty();
|
return Stream.empty();
|
||||||
|
@ -61,6 +61,9 @@ public class DefaultCommands {
|
|||||||
new FindCommand(),
|
new FindCommand(),
|
||||||
new MineCommand(),
|
new MineCommand(),
|
||||||
new ClickCommand(),
|
new ClickCommand(),
|
||||||
new ThisWayCommand()
|
new ThisWayCommand(),
|
||||||
|
new WaypointsCommand(),
|
||||||
|
new CommandAlias("sethome", "Sets your home waypoint", "waypoints save home"),
|
||||||
|
new CommandAlias("home", "Set goal to your home waypoint", "waypoints goal home")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,352 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.utils.command.defaults;
|
||||||
|
|
||||||
|
import baritone.api.Settings;
|
||||||
|
import baritone.api.cache.IWaypoint;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
|
import baritone.api.pathing.goals.Goal;
|
||||||
|
import baritone.api.pathing.goals.GoalBlock;
|
||||||
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.command.Command;
|
||||||
|
import baritone.api.utils.command.datatypes.ForWaypoints;
|
||||||
|
import baritone.api.utils.command.datatypes.RelativeBlockPos;
|
||||||
|
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||||
|
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||||
|
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||||
|
import baritone.api.utils.command.helpers.pagination.Paginator;
|
||||||
|
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraft.util.text.event.ClickEvent;
|
||||||
|
import net.minecraft.util.text.event.HoverEvent;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static baritone.api.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
public class WaypointsCommand extends Command {
|
||||||
|
public WaypointsCommand() {
|
||||||
|
super(asList("waypoints", "waypoint", "wp"), "Manage waypoints");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||||
|
Action action = args.has() ? 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().names[0],
|
||||||
|
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.has() ? ForWaypoints.getTagByName(args.peekString()) : null;
|
||||||
|
|
||||||
|
if (tag != null) {
|
||||||
|
args.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
IWaypoint[] waypoints = tag != null
|
||||||
|
? ForWaypoints.getWaypointsByTag(tag)
|
||||||
|
: ForWaypoints.getWaypoints();
|
||||||
|
|
||||||
|
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.names[0] : ""
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} 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 = ForWaypoints.getTagByName(args.getString());
|
||||||
|
|
||||||
|
if (tag == null) {
|
||||||
|
throw new CommandInvalidStateException(String.format("'%s' is not a tag ", args.consumedString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = args.has() ? args.getString() : "";
|
||||||
|
BetterBlockPos pos = args.has()
|
||||||
|
? args.getDatatypePost(RelativeBlockPos.class, ctx.playerFeet())
|
||||||
|
: ctx.playerFeet();
|
||||||
|
|
||||||
|
args.requireMax(0);
|
||||||
|
|
||||||
|
IWaypoint waypoint = new Waypoint(name, tag, pos);
|
||||||
|
ForWaypoints.waypoints().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 = ForWaypoints.getTagByName(args.getString());
|
||||||
|
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(tag);
|
||||||
|
|
||||||
|
for (IWaypoint waypoint : waypoints) {
|
||||||
|
ForWaypoints.waypoints().removeWaypoint(waypoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
logDirect(String.format("Cleared %d waypoints", waypoints.length));
|
||||||
|
} else {
|
||||||
|
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.class);
|
||||||
|
IWaypoint waypoint = null;
|
||||||
|
|
||||||
|
if (args.has() && 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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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().names[0],
|
||||||
|
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().names[0],
|
||||||
|
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().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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||||
|
if (args.has()) {
|
||||||
|
if (args.hasExactlyOne()) {
|
||||||
|
return new TabCompleteHelper()
|
||||||
|
.append(Action.getAllNames())
|
||||||
|
.sortAlphabetically()
|
||||||
|
.filterPrefix(args.getString())
|
||||||
|
.stream();
|
||||||
|
} else {
|
||||||
|
Action action = Action.getByName(args.getString());
|
||||||
|
|
||||||
|
if (args.hasExactlyOne()) {
|
||||||
|
if (action == Action.LIST || action == Action.SAVE || action == Action.CLEAR) {
|
||||||
|
return new TabCompleteHelper()
|
||||||
|
.append(ForWaypoints.getTagNames())
|
||||||
|
.sortAlphabetically()
|
||||||
|
.filterPrefix(args.getString())
|
||||||
|
.stream();
|
||||||
|
} else {
|
||||||
|
return args.tabCompleteDatatype(ForWaypoints.class);
|
||||||
|
}
|
||||||
|
} else if (args.has(3) && action == Action.SAVE) {
|
||||||
|
args.get();
|
||||||
|
args.get();
|
||||||
|
return args.tabCompleteDatatype(RelativeBlockPos.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Stream.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getLongDesc() {
|
||||||
|
return asList(
|
||||||
|
"The waypoint command allows you to manage Baritone's waypoints.",
|
||||||
|
"",
|
||||||
|
"Waypoints can be used to mark positions for later. Waypoints are each given a tag and an optional name.",
|
||||||
|
"",
|
||||||
|
"Note that the info, delete, and goal commands let you specify a waypoint by tag. If there is more than one waypoint with a certain tag, then they will let you select which waypoint you mean.",
|
||||||
|
"",
|
||||||
|
"Usage:",
|
||||||
|
"> wp [l/list] - List all waypoints.",
|
||||||
|
"> wp <s/save> <tag> - Save your current position as an unnamed waypoint with the specified tag.",
|
||||||
|
"> wp <s/save> <tag> <name> - Save the waypoint with the specified name.",
|
||||||
|
"> wp <s/save> <tag> <name> <pos> - Save the waypoint with the specified name and position.",
|
||||||
|
"> wp <i/info/show> <tag> - Show info on a waypoint by tag.",
|
||||||
|
"> wp <d/delete> <tag> - Delete a waypoint by tag.",
|
||||||
|
"> wp <g/goal/goto> <tag> - Set a goal to a waypoint by tag."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Action {
|
||||||
|
LIST("list", "get", "l"),
|
||||||
|
CLEAR("clear", "c"),
|
||||||
|
SAVE("save", "s"),
|
||||||
|
INFO("info", "show", "i"),
|
||||||
|
DELETE("delete", "d"),
|
||||||
|
GOAL("goal", "goto", "g");
|
||||||
|
|
||||||
|
private final String[] names;
|
||||||
|
|
||||||
|
Action(String... names) {
|
||||||
|
this.names = names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Action getByName(String name) {
|
||||||
|
for (Action action : Action.values()) {
|
||||||
|
for (String alias : action.names) {
|
||||||
|
if (alias.equalsIgnoreCase(name)) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getAllNames() {
|
||||||
|
Set<String> names = new HashSet<>();
|
||||||
|
|
||||||
|
for (Action action : Action.values()) {
|
||||||
|
names.addAll(asList(action.names));
|
||||||
|
}
|
||||||
|
|
||||||
|
return names.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -300,6 +300,10 @@ public class ArgConsumer {
|
|||||||
return consumed.size() > 0 ? consumed.getLast() : CommandArgument.unknown();
|
return consumed.size() > 0 ? consumed.getLast() : CommandArgument.unknown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String consumedString() {
|
||||||
|
return consumed().value;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||||
@Override
|
@Override
|
||||||
public ArgConsumer clone() {
|
public ArgConsumer clone() {
|
||||||
|
@ -29,6 +29,7 @@ import net.minecraft.util.text.event.HoverEvent;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class Paginator<E> implements Helper {
|
public class Paginator<E> implements Helper {
|
||||||
@ -40,6 +41,10 @@ public class Paginator<E> implements Helper {
|
|||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Paginator(E... entries) {
|
||||||
|
this.entries = asList(entries);
|
||||||
|
}
|
||||||
|
|
||||||
public Paginator<E> setPageSize(int pageSize) {
|
public Paginator<E> setPageSize(int pageSize) {
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
|
|
||||||
@ -60,7 +65,7 @@ public class Paginator<E> implements Helper {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(Function<E, ITextComponent> transform, String commandFormat) {
|
public void display(Function<E, ITextComponent> transform, String commandPrefix) {
|
||||||
int offset = (page - 1) * pageSize;
|
int offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
for (int i = offset; i < offset + pageSize; i++) {
|
for (int i = offset; i < offset + pageSize; i++) {
|
||||||
@ -71,8 +76,8 @@ public class Paginator<E> implements Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasPrevPage = nonNull(commandFormat) && validPage(page - 1);
|
boolean hasPrevPage = nonNull(commandPrefix) && validPage(page - 1);
|
||||||
boolean hasNextPage = nonNull(commandFormat) && validPage(page + 1);
|
boolean hasNextPage = nonNull(commandPrefix) && validPage(page + 1);
|
||||||
|
|
||||||
logDirect(new TextComponentString("") {{
|
logDirect(new TextComponentString("") {{
|
||||||
getStyle().setColor(TextFormatting.GRAY);
|
getStyle().setColor(TextFormatting.GRAY);
|
||||||
@ -82,7 +87,7 @@ public class Paginator<E> implements Helper {
|
|||||||
getStyle()
|
getStyle()
|
||||||
.setClickEvent(new ClickEvent(
|
.setClickEvent(new ClickEvent(
|
||||||
ClickEvent.Action.RUN_COMMAND,
|
ClickEvent.Action.RUN_COMMAND,
|
||||||
String.format(commandFormat, page - 1)
|
String.format("%s %d", commandPrefix, page - 1)
|
||||||
))
|
))
|
||||||
.setHoverEvent(new HoverEvent(
|
.setHoverEvent(new HoverEvent(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
HoverEvent.Action.SHOW_TEXT,
|
||||||
@ -100,7 +105,7 @@ public class Paginator<E> implements Helper {
|
|||||||
getStyle()
|
getStyle()
|
||||||
.setClickEvent(new ClickEvent(
|
.setClickEvent(new ClickEvent(
|
||||||
ClickEvent.Action.RUN_COMMAND,
|
ClickEvent.Action.RUN_COMMAND,
|
||||||
String.format(commandFormat, page + 1)
|
commandPrefix + " " + (page + 1)
|
||||||
))
|
))
|
||||||
.setHoverEvent(new HoverEvent(
|
.setHoverEvent(new HoverEvent(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
HoverEvent.Action.SHOW_TEXT,
|
||||||
@ -119,7 +124,7 @@ public class Paginator<E> implements Helper {
|
|||||||
display(transform, null);
|
display(transform, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform, String commandFormat) {
|
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
int page = 1;
|
int page = 1;
|
||||||
|
|
||||||
consumer.requireMax(1);
|
consumer.requireMax(1);
|
||||||
@ -145,18 +150,50 @@ public class Paginator<E> implements Helper {
|
|||||||
pre.run();
|
pre.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
pagi.display(transform, commandFormat);
|
pagi.display(transform, commandPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform, String commandName) {
|
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
paginate(consumer, pagi, null, transform, commandName);
|
paginate(consumer, new Paginator<>(elems), pre, transform, commandPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
|
paginate(consumer, asList(elems), pre, transform, commandPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
|
paginate(consumer, pagi, null, transform, commandPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
|
paginate(consumer, new Paginator<>(elems), null, transform, commandPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||||
|
paginate(consumer, asList(elems), null, transform, commandPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform) {
|
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform) {
|
||||||
paginate(consumer, pagi, pre, transform, null);
|
paginate(consumer, pagi, pre, transform, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform) {
|
||||||
|
paginate(consumer, new Paginator<>(elems), pre, transform, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform) {
|
||||||
|
paginate(consumer, asList(elems), pre, transform, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform) {
|
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform) {
|
||||||
paginate(consumer, pagi, null, transform, null);
|
paginate(consumer, pagi, null, transform, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform) {
|
||||||
|
paginate(consumer, new Paginator<>(elems), null, transform, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform) {
|
||||||
|
paginate(consumer, asList(elems), null, transform, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
|
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
|
||||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos()));
|
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, BetterBlockPos.from(event.getPos())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ package baritone.cache;
|
|||||||
import baritone.api.cache.IWaypoint;
|
import baritone.api.cache.IWaypoint;
|
||||||
import baritone.api.cache.IWaypointCollection;
|
import baritone.api.cache.IWaypointCollection;
|
||||||
import baritone.api.cache.Waypoint;
|
import baritone.api.cache.Waypoint;
|
||||||
|
import baritone.api.utils.BetterBlockPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -86,7 +87,7 @@ public class WaypointCollection implements IWaypointCollection {
|
|||||||
int x = in.readInt();
|
int x = in.readInt();
|
||||||
int y = in.readInt();
|
int y = in.readInt();
|
||||||
int z = in.readInt();
|
int z = in.readInt();
|
||||||
this.waypoints.get(tag).add(new Waypoint(name, tag, new BlockPos(x, y, z), creationTimestamp));
|
this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user