ignore y coordinate for distance, fixes #62

This commit is contained in:
Leijurv 2018-08-21 16:20:08 -07:00
parent 843bc17777
commit 86f45202d0
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 22 additions and 2 deletions

View File

@ -135,6 +135,15 @@ public class Settings {
*/ */
public Setting<Integer> maxFallHeight = new Setting<>(3); public Setting<Integer> maxFallHeight = new Setting<>(3);
/**
* If your goal is a GoalBlock in an unloaded chunk, assume it's far enough away that the Y coord
* doesn't matter yet, and replace it with a GoalXZ to the same place before calculating a path.
* Once a segment ends within chunk load range of the GoalBlock, it will go back to normal behavior
* of considering the Y coord. The reasoning is that if your X and Z are 10,000 blocks away,
* your Y coordinate's accuracy doesn't matter at all until you get much much closer.
*/
public Setting<Boolean> simplifyUnloadedYCoord = new Setting<>(true);
/** /**
* If a movement takes this many ticks more than its initial cost estimate, cancel it * If a movement takes this many ticks more than its initial cost estimate, cancel it
*/ */

View File

@ -26,12 +26,15 @@ import baritone.bot.pathing.calc.AStarPathFinder;
import baritone.bot.pathing.calc.AbstractNodeCostSearch; import baritone.bot.pathing.calc.AbstractNodeCostSearch;
import baritone.bot.pathing.calc.IPathFinder; import baritone.bot.pathing.calc.IPathFinder;
import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.goals.Goal;
import baritone.bot.pathing.goals.GoalBlock;
import baritone.bot.pathing.goals.GoalXZ;
import baritone.bot.pathing.path.IPath; import baritone.bot.pathing.path.IPath;
import baritone.bot.pathing.path.PathExecutor; import baritone.bot.pathing.path.PathExecutor;
import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.PathRenderer; import baritone.bot.utils.PathRenderer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
import java.awt.*; import java.awt.*;
import java.util.Collections; import java.util.Collections;
@ -258,10 +261,18 @@ public class PathingBehavior extends Behavior {
* @return * @return
*/ */
private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous) { private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous) {
Goal goal = this.goal;
if (goal == null) { if (goal == null) {
displayChatMessageRaw("no goal"); displayChatMessageRaw("no goal");
return Optional.empty(); return Optional.empty();
} }
if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof GoalBlock) {
BlockPos pos = ((GoalBlock) goal).getGoalPos();
if (world().getChunk(pos) instanceof EmptyChunk) {
displayChatMessageRaw("Simplifying GoalBlock to GoalXZ due to distance");
goal = new GoalXZ(pos.getX(), pos.getZ());
}
}
try { try {
IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions));
return pf.calculate(); return pf.calculate();

View File

@ -44,11 +44,11 @@ public class GoalYLevel implements Goal {
public double heuristic(BlockPos pos) { public double heuristic(BlockPos pos) {
if (pos.getY() > level) { if (pos.getY() > level) {
// need to descend // need to descend
return FALL_N_BLOCKS_COST[1] * (pos.getY() - level); return FALL_N_BLOCKS_COST[2] / 2 * (pos.getY() - level);
} }
if (pos.getY() < level) { if (pos.getY() < level) {
// need to ascend // need to ascend
return (level - pos.getY()) * JUMP_ONE_BLOCK_COST; return (level - pos.getY()) * JUMP_ONE_BLOCK_COST * 0.9;
} }
return 0; return 0;
} }