MovementFall

This commit is contained in:
Leijurv 2018-08-06 14:04:55 -07:00
parent 4fa64059af
commit ee4ed0cc65
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 61 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import baritone.bot.pathing.movement.ActionCosts;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.movements.MovementAscend;
import baritone.bot.pathing.movement.movements.MovementDescend;
import baritone.bot.pathing.movement.movements.MovementFall;
import baritone.bot.pathing.movement.movements.MovementTraverse;
import baritone.bot.pathing.path.IPath;
import baritone.bot.utils.ToolSet;
@ -149,7 +150,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
Movement[] movements = new Movement[12];
Movement[] movements = new Movement[13];
movements[0] = new MovementTraverse(pos, new BlockPos(x + 1, y, z));
movements[1] = new MovementTraverse(pos, new BlockPos(x - 1, y, z));
movements[2] = new MovementTraverse(pos, new BlockPos(x, y, z + 1));
@ -162,6 +163,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
movements[9] = new MovementDescend(pos, new BlockPos(x - 1, y - 1, z));
movements[10] = new MovementDescend(pos, new BlockPos(x, y - 1, z + 1));
movements[11] = new MovementDescend(pos, new BlockPos(x, y - 1, z - 1));
movements[12] = new MovementFall(pos);
/*Action[] actions = new Action[26];
actions[0] = new ActionPillar(pos);
actions[1] = new ActionBridge(pos, new BlockPos(x + 1, y, z));

View File

@ -1,4 +1,61 @@
package baritone.bot.pathing.movement.movements;
public class MovementFall {
import baritone.bot.InputOverrideHandler;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementHelper;
import baritone.bot.pathing.movement.MovementState;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.Rotation;
import baritone.bot.utils.ToolSet;
import baritone.bot.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.util.math.BlockPos;
public class MovementFall extends Movement {
public MovementFall(BlockPos start) {
super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]);
}
int numTicks = 0;
@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
System.out.println("Ticking with state " + state.getStatus());
switch (state.getStatus()) {
case PREPPING:
case UNREACHABLE:
case FAILED:
return state;
case WAITING:
case RUNNING:
if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
}
if (numTicks++ < 10) {
return state;
}
Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[0], world()));
return state.setTarget(new MovementState.MovementTarget(rotationToBlock)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
default:
return state;
}
}
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) {
return COST_INF;
}
Block td = BlockStateInterface.get(dest).getBlock();
boolean ladder = td instanceof BlockLadder || td instanceof BlockVine;
if (ladder) {
return LADDER_DOWN_ONE_COST;
} else {
return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts);
}
}
}