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.
|
|
|
|
*
|
2018-08-08 04:15:22 +00:00
|
|
|
* 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-07 14:52:49 +00:00
|
|
|
package baritone.bot.pathing.movement.movements;
|
|
|
|
|
2018-08-07 21:36:32 +00:00
|
|
|
import baritone.bot.pathing.movement.CalculationContext;
|
2018-08-07 14:52:49 +00:00
|
|
|
import baritone.bot.pathing.movement.Movement;
|
|
|
|
import baritone.bot.pathing.movement.MovementHelper;
|
|
|
|
import baritone.bot.pathing.movement.MovementState;
|
|
|
|
import baritone.bot.utils.BlockStateInterface;
|
2018-08-12 15:24:53 +00:00
|
|
|
import net.minecraft.block.BlockMagma;
|
2018-08-07 14:52:49 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
2018-08-12 15:40:44 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-08-07 14:52:49 +00:00
|
|
|
public class MovementDiagonal extends Movement {
|
2018-08-07 21:14:36 +00:00
|
|
|
|
2018-08-12 04:27:46 +00:00
|
|
|
private static final double SQRT_2 = Math.sqrt(2);
|
|
|
|
|
2018-08-07 14:52:49 +00:00
|
|
|
public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
|
|
|
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
2018-08-07 21:14:36 +00:00
|
|
|
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
2018-08-07 14:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) {
|
|
|
|
this(start, dir1.offset(drr2), dir1, dir2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
2018-08-11 20:08:16 +00:00
|
|
|
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()});
|
2018-08-07 14:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MovementState updateState(MovementState state) {
|
|
|
|
super.updateState(state);
|
|
|
|
switch (state.getStatus()) {
|
|
|
|
case PREPPING:
|
|
|
|
case UNREACHABLE:
|
|
|
|
case FAILED:
|
|
|
|
return state;
|
|
|
|
case WAITING:
|
|
|
|
case RUNNING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (playerFeet().equals(dest)) {
|
|
|
|
state.setStatus(MovementState.MovementStatus.SUCCESS);
|
|
|
|
return state;
|
|
|
|
}
|
2018-08-11 20:08:16 +00:00
|
|
|
if (!BlockStateInterface.isLiquid(playerFeet())) {
|
|
|
|
player().setSprinting(true);
|
|
|
|
}
|
2018-08-08 19:51:04 +00:00
|
|
|
MovementHelper.moveTowards(state, dest);
|
2018-08-07 14:52:49 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-07 21:36:32 +00:00
|
|
|
protected double calculateCost(CalculationContext context) {
|
2018-08-12 04:27:46 +00:00
|
|
|
double lastPos = MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[4]) + MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[5]);
|
|
|
|
if (lastPos != 0) {
|
2018-08-07 14:52:49 +00:00
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
2018-08-12 15:24:53 +00:00
|
|
|
if (BlockStateInterface.get(positionsToBreak[2].down()).getBlock() instanceof BlockMagma) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
2018-08-12 04:27:46 +00:00
|
|
|
double optionA = MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[0]) + MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[1]);
|
|
|
|
double optionB = MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[2]) + MovementHelper.getMiningDurationTicks(context.getToolSet(), positionsToBreak[3]);
|
|
|
|
if (optionA != 0 && optionB != 0) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (optionA == 0) {
|
|
|
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[2]))) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[3]))) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optionB == 0) {
|
|
|
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[0]))) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[1]))) {
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double multiplier = 1;
|
|
|
|
if (optionA != 0 || optionB != 0) {
|
2018-08-12 14:58:22 +00:00
|
|
|
multiplier = SQRT_2 - 0.001; // TODO tune
|
2018-08-12 04:27:46 +00:00
|
|
|
}
|
|
|
|
return multiplier * SQRT_2 * (BlockStateInterface.isWater(src) || BlockStateInterface.isWater(dest) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean prepared(MovementState state) {
|
|
|
|
return true;
|
2018-08-07 14:52:49 +00:00
|
|
|
}
|
2018-08-12 15:40:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<BlockPos> toBreak() {
|
|
|
|
if (toBreakCached != null) {
|
|
|
|
return toBreakCached;
|
|
|
|
}
|
|
|
|
ArrayList<BlockPos> result = new ArrayList<>();
|
|
|
|
for (int i = 4; i < 6; i++) {
|
|
|
|
if (!MovementHelper.canWalkThrough(positionsToBreak[i])) {
|
|
|
|
result.add(positionsToBreak[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toBreakCached = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<BlockPos> toWalkInto() {
|
|
|
|
if (toWalkIntoCached == null) {
|
|
|
|
toWalkIntoCached = new ArrayList<>();
|
|
|
|
}
|
|
|
|
ArrayList<BlockPos> result = new ArrayList<>();
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (!MovementHelper.canWalkThrough(positionsToBreak[i])) {
|
|
|
|
result.add(positionsToBreak[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toWalkIntoCached = result;
|
|
|
|
return toWalkIntoCached;
|
|
|
|
}
|
2018-08-07 14:52:49 +00:00
|
|
|
}
|