From c74c01271d54a48c52826c0be7361c40c0cc7ff8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 14:36:44 -0800 Subject: [PATCH] better strategy --- .../baritone/api/pathing/goals/GoalBlock.java | 6 +++--- .../pathing/movement/CalculationContext.java | 2 +- .../movement/movements/MovementTraverse.java | 14 ++++++++++++-- .../java/baritone/process/BuilderProcess.java | 17 +++++++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java index e0a60b59..89dd6304 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java @@ -30,17 +30,17 @@ public class GoalBlock implements Goal, IGoalRenderPos { /** * The X block position of this goal */ - private final int x; + public final int x; /** * The Y block position of this goal */ - private final int y; + public final int y; /** * The Z block position of this goal */ - private final int z; + public final int z; public GoalBlock(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 4611d975..95887efd 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -65,7 +65,7 @@ public class CalculationContext { public final int maxFallHeightBucket; public final double waterWalkSpeed; public final double breakBlockAdditionalCost; - public final double jumpPenalty; + public double jumpPenalty; public final double walkOnWaterOnePenalty; public final BetterWorldBorder worldBorder; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 9f7c0fdf..57bc333c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -275,14 +275,24 @@ public class MovementTraverse extends Movement { double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D; double faceY = (dest.getY() + against1.getY()) * 0.5D; double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D; - state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true)); + Rotation rot = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()); + state.setTarget(new MovementState.MovementTarget(rot, true)); EnumFacing side = ctx.objectMouseOver().sideHit; if (Objects.equals(ctx.getSelectedBlock().orElse(null), against1) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && ctx.getSelectedBlock().get().offset(side).equals(positionToPlace)) { return state.setInput(Input.CLICK_RIGHT, true); } + if (ctx.playerRotations().isReallyCloseTo(rot)) { + double dist = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D))); + if (dist > 0.83) { + // might need to go forward a bit + return state.setInput(Input.MOVE_FORWARD, true); + } + // don't left click for one tick + return state.setInput(Input.CLICK_LEFT, true); + } + return state; //System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock()); - return state.setInput(Input.CLICK_LEFT, true); } } if (!Baritone.settings().assumeSafeWalk.get()) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 27142120..b4b13725 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -215,7 +215,7 @@ public class BuilderProcess extends BaritoneProcessHelper { List approxPlacable = placable(); List placable = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() == Blocks.AIR && approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))).collect(Collectors.toList()); if (!placable.isEmpty()) { - return placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(BetterBlockPos::up).map(GoalBlock::new).toArray(Goal[]::new); + return placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(GoalPlace::new).toArray(Goal[]::new); } return incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() != Blocks.AIR).map(GoalBreak::new).toArray(Goal[]::new); } @@ -229,7 +229,7 @@ public class BuilderProcess extends BaritoneProcessHelper { @Override public boolean isInGoal(int x, int y, int z) { // can't stand right on top of a block, that might not work (what if it's unsupported, can't break then) - if (x == this.x && y == this.y + 1 && z == this.z) { + if (y > this.y) { return false; } // but any other adjacent works for breaking, including inside or below @@ -237,6 +237,17 @@ public class BuilderProcess extends BaritoneProcessHelper { } } + public static class GoalPlace extends GoalBlock { + public GoalPlace(BlockPos placeAt) { + super(placeAt.up()); + } + + public double heuristic(int x, int y, int z) { + // prioritize lower y coordinates + return this.y * 100 + super.heuristic(x, y, z); + } + } + @Override public void onLostControl() { incorrectPositions = null; @@ -290,6 +301,8 @@ public class BuilderProcess extends BaritoneProcessHelper { this.originX = schematicOrigin.getX(); this.originY = schematicOrigin.getY(); this.originZ = schematicOrigin.getZ(); + + this.jumpPenalty += 10; } private IBlockState getSchematic(int x, int y, int z) {