-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use the string representation of the |
||
private int tickCount = 0; | ||
private int arrivalTickCount = 0; | ||
|
||
|
@@ -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; | ||
|
@@ -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(); | ||
} | ||
|
@@ -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(); | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (!gettingTo.stream().anyMatch(bom -> !rightClickOnArrival(bom.getBlock()))) { | ||
if (rightClick()) { | ||
onLostControl(); | ||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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 aBlockOptionalMetaLookup