From 91c4d8292dea32a653c934f7554f7b5835e7f58e Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 26 Aug 2018 02:53:50 -0500 Subject: [PATCH 01/47] Cleaned up 7 duplicate switch statements --- src/main/java/baritone/pathing/movement/Movement.java | 5 +++++ .../pathing/movement/movements/MovementAscend.java | 10 ++-------- .../pathing/movement/movements/MovementDescend.java | 10 ++-------- .../pathing/movement/movements/MovementDiagonal.java | 10 ++-------- .../pathing/movement/movements/MovementDownward.java | 10 ++-------- .../pathing/movement/movements/MovementFall.java | 10 ++-------- .../pathing/movement/movements/MovementPillar.java | 10 ++-------- .../pathing/movement/movements/MovementTraverse.java | 10 ++-------- 8 files changed, 19 insertions(+), 56 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 27cbb08e..ee9bf27a 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -266,6 +266,11 @@ public abstract class Movement implements Helper, MovementHelper { } else if (state.getStatus() == MovementStatus.PREPPING) { state.setStatus(MovementStatus.WAITING); } + + if (state.getStatus() == MovementStatus.WAITING) { + state.setStatus(MovementStatus.RUNNING); + } + return state; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index f3225337..1dce611c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -122,14 +122,8 @@ public class MovementAscend extends Movement { super.updateState(state); // TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump // for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly) - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 6e299bd1..b9004d9a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -65,14 +65,8 @@ public class MovementDescend extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; BlockPos playerFeet = playerFeet(); if (playerFeet.equals(dest)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 7bde41c7..8ece8a44 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -52,14 +52,8 @@ public class MovementDiagonal extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 724b8688..8262035c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -60,14 +60,8 @@ public class MovementDownward extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 5c40c706..6117b418 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -80,14 +80,8 @@ public class MovementFall extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementStatus.RUNNING) + return state; BlockPos playerFeet = playerFeet(); Rotation targetRotation = null; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index dba55466..794eb317 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -107,14 +107,8 @@ public class MovementPillar extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; IBlockState fromDown = BlockStateInterface.get(src); boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index e92fc527..485fc5a7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -129,14 +129,8 @@ public class MovementTraverse extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - switch (state.getStatus()) { - case WAITING: - state.setStatus(MovementState.MovementStatus.RUNNING); - case RUNNING: - break; - default: - return state; - } + if (state.getStatus() != MovementState.MovementStatus.RUNNING) + return state; Block fd = BlockStateInterface.get(src.down()).getBlock(); boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; From 63b04df95da2ca369a15060c882161055124b311 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Sep 2018 07:48:27 -0700 Subject: [PATCH 02/47] parkour --- FEATURES.md | 4 +- src/main/java/baritone/Settings.java | 5 + .../pathing/calc/AStarPathFinder.java | 6 +- .../baritone/pathing/movement/Movement.java | 4 + .../pathing/movement/MovementHelper.java | 34 ++++ .../movement/movements/MovementParkour.java | 151 ++++++++++++++++++ .../utils/pathing/BetterBlockPos.java | 6 + 7 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 src/main/java/baritone/pathing/movement/movements/MovementParkour.java diff --git a/FEATURES.md b/FEATURES.md index 998b546a..98bae9e2 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -9,6 +9,7 @@ - **Slabs and stairs** - **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore). - **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc. +- **Parkour** Sprint jumping over 1, 2, or 3 block gaps # Pathing method Baritone uses a modified version of A*. @@ -41,8 +42,7 @@ Things it doesn't have yet See issues for more. Things it may not ever have, from most likely to least likely =( -- Parkour (jumping over gaps of any length) -- Boats - Pigs +- Boats - Horses (2x3 path instead of 1x2) - Elytra diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 1eed4333..5bb57549 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -83,6 +83,11 @@ public class Settings { */ public Setting allowWalkOnBottomSlab = new Setting<>(true); + /** + * You know what it is + */ + public Setting allowParkour = new Setting<>(true); // disable in release because its sketchy af lol + /** * For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly. */ diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 73442998..893d9686 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -233,7 +233,11 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST), - new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)) + new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)), + MovementParkour.calculate(pos, EnumFacing.NORTH), + MovementParkour.calculate(pos, EnumFacing.SOUTH), + MovementParkour.calculate(pos, EnumFacing.EAST), + MovementParkour.calculate(pos, EnumFacing.WEST), }; } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 5eba39ab..76871934 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -84,6 +84,10 @@ public abstract class Movement implements Helper, MovementHelper { return getCost(null); } + protected void override(double cost) { + this.cost = cost; + } + public double calculateCostWithoutCaching() { return calculateCost(new CalculationContext()); } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6897d5a4..7c9a8c36 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -70,6 +70,9 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean canWalkThrough(BlockPos pos, IBlockState state) { Block block = state.getBlock(); + if (block == Blocks.AIR) { + return true; + } if (block instanceof BlockFire || block instanceof BlockTripWire || block instanceof BlockWeb @@ -106,6 +109,37 @@ public interface MovementHelper extends ActionCosts, Helper { return block.isPassable(mc.world, pos); } + /** + * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), + * not including water, and not including ladders or vines or cobwebs (they slow us down) + * + * @return + */ + static boolean fullyPassable(BlockPos pos) { + return fullyPassable(pos, BlockStateInterface.get(pos)); + } + + static boolean fullyPassable(BlockPos pos, IBlockState state) { + Block block = state.getBlock(); + if (block == Blocks.AIR) { + return true; + } + if (block == Blocks.FIRE + || block == Blocks.TRIPWIRE + || block == Blocks.WEB + || block == Blocks.VINE + || block == Blocks.LADDER + || block instanceof BlockDoor + || block instanceof BlockFenceGate + || block instanceof BlockSnow + || block instanceof BlockLiquid + || block instanceof BlockTrapDoor + || block instanceof BlockEndPortal) { + return false; + } + return block.isPassable(mc.world, pos); + } + static boolean isReplacable(BlockPos pos, IBlockState state) { // for MovementTraverse and MovementAscend // block double plant defaults to true when the block doesn't match, so don't need to check that case diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java new file mode 100644 index 00000000..3749e6ec --- /dev/null +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -0,0 +1,151 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.pathing.movement.movements; + +import baritone.Baritone; +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 net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +public class MovementParkour extends Movement { + + final EnumFacing direction; + final int dist; + + private MovementParkour(BlockPos src, int dist, EnumFacing dir) { + super(src, src.offset(dir, dist), new BlockPos[]{}); + this.direction = dir; + this.dist = dist; + super.override(costFromJumpDistance(dist)); + } + + public static MovementParkour calculate(BlockPos src, EnumFacing dir) { + if (!Baritone.settings().allowParkour.get()) { + return null; + } + IBlockState standingOn = BlockStateInterface.get(src.down()); + if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) { + return null; + } + BlockPos adjBlock = src.down().offset(dir); + IBlockState adj = BlockStateInterface.get(adjBlock); + if (MovementHelper.avoidWalkingInto(adj.getBlock())) { // magma sucks + return null; + } + if (MovementHelper.canWalkOn(adjBlock, adj)) { // don't parkour if we could just traverse (for now) + return null; + } + + if (!MovementHelper.fullyPassable(src.offset(dir))) { + return null; + } + if (!MovementHelper.fullyPassable(src.up().offset(dir))) { + return null; + } + for (int i = 2; i <= 4; i++) { + BlockPos dest = src.offset(dir, i); + if (!MovementHelper.fullyPassable(dest)) { + return null; + } + if (!MovementHelper.fullyPassable(dest.up())) { + return null; + } + if (MovementHelper.canWalkOn(dest.down())) { + return new MovementParkour(src, i, dir); + } + } + return null; + } + + private static double costFromJumpDistance(int dist) { + switch (dist) { + case 2: + return WALK_ONE_BLOCK_COST * 2; // IDK LOL + case 3: + return WALK_ONE_BLOCK_COST * 3; + case 4: + return SPRINT_ONE_BLOCK_COST * 3; + } + throw new IllegalStateException("LOL"); + } + + + @Override + protected double calculateCost(CalculationContext context) { + if (!MovementHelper.canWalkOn(dest.down())) { + return COST_INF; + } + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(src.down().offset(direction)).getBlock())) { + return COST_INF; + } + for (int i = 1; i <= 4; i++) { + BlockPos d = src.offset(direction, i); + if (!MovementHelper.fullyPassable(d)) { + return COST_INF; + } + if (!MovementHelper.fullyPassable(d.up())) { + return COST_INF; + } + if (d.equals(dest)) { + return costFromJumpDistance(i); + } + } + throw new IllegalStateException("invalid jump distance?"); + } + + @Override + public MovementState updateState(MovementState state) { + super.updateState(state); + switch (state.getStatus()) { + case WAITING: + state.setStatus(MovementState.MovementStatus.RUNNING); + case RUNNING: + break; + default: + return state; + } + if (dist >= 4) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); + } + MovementHelper.moveTowards(state, dest); + if (playerFeet().equals(dest)) { + if (player().posY - playerFeet().getY() < 0.01) { + state.setStatus(MovementState.MovementStatus.SUCCESS); + } + } else if (!playerFeet().equals(src)) { + if (playerFeet().equals(src.offset(direction)) || player().posY - playerFeet().getY() > 0.0001) { + state.setInput(InputOverrideHandler.Input.JUMP, true); + } else { + state.setInput(InputOverrideHandler.Input.SPRINT, false); + if (playerFeet().equals(src.offset(direction, -1))) { + MovementHelper.moveTowards(state, src); + } else { + MovementHelper.moveTowards(state, src.offset(direction, -1)); + } + } + } + return state; + } +} \ No newline at end of file diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index ec8891f4..6a05c109 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -119,4 +119,10 @@ public final class BetterBlockPos extends BlockPos { Vec3i vec = dir.getDirectionVec(); return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ()); } + + @Override + public BlockPos offset(EnumFacing dir, int dist) { + Vec3i vec = dir.getDirectionVec(); + return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist); + } } From 915b03a44e4d0c46b9f45a438c1f68b82b25bb34 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Sep 2018 07:54:12 -0700 Subject: [PATCH 03/47] lol --- .../baritone/pathing/movement/movements/MovementParkour.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 3749e6ec..05a88ded 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -86,7 +86,7 @@ public class MovementParkour extends Movement { case 3: return WALK_ONE_BLOCK_COST * 3; case 4: - return SPRINT_ONE_BLOCK_COST * 3; + return SPRINT_ONE_BLOCK_COST * 4; } throw new IllegalStateException("LOL"); } From b746e56631adf7ddf5048f31643277d830c29a76 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Sep 2018 10:13:50 -0700 Subject: [PATCH 04/47] lol you can't jump with a ceiling above you --- .../movement/movements/MovementParkour.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 05a88ded..edae2abf 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -66,11 +66,10 @@ public class MovementParkour extends Movement { } for (int i = 2; i <= 4; i++) { BlockPos dest = src.offset(dir, i); - if (!MovementHelper.fullyPassable(dest)) { - return null; - } - if (!MovementHelper.fullyPassable(dest.up())) { - return null; + for (int y = 0; y < 3; y++) { + if (!MovementHelper.fullyPassable(dest.up(y))) { + return null; + } } if (MovementHelper.canWalkOn(dest.down())) { return new MovementParkour(src, i, dir); @@ -102,11 +101,10 @@ public class MovementParkour extends Movement { } for (int i = 1; i <= 4; i++) { BlockPos d = src.offset(direction, i); - if (!MovementHelper.fullyPassable(d)) { - return COST_INF; - } - if (!MovementHelper.fullyPassable(d.up())) { - return COST_INF; + for (int y = 0; y < 3; y++) { + if (!MovementHelper.fullyPassable(d.up(y))) { + return COST_INF; + } } if (d.equals(dest)) { return costFromJumpDistance(i); From 9757422626984e78cc7dd81258d724c7582a03ec Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Sep 2018 10:14:41 -0700 Subject: [PATCH 05/47] also check where we might hit our head --- .../baritone/pathing/movement/movements/MovementParkour.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index edae2abf..40f9b5a3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -66,7 +66,8 @@ public class MovementParkour extends Movement { } for (int i = 2; i <= 4; i++) { BlockPos dest = src.offset(dir, i); - for (int y = 0; y < 3; y++) { + // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? + for (int y = 0; y < 4; y++) { if (!MovementHelper.fullyPassable(dest.up(y))) { return null; } @@ -101,7 +102,7 @@ public class MovementParkour extends Movement { } for (int i = 1; i <= 4; i++) { BlockPos d = src.offset(direction, i); - for (int y = 0; y < 3; y++) { + for (int y = 0; y < 4; y++) { if (!MovementHelper.fullyPassable(d.up(y))) { return COST_INF; } From d17cc96e90d560b6d6d8d3c50f710c9a085e3ca6 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 7 Sep 2018 19:40:15 -0500 Subject: [PATCH 06/47] Constructor fix --- .../baritone/pathing/movement/movements/MovementDiagonal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 127d277c..1a11295e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -47,7 +47,7 @@ public class MovementDiagonal extends Movement { } public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) { - super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()}); + super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } @Override From 2d969b55ef36ba2f98ffd18a2ff57730b9de2aa9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 18:23:05 -0700 Subject: [PATCH 07/47] fix world scanner radius --- src/main/java/baritone/chunk/WorldScanner.java | 12 ++++++------ .../baritone/utils/interfaces/IGoalRenderPos.java | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 src/main/java/baritone/utils/interfaces/IGoalRenderPos.java diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index 09edd1e5..27345670 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -47,13 +47,13 @@ public enum WorldScanner implements Helper { int playerChunkX = playerFeet().getX() >> 4; int playerChunkZ = playerFeet().getZ() >> 4; - int searchRadius = 2; + int searchRadiusSq = 0; while (true) { boolean allUnloaded = true; - for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) { - for (int zoff = -searchRadius; zoff <= searchRadius; zoff++) { + for (int xoff = -searchRadiusSq; xoff <= searchRadiusSq; xoff++) { + for (int zoff = -searchRadiusSq; zoff <= searchRadiusSq; zoff++) { int distance = xoff * xoff + zoff * zoff; - if (distance != searchRadius) { + if (distance != searchRadiusSq) { continue; } int chunkX = xoff + playerChunkX; @@ -91,10 +91,10 @@ public enum WorldScanner implements Helper { if (allUnloaded) { return res; } - if (res.size() >= max) { + if (res.size() >= max && searchRadiusSq < 26) { return res; } - searchRadius++; + searchRadiusSq++; } } } diff --git a/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java new file mode 100644 index 00000000..cdc7cd00 --- /dev/null +++ b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java @@ -0,0 +1,4 @@ +package baritone.utils.interfaces; + +public class IGoalRenderPos { +} From 85babda97e3d27dfe1fa427a29bdd2d1779f2c31 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 18:23:32 -0700 Subject: [PATCH 08/47] render more goals, fixes #25 --- .../baritone/pathing/goals/GoalBlock.java | 3 ++- .../pathing/goals/GoalGetToBlock.java | 3 ++- .../java/baritone/pathing/goals/GoalNear.java | 3 ++- .../baritone/pathing/goals/GoalTwoBlocks.java | 5 +++-- .../pathing/movement/MovementHelper.java | 1 + .../java/baritone/utils/PathRenderer.java | 13 ++++++----- .../utils/interfaces/IGoalRenderPos.java | 22 ++++++++++++++++++- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/pathing/goals/GoalBlock.java b/src/main/java/baritone/pathing/goals/GoalBlock.java index 78d7b87d..9e6ea556 100644 --- a/src/main/java/baritone/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -24,7 +25,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalBlock implements Goal { +public class GoalBlock implements Goal, IGoalRenderPos { /** * The X block position of this goal diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index 30937772..4e81018b 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; @@ -26,7 +27,7 @@ import net.minecraft.util.math.BlockPos; * * @author avecowa */ -public class GoalGetToBlock implements Goal { +public class GoalGetToBlock implements Goal, IGoalRenderPos { private final int x; private final int y; diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index 2ec6bf1d..e78788ac 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -17,9 +17,10 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; -public class GoalNear implements Goal { +public class GoalNear implements Goal, IGoalRenderPos { final int x; final int y; final int z; diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 65571a49..021103a1 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -25,7 +26,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalTwoBlocks implements Goal { +public class GoalTwoBlocks implements Goal, IGoalRenderPos { /** * The X block position of this goal @@ -69,7 +70,7 @@ public class GoalTwoBlocks implements Goal { } public BlockPos getGoalPos() { - return new BlockPos(x, y, z); + return new BlockPos(x, y - 1, z); } @Override diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7c9a8c36..1369a42f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -124,6 +124,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { return true; } + // exceptions - blocks that are isPassasble true, but we can't actually jump through if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 6fd3466e..c4ea8103 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -19,9 +19,10 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; -import baritone.pathing.goals.GoalBlock; +import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -183,13 +184,13 @@ public final class PathRenderer implements Helper { double maxY; double y1; double y2; - if (goal instanceof GoalBlock) { - BlockPos goalPos = ((GoalBlock) goal).getGoalPos(); + if (goal instanceof IGoalRenderPos) { + BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos(); minX = goalPos.getX() + 0.002 - renderPosX; maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2)); + double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; @@ -207,7 +208,9 @@ public final class PathRenderer implements Helper { minY = 0 - renderPosY; maxY = 256 - renderPosY; } else { - // TODO GoalComposite + for (Goal g : ((GoalComposite) goal).goals()) { + drawLitDankGoalBox(player, g, partialTicks, color); + } return; } diff --git a/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java index cdc7cd00..0aed1ea4 100644 --- a/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java +++ b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java @@ -1,4 +1,24 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + package baritone.utils.interfaces; -public class IGoalRenderPos { +import net.minecraft.util.math.BlockPos; + +public interface IGoalRenderPos { + BlockPos getGoalPos(); } From 6ad9451798621a9b9c61d810c1579d585a7abb36 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 20:43:12 -0700 Subject: [PATCH 09/47] smaller cuter boxes for goaltwoblocks --- src/main/java/baritone/pathing/goals/GoalTwoBlocks.java | 2 +- src/main/java/baritone/utils/PathRenderer.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 021103a1..dcd8d17d 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -70,7 +70,7 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { } public BlockPos getGoalPos() { - return new BlockPos(x, y - 1, z); + return new BlockPos(x, y, z); } @Override diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index c4ea8103..8f3cf37b 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; +import baritone.pathing.goals.GoalTwoBlocks; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; import baritone.utils.interfaces.IGoalRenderPos; @@ -191,10 +192,18 @@ public final class PathRenderer implements Helper { minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); + if (goal instanceof GoalTwoBlocks) { + y /= 2; + } y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; maxY = minY + 2; + if (goal instanceof GoalTwoBlocks) { + y1 -= 0.5; + y2 -= 0.5; + maxY--; + } } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal; From 3261687ee08ecadbe37d1f1fb608501673e252a3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 18:23:32 -0700 Subject: [PATCH 10/47] render more goals, fixes #25 --- .../baritone/pathing/goals/GoalBlock.java | 3 ++- .../pathing/goals/GoalGetToBlock.java | 3 ++- .../java/baritone/pathing/goals/GoalNear.java | 3 ++- .../baritone/pathing/goals/GoalTwoBlocks.java | 5 ++-- .../java/baritone/utils/PathRenderer.java | 13 ++++++---- .../utils/interfaces/IGoalRenderPos.java | 24 +++++++++++++++++++ 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/main/java/baritone/utils/interfaces/IGoalRenderPos.java diff --git a/src/main/java/baritone/pathing/goals/GoalBlock.java b/src/main/java/baritone/pathing/goals/GoalBlock.java index 78d7b87d..9e6ea556 100644 --- a/src/main/java/baritone/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -24,7 +25,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalBlock implements Goal { +public class GoalBlock implements Goal, IGoalRenderPos { /** * The X block position of this goal diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index 30937772..4e81018b 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; @@ -26,7 +27,7 @@ import net.minecraft.util.math.BlockPos; * * @author avecowa */ -public class GoalGetToBlock implements Goal { +public class GoalGetToBlock implements Goal, IGoalRenderPos { private final int x; private final int y; diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index 2ec6bf1d..e78788ac 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -17,9 +17,10 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; -public class GoalNear implements Goal { +public class GoalNear implements Goal, IGoalRenderPos { final int x; final int y; final int z; diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 65571a49..021103a1 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -17,6 +17,7 @@ package baritone.pathing.goals; +import baritone.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; /** @@ -25,7 +26,7 @@ import net.minecraft.util.math.BlockPos; * * @author leijurv */ -public class GoalTwoBlocks implements Goal { +public class GoalTwoBlocks implements Goal, IGoalRenderPos { /** * The X block position of this goal @@ -69,7 +70,7 @@ public class GoalTwoBlocks implements Goal { } public BlockPos getGoalPos() { - return new BlockPos(x, y, z); + return new BlockPos(x, y - 1, z); } @Override diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 6fd3466e..c4ea8103 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -19,9 +19,10 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; -import baritone.pathing.goals.GoalBlock; +import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; +import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -183,13 +184,13 @@ public final class PathRenderer implements Helper { double maxY; double y1; double y2; - if (goal instanceof GoalBlock) { - BlockPos goalPos = ((GoalBlock) goal).getGoalPos(); + if (goal instanceof IGoalRenderPos) { + BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos(); minX = goalPos.getX() + 0.002 - renderPosX; maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2)); + double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; @@ -207,7 +208,9 @@ public final class PathRenderer implements Helper { minY = 0 - renderPosY; maxY = 256 - renderPosY; } else { - // TODO GoalComposite + for (Goal g : ((GoalComposite) goal).goals()) { + drawLitDankGoalBox(player, g, partialTicks, color); + } return; } diff --git a/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java new file mode 100644 index 00000000..0aed1ea4 --- /dev/null +++ b/src/main/java/baritone/utils/interfaces/IGoalRenderPos.java @@ -0,0 +1,24 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.interfaces; + +import net.minecraft.util.math.BlockPos; + +public interface IGoalRenderPos { + BlockPos getGoalPos(); +} From 9052781889776458ede26003e951d0c78647d286 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 20:43:12 -0700 Subject: [PATCH 11/47] smaller cuter boxes for goaltwoblocks --- src/main/java/baritone/pathing/goals/GoalTwoBlocks.java | 2 +- src/main/java/baritone/utils/PathRenderer.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 021103a1..dcd8d17d 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -70,7 +70,7 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { } public BlockPos getGoalPos() { - return new BlockPos(x, y - 1, z); + return new BlockPos(x, y, z); } @Override diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index c4ea8103..8f3cf37b 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; +import baritone.pathing.goals.GoalTwoBlocks; import baritone.pathing.goals.GoalXZ; import baritone.pathing.path.IPath; import baritone.utils.interfaces.IGoalRenderPos; @@ -191,10 +192,18 @@ public final class PathRenderer implements Helper { minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); + if (goal instanceof GoalTwoBlocks) { + y /= 2; + } y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; maxY = minY + 2; + if (goal instanceof GoalTwoBlocks) { + y1 -= 0.5; + y2 -= 0.5; + maxY--; + } } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal; From 132e277388770dbd0d7a6b5ed3bbc47076eac925 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 21:32:25 -0700 Subject: [PATCH 12/47] { } --- .../java/baritone/launch/BaritoneTweaker.java | 12 +++++++--- .../launch/mixins/MixinEntityPlayerSP.java | 3 ++- .../launch/mixins/MixinKeyBinding.java | 3 ++- .../launch/mixins/MixinNetworkManager.java | 10 ++++---- .../baritone/api/event/GameEventHandler.java | 6 +++-- src/main/java/baritone/behavior/Behavior.java | 3 ++- .../baritone/behavior/impl/LookBehavior.java | 8 ++++--- .../behavior/impl/LookBehaviorUtils.java | 8 ++++--- .../behavior/impl/MemoryBehavior.java | 17 +++++++------- .../behavior/impl/PathingBehavior.java | 3 ++- src/main/java/baritone/chunk/CachedChunk.java | 3 ++- .../java/baritone/chunk/CachedRegion.java | 12 ++++++---- src/main/java/baritone/chunk/CachedWorld.java | 18 ++++++++++----- src/main/java/baritone/chunk/Waypoints.java | 3 ++- .../java/baritone/chunk/WorldProvider.java | 7 +++--- .../java/baritone/pathing/calc/PathNode.java | 3 ++- .../baritone/pathing/movement/Movement.java | 9 +++++--- .../pathing/movement/MovementHelper.java | 23 +++++++++++-------- .../movement/movements/MovementAscend.java | 3 ++- .../movement/movements/MovementDescend.java | 3 ++- .../movement/movements/MovementDiagonal.java | 3 ++- .../movement/movements/MovementDownward.java | 3 ++- .../movement/movements/MovementFall.java | 6 ++--- .../movement/movements/MovementPillar.java | 3 ++- .../movement/movements/MovementTraverse.java | 4 ++-- .../baritone/utils/BlockStateInterface.java | 3 ++- src/main/java/baritone/utils/ToolSet.java | 3 ++- 27 files changed, 114 insertions(+), 68 deletions(-) diff --git a/src/launch/java/baritone/launch/BaritoneTweaker.java b/src/launch/java/baritone/launch/BaritoneTweaker.java index e281ece3..9638214c 100644 --- a/src/launch/java/baritone/launch/BaritoneTweaker.java +++ b/src/launch/java/baritone/launch/BaritoneTweaker.java @@ -39,9 +39,15 @@ public class BaritoneTweaker implements ITweaker { @Override public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { this.args = new ArrayList<>(args); - if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath()); - if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath()); - if (profile != null) addArg("version", profile); + if (gameDir != null) { + addArg("gameDir", gameDir.getAbsolutePath()); + } + if (assetsDir != null) { + addArg("assetsDir", assetsDir.getAbsolutePath()); + } + if (profile != null) { + addArg("version", profile); + } } @Override diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java index 9da39df3..9a45659e 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -42,8 +42,9 @@ public class MixinEntityPlayerSP { private void sendChatMessage(String msg, CallbackInfo ci) { ChatEvent event = new ChatEvent(msg); Baritone.INSTANCE.getGameEventHandler().onSendChatMessage(event); - if (event.isCancelled()) + if (event.isCancelled()) { ci.cancel(); + } } @Inject( diff --git a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java index 838802cd..4285c14d 100644 --- a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java +++ b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java @@ -37,7 +37,8 @@ public class MixinKeyBinding { cancellable = true ) private void isKeyDown(CallbackInfoReturnable cir) { - if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) + if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) { cir.setReturnValue(true); + } } } diff --git a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java index 46664e7c..b0fedc62 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java @@ -39,13 +39,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(NetworkManager.class) public class MixinNetworkManager { - @Shadow private Channel channel; + @Shadow + private Channel channel; @Inject( method = "dispatchPacket", at = @At("HEAD") ) - private void preDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { + private void preDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.PRE, inPacket)); } @@ -53,7 +54,7 @@ public class MixinNetworkManager { method = "dispatchPacket", at = @At("RETURN") ) - private void postDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { + private void postDispatchPacket(Packet inPacket, final GenericFutureListener>[] futureListeners, CallbackInfo ci) { Baritone.INSTANCE.getGameEventHandler().onSendPacket(new PacketEvent(EventState.POST, inPacket)); } @@ -73,7 +74,8 @@ public class MixinNetworkManager { at = @At("RETURN") ) private void postProcessPacket(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { - if (this.channel.isOpen()) + if (this.channel.isOpen()) { Baritone.INSTANCE.getGameEventHandler().onReceivePacket(new PacketEvent(EventState.POST, packet)); + } } } diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 1ec2d834..af2a4020 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -80,8 +80,9 @@ public final class GameEventHandler implements IGameEventListener, Helper { if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) { int keyCode = keyBinding.getKeyCode(); - if (keyCode < Keyboard.KEYBOARD_SIZE) + if (keyCode < Keyboard.KEYBOARD_SIZE) { KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode); + } } } @@ -141,8 +142,9 @@ public final class GameEventHandler implements IGameEventListener, Helper { break; case POST: cache.closeWorld(); - if (event.getWorld() != null) + if (event.getWorld() != null) { cache.initWorld(event.getWorld()); + } break; } diff --git a/src/main/java/baritone/behavior/Behavior.java b/src/main/java/baritone/behavior/Behavior.java index ad5e3a88..5bf6c5c6 100644 --- a/src/main/java/baritone/behavior/Behavior.java +++ b/src/main/java/baritone/behavior/Behavior.java @@ -52,8 +52,9 @@ public class Behavior implements AbstractGameEventListener, Toggleable, Helper { @Override public final boolean setEnabled(boolean enabled) { boolean newState = getNewState(this.enabled, enabled); - if (newState == this.enabled) + if (newState == this.enabled) { return this.enabled; + } if (this.enabled = newState) { onStart(); diff --git a/src/main/java/baritone/behavior/impl/LookBehavior.java b/src/main/java/baritone/behavior/impl/LookBehavior.java index 080d75d5..b740618a 100644 --- a/src/main/java/baritone/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/behavior/impl/LookBehavior.java @@ -19,9 +19,9 @@ package baritone.behavior.impl; import baritone.Baritone; import baritone.Settings; -import baritone.behavior.Behavior; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RelativeMoveEvent; +import baritone.behavior.Behavior; import baritone.utils.Rotation; public class LookBehavior extends Behavior { @@ -57,8 +57,9 @@ public class LookBehavior extends Behavior { @Override public void onPlayerUpdate(PlayerUpdateEvent event) { - if (this.target == null) + if (this.target == null) { return; + } // Whether or not we're going to silently set our angles boolean silent = Baritone.settings().antiCheatCompatibility.get(); @@ -102,8 +103,9 @@ public class LookBehavior extends Behavior { player().rotationYaw = this.lastYaw; // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() - if (!Baritone.settings().antiCheatCompatibility.get()) + if (!Baritone.settings().antiCheatCompatibility.get()) { this.target = null; + } break; } } diff --git a/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java b/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java index 91b046e0..a7896d03 100644 --- a/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java +++ b/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java @@ -67,9 +67,10 @@ public final class LookBehaviorUtils implements Helper { return Optional.of(new Rotation(mc.player.rotationYaw, mc.player.rotationPitch + 0.0001f)); } Optional possibleRotation = reachableCenter(pos); - System.out.println("center: " + possibleRotation); - if (possibleRotation.isPresent()) + //System.out.println("center: " + possibleRotation); + if (possibleRotation.isPresent()) { return possibleRotation; + } IBlockState state = BlockStateInterface.get(pos); AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos); @@ -78,8 +79,9 @@ public final class LookBehaviorUtils implements Helper { double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff)); - if (possibleRotation.isPresent()) + if (possibleRotation.isPresent()) { return possibleRotation; + } } return Optional.empty(); } diff --git a/src/main/java/baritone/behavior/impl/MemoryBehavior.java b/src/main/java/baritone/behavior/impl/MemoryBehavior.java index 8f43a8e8..93657988 100644 --- a/src/main/java/baritone/behavior/impl/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/impl/MemoryBehavior.java @@ -1,9 +1,9 @@ package baritone.behavior.impl; -import baritone.behavior.Behavior; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.type.EventState; +import baritone.behavior.Behavior; import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.network.play.client.CPacketCloseWindow; @@ -38,8 +38,9 @@ public class MemoryBehavior extends Behavior { @Override public void onPlayerUpdate(PlayerUpdateEvent event) { - if (event.getState() == EventState.PRE) + if (event.getState() == EventState.PRE) { updateInventory(); + } } @Override @@ -86,13 +87,13 @@ public class MemoryBehavior extends Behavior { this.futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) .findFirst().ifPresent(matched -> { - // Remove the future inventory - this.futureInventories.remove(matched); + // Remove the future inventory + this.futureInventories.remove(matched); - // Setup the remembered inventory - RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory()); - inventory.windowId = packet.getWindowId(); - inventory.size = packet.getSlotCount(); + // Setup the remembered inventory + RememberedInventory inventory = this.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory()); + inventory.windowId = packet.getWindowId(); + inventory.size = packet.getSlotCount(); }); } diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index fa651a87..14060fba 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -389,8 +389,9 @@ public class PathingBehavior extends Behavior { }); long end = System.nanoTime(); //System.out.println((end - split) + " " + (split - start)); - // if (end - start > 0) + // if (end - start > 0) { // System.out.println("Frame took " + (split - start) + " " + (end - split)); + //} } } diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index 418a015e..56f7662a 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -199,7 +199,8 @@ public final class CachedChunk implements IBlockTypeAccess { * @throws IllegalArgumentException if the bitset size exceeds the maximum size */ private static void validateSize(BitSet data) { - if (data.size() > SIZE) + if (data.size() > SIZE) { throw new IllegalArgumentException("BitSet of invalid length provided"); + } } } diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index e15164e4..ee305527 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -112,13 +112,15 @@ public final class CachedRegion implements IBlockTypeAccess { } try { Path path = Paths.get(directory); - if (!Files.exists(path)) + if (!Files.exists(path)) { Files.createDirectories(path); + } System.out.println("Saving region " + x + "," + z + " to disk " + path); Path regionFile = getRegionFile(path, this.x, this.z); - if (!Files.exists(regionFile)) + if (!Files.exists(regionFile)) { Files.createFile(regionFile); + } try ( FileOutputStream fileOut = new FileOutputStream(regionFile.toFile()); GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384); @@ -175,12 +177,14 @@ public final class CachedRegion implements IBlockTypeAccess { public synchronized void load(String directory) { try { Path path = Paths.get(directory); - if (!Files.exists(path)) + if (!Files.exists(path)) { Files.createDirectories(path); + } Path regionFile = getRegionFile(path, this.x, this.z); - if (!Files.exists(regionFile)) + if (!Files.exists(regionFile)) { return; + } System.out.println("Loading region " + x + "," + z + " from disk " + path); long start = System.nanoTime() / 1000000L; diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index 56d8ef38..14097c16 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -128,9 +128,11 @@ public final class CachedWorld implements IBlockTypeAccess { int regionX = xoff + playerRegionX; int regionZ = zoff + playerRegionZ; CachedRegion region = getOrCreateRegion(regionX, regionZ); - if (region != null) - for (BlockPos pos : region.getLocationsOf(block)) + if (region != null) { + for (BlockPos pos : region.getLocationsOf(block)) { res.add(pos); + } + } } } if (res.size() >= minimum) { @@ -153,8 +155,9 @@ public final class CachedWorld implements IBlockTypeAccess { } long start = System.nanoTime() / 1000000L; this.cachedRegions.values().parallelStream().forEach(region -> { - if (region != null) + if (region != null) { region.save(this.directory); + } }); long now = System.nanoTime() / 1000000L; System.out.println("World save took " + (now - start) + "ms"); @@ -163,8 +166,9 @@ public final class CachedWorld implements IBlockTypeAccess { public final void reloadAllFromDisk() { long start = System.nanoTime() / 1000000L; this.cachedRegions.values().forEach(region -> { - if (region != null) + if (region != null) { region.load(this.directory); + } }); long now = System.nanoTime() / 1000000L; System.out.println("World load took " + (now - start) + "ms"); @@ -199,8 +203,9 @@ public final class CachedWorld implements IBlockTypeAccess { public void forEachRegion(Consumer consumer) { this.cachedRegions.forEach((id, r) -> { - if (r != null) + if (r != null) { consumer.accept(r); + } }); } @@ -213,8 +218,9 @@ public final class CachedWorld implements IBlockTypeAccess { * @return The region ID */ private long getRegionID(int regionX, int regionZ) { - if (!isRegionInWorld(regionX, regionZ)) + if (!isRegionInWorld(regionX, regionZ)) { return 0; + } return (long) regionX & 0xFFFFFFFFL | ((long) regionZ & 0xFFFFFFFFL) << 32; } diff --git a/src/main/java/baritone/chunk/Waypoints.java b/src/main/java/baritone/chunk/Waypoints.java index d75ff733..ec587fea 100644 --- a/src/main/java/baritone/chunk/Waypoints.java +++ b/src/main/java/baritone/chunk/Waypoints.java @@ -61,8 +61,9 @@ public class Waypoints { waypoints.put(tag, new HashSet<>()); Path fileName = directory.resolve(tag.name().toLowerCase() + ".mp4"); - if (!Files.exists(fileName)) + if (!Files.exists(fileName)) { return; + } try ( FileInputStream fileIn = new FileInputStream(fileName.toFile()); diff --git a/src/main/java/baritone/chunk/WorldProvider.java b/src/main/java/baritone/chunk/WorldProvider.java index 275b6ac1..007f037d 100644 --- a/src/main/java/baritone/chunk/WorldProvider.java +++ b/src/main/java/baritone/chunk/WorldProvider.java @@ -18,9 +18,9 @@ package baritone.chunk; import baritone.Baritone; +import baritone.utils.Helper; import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IChunkProviderServer; -import baritone.utils.Helper; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.world.WorldServer; @@ -69,7 +69,7 @@ public enum WorldProvider implements Helper { directory = new File(directory, "baritone"); readme = directory; - + } else { //remote directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP); @@ -102,7 +102,8 @@ public enum WorldProvider implements Helper { } public final void ifWorldLoaded(Consumer currentWorldConsumer) { - if (this.currentWorld != null) + if (this.currentWorld != null) { currentWorldConsumer.accept(this.currentWorld); + } } } diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index 314c996b..ac6f8b8b 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -103,8 +103,9 @@ public class PathNode { // GOTTA GO FAST // ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE // SKRT SKRT - //if (obj == null || !(obj instanceof PathNode)) + //if (obj == null || !(obj instanceof PathNode)) { // return false; + //} //final PathNode other = (PathNode) obj; //return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal); diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index d3d86463..d1e2230d 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -70,8 +70,9 @@ public abstract class Movement implements Helper, MovementHelper { public double getCost(CalculationContext context) { if (cost == null) { - if (context == null) + if (context == null) { context = new CalculationContext(); + } cost = calculateCost(context); } return cost; @@ -128,13 +129,15 @@ public abstract class Movement implements Helper, MovementHelper { }); latestState.getInputStates().replaceAll((input, forced) -> false); - if (!this.didBreakLastTick) + if (!this.didBreakLastTick) { BlockBreakHelper.stopBreakingBlock(); + } currentState = latestState; - if (isFinished()) + if (isFinished()) { onFinish(latestState); + } return currentState.getStatus(); } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 49fc5968..f93ea82d 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -70,10 +70,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean canWalkThrough(BlockPos pos, IBlockState state) { Block block = state.getBlock(); - if (block instanceof BlockFire - || block instanceof BlockTripWire - || block instanceof BlockWeb - || block instanceof BlockEndPortal) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire + if (block instanceof BlockFire || block instanceof BlockTripWire || block instanceof BlockWeb || block instanceof BlockEndPortal) { return false; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -127,30 +124,35 @@ public interface MovementHelper extends ActionCosts, Helper { } static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) { - if (playerPos.equals(doorPos)) + if (playerPos.equals(doorPos)) { return false; + } IBlockState state = BlockStateInterface.get(doorPos); - if (!(state.getBlock() instanceof BlockDoor)) + if (!(state.getBlock() instanceof BlockDoor)) { return true; + } return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN); } static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) { - if (playerPos.equals(gatePos)) + if (playerPos.equals(gatePos)) { return false; + } IBlockState state = BlockStateInterface.get(gatePos); - if (!(state.getBlock() instanceof BlockFenceGate)) + if (!(state.getBlock() instanceof BlockFenceGate)) { return true; + } return isHorizontalBlockPassable(gatePos, state, playerPos, BlockFenceGate.OPEN); } static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, PropertyBool propertyOpen) { - if (playerPos.equals(blockPos)) + if (playerPos.equals(blockPos)) { return false; + } EnumFacing.Axis facing = blockState.getValue(BlockHorizontal.FACING).getAxis(); boolean open = blockState.getValue(propertyOpen); @@ -260,8 +262,9 @@ public interface MovementHelper extends ActionCosts, Helper { } double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table double strVsBlock = context.getToolSet().getStrVsBlock(state); - if (strVsBlock < 0) + if (strVsBlock < 0) { return COST_INF; + } double result = m / strVsBlock; if (includeFalling) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index e79929be..474fd162 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -123,8 +123,9 @@ public class MovementAscend extends Movement { super.updateState(state); // TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump // for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly) - if (state.getStatus() != MovementStatus.RUNNING) + if (state.getStatus() != MovementStatus.RUNNING) { return state; + } if (playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 86d9db99..d8d9d3b2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -67,8 +67,9 @@ public class MovementDescend extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementStatus.RUNNING) + if (state.getStatus() != MovementStatus.RUNNING) { return state; + } BlockPos playerFeet = playerFeet(); if (playerFeet.equals(dest)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 1a11295e..d343234c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -119,8 +119,9 @@ public class MovementDiagonal extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementState.MovementStatus.RUNNING) + if (state.getStatus() != MovementState.MovementStatus.RUNNING) { return state; + } if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 3be854ad..9565e932 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -60,8 +60,9 @@ public class MovementDownward extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementState.MovementStatus.RUNNING) + if (state.getStatus() != MovementState.MovementStatus.RUNNING) { return state; + } if (playerFeet().equals(dest)) { state.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index db3b997a..40fa291d 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -96,8 +96,9 @@ public class MovementFall extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementStatus.RUNNING) + if (state.getStatus() != MovementStatus.RUNNING) { return state; + } BlockPos playerFeet = playerFeet(); Rotation targetRotation = null; @@ -123,8 +124,7 @@ public class MovementFall extends Movement { } else { state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)), false)); } - if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 // lilypads - || BlockStateInterface.isWater(dest))) { + if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 || BlockStateInterface.isWater(dest))) { // 0.094 because lilypads if (BlockStateInterface.isWater(dest) && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) { player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY); if (player().motionY >= 0) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 6d5a1a05..6933a83f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -121,8 +121,9 @@ public class MovementPillar extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementState.MovementStatus.RUNNING) + if (state.getStatus() != MovementState.MovementStatus.RUNNING) { return state; + } IBlockState fromDown = BlockStateInterface.get(src); boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index b12088d9..44c594c0 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -125,9 +125,9 @@ public class MovementTraverse extends Movement { @Override public MovementState updateState(MovementState state) { super.updateState(state); - if (state.getStatus() != MovementState.MovementStatus.RUNNING) + if (state.getStatus() != MovementState.MovementStatus.RUNNING) { return state; - + } state.setInput(InputOverrideHandler.Input.SNEAK, false); Block fd = BlockStateInterface.get(src.down()).getBlock(); diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index cd3ca646..efb83e36 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -35,8 +35,9 @@ public class BlockStateInterface implements Helper { public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability // Invalid vertical position - if (pos.getY() < 0 || pos.getY() >= 256) + if (pos.getY() < 0 || pos.getY() >= 256) { return Blocks.AIR.getDefaultState(); + } if (!Baritone.settings().pathThroughCachedOnly.get()) { Chunk cached = prev; diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index e31fe09e..9a6ca4d7 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -87,8 +87,9 @@ public class ToolSet implements Helper { ItemStack contents = player().inventory.getStackInSlot(slot); float blockHard = state.getBlockHardness(null, null); - if (blockHard < 0) + if (blockHard < 0) { return -1; + } float speed = contents.getDestroySpeed(state); if (speed > 1) { From 9577967da1a2e52056d9f4af280525ec750c4a71 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 8 Sep 2018 08:15:10 -0700 Subject: [PATCH 13/47] final --- src/main/java/baritone/pathing/calc/PathNode.java | 2 +- src/main/java/baritone/utils/pathing/BetterBlockPos.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index ac6f8b8b..45190fa7 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -26,7 +26,7 @@ import baritone.utils.pathing.BetterBlockPos; * * @author leijurv */ -public class PathNode { +public final class PathNode { /** * The position of this node diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index ec8891f4..53d20075 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -60,12 +60,12 @@ public final class BetterBlockPos extends BlockPos { } @Override - public final int hashCode() { + public int hashCode() { return (int) hashCode; } @Override - public final boolean equals(Object o) { + public boolean equals(Object o) { if (o == null) { return false; } From fadb17f3644a39ca26e7aafb24c7f41825562ec0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 8 Sep 2018 14:16:54 -0700 Subject: [PATCH 14/47] that was dumb --- src/main/java/baritone/utils/PathRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 8f3cf37b..ae078268 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -216,11 +216,13 @@ public final class PathRenderer implements Helper { y2 = 0; minY = 0 - renderPosY; maxY = 256 - renderPosY; - } else { + } else if (goal instanceof GoalComposite) { for (Goal g : ((GoalComposite) goal).goals()) { drawLitDankGoalBox(player, g, partialTicks, color); } return; + } else { + return; } GlStateManager.enableBlend(); From b45a2c94eaaaac8c9f057456a1951e478a6324e5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 8 Sep 2018 20:45:40 -0700 Subject: [PATCH 15/47] direct invocation --- .../baritone/api/event/GameEventHandler.java | 89 ++++++++++++++----- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index af2a4020..32634213 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -49,7 +49,6 @@ import org.lwjgl.input.Keyboard; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; /** * @author Brady @@ -61,12 +60,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onTick(TickEvent event) { - dispatch(listener -> listener.onTick(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onTick(event); + } + } } @Override public final void onPlayerUpdate(PlayerUpdateEvent event) { - dispatch(listener -> listener.onPlayerUpdate(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onPlayerUpdate(event); + } + } } @Override @@ -86,12 +93,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { } } - dispatch(IGameEventListener::onProcessKeyBinds); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onProcessKeyBinds(); + } + } } @Override public final void onSendChatMessage(ChatEvent event) { - dispatch(listener -> listener.onSendChatMessage(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onSendChatMessage(event); + } + } } @Override @@ -117,18 +132,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { } - dispatch(listener -> listener.onChunkEvent(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onChunkEvent(event); + } + } } @Override public final void onRenderPass(RenderEvent event) { - /* - WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> { - drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks()); - }))); - */ - - dispatch(listener -> listener.onRenderPass(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onRenderPass(event); + } + } } @Override @@ -148,47 +165,71 @@ public final class GameEventHandler implements IGameEventListener, Helper { break; } - dispatch(listener -> listener.onWorldEvent(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onWorldEvent(event); + } + } } @Override public final void onSendPacket(PacketEvent event) { - dispatch(listener -> listener.onSendPacket(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onSendPacket(event); + } + } } @Override public final void onReceivePacket(PacketEvent event) { - dispatch(listener -> listener.onReceivePacket(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onReceivePacket(event); + } + } } @Override public void onPlayerRelativeMove(RelativeMoveEvent event) { - dispatch(listener -> listener.onPlayerRelativeMove(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onPlayerRelativeMove(event); + } + } } @Override public void onBlockInteract(BlockInteractEvent event) { - dispatch(listener -> listener.onBlockInteract(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onBlockInteract(event); + } + } } @Override public void onPlayerDeath() { - dispatch(IGameEventListener::onPlayerDeath); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onPlayerDeath(); + } + } } @Override public void onPathEvent(PathEvent event) { - dispatch(listener -> listener.onPathEvent(event)); + for (IGameEventListener l : listeners) { + if (canDispatch(l)) { + l.onPathEvent(event); + } + } } public final void registerEventListener(IGameEventListener listener) { this.listeners.add(listener); } - private void dispatch(Consumer dispatchFunction) { - this.listeners.stream().filter(this::canDispatch).forEach(dispatchFunction); - } - private boolean canDispatch(IGameEventListener listener) { return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled(); } From b143dcff5f9670e498c277ecfafed572b9647949 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 9 Sep 2018 00:27:24 -0500 Subject: [PATCH 16/47] You can use it in COMPLIANCE --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba4897ee..cdd31b0d 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ PathingBehavior.INSTANCE.path(); ## Can I use Baritone as a library in my hacked client? -Sure! +Sure! (As long as usage is in compliance with the GPL 3 License) ## How is it so fast? From 489b9dea98efb1560412b69c2b77d1849b3cf2af Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 18:23:05 -0700 Subject: [PATCH 17/47] fix world scanner radius --- src/main/java/baritone/chunk/WorldScanner.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index 09edd1e5..27345670 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -47,13 +47,13 @@ public enum WorldScanner implements Helper { int playerChunkX = playerFeet().getX() >> 4; int playerChunkZ = playerFeet().getZ() >> 4; - int searchRadius = 2; + int searchRadiusSq = 0; while (true) { boolean allUnloaded = true; - for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) { - for (int zoff = -searchRadius; zoff <= searchRadius; zoff++) { + for (int xoff = -searchRadiusSq; xoff <= searchRadiusSq; xoff++) { + for (int zoff = -searchRadiusSq; zoff <= searchRadiusSq; zoff++) { int distance = xoff * xoff + zoff * zoff; - if (distance != searchRadius) { + if (distance != searchRadiusSq) { continue; } int chunkX = xoff + playerChunkX; @@ -91,10 +91,10 @@ public enum WorldScanner implements Helper { if (allUnloaded) { return res; } - if (res.size() >= max) { + if (res.size() >= max && searchRadiusSq < 26) { return res; } - searchRadius++; + searchRadiusSq++; } } } From 02ebc1947be5b5b4957a05808fc71984e4c3e837 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 07:18:03 -0700 Subject: [PATCH 18/47] actually disable by default --- src/main/java/baritone/Settings.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 5bb57549..bfab655e 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -85,8 +85,10 @@ public class Settings { /** * You know what it is + *

+ * But it's very unreliable and falls off when cornering like all the time so. */ - public Setting allowParkour = new Setting<>(true); // disable in release because its sketchy af lol + public Setting allowParkour = new Setting<>(false); /** * For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly. From 387e27e8de2e5af210f9dec0437dad99133b6d0b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 08:11:33 -0700 Subject: [PATCH 19/47] movementhelper overhaul --- .../pathing/movement/MovementHelper.java | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 79ad6371..832663cc 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -73,7 +73,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { return true; } - if (block instanceof BlockFire || block instanceof BlockTripWire || block instanceof BlockWeb || block instanceof BlockEndPortal) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL) { return false; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -206,10 +206,11 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean avoidWalkingInto(Block block) { return BlockStateInterface.isLava(block) - || block instanceof BlockCactus - || block instanceof BlockFire - || block instanceof BlockEndPortal - || block instanceof BlockWeb; + || block == Blocks.MAGMA + || block == Blocks.CACTUS + || block == Blocks.FIRE + || block == Blocks.END_PORTAL + || block == Blocks.WEB; } /** @@ -221,31 +222,22 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean canWalkOn(BlockPos pos, IBlockState state) { Block block = state.getBlock(); - if (block == Blocks.AIR) { + if (block == Blocks.AIR || block == Blocks.MAGMA) { return false; } - if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this - return true; - } - if (block instanceof BlockGlass || block instanceof BlockStainedGlass) { - return true; - } - if (Blocks.FARMLAND.equals(block) || Blocks.GRASS_PATH.equals(block)) { - return true; - } - if (Blocks.ENDER_CHEST.equals(block) || Blocks.CHEST.equals(block)) { - return true; - } - if (block instanceof BlockSlab) { - if (!Baritone.settings().allowWalkOnBottomSlab.get()) { - if (((BlockSlab) block).isDouble()) { - return true; - } - return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM; + if (state.isBlockNormalCube()) { + if (BlockStateInterface.isLava(block) || BlockStateInterface.isWater(block)) { + throw new IllegalStateException(); } return true; } - if (block instanceof BlockStairs) { + if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.get())) { // TODO reconsider this + return true; + } + if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { + return true; + } + if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST) { return true; } if (BlockStateInterface.isWater(block)) { @@ -261,20 +253,28 @@ public interface MovementHelper extends ActionCosts, Helper { // if assumeWalkOnWater is off, we can only walk on water if there is water above it return BlockStateInterface.isWater(up) ^ Baritone.settings().assumeWalkOnWater.get(); } - if (Blocks.MAGMA.equals(block)) { - return false; + if (block instanceof BlockGlass || block instanceof BlockStainedGlass) { + return true; } - return state.isBlockNormalCube() && !BlockStateInterface.isLava(block); + if (block instanceof BlockSlab) { + if (!Baritone.settings().allowWalkOnBottomSlab.get()) { + if (((BlockSlab) block).isDouble()) { + return true; + } + return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM; + } + return true; + } + if (block instanceof BlockStairs) { + return true; + } + return false; } static boolean canWalkOn(BlockPos pos) { return canWalkOn(pos, BlockStateInterface.get(pos)); } - static boolean canFall(BlockPos pos) { - return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; - } - static boolean canPlaceAgainst(BlockPos pos) { IBlockState state = BlockStateInterface.get(pos); // TODO isBlockNormalCube isn't the best check for whether or not we can place a block against it. e.g. glass isn't normalCube but we can place against it @@ -288,7 +288,7 @@ public interface MovementHelper extends ActionCosts, Helper { static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) { Block block = state.getBlock(); - if (!block.equals(Blocks.AIR) && !canWalkThrough(position, state)) { // TODO is the air check really necessary? Isn't air canWalkThrough? + if (!canWalkThrough(position, state)) { if (!context.allowBreak()) { return COST_INF; } From b69acadca6f43fc585dd378dec7eae7ddd9dd1e9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 08:53:15 -0700 Subject: [PATCH 20/47] start of blockstateinterface overhaul --- .../movement/movements/MovementAscend.java | 2 +- .../baritone/utils/BlockStateInterface.java | 42 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 474fd162..1177b376 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -69,7 +69,7 @@ public class MovementAscend extends Movement { if (!context.hasThrowaway()) { return COST_INF; } - if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) { + if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) { return COST_INF; } // TODO: add ability to place against .down() as well as the cardinal directions diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index efb83e36..4fa2449d 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -21,21 +21,29 @@ import baritone.Baritone; import baritone.chunk.WorldData; import baritone.chunk.WorldProvider; import net.minecraft.block.Block; -import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockLiquid; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; +/** + * Wraps get for chuck caching capability + * + * @author leijurv + */ public class BlockStateInterface implements Helper { private static Chunk prev = null; - public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability + public static IBlockState get(BlockPos pos) { + return get(pos.getX(), pos.getY(), pos.getZ()); + } + + public static IBlockState get(int x, int y, int z) { // Invalid vertical position - if (pos.getY() < 0 || pos.getY() >= 256) { + if (y < 0 || y >= 256) { return Blocks.AIR.getDefaultState(); } @@ -46,18 +54,18 @@ public class BlockStateInterface implements Helper { // if it's the same chunk as last time // we can just skip the mc.world.getChunk lookup // which is a Long2ObjectOpenHashMap.get - if (cached != null && cached.x == pos.getX() >> 4 && cached.z == pos.getZ() >> 4) { - return cached.getBlockState(pos); + if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) { + return cached.getBlockState(x, y, z); } - Chunk chunk = mc.world.getChunk(pos); + Chunk chunk = mc.world.getChunk(x >> 4, z >> 4); if (chunk.isLoaded()) { prev = chunk; - return chunk.getBlockState(pos); + return chunk.getBlockState(x, y, z); } } WorldData world = WorldProvider.INSTANCE.getCurrentWorld(); if (world != null) { - IBlockState type = world.cache.getBlock(pos); + IBlockState type = world.cache.getBlock(x, y, z); if (type != null) { return type; } @@ -88,7 +96,7 @@ public class BlockStateInterface implements Helper { * @return Whether or not the block is water */ public static boolean isWater(Block b) { - return waterFlowing.equals(b) || waterStill.equals(b); + return b == waterFlowing || b == waterStill; } /** @@ -103,7 +111,7 @@ public class BlockStateInterface implements Helper { } public static boolean isLava(Block b) { - return lavaFlowing.equals(b) || lavaStill.equals(b); + return b == lavaFlowing || b == lavaStill; } /** @@ -122,18 +130,4 @@ public class BlockStateInterface implements Helper { && state.getPropertyKeys().contains(BlockLiquid.LEVEL) && state.getValue(BlockLiquid.LEVEL) != 0; } - - public static boolean isAir(BlockPos pos) { - return BlockStateInterface.getBlock(pos).equals(Blocks.AIR); - } - - public static boolean isAir(IBlockState state) { - return state.getBlock().equals(Blocks.AIR); - } - - static boolean canFall(BlockPos pos) { - return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; - } - - } From a8ef421757b5eb76d6af7d0cc830dd0a6144ba5d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 08:57:20 -0700 Subject: [PATCH 21/47] epic performance --- .../pathing/movement/MovementHelper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 832663cc..1dbcfae5 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -48,14 +48,18 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean avoidBreaking(BlockPos pos, IBlockState state) { Block b = state.getBlock(); - Block below = BlockStateInterface.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock(); - return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); + Block below = BlockStateInterface.get(x, y - 1, z).getBlock(); + return b == Blocks.ICE // ice becomes water, and water can mess up the path || b instanceof BlockSilverfish // obvious reasons - || BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side - || BlockStateInterface.isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())) - || BlockStateInterface.isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())) - || BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)) - || BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)); + // call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason + || BlockStateInterface.get(x, y + 1, z) instanceof BlockLiquid//don't break anything touching liquid on any side + || BlockStateInterface.get(x + 1, y, z) instanceof BlockLiquid + || BlockStateInterface.get(x - 1, y, z) instanceof BlockLiquid + || BlockStateInterface.get(x, y, z + 1) instanceof BlockLiquid + || BlockStateInterface.get(x, y, z - 1) instanceof BlockLiquid; } /** From dce51d856b20ec13f2fca4b7ac3b12a23f3662fd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 08:58:36 -0700 Subject: [PATCH 22/47] more specific return type --- .../java/baritone/utils/pathing/BetterBlockPos.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index d25812c0..3cf47478 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -83,7 +83,7 @@ public final class BetterBlockPos extends BlockPos { } @Override - public BlockPos up() { + public BetterBlockPos up() { // this is unimaginably faster than blockpos.up // that literally calls // this.up(1) @@ -97,31 +97,31 @@ public final class BetterBlockPos extends BlockPos { } @Override - public BlockPos up(int amt) { + public BetterBlockPos up(int amt) { // see comment in up() return amt == 0 ? this : new BetterBlockPos(x, y + amt, z); } @Override - public BlockPos down() { + public BetterBlockPos down() { // see comment in up() return new BetterBlockPos(x, y - 1, z); } @Override - public BlockPos down(int amt) { + public BetterBlockPos down(int amt) { // see comment in up() return new BetterBlockPos(x, y - amt, z); } @Override - public BlockPos offset(EnumFacing dir) { + public BetterBlockPos offset(EnumFacing dir) { Vec3i vec = dir.getDirectionVec(); return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ()); } @Override - public BlockPos offset(EnumFacing dir, int dist) { + public BetterBlockPos offset(EnumFacing dir, int dist) { Vec3i vec = dir.getDirectionVec(); return new BetterBlockPos(x + vec.getX() * dist, y + vec.getY() * dist, z + vec.getZ() * dist); } From 760f68cb059e8297ebb1b158b958bba30656a9a5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 09:22:35 -0700 Subject: [PATCH 23/47] instead of casting to BetterBlockPos at runtime, let the compiler verify that --- .../java/baritone/pathing/calc/AStarPathFinder.java | 2 +- .../java/baritone/pathing/movement/Movement.java | 13 +++++++------ .../baritone/pathing/movement/MovementHelper.java | 5 +++-- .../pathing/movement/movements/MovementAscend.java | 7 ++++--- .../pathing/movement/movements/MovementDescend.java | 3 ++- .../movement/movements/MovementDiagonal.java | 7 ++++--- .../movement/movements/MovementDownward.java | 3 ++- .../pathing/movement/movements/MovementFall.java | 3 ++- .../pathing/movement/movements/MovementParkour.java | 5 +++-- .../pathing/movement/movements/MovementPillar.java | 5 +++-- .../movement/movements/MovementTraverse.java | 3 ++- 11 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 893d9686..7435c3f0 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -109,7 +109,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { if (movementToGetToNeighbor == null) { continue; } - BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); + BetterBlockPos dest = movementToGetToNeighbor.getDest(); int chunkX = currentNodePos.x >> 4; int chunkZ = currentNodePos.z >> 4; if (dest.x >> 4 != chunkX || dest.z >> 4 != chunkZ) { diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 0ee4a35f..ddf36034 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -22,6 +22,7 @@ import baritone.behavior.impl.LookBehavior; import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.utils.*; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -39,9 +40,9 @@ public abstract class Movement implements Helper, MovementHelper { private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING); - protected final BlockPos src; + protected final BetterBlockPos src; - protected final BlockPos dest; + protected final BetterBlockPos dest; /** * The positions that need to be broken before this movement can ensue @@ -57,14 +58,14 @@ public abstract class Movement implements Helper, MovementHelper { private Double cost; - protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { + protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { this.src = src; this.dest = dest; this.positionsToBreak = toBreak; this.positionToPlace = toPlace; } - protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) { + protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) { this(src, dest, toBreak, null); } @@ -185,11 +186,11 @@ public abstract class Movement implements Helper, MovementHelper { && currentState.getStatus() != MovementStatus.WAITING); } - public BlockPos getSrc() { + public BetterBlockPos getSrc() { return src; } - public BlockPos getDest() { + public BetterBlockPos getDest() { return dest; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 1dbcfae5..6aa2f5e0 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementState.MovementTarget; import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementFall; import baritone.utils.*; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; @@ -401,7 +402,7 @@ public interface MovementHelper extends ActionCosts, Helper { )).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); } - static Movement generateMovementFallOrDescend(BlockPos pos, BlockPos dest, CalculationContext calcContext) { + static Movement generateMovementFallOrDescend(BetterBlockPos pos, BetterBlockPos dest, CalculationContext calcContext) { // A //SA // A @@ -423,7 +424,7 @@ public interface MovementHelper extends ActionCosts, Helper { // we're clear for a fall 2 // let's see how far we can fall for (int fallHeight = 3; true; fallHeight++) { - BlockPos onto = dest.down(fallHeight); + BetterBlockPos onto = dest.down(fallHeight); if (onto.getY() < 0) { // when pathing in the end, where you could plausibly fall into the void // this check prevents it from getting the block at y=-1 and crashing diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 1177b376..9ddb7760 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -26,6 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus; 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.BlockFalling; import net.minecraft.block.state.IBlockState; @@ -41,7 +42,7 @@ public class MovementAscend extends Movement { private int ticksWithoutPlacement = 0; - public MovementAscend(BlockPos src, BlockPos dest) { + public MovementAscend(BetterBlockPos src, BetterBlockPos dest) { super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); } @@ -155,8 +156,8 @@ public class MovementAscend extends Movement { if (player().isSneaking()) { state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); } - if (ticksWithoutPlacement > 20) { - // After 20 ticks without placement, we might be standing in the way, move back + if (ticksWithoutPlacement > 10) { + // After 10 ticks without placement, we might be standing in the way, move back state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); } } else { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index d8d9d3b2..593c410a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -24,13 +24,14 @@ import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; public class MovementDescend extends Movement { - public MovementDescend(BlockPos start, BlockPos end) { + public MovementDescend(BetterBlockPos start, BetterBlockPos end) { super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down()); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index d343234c..121ea7c7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.block.BlockMagma; import net.minecraft.block.state.IBlockState; @@ -37,16 +38,16 @@ public class MovementDiagonal extends Movement { private static final double SQRT_2 = Math.sqrt(2); - public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) { + public MovementDiagonal(BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) { this(start, start.offset(dir1), start.offset(dir2), dir2); // super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()}); } - public MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) { + private MovementDiagonal(BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) { this(start, dir1.offset(drr2), dir1, dir2); } - public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) { + private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) { super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 9565e932..48d26161 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -22,6 +22,7 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -31,7 +32,7 @@ public class MovementDownward extends Movement { private int numTicks = 0; - public MovementDownward(BlockPos start, BlockPos end) { + public MovementDownward(BetterBlockPos start, BetterBlockPos end) { super(start, end, new BlockPos[]{end}); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 40fa291d..dbcde285 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; import net.minecraft.block.state.IBlockState; @@ -41,7 +42,7 @@ public class MovementFall extends Movement { private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET); private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET); - public MovementFall(BlockPos src, BlockPos dest) { + public MovementFall(BetterBlockPos src, BetterBlockPos dest) { super(src, dest, MovementFall.buildPositionsToBreak(src, dest)); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 40f9b5a3..1041ae07 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -24,6 +24,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; @@ -34,14 +35,14 @@ public class MovementParkour extends Movement { final EnumFacing direction; final int dist; - private MovementParkour(BlockPos src, int dist, EnumFacing dir) { + private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) { super(src, src.offset(dir, dist), new BlockPos[]{}); this.direction = dir; this.dist = dist; super.override(costFromJumpDistance(dist)); } - public static MovementParkour calculate(BlockPos src, EnumFacing dir) { + public static MovementParkour calculate(BetterBlockPos src, EnumFacing dir) { if (!Baritone.settings().allowParkour.get()) { return null; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 6933a83f..73a591ad 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -25,6 +25,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import baritone.utils.Rotation; import baritone.utils.Utils; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -33,7 +34,7 @@ import net.minecraft.util.math.BlockPos; public class MovementPillar extends Movement { private int numTicks = 0; - public MovementPillar(BlockPos start, BlockPos end) { + public MovementPillar(BetterBlockPos start, BetterBlockPos end) { super(start, end, new BlockPos[]{start.up(2)}, start); } @@ -169,7 +170,7 @@ public class MovementPillar extends Movement { state.setInput(InputOverrideHandler.Input.SNEAK, true); // Otherwise jump - if (numTicks > 40) { + if (numTicks > 20) { double diffX = player().posX - (dest.getX() + 0.5); double diffZ = player().posZ - (dest.getZ() + 0.5); double dist = Math.sqrt(diffX * diffX + diffZ * diffZ); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 44c594c0..da206d5e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -25,6 +25,7 @@ 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.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -42,7 +43,7 @@ public class MovementTraverse extends Movement { */ private boolean wasTheBridgeBlockAlwaysThere = true; - public MovementTraverse(BlockPos from, BlockPos to) { + public MovementTraverse(BetterBlockPos from, BetterBlockPos to) { super(from, to, new BlockPos[]{to.up(), to}, to.down()); } From 07b0e2cdbfbcee5e136bb58759e5e3f67bbadf56 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 09:50:19 -0700 Subject: [PATCH 24/47] block state interface cache region too --- .../pathing/calc/AStarPathFinder.java | 2 ++ .../baritone/utils/BlockStateInterface.java | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 7435c3f0..e1cc7372 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -28,6 +28,7 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.pathing.path.IPath; +import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.client.Minecraft; @@ -72,6 +73,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { currentlyRunning = this; CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null); ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); + BlockStateInterface.clearCachedChunk(); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 4fa2449d..bd3186e1 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.chunk.CachedRegion; import baritone.chunk.WorldData; import baritone.chunk.WorldProvider; import net.minecraft.block.Block; @@ -35,6 +36,13 @@ import net.minecraft.world.chunk.Chunk; public class BlockStateInterface implements Helper { private static Chunk prev = null; + private static CachedRegion prevCached = null; + + private static IBlockState AIR = Blocks.AIR.getDefaultState(); + public static final Block waterFlowing = Blocks.FLOWING_WATER; + public static final Block waterStill = Blocks.WATER; + public static final Block lavaFlowing = Blocks.FLOWING_LAVA; + public static final Block lavaStill = Blocks.LAVA; public static IBlockState get(BlockPos pos) { return get(pos.getX(), pos.getY(), pos.getZ()); @@ -44,7 +52,7 @@ public class BlockStateInterface implements Helper { // Invalid vertical position if (y < 0 || y >= 256) { - return Blocks.AIR.getDefaultState(); + return AIR; } if (!Baritone.settings().pathThroughCachedOnly.get()) { @@ -63,30 +71,39 @@ public class BlockStateInterface implements Helper { return chunk.getBlockState(x, y, z); } } + // same idea here, skip the Long2ObjectOpenHashMap.get if at all possible + // except here, it's 512x512 tiles instead of 16x16, so even better repetition + CachedRegion cached = prevCached; + if (cached != null && cached.getX() == x >> 9 && cached.getZ() == z >> 9) { + IBlockState type = cached.getBlock(x & 511, y, z & 511); + if (type == null) { + return AIR; + } + return type; + } WorldData world = WorldProvider.INSTANCE.getCurrentWorld(); if (world != null) { + CachedRegion region = world.cache.getRegion(x >> 9, z >> 9); + if (region != null) { + prevCached = region; + } IBlockState type = world.cache.getBlock(x, y, z); if (type != null) { return type; } } - - - return Blocks.AIR.getDefaultState(); + return AIR; } public static void clearCachedChunk() { prev = null; + prevCached = null; } public static Block getBlock(BlockPos pos) { return get(pos).getBlock(); } - public static final Block waterFlowing = Blocks.FLOWING_WATER; - public static final Block waterStill = Blocks.WATER; - public static final Block lavaFlowing = Blocks.FLOWING_LAVA; - public static final Block lavaStill = Blocks.LAVA; /** * Returns whether or not the specified block is From 44ece7c510df5163ecc7a3ad83e755de66dd7f69 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 09:54:09 -0700 Subject: [PATCH 25/47] prevent double lookup --- src/main/java/baritone/utils/BlockStateInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index bd3186e1..cf56737a 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -87,7 +87,7 @@ public class BlockStateInterface implements Helper { if (region != null) { prevCached = region; } - IBlockState type = world.cache.getBlock(x, y, z); + IBlockState type = region.getBlock(x & 511, y, z & 511); if (type != null) { return type; } From ef4de2b15997d2cb7de8ce74e1b96d3da09186f8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 09:55:59 -0700 Subject: [PATCH 26/47] oh look and another bug --- src/main/java/baritone/utils/BlockStateInterface.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index cf56737a..9a7c7028 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -86,10 +86,10 @@ public class BlockStateInterface implements Helper { CachedRegion region = world.cache.getRegion(x >> 9, z >> 9); if (region != null) { prevCached = region; - } - IBlockState type = region.getBlock(x & 511, y, z & 511); - if (type != null) { - return type; + IBlockState type = region.getBlock(x & 511, y, z & 511); + if (type != null) { + return type; + } } } return AIR; From 4a13b54e50d56e77f0c31de053b0b2e4cd519171 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 10:27:47 -0700 Subject: [PATCH 27/47] brady was right and I was wrong --- .../baritone/api/event/GameEventHandler.java | 52 +++++++++---------- .../pathing/movement/MovementHelper.java | 1 + 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 32634213..9e569980 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -60,20 +60,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onTick(TickEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onTick(event); } - } + }); } @Override public final void onPlayerUpdate(PlayerUpdateEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onPlayerUpdate(event); } - } + }); } @Override @@ -93,20 +93,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { } } - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onProcessKeyBinds(); } - } + }); } @Override public final void onSendChatMessage(ChatEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onSendChatMessage(event); } - } + }); } @Override @@ -132,20 +132,20 @@ public final class GameEventHandler implements IGameEventListener, Helper { } - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onChunkEvent(event); } - } + }); } @Override public final void onRenderPass(RenderEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onRenderPass(event); } - } + }); } @Override @@ -165,65 +165,65 @@ public final class GameEventHandler implements IGameEventListener, Helper { break; } - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onWorldEvent(event); } - } + }); } @Override public final void onSendPacket(PacketEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onSendPacket(event); } - } + }); } @Override public final void onReceivePacket(PacketEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onReceivePacket(event); } - } + }); } @Override public void onPlayerRelativeMove(RelativeMoveEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onPlayerRelativeMove(event); } - } + }); } @Override public void onBlockInteract(BlockInteractEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onBlockInteract(event); } - } + }); } @Override public void onPlayerDeath() { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onPlayerDeath(); } - } + }); } @Override public void onPathEvent(PathEvent event) { - for (IGameEventListener l : listeners) { + listeners.forEach(l -> { if (canDispatch(l)) { l.onPathEvent(event); } - } + }); } public final void registerEventListener(IGameEventListener listener) { diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6aa2f5e0..1036b69f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -419,6 +419,7 @@ public interface MovementHelper extends ActionCosts, Helper { //this doesn't guarantee descend is possible, it just guarantees fall is impossible return new MovementDescend(pos, dest.down()); // standard move out by 1 and descend by 1 + // we can't cost shortcut descend because !canWalkThrough doesn't mean canWalkOn } // we're clear for a fall 2 From 7b712fe677d38f7b9b82355270ace383e58a8e58 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 11:00:57 -0700 Subject: [PATCH 28/47] add synchronization, fixes #145 --- .../baritone/api/event/GameEventHandler.java | 3 +-- src/main/java/baritone/chunk/CachedWorld.java | 21 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 9e569980..2ac27792 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -48,7 +48,6 @@ import net.minecraft.world.chunk.Chunk; import org.lwjgl.input.Keyboard; import java.util.ArrayList; -import java.util.List; /** * @author Brady @@ -56,7 +55,7 @@ import java.util.List; */ public final class GameEventHandler implements IGameEventListener, Helper { - private final List listeners = new ArrayList<>(); + private final ArrayList listeners = new ArrayList<>(); @Override public final void onTick(TickEvent event) { diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index 14097c16..de6ebd5f 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -28,9 +28,10 @@ import net.minecraft.world.chunk.Chunk; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.concurrent.LinkedBlockingQueue; -import java.util.function.Consumer; /** * @author Brady @@ -154,7 +155,7 @@ public final class CachedWorld implements IBlockTypeAccess { return; } long start = System.nanoTime() / 1000000L; - this.cachedRegions.values().parallelStream().forEach(region -> { + allRegions().parallelStream().forEach(region -> { if (region != null) { region.save(this.directory); } @@ -163,9 +164,13 @@ public final class CachedWorld implements IBlockTypeAccess { System.out.println("World save took " + (now - start) + "ms"); } + private synchronized List allRegions() { + return new ArrayList<>(this.cachedRegions.values()); + } + public final void reloadAllFromDisk() { long start = System.nanoTime() / 1000000L; - this.cachedRegions.values().forEach(region -> { + allRegions().forEach(region -> { if (region != null) { region.load(this.directory); } @@ -181,7 +186,7 @@ public final class CachedWorld implements IBlockTypeAccess { * @param regionZ The region Z coordinate * @return The region located at the specified coordinates */ - public final CachedRegion getRegion(int regionX, int regionZ) { + public final synchronized CachedRegion getRegion(int regionX, int regionZ) { return cachedRegions.get(getRegionID(regionX, regionZ)); } @@ -201,14 +206,6 @@ public final class CachedWorld implements IBlockTypeAccess { }); } - public void forEachRegion(Consumer consumer) { - this.cachedRegions.forEach((id, r) -> { - if (r != null) { - consumer.accept(r); - } - }); - } - /** * Returns the region ID based on the region coordinates. 0 will be * returned if the specified region coordinates are out of bounds. From 6801d00d7e11a41790af9072190c3960af0004f2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 11:06:02 -0700 Subject: [PATCH 29/47] enable 1-skipback --- src/main/java/baritone/pathing/path/PathExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 818f9bbb..c1281359 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -90,7 +90,7 @@ public class PathExecutor implements Helper { if (!whereShouldIBe.equals(whereAmI)) { //System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI); if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip - for (int i = 0; i < pathPosition - 2 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks + for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks if (whereAmI.equals(path.positions().get(i))) { displayChatMessageRaw("Skipping back " + (pathPosition - i) + " steps, to " + i); int previousPos = pathPosition; From 4221c07d1f00d6b9deee6940b7795056899e2958 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 13:04:41 -0700 Subject: [PATCH 30/47] i don't know how i keep getting worldscanner wrong lol --- src/main/java/baritone/chunk/WorldScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index 27345670..47d377b1 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -91,7 +91,7 @@ public enum WorldScanner implements Helper { if (allUnloaded) { return res; } - if (res.size() >= max && searchRadiusSq < 26) { + if (res.size() >= max && searchRadiusSq > 26) { return res; } searchRadiusSq++; From d29a37664c05f72e2d7b1d8b1289828675e005bb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 13:09:56 -0700 Subject: [PATCH 31/47] clarify error messages --- .../java/baritone/utils/ExampleBaritoneControl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 9c28f058..492c3652 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -108,7 +108,11 @@ public class ExampleBaritoneControl extends Behavior { if (PathingBehavior.INSTANCE.getGoal() == null) { displayChatMessageRaw("No goal."); } else { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) { + displayChatMessageRaw("Already in goal"); + } else { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } } } event.cancel(); @@ -266,7 +270,9 @@ public class ExampleBaritoneControl extends Behavior { Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); if (!PathingBehavior.INSTANCE.path()) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + if (!goal.isInGoal(playerFeet())) { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } } event.cancel(); return; From d8ca6cad4e9d95eb006325864029853d4697a799 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 13:19:48 -0700 Subject: [PATCH 32/47] i am an idiot 2: electric boogaloo --- .../baritone/pathing/movement/MovementHelper.java | 11 +++++------ .../java/baritone/utils/ExampleBaritoneControl.java | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 1036b69f..dc66d202 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -52,15 +52,14 @@ public interface MovementHelper extends ActionCosts, Helper { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); - Block below = BlockStateInterface.get(x, y - 1, z).getBlock(); return b == Blocks.ICE // ice becomes water, and water can mess up the path || b instanceof BlockSilverfish // obvious reasons // call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason - || BlockStateInterface.get(x, y + 1, z) instanceof BlockLiquid//don't break anything touching liquid on any side - || BlockStateInterface.get(x + 1, y, z) instanceof BlockLiquid - || BlockStateInterface.get(x - 1, y, z) instanceof BlockLiquid - || BlockStateInterface.get(x, y, z + 1) instanceof BlockLiquid - || BlockStateInterface.get(x, y, z - 1) instanceof BlockLiquid; + || BlockStateInterface.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side + || BlockStateInterface.get(x + 1, y, z).getBlock() instanceof BlockLiquid + || BlockStateInterface.get(x - 1, y, z).getBlock() instanceof BlockLiquid + || BlockStateInterface.get(x, y, z + 1).getBlock() instanceof BlockLiquid + || BlockStateInterface.get(x, y, z - 1).getBlock() instanceof BlockLiquid; } /** diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 492c3652..c3eb40aa 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -314,6 +314,9 @@ public class ExampleBaritoneControl extends Behavior { if (msg.toLowerCase().equals("costs")) { Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext()); List moves = new ArrayList<>(Arrays.asList(movements)); + while (moves.contains(null)) { + moves.remove(null); + } moves.sort(Comparator.comparingDouble(movement -> movement.getCost(new CalculationContext()))); for (Movement move : moves) { String[] parts = move.getClass().toString().split("\\."); From 8fa0d63ae5d6ba396210e51343cebc6e725a8e45 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 15:33:53 -0700 Subject: [PATCH 33/47] add link to benchmark --- src/main/java/baritone/utils/pathing/BetterBlockPos.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 3cf47478..574e0250 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -23,6 +23,10 @@ import net.minecraft.util.math.Vec3i; /** * A better BlockPos that has fewer hash collisions (and slightly more performant offsets) + *

+ * Is it really faster to subclass BlockPos and calculate a hash in the constructor like this, taking everything into account? + * Yes. It's called BETTER BlockPos for a reason. Source: + * https://docs.google.com/spreadsheets/d/1GWjOjOZINkg_0MkRgKRPH1kUzxjsnEROD9u3UFh_DJc/edit * * @author leijurv */ From ecbb34366f861e77a75e713737a25710e8d64d16 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 9 Sep 2018 17:37:12 -0500 Subject: [PATCH 34/47] Hyperlink the benchmark spreadsheet for BetterBlockPos --- src/main/java/baritone/utils/pathing/BetterBlockPos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 574e0250..216a8b63 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.Vec3i; *

* Is it really faster to subclass BlockPos and calculate a hash in the constructor like this, taking everything into account? * Yes. It's called BETTER BlockPos for a reason. Source: - * https://docs.google.com/spreadsheets/d/1GWjOjOZINkg_0MkRgKRPH1kUzxjsnEROD9u3UFh_DJc/edit + * Benchmark Spreadsheet * * @author leijurv */ From 075ad3f244166e24066cdb79a1d4c6b9b499bab7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Sep 2018 15:38:59 -0700 Subject: [PATCH 35/47] almost forgot crucial performance numbers --- src/main/java/baritone/utils/pathing/BetterBlockPos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 216a8b63..895d982f 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -25,7 +25,7 @@ import net.minecraft.util.math.Vec3i; * A better BlockPos that has fewer hash collisions (and slightly more performant offsets) *

* Is it really faster to subclass BlockPos and calculate a hash in the constructor like this, taking everything into account? - * Yes. It's called BETTER BlockPos for a reason. Source: + * Yes. 20% faster actually. It's called BETTER BlockPos for a reason. Source: * Benchmark Spreadsheet * * @author leijurv From 72eec135d02d09b773240c175edb3c8accab8654 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 10 Sep 2018 09:22:32 -0700 Subject: [PATCH 36/47] misc improvements --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- src/main/java/baritone/pathing/calc/PathNode.java | 3 ++- .../pathing/movement/movements/MovementParkour.java | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index e1cc7372..d03e52f8 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -158,8 +158,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { if (neighbor.isOpen) { openSet.update(neighbor); } else { - openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there neighbor.isOpen = true; + openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there } for (int i = 0; i < bestSoFar.length; i++) { double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i]; diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index 45190fa7..3d984548 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -18,6 +18,7 @@ package baritone.pathing.calc; import baritone.pathing.goals.Goal; +import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.Movement; import baritone.utils.pathing.BetterBlockPos; @@ -81,7 +82,7 @@ public final class PathNode { public PathNode(BetterBlockPos pos, Goal goal) { this.pos = pos; this.previous = null; - this.cost = Short.MAX_VALUE; + this.cost = ActionCosts.COST_INF; this.goal = goal; this.estimatedCostToGoal = goal.heuristic(pos); this.previousMovement = null; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 1041ae07..8cd37c73 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -65,6 +65,12 @@ public class MovementParkour extends Movement { if (!MovementHelper.fullyPassable(src.up().offset(dir))) { return null; } + if (!MovementHelper.fullyPassable(src.up(2).offset(dir))) { + return null; + } + if (!MovementHelper.fullyPassable(src.up(2))) { + return null; + } for (int i = 2; i <= 4; i++) { BlockPos dest = src.offset(dir, i); // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? From a59d30d11e8a23d575b9aace500a3b2ef0946369 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 10 Sep 2018 10:42:55 -0700 Subject: [PATCH 37/47] update commit and link --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index 7fa22435..574e5a0c 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -2,7 +2,7 @@ Baritone will be in Impact 4.4 with nice integrations with its utility modules, but if you're impatient you can run Baritone on top of Impact 4.3 right now. -You can either build Baritone yourself, or download the jar from September 4 from here +You can either build Baritone yourself, or download the jar (as of commit 72eec13, built on September 10) from here. To build it yourself, clone and setup Baritone (instructions in main README.md). Then, build the jar. From the command line, it's `./gradlew build` (or `gradlew build` on Windows). In IntelliJ, you can just start the `build` task in the Gradle menu. From fb07e471418b4848c661b05ac9676acf77e19c93 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 10 Sep 2018 10:47:31 -0700 Subject: [PATCH 38/47] better instructions --- IMPACT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IMPACT.md b/IMPACT.md index 574e5a0c..ec7b6707 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -6,9 +6,9 @@ You can either build Baritone yourself, or download the jar (as of commit Date: Mon, 10 Sep 2018 14:48:18 -0700 Subject: [PATCH 39/47] misc cleanup --- .../pathing/calc/AStarPathFinder.java | 29 ++++++++++++------- .../pathing/calc/AbstractNodeCostSearch.java | 6 ++-- .../movement/movements/MovementParkour.java | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index d03e52f8..bf553e18 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -210,36 +210,43 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) { - int x = pos.getX(); - int y = pos.getY(); - int z = pos.getZ(); + int x = pos.x; + int y = pos.y; + int z = pos.z; BetterBlockPos east = new BetterBlockPos(x + 1, y, z); BetterBlockPos west = new BetterBlockPos(x - 1, y, z); BetterBlockPos south = new BetterBlockPos(x, y, z + 1); BetterBlockPos north = new BetterBlockPos(x, y, z - 1); return new Movement[]{ + new MovementDownward(pos, new BetterBlockPos(x, y - 1, z)), + + new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)), + new MovementTraverse(pos, east), new MovementTraverse(pos, west), new MovementTraverse(pos, north), new MovementTraverse(pos, south), + new MovementAscend(pos, new BetterBlockPos(x + 1, y + 1, z)), new MovementAscend(pos, new BetterBlockPos(x - 1, y + 1, z)), new MovementAscend(pos, new BetterBlockPos(x, y + 1, z + 1)), new MovementAscend(pos, new BetterBlockPos(x, y + 1, z - 1)), + MovementHelper.generateMovementFallOrDescend(pos, east, calcContext), MovementHelper.generateMovementFallOrDescend(pos, west, calcContext), MovementHelper.generateMovementFallOrDescend(pos, north, calcContext), MovementHelper.generateMovementFallOrDescend(pos, south, calcContext), - new MovementDownward(pos, new BetterBlockPos(x, y - 1, z)), - new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST), + new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST), - new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST), + new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST), - new MovementPillar(pos, new BetterBlockPos(x, y + 1, z)), - MovementParkour.calculate(pos, EnumFacing.NORTH), - MovementParkour.calculate(pos, EnumFacing.SOUTH), - MovementParkour.calculate(pos, EnumFacing.EAST), - MovementParkour.calculate(pos, EnumFacing.WEST), + + 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), }; } diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 5804cb1a..92c85b1d 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -107,9 +107,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * @return The distance, squared */ protected double getDistFromStartSq(PathNode n) { - int xDiff = n.pos.getX() - start.getX(); - int yDiff = n.pos.getY() - start.getY(); - int zDiff = n.pos.getZ() - start.getZ(); + int xDiff = n.pos.x - start.x; + int yDiff = n.pos.y - start.y; + int zDiff = n.pos.z - start.z; return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 8cd37c73..b14abbca 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -42,7 +42,7 @@ public class MovementParkour extends Movement { super.override(costFromJumpDistance(dist)); } - public static MovementParkour calculate(BetterBlockPos src, EnumFacing dir) { + public static MovementParkour generate(BetterBlockPos src, EnumFacing dir) { if (!Baritone.settings().allowParkour.get()) { return null; } From a67e6fd1638818d7856001b39dd599a0fbf57690 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 10 Sep 2018 17:18:01 -0500 Subject: [PATCH 40/47] Create and use injection point on pre/post jump, fixes #146 Also removed ItemSlotEvent because @leijurv is retarded --- .../baritone/launch/mixins/MixinEntity.java | 6 +- .../launch/mixins/MixinEntityLivingBase.java | 57 +++++++++++++++++++ src/launch/resources/mixins.baritone.json | 1 + .../baritone/api/event/GameEventHandler.java | 4 +- .../api/event/events/ItemSlotEvent.java | 56 ------------------ ...eMoveEvent.java => RotationMoveEvent.java} | 36 +++++++++++- .../listener/AbstractGameEventListener.java | 2 +- .../event/listener/IGameEventListener.java | 5 +- .../baritone/behavior/impl/LookBehavior.java | 7 ++- 9 files changed, 106 insertions(+), 68 deletions(-) create mode 100644 src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java delete mode 100644 src/main/java/baritone/api/event/events/ItemSlotEvent.java rename src/main/java/baritone/api/event/events/{RelativeMoveEvent.java => RotationMoveEvent.java} (59%) diff --git a/src/launch/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java index 2a0134d3..22be4154 100644 --- a/src/launch/java/baritone/launch/mixins/MixinEntity.java +++ b/src/launch/java/baritone/launch/mixins/MixinEntity.java @@ -18,7 +18,7 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.api.event.events.RelativeMoveEvent; +import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.type.EventState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; @@ -41,7 +41,7 @@ public class MixinEntity { private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { Entity _this = (Entity) (Object) this; if (_this == Minecraft.getMinecraft().player) - Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.PRE)); + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.MOTION_UPDATE)); } @Inject( @@ -51,6 +51,6 @@ public class MixinEntity { private void postMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) { Entity _this = (Entity) (Object) this; if (_this == Minecraft.getMinecraft().player) - Baritone.INSTANCE.getGameEventHandler().onPlayerRelativeMove(new RelativeMoveEvent(EventState.POST)); + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.MOTION_UPDATE)); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java new file mode 100644 index 00000000..61f6db7a --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinEntityLivingBase.java @@ -0,0 +1,57 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.launch.mixins; + +import baritone.Baritone; +import baritone.api.event.events.RotationMoveEvent; +import baritone.api.event.events.type.EventState; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * @author Brady + * @since 9/10/2018 + */ +@Mixin(EntityLivingBase.class) +public class MixinEntityLivingBase { + + @Inject( + method = "jump", + at = @At("HEAD") + ) + private void preJump(CallbackInfo ci) { + Entity _this = (Entity) (Object) this; + if (_this == Minecraft.getMinecraft().player) + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.PRE, RotationMoveEvent.Type.JUMP)); + } + + @Inject( + method = "jump", + at = @At("RETURN") + ) + private void postJump(CallbackInfo ci) { + Entity _this = (Entity) (Object) this; + if (_this == Minecraft.getMinecraft().player) + Baritone.INSTANCE.getGameEventHandler().onPlayerRotationMove(new RotationMoveEvent(EventState.POST, RotationMoveEvent.Type.JUMP)); + } +} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index b1a8ed31..413bbbe7 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -12,6 +12,7 @@ "MixinBlockPos", "MixinChunkProviderServer", "MixinEntity", + "MixinEntityLivingBase", "MixinEntityPlayerSP", "MixinEntityRenderer", "MixinGameSettings", diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 2ac27792..299ff323 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -190,10 +190,10 @@ public final class GameEventHandler implements IGameEventListener, Helper { } @Override - public void onPlayerRelativeMove(RelativeMoveEvent event) { + public void onPlayerRotationMove(RotationMoveEvent event) { listeners.forEach(l -> { if (canDispatch(l)) { - l.onPlayerRelativeMove(event); + l.onPlayerRotationMove(event); } }); } diff --git a/src/main/java/baritone/api/event/events/ItemSlotEvent.java b/src/main/java/baritone/api/event/events/ItemSlotEvent.java deleted file mode 100644 index 82e69177..00000000 --- a/src/main/java/baritone/api/event/events/ItemSlotEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.event.events; - -import baritone.api.event.listener.IGameEventListener; - -/** - * Called in some cases where a player's inventory has it's current slot queried. - *

- * @see IGameEventListener#onQueryItemSlotForBlocks() - * - * @author Brady - * @since 8/20/2018 - */ -public final class ItemSlotEvent { - - /** - * The current slot index - */ - private int slot; - - public ItemSlotEvent(int slot) { - this.slot = slot; - } - - /** - * Sets the new slot index that will be used - * - * @param slot The slot index - */ - public final void setSlot(int slot) { - this.slot = slot; - } - - /** - * @return The current slot index - */ - public final int getSlot() { - return this.slot; - } -} diff --git a/src/main/java/baritone/api/event/events/RelativeMoveEvent.java b/src/main/java/baritone/api/event/events/RotationMoveEvent.java similarity index 59% rename from src/main/java/baritone/api/event/events/RelativeMoveEvent.java rename to src/main/java/baritone/api/event/events/RotationMoveEvent.java index 14798fd5..7bedf857 100644 --- a/src/main/java/baritone/api/event/events/RelativeMoveEvent.java +++ b/src/main/java/baritone/api/event/events/RotationMoveEvent.java @@ -18,20 +18,28 @@ package baritone.api.event.events; import baritone.api.event.events.type.EventState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; /** * @author Brady * @since 8/21/2018 */ -public final class RelativeMoveEvent { +public final class RotationMoveEvent { + + /** + * The type of event + */ + private final Type type; /** * The state of the event */ private final EventState state; - public RelativeMoveEvent(EventState state) { + public RotationMoveEvent(EventState state, Type type) { this.state = state; + this.type = type; } /** @@ -40,4 +48,28 @@ public final class RelativeMoveEvent { public final EventState getState() { return this.state; } + + /** + * @return The type of the event + */ + public final Type getType() { + return this.type; + } + + public enum Type { + + /** + * Called when the player's motion is updated. + * + * @see Entity#moveRelative(float, float, float, float) + */ + MOTION_UPDATE, + + /** + * Called when the player jumps. + * + * @see EntityLivingBase#jump + */ + JUMP + } } diff --git a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java index 3b228e9d..5839e6d5 100644 --- a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -75,7 +75,7 @@ public interface AbstractGameEventListener extends IGameEventListener { default void onReceivePacket(PacketEvent event) {} @Override - default void onPlayerRelativeMove(RelativeMoveEvent event) {} + default void onPlayerRotationMove(RotationMoveEvent event) {} @Override default void onBlockInteract(BlockInteractEvent event) {} diff --git a/src/main/java/baritone/api/event/listener/IGameEventListener.java b/src/main/java/baritone/api/event/listener/IGameEventListener.java index 81f91774..c63cbfbc 100644 --- a/src/main/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/IGameEventListener.java @@ -43,6 +43,7 @@ import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.util.text.ITextComponent; @@ -120,10 +121,12 @@ public interface IGameEventListener { /** * Run once per game tick from before and after the player's moveRelative method is called + * and before and after the player jumps. * * @see Entity#moveRelative(float, float, float, float) + * @see EntityLivingBase#jump() */ - void onPlayerRelativeMove(RelativeMoveEvent event); + void onPlayerRotationMove(RotationMoveEvent event); /** * Called when the local player interacts with a block, whether it is breaking or opening/placing. diff --git a/src/main/java/baritone/behavior/impl/LookBehavior.java b/src/main/java/baritone/behavior/impl/LookBehavior.java index b740618a..904087ab 100644 --- a/src/main/java/baritone/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/behavior/impl/LookBehavior.java @@ -20,7 +20,7 @@ package baritone.behavior.impl; import baritone.Baritone; import baritone.Settings; import baritone.api.event.events.PlayerUpdateEvent; -import baritone.api.event.events.RelativeMoveEvent; +import baritone.api.event.events.RotationMoveEvent; import baritone.behavior.Behavior; import baritone.utils.Rotation; @@ -92,7 +92,7 @@ public class LookBehavior extends Behavior { } @Override - public void onPlayerRelativeMove(RelativeMoveEvent event) { + public void onPlayerRotationMove(RotationMoveEvent event) { if (this.target != null && !this.force) { switch (event.getState()) { case PRE: @@ -103,7 +103,8 @@ public class LookBehavior extends Behavior { player().rotationYaw = this.lastYaw; // If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate() - if (!Baritone.settings().antiCheatCompatibility.get()) { + // Also the type has to be MOTION_UPDATE because that is called after JUMP + if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE) { this.target = null; } break; From 9daf46e30c061ee82f95f4b5da54d0968c4b28b0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 06:37:08 -0700 Subject: [PATCH 41/47] typos --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- src/main/java/baritone/utils/Helper.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index dc66d202..6aab4bd5 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -125,7 +125,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { return true; } - // exceptions - blocks that are isPassasble true, but we can't actually jump through + // exceptions - blocks that are isPassable true, but we can't actually jump through if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 383e7bf0..30e1f398 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -77,7 +77,9 @@ public interface Helper { if (!Baritone.settings().chatDebug.get()) { System.out.println("Suppressed debug message:"); System.out.println(message); - return; + /*if (!Stream.of(Thread.currentThread().getStackTrace()).map(StackTraceElement::getClassName).anyMatch(x -> x.equals(ExampleBaritoneControl.class.getName()))) { + return; + }*/ } ITextComponent component = MESSAGE_PREFIX.createCopy(); From a0a480e2cca46b3b72d2b5ee4213b8c834b768db Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 11 Sep 2018 12:05:12 -0500 Subject: [PATCH 42/47] Move api package in main to api sourceset --- .../api/event/events/BlockInteractEvent.java | 0 .../baritone/api/event/events/ChatEvent.java | 0 .../baritone/api/event/events/ChunkEvent.java | 0 .../api/event/events/PacketEvent.java | 0 .../baritone/api/event/events/PathEvent.java | 0 .../api/event/events/PlayerUpdateEvent.java | 0 .../api/event/events/RenderEvent.java | 0 .../api/event/events/RotationMoveEvent.java | 0 .../baritone/api/event/events/TickEvent.java | 0 .../baritone/api/event/events/WorldEvent.java | 0 .../api/event/events/type/Cancellable.java | 0 .../api/event/events/type/EventState.java | 0 .../listener/AbstractGameEventListener.java | 0 .../event/listener/IGameEventListener.java | 0 src/main/java/baritone/Baritone.java | 5 +++-- .../{api => }/event/GameEventHandler.java | 19 +------------------ 16 files changed, 4 insertions(+), 20 deletions(-) rename src/{main => api}/java/baritone/api/event/events/BlockInteractEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/ChatEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/ChunkEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/PacketEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/PathEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/PlayerUpdateEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/RenderEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/RotationMoveEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/TickEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/WorldEvent.java (100%) rename src/{main => api}/java/baritone/api/event/events/type/Cancellable.java (100%) rename src/{main => api}/java/baritone/api/event/events/type/EventState.java (100%) rename src/{main => api}/java/baritone/api/event/listener/AbstractGameEventListener.java (100%) rename src/{main => api}/java/baritone/api/event/listener/IGameEventListener.java (100%) rename src/main/java/baritone/{api => }/event/GameEventHandler.java (89%) diff --git a/src/main/java/baritone/api/event/events/BlockInteractEvent.java b/src/api/java/baritone/api/event/events/BlockInteractEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/BlockInteractEvent.java rename to src/api/java/baritone/api/event/events/BlockInteractEvent.java diff --git a/src/main/java/baritone/api/event/events/ChatEvent.java b/src/api/java/baritone/api/event/events/ChatEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/ChatEvent.java rename to src/api/java/baritone/api/event/events/ChatEvent.java diff --git a/src/main/java/baritone/api/event/events/ChunkEvent.java b/src/api/java/baritone/api/event/events/ChunkEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/ChunkEvent.java rename to src/api/java/baritone/api/event/events/ChunkEvent.java diff --git a/src/main/java/baritone/api/event/events/PacketEvent.java b/src/api/java/baritone/api/event/events/PacketEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/PacketEvent.java rename to src/api/java/baritone/api/event/events/PacketEvent.java diff --git a/src/main/java/baritone/api/event/events/PathEvent.java b/src/api/java/baritone/api/event/events/PathEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/PathEvent.java rename to src/api/java/baritone/api/event/events/PathEvent.java diff --git a/src/main/java/baritone/api/event/events/PlayerUpdateEvent.java b/src/api/java/baritone/api/event/events/PlayerUpdateEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/PlayerUpdateEvent.java rename to src/api/java/baritone/api/event/events/PlayerUpdateEvent.java diff --git a/src/main/java/baritone/api/event/events/RenderEvent.java b/src/api/java/baritone/api/event/events/RenderEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/RenderEvent.java rename to src/api/java/baritone/api/event/events/RenderEvent.java diff --git a/src/main/java/baritone/api/event/events/RotationMoveEvent.java b/src/api/java/baritone/api/event/events/RotationMoveEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/RotationMoveEvent.java rename to src/api/java/baritone/api/event/events/RotationMoveEvent.java diff --git a/src/main/java/baritone/api/event/events/TickEvent.java b/src/api/java/baritone/api/event/events/TickEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/TickEvent.java rename to src/api/java/baritone/api/event/events/TickEvent.java diff --git a/src/main/java/baritone/api/event/events/WorldEvent.java b/src/api/java/baritone/api/event/events/WorldEvent.java similarity index 100% rename from src/main/java/baritone/api/event/events/WorldEvent.java rename to src/api/java/baritone/api/event/events/WorldEvent.java diff --git a/src/main/java/baritone/api/event/events/type/Cancellable.java b/src/api/java/baritone/api/event/events/type/Cancellable.java similarity index 100% rename from src/main/java/baritone/api/event/events/type/Cancellable.java rename to src/api/java/baritone/api/event/events/type/Cancellable.java diff --git a/src/main/java/baritone/api/event/events/type/EventState.java b/src/api/java/baritone/api/event/events/type/EventState.java similarity index 100% rename from src/main/java/baritone/api/event/events/type/EventState.java rename to src/api/java/baritone/api/event/events/type/EventState.java diff --git a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java similarity index 100% rename from src/main/java/baritone/api/event/listener/AbstractGameEventListener.java rename to src/api/java/baritone/api/event/listener/AbstractGameEventListener.java diff --git a/src/main/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java similarity index 100% rename from src/main/java/baritone/api/event/listener/IGameEventListener.java rename to src/api/java/baritone/api/event/listener/IGameEventListener.java diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 5baacec8..3c7bf24c 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -17,9 +17,10 @@ package baritone; -import baritone.api.event.GameEventHandler; +import baritone.api.event.listener.IGameEventListener; import baritone.behavior.Behavior; import baritone.behavior.impl.*; +import baritone.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; @@ -99,7 +100,7 @@ public enum Baritone { return this.initialized; } - public final GameEventHandler getGameEventHandler() { + public final IGameEventListener getGameEventHandler() { return this.gameEventHandler; } diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java similarity index 89% rename from src/main/java/baritone/api/event/GameEventHandler.java rename to src/main/java/baritone/event/GameEventHandler.java index 299ff323..e6dba1ec 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -15,24 +15,7 @@ * along with Baritone. If not, see . */ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.event; +package baritone.event; import baritone.Baritone; import baritone.api.event.events.*; From 35ed0f6821170034372c0154ce62e820c02b1b69 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 10:28:03 -0700 Subject: [PATCH 43/47] refactor chunk to cache --- .../baritone/behavior/impl/LocationTrackingBehavior.java | 4 ++-- src/main/java/baritone/behavior/impl/MineBehavior.java | 8 ++++---- src/main/java/baritone/{chunk => cache}/CachedChunk.java | 2 +- src/main/java/baritone/{chunk => cache}/CachedRegion.java | 2 +- src/main/java/baritone/{chunk => cache}/CachedWorld.java | 2 +- src/main/java/baritone/{chunk => cache}/ChunkPacker.java | 2 +- src/main/java/baritone/{chunk => cache}/Waypoint.java | 2 +- src/main/java/baritone/{chunk => cache}/Waypoints.java | 2 +- src/main/java/baritone/{chunk => cache}/WorldData.java | 2 +- .../java/baritone/{chunk => cache}/WorldProvider.java | 2 +- src/main/java/baritone/{chunk => cache}/WorldScanner.java | 2 +- src/main/java/baritone/event/GameEventHandler.java | 2 +- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 4 ++-- src/main/java/baritone/utils/BlockStateInterface.java | 6 +++--- src/main/java/baritone/utils/ExampleBaritoneControl.java | 6 +++--- .../java/baritone/{chunk => cache}/CachedRegionTest.java | 2 +- 16 files changed, 25 insertions(+), 25 deletions(-) rename src/main/java/baritone/{chunk => cache}/CachedChunk.java (99%) rename src/main/java/baritone/{chunk => cache}/CachedRegion.java (99%) rename src/main/java/baritone/{chunk => cache}/CachedWorld.java (99%) rename src/main/java/baritone/{chunk => cache}/ChunkPacker.java (99%) rename src/main/java/baritone/{chunk => cache}/Waypoint.java (99%) rename src/main/java/baritone/{chunk => cache}/Waypoints.java (99%) rename src/main/java/baritone/{chunk => cache}/WorldData.java (98%) rename src/main/java/baritone/{chunk => cache}/WorldProvider.java (99%) rename src/main/java/baritone/{chunk => cache}/WorldScanner.java (99%) rename src/test/java/baritone/{chunk => cache}/CachedRegionTest.java (98%) diff --git a/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java index ba075dd3..47dfcd7c 100644 --- a/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java +++ b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java @@ -18,8 +18,8 @@ package baritone.behavior.impl; import baritone.behavior.Behavior; -import baritone.chunk.Waypoint; -import baritone.chunk.WorldProvider; +import baritone.cache.Waypoint; +import baritone.cache.WorldProvider; import baritone.api.event.events.BlockInteractEvent; import baritone.utils.BlockStateInterface; import net.minecraft.block.BlockBed; diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 0b4b3b2a..ab68783e 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -19,10 +19,10 @@ package baritone.behavior.impl; import baritone.api.event.events.PathEvent; import baritone.behavior.Behavior; -import baritone.chunk.CachedChunk; -import baritone.chunk.ChunkPacker; -import baritone.chunk.WorldProvider; -import baritone.chunk.WorldScanner; +import baritone.cache.CachedChunk; +import baritone.cache.ChunkPacker; +import baritone.cache.WorldProvider; +import baritone.cache.WorldScanner; import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java similarity index 99% rename from src/main/java/baritone/chunk/CachedChunk.java rename to src/main/java/baritone/cache/CachedChunk.java index 56f7662a..fbab3161 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.utils.pathing.IBlockTypeAccess; import baritone.utils.pathing.PathingBlockType; diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/cache/CachedRegion.java similarity index 99% rename from src/main/java/baritone/chunk/CachedRegion.java rename to src/main/java/baritone/cache/CachedRegion.java index ee305527..1e5e8ea5 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/cache/CachedRegion.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.utils.pathing.IBlockTypeAccess; import net.minecraft.block.state.IBlockState; diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java similarity index 99% rename from src/main/java/baritone/chunk/CachedWorld.java rename to src/main/java/baritone/cache/CachedWorld.java index de6ebd5f..d56882b4 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.Baritone; import baritone.utils.pathing.IBlockTypeAccess; diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java similarity index 99% rename from src/main/java/baritone/chunk/ChunkPacker.java rename to src/main/java/baritone/cache/ChunkPacker.java index 583dddc0..7167df34 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; diff --git a/src/main/java/baritone/chunk/Waypoint.java b/src/main/java/baritone/cache/Waypoint.java similarity index 99% rename from src/main/java/baritone/chunk/Waypoint.java rename to src/main/java/baritone/cache/Waypoint.java index 8b290d56..7cd5ace3 100644 --- a/src/main/java/baritone/chunk/Waypoint.java +++ b/src/main/java/baritone/cache/Waypoint.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import com.google.common.collect.ImmutableList; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/chunk/Waypoints.java b/src/main/java/baritone/cache/Waypoints.java similarity index 99% rename from src/main/java/baritone/chunk/Waypoints.java rename to src/main/java/baritone/cache/Waypoints.java index ec587fea..82cf893f 100644 --- a/src/main/java/baritone/chunk/Waypoints.java +++ b/src/main/java/baritone/cache/Waypoints.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/chunk/WorldData.java b/src/main/java/baritone/cache/WorldData.java similarity index 98% rename from src/main/java/baritone/chunk/WorldData.java rename to src/main/java/baritone/cache/WorldData.java index 3cd7b737..a7d0b72a 100644 --- a/src/main/java/baritone/chunk/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import java.nio.file.Path; diff --git a/src/main/java/baritone/chunk/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java similarity index 99% rename from src/main/java/baritone/chunk/WorldProvider.java rename to src/main/java/baritone/cache/WorldProvider.java index 007f037d..0275301d 100644 --- a/src/main/java/baritone/chunk/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.Baritone; import baritone.utils.Helper; diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java similarity index 99% rename from src/main/java/baritone/chunk/WorldScanner.java rename to src/main/java/baritone/cache/WorldScanner.java index 47d377b1..2b1ebe23 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import baritone.utils.Helper; import net.minecraft.block.Block; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index e6dba1ec..c681bc29 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -21,7 +21,7 @@ import baritone.Baritone; import baritone.api.event.events.*; import baritone.api.event.events.type.EventState; import baritone.api.event.listener.IGameEventListener; -import baritone.chunk.WorldProvider; +import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.InputOverrideHandler; diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index bf553e18..674d5b64 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -18,8 +18,8 @@ package baritone.pathing.calc; import baritone.Baritone; -import baritone.chunk.CachedWorld; -import baritone.chunk.WorldProvider; +import baritone.cache.CachedWorld; +import baritone.cache.WorldProvider; import baritone.pathing.calc.openset.BinaryHeapOpenSet; import baritone.pathing.goals.Goal; import baritone.pathing.movement.ActionCosts; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 9a7c7028..1ccd5ac6 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -18,9 +18,9 @@ package baritone.utils; import baritone.Baritone; -import baritone.chunk.CachedRegion; -import baritone.chunk.WorldData; -import baritone.chunk.WorldProvider; +import baritone.cache.CachedRegion; +import baritone.cache.WorldData; +import baritone.cache.WorldProvider; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.state.IBlockState; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index c3eb40aa..b12db109 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -24,9 +24,9 @@ import baritone.behavior.Behavior; import baritone.behavior.impl.FollowBehavior; import baritone.behavior.impl.MineBehavior; import baritone.behavior.impl.PathingBehavior; -import baritone.chunk.ChunkPacker; -import baritone.chunk.Waypoint; -import baritone.chunk.WorldProvider; +import baritone.cache.ChunkPacker; +import baritone.cache.Waypoint; +import baritone.cache.WorldProvider; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.goals.*; diff --git a/src/test/java/baritone/chunk/CachedRegionTest.java b/src/test/java/baritone/cache/CachedRegionTest.java similarity index 98% rename from src/test/java/baritone/chunk/CachedRegionTest.java rename to src/test/java/baritone/cache/CachedRegionTest.java index 8350390c..dc595e2e 100644 --- a/src/test/java/baritone/chunk/CachedRegionTest.java +++ b/src/test/java/baritone/cache/CachedRegionTest.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.chunk; +package baritone.cache; import org.junit.Test; From 3dfde818d3a42116445d1c90ada770c7d0189f01 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 11:29:54 -0700 Subject: [PATCH 44/47] api source set --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8a2639f8..1ab9fe8d 100755 --- a/build.gradle +++ b/build.gradle @@ -87,5 +87,5 @@ mixin { } jar { - from sourceSets.launch.output + from sourceSets.launch.output, sourceSets.api.output } From ab1037bcfd9f504af53f1c2bb93f1956c1ece4f7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 11:56:59 -0700 Subject: [PATCH 45/47] blockstateinterface reorg --- src/main/java/baritone/cache/CachedWorld.java | 16 ++---------- .../baritone/utils/BlockStateInterface.java | 26 +++++++++---------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index d56882b4..d903c2cd 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -18,10 +18,9 @@ package baritone.cache; import baritone.Baritone; -import baritone.utils.pathing.IBlockTypeAccess; +import baritone.utils.Helper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; @@ -37,7 +36,7 @@ import java.util.concurrent.LinkedBlockingQueue; * @author Brady * @since 8/4/2018 12:02 AM */ -public final class CachedWorld implements IBlockTypeAccess { +public final class CachedWorld implements Helper { /** * The maximum number of regions in any direction from (0,0) @@ -92,16 +91,6 @@ public final class CachedWorld implements IBlockTypeAccess { } } - @Override - public final IBlockState getBlock(int x, int y, int z) { - // no point in doing getOrCreate region, if we don't have it we don't have it - CachedRegion region = getRegion(x >> 9, z >> 9); - if (region == null) { - return null; - } - return region.getBlock(x & 511, y, z & 511); - } - public final boolean isCached(BlockPos pos) { int x = pos.getX(); int z = pos.getZ(); @@ -112,7 +101,6 @@ public final class CachedWorld implements IBlockTypeAccess { return region.isCached(x & 511, z & 511); } - public final LinkedList getLocationsOf(String block, int minimum, int maxRegionDistanceSq) { LinkedList res = new LinkedList<>(); int playerRegionX = playerFeet().getX() >> 9; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 1ccd5ac6..bb4d094d 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -74,25 +74,23 @@ public class BlockStateInterface implements Helper { // same idea here, skip the Long2ObjectOpenHashMap.get if at all possible // except here, it's 512x512 tiles instead of 16x16, so even better repetition CachedRegion cached = prevCached; - if (cached != null && cached.getX() == x >> 9 && cached.getZ() == z >> 9) { - IBlockState type = cached.getBlock(x & 511, y, z & 511); - if (type == null) { + if (cached == null || cached.getX() != x >> 9 || cached.getZ() != z >> 9) { + WorldData world = WorldProvider.INSTANCE.getCurrentWorld(); + if (world == null) { return AIR; } - return type; - } - WorldData world = WorldProvider.INSTANCE.getCurrentWorld(); - if (world != null) { CachedRegion region = world.cache.getRegion(x >> 9, z >> 9); - if (region != null) { - prevCached = region; - IBlockState type = region.getBlock(x & 511, y, z & 511); - if (type != null) { - return type; - } + if (region == null) { + return AIR; } + prevCached = region; + cached = region; } - return AIR; + IBlockState type = cached.getBlock(x & 511, y, z & 511); + if (type == null) { + return AIR; + } + return type; } public static void clearCachedChunk() { From bafc938424164088852b06b5d12752c400bdcc5c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 13:15:13 -0700 Subject: [PATCH 46/47] possibly fix parkour cost calculation issue --- .../baritone/pathing/movement/movements/MovementParkour.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index b14abbca..07126ca1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -109,7 +109,7 @@ public class MovementParkour extends Movement { } for (int i = 1; i <= 4; i++) { BlockPos d = src.offset(direction, i); - for (int y = 0; y < 4; y++) { + for (int y = 0; y < (i == 1 ? 3 : 4); y++) { if (!MovementHelper.fullyPassable(d.up(y))) { return COST_INF; } From ff2714b15fe05fcb338ffe68a2b0bab5d05c15f1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 13:45:43 -0700 Subject: [PATCH 47/47] refactor logging, fixes #153 --- .../baritone/behavior/impl/MineBehavior.java | 2 +- .../behavior/impl/PathingBehavior.java | 22 +++--- .../pathing/calc/AStarPathFinder.java | 10 +-- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 6 +- .../java/baritone/pathing/path/IPath.java | 8 +- .../baritone/pathing/path/PathExecutor.java | 20 ++--- .../utils/ExampleBaritoneControl.java | 76 +++++++++---------- src/main/java/baritone/utils/Helper.java | 17 ++++- 9 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index ab68783e..5b0d6a5a 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -60,7 +60,7 @@ public class MineBehavior extends Behavior { } List locs = scanFor(mining, 64); if (locs.isEmpty()) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDebug("No locations for " + mining + " known, cancelling"); cancel(); return; } diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 14060fba..cd4cf357 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -77,14 +77,14 @@ public class PathingBehavior extends Behavior { if (current.failed() || current.finished()) { current = null; if (goal == null || goal.isInGoal(playerFeet())) { - displayChatMessageRaw("All done. At " + goal); + logDebug("All done. At " + goal); dispatchPathEvent(PathEvent.AT_GOAL); next = null; return; } if (next != null && !next.getPath().positions().contains(playerFeet())) { // if the current path failed, we may not actually be on the next one, so make sure - displayChatMessageRaw("Discarding next path as it does not contain current position"); + logDebug("Discarding next path as it does not contain current position"); // for example if we had a nicely planned ahead path that starts where current ends // that's all fine and good // but if we fail in the middle of current @@ -94,7 +94,7 @@ public class PathingBehavior extends Behavior { next = null; } if (next != null) { - displayChatMessageRaw("Continuing on to planned next path"); + logDebug("Continuing on to planned next path"); dispatchPathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT); current = next; next = null; @@ -118,7 +118,7 @@ public class PathingBehavior extends Behavior { if (next != null) { if (next.getPath().positions().contains(playerFeet())) { // jump directly onto the next path - displayChatMessageRaw("Splicing into planned next path early..."); + logDebug("Splicing into planned next path early..."); dispatchPathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); current = next; next = null; @@ -141,7 +141,7 @@ public class PathingBehavior extends Behavior { } if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) { // and this path has 5 seconds or less left - displayChatMessageRaw("Path almost over. Planning ahead..."); + logDebug("Path almost over. Planning ahead..."); dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED); findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath())); } @@ -248,7 +248,7 @@ public class PathingBehavior extends Behavior { } new Thread(() -> { if (talkAboutIt) { - displayChatMessageRaw("Starting to search for path from " + start + " to " + goal); + logDebug("Starting to search for path from " + start + " to " + goal); } Optional path = findPath(start, previous); @@ -280,9 +280,9 @@ public class PathingBehavior extends Behavior { if (talkAboutIt && current != null && current.getPath() != null) { if (goal == null || goal.isInGoal(current.getPath().getDest())) { - displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + logDebug("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); } else { - displayChatMessageRaw("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + logDebug("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); } } @@ -301,7 +301,7 @@ public class PathingBehavior extends Behavior { private Optional findPath(BlockPos start, Optional previous) { Goal goal = this.goal; if (goal == null) { - displayChatMessageRaw("no goal"); + logDebug("no goal"); return Optional.empty(); } if (Baritone.settings().simplifyUnloadedYCoord.get()) { @@ -320,7 +320,7 @@ public class PathingBehavior extends Behavior { } // TODO simplify each individual goal in a GoalComposite if (pos != null && world().getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); + logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); goal = new GoalXZ(pos.getX(), pos.getZ()); } } @@ -334,7 +334,7 @@ public class PathingBehavior extends Behavior { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); return pf.calculate(timeout); } catch (Exception e) { - displayChatMessageRaw("Pathing exception: " + e); + logDebug("Pathing exception: " + e); e.printStackTrace(); return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 674d5b64..16bc1997 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -77,7 +77,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { - displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); + logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); } long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.get() : timeout); //long lastPrintout = 0; @@ -102,7 +102,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { numNodes++; if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; - displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes)); } Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order @@ -191,7 +191,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); if (COEFFICIENTS[i] >= 3) { System.out.println("Warning: cost coefficient is greater than three! Probably means that"); System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)"); @@ -202,8 +202,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { return Optional.of(new Path(startNode, bestSoFar[i], numNodes)); } } - displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); - displayChatMessageRaw("No path found =("); + logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); + logDebug("No path found =("); currentlyRunning = null; return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 73a591ad..db5bbf49 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -139,7 +139,7 @@ public class MovementPillar extends Movement { if (ladder) { BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); if (against == null) { - displayChatMessageRaw("Unable to climb vines"); + logDebug("Unable to climb vines"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index da206d5e..67430d05 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -171,7 +171,7 @@ public class MovementTraverse extends Movement { boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder; BlockPos whereAmI = playerFeet(); if (whereAmI.getY() != dest.getY() && !ladder) { - displayChatMessageRaw("Wrong Y coordinate"); + logDebug("Wrong Y coordinate"); if (whereAmI.getY() < dest.getY()) { state.setInput(InputOverrideHandler.Input.JUMP, true); } @@ -203,7 +203,7 @@ public class MovementTraverse extends Movement { against1 = against1.down(); if (MovementHelper.canPlaceAgainst(against1)) { if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block - displayChatMessageRaw("bb pls get me some blocks. dirt or cobble"); + logDebug("bb pls get me some blocks. dirt or cobble"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } state.setInput(InputOverrideHandler.Input.SNEAK, true); @@ -240,7 +240,7 @@ public class MovementTraverse extends Movement { // If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of // Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI); if (!MovementHelper.throwaway(true)) {// get ready to place a throwaway block - displayChatMessageRaw("bb pls get me some blocks. dirt or cobble"); + logDebug("bb pls get me some blocks. dirt or cobble"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D; diff --git a/src/main/java/baritone/pathing/path/IPath.java b/src/main/java/baritone/pathing/path/IPath.java index 39c17993..0db487d5 100644 --- a/src/main/java/baritone/pathing/path/IPath.java +++ b/src/main/java/baritone/pathing/path/IPath.java @@ -128,12 +128,12 @@ public interface IPath extends Helper { for (int i = 0; i < positions().size(); i++) { BlockPos pos = positions().get(i); if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Cutting off path at edge of loaded chunks"); - displayChatMessageRaw("Length decreased by " + (positions().size() - i - 1)); + logDebug("Cutting off path at edge of loaded chunks"); + logDebug("Length decreased by " + (positions().size() - i - 1)); return new CutoffPath(this, i); } } - displayChatMessageRaw("Path ends within loaded chunks"); + logDebug("Path ends within loaded chunks"); return this; } @@ -146,7 +146,7 @@ public interface IPath extends Helper { } double factor = Baritone.settings().pathCutoffFactor.get(); int newLength = (int) (length() * factor); - //displayChatMessageRaw("Static cutoff " + length() + " to " + newLength); + //logDebug("Static cutoff " + length() + " to " + newLength); return new CutoffPath(this, newLength); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index c1281359..5a8af7db 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -92,7 +92,7 @@ public class PathExecutor implements Helper { if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks if (whereAmI.equals(path.positions().get(i))) { - displayChatMessageRaw("Skipping back " + (pathPosition - i) + " steps, to " + i); + logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); int previousPos = pathPosition; pathPosition = Math.max(i - 1, 0); // previous step might not actually be done for (int j = pathPosition; j <= previousPos; j++) { @@ -105,7 +105,7 @@ public class PathExecutor implements Helper { for (int i = pathPosition + 2; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) if (whereAmI.equals(path.positions().get(i))) { if (i - pathPosition > 2) { - displayChatMessageRaw("Skipping forward " + (i - pathPosition) + " steps, to " + i); + logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i); } System.out.println("Double skip sundae"); pathPosition = i - 1; @@ -121,7 +121,7 @@ public class PathExecutor implements Helper { ticksAway++; System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DIST_FROM_PATH); if (ticksAway > MAX_TICKS_AWAY) { - displayChatMessageRaw("Too far away from path for too long, cancelling path"); + logDebug("Too far away from path for too long, cancelling path"); System.out.println("Too many ticks"); pathPosition = path.length() + 3; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -134,7 +134,7 @@ public class PathExecutor implements Helper { if (distanceFromPath > MAX_MAX_DIST_FROM_PATH) { if (!(path.movements().get(pathPosition) instanceof MovementFall)) { // might be midair if (pathPosition == 0 || !(path.movements().get(pathPosition - 1) instanceof MovementFall)) { // might have overshot the landing - displayChatMessageRaw("too far from path"); + logDebug("too far from path"); pathPosition = path.length() + 3; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); failed = true; @@ -211,7 +211,7 @@ public class PathExecutor implements Helper { } long end = System.nanoTime() / 1000000L; if (end - start > 0) { - //displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms"); + //logDebug("Recalculating break and place took " + (end - start) + "ms"); } Movement movement = path.movements().get(pathPosition); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { @@ -220,7 +220,7 @@ public class PathExecutor implements Helper { currentMovementInitialCostEstimate = movement.getCost(null); for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); + logDebug("Something has changed in the world and a future movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -230,7 +230,7 @@ public class PathExecutor implements Helper { } double currentCost = movement.recalculateCost(); if (currentCost >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling."); + logDebug("Something has changed in the world and this movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -238,7 +238,7 @@ public class PathExecutor implements Helper { } MovementState.MovementStatus movementStatus = movement.update(); if (movementStatus == UNREACHABLE || movementStatus == FAILED) { - displayChatMessageRaw("Movement returns status " + movementStatus); + logDebug("Movement returns status " + movementStatus); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -259,7 +259,7 @@ public class PathExecutor implements Helper { // as you break the blocks required, the remaining cost goes down, to the point where // ticksOnCurrent is greater than recalculateCost + 100 // this is why we cache cost at the beginning, and don't recalculate for this comparison every tick - displayChatMessageRaw("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling."); + logDebug("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling."); movement.cancel(); Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); pathPosition = path.length() + 3; @@ -318,7 +318,7 @@ public class PathExecutor implements Helper { } return; } - //displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); + //logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); } player().setSprinting(false); } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index b12db109..6a301a6c 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -92,26 +92,26 @@ public class ExampleBaritoneControl extends Behavior { goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2]))); break; default: - displayChatMessageRaw("unable to understand lol"); + logDirect("unable to understand lol"); return; } } catch (NumberFormatException ex) { - displayChatMessageRaw("unable to parse integer " + ex); + logDirect("unable to parse integer " + ex); return; } PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Goal: " + goal); + logDirect("Goal: " + goal); return; } if (msg.equals("path")) { if (!PathingBehavior.INSTANCE.path()) { if (PathingBehavior.INSTANCE.getGoal() == null) { - displayChatMessageRaw("No goal."); + logDirect("No goal."); } else { if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) { - displayChatMessageRaw("Already in goal"); + logDirect("Already in goal"); } else { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } } } @@ -123,13 +123,13 @@ public class ExampleBaritoneControl extends Behavior { FollowBehavior.INSTANCE.cancel(); MineBehavior.INSTANCE.cancel(); event.cancel(); - displayChatMessageRaw("ok canceled"); + logDirect("ok canceled"); return; } if (msg.toLowerCase().equals("forcecancel")) { AbstractNodeCostSearch.forceCancel(); event.cancel(); - displayChatMessageRaw("ok force canceled"); + logDirect("ok force canceled"); return; } if (msg.toLowerCase().equals("invert")) { @@ -140,8 +140,8 @@ public class ExampleBaritoneControl extends Behavior { } else if (goal instanceof GoalBlock) { runAwayFrom = ((GoalBlock) goal).getGoalPos(); } else { - displayChatMessageRaw("Goal must be GoalXZ or GoalBlock to invert"); - displayChatMessageRaw("Inverting goal of player feet"); + logDirect("Goal must be GoalXZ or GoalBlock to invert"); + logDirect("Inverting goal of player feet"); runAwayFrom = playerFeet(); } PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) { @@ -151,7 +151,7 @@ public class ExampleBaritoneControl extends Behavior { } }); if (!PathingBehavior.INSTANCE.path()) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } event.cancel(); return; @@ -159,31 +159,31 @@ public class ExampleBaritoneControl extends Behavior { if (msg.toLowerCase().equals("follow")) { Optional entity = MovementHelper.whatEntityAmILookingAt(); if (!entity.isPresent()) { - displayChatMessageRaw("You aren't looking at an entity bruh"); + logDirect("You aren't looking at an entity bruh"); event.cancel(); return; } FollowBehavior.INSTANCE.follow(entity.get()); - displayChatMessageRaw("Following " + entity.get()); + logDirect("Following " + entity.get()); event.cancel(); return; } if (msg.toLowerCase().equals("reloadall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk(); - displayChatMessageRaw("ok"); + logDirect("ok"); event.cancel(); return; } if (msg.toLowerCase().equals("saveall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.save(); - displayChatMessageRaw("ok"); + logDirect("ok"); event.cancel(); return; } if (msg.toLowerCase().startsWith("find")) { String blockType = msg.toLowerCase().substring(4).trim(); LinkedList locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4); - displayChatMessageRaw("Have " + locs.size() + " locations"); + logDirect("Have " + locs.size() + " locations"); for (BlockPos pos : locs) { Block actually = BlockStateInterface.get(pos).getBlock(); if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) { @@ -197,20 +197,20 @@ public class ExampleBaritoneControl extends Behavior { String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" "); for (String s : blockTypes) { if (ChunkPacker.stringToBlock(s) == null) { - displayChatMessageRaw(s + " isn't a valid block name"); + logDirect(s + " isn't a valid block name"); event.cancel(); return; } } MineBehavior.INSTANCE.mine(blockTypes); - displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes)); + logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); event.cancel(); return; } if (msg.toLowerCase().startsWith("thisway")) { Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Goal: " + goal); + logDirect("Goal: " + goal); event.cancel(); return; } @@ -222,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior { } Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { - displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); + logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); return; } @@ -230,9 +230,9 @@ public class ExampleBaritoneControl extends Behavior { // might as well show them from oldest to newest List sorted = new ArrayList<>(waypoints); sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp)); - displayChatMessageRaw("Waypoints under tag " + tag + ":"); + logDirect("Waypoints under tag " + tag + ":"); for (Waypoint waypoint : sorted) { - displayChatMessageRaw(waypoint.toString()); + logDirect(waypoint.toString()); } event.cancel(); return; @@ -246,15 +246,15 @@ public class ExampleBaritoneControl extends Behavior { Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { String mining = waypointType; - //displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); + //logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); if (ChunkPacker.stringToBlock(mining) == null) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDirect("No locations for " + mining + " known, cancelling"); return; } List locs = MineBehavior.scanFor(Arrays.asList(mining), 64); if (locs.isEmpty()) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDirect("No locations for " + mining + " known, cancelling"); return; } PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new))); @@ -263,7 +263,7 @@ public class ExampleBaritoneControl extends Behavior { } Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag); if (waypoint == null) { - displayChatMessageRaw("None saved for tag " + tag); + logDirect("None saved for tag " + tag); event.cancel(); return; } @@ -271,7 +271,7 @@ public class ExampleBaritoneControl extends Behavior { PathingBehavior.INSTANCE.setGoal(goal); if (!PathingBehavior.INSTANCE.path()) { if (!goal.isInGoal(playerFeet())) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } } event.cancel(); @@ -283,30 +283,30 @@ public class ExampleBaritoneControl extends Behavior { BlockPos spawnPoint = player().getBedLocation(); // for some reason the default spawnpoint is underground sometimes Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ()); - displayChatMessageRaw("spawn not saved, defaulting to world spawn. set goal to " + goal); + logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal); PathingBehavior.INSTANCE.setGoal(goal); } else { Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Set goal to most recent bed " + goal); + logDirect("Set goal to most recent bed " + goal); } event.cancel(); return; } if (msg.toLowerCase().equals("sethome")) { WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet())); - displayChatMessageRaw("Saved. Say home to set goal."); + logDirect("Saved. Say home to set goal."); event.cancel(); return; } if (msg.toLowerCase().equals("home")) { Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME); if (waypoint == null) { - displayChatMessageRaw("home not saved"); + logDirect("home not saved"); } else { Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Set goal to saved home " + goal); + logDirect("Set goal to saved home " + goal); } event.cancel(); return; @@ -325,7 +325,7 @@ public class ExampleBaritoneControl extends Behavior { if (cost >= ActionCosts.COST_INF) { strCost = "IMPOSSIBLE"; } - displayChatMessageRaw(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); + logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); } event.cancel(); return; @@ -335,13 +335,13 @@ public class ExampleBaritoneControl extends Behavior { if (msg.equalsIgnoreCase(setting.getName())) { setting.value ^= true; event.cancel(); - displayChatMessageRaw("Toggled " + setting.getName() + " to " + setting.value); + logDirect("Toggled " + setting.getName() + " to " + setting.value); return; } } if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) { for (Settings.Setting setting : Baritone.settings().allSettings) { - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); } event.cancel(); return; @@ -362,11 +362,11 @@ public class ExampleBaritoneControl extends Behavior { setting.value = Double.parseDouble(data[1]); } } catch (NumberFormatException e) { - displayChatMessageRaw("Unable to parse " + data[1]); + logDirect("Unable to parse " + data[1]); event.cancel(); return; } - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); event.cancel(); return; } @@ -374,7 +374,7 @@ public class ExampleBaritoneControl extends Behavior { } if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) { Settings.Setting setting = Baritone.settings().byLowerName.get(msg.toLowerCase()); - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); event.cancel(); return; } diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 30e1f398..9bcf082d 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -73,15 +73,24 @@ public interface Helper { return new Rotation(player().rotationYaw, player().rotationPitch); } - default void displayChatMessageRaw(String message) { + /** + * Send a message to chat only if chatDebug is on + * @param message + */ + default void logDebug(String message) { if (!Baritone.settings().chatDebug.get()) { System.out.println("Suppressed debug message:"); System.out.println(message); - /*if (!Stream.of(Thread.currentThread().getStackTrace()).map(StackTraceElement::getClassName).anyMatch(x -> x.equals(ExampleBaritoneControl.class.getName()))) { - return; - }*/ + return; } + logDirect(message); + } + /** + * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) + * @param message + */ + default void logDirect(String message) { ITextComponent component = MESSAGE_PREFIX.createCopy(); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(new TextComponentString(" " + message));