add goal axis and fix movement fall path detection
This commit is contained in:
parent
a978ddec08
commit
27b9324cf1
@ -338,6 +338,11 @@ public class Settings {
|
||||
*/
|
||||
public Setting<Boolean> cancelOnGoalInvalidation = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* The "axis" command (aka GoalAxis) will go to a axis, or diagonal axis, at this Y level.
|
||||
*/
|
||||
public Setting<Integer> axisHeight = new Setting<>(120);
|
||||
|
||||
public final Map<String, Setting<?>> byLowerName;
|
||||
public final List<Setting<?>> allSettings;
|
||||
|
||||
|
54
src/main/java/baritone/pathing/goals/GoalAxis.java
Normal file
54
src/main/java/baritone/pathing/goals/GoalAxis.java
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.Baritone;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class GoalAxis implements Goal {
|
||||
|
||||
private static final double SQRT_2_OVER_2 = Math.sqrt(2) / 2;
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
return y == Baritone.settings().axisHeight.get() && (x == 0 || z == 0 || Math.abs(x) == Math.abs(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {
|
||||
int x = Math.abs(pos.getX());
|
||||
int y = pos.getY();
|
||||
int z = Math.abs(pos.getZ());
|
||||
|
||||
int shrt = Math.min(x, z);
|
||||
int lng = Math.max(x, z);
|
||||
int diff = lng - shrt;
|
||||
|
||||
double flatAxisDistance = Math.min(x, Math.min(z, diff * SQRT_2_OVER_2));
|
||||
|
||||
return flatAxisDistance * Baritone.settings().costHeuristic.get() + GoalYLevel.calculate(Baritone.settings().axisHeight.get(), y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalAxis";
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class GoalBlock implements Goal, IGoalRenderPos {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}";
|
||||
return "GoalBlock{x=" + x + ",y=" + y + ",z=" + z + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +92,7 @@ public class GoalBlock implements Goal, IGoalRenderPos {
|
||||
|
||||
// if yDiff is 1 that means that pos.getY()-this.y==1 which means that we're 1 block below where we should be
|
||||
// therefore going from 0,0,0 to a GoalYLevel of pos.getY()-this.y is accurate
|
||||
heuristic += new GoalYLevel(yDiff).heuristic(new BlockPos(0, 0, 0));
|
||||
heuristic += GoalYLevel.calculate(yDiff, 0);
|
||||
|
||||
//use the pythagorean and manhattan mixture from GoalXZ
|
||||
heuristic += GoalXZ.calculate(xDiff, zDiff);
|
||||
|
@ -61,4 +61,9 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
||||
int zDiff = pos.getZ() - this.z;
|
||||
return GoalBlock.calculate(xDiff, yDiff, zDiff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalGetToBlock{x=" + x + ",y=" + y + ",z=" + z + "}";
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,13 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Useful for automated combat (retreating specifically)
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalRunAway implements Goal {
|
||||
@ -65,6 +67,6 @@ public class GoalRunAway implements Goal {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalRunAwayFrom[" + Arrays.asList(from) + "]";
|
||||
return "GoalRunAwayFrom" + Arrays.asList(from);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class GoalXZ implements Goal {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goal{x=" + x + ",z=" + z + "}";
|
||||
return "GoalXZ{x=" + x + ",z=" + z + "}";
|
||||
}
|
||||
|
||||
public static double calculate(double xDiff, double zDiff) {
|
||||
|
@ -42,19 +42,23 @@ public class GoalYLevel implements Goal {
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {
|
||||
if (pos.getY() > level) {
|
||||
return calculate(level, pos.getY());
|
||||
}
|
||||
|
||||
static double calculate(int goalY, int currentY) {
|
||||
if (currentY > goalY) {
|
||||
// need to descend
|
||||
return FALL_N_BLOCKS_COST[2] / 2 * (pos.getY() - level);
|
||||
return FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY);
|
||||
}
|
||||
if (pos.getY() < level) {
|
||||
if (currentY < goalY) {
|
||||
// need to ascend
|
||||
return (level - pos.getY()) * JUMP_ONE_BLOCK_COST;
|
||||
return (goalY - currentY) * JUMP_ONE_BLOCK_COST;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goal{y=" + level + "}";
|
||||
return "GoalYLevel{y=" + level + "}";
|
||||
}
|
||||
}
|
||||
|
@ -134,15 +134,22 @@ public class MovementFall extends Movement {
|
||||
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false));
|
||||
}
|
||||
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads
|
||||
if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
|
||||
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
|
||||
if (player().motionY >= 0) {
|
||||
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
if (BlockStateInterface.isWater(dest)) {
|
||||
if (InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
|
||||
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
|
||||
if (player().motionY >= 0) {
|
||||
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
} else {
|
||||
return state;
|
||||
if (player().motionY >= 0) {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
} // don't else return state; we need to stay centered because this water might be flowing under the surface
|
||||
}
|
||||
} else {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
|
||||
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
|
||||
|
@ -264,7 +264,7 @@ public class PathExecutor implements Helper {
|
||||
// when we're midair in the middle of a fall, we're very far from both the beginning and the end, but we aren't actually off path
|
||||
if (path.movements().get(pathPosition) instanceof MovementFall) {
|
||||
BlockPos fallDest = path.positions().get(pathPosition + 1); // .get(pathPosition) is the block we fell off of
|
||||
if (Utils.playerFlatDistanceToCenter(fallDest) < 0.5) {
|
||||
if (Utils.playerFlatDistanceToCenter(fallDest) < leniency) { // ignore Y by using flat distance
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -119,6 +119,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.equals("axis")) {
|
||||
PathingBehavior.INSTANCE.setGoal(new GoalAxis());
|
||||
PathingBehavior.INSTANCE.path();
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().equals("cancel")) {
|
||||
MineBehavior.INSTANCE.cancel();
|
||||
FollowBehavior.INSTANCE.cancel();
|
||||
|
Loading…
Reference in New Issue
Block a user