diff --git a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java index 48b834215..49e2e1422 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java @@ -76,7 +76,7 @@ public class CreateDistTask extends BaritoneGradleTask { return DatatypeConverter.printHexBinary(SHA1_DIGEST.digest(Files.readAllBytes(path))).toLowerCase(); } catch (Exception e) { // haha no thanks - throw new RuntimeException(e); + throw new IllegalStateException(e); } } } diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index ce0e38006..350f74469 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -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 int exitCode = p.waitFor(); if (exitCode != 0) { - throw new Exception("Proguard exited with code " + exitCode); + throw new IllegalStateException("Proguard exited with code " + exitCode); } } diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index c7ff30578..a8449dc73 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -220,10 +220,8 @@ public final class RotationUtils { if (result.getBlockPos().equals(pos)) { return Optional.of(rotation); } - if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire) { - if (result.getBlockPos().equals(pos.down())) { - return Optional.of(rotation); - } + if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire && result.getBlockPos().equals(pos.down())) { + return Optional.of(rotation); } } return Optional.empty(); diff --git a/src/main/java/baritone/behavior/MineBehavior.java b/src/main/java/baritone/behavior/MineBehavior.java index bdc44320c..889cb4ff3 100644 --- a/src/main/java/baritone/behavior/MineBehavior.java +++ b/src/main/java/baritone/behavior/MineBehavior.java @@ -75,10 +75,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe } } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); - if (mineGoalUpdateInterval != 0) { - if (event.getCount() % mineGoalUpdateInterval == 0) { - Baritone.INSTANCE.getExecutor().execute(this::rescan); - } + if (mineGoalUpdateInterval != 0 && event.getCount() % mineGoalUpdateInterval == 0) { + Baritone.INSTANCE.getExecutor().execute(this::rescan); } if (Baritone.settings().legitMine.get()) { addNearby(); @@ -190,10 +188,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) { for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) { BlockPos pos = new BlockPos(x, y, z); - if (mining.contains(BlockStateInterface.getBlock(pos))) { - 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); - } + 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 + knownOreLocations.add(pos); } } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index f18993335..d626ac4ff 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -134,19 +134,14 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return; } // at this point, we know current is in progress - if (safe) { - // a movement just ended - if (next != null) { - if (next.snipsnapifpossible()) { - // jump directly onto the next path - logDebug("Splicing into planned next path early..."); - queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); - current = next; - next = null; - current.onTick(); - return; - } - } + if (safe && next != null && next.snipsnapifpossible()) { + // a movement just ended; jump directly onto the next path + logDebug("Splicing into planned next path early..."); + queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); + current = next; + next = null; + current.onTick(); + return; } synchronized (pathCalcLock) { if (isPathCalcInProgress) { diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 020acc349..dfecae2ea 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -99,14 +99,12 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel for (Moves moves : Moves.values()) { int newX = currentNode.x + moves.xOffset; 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 - if (!BlockStateInterface.isLoaded(newX, newZ)) { - if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed - numEmptyChunk++; - } - continue; + if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed + numEmptyChunk++; } + continue; } if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) { continue; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 52b0c78e1..e0d410471 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -97,21 +97,19 @@ public class MovementAscend extends Movement { } } 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 // 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 - 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 - // (the presupposition of this Movement) - // we have necessarily already cleared the entire BlockFalling stack - // on top of our head + // 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) + // we have necessarily already cleared the entire BlockFalling stack + // on top of our head - // as in, if we have a block, then two BlockFallings on top of it - // 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 - return COST_INF; - } + // as in, if we have a block, then two BlockFallings on top of it + // 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 + return COST_INF; // you may think we only need to check srcUp2, not srcUp // 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 @@ -206,10 +204,8 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (MovementHelper.isBottomSlab(jumpingOnto)) { - if (!MovementHelper.isBottomSlab(src.down())) { - return state; // don't jump while walking from a non double slab into a bottom slab - } + if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(src.down())) { + return state; // don't jump while walking from a non double slab into a bottom slab } if (Baritone.settings().assumeStep.get()) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index d2e3d3061..5fb78d743 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -183,11 +183,10 @@ public class MovementDescend extends Movement { } BlockPos playerFeet = playerFeet(); - if (playerFeet.equals(dest)) { - 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 - return state.setStatus(MovementStatus.SUCCESS); - }/* else { + if (playerFeet.equals(dest) && (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 + return state.setStatus(MovementStatus.SUCCESS); + /* else { // System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY())); }*/ } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 8ff681c63..19f72fca2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -101,22 +101,18 @@ public class MovementDiagonal extends Movement { return COST_INF; } 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 - 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); if (optionA != 0 && optionB != 0) { // and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible 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 - 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; if (BlockStateInterface.isWater(BlockStateInterface.getBlock(x, y, z)) || BlockStateInterface.isWater(destInto.getBlock())) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 62241a2bf..c11df54a4 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -54,16 +54,12 @@ public class MovementPillar extends Movement { if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { return COST_INF; } - if (fromDownDown.getBlock() instanceof BlockSlab) { - 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 - } + if (fromDownDown.getBlock() instanceof BlockSlab && !((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 } } - if (fromDown instanceof BlockVine) { - if (!hasAgainst(x, y, z)) { - return COST_INF; - } + if (fromDown instanceof BlockVine && !hasAgainst(x, y, z)) { + return COST_INF; } IBlockState toBreak = BlockStateInterface.get(x, y + 2, z); Block toBreakBlock = toBreak.getBlock(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index a71be4150..7f9c3902e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -189,11 +189,9 @@ public class MovementTraverse extends Movement { } else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(dest, src)) { isDoorActuallyBlockingUs = true; } - if (isDoorActuallyBlockingUs) { - 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)) - .setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); - } + if (isDoorActuallyBlockingUs && !(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)) + .setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); } } @@ -267,11 +265,8 @@ public class MovementTraverse extends Movement { state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true)); EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; - if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get())) { - if (RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) { - return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); - } - // wrong side? + if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get()) && RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) { + return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); } //System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock()); return state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 045cdab9c..ac48a8dbb 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -427,15 +427,11 @@ public class PathExecutor implements IPathExecutor, Helper { } private static boolean canSprintInto(IMovement current, IMovement next) { - if (next instanceof MovementDescend) { - if (next.getDirection().equals(current.getDirection())) { - return true; - } + if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { + return true; } - if (next instanceof MovementTraverse) { - if (next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) { - return true; - } + if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) { + return true; } if (next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get()) { return true; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index f1f70c77a..18fe9fb7b 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -60,10 +60,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { @Override public void onSendChatMessage(ChatEvent event) { - if (!Baritone.settings().chatControl.get()) { - if (!Baritone.settings().removePrefix.get()) { - return; - } + if (!Baritone.settings().chatControl.get() && !Baritone.settings().removePrefix.get()) { + return; } String msg = event.getMessage(); if (Baritone.settings().prefix.get()) { @@ -77,8 +75,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } } - public boolean runCommand(String msg) { - msg = msg.toLowerCase(Locale.US).trim(); + public boolean runCommand(String msg0) { + String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { if (msg.equalsIgnoreCase(setting.getName())) { @@ -252,10 +250,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } else { for (EntityPlayer pl : world().playerEntities) { String theirName = pl.getName().trim().toLowerCase(); - if (!theirName.equals(player().getName().trim().toLowerCase())) { // don't follow ourselves lol - if (theirName.contains(name) || name.contains(theirName)) { - toFollow = Optional.of(pl); - } + if (!theirName.equals(player().getName().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol + toFollow = Optional.of(pl); } } } @@ -400,10 +396,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } Goal goal = new GoalBlock(waypoint.getLocation()); PathingBehavior.INSTANCE.setGoal(goal); - if (!PathingBehavior.INSTANCE.path()) { - if (!goal.isInGoal(playerFeet())) { - logDirect("Currently executing a path. Please cancel it first."); - } + if (!PathingBehavior.INSTANCE.path() && !goal.isInGoal(playerFeet())) { + logDirect("Currently executing a path. Please cancel it first."); } return true; }