Merge branch 'skynet'

This commit is contained in:
Leijurv 2018-09-12 10:13:39 -07:00
commit a7504caa67
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 85 additions and 7 deletions

View File

@ -243,10 +243,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
MovementParkour.generate(pos, EnumFacing.EAST),
MovementParkour.generate(pos, EnumFacing.WEST),
MovementParkour.generate(pos, EnumFacing.NORTH),
MovementParkour.generate(pos, EnumFacing.SOUTH),
MovementParkour.generate(pos, EnumFacing.EAST, calcContext),
MovementParkour.generate(pos, EnumFacing.WEST, calcContext),
MovementParkour.generate(pos, EnumFacing.NORTH, calcContext),
MovementParkour.generate(pos, EnumFacing.SOUTH, calcContext),
};
}

View File

@ -18,20 +18,28 @@
package baritone.pathing.movement.movements;
import baritone.Baritone;
import baritone.behavior.impl.LookBehaviorUtils;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Objects;
public class MovementParkour extends Movement {
protected static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
final EnumFacing direction;
final int dist;
@ -43,7 +51,7 @@ public class MovementParkour extends Movement {
super.override(costFromJumpDistance(dist));
}
public static MovementParkour generate(BetterBlockPos src, EnumFacing dir) {
public static MovementParkour generate(BetterBlockPos src, EnumFacing dir, CalculationContext context) {
// MUST BE KEPT IN SYNC WITH calculateCost
if (!Baritone.settings().allowParkour.get()) {
return null;
@ -85,6 +93,27 @@ public class MovementParkour extends Movement {
return new MovementParkour(src, i, dir);
}
}
BlockPos dest = src.offset(dir, 4);
BlockPos positionToPlace = dest.down();
IBlockState toPlace = BlockStateInterface.get(positionToPlace);
if (!context.hasThrowaway()) {
return null;
}
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
return null;
}
for (int i = 0; i < 5; i++) {
BlockPos against1 = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP[i]);
if (against1.up().equals(src.offset(dir, 3))) { // we can't turn around that fast
continue;
}
if (MovementHelper.canPlaceAgainst(against1)) {
// holy jesus we gonna do it
MovementParkour ret = new MovementParkour(src, 4, dir);
ret.override(costFromJumpDistance(4) + context.placeBlockCost());
return ret;
}
}
return null;
}
@ -104,9 +133,31 @@ public class MovementParkour extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
// MUST BE KEPT IN SYNC WITH generate
boolean placing = false;
if (!MovementHelper.canWalkOn(dest.down())) {
if (dist != 4) {
return COST_INF;
}
BlockPos positionToPlace = dest.down();
IBlockState toPlace = BlockStateInterface.get(positionToPlace);
if (!context.hasThrowaway()) {
return COST_INF;
}
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
return COST_INF;
}
for (int i = 0; i < 5; i++) {
BlockPos against1 = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP[i]);
if (against1.up().equals(src.offset(direction, 3))) { // we can't turn around that fast
continue;
}
if (MovementHelper.canPlaceAgainst(against1)) {
// holy jesus we gonna do it
placing = true;
break;
}
}
}
Block walkOff = BlockStateInterface.get(src.down().offset(direction)).getBlock();
if (MovementHelper.avoidWalkingInto(walkOff) && walkOff != Blocks.WATER && walkOff != Blocks.FLOWING_WATER) {
return COST_INF;
@ -119,7 +170,7 @@ public class MovementParkour extends Movement {
}
}
if (d.equals(dest)) {
return costFromJumpDistance(i);
return costFromJumpDistance(i) + (placing ? context.placeBlockCost() : 0);
}
}
throw new IllegalStateException("invalid jump distance?");
@ -146,6 +197,33 @@ public class MovementParkour extends Movement {
}
} else if (!playerFeet().equals(src)) {
if (playerFeet().equals(src.offset(direction)) || player().posY - playerFeet().getY() > 0.0001) {
if (!MovementHelper.canWalkOn(dest.down())) {
BlockPos positionToPlace = dest.down();
for (int i = 0; i < 5; i++) {
BlockPos against1 = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP[i]);
if (against1.up().equals(src.offset(direction, 3))) { // we can't turn around that fast
continue;
}
if (MovementHelper.canPlaceAgainst(against1)) {
if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
return state.setStatus(MovementState.MovementStatus.UNREACHABLE);
}
double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D;
double faceY = (dest.getY() + against1.getY()) * 0.5D;
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> {
if (Objects.equals(selectedBlock, against1) && selectedBlock.offset(side).equals(dest.down())) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
});
}
}
}
state.setInput(InputOverrideHandler.Input.JUMP, true);
} else {
state.setInput(InputOverrideHandler.Input.SPRINT, false);