use of baritone.api.cache.Waypoint in project baritone by cabaletta.
the class WaypointCollection method load.
private synchronized void load(Waypoint.Tag tag) {
this.waypoints.put(tag, new HashSet<>());
Path fileName = this.directory.resolve(tag.name().toLowerCase() + ".mp4");
if (!Files.exists(fileName)) {
return;
}
try (FileInputStream fileIn = new FileInputStream(fileName.toFile());
BufferedInputStream bufIn = new BufferedInputStream(fileIn);
DataInputStream in = new DataInputStream(bufIn)) {
long magic = in.readLong();
if (magic != WAYPOINT_MAGIC_VALUE) {
throw new IOException("Bad magic value " + magic);
}
// Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
long length = in.readLong();
while (length-- > 0) {
String name = in.readUTF();
long creationTimestamp = in.readLong();
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
}
} catch (IOException ignored) {
}
}
use of baritone.api.cache.Waypoint in project Spark-Client by Spark-Client-Development.
the class WaypointCollection method load.
private synchronized void load(Waypoint.Tag tag) {
this.waypoints.put(tag, new HashSet<>());
Path fileName = this.directory.resolve(tag.name().toLowerCase() + ".mp4");
if (!Files.exists(fileName)) {
return;
}
try (FileInputStream fileIn = new FileInputStream(fileName.toFile());
BufferedInputStream bufIn = new BufferedInputStream(fileIn);
DataInputStream in = new DataInputStream(bufIn)) {
long magic = in.readLong();
if (magic != WAYPOINT_MAGIC_VALUE) {
throw new IOException("Bad magic value " + magic);
}
// Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
long length = in.readLong();
while (length-- > 0) {
String name = in.readUTF();
long creationTimestamp = in.readLong();
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
}
} catch (IOException ignored) {
}
}
use of baritone.api.cache.Waypoint in project Spark-Client by Spark-Client-Development.
the class MemoryBehavior method onPlayerDeath.
@Override
public void onPlayerDeath() {
Waypoint deathWaypoint = new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet());
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(deathWaypoint);
ITextComponent component = new TextComponentString("Death position saved.");
component.getStyle().setColor(TextFormatting.WHITE).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to goto death"))).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s goto %s @ %d", FORCE_COMMAND_PREFIX, "wp", deathWaypoint.getTag().getName(), deathWaypoint.getCreationTimestamp())));
Helper.HELPER.logDirect(component);
}
use of baritone.api.cache.Waypoint in project Spark-Client by Spark-Client-Development.
the class MapGuiSubMenu method renderContent.
@Override
public void renderContent(int MouseX, int MouseY, float deltaTime) {
super.renderContent(MouseX, MouseY, deltaTime);
addWayPointButton.setText("Waypoint");
int lenGotoButton = 4 + fontManager.getTextWidth(gotoButton.getText());
int lenAddWayPointButton = 4 + fontManager.getTextWidth(addWayPointButton.getText());
width = 6 + lenGotoButton + lenAddWayPointButton;
RenderUtil.drawFilledCircle(posX, posY, 3, guiSettings.getContrastColor().getRGB());
drawQuad(posX, posY, width, height, guiSettings.getContrastColor().getRGB());
drawQuad(posX, posY, width, height, guiSettings.getGuiScreenBackgroundColor().getRGB());
height = 15;
if (addingWayPoint) {
inputField.setPositionAndSize(posX + 2, posY + 2, width - 4, 11);
inputField.setBackGroundColor(guiSettings.getGuiSubPanelBackgroundColor().getRGB());
inputField.renderContent(MouseX, MouseY, deltaTime);
addWayPointButton.setText("Add Waypoint");
addWayPointButton.setPositionAndSize(posX + 2, posY + 11 + 4, width - 4, 11);
addWayPointButton.renderContent(MouseX, MouseY, deltaTime);
height += 11 + 2;
} else {
gotoButton.setPositionAndSize(posX + 2, posY + 2, lenGotoButton, 11);
gotoButton.renderContent(MouseX, MouseY, deltaTime);
addWayPointButton.setText("Waypoint");
addWayPointButton.setPositionAndSize(posX + lenGotoButton + 4, posY + 2, lenAddWayPointButton, 11);
addWayPointButton.renderContent(MouseX, MouseY, deltaTime);
}
}
use of baritone.api.cache.Waypoint 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));
}
}
}
}
Aggregations