Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial support for multiple #goto targets #4104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/api/java/baritone/api/process/IGetToBlockProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@

import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.block.Block;
import java.util.List;
import java.util.Arrays;

/**
* but it rescans the world every once in a while so it doesn't get fooled by its cache
*/
public interface IGetToBlockProcess extends IBaritoneProcess {

void getToBlock(BlockOptionalMeta block);

default void getToBlock(BlockOptionalMeta block) {
getToBlock(Arrays.asList(block));
}
default void getToBlock(Block block) {
getToBlock(new BlockOptionalMeta(block));
}
void getToBlock(List<BlockOptionalMeta> blocks);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The List<BlockOptionalMeta> should be a BlockOptionalMetaLookup


boolean blacklistClosest();
}
9 changes: 6 additions & 3 deletions src/main/java/baritone/command/defaults/GotoCommand.java
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need to update the tab completion and help text.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import baritone.api.utils.BlockOptionalMeta;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

Expand All @@ -51,9 +52,11 @@ public void execute(String label, IArgConsumer args) throws CommandException {
baritone.getCustomGoalProcess().setGoalAndPath(goal);
return;
}
args.requireMax(1);
BlockOptionalMeta destination = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
baritone.getGetToBlockProcess().getToBlock(destination);
List<BlockOptionalMeta> destinations = new ArrayList<BlockOptionalMeta>();
while(args.hasAny()) {
destinations.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
}
baritone.getGetToBlockProcess().getToBlock(destinations);
}

@Override
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/baritone/process/GetToBlockProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@
import net.minecraft.util.math.BlockPos;

import java.util.*;
import java.util.stream.Collectors;

public final class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {

private BlockOptionalMeta gettingTo;
private List<BlockOptionalMeta> gettingTo;
private List<BlockPos> knownLocations;
private List<BlockPos> blacklist; // locations we failed to calc to
private BlockPos start;

private String strGettingTo() {
return gettingTo.stream().map(bom -> bom.toString()).collect(Collectors.joining("/"));
}

Comment on lines +48 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use the string representation of the BlockOptionalMetaLookup.

private int tickCount = 0;
private int arrivalTickCount = 0;

Expand All @@ -52,9 +57,9 @@ public GetToBlockProcess(Baritone baritone) {
}

@Override
public void getToBlock(BlockOptionalMeta block) {
public void getToBlock(List<BlockOptionalMeta> blocks) {
onLostControl();
gettingTo = block;
gettingTo = blocks;
start = ctx.playerFeet();
blacklist = new ArrayList<>();
arrivalTickCount = 0;
Expand Down Expand Up @@ -85,7 +90,7 @@ public double heuristic() {
}
}, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
}
logDirect("No known locations of " + gettingTo + ", canceling GetToBlock");
logDirect("No known locations of " + strGettingTo() + ", canceling GetToBlock");
if (isSafeToCancel) {
onLostControl();
}
Expand All @@ -94,11 +99,11 @@ public double heuristic() {
Goal goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new));
if (calcFailed) {
if (Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + gettingTo + ", blacklisting presumably unreachable closest instances...");
logDirect("Unable to find any path to " + strGettingTo() + ", blacklisting presumably unreachable closest instances...");
blacklistClosest();
return onTick(false, isSafeToCancel); // gamer moment
} else {
logDirect("Unable to find any path to " + gettingTo + ", canceling GetToBlock");
logDirect("Unable to find any path to " + strGettingTo() + ", canceling GetToBlock");
if (isSafeToCancel) {
onLostControl();
}
Expand All @@ -113,7 +118,8 @@ public double heuristic() {
}
if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) {
// we're there
if (rightClickOnArrival(gettingTo.getBlock())) {
// currently don't know matched position/BOM, so will only right click if all BOM's in gettingTo are right clickable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does certainly make things easier it will almost certainly result in false bug reports.
Maybe try clicking on any target location for which createGoal(pos).isInGoal(playerPos) is true and if there is no such position succeed right away.

if (!gettingTo.stream().anyMatch(bom -> !rightClickOnArrival(bom.getBlock()))) {
if (rightClick()) {
onLostControl();
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
Expand Down Expand Up @@ -187,22 +193,23 @@ public synchronized void onLostControl() {
@Override
public String displayName0() {
if (knownLocations.isEmpty()) {
return "Exploring randomly to find " + gettingTo + ", no known locations";
return "Exploring randomly to find " + strGettingTo() + ", no known locations";
}
return "Get To " + gettingTo + ", " + knownLocations.size() + " known locations";
return "Get To " + strGettingTo() + ", " + knownLocations.size() + " known locations";
}

private synchronized void rescan(List<BlockPos> known, CalculationContext context) {
List<BlockPos> positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo), 64, known, blacklist, Collections.emptyList());
List<BlockPos> positions = MineProcess.searchWorld(context, new BlockOptionalMetaLookup(gettingTo.toArray(new BlockOptionalMeta[0])), 64, known, blacklist, Collections.emptyList());
positions.removeIf(blacklist::contains);
knownLocations = positions;
}

private Goal createGoal(BlockPos pos) {
if (walkIntoInsteadOfAdjacent(gettingTo.getBlock())) {
// determines which actions to take (action done iff should be done for all target blocks))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to assume unclickable for unknown positions and decide per block for known positions.

if (!gettingTo.stream().anyMatch(bom -> !walkIntoInsteadOfAdjacent(bom.getBlock()))) {
return new GoalTwoBlocks(pos);
}
if (blockOnTopMustBeRemoved(gettingTo.getBlock()) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
if (!gettingTo.stream().anyMatch(bom -> !blockOnTopMustBeRemoved(bom.getBlock())) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
return new GoalBlock(pos.up());
}
return new GoalGetToBlock(pos);
Expand Down