From ce329d7fb3d6678d0a24049da303bbbc0876a300 Mon Sep 17 00:00:00 2001 From: Logan Darklock Date: Sun, 1 Sep 2019 14:18:59 -0700 Subject: [PATCH] Waypoints command --- .../java/baritone/api/cache/IWaypoint.java | 6 +- src/api/java/baritone/api/cache/Waypoint.java | 10 +- .../api/utils/ExampleBaritoneControlOld.java | 4 +- .../command/argparser/DefaultArgParsers.java | 14 + .../utils/command/datatypes/ForWaypoints.java | 108 ++++++ .../command/datatypes/RelativeBlockPos.java | 6 +- .../command/defaults/DefaultCommands.java | 5 +- .../command/defaults/WaypointsCommand.java | 352 ++++++++++++++++++ .../helpers/arguments/ArgConsumer.java | 4 + .../command/helpers/pagination/Paginator.java | 55 ++- .../baritone/behavior/MemoryBehavior.java | 2 +- .../baritone/cache/WaypointCollection.java | 3 +- 12 files changed, 543 insertions(+), 26 deletions(-) create mode 100644 src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java create mode 100644 src/api/java/baritone/api/utils/command/defaults/WaypointsCommand.java diff --git a/src/api/java/baritone/api/cache/IWaypoint.java b/src/api/java/baritone/api/cache/IWaypoint.java index 01df2a48..23df5d39 100644 --- a/src/api/java/baritone/api/cache/IWaypoint.java +++ b/src/api/java/baritone/api/cache/IWaypoint.java @@ -17,7 +17,7 @@ package baritone.api.cache; -import net.minecraft.util.math.BlockPos; +import baritone.api.utils.BetterBlockPos; import org.apache.commons.lang3.ArrayUtils; import java.util.Arrays; @@ -60,7 +60,7 @@ public interface IWaypoint { * * @return The block position of this waypoint */ - BlockPos getLocation(); + BetterBlockPos getLocation(); enum Tag { @@ -92,7 +92,7 @@ public interface IWaypoint { /** * 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) { this.names = names; diff --git a/src/api/java/baritone/api/cache/Waypoint.java b/src/api/java/baritone/api/cache/Waypoint.java index 720e835e..f126de38 100644 --- a/src/api/java/baritone/api/cache/Waypoint.java +++ b/src/api/java/baritone/api/cache/Waypoint.java @@ -32,9 +32,9 @@ public class Waypoint implements IWaypoint { private final String name; private final Tag tag; 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()); } @@ -47,7 +47,7 @@ public class Waypoint implements IWaypoint { * @param location The waypoint location * @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.tag = tag; this.location = location; @@ -56,7 +56,7 @@ public class Waypoint implements IWaypoint { @Override public int hashCode() { - return name.hashCode() * tag.hashCode() * location.hashCode(); //lol + return name.hashCode() ^ tag.hashCode() ^ location.hashCode() ^ Long.hashCode(creationTimestamp); } @Override @@ -75,7 +75,7 @@ public class Waypoint implements IWaypoint { } @Override - public BlockPos getLocation() { + public BetterBlockPos getLocation() { return this.location; } diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java b/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java index 56f6976b..998a981f 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java @@ -575,7 +575,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe } if (msg.startsWith("save")) { String name = msg.substring(4).trim(); - BlockPos pos = ctx.playerFeet(); + BetterBlockPos pos = ctx.playerFeet(); if (name.contains(" ")) { logDirect("Name contains a space, assuming it's in the format 'save waypointName X Y Z'"); String[] parts = name.split(" "); @@ -584,7 +584,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe return true; } 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) { logDirect("Unable to parse coordinate integers"); return true; diff --git a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java b/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java index 03d3b5c9..ae80734d 100644 --- a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java +++ b/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java @@ -39,6 +39,19 @@ public class DefaultArgParsers { } } + public static class LongArgumentParser extends ArgParser implements IArgParser.Stateless { + 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 implements IArgParser.Stateless { public static final FloatArgumentParser INSTANCE = new FloatArgumentParser(); @@ -103,6 +116,7 @@ public class DefaultArgParsers { public static final List> all = Collections.unmodifiableList(asList( IntArgumentParser.INSTANCE, + LongArgumentParser.INSTANCE, FloatArgumentParser.INSTANCE, DoubleArgumentParser.INSTANCE, BooleanArgumentParser.INSTANCE diff --git a/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java b/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java new file mode 100644 index 00000000..6cc358e4 --- /dev/null +++ b/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java @@ -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 { + 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 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 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 found = new HashSet<>(); + + for (IWaypoint waypoint : getWaypoints()) { + if (waypoint.getName().equalsIgnoreCase(name)) { + found.add(waypoint); + } + } + + return found.toArray(new IWaypoint[0]); + } +} diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java b/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java index 788986b1..28c86e80 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java +++ b/src/api/java/baritone/api/utils/command/datatypes/RelativeBlockPos.java @@ -42,11 +42,9 @@ public class RelativeBlockPos implements IDatatypePost. + */ + +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 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 : ""); + 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 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 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 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 - Save your current position as an unnamed waypoint with the specified tag.", + "> wp - Save the waypoint with the specified name.", + "> wp - Save the waypoint with the specified name and position.", + "> wp - Show info on a waypoint by tag.", + "> wp - Delete a waypoint by tag.", + "> wp - 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 names = new HashSet<>(); + + for (Action action : Action.values()) { + names.addAll(asList(action.names)); + } + + return names.toArray(new String[0]); + } + } +} diff --git a/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java b/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java index df20d3b4..3cf823a0 100644 --- a/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java +++ b/src/api/java/baritone/api/utils/command/helpers/arguments/ArgConsumer.java @@ -300,6 +300,10 @@ public class ArgConsumer { return consumed.size() > 0 ? consumed.getLast() : CommandArgument.unknown(); } + public String consumedString() { + return consumed().value; + } + @SuppressWarnings("MethodDoesntCallSuperMethod") @Override public ArgConsumer clone() { diff --git a/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java b/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java index db7942b6..24d0b6a3 100644 --- a/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java +++ b/src/api/java/baritone/api/utils/command/helpers/pagination/Paginator.java @@ -29,6 +29,7 @@ import net.minecraft.util.text.event.HoverEvent; import java.util.List; import java.util.function.Function; +import static java.util.Arrays.asList; import static java.util.Objects.nonNull; public class Paginator implements Helper { @@ -40,6 +41,10 @@ public class Paginator implements Helper { this.entries = entries; } + public Paginator(E... entries) { + this.entries = asList(entries); + } + public Paginator setPageSize(int pageSize) { this.pageSize = pageSize; @@ -60,7 +65,7 @@ public class Paginator implements Helper { return this; } - public void display(Function transform, String commandFormat) { + public void display(Function transform, String commandPrefix) { int offset = (page - 1) * pageSize; for (int i = offset; i < offset + pageSize; i++) { @@ -71,8 +76,8 @@ public class Paginator implements Helper { } } - boolean hasPrevPage = nonNull(commandFormat) && validPage(page - 1); - boolean hasNextPage = nonNull(commandFormat) && validPage(page + 1); + boolean hasPrevPage = nonNull(commandPrefix) && validPage(page - 1); + boolean hasNextPage = nonNull(commandPrefix) && validPage(page + 1); logDirect(new TextComponentString("") {{ getStyle().setColor(TextFormatting.GRAY); @@ -82,7 +87,7 @@ public class Paginator implements Helper { getStyle() .setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, - String.format(commandFormat, page - 1) + String.format("%s %d", commandPrefix, page - 1) )) .setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, @@ -100,7 +105,7 @@ public class Paginator implements Helper { getStyle() .setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, - String.format(commandFormat, page + 1) + commandPrefix + " " + (page + 1) )) .setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, @@ -119,7 +124,7 @@ public class Paginator implements Helper { display(transform, null); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Runnable pre, Function transform, String commandFormat) { + public static void paginate(ArgConsumer consumer, Paginator pagi, Runnable pre, Function transform, String commandPrefix) { int page = 1; consumer.requireMax(1); @@ -145,18 +150,50 @@ public class Paginator implements Helper { pre.run(); } - pagi.display(transform, commandFormat); + pagi.display(transform, commandPrefix); } - public static void paginate(ArgConsumer consumer, Paginator pagi, Function transform, String commandName) { - paginate(consumer, pagi, null, transform, commandName); + public static void paginate(ArgConsumer consumer, List elems, Runnable pre, Function transform, String commandPrefix) { + paginate(consumer, new Paginator<>(elems), pre, transform, commandPrefix); + } + + public static void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function transform, String commandPrefix) { + paginate(consumer, asList(elems), pre, transform, commandPrefix); + } + + public static void paginate(ArgConsumer consumer, Paginator pagi, Function transform, String commandPrefix) { + paginate(consumer, pagi, null, transform, commandPrefix); + } + + public static void paginate(ArgConsumer consumer, List elems, Function transform, String commandPrefix) { + paginate(consumer, new Paginator<>(elems), null, transform, commandPrefix); + } + + public static void paginate(ArgConsumer consumer, T[] elems, Function transform, String commandPrefix) { + paginate(consumer, asList(elems), null, transform, commandPrefix); } public static void paginate(ArgConsumer consumer, Paginator pagi, Runnable pre, Function transform) { paginate(consumer, pagi, pre, transform, null); } + public static void paginate(ArgConsumer consumer, List elems, Runnable pre, Function transform) { + paginate(consumer, new Paginator<>(elems), pre, transform, null); + } + + public static void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function transform) { + paginate(consumer, asList(elems), pre, transform, null); + } + public static void paginate(ArgConsumer consumer, Paginator pagi, Function transform) { paginate(consumer, pagi, null, transform, null); } + + public static void paginate(ArgConsumer consumer, List elems, Function transform) { + paginate(consumer, new Paginator<>(elems), null, transform, null); + } + + public static void paginate(ArgConsumer consumer, T[] elems, Function transform) { + paginate(consumer, asList(elems), null, transform, null); + } } diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 5caee6a3..aac6b554 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -160,7 +160,7 @@ public final class MemoryBehavior extends Behavior { @Override public void onBlockInteract(BlockInteractEvent event) { 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()))); } } diff --git a/src/main/java/baritone/cache/WaypointCollection.java b/src/main/java/baritone/cache/WaypointCollection.java index 18b13b89..448dddd3 100644 --- a/src/main/java/baritone/cache/WaypointCollection.java +++ b/src/main/java/baritone/cache/WaypointCollection.java @@ -20,6 +20,7 @@ package baritone.cache; import baritone.api.cache.IWaypoint; import baritone.api.cache.IWaypointCollection; import baritone.api.cache.Waypoint; +import baritone.api.utils.BetterBlockPos; import net.minecraft.util.math.BlockPos; import java.io.*; @@ -86,7 +87,7 @@ public class WaypointCollection implements IWaypointCollection { int x = in.readInt(); int y = 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) {} }