baritone/src/main/java/baritone/pathing/movement/movements/MovementDownward.java

80 lines
2.7 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* 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,
2018-08-08 03:16:53 +00:00
* 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/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.pathing.movement.movements;
2018-08-06 22:23:08 +00:00
2018-08-22 20:15:56 +00:00
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
2018-08-06 22:23:08 +00:00
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
2018-08-17 19:24:40 +00:00
import net.minecraft.block.state.IBlockState;
2018-08-06 22:23:08 +00:00
import net.minecraft.util.math.BlockPos;
public class MovementDownward extends Movement {
private int numTicks = 0;
2018-08-14 17:47:31 +00:00
public MovementDownward(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end}, new BlockPos[0]);
2018-08-06 22:23:08 +00:00
}
@Override
protected double calculateCost(CalculationContext context) {
if (!MovementHelper.canWalkOn(dest.down())) {
return COST_INF;
}
2018-08-17 19:24:40 +00:00
IBlockState d = BlockStateInterface.get(dest);
Block td = d.getBlock();
boolean ladder = td instanceof BlockLadder || td instanceof BlockVine;
if (ladder) {
return LADDER_DOWN_ONE_COST;
} else {
return FALL_N_BLOCKS_COST[1] + MovementHelper.getMiningDurationTicks(context, dest, d);
}
}
2018-08-06 22:23:08 +00:00
@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
switch (state.getStatus()) {
case WAITING:
2018-08-18 19:33:00 +00:00
state.setStatus(MovementState.MovementStatus.RUNNING);
2018-08-06 22:23:08 +00:00
case RUNNING:
2018-08-14 15:28:35 +00:00
break;
2018-08-06 22:23:08 +00:00
default:
return state;
}
2018-08-14 15:28:35 +00:00
if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
}
double diffX = player().posX - (dest.getX() + 0.5);
double diffZ = player().posZ - (dest.getZ() + 0.5);
double ab = Math.sqrt(diffX * diffX + diffZ * diffZ);
if (numTicks++ < 10 && ab < 0.2) {
return state;
}
MovementHelper.moveTowards(state, positionsToBreak[0]);
return state;
2018-08-06 22:23:08 +00:00
}
}