completely submitting to codacy

This commit is contained in:
Leijurv 2018-10-27 14:41:25 -07:00
parent 8cee173f92
commit 1dee8ef355
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
13 changed files with 60 additions and 101 deletions

View File

@ -76,7 +76,7 @@ public class CreateDistTask extends BaritoneGradleTask {
return DatatypeConverter.printHexBinary(SHA1_DIGEST.digest(Files.readAllBytes(path))).toLowerCase(); return DatatypeConverter.printHexBinary(SHA1_DIGEST.digest(Files.readAllBytes(path))).toLowerCase();
} catch (Exception e) { } catch (Exception e) {
// haha no thanks // haha no thanks
throw new RuntimeException(e); throw new IllegalStateException(e);
} }
} }
} }

View File

@ -241,7 +241,7 @@ public class ProguardTask extends BaritoneGradleTask {
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception // Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
int exitCode = p.waitFor(); int exitCode = p.waitFor();
if (exitCode != 0) { if (exitCode != 0) {
throw new Exception("Proguard exited with code " + exitCode); throw new IllegalStateException("Proguard exited with code " + exitCode);
} }
} }

View File

@ -220,12 +220,10 @@ public final class RotationUtils {
if (result.getBlockPos().equals(pos)) { if (result.getBlockPos().equals(pos)) {
return Optional.of(rotation); return Optional.of(rotation);
} }
if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire) { if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire && result.getBlockPos().equals(pos.down())) {
if (result.getBlockPos().equals(pos.down())) {
return Optional.of(rotation); return Optional.of(rotation);
} }
} }
}
return Optional.empty(); return Optional.empty();
} }

View File

@ -75,11 +75,9 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
} }
} }
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
if (mineGoalUpdateInterval != 0) { if (mineGoalUpdateInterval != 0 && event.getCount() % mineGoalUpdateInterval == 0) {
if (event.getCount() % mineGoalUpdateInterval == 0) {
Baritone.INSTANCE.getExecutor().execute(this::rescan); Baritone.INSTANCE.getExecutor().execute(this::rescan);
} }
}
if (Baritone.settings().legitMine.get()) { if (Baritone.settings().legitMine.get()) {
addNearby(); addNearby();
} }
@ -190,14 +188,12 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) { for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) {
for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) { for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) {
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
if (mining.contains(BlockStateInterface.getBlock(pos))) { if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(player(), pos).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
if (RotationUtils.reachable(player(), pos).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
knownOreLocations.add(pos); knownOreLocations.add(pos);
} }
} }
} }
} }
}
knownOreLocations = prune(knownOreLocations, mining, 64); knownOreLocations = prune(knownOreLocations, mining, 64);
} }

View File

