1
0
mirror of https://github.com/cabaletta/baritone synced 2024-12-24 07:52:54 +00:00

Add cost-only MovementFall

This commit is contained in:
Howard Stark 2018-08-06 16:07:54 -07:00
parent 6ecc928039
commit d357a48710
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3

View File

@ -1,61 +1,41 @@
package baritone.bot.pathing.movement.movements;
import baritone.bot.InputOverrideHandler;
import baritone.bot.pathing.movement.ActionCosts;
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]);
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
BlockPos[] toBreak;
int diffX = dest.getX() - src.getX();
int diffZ = dest.getZ() - src.getZ();
int diffY = dest.getY() - src.getY();
toBreak = new BlockPos[diffY + 1];
for(int i = 0; i < toBreak.length; i++ ) {
toBreak[i] = new BlockPos(dest.getX() - diffX, dest.getY() + (toBreak.length - 1) - i, dest.getZ() - diffZ);
}
return toBreak;
}
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;
}
protected MovementFall(BlockPos src, BlockPos dest) {
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()});
}
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) {
if(!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
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);
double placeBucketCost = 0.0;
if(!BlockStateInterface.isWater(dest)) {
placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST;
}
return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost;
}
}