less indentation

This commit is contained in:
Leijurv 2018-08-14 08:28:35 -07:00
parent 1e731b3246
commit 46593fc1a4
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 103 additions and 86 deletions

View File

@ -113,4 +113,6 @@ public interface IGameEventListener {
* @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[])
*/
void onReceivePacket(PacketEvent event);
}

View File

@ -21,8 +21,6 @@ import baritone.bot.pathing.goals.Goal;
import baritone.bot.pathing.movement.Movement;
import net.minecraft.util.math.BlockPos;
import java.util.Objects;
/**
* A node in the path, containing the cost and steps to get to it.
*
@ -80,6 +78,8 @@ public class PathNode {
*/
public int heapPosition;
public final int hashCode;
public PathNode(BlockPos pos, Goal goal) {
this.pos = pos;
this.previous = null;
@ -88,6 +88,7 @@ public class PathNode {
this.estimatedCostToGoal = goal.heuristic(pos);
this.previousMovement = null;
this.isOpen = false;
this.hashCode = calcHashCode();
}
/**
@ -97,12 +98,25 @@ public class PathNode {
*/
@Override
public int hashCode() {
throw new IllegalStateException();
}
private final int calcHashCode() {
/*
* This is the hashcode implementation of Vec3i, the superclass of BlockPos
*
* public int hashCode() {
* return (this.getY() + this.getZ() * 31) * 31 + this.getX();
* }
*
* That is terrible and has tons of collisions and makes the HashMap terribly inefficient.
*
* That's why we grab out the X, Y, Z and calculate our own hashcode
*/
int hash = 3241;
hash = 3457689 * hash + this.pos.getX();
hash = 8734625 * hash + this.pos.getY();
hash = 2873465 * hash + this.pos.getZ();
// Don't call goal.hashCode(). this calls objects hashcode to verify that the actual goal objects are == identical, which is important for node caching
hash = 3241543 * hash + Objects.hashCode(this.goal);
return hash;
}

View File

@ -66,42 +66,41 @@ public class MovementDescend extends Movement {
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
BlockPos playerFeet = playerFeet();
if (playerFeet.equals(dest)) {
if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.01) {
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
state.setStatus(MovementStatus.SUCCESS);
return state;
} else {
System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY()));
}
}
double diffX = player().posX - (dest.getX() + 0.5);
double diffZ = player().posZ - (dest.getZ() + 0.5);
double ab = Math.sqrt(diffX * diffX + diffZ * diffZ);
double x = player().posX - (src.getX() + 0.5);
double z = player().posZ - (src.getZ() + 0.5);
double fromStart = Math.sqrt(x * x + z * z);
if (!playerFeet.equals(dest) || ab > 0.25) {
BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ());
double diffX2 = player().posX - (fakeDest.getX() + 0.5);
double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5);
double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2);
if (numTicks++ < 20) {
MovementHelper.moveTowards(state, fakeDest);
if (fromStart > 1.25) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false);
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
}
} else {
MovementHelper.moveTowards(state, dest);
}
}
return state;
break;
default:
return state;
}
BlockPos playerFeet = playerFeet();
if (playerFeet.equals(dest)) {
if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.01) {
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
state.setStatus(MovementStatus.SUCCESS);
return state;
} else {
System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY()));
}
}
double diffX = player().posX - (dest.getX() + 0.5);
double diffZ = player().posZ - (dest.getZ() + 0.5);
double ab = Math.sqrt(diffX * diffX + diffZ * diffZ);
double x = player().posX - (src.getX() + 0.5);
double z = player().posZ - (src.getZ() + 0.5);
double fromStart = Math.sqrt(x * x + z * z);
if (!playerFeet.equals(dest) || ab > 0.25) {
BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ());
double diffX2 = player().posX - (fakeDest.getX() + 0.5);
double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5);
double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2);
if (numTicks++ < 20) {
MovementHelper.moveTowards(state, fakeDest);
if (fromStart > 1.25) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false);
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
}
} else {
MovementHelper.moveTowards(state, dest);
}
}
return state;
}
}

View File

@ -59,21 +59,22 @@ public class MovementDownward extends Movement {
return state;
case WAITING:
case RUNNING:
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;
break;
default:
return state;
}
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;
}
}

View File

@ -74,44 +74,45 @@ public class MovementFall extends Movement {
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
BlockPos playerFeet = playerFeet();
Optional<Rotation> targetRotation = Optional.empty();
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) {
if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory
state.setStatus(MovementStatus.UNREACHABLE);
return state;
}
if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER);
targetRotation = LookBehaviorUtils.reachable(dest.down());
}
}
if (targetRotation.isPresent()) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true)
.setTarget(new MovementTarget(targetRotation.get()));
} else {
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest))));
}
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01
|| BlockStateInterface.isWater(dest))) {
if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (player().motionY >= 0) {
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} else {
return state;
}
}
return state.setStatus(MovementStatus.SUCCESS);
}
Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
return state;
break;
default:
return state;
}
BlockPos playerFeet = playerFeet();
Optional<Rotation> targetRotation = Optional.empty();
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) {
if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory
state.setStatus(MovementStatus.UNREACHABLE);
return state;
}
if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER);
targetRotation = LookBehaviorUtils.reachable(dest.down());
}
}
if (targetRotation.isPresent()) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true)
.setTarget(new MovementTarget(targetRotation.get()));
} else {
state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest))));
}
if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01
|| BlockStateInterface.isWater(dest))) {
if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (player().motionY >= 0) {
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} else {
return state;
}
}
return state.setStatus(MovementStatus.SUCCESS);
}
Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
return state;
}
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {