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,8 +66,11 @@ public class MovementDescend extends Movement {
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
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
@ -99,9 +102,5 @@ public class MovementDescend extends Movement {
}
}
return state;
default:
return state;
}
}
}

View File

@ -59,6 +59,10 @@ public class MovementDownward extends Movement {
return state;
case WAITING:
case RUNNING:
break;
default:
return state;
}
if (playerFeet().equals(dest)) {
state.setStatus(MovementState.MovementStatus.SUCCESS);
return state;
@ -72,8 +76,5 @@ public class MovementDownward extends Movement {
}
MovementHelper.moveTowards(state, positionsToBreak[0]);
return state;
default:
return state;
}
}
}

View File

@ -74,6 +74,10 @@ public class MovementFall extends Movement {
case WAITING:
state.setStatus(MovementStatus.RUNNING);
case RUNNING:
break;
default:
return state;
}
BlockPos playerFeet = playerFeet();
Optional<Rotation> targetRotation = Optional.empty();
if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) {
@ -109,9 +113,6 @@ public class MovementFall extends Movement {
state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
return state;
default:
return state;
}
}
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {