simplification support for more goal types

This commit is contained in:
leijurv 2018-08-28 08:55:56 -07:00
parent c404258b00
commit 46fefa9298
4 changed files with 34 additions and 8 deletions

View File

@ -26,9 +26,7 @@ import baritone.api.event.events.TickEvent;
import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AStarPathFinder;
import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.calc.IPathFinder; import baritone.pathing.calc.IPathFinder;
import baritone.pathing.goals.Goal; import baritone.pathing.goals.*;
import baritone.pathing.goals.GoalBlock;
import baritone.pathing.goals.GoalXZ;
import baritone.pathing.path.IPath; import baritone.pathing.path.IPath;
import baritone.pathing.path.PathExecutor; import baritone.pathing.path.PathExecutor;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
@ -293,10 +291,23 @@ public class PathingBehavior extends Behavior {
displayChatMessageRaw("no goal"); displayChatMessageRaw("no goal");
return Optional.empty(); return Optional.empty();
} }
if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof GoalBlock) { if (Baritone.settings().simplifyUnloadedYCoord.get()) {
BlockPos pos = ((GoalBlock) goal).getGoalPos(); BlockPos pos = null;
if (world().getChunk(pos) instanceof EmptyChunk) { if (goal instanceof GoalBlock) {
displayChatMessageRaw("Simplifying GoalBlock to GoalXZ due to distance"); pos = ((GoalBlock) goal).getGoalPos();
}
if (goal instanceof GoalTwoBlocks) {
pos = ((GoalTwoBlocks) goal).getGoalPos();
}
if (goal instanceof GoalNear) {
pos = ((GoalNear) goal).getGoalPos();
}
if (goal instanceof GoalGetToBlock) {
pos = ((GoalGetToBlock) goal).getGoalPos();
}
// TODO simplify each individual goal in a GoalComposite
if (pos != null && world().getChunk(pos) instanceof EmptyChunk) {
displayChatMessageRaw("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
goal = new GoalXZ(pos.getX(), pos.getZ()); goal = new GoalXZ(pos.getX(), pos.getZ());
} }
} }
@ -304,7 +315,7 @@ public class PathingBehavior extends Behavior {
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();
} catch (Exception e) { } catch (Exception e) {
displayChatMessageRaw("Exception: " + e); displayChatMessageRaw("Pathing exception: " + e);
e.printStackTrace(); e.printStackTrace();
return Optional.empty(); return Optional.empty();
} }

View File

@ -27,8 +27,11 @@ import net.minecraft.util.math.BlockPos;
*/ */
public class GoalGetToBlock extends GoalComposite { public class GoalGetToBlock extends GoalComposite {
private final BlockPos pos;
public GoalGetToBlock(BlockPos pos) { public GoalGetToBlock(BlockPos pos) {
super(adjacentBlocks(pos)); super(adjacentBlocks(pos));
this.pos = pos;
} }
private static BlockPos[] adjacentBlocks(BlockPos pos) { private static BlockPos[] adjacentBlocks(BlockPos pos) {
@ -38,4 +41,8 @@ public class GoalGetToBlock extends GoalComposite {
} }
return sides; return sides;
} }
public BlockPos getGoalPos() {
return pos;
}
} }

View File

@ -47,4 +47,8 @@ public class GoalNear implements Goal {
int diffZ = z - pos.getZ(); int diffZ = z - pos.getZ();
return GoalBlock.calculate(diffX, diffY, diffZ); return GoalBlock.calculate(diffX, diffY, diffZ);
} }
public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
} }

View File

@ -68,6 +68,10 @@ public class GoalTwoBlocks implements Goal {
return GoalBlock.calculate(xDiff, yDiff, zDiff); return GoalBlock.calculate(xDiff, yDiff, zDiff);
} }
public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
@Override @Override
public String toString() { public String toString() {
return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}"; return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}";