@ -134,11 +134,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
return; return;
} }
// at this point, we know current is in progress // at this point, we know current is in progress
if (safe) { if (safe && next != null && next.snipsnapifpossible()) {
// a movement just ended // a movement just ended; jump directly onto the next path
if (next != null) {
if (next.snipsnapifpossible()) {
// jump directly onto the next path
logDebug("Splicing into planned next path early..."); logDebug("Splicing into planned next path early...");
queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
current = next; current = next;
@ -146,8 +143,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
current.onTick(); current.onTick();
return; return;
} }
}
}
synchronized (pathCalcLock) { synchronized (pathCalcLock) {
if (isPathCalcInProgress) { if (isPathCalcInProgress) {
// if we aren't calculating right now // if we aren't calculating right now

View File

@ -99,15 +99,13 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
for (Moves moves : Moves.values()) { for (Moves moves : Moves.values()) {
int newX = currentNode.x + moves.xOffset; int newX = currentNode.x + moves.xOffset;
int newZ = currentNode.z + moves.zOffset; int newZ = currentNode.z + moves.zOffset;
if (newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) { if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !BlockStateInterface.isLoaded(newX, newZ)) {
// only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement // only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement
if (!BlockStateInterface.isLoaded(newX, newZ)) {
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
numEmptyChunk++; numEmptyChunk++;
} }
continue; continue;
} }
}
if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) { if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) {
continue; continue;
} }

View File

@ -97,11 +97,10 @@ public class MovementAscend extends Movement {
} }
} }
IBlockState srcUp2 = null; IBlockState srcUp2 = null;
if (BlockStateInterface.get(x, y + 3, z).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us if (BlockStateInterface.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(x, y + 1, z) || !((srcUp2 = BlockStateInterface.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us
// HOWEVER, we assume that we're standing in the start position // HOWEVER, we assume that we're standing in the start position
// that means that src and src.up(1) are both air // that means that src and src.up(1) are both air
// maybe they aren't now, but they will be by the time this starts // maybe they aren't now, but they will be by the time this starts
if (MovementHelper.canWalkThrough(x, y + 1, z) || !((srcUp2 = BlockStateInterface.get(x, y + 2, z)).getBlock() instanceof BlockFalling)) {
// if the lower one is can't walk through and the upper one is falling, that means that by standing on src // if the lower one is can't walk through and the upper one is falling, that means that by standing on src
// (the presupposition of this Movement) // (the presupposition of this Movement)
// we have necessarily already cleared the entire BlockFalling stack // we have necessarily already cleared the entire BlockFalling stack
@ -111,7 +110,6 @@ public class MovementAscend extends Movement {
// and that block is x, y+1, z, and we'd have to clear it to even start this movement // and that block is x, y+1, z, and we'd have to clear it to even start this movement
// we don't need to worry about those BlockFallings because we've already cleared them // we don't need to worry about those BlockFallings because we've already cleared them
return COST_INF; return COST_INF;
}
// you may think we only need to check srcUp2, not srcUp // you may think we only need to check srcUp2, not srcUp
// however, in the scenario where glitchy world gen where unsupported sand / gravel generates // however, in the scenario where glitchy world gen where unsupported sand / gravel generates
// it's possible srcUp is AIR from the start, and srcUp2 is falling // it's possible srcUp is AIR from the start, and srcUp2 is falling
@ -206,11 +204,9 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.UNREACHABLE); return state.setStatus(MovementStatus.UNREACHABLE);
} }
MovementHelper.moveTowards(state, dest); MovementHelper.moveTowards(state, dest);
if (MovementHelper.isBottomSlab(jumpingOnto)) { if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(src.down())) {
if (!MovementHelper.isBottomSlab(src.down())) {
return state; // don't jump while walking from a non double slab into a bottom slab return state; // don't jump while walking from a non double slab into a bottom slab
} }
}
if (Baritone.settings().assumeStep.get()) { if (Baritone.settings().assumeStep.get()) {
return state; return state;

View File

@ -183,11 +183,10 @@ public class MovementDescend extends Movement {
} }
BlockPos playerFeet = playerFeet(); BlockPos playerFeet = playerFeet();
if (playerFeet.equals(dest)) { if (playerFeet.equals(dest) && (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.094)) { // lilypads
if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.094) { // lilypads
// 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 // 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
return state.setStatus(MovementStatus.SUCCESS); return state.setStatus(MovementStatus.SUCCESS);
}/* else { /* else {
// System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY())); // System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY()));
}*/ }*/
} }

View File

@ -101,23 +101,19 @@ public class MovementDiagonal extends Movement {
return COST_INF; return COST_INF;
} }
IBlockState pb3 = BlockStateInterface.get(destX, y + 1, z); IBlockState pb3 = BlockStateInterface.get(destX, y + 1, z);
if (optionA == 0) { if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER))) {
// at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction // at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction
if ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER)) {
return COST_INF; return COST_INF;
} }
}
optionB += MovementHelper.getMiningDurationTicks(context, destX, y + 1, z, pb3, true); optionB += MovementHelper.getMiningDurationTicks(context, destX, y + 1, z, pb3, true);
if (optionA != 0 && optionB != 0) { if (optionA != 0 && optionB != 0) {
// and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible // and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible
return COST_INF; return COST_INF;
} }
if (optionB == 0) { if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb1.getBlock()) && pb1.getBlock() != Blocks.WATER))) {
// and now that option B is fully calculated, see if we can edge around that way // and now that option B is fully calculated, see if we can edge around that way
if ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb1.getBlock()) && pb1.getBlock() != Blocks.WATER)) {
return COST_INF; return COST_INF;
} }
}
boolean water = false; boolean water = false;
if (BlockStateInterface.isWater(BlockStateInterface.getBlock(x, y, z)) || BlockStateInterface.isWater(destInto.getBlock())) { if (BlockStateInterface.isWater(BlockStateInterface.getBlock(x, y, z)) || BlockStateInterface.isWater(destInto.getBlock())) {
// Ignore previous multiplier // Ignore previous multiplier

View File

@ -54,17 +54,13 @@ public class MovementPillar extends Movement {
if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) {
return COST_INF; return COST_INF;
} }
if (fromDownDown.getBlock() instanceof BlockSlab) { if (fromDownDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) {
if (!((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) {
return COST_INF; // can't pillar up from a bottom slab onto a non ladder return COST_INF; // can't pillar up from a bottom slab onto a non ladder
} }
} }
} if (fromDown instanceof BlockVine && !hasAgainst(x, y, z)) {
if (fromDown instanceof BlockVine) {
if (!hasAgainst(x, y, z)) {
return COST_INF; return COST_INF;
} }
}
IBlockState toBreak = BlockStateInterface.get(x, y + 2, z); IBlockState toBreak = BlockStateInterface.get(x, y + 2, z);
Block toBreakBlock = toBreak.getBlock(); Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) { if (toBreakBlock instanceof BlockFenceGate) {

View File

@ -189,13 +189,11 @@ public class MovementTraverse extends Movement {
} else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(dest, src)) { } else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(dest, src)) {
isDoorActuallyBlockingUs = true; isDoorActuallyBlockingUs = true;
} }
if (isDoorActuallyBlockingUs) { if (isDoorActuallyBlockingUs && !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
if (!(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.calculateBlockCenter(positionsToBreak[0])), true)) return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), VecUtils.calculateBlockCenter(positionsToBreak[0])), true))
.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); .setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} }
} }
}
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) { if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
BlockPos blocked = null; BlockPos blocked = null;
@ -267,12 +265,9 @@ public class MovementTraverse extends Movement {
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true)); state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get())) { if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get()) && RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
if (RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} }
// wrong side?
}
//System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock()); //System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
return state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true); return state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
} }

View File

@ -427,16 +427,12 @@ public class PathExecutor implements IPathExecutor, Helper {
} }
private static boolean canSprintInto(IMovement current, IMovement next) { private static boolean canSprintInto(IMovement current, IMovement next) {
if (next instanceof MovementDescend) { if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) {
if (next.getDirection().equals(current.getDirection())) {
return true; return true;
} }
} if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) {
if (next instanceof MovementTraverse) {
if (next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) {
return true; return true;
} }
}
if (next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get()) { if (next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get()) {
return true; return true;
} }

View File

@ -60,11 +60,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
@Override @Override
public void onSendChatMessage(ChatEvent event) { public void onSendChatMessage(ChatEvent event) {
if (!Baritone.settings().chatControl.get()) { if (!Baritone.settings().chatControl.get() && !Baritone.settings().removePrefix.get()) {
if (!Baritone.settings().removePrefix.get()) {
return; return;
} }
}
String msg = event.getMessage(); String msg = event.getMessage();
if (Baritone.settings().prefix.get()) { if (Baritone.settings().prefix.get()) {
if (!msg.startsWith("#")) { if (!msg.startsWith("#")) {
@ -77,8 +75,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} }
} }
public boolean runCommand(String msg) { public boolean runCommand(String msg0) {
msg = msg.toLowerCase(Locale.US).trim(); String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
for (Settings.Setting<Boolean> setting : toggleable) { for (Settings.Setting<Boolean> setting : toggleable) {
if (msg.equalsIgnoreCase(setting.getName())) { if (msg.equalsIgnoreCase(setting.getName())) {
@ -252,13 +250,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} else { } else {
for (EntityPlayer pl : world().playerEntities) { for (EntityPlayer pl : world().playerEntities) {
String theirName = pl.getName().trim().toLowerCase(); String theirName = pl.getName().trim().toLowerCase();
if (!theirName.equals(player().getName().trim().toLowerCase())) { // don't follow ourselves lol if (!theirName.equals(player().getName().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol
if (theirName.contains(name) || name.contains(theirName)) {
toFollow = Optional.of(pl); toFollow = Optional.of(pl);
} }
} }
} }
}
if (!toFollow.isPresent()) { if (!toFollow.isPresent()) {
logDirect("Not found"); logDirect("Not found");
return true; return true;
@ -400,11 +396,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} }
Goal goal = new GoalBlock(waypoint.getLocation()); Goal goal = new GoalBlock(waypoint.getLocation());
PathingBehavior.INSTANCE.setGoal(goal); PathingBehavior.INSTANCE.setGoal(goal);
if (!PathingBehavior.INSTANCE.path()) { if (!PathingBehavior.INSTANCE.path() && !goal.isInGoal(playerFeet())) {
if (!goal.isInGoal(playerFeet())) {
logDirect("Currently executing a path. Please cancel it first."); logDirect("Currently executing a path. Please cancel it first.");
} }
}
return true; return true;
} }
if (msg.equals("spawn") || msg.equals("bed")) { if (msg.equals("spawn") || msg.equals("bed")) {