use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class MovementFall method buildPositionsToBreak.
private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) {
BetterBlockPos[] toBreak;
int diffX = src.getX() - dest.getX();
int diffZ = src.getZ() - dest.getZ();
int diffY = src.getY() - dest.getY();
toBreak = new BetterBlockPos[diffY + 2];
for (int i = 0; i < toBreak.length; i++) {
toBreak[i] = new BetterBlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ);
}
return toBreak;
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
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 = args.hasAny() ? IWaypoint.Tag.getByName(args.peekString()) : null;
if (tag == null) {
tag = IWaypoint.Tag.USER;
} else {
args.get();
}
String name = (args.hasExactlyOne() || args.hasExactly(4)) ? 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);
}
deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).addAll(Arrays.<IWaypoint>asList(waypoints));
ITextComponent textComponent = new TextComponentString(String.format("Cleared %d waypoints, click to restore them", waypoints.length));
textComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s restore @ %s", FORCE_COMMAND_PREFIX, label, Stream.of(waypoints).map(wp -> Long.toString(wp.getCreationTimestamp())).collect(Collectors.joining(" ")))));
logDirect(textComponent);
} else if (action == Action.RESTORE) {
List<IWaypoint> waypoints = new ArrayList<>();
List<IWaypoint> deletedWaypoints = this.deletedWaypoints.getOrDefault(baritone.getWorldProvider().getCurrentWorld(), Collections.emptyList());
if (args.peekString().equals("@")) {
args.get();
// no args.requireMin(1) because if the user clears an empty tag there is nothing to restore
while (args.hasAny()) {
long timestamp = args.getAs(Long.class);
for (IWaypoint waypoint : deletedWaypoints) {
if (waypoint.getCreationTimestamp() == timestamp) {
waypoints.add(waypoint);
break;
}
}
}
} else {
args.requireExactly(1);
int size = deletedWaypoints.size();
int amount = Math.min(size, args.getAs(Integer.class));
waypoints = new ArrayList<>(deletedWaypoints.subList(size - amount, size));
}
waypoints.forEach(ForWaypoints.waypoints(this.baritone)::addWaypoint);
deletedWaypoints.removeIf(waypoints::contains);
logDirect(String.format("Restored %d waypoints", waypoints.size()));
} 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 recreateComponent = new TextComponentString("Click to show a command to recreate this waypoint");
recreateComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("%s%s save %s %s %s %s %s", // This uses the normal prefix because it is run by the user.
Baritone.settings().prefix.value, label, waypoint.getTag().getName(), waypoint.getName(), waypoint.getLocation().x, waypoint.getLocation().y, waypoint.getLocation().z)));
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(recreateComponent);
logDirect(backComponent);
} else if (action == Action.DELETE) {
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).add(waypoint);
ITextComponent textComponent = new TextComponentString("That waypoint has successfully been deleted, click to restore it");
textComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("%s%s restore @ %s", FORCE_COMMAND_PREFIX, label, waypoint.getCreationTimestamp())));
logDirect(textComponent);
} 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));
}
}
}
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
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.value);
}
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));
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class FarmCommand method execute.
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(2);
int range = 0;
BetterBlockPos origin = null;
// range
if (args.has(1)) {
range = args.getAs(Integer.class);
}
// waypoint
if (args.has(1)) {
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
IWaypoint waypoint = null;
switch(waypoints.length) {
case 0:
throw new CommandInvalidStateException("No waypoints found");
case 1:
waypoint = waypoints[0];
break;
default:
throw new CommandInvalidStateException("Multiple waypoints were found");
}
origin = waypoint.getLocation();
}
baritone.getFarmProcess().farm(range, origin);
logDirect("Farming");
}
use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.
the class BuilderProcess method onTick.
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel, int recursions) {
if (recursions > 1000) {
// onTick calls itself, don't crash
return new PathingCommand(null, PathingCommandType.SET_GOAL_AND_PATH);
}
approxPlaceable = approxPlaceable(36);
if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
ticks = 5;
} else {
ticks--;
}
baritone.getInputOverrideHandler().clearAllKeys();
if (paused) {
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
if (Baritone.settings().buildInLayers.value) {
if (realSchematic == null) {
realSchematic = schematic;
}
// wrap this properly, dont just have the inner class refer to the builderprocess.this
ISchematic realSchematic = this.realSchematic;
int minYInclusive;
int maxYInclusive;
// layer = realSchematic.heightY() should be everything
if (Baritone.settings().layerOrder.value) {
// top to bottom
maxYInclusive = realSchematic.heightY() - 1;
minYInclusive = realSchematic.heightY() - layer * Baritone.settings().layerHeight.value;
} else {
maxYInclusive = layer * Baritone.settings().layerHeight.value - 1;
minYInclusive = 0;
}
schematic = new ISchematic() {
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
}
@Override
public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
}
@Override
public void reset() {
realSchematic.reset();
}
@Override
public int widthX() {
return realSchematic.widthX();
}
@Override
public int heightY() {
return realSchematic.heightY();
}
@Override
public int lengthZ() {
return realSchematic.lengthZ();
}
};
}
BuilderCalculationContext bcc = new BuilderCalculationContext();
if (!recalc(bcc)) {
if (Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) {
logDirect("Starting layer " + layer);
layer++;
return onTick(calcFailed, isSafeToCancel, recursions + 1);
}
Vec3i repeat = Baritone.settings().buildRepeat.value;
int max = Baritone.settings().buildRepeatCount.value;
numRepeats++;
if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
logDirect("Done building");
if (Baritone.settings().notificationOnBuildFinished.value) {
logNotification("Done building", false);
}
onLostControl();
return null;
}
// build repeat time
layer = 0;
origin = new BlockPos(origin).add(repeat);
if (!Baritone.settings().buildRepeatSneaky.value) {
schematic.reset();
}
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
return onTick(calcFailed, isSafeToCancel, recursions + 1);
}
if (Baritone.settings().distanceTrim.value) {
trim();
}
Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
// we'd like to pause to break this block
// only change look direction if it's safe (don't want to fuck up an in progress parkour for example
Rotation rot = toBreak.get().getSecond();
BetterBlockPos pos = toBreak.get().getFirst();
baritone.getLookBehavior().updateTarget(rot, true);
MovementHelper.switchToBestToolFor(ctx, bcc.get(pos));
if (ctx.player().isSneaking()) {
// really horrible bug where a block is visible for breaking while sneaking but not otherwise
// so you can't see it, it goes to place something else, sneaks, then the next tick it tries to break
// and is unable since it's unsneaked in the intermediary tick
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
}
if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<IBlockState> desirableOnHotbar = new ArrayList<>();
Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
if (Baritone.settings().allowInventory.value) {
ArrayList<Integer> usefulSlots = new ArrayList<>();
List<IBlockState> noValidHotbarOption = new ArrayList<>();
outer: for (IBlockState desired : desirableOnHotbar) {
for (int i = 0; i < 9; i++) {
if (valid(approxPlaceable.get(i), desired, true)) {
usefulSlots.add(i);
continue outer;
}
}
noValidHotbarOption.add(desired);
}
outer: for (int i = 9; i < 36; i++) {
for (IBlockState desired : noValidHotbarOption) {
if (valid(approxPlaceable.get(i), desired, true)) {
baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
break outer;
}
}
}
}
Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
if (goal == null) {
// we're far away, so assume that we have our whole inventory to recalculate placeable properly
goal = assemble(bcc, approxPlaceable, true);
if (goal == null) {
if (Baritone.settings().skipFailedLayers.value && Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) {
logDirect("Skipping layer that I cannot construct! Layer #" + layer);
layer++;
return onTick(calcFailed, isSafeToCancel, recursions + 1);
}
logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
paused = true;
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
}
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}
Aggregations