From 50fd63647b4f0481e362ed45780cb6cfd797aee5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:12:57 -0700 Subject: [PATCH 001/165] sprint through descend, fixes #29 and #38 --- src/main/java/baritone/Settings.java | 7 +++ .../baritone/pathing/movement/Movement.java | 5 +- .../pathing/movement/MovementHelper.java | 2 +- .../movement/movements/MovementDiagonal.java | 6 +- .../movement/movements/MovementTraverse.java | 5 +- .../baritone/pathing/path/PathExecutor.java | 57 +++++++++++++++++++ 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index e596df14..a23401dc 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -147,6 +147,13 @@ public class Settings { */ public Setting maxFallHeightBucket = new Setting<>(20); + /** + * Is it okay to sprint through a descend followed by a diagonal? + * The player overshoots the landing, but not enough to fall off. And the diagonal ensures that there isn't + * lava or anything that's !canWalkInto in that space, so it's technically safe, just a little sketchy. + */ + public Setting allowOvershootDiagonalDescend = new Setting<>(true); + /** * If your goal is a GoalBlock in an unloaded chunk, assume it's far enough away that the Y coord * doesn't matter yet, and replace it with a GoalXZ to the same place before calculating a path. diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 27cbb08e..5a3f26f5 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -104,7 +104,6 @@ public abstract class Movement implements Helper, MovementHelper { * @return Status */ public MovementStatus update() { - player().setSprinting(false); MovementState latestState = updateState(currentState); if (BlockStateInterface.isLiquid(playerFeet())) { latestState.setInput(Input.JUMP, true); @@ -269,6 +268,10 @@ public abstract class Movement implements Helper, MovementHelper { return state; } + public BlockPos getDirection() { + return getDest().subtract(getSrc()); + } + public List toBreakCached = null; public List toPlaceCached = null; public List toWalkIntoCached = null; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 34c65ae6..fd033b78 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -158,7 +158,7 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } - return (facing == playerFacing) == open; + return facing == playerFacing == open; } static boolean avoidWalkingInto(Block block) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 7bde41c7..cd29bdbf 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -17,12 +17,12 @@ 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.BlockMagma; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -65,8 +65,8 @@ public class MovementDiagonal extends Movement { state.setStatus(MovementState.MovementStatus.SUCCESS); return state; } - if (!BlockStateInterface.isLiquid(playerFeet()) && Baritone.settings().allowSprint.get()) { - player().setSprinting(true); + if (!BlockStateInterface.isLiquid(playerFeet())) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); } MovementHelper.moveTowards(state, dest); return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index e92fc527..20b284e6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -17,7 +17,6 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -190,8 +189,8 @@ public class MovementTraverse extends Movement { state.setStatus(MovementState.MovementStatus.SUCCESS); return state; } - if (wasTheBridgeBlockAlwaysThere && !BlockStateInterface.isLiquid(playerFeet()) && Baritone.settings().allowSprint.get()) { - player().setSprinting(true); + if (wasTheBridgeBlockAlwaysThere && !BlockStateInterface.isLiquid(playerFeet())) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); } Block destDown = BlockStateInterface.get(dest.down()).getBlock(); if (ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 88a7126c..210544c4 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -22,6 +22,9 @@ import baritone.event.events.TickEvent; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementState; +import baritone.pathing.movement.movements.MovementDescend; +import baritone.pathing.movement.movements.MovementDiagonal; +import baritone.pathing.movement.movements.MovementTraverse; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; @@ -228,6 +231,7 @@ public class PathExecutor implements Helper { onTick(event); return true; } else { + sprintIfRequested(); ticksOnCurrent++; if (ticksOnCurrent > currentMovementInitialCostEstimate + Baritone.settings().movementTimeoutTicks.get()) { // only fail if the total time has exceeded the initial estimate @@ -245,6 +249,59 @@ public class PathExecutor implements Helper { return false; // movement is in progress } + private void sprintIfRequested() { + if (!Baritone.settings().allowSprint.get()) { + player().setSprinting(false); + return; + } + if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown(mc.gameSettings.keyBindSprint)) { + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + Movement movement = path.movements().get(pathPosition); + if (movement instanceof MovementDescend && pathPosition < path.length() - 2) { + Movement next = path.movements().get(pathPosition + 1); + if (next instanceof MovementDescend) { + if (next.getDirection().equals(movement.getDirection())) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + } + if (next instanceof MovementTraverse) { + if (next.getDirection().down().equals(movement.getDirection())) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + } + if (next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get()) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); + } + player().setSprinting(false); + } + public int getPosition() { return pathPosition; } From 6dd501a46bbba8710bd8bea524f6c2bf13987996 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:19:14 -0700 Subject: [PATCH 002/165] add cost verification lookahead --- src/main/java/baritone/Settings.java | 7 +++++++ src/main/java/baritone/pathing/path/PathExecutor.java | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index a23401dc..9b918416 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -119,6 +119,13 @@ public class Settings { */ public Setting cutoffAtLoadBoundary = new Setting<>(true); + /** + * Stop 5 movements before anything that made the path COST_INF. + * For example, if lava has spread across the path, don't walk right up to it then recalculate, it might + * still be spreading lol + */ + public Setting costVerificationLookahead = new Setting<>(5); + /** * Static cutoff factor. 0.9 means cut off the last 10% of all paths, regardless of chunk load state */ diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 210544c4..75bebc8a 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -211,6 +211,15 @@ public class PathExecutor implements Helper { Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); return true; } + for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { + if (path.movements().get(pathPosition + 1).recalculateCost() >= ActionCosts.COST_INF) { + displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); + pathPosition = path.length() + 3; + failed = true; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + return true; + } + } if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; currentMovementInitialCostEstimate = currentCost; // do this only once, when the movement starts From e8c644fc6321d9a20c61999aba65f087823c8537 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:22:34 -0700 Subject: [PATCH 003/165] haha --- 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 75bebc8a..1dbaf4fb 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -212,7 +212,7 @@ public class PathExecutor implements Helper { return true; } for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { - if (path.movements().get(pathPosition + 1).recalculateCost() >= ActionCosts.COST_INF) { + if (path.movements().get(pathPosition + i).recalculateCost() >= ActionCosts.COST_INF) { displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true; From 5f6a5ea4030386286d83b2b95532b1b73bfb3d32 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:31:03 -0700 Subject: [PATCH 004/165] extend MovementFall breakability one more, fixes #97 --- .../pathing/movement/MovementHelper.java | 18 +++++++++--------- .../movement/movements/MovementFall.java | 13 ++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index fd033b78..93bd34fb 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -304,22 +304,22 @@ public interface MovementHelper extends ActionCosts, Helper { static Movement generateMovementFallOrDescend(BlockPos pos, BlockPos dest, CalculationContext calcContext) { // A //SA - // B + // A // B // C // D - //if S is where you start, both of B need to be air for a movementfall + //if S is where you start, B needs to be air for a movementfall //A is plausibly breakable by either descend or fall //C, D, etc determine the length of the fall - for (int i = 1; i < 3; i++) { - if (!canWalkThrough(dest.down(i))) { - //if any of these two (B in the diagram) aren't air - //have to do a descend, because fall is impossible - //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 - } + if (!canWalkThrough(dest.down(2))) { + //if B in the diagram aren't air + //have to do a descend, because fall is impossible + + //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're clear for a fall 2 // let's see how far we can fall for (int fallHeight = 3; true; fallHeight++) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 5c40c706..04e42938 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -56,14 +56,17 @@ public class MovementFall extends Movement { } placeBucketCost = context.placeBlockCost(); } - double frontTwo = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1]); - if (frontTwo >= COST_INF) { - return COST_INF; + double frontThree = 0; + for (int i = 0; i < 3; i++) { + frontThree += MovementHelper.getMiningDurationTicks(context, positionsToBreak[i]); + if (frontThree >= COST_INF) { + return COST_INF; + } } if (BlockStateInterface.get(positionsToBreak[0].up()).getBlock() instanceof BlockFalling) { return COST_INF; } - for (int i = 2; i < positionsToBreak.length; i++) { + for (int i = 3; i < positionsToBreak.length; i++) { // TODO is this the right check here? // MiningDurationTicks is all right, but shouldn't it be canWalkThrough instead? // Lilypads (i think?) are 0 ticks to mine, but they definitely cause fall damage @@ -74,7 +77,7 @@ public class MovementFall extends Movement { return COST_INF; } } - return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + placeBucketCost + frontTwo; + return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + placeBucketCost + frontThree; } @Override From f95e35de0a17b91ee58c11bd24e75d6939833bc9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:45:02 -0700 Subject: [PATCH 005/165] rudimentary setup readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea844c28..5d5d9c47 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # Baritone A Minecraft bot. This project is an updated version of [Minebot](https://github.com/leijurv/MineBot/), -the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. \ No newline at end of file +the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. + +# Setup +- Open the project in IntelliJ as a Gradle project +- Run the Gradle task `setupDecompWorkspace` +- Run the Gradle task `genIntellijRuns` +- Restart IntelliJ and import Gradle changes +- Select the "Minecraft Client" launch config and run \ No newline at end of file From 9a24e6a1a3ecdba0cd20d9818800b00e7cffefd4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:49:56 -0700 Subject: [PATCH 006/165] fixed overzealous cost check --- .../baritone/pathing/path/PathExecutor.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 1dbaf4fb..504e9ecb 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -211,18 +211,18 @@ public class PathExecutor implements Helper { Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); return true; } - for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { - if (path.movements().get(pathPosition + i).recalculateCost() >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); - pathPosition = path.length() + 3; - failed = true; - Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); - return true; - } - } if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; currentMovementInitialCostEstimate = currentCost; // do this only once, when the movement starts + for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { + if (path.movements().get(pathPosition + i).recalculateCost() >= ActionCosts.COST_INF) { + displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); + pathPosition = path.length() + 3; + failed = true; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + return true; + } + } } MovementState.MovementStatus movementStatus = movement.update(); if (movementStatus == UNREACHABLE || movementStatus == FAILED) { From 45631fa12add1479203534acb168e6044020cf72 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:50:30 -0700 Subject: [PATCH 007/165] brady pls --- src/main/java/baritone/chunk/CachedRegion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 923edc16..d8484ecd 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -231,7 +231,7 @@ public final class CachedRegion implements IBlockTypeAccess { if (tmpCached[x][z] != null) { // 16 * 16 * 256 = 65536 so a short is enough // ^ haha jokes on leijurv, java doesn't have unsigned types so that isn't correct - // also ur gay if u have more than 32767 special blocks in a chunk + // also why would you have more than 32767 special blocks in a chunk short numSpecialBlockTypes = in.readShort(); for (int i = 0; i < numSpecialBlockTypes; i++) { String blockName = in.readUTF(); From 6408e678ff44daa4a3548f6cd6e130f937a626c9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:51:56 -0700 Subject: [PATCH 008/165] fix short int conversion --- src/main/java/baritone/chunk/CachedRegion.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index d8484ecd..e6aa4198 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -232,12 +232,19 @@ public final class CachedRegion implements IBlockTypeAccess { // 16 * 16 * 256 = 65536 so a short is enough // ^ haha jokes on leijurv, java doesn't have unsigned types so that isn't correct // also why would you have more than 32767 special blocks in a chunk - short numSpecialBlockTypes = in.readShort(); + // haha double jokes on you now it works for 65535 not just 32767 + int numSpecialBlockTypes = in.readShort(); + if (numSpecialBlockTypes < 0) { + numSpecialBlockTypes += 65536; + } for (int i = 0; i < numSpecialBlockTypes; i++) { String blockName = in.readUTF(); List locs = new ArrayList<>(); location[x][z].put(blockName, locs); - short numLocations = in.readShort(); + int numLocations = in.readShort(); + if (numLocations < 0) { + numLocations += 65536; + } for (int j = 0; j < numLocations; j++) { byte xz = in.readByte(); int X = xz & 0x0f; From 68c2537d20589044c3c62f9c6e6091c24ad27226 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 26 Aug 2018 12:09:23 -0500 Subject: [PATCH 009/165] Leijurv doesn't know how unsigned works in java --- src/main/java/baritone/chunk/CachedRegion.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index e6aa4198..d4a25834 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -233,18 +233,12 @@ public final class CachedRegion implements IBlockTypeAccess { // ^ haha jokes on leijurv, java doesn't have unsigned types so that isn't correct // also why would you have more than 32767 special blocks in a chunk // haha double jokes on you now it works for 65535 not just 32767 - int numSpecialBlockTypes = in.readShort(); - if (numSpecialBlockTypes < 0) { - numSpecialBlockTypes += 65536; - } + int numSpecialBlockTypes = in.readShort() & 0xffff; for (int i = 0; i < numSpecialBlockTypes; i++) { String blockName = in.readUTF(); List locs = new ArrayList<>(); location[x][z].put(blockName, locs); - int numLocations = in.readShort(); - if (numLocations < 0) { - numLocations += 65536; - } + int numLocations = in.readShort() & 0xffff; for (int j = 0; j < numLocations; j++) { byte xz = in.readByte(); int X = xz & 0x0f; From f052c91cda5f5c4bbfcf38eaed085df92750d29b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 12:54:01 -0700 Subject: [PATCH 010/165] map 0 to 65536 --- src/main/java/baritone/chunk/CachedRegion.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index d4a25834..0fbe8b4e 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -239,6 +239,10 @@ public final class CachedRegion implements IBlockTypeAccess { List locs = new ArrayList<>(); location[x][z].put(blockName, locs); int numLocations = in.readShort() & 0xffff; + if (numLocations == 0) { + // an entire chunk full of air can happen in the end + numLocations = 65536; + } for (int j = 0; j < numLocations; j++) { byte xz = in.readByte(); int X = xz & 0x0f; From 74916dd24ed1c7a755f220db9c92ce9047681afb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 13:09:20 -0700 Subject: [PATCH 011/165] consistency between byte and short read methods --- src/main/java/baritone/chunk/CachedRegion.java | 5 +---- src/test/java/baritone/chunk/CachedRegionTest.java | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 0fbe8b4e..7d2ed3dc 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -247,10 +247,7 @@ public final class CachedRegion implements IBlockTypeAccess { byte xz = in.readByte(); int X = xz & 0x0f; int Z = (xz >>> 4) & 0x0f; - int Y = (int) in.readByte(); - if (Y < 0) { - Y += 256; - } + int Y = in.readByte() & 0xff; locs.add(new BlockPos(X, Y, Z)); } } diff --git a/src/test/java/baritone/chunk/CachedRegionTest.java b/src/test/java/baritone/chunk/CachedRegionTest.java index 0992cee1..8350390c 100644 --- a/src/test/java/baritone/chunk/CachedRegionTest.java +++ b/src/test/java/baritone/chunk/CachedRegionTest.java @@ -33,10 +33,7 @@ public class CachedRegionTest { byte xz = part1; int X = xz & 0x0f; int Z = (xz >>> 4) & 0x0f; - int Y = (int) part2; - if (Y < 0) { - Y += 256; - } + int Y = part2 & 0xff; if (x != X || y != Y || z != Z) { System.out.println(x + " " + X + " " + y + " " + Y + " " + z + " " + Z); } From 5abadc6fe50884afdc8da3a2d0be5cbf8307214f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 13:48:08 -0700 Subject: [PATCH 012/165] address cost calculation of blockfalling stacks --- .../baritone/pathing/movement/Movement.java | 69 +++++++++++-------- .../pathing/movement/MovementHelper.java | 18 +++-- .../movement/movements/MovementDiagonal.java | 4 +- .../movement/movements/MovementDownward.java | 3 +- .../movement/movements/MovementFall.java | 5 +- 5 files changed, 62 insertions(+), 37 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 5a3f26f5..11a88ad1 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -33,6 +33,7 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -214,39 +215,53 @@ public abstract class Movement implements Helper, MovementHelper { } public double getTotalHardnessOfBlocksToBreak(CalculationContext ctx) { - /* - double sum = 0; - HashSet toBreak = new HashSet(); - for (BlockPos positionsToBreak1 : positionsToBreak) { - toBreak.add(positionsToBreak1); - if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us - continue; - } - BlockPos tmp = positionsToBreak1.up(); - while (canFall(tmp)) { - toBreak.add(tmp); - tmp = tmp.up(); - } + if (positionsToBreak.length == 0) { + return 0; } - for (BlockPos pos : toBreak) { - sum += getHardness(ts, Baritone.get(pos), pos); - if (sum >= COST_INF) { - return COST_INF; - } + if (positionsToBreak.length == 1) { + return MovementHelper.getMiningDurationTicks(ctx, positionsToBreak[0], true); } - if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) { - for (int i = 0; i < blocksToPlace.length; i++) { - if (!canWalkOn(positionsToPlace[i])) { - return COST_INF; + int firstColumnX = positionsToBreak[0].getX(); + int firstColumnZ = positionsToBreak[0].getZ(); + int firstColumnMaxY = positionsToBreak[0].getY(); + int firstColumnMaximalIndex = 0; + boolean hasSecondColumn = false; + int secondColumnX = -1; + int secondColumnZ = -1; + int secondColumnMaxY = -1; + int secondColumnMaximalIndex = -1; + for (int i = 0; i < positionsToBreak.length; i++) { + BlockPos pos = positionsToBreak[i]; + if (pos.getX() == firstColumnX && pos.getZ() == firstColumnZ) { + if (pos.getY() > firstColumnMaxY) { + firstColumnMaxY = pos.getY(); + firstColumnMaximalIndex = i; + } + } else { + if (!hasSecondColumn || (pos.getX() == secondColumnX && pos.getZ() == secondColumnZ)) { + if (hasSecondColumn) { + if (pos.getY() > secondColumnMaxY) { + secondColumnMaxY = pos.getY(); + secondColumnMaximalIndex = i; + } + } else { + hasSecondColumn = true; + secondColumnX = pos.getX(); + secondColumnZ = pos.getZ(); + secondColumnMaxY = pos.getY(); + secondColumnMaximalIndex = i; + } + } else { + throw new IllegalStateException("I literally have no idea " + Arrays.asList(positionsToBreak)); } } - }*/ - //^ the above implementation properly deals with falling blocks, TODO integrate + } + double sum = 0; - for (BlockPos pos : positionsToBreak) { - sum += MovementHelper.getMiningDurationTicks(ctx, pos); + for (int i = 0; i < positionsToBreak.length; i++) { + sum += MovementHelper.getMiningDurationTicks(ctx, positionsToBreak[i], firstColumnMaximalIndex == i || secondColumnMaximalIndex == i); if (sum >= COST_INF) { - return COST_INF; + break; } } return sum; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 93bd34fb..549ee621 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -208,12 +208,12 @@ public interface MovementHelper extends ActionCosts, Helper { return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; } - static double getMiningDurationTicks(CalculationContext context, BlockPos position) { + static double getMiningDurationTicks(CalculationContext context, BlockPos position, boolean includeFalling) { IBlockState state = BlockStateInterface.get(position); - return getMiningDurationTicks(context, position, state); + return getMiningDurationTicks(context, position, state, includeFalling); } - static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state) { + 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 (!context.allowBreak()) { @@ -223,9 +223,17 @@ public interface MovementHelper extends ActionCosts, Helper { return COST_INF; } 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 - return m / context.getToolSet().getStrVsBlock(state, position); + double result = m / context.getToolSet().getStrVsBlock(state, position); + if (includeFalling) { + BlockPos up = position.up(); + IBlockState above = BlockStateInterface.get(up); + if (above.getBlock() instanceof BlockFalling) { + result += getMiningDurationTicks(context, up, above, true); + } + } + return result; } - return 0; + return 0; // we won't actually mine it, so don't check fallings above } /** diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index cd29bdbf..20defe13 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -97,8 +97,8 @@ public class MovementDiagonal extends Movement { if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) { return COST_INF; } - double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1]); - double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3]); + double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1], true); + double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3], true); if (optionA != 0 && optionB != 0) { return COST_INF; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 724b8688..38232396 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -53,7 +53,8 @@ public class MovementDownward extends Movement { if (ladder) { return LADDER_DOWN_ONE_COST; } else { - return FALL_N_BLOCKS_COST[1] + MovementHelper.getMiningDurationTicks(context, dest, d); + // we're standing on it, while it might be block falling, it'll be air by the time we get here in the movement + return FALL_N_BLOCKS_COST[1] + MovementHelper.getMiningDurationTicks(context, dest, d, false); } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 04e42938..c42a8661 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -58,7 +58,8 @@ public class MovementFall extends Movement { } double frontThree = 0; for (int i = 0; i < 3; i++) { - frontThree += MovementHelper.getMiningDurationTicks(context, positionsToBreak[i]); + frontThree += MovementHelper.getMiningDurationTicks(context, positionsToBreak[i], false); + // don't include falling because we will check falling right after this, and if it's there it's COST_INF if (frontThree >= COST_INF) { return COST_INF; } @@ -72,7 +73,7 @@ public class MovementFall extends Movement { // Lilypads (i think?) are 0 ticks to mine, but they definitely cause fall damage // Same thing for falling through water... we can't actually do that // And falling through signs is possible, but they do have a mining duration, right? - if (MovementHelper.getMiningDurationTicks(context, positionsToBreak[i]) > 0) { + if (MovementHelper.getMiningDurationTicks(context, positionsToBreak[i], false) > 0) { //can't break while falling return COST_INF; } From 3bb1c1a972a50232956c05a4d6498d1500a3f929 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 13:51:50 -0700 Subject: [PATCH 013/165] unneeded --- 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 504e9ecb..0e7ebec6 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -306,7 +306,7 @@ public class PathExecutor implements Helper { } return; } - displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); + //displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); } player().setSprinting(false); } From 3bf4b997b096467044048d2184e253968d9c07b5 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 13:39:36 -0500 Subject: [PATCH 014/165] Rename getByValueType to getAllValuesByType --- src/main/java/baritone/Settings.java | 2 +- src/main/java/baritone/utils/ExampleBaritoneControl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 9b918416..6a30099c 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -323,7 +323,7 @@ public class Settings { } @SuppressWarnings("unchecked") - public List> getByValueType(Class klass) { + public List> getAllValuesByType(Class klass) { List> result = new ArrayList<>(); for (Setting setting : allSettings) { if (setting.klass.equals(klass)) { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index e7c637d7..59cafd6b 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -286,7 +286,7 @@ public class ExampleBaritoneControl extends Behavior { event.cancel(); return; } - List> toggleable = Baritone.settings().getByValueType(Boolean.class); + List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { if (msg.equalsIgnoreCase(setting.getName())) { setting.value ^= true; From 92e0b842be0523ba669700fb4445b923e5846621 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 13:51:22 -0500 Subject: [PATCH 015/165] Double frown? Let's be more positive! --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 2c1df800..dc31e1c4 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -190,7 +190,7 @@ 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 " + bestDist + " blocks =("); + displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + bestDist + " blocks"); displayChatMessageRaw("No path found =("); currentlyRunning = null; return Optional.empty(); From 71e04ad1045ba1ffb91ee9d1a7ab8ca49ae6f808 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 13:53:17 -0500 Subject: [PATCH 016/165] Change the instructions in the README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d5d9c47..2a26afb0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. # Setup - Open the project in IntelliJ as a Gradle project - Run the Gradle task `setupDecompWorkspace` +- Refresh the Gradle project - Run the Gradle task `genIntellijRuns` -- Restart IntelliJ and import Gradle changes -- Select the "Minecraft Client" launch config and run \ No newline at end of file +- Select the "Minecraft Client" launch config and run From 3da6b160db09a876ef46de94840819c9c1f5de20 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 13:59:36 -0500 Subject: [PATCH 017/165] Include setup commands in the README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 2a26afb0..ddc779f5 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,10 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. - Refresh the Gradle project - Run the Gradle task `genIntellijRuns` - Select the "Minecraft Client" launch config and run + +## Command Line +``` +$ gradlew setupDecompWorkspace +$ gradlew --refresh-dependencies +$ gradlew genIntellijRuns +``` From aca6503ac6f491026e39b46cbb7ae7806c775c27 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 27 Aug 2018 12:02:51 -0700 Subject: [PATCH 018/165] readme --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d5d9c47..d2750b35 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,19 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. - Run the Gradle task `setupDecompWorkspace` - Run the Gradle task `genIntellijRuns` - Restart IntelliJ and import Gradle changes -- Select the "Minecraft Client" launch config and run \ No newline at end of file +- Select the "Minecraft Client" launch config and run + +# Chat control +Defined here + +Quick start example: `thisway 1000` or `goal 70` to set the goal, `path` to actually start pathing. Also try `mine diamond_ore`. `cancel` to cancel. + +# API example + +``` +Baritone.settings().allowSprint.value = true; +Baritone.settings().pathTimeoutMS.value = 2000L; + +PathingBehavior.INSTANCE.setGoal(new GoalXZ(10000, 20000)); +PathingBehavior.INSTANCE.path(); +``` \ No newline at end of file From 9762fe73cf0c03fa4e7e6f1ab64f2f86ef8df393 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 27 Aug 2018 12:12:52 -0700 Subject: [PATCH 019/165] fix --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 676c0d7b..5260cdc1 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,8 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. # Setup - Open the project in IntelliJ as a Gradle project - Run the Gradle task `setupDecompWorkspace` -- Refresh the Gradle project - Run the Gradle task `genIntellijRuns` -- Restart IntelliJ and import Gradle changes +- Refresh the Gradle project (or just restart IntelliJ) - Select the "Minecraft Client" launch config and run ## Command Line From 8f8bedb1b05033579cd93d2ac783f58bca917e51 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 14:35:30 -0500 Subject: [PATCH 020/165] If we're going to have a getter we might as well use it --- src/main/java/baritone/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 6a30099c..099493e2 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -326,7 +326,7 @@ public class Settings { public List> getAllValuesByType(Class klass) { List> result = new ArrayList<>(); for (Setting setting : allSettings) { - if (setting.klass.equals(klass)) { + if (setting.getValueClass().equals(klass)) { result.add((Setting) setting); } } From 423087cc12629f37ce57d248584567097a60b4bd Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 17:45:31 -0500 Subject: [PATCH 021/165] Add a way to hook into Baritone's post-init stage --- src/main/java/baritone/Baritone.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 5642323b..333a9fdb 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -54,11 +54,20 @@ public enum Baritone { private List behaviors; private File dir; + /** + * List of runnables to be called after Baritone has initialized + */ + private List onInitRunnables; + /** * Whether or not Baritone is active */ private boolean active; + Baritone() { + this.onInitRunnables = new ArrayList<>(); + } + public synchronized void init() { if (initialized) { return; @@ -82,6 +91,8 @@ public enum Baritone { this.active = true; this.initialized = true; + + this.onInitRunnables.forEach(Runnable::run); } public final boolean isInitialized() { @@ -120,4 +131,8 @@ public enum Baritone { public final File getDir() { return this.dir; } + + public final void registerInitListener(Runnable runnable) { + this.onInitRunnables.add(runnable); + } } From 43b7aece742180ed268303dd1b4978f7218cfb96 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 19:37:21 -0500 Subject: [PATCH 022/165] Move events to api package --- src/main/java/baritone/Baritone.java | 2 +- .../java/baritone/{ => api}/event/GameEventHandler.java | 8 ++++---- .../{ => api}/event/events/BlockInteractEvent.java | 2 +- .../java/baritone/{ => api}/event/events/ChatEvent.java | 4 ++-- .../java/baritone/{ => api}/event/events/ChunkEvent.java | 4 ++-- .../baritone/{ => api}/event/events/ItemSlotEvent.java | 4 ++-- .../java/baritone/{ => api}/event/events/PacketEvent.java | 4 ++-- .../java/baritone/{ => api}/event/events/PathEvent.java | 2 +- .../{ => api}/event/events/PlayerUpdateEvent.java | 4 ++-- .../{ => api}/event/events/RelativeMoveEvent.java | 4 ++-- .../java/baritone/{ => api}/event/events/RenderEvent.java | 2 +- .../java/baritone/{ => api}/event/events/TickEvent.java | 4 ++-- .../java/baritone/{ => api}/event/events/WorldEvent.java | 4 ++-- .../baritone/{ => api}/event/events/type/Cancellable.java | 2 +- .../baritone/{ => api}/event/events/type/EventState.java | 2 +- .../event/listener/AbstractGameEventListener.java | 4 ++-- .../{ => api}/event/listener/IGameEventListener.java | 4 ++-- src/main/java/baritone/behavior/Behavior.java | 2 +- .../baritone/behavior/impl/LocationTrackingBehavior.java | 2 +- src/main/java/baritone/behavior/impl/LookBehavior.java | 5 ++--- src/main/java/baritone/behavior/impl/MemoryBehavior.java | 6 +++--- src/main/java/baritone/behavior/impl/PathingBehavior.java | 8 ++++---- src/main/java/baritone/launch/mixins/MixinEntity.java | 4 ++-- .../java/baritone/launch/mixins/MixinEntityPlayerSP.java | 6 +++--- .../java/baritone/launch/mixins/MixinEntityRenderer.java | 2 +- .../java/baritone/launch/mixins/MixinInventoryPlayer.java | 2 +- src/main/java/baritone/launch/mixins/MixinMinecraft.java | 8 ++++---- .../baritone/launch/mixins/MixinNetHandlerPlayClient.java | 4 ++-- .../java/baritone/launch/mixins/MixinNetworkManager.java | 4 ++-- .../java/baritone/launch/mixins/MixinWorldClient.java | 4 ++-- src/main/java/baritone/pathing/path/PathExecutor.java | 2 +- src/main/java/baritone/utils/ExampleBaritoneControl.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 4 ++-- 33 files changed, 62 insertions(+), 63 deletions(-) rename src/main/java/baritone/{ => api}/event/GameEventHandler.java (97%) rename src/main/java/baritone/{ => api}/event/events/BlockInteractEvent.java (97%) rename src/main/java/baritone/{ => api}/event/events/ChatEvent.java (92%) rename src/main/java/baritone/{ => api}/event/events/ChunkEvent.java (96%) rename src/main/java/baritone/{ => api}/event/events/ItemSlotEvent.java (93%) rename src/main/java/baritone/{ => api}/event/events/PacketEvent.java (93%) rename src/main/java/baritone/{ => api}/event/events/PathEvent.java (96%) rename src/main/java/baritone/{ => api}/event/events/PlayerUpdateEvent.java (92%) rename src/main/java/baritone/{ => api}/event/events/RelativeMoveEvent.java (92%) rename src/main/java/baritone/{ => api}/event/events/RenderEvent.java (96%) rename src/main/java/baritone/{ => api}/event/events/TickEvent.java (93%) rename src/main/java/baritone/{ => api}/event/events/WorldEvent.java (94%) rename src/main/java/baritone/{ => api}/event/events/type/Cancellable.java (96%) rename src/main/java/baritone/{ => api}/event/events/type/EventState.java (96%) rename src/main/java/baritone/{ => api}/event/listener/AbstractGameEventListener.java (97%) rename src/main/java/baritone/{ => api}/event/listener/IGameEventListener.java (98%) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 333a9fdb..0ef6da9d 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -22,7 +22,7 @@ import baritone.behavior.impl.LookBehavior; import baritone.behavior.impl.MemoryBehavior; import baritone.behavior.impl.PathingBehavior; import baritone.behavior.impl.LocationTrackingBehavior; -import baritone.event.GameEventHandler; +import baritone.api.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java similarity index 97% rename from src/main/java/baritone/event/GameEventHandler.java rename to src/main/java/baritone/api/event/GameEventHandler.java index 02c7f393..22da9430 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -32,13 +32,13 @@ * along with Baritone. If not, see . */ -package baritone.event; +package baritone.api.event; import baritone.Baritone; import baritone.chunk.WorldProvider; -import baritone.event.events.*; -import baritone.event.events.type.EventState; -import baritone.event.listener.IGameEventListener; +import baritone.api.event.events.*; +import baritone.api.event.events.type.EventState; +import baritone.api.event.listener.IGameEventListener; import baritone.utils.Helper; import baritone.utils.InputOverrideHandler; import baritone.utils.interfaces.Toggleable; diff --git a/src/main/java/baritone/event/events/BlockInteractEvent.java b/src/main/java/baritone/api/event/events/BlockInteractEvent.java similarity index 97% rename from src/main/java/baritone/event/events/BlockInteractEvent.java rename to src/main/java/baritone/api/event/events/BlockInteractEvent.java index c458f6b6..2c57952c 100644 --- a/src/main/java/baritone/event/events/BlockInteractEvent.java +++ b/src/main/java/baritone/api/event/events/BlockInteractEvent.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/event/events/ChatEvent.java b/src/main/java/baritone/api/event/events/ChatEvent.java similarity index 92% rename from src/main/java/baritone/event/events/ChatEvent.java rename to src/main/java/baritone/api/event/events/ChatEvent.java index 5fdf269c..87a81e70 100644 --- a/src/main/java/baritone/event/events/ChatEvent.java +++ b/src/main/java/baritone/api/event/events/ChatEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.Cancellable; +import baritone.api.event.events.type.Cancellable; /** * @author Brady diff --git a/src/main/java/baritone/event/events/ChunkEvent.java b/src/main/java/baritone/api/event/events/ChunkEvent.java similarity index 96% rename from src/main/java/baritone/event/events/ChunkEvent.java rename to src/main/java/baritone/api/event/events/ChunkEvent.java index e5fe8a7f..1f8c6c39 100644 --- a/src/main/java/baritone/event/events/ChunkEvent.java +++ b/src/main/java/baritone/api/event/events/ChunkEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; /** * @author Brady diff --git a/src/main/java/baritone/event/events/ItemSlotEvent.java b/src/main/java/baritone/api/event/events/ItemSlotEvent.java similarity index 93% rename from src/main/java/baritone/event/events/ItemSlotEvent.java rename to src/main/java/baritone/api/event/events/ItemSlotEvent.java index b660cbea..82e69177 100644 --- a/src/main/java/baritone/event/events/ItemSlotEvent.java +++ b/src/main/java/baritone/api/event/events/ItemSlotEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.listener.IGameEventListener; +import baritone.api.event.listener.IGameEventListener; /** * Called in some cases where a player's inventory has it's current slot queried. diff --git a/src/main/java/baritone/event/events/PacketEvent.java b/src/main/java/baritone/api/event/events/PacketEvent.java similarity index 93% rename from src/main/java/baritone/event/events/PacketEvent.java rename to src/main/java/baritone/api/event/events/PacketEvent.java index 54401f6a..77310994 100644 --- a/src/main/java/baritone/event/events/PacketEvent.java +++ b/src/main/java/baritone/api/event/events/PacketEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; import net.minecraft.network.Packet; /** diff --git a/src/main/java/baritone/event/events/PathEvent.java b/src/main/java/baritone/api/event/events/PathEvent.java similarity index 96% rename from src/main/java/baritone/event/events/PathEvent.java rename to src/main/java/baritone/api/event/events/PathEvent.java index 53892058..a3fee3f8 100644 --- a/src/main/java/baritone/event/events/PathEvent.java +++ b/src/main/java/baritone/api/event/events/PathEvent.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; public enum PathEvent { CALC_STARTED, diff --git a/src/main/java/baritone/event/events/PlayerUpdateEvent.java b/src/main/java/baritone/api/event/events/PlayerUpdateEvent.java similarity index 92% rename from src/main/java/baritone/event/events/PlayerUpdateEvent.java rename to src/main/java/baritone/api/event/events/PlayerUpdateEvent.java index 1f52bd80..59bdf702 100644 --- a/src/main/java/baritone/event/events/PlayerUpdateEvent.java +++ b/src/main/java/baritone/api/event/events/PlayerUpdateEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; /** * @author Brady diff --git a/src/main/java/baritone/event/events/RelativeMoveEvent.java b/src/main/java/baritone/api/event/events/RelativeMoveEvent.java similarity index 92% rename from src/main/java/baritone/event/events/RelativeMoveEvent.java rename to src/main/java/baritone/api/event/events/RelativeMoveEvent.java index 1b639df5..14798fd5 100644 --- a/src/main/java/baritone/event/events/RelativeMoveEvent.java +++ b/src/main/java/baritone/api/event/events/RelativeMoveEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; /** * @author Brady diff --git a/src/main/java/baritone/event/events/RenderEvent.java b/src/main/java/baritone/api/event/events/RenderEvent.java similarity index 96% rename from src/main/java/baritone/event/events/RenderEvent.java rename to src/main/java/baritone/api/event/events/RenderEvent.java index 73db95a7..ef693e2a 100644 --- a/src/main/java/baritone/event/events/RenderEvent.java +++ b/src/main/java/baritone/api/event/events/RenderEvent.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; /** * @author Brady diff --git a/src/main/java/baritone/event/events/TickEvent.java b/src/main/java/baritone/api/event/events/TickEvent.java similarity index 93% rename from src/main/java/baritone/event/events/TickEvent.java rename to src/main/java/baritone/api/event/events/TickEvent.java index d45f7d4d..e82c31ad 100644 --- a/src/main/java/baritone/event/events/TickEvent.java +++ b/src/main/java/baritone/api/event/events/TickEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; public final class TickEvent { diff --git a/src/main/java/baritone/event/events/WorldEvent.java b/src/main/java/baritone/api/event/events/WorldEvent.java similarity index 94% rename from src/main/java/baritone/event/events/WorldEvent.java rename to src/main/java/baritone/api/event/events/WorldEvent.java index 60bc660e..454755fe 100644 --- a/src/main/java/baritone/event/events/WorldEvent.java +++ b/src/main/java/baritone/api/event/events/WorldEvent.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.event.events; +package baritone.api.event.events; -import baritone.event.events.type.EventState; +import baritone.api.event.events.type.EventState; import net.minecraft.client.multiplayer.WorldClient; /** diff --git a/src/main/java/baritone/event/events/type/Cancellable.java b/src/main/java/baritone/api/event/events/type/Cancellable.java similarity index 96% rename from src/main/java/baritone/event/events/type/Cancellable.java rename to src/main/java/baritone/api/event/events/type/Cancellable.java index 3d8f7536..4c26f8f8 100644 --- a/src/main/java/baritone/event/events/type/Cancellable.java +++ b/src/main/java/baritone/api/event/events/type/Cancellable.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.event.events.type; +package baritone.api.event.events.type; /** * @author Brady diff --git a/src/main/java/baritone/event/events/type/EventState.java b/src/main/java/baritone/api/event/events/type/EventState.java similarity index 96% rename from src/main/java/baritone/event/events/type/EventState.java rename to src/main/java/baritone/api/event/events/type/EventState.java index c0a6a863..a7fccff1 100644 --- a/src/main/java/baritone/event/events/type/EventState.java +++ b/src/main/java/baritone/api/event/events/type/EventState.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.event.events.type; +package baritone.api.event.events.type; /** * @author Brady diff --git a/src/main/java/baritone/event/listener/AbstractGameEventListener.java b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java similarity index 97% rename from src/main/java/baritone/event/listener/AbstractGameEventListener.java rename to src/main/java/baritone/api/event/listener/AbstractGameEventListener.java index 4b8de23a..b47468bd 100644 --- a/src/main/java/baritone/event/listener/AbstractGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -32,9 +32,9 @@ * along with Baritone. If not, see . */ -package baritone.event.listener; +package baritone.api.event.listener; -import baritone.event.events.*; +import baritone.api.event.events.*; /** * An implementation of {@link IGameEventListener} that has all methods diff --git a/src/main/java/baritone/event/listener/IGameEventListener.java b/src/main/java/baritone/api/event/listener/IGameEventListener.java similarity index 98% rename from src/main/java/baritone/event/listener/IGameEventListener.java rename to src/main/java/baritone/api/event/listener/IGameEventListener.java index 4900f1eb..9be19aab 100644 --- a/src/main/java/baritone/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/IGameEventListener.java @@ -32,9 +32,9 @@ * along with Baritone. If not, see . */ -package baritone.event.listener; +package baritone.api.event.listener; -import baritone.event.events.*; +import baritone.api.event.events.*; import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; diff --git a/src/main/java/baritone/behavior/Behavior.java b/src/main/java/baritone/behavior/Behavior.java index d9e0e357..ad5e3a88 100644 --- a/src/main/java/baritone/behavior/Behavior.java +++ b/src/main/java/baritone/behavior/Behavior.java @@ -17,7 +17,7 @@ package baritone.behavior; -import baritone.event.listener.AbstractGameEventListener; +import baritone.api.event.listener.AbstractGameEventListener; import baritone.utils.Helper; import baritone.utils.interfaces.Toggleable; diff --git a/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java index b4caa766..ba075dd3 100644 --- a/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java +++ b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java @@ -20,7 +20,7 @@ package baritone.behavior.impl; import baritone.behavior.Behavior; import baritone.chunk.Waypoint; import baritone.chunk.WorldProvider; -import baritone.event.events.BlockInteractEvent; +import baritone.api.event.events.BlockInteractEvent; import baritone.utils.BlockStateInterface; import net.minecraft.block.BlockBed; diff --git a/src/main/java/baritone/behavior/impl/LookBehavior.java b/src/main/java/baritone/behavior/impl/LookBehavior.java index 00ffce54..080d75d5 100644 --- a/src/main/java/baritone/behavior/impl/LookBehavior.java +++ b/src/main/java/baritone/behavior/impl/LookBehavior.java @@ -20,9 +20,8 @@ package baritone.behavior.impl; import baritone.Baritone; import baritone.Settings; import baritone.behavior.Behavior; -import baritone.event.events.PlayerUpdateEvent; -import baritone.event.events.RelativeMoveEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.RelativeMoveEvent; import baritone.utils.Rotation; public class LookBehavior extends Behavior { diff --git a/src/main/java/baritone/behavior/impl/MemoryBehavior.java b/src/main/java/baritone/behavior/impl/MemoryBehavior.java index ed5bd686..2edb9ec3 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.event.events.PacketEvent; -import baritone.event.events.PlayerUpdateEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.PacketEvent; +import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.type.EventState; import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.network.play.client.CPacketCloseWindow; diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 83a479a4..37690f21 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -19,10 +19,10 @@ package baritone.behavior.impl; import baritone.Baritone; import baritone.behavior.Behavior; -import baritone.event.events.PathEvent; -import baritone.event.events.PlayerUpdateEvent; -import baritone.event.events.RenderEvent; -import baritone.event.events.TickEvent; +import baritone.api.event.events.PathEvent; +import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.RenderEvent; +import baritone.api.event.events.TickEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; diff --git a/src/main/java/baritone/launch/mixins/MixinEntity.java b/src/main/java/baritone/launch/mixins/MixinEntity.java index 31b1e41b..2a0134d3 100644 --- a/src/main/java/baritone/launch/mixins/MixinEntity.java +++ b/src/main/java/baritone/launch/mixins/MixinEntity.java @@ -18,8 +18,8 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.RelativeMoveEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.RelativeMoveEvent; +import baritone.api.event.events.type.EventState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java index ea0896c5..9da39df3 100644 --- a/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java +++ b/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java @@ -18,9 +18,9 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.ChatEvent; -import baritone.event.events.PlayerUpdateEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.ChatEvent; +import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.type.EventState; import net.minecraft.client.entity.EntityPlayerSP; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java b/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java index a2cfe664..55adfc83 100644 --- a/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java +++ b/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java @@ -18,7 +18,7 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.RenderEvent; +import baritone.api.event.events.RenderEvent; import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java b/src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java index 24aff3cf..dfaa4b19 100644 --- a/src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java +++ b/src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java @@ -18,7 +18,7 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.ItemSlotEvent; +import baritone.api.event.events.ItemSlotEvent; import net.minecraft.entity.player.InventoryPlayer; import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/baritone/launch/mixins/MixinMinecraft.java b/src/main/java/baritone/launch/mixins/MixinMinecraft.java index 3d0b6619..0f0052bb 100755 --- a/src/main/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/main/java/baritone/launch/mixins/MixinMinecraft.java @@ -19,10 +19,10 @@ package baritone.launch.mixins; import baritone.Baritone; import baritone.behavior.impl.PathingBehavior; -import baritone.event.events.BlockInteractEvent; -import baritone.event.events.TickEvent; -import baritone.event.events.WorldEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.BlockInteractEvent; +import baritone.api.event.events.TickEvent; +import baritone.api.event.events.WorldEvent; +import baritone.api.event.events.type.EventState; import baritone.utils.ExampleBaritoneControl; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; diff --git a/src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java index 1af4ca6c..bd4cbb97 100644 --- a/src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java +++ b/src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java @@ -18,8 +18,8 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.ChunkEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.ChunkEvent; +import baritone.api.event.events.type.EventState; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketCombatEvent; diff --git a/src/main/java/baritone/launch/mixins/MixinNetworkManager.java b/src/main/java/baritone/launch/mixins/MixinNetworkManager.java index 48da859f..472d4f04 100644 --- a/src/main/java/baritone/launch/mixins/MixinNetworkManager.java +++ b/src/main/java/baritone/launch/mixins/MixinNetworkManager.java @@ -18,8 +18,8 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.PacketEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.PacketEvent; +import baritone.api.event.events.type.EventState; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.util.concurrent.Future; diff --git a/src/main/java/baritone/launch/mixins/MixinWorldClient.java b/src/main/java/baritone/launch/mixins/MixinWorldClient.java index da4b019f..005dbe16 100644 --- a/src/main/java/baritone/launch/mixins/MixinWorldClient.java +++ b/src/main/java/baritone/launch/mixins/MixinWorldClient.java @@ -18,8 +18,8 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.event.events.ChunkEvent; -import baritone.event.events.type.EventState; +import baritone.api.event.events.ChunkEvent; +import baritone.api.event.events.type.EventState; import net.minecraft.client.multiplayer.WorldClient; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0e7ebec6..e9f094a5 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -18,7 +18,7 @@ package baritone.pathing.path; import baritone.Baritone; -import baritone.event.events.TickEvent; +import baritone.api.event.events.TickEvent; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementState; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 59cafd6b..3b9cc18e 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -24,7 +24,7 @@ import baritone.behavior.impl.PathingBehavior; import baritone.chunk.ChunkPacker; import baritone.chunk.Waypoint; import baritone.chunk.WorldProvider; -import baritone.event.events.ChatEvent; +import baritone.api.event.events.ChatEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.goals.*; import baritone.pathing.movement.ActionCosts; diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index bb445226..415d8ebd 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -18,8 +18,8 @@ package baritone.utils; import baritone.Baritone; -import baritone.event.events.ItemSlotEvent; -import baritone.event.listener.AbstractGameEventListener; +import baritone.api.event.events.ItemSlotEvent; +import baritone.api.event.listener.AbstractGameEventListener; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; From af3bc1807914d8e630efb0ea079285827c11a993 Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 27 Aug 2018 18:00:11 -0700 Subject: [PATCH 023/165] add GoalNear --- .../java/baritone/pathing/goals/GoalNear.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/baritone/pathing/goals/GoalNear.java diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java new file mode 100644 index 00000000..e375f17c --- /dev/null +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -0,0 +1,50 @@ +/* + * 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.goals; + +import net.minecraft.util.math.BlockPos; + +public class GoalNear implements Goal { + final int x; + final int y; + final int z; + final int rangeSq; + + public GoalNear(BlockPos pos, int range) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + this.rangeSq = range * range; + } + + @Override + public boolean isInGoal(BlockPos pos) { + int diffX = x - pos.getX(); + int diffY = y - pos.getY(); + int diffZ = z - pos.getZ(); + return diffX * diffX + diffY * diffY + diffZ * diffZ <= rangeSq; + } + + @Override + public double heuristic(BlockPos pos) { + int diffX = x - pos.getX(); + int diffY = y - pos.getY(); + int diffZ = z - pos.getZ(); + return GoalBlock.calculate(diffX, diffY, diffZ); + } +} From 65bfe466bb0a95a43bb2fcf36916bbacb42795a5 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 20:06:38 -0500 Subject: [PATCH 024/165] Clean up retrieving tags by string --- src/main/java/baritone/chunk/Waypoint.java | 32 ++++++++++--------- .../utils/ExampleBaritoneControl.java | 4 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/chunk/Waypoint.java b/src/main/java/baritone/chunk/Waypoint.java index 091c958c..8b290d56 100644 --- a/src/main/java/baritone/chunk/Waypoint.java +++ b/src/main/java/baritone/chunk/Waypoint.java @@ -17,12 +17,11 @@ package baritone.chunk; +import com.google.common.collect.ImmutableList; import net.minecraft.util.math.BlockPos; +import org.apache.commons.lang3.ArrayUtils; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * A single waypoint @@ -30,6 +29,7 @@ import java.util.Map; * @author leijurv */ public class Waypoint { + public final String name; public final Tag tag; private final long creationTimestamp; @@ -72,19 +72,21 @@ public class Waypoint { } public enum Tag { - HOME, DEATH, BED, USER; + HOME("home", "base"), + DEATH("death"), + BED("bed", "spawn"), + USER(); - } + private static final List TAG_LIST = ImmutableList.builder().add(Tag.values()).build(); - public static final Map TAG_MAP; + private final String[] names; - static { - HashMap map = new HashMap<>(); - map.put("home", Tag.HOME); - map.put("base", Tag.HOME); - map.put("bed", Tag.BED); - map.put("spawn", Tag.BED); - map.put("death", Tag.DEATH); - TAG_MAP = Collections.unmodifiableMap(map); + Tag(String... names) { + this.names = names; + } + + public static Tag fromString(String name) { + return TAG_LIST.stream().filter(tag -> ArrayUtils.contains(tag.names, name.toLowerCase())).findFirst().orElse(null); + } } } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 3b9cc18e..57906ff0 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -195,7 +195,7 @@ public class ExampleBaritoneControl extends Behavior { // for example, "show deaths" waypointType = waypointType.substring(0, waypointType.length() - 1); } - Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType); + Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); @@ -218,7 +218,7 @@ public class ExampleBaritoneControl extends Behavior { // for example, "show deaths" waypointType = waypointType.substring(0, waypointType.length() - 1); } - Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType); + Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); From 27a3adecebfa1e12ba9c3fb7315e2c0f4bd8813b Mon Sep 17 00:00:00 2001 From: leijurv Date: Mon, 27 Aug 2018 19:05:21 -0700 Subject: [PATCH 025/165] FollowBehavior --- src/main/java/baritone/Baritone.java | 6 +- .../behavior/impl/FollowBehavior.java | 55 +++++++++++++++++++ .../utils/ExampleBaritoneControl.java | 15 +++++ 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/main/java/baritone/behavior/impl/FollowBehavior.java diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 0ef6da9d..2a88ed21 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -18,10 +18,7 @@ package baritone; import baritone.behavior.Behavior; -import baritone.behavior.impl.LookBehavior; -import baritone.behavior.impl.MemoryBehavior; -import baritone.behavior.impl.PathingBehavior; -import baritone.behavior.impl.LocationTrackingBehavior; +import baritone.behavior.impl.*; import baritone.api.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; @@ -81,6 +78,7 @@ public enum Baritone { registerBehavior(LookBehavior.INSTANCE); registerBehavior(MemoryBehavior.INSTANCE); registerBehavior(LocationTrackingBehavior.INSTANCE); + registerBehavior(FollowBehavior.INSTANCE); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/behavior/impl/FollowBehavior.java b/src/main/java/baritone/behavior/impl/FollowBehavior.java new file mode 100644 index 00000000..7ac54c32 --- /dev/null +++ b/src/main/java/baritone/behavior/impl/FollowBehavior.java @@ -0,0 +1,55 @@ +/* + * 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.behavior.impl; + +import baritone.api.event.events.TickEvent; +import baritone.behavior.Behavior; +import baritone.pathing.goals.GoalNear; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; + +public class FollowBehavior extends Behavior { + public static final FollowBehavior INSTANCE = new FollowBehavior(); + + private FollowBehavior() { + } + + Entity following; + + @Override + public void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + return; + } + if (following == null) { + return; + } + // lol this is trashy but it works + PathingBehavior.INSTANCE.setGoal(new GoalNear(new BlockPos(following), 3)); + PathingBehavior.INSTANCE.path(); + } + + public void follow(Entity follow) { + this.following = follow; + } + + public void cancel() { + PathingBehavior.INSTANCE.cancel(); + follow(null); + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 3b9cc18e..997011df 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.Settings; import baritone.behavior.Behavior; +import baritone.behavior.impl.FollowBehavior; import baritone.behavior.impl.PathingBehavior; import baritone.chunk.ChunkPacker; import baritone.chunk.Waypoint; @@ -30,8 +31,10 @@ import baritone.pathing.goals.*; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; +import baritone.pathing.movement.MovementHelper; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -131,6 +134,18 @@ public class ExampleBaritoneControl extends Behavior { event.cancel(); return; } + if (msg.toLowerCase().equals("follow")) { + Optional entity = MovementHelper.whatEntityAmILookingAt(); + if (!entity.isPresent()) { + displayChatMessageRaw("You aren't looking at an entity bruh"); + event.cancel(); + return; + } + FollowBehavior.INSTANCE.follow(entity.get()); + displayChatMessageRaw("Following " + entity.get()); + event.cancel(); + return; + } if (msg.toLowerCase().equals("reloadall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk(); displayChatMessageRaw("ok"); From 850beb6c082bc24576e0a41faced67c53810f041 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 07:29:41 -0700 Subject: [PATCH 026/165] really cancel --- src/main/java/baritone/utils/ExampleBaritoneControl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 32e58c8b..fcab3334 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -19,13 +19,13 @@ package baritone.utils; import baritone.Baritone; import baritone.Settings; +import baritone.api.event.events.ChatEvent; import baritone.behavior.Behavior; import baritone.behavior.impl.FollowBehavior; import baritone.behavior.impl.PathingBehavior; import baritone.chunk.ChunkPacker; import baritone.chunk.Waypoint; import baritone.chunk.WorldProvider; -import baritone.api.event.events.ChatEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.goals.*; import baritone.pathing.movement.ActionCosts; @@ -108,6 +108,7 @@ public class ExampleBaritoneControl extends Behavior { } if (msg.toLowerCase().equals("cancel")) { PathingBehavior.INSTANCE.cancel(); + FollowBehavior.INSTANCE.cancel(); event.cancel(); displayChatMessageRaw("ok canceled"); return; From 46fefa9298910802426d4d936a40f2c15cd3ac6f Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 28 Aug 2018 08:55:56 -0700 Subject: [PATCH 027/165] simplification support for more goal types --- .../behavior/impl/PathingBehavior.java | 27 +++++++++++++------ .../pathing/goals/GoalGetToBlock.java | 7 +++++ .../java/baritone/pathing/goals/GoalNear.java | 4 +++ .../baritone/pathing/goals/GoalTwoBlocks.java | 4 +++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 37690f21..8b43d2f6 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -26,9 +26,7 @@ import baritone.api.event.events.TickEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; -import baritone.pathing.goals.Goal; -import baritone.pathing.goals.GoalBlock; -import baritone.pathing.goals.GoalXZ; +import baritone.pathing.goals.*; import baritone.pathing.path.IPath; import baritone.pathing.path.PathExecutor; import baritone.utils.BlockStateInterface; @@ -293,10 +291,23 @@ public class PathingBehavior extends Behavior { displayChatMessageRaw("no goal"); return Optional.empty(); } - if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof GoalBlock) { - BlockPos pos = ((GoalBlock) goal).getGoalPos(); - if (world().getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Simplifying GoalBlock to GoalXZ due to distance"); + if (Baritone.settings().simplifyUnloadedYCoord.get()) { + BlockPos pos = null; + if (goal instanceof GoalBlock) { + pos = ((GoalBlock) goal).getGoalPos(); + } + if (goal instanceof GoalTwoBlocks) { + pos = ((GoalTwoBlocks) goal).getGoalPos(); + } + if (goal instanceof GoalNear) { + pos = ((GoalNear) goal).getGoalPos(); + } + if (goal instanceof GoalGetToBlock) { + pos = ((GoalGetToBlock) goal).getGoalPos(); + } + // 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"); goal = new GoalXZ(pos.getX(), pos.getZ()); } } @@ -304,7 +315,7 @@ public class PathingBehavior extends Behavior { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); return pf.calculate(); } catch (Exception e) { - displayChatMessageRaw("Exception: " + e); + displayChatMessageRaw("Pathing exception: " + e); e.printStackTrace(); return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index daf7fc9d..9c847918 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -27,8 +27,11 @@ import net.minecraft.util.math.BlockPos; */ public class GoalGetToBlock extends GoalComposite { + private final BlockPos pos; + public GoalGetToBlock(BlockPos pos) { super(adjacentBlocks(pos)); + this.pos = pos; } private static BlockPos[] adjacentBlocks(BlockPos pos) { @@ -38,4 +41,8 @@ public class GoalGetToBlock extends GoalComposite { } return sides; } + + public BlockPos getGoalPos() { + return pos; + } } diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index e375f17c..d19fadf8 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -47,4 +47,8 @@ public class GoalNear implements Goal { int diffZ = z - pos.getZ(); return GoalBlock.calculate(diffX, diffY, diffZ); } + + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); + } } diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 70690fa3..65571a49 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -68,6 +68,10 @@ public class GoalTwoBlocks implements Goal { return GoalBlock.calculate(xDiff, yDiff, zDiff); } + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); + } + @Override public String toString() { return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}"; From df73e07923805f84bce28594001dcda0bd958c8e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 10:04:25 -0700 Subject: [PATCH 028/165] Add comment, fixes #102 --- 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 e9f094a5..88c9df26 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -46,7 +46,7 @@ import static baritone.pathing.movement.MovementState.MovementStatus.*; */ public class PathExecutor implements Helper { private static final double MAX_DIST_FROM_PATH = 2; - private static final double MAX_TICKS_AWAY = 200; // ten seconds + private static final double MAX_TICKS_AWAY = 200; // ten seconds. ok to decrease this, but it must be at least 110, see issue #102 private final IPath path; private int pathPosition; private int ticksAway; From c0fb57825cc4bd7d823a02924cf2f0baf795caf2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 11:17:11 -0700 Subject: [PATCH 029/165] cancel calculation in progress --- src/main/java/baritone/behavior/impl/PathingBehavior.java | 3 ++- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 6 +++++- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 8b43d2f6..25eb89ef 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -18,11 +18,11 @@ package baritone.behavior.impl; import baritone.Baritone; -import baritone.behavior.Behavior; import baritone.api.event.events.PathEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.RenderEvent; import baritone.api.event.events.TickEvent; +import baritone.behavior.Behavior; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; @@ -194,6 +194,7 @@ public class PathingBehavior extends Behavior { current = null; next = null; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); } public void path() { diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index dc31e1c4..2dca7bb8 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -80,7 +80,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); - while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime) { + while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) { if (slowPath) { try { Thread.sleep(Baritone.settings().slowPathTimeDelayMS.get()); @@ -169,6 +169,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } } } + if (cancelRequested) { + currentlyRunning = null; + return Optional.empty(); + } double bestDist = 0; for (int i = 0; i < bestSoFar.length; i++) { if (bestSoFar[i] == null) { diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 5414f89c..18b8050f 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -52,6 +52,8 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { private volatile boolean isFinished; + protected boolean cancelRequested; + /** * This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so * long it was easier as a Google Doc (because I could insert charts). @@ -70,10 +72,15 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { this.map = new HashMap<>(); } + public void cancel() { + cancelRequested = true; + } + public synchronized Optional calculate() { if (isFinished) { throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); } + this.cancelRequested = false; Optional path = calculate0(); isFinished = true; return path; From c761a9b12783bb075efb79d5185f51167ad217ab Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 11:28:36 -0700 Subject: [PATCH 030/165] better chunk saving and loading --- src/main/java/baritone/behavior/impl/MineBehavior.java | 4 ++++ src/main/java/baritone/chunk/CachedRegion.java | 8 ++++---- src/main/java/baritone/chunk/CachedWorld.java | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/main/java/baritone/behavior/impl/MineBehavior.java diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java new file mode 100644 index 00000000..01dd4137 --- /dev/null +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -0,0 +1,4 @@ +package baritone.behavior.impl; + +public class MineBehavior { +} diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 7d2ed3dc..66204d5a 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -117,8 +117,8 @@ public final class CachedRegion implements IBlockTypeAccess { Files.createFile(regionFile); try ( FileOutputStream fileOut = new FileOutputStream(regionFile.toFile()); - GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut); - DataOutputStream out = new DataOutputStream(gzipOut); + GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384); + DataOutputStream out = new DataOutputStream(gzipOut) ) { out.writeInt(CACHED_REGION_MAGIC); for (int z = 0; z < 32; z++) { @@ -183,8 +183,8 @@ public final class CachedRegion implements IBlockTypeAccess { try ( FileInputStream fileIn = new FileInputStream(regionFile.toFile()); - GZIPInputStream gzipIn = new GZIPInputStream(fileIn); - DataInputStream in = new DataInputStream(gzipIn); + GZIPInputStream gzipIn = new GZIPInputStream(fileIn, 32768); + DataInputStream in = new DataInputStream(gzipIn) ) { int magic = in.readInt(); if (magic != CACHED_REGION_MAGIC) { diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index b24857de..42b4c13d 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -69,6 +69,7 @@ public final class CachedWorld implements IBlockTypeAccess { new Thread() { public void run() { try { + Thread.sleep(30000); while (true) { // since a region only saves if it's been modified since its last save // saving every 10 minutes means that once it's time to exit @@ -141,7 +142,7 @@ public final class CachedWorld implements IBlockTypeAccess { return; } long start = System.currentTimeMillis(); - this.cachedRegions.values().forEach(region -> { + this.cachedRegions.values().parallelStream().forEach(region -> { if (region != null) region.save(this.directory); }); From 01dbf75eca3130ea57eb78df152f59c2dac94f65 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 11:43:28 -0700 Subject: [PATCH 031/165] MineBehavior --- src/main/java/baritone/Baritone.java | 3 +- .../behavior/impl/FollowBehavior.java | 5 ++ .../baritone/behavior/impl/MineBehavior.java | 84 ++++++++++++++++++- .../behavior/impl/PathingBehavior.java | 13 ++- .../utils/ExampleBaritoneControl.java | 39 +++------ 5 files changed, 112 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 2a88ed21..bd678dd8 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -17,9 +17,9 @@ package baritone; +import baritone.api.event.GameEventHandler; import baritone.behavior.Behavior; import baritone.behavior.impl.*; -import baritone.api.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; @@ -79,6 +79,7 @@ public enum Baritone { registerBehavior(MemoryBehavior.INSTANCE); registerBehavior(LocationTrackingBehavior.INSTANCE); registerBehavior(FollowBehavior.INSTANCE); + registerBehavior(MineBehavior.INSTANCE); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/behavior/impl/FollowBehavior.java b/src/main/java/baritone/behavior/impl/FollowBehavior.java index 7ac54c32..55ec5539 100644 --- a/src/main/java/baritone/behavior/impl/FollowBehavior.java +++ b/src/main/java/baritone/behavior/impl/FollowBehavior.java @@ -23,6 +23,11 @@ import baritone.pathing.goals.GoalNear; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; +/** + * Follow an entity + * + * @author leijurv + */ public class FollowBehavior extends Behavior { public static final FollowBehavior INSTANCE = new FollowBehavior(); diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 01dd4137..e59058a8 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -1,4 +1,86 @@ +/* + * 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.behavior.impl; -public class MineBehavior { +import baritone.api.event.events.TickEvent; +import baritone.behavior.Behavior; +import baritone.chunk.ChunkPacker; +import baritone.chunk.WorldProvider; +import baritone.pathing.goals.Goal; +import baritone.pathing.goals.GoalComposite; +import baritone.pathing.goals.GoalTwoBlocks; +import baritone.utils.BlockStateInterface; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.EmptyChunk; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Mine blocks of a certain type + * + * @author leijurv + */ +public class MineBehavior extends Behavior { + public static final MineBehavior INSTANCE = new MineBehavior(); + + private MineBehavior() { + } + + String mining; + + @Override + public void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + return; + } + if (mining == null) { + return; + } + List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1)); + if (locs.isEmpty()) { + displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + cancel(); + return; + } + BlockPos playerFeet = playerFeet(); + locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); + + // remove any that are within loaded chunks that aren't actually what we want + locs.removeAll(locs.stream() + .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) + .filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining)) + .collect(Collectors.toList())); + if (locs.size() > 30) { + locs = locs.subList(0, 30); + } + PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalTwoBlocks::new).toArray(Goal[]::new))); + PathingBehavior.INSTANCE.path(); + } + + public void mine(String mining) { + this.mining = mining; + } + + public void cancel() { + PathingBehavior.INSTANCE.cancel(); + mine(null); + } } diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 25eb89ef..4b5f1f43 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -197,18 +197,23 @@ public class PathingBehavior extends Behavior { AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); } - public void path() { + /** + * Start calculating a path if we aren't already + * + * @return true if this call started path calculation, false if it was already calculating or executing a path + */ + public boolean path() { synchronized (pathPlanLock) { if (current != null) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); - return; + return false; } synchronized (pathCalcLock) { if (isPathCalcInProgress) { - return; + return false; } dispatchPathEvent(PathEvent.CALC_STARTED); findPathInNewThread(pathStart(), true, Optional.empty()); + return true; } } } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index fcab3334..542ea323 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -22,6 +22,7 @@ import baritone.Settings; import baritone.api.event.events.ChatEvent; 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; @@ -36,10 +37,8 @@ import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; import java.util.*; -import java.util.stream.Collectors; public class ExampleBaritoneControl extends Behavior { public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl(); @@ -102,13 +101,16 @@ public class ExampleBaritoneControl extends Behavior { return; } if (msg.equals("path")) { - PathingBehavior.INSTANCE.path(); + if (!PathingBehavior.INSTANCE.path()) { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } event.cancel(); return; } if (msg.toLowerCase().equals("cancel")) { PathingBehavior.INSTANCE.cancel(); FollowBehavior.INSTANCE.cancel(); + MineBehavior.INSTANCE.cancel(); event.cancel(); displayChatMessageRaw("ok canceled"); return; @@ -131,7 +133,9 @@ public class ExampleBaritoneControl extends Behavior { return false; } }); - PathingBehavior.INSTANCE.path(); + if (!PathingBehavior.INSTANCE.path()) { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } event.cancel(); return; } @@ -174,27 +178,8 @@ public class ExampleBaritoneControl extends Behavior { } if (msg.toLowerCase().startsWith("mine")) { String blockType = msg.toLowerCase().substring(4).trim(); - List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 1)); - if (locs.isEmpty()) { - displayChatMessageRaw("No locations known"); - event.cancel(); - return; - } - BlockPos playerFeet = playerFeet(); - locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); - - // remove any that are within loaded chunks that aren't actually what we want - locs.removeAll(locs.stream() - .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) - .filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(blockType)) - .collect(Collectors.toList())); - - if (locs.size() > 30) { - displayChatMessageRaw("Pathing to any of closest 30"); - locs = locs.subList(0, 30); - } - PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalTwoBlocks::new).toArray(Goal[]::new))); - PathingBehavior.INSTANCE.path(); + MineBehavior.INSTANCE.mine(blockType); + displayChatMessageRaw("Started mining blocks of type" + blockType); event.cancel(); return; } @@ -248,7 +233,9 @@ public class ExampleBaritoneControl extends Behavior { } Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); - PathingBehavior.INSTANCE.path(); + if (!PathingBehavior.INSTANCE.path()) { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } event.cancel(); return; } From 169eb1d0a3515e536678f8a5ad5fbe56b7d0b28a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 11:57:31 -0700 Subject: [PATCH 032/165] more efficient check --- .../java/baritone/pathing/movement/MovementHelper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 549ee621..79892bbe 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -93,10 +93,15 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } } - IBlockState up = BlockStateInterface.get(pos.up()); - if (BlockStateInterface.isFlowing(state) || up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { + if (BlockStateInterface.isFlowing(state)) { return false; // Don't walk through flowing liquids } + if (block instanceof BlockLiquid) { + IBlockState up = BlockStateInterface.get(pos.up()); + if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { + return false; + } + } return block.isPassable(mc.world, pos); } From bf05de1de7970eacce5b796bd36239d9a0d7fb9e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 12:23:54 -0700 Subject: [PATCH 033/165] can't use flowing water, so pack it as such --- src/main/java/baritone/chunk/ChunkPacker.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index e205d7f8..6bac5529 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -18,7 +18,6 @@ package baritone.chunk; import baritone.pathing.movement.MovementHelper; -import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.block.Block; @@ -105,11 +104,12 @@ public final class ChunkPacker implements Helper { } private static PathingBlockType getPathingBlockType(Block block) { - if (BlockStateInterface.isWater(block)) { + if (block.equals(Blocks.WATER)) { + // only water source blocks are plausibly usable, flowing water should be avoid return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block)) { + if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER)) { return PathingBlockType.AVOID; } // We used to do an AABB check here From 890e5be0edb28516f2e7dd3717642e78702bd83a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 12:30:08 -0700 Subject: [PATCH 034/165] assumeWalkOnWater --- src/main/java/baritone/Settings.java | 6 ++++++ .../baritone/pathing/movement/MovementHelper.java | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 099493e2..75aaddc9 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -56,6 +56,12 @@ public class Settings { */ public Setting allowWaterBucketFall = new Setting<>(true); + /** + * Allow Baritone to assume it can walk on still water just like any other block. + * This functionality is assumed to be provided by a separate library that might have imported Baritone. + */ + public Setting assumeWalkOnWater = new Setting<>(false); + /** * Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.) */ diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 79892bbe..95ded07c 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -48,7 +48,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean avoidBreaking(BlockPos pos, IBlockState state) { Block b = state.getBlock(); - BlockPos below = new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ()); + 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 || 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 @@ -56,7 +56,7 @@ public interface MovementHelper extends ActionCosts, Helper { || 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)) - || (!(b instanceof BlockLilyPad && BlockStateInterface.isWater(below)) && BlockStateInterface.isLiquid(below));//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid + || (!(b instanceof BlockLilyPad && BlockStateInterface.isWater(below)) && below instanceof BlockLiquid);//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid // TODO revisit this. why is it not okay to break non-lilypads that are right above water? } @@ -97,6 +97,9 @@ public interface MovementHelper extends ActionCosts, Helper { return false; // Don't walk through flowing liquids } if (block instanceof BlockLiquid) { + if (Baritone.settings().assumeWalkOnWater.get()) { + return false; + } IBlockState up = BlockStateInterface.get(pos.up()); if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { return false; @@ -196,6 +199,12 @@ public interface MovementHelper extends ActionCosts, Helper { return false; } if (BlockStateInterface.isWater(block)) { + if (BlockStateInterface.isFlowing(state)) { + return false; + } + if (Baritone.settings().assumeWalkOnWater.get()) { + return true; + } Block up = BlockStateInterface.get(pos.up()).getBlock(); return BlockStateInterface.isWater(up) || up instanceof BlockLilyPad; // You can only walk on water if there is water above it } From d4d2fb392a28405bb1e02ad87df8168c57a8e187 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 12:39:58 -0700 Subject: [PATCH 035/165] small optimization --- .../pathing/movement/movements/MovementTraverse.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 20b284e6..056b2741 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -86,7 +86,12 @@ public class MovementTraverse extends Movement { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } } - if (MovementHelper.canWalkThrough(positionsToBreak[0], pb0) && MovementHelper.canWalkThrough(positionsToBreak[1], pb1)) { + double hardness1 = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0], pb0, true); + if (hardness1 >= COST_INF) { + return COST_INF; + } + double hardness2 = MovementHelper.getMiningDurationTicks(context, positionsToBreak[1], pb1, false); + if (hardness1 == 0 && hardness2 == 0) { if (WC == WALK_ONE_BLOCK_COST && context.canSprint()) { // If there's nothing in the way, and this isn't water or soul sand, and we aren't sneak placing // We can sprint =D @@ -94,10 +99,7 @@ public class MovementTraverse extends Movement { } return WC; } - // double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]); - // double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]); - // Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")"); - return WC + getTotalHardnessOfBlocksToBreak(context); + return WC + hardness1 + hardness2; } else {//this is a bridge, so we need to place a block Block srcDown = BlockStateInterface.get(src.down()).getBlock(); if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) { From 1dc0f5c3ad68c364fb071ebf80a45e0360ae17c1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 12:53:01 -0700 Subject: [PATCH 036/165] update logic --- .../java/baritone/pathing/movement/MovementHelper.java | 8 +++++--- .../pathing/movement/movements/MovementTraverse.java | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 95ded07c..72fc9f5b 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -202,11 +202,13 @@ public interface MovementHelper extends ActionCosts, Helper { if (BlockStateInterface.isFlowing(state)) { return false; } - if (Baritone.settings().assumeWalkOnWater.get()) { + Block up = BlockStateInterface.get(pos.up()).getBlock(); + if (up instanceof BlockLilyPad) { return true; } - Block up = BlockStateInterface.get(pos.up()).getBlock(); - return BlockStateInterface.isWater(up) || up instanceof BlockLilyPad; // You can only walk on water if there is water above it + // if assumeWalkOnWater is on, we can only walk on water if there isn't water above it + // 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; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 056b2741..54e61359 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -105,12 +105,15 @@ public class MovementTraverse extends Movement { if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) { return COST_INF; } - IBlockState pp0 = BlockStateInterface.get(positionsToPlace[0]); - if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && MovementHelper.isReplacable(positionsToPlace[0], pp0))) { + if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionsToPlace[0], destOn)) { + boolean throughWater = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock()); + if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) { + return COST_INF; + } if (!context.hasThrowaway()) { return COST_INF; } - double WC = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock()) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST; + double WC = throughWater ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST; for (BlockPos against1 : against) { if (BlockStateInterface.get(against1).isBlockNormalCube()) { return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); From 4836f044bac6fbec2890e5b695b798d1172aa3f7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 13:24:34 -0700 Subject: [PATCH 037/165] pillar logic --- .../movement/movements/MovementPillar.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index dba55466..9da13b2c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -28,7 +28,6 @@ import baritone.utils.Utils; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.math.BlockPos; public class MovementPillar extends Movement { @@ -63,6 +62,9 @@ public class MovementPillar extends Movement { } } double hardness = getTotalHardnessOfBlocksToBreak(context); + if (hardness >= COST_INF) { + return COST_INF; + } if (hardness != 0) { Block tmp = BlockStateInterface.get(src.up(2)).getBlock(); if (tmp instanceof BlockLadder || tmp instanceof BlockVine) { @@ -70,12 +72,19 @@ public class MovementPillar extends Movement { } else { BlockPos chkPos = src.up(3); IBlockState check = BlockStateInterface.get(chkPos); - if (!MovementHelper.canWalkOn(chkPos, check) || MovementHelper.canWalkThrough(chkPos, check) || check.getBlock() instanceof BlockFalling) {//if the block above where we want to break is not a full block, don't do it - // TODO why does canWalkThrough mean this action is COST_INF? - // BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava - // but I don't understand why canWalkThrough makes it impossible - return COST_INF; + if (check.getBlock() instanceof BlockFalling) { + // see MovementAscend's identical check for breaking a falling block above our head + if (!(tmp instanceof BlockFalling) || !(BlockStateInterface.get(src.up(1)).getBlock() instanceof BlockFalling)) { + return COST_INF; + } } + // this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era. + //if (!MovementHelper.canWalkOn(chkPos, check) || MovementHelper.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it + // TODO why does canWalkThrough mean this action is COST_INF? + // BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava + // but I don't understand why canWalkThrough makes it impossible + // return COST_INF; + //} } } if (fromDown instanceof BlockLiquid || fromDownDown instanceof BlockLiquid) {//can't pillar on water or in water From 53d477d99adc433cb9ac02350a865d5caff632fb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 13:29:32 -0700 Subject: [PATCH 038/165] optimize diagonal --- .../movement/movements/MovementDiagonal.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 20defe13..d3c5b622 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -82,7 +82,6 @@ public class MovementDiagonal extends Movement { return COST_INF; } double multiplier = WALK_ONE_BLOCK_COST; - // For either possible soul sand, that affects half of our walking if (destWalkOn.getBlock().equals(Blocks.SOUL_SAND)) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; @@ -90,31 +89,34 @@ public class MovementDiagonal extends Movement { if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - if (BlockStateInterface.get(positionsToBreak[2].down()).getBlock() instanceof BlockMagma) { return COST_INF; } if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) { return COST_INF; } - double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1], true); - double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3], true); + IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); + IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]); + IBlockState pb2 = BlockStateInterface.get(positionsToBreak[2]); + IBlockState pb3 = BlockStateInterface.get(positionsToBreak[3]); + double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0], pb0, false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1], pb1, true); + double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2], pb2, false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3], pb3, true); if (optionA != 0 && optionB != 0) { return COST_INF; } if (optionA == 0) { - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[2]))) { + if (MovementHelper.avoidWalkingInto(pb2.getBlock())) { return COST_INF; } - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[3]))) { + if (MovementHelper.avoidWalkingInto(pb3.getBlock())) { return COST_INF; } } if (optionB == 0) { - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[0]))) { + if (MovementHelper.avoidWalkingInto(pb0.getBlock())) { return COST_INF; } - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(positionsToBreak[1]))) { + if (MovementHelper.avoidWalkingInto(pb1.getBlock())) { return COST_INF; } } From 557f2e48c30eae1c95bdd12edd2d64c21a9fd05c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 13:41:44 -0700 Subject: [PATCH 039/165] no movement places more than one thing... --- .../baritone/pathing/movement/Movement.java | 19 ++++++++----------- .../movement/movements/MovementAscend.java | 14 +++++++------- .../movement/movements/MovementDescend.java | 4 ++-- .../movement/movements/MovementDiagonal.java | 7 ++++--- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementFall.java | 4 ++-- .../movement/movements/MovementPillar.java | 4 ++-- .../movement/movements/MovementTraverse.java | 12 ++++++------ 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 11a88ad1..ce730b00 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -30,7 +30,6 @@ import net.minecraft.block.BlockLadder; import net.minecraft.block.BlockVine; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; import java.util.ArrayList; import java.util.Arrays; @@ -53,23 +52,23 @@ public abstract class Movement implements Helper, MovementHelper { protected final BlockPos[] positionsToBreak; /** - * The positions where we need to place a block before this movement can ensue + * The position where we need to place a block before this movement can ensue */ - protected final BlockPos[] positionsToPlace; + protected final BlockPos positionToPlace; private boolean didBreakLastTick; private Double cost; - protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace) { + protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { this.src = src; this.dest = dest; this.positionsToBreak = toBreak; - this.positionsToPlace = toPlace; + this.positionToPlace = toPlace; } - protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) { - this(src, dest, toBreak, toPlace); + protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) { + this(src, dest, toBreak, null); } public double getCost(CalculationContext context) { @@ -310,10 +309,8 @@ public abstract class Movement implements Helper, MovementHelper { return toPlaceCached; } List result = new ArrayList<>(); - for (BlockPos positionToBreak : positionsToPlace) { - if (!MovementHelper.canWalkOn(positionToBreak)) { - result.add(positionToBreak); - } + if (positionToPlace != null && !MovementHelper.canWalkOn(positionToPlace)) { + result.add(positionToPlace); } toPlaceCached = result; return result; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index f3225337..dc4476f3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -43,9 +43,9 @@ public class MovementAscend extends Movement { private int ticksWithoutPlacement = 0; public MovementAscend(BlockPos src, BlockPos dest) { - super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, new BlockPos[]{dest.down()}); + super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); - BlockPos placementLocation = positionsToPlace[0]; // dest.down() + BlockPos placementLocation = positionToPlace; // dest.down() int i = 0; if (!placementLocation.north().equals(src)) against[i++] = placementLocation.north(); @@ -72,12 +72,12 @@ public class MovementAscend extends Movement { @Override protected double calculateCost(CalculationContext context) { - IBlockState toPlace = BlockStateInterface.get(positionsToPlace[0]); - if (!MovementHelper.canWalkOn(positionsToPlace[0], toPlace)) { + IBlockState toPlace = BlockStateInterface.get(positionToPlace); + if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!context.hasThrowaway()) { return COST_INF; } - if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionsToPlace[0], toPlace)) { + if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) { return COST_INF; } for (BlockPos against1 : against) { @@ -135,7 +135,7 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.SUCCESS); } - if (!MovementHelper.canWalkOn(positionsToPlace[0])) { + if (!MovementHelper.canWalkOn(positionToPlace)) { for (BlockPos anAgainst : against) { if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) { if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block @@ -148,7 +148,7 @@ public class MovementAscend extends Movement { EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> { - if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionsToPlace[0])) { + if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) { ticksWithoutPlacement++; state.setInput(InputOverrideHandler.Input.SNEAK, true); if (player().isSneaking()) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 6e299bd1..7a07abb1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -33,7 +33,7 @@ import net.minecraft.util.math.BlockPos; public class MovementDescend extends Movement { public MovementDescend(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()}); + super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down()); } @Override @@ -44,7 +44,7 @@ public class MovementDescend extends Movement { @Override protected double calculateCost(CalculationContext context) { - if (!MovementHelper.canWalkOn(positionsToPlace[0])) { + if (!MovementHelper.canWalkOn(positionToPlace)) { return COST_INF; } Block tmp1 = BlockStateInterface.get(dest).getBlock(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index d3c5b622..384cf6be 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -46,7 +46,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 @@ -77,8 +77,9 @@ public class MovementDiagonal extends Movement { if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) { return COST_INF; } - IBlockState destWalkOn = BlockStateInterface.get(positionsToPlace[0]); - if (!MovementHelper.canWalkOn(positionsToPlace[0], destWalkOn)) { + BlockPos destDown = dest.down(); + IBlockState destWalkOn = BlockStateInterface.get(destDown); + if (!MovementHelper.canWalkOn(destDown, destWalkOn)) { return COST_INF; } double multiplier = WALK_ONE_BLOCK_COST; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 38232396..ece2c8f5 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -33,7 +33,7 @@ public class MovementDownward extends Movement { private int numTicks = 0; public MovementDownward(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end}, new BlockPos[0]); + super(start, end, new BlockPos[]{end}); } @Override diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index c42a8661..ee019c98 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -38,12 +38,12 @@ public class MovementFall extends Movement { private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET); public MovementFall(BlockPos src, BlockPos dest) { - super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()}); + super(src, dest, MovementFall.buildPositionsToBreak(src, dest)); } @Override protected double calculateCost(CalculationContext context) { - if (!MovementHelper.canWalkOn(positionsToPlace[0])) { + if (!MovementHelper.canWalkOn(dest.down())) { return COST_INF; } double placeBucketCost = 0.0; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 9da13b2c..d7ff3016 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -34,7 +34,7 @@ public class MovementPillar extends Movement { private int numTicks = 0; public MovementPillar(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{start.up(2)}, new BlockPos[]{start}); + super(start, end, new BlockPos[]{start.up(2)}, start); } @Override @@ -130,7 +130,7 @@ public class MovementPillar extends Movement { boolean vine = fromDown.getBlock() instanceof BlockVine; if (!ladder) { state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), - Utils.getBlockPosCenter(positionsToPlace[0]), + Utils.getBlockPosCenter(positionToPlace), new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)), true)); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 54e61359..6d09dee8 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -45,7 +45,7 @@ public class MovementTraverse extends Movement { private boolean wasTheBridgeBlockAlwaysThere = true; public MovementTraverse(BlockPos from, BlockPos to) { - super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()}); + super(from, to, new BlockPos[]{to.up(), to}, to.down()); int i = 0; if (!to.north().equals(from)) @@ -73,8 +73,8 @@ public class MovementTraverse extends Movement { protected double calculateCost(CalculationContext context) { IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]); - IBlockState destOn = BlockStateInterface.get(positionsToPlace[0]); - if (MovementHelper.canWalkOn(positionsToPlace[0], destOn)) {//this is a walk, not a bridge + IBlockState destOn = BlockStateInterface.get(positionToPlace); + if (MovementHelper.canWalkOn(positionToPlace, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) { WC = WALK_ONE_IN_WATER_COST; @@ -105,7 +105,7 @@ public class MovementTraverse extends Movement { if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) { return COST_INF; } - if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionsToPlace[0], destOn)) { + if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionToPlace, destOn)) { boolean throughWater = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock()); if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) { return COST_INF; @@ -179,7 +179,7 @@ public class MovementTraverse extends Movement { } } - boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionsToPlace[0]) || ladder; + boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder; BlockPos whereAmI = playerFeet(); if (whereAmI.getY() != dest.getY() && !ladder) { displayChatMessageRaw("Wrong Y coordinate"); @@ -220,7 +220,7 @@ public class MovementTraverse extends Movement { EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against1) && Minecraft.getMinecraft().player.isSneaking()) { - if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionsToPlace[0])) { + if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) { return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); } else { // Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug); From ff83b42132d107b7721b7e505bb3edb4a15dface Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 13:58:36 -0700 Subject: [PATCH 040/165] fix heightMap bug --- src/main/java/baritone/chunk/ChunkPacker.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 6bac5529..3cd0b415 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -22,8 +22,6 @@ import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.block.Block; import net.minecraft.block.BlockAir; -import net.minecraft.block.BlockDoublePlant; -import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -69,17 +67,17 @@ public final class ChunkPacker implements Helper { //System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z); String[] blockNames = new String[256]; for (int z = 0; z < 16; z++) { + outerLoop: for (int x = 0; x < 16; x++) { - int height = chunk.getHeightValue(x, z); - IBlockState blockState = chunk.getBlockState(x, height, z); - for (int y = height; y > 0; y--) { - blockState = chunk.getBlockState(x, y, z); - if (getPathingBlockType(blockState.getBlock()) != PathingBlockType.AIR) { - break; + for (int y = 255; y >= 0; y--) { + int index = CachedChunk.getPositionIndex(x, y, z); + if (!bitSet.get(index) && !bitSet.get(index + 1)) { + String name = blockToString(chunk.getBlockState(x, y, z).getBlock()); + blockNames[z << 4 | x] = name; + continue outerLoop; } } - String name = blockToString(blockState.getBlock()); - blockNames[z << 4 | x] = name; + blockNames[z << 4 | x] = "air"; } } CachedChunk cached = new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks); @@ -116,7 +114,7 @@ public final class ChunkPacker implements Helper { // however, this failed in the nether when you were near a nether fortress // because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape // this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors - if (block instanceof BlockAir || block instanceof BlockTallGrass || block instanceof BlockDoublePlant) { + if (block instanceof BlockAir) { return PathingBlockType.AIR; } From 804cad27763e87adf92eff905cd5e8652a6b803e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:00:02 -0700 Subject: [PATCH 041/165] sanik --- src/main/java/baritone/chunk/CachedChunk.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index 520bcbea..2c8288b3 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -183,7 +183,7 @@ public final class CachedChunk implements IBlockTypeAccess { * @return The bit index */ public static int getPositionIndex(int x, int y, int z) { - return (x + (z << 4) + (y << 8)) * 2; + return (x + (z << 4) + (y << 8)) << 1; } /** From 4e531ec5786f0f41a9114d56cfe10ba0298b64dc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:00:40 -0700 Subject: [PATCH 042/165] SANIK --- src/main/java/baritone/chunk/CachedChunk.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index 2c8288b3..9449d20b 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -183,7 +183,7 @@ public final class CachedChunk implements IBlockTypeAccess { * @return The bit index */ public static int getPositionIndex(int x, int y, int z) { - return (x + (z << 4) + (y << 8)) << 1; + return (x << 1) + (z << 5) + (y << 9); } /** From 801f942c30ddfe7a4e44f45d628ce396299ec083 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:02:57 -0700 Subject: [PATCH 043/165] S A N I K --- src/main/java/baritone/chunk/CachedChunk.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index 9449d20b..50e543a8 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -139,7 +139,8 @@ public final class CachedChunk implements IBlockTypeAccess { int index = z << 4 | x; heightMap[index] = 0; for (int y = 256; y >= 0; y--) { - if (getType(x, y, z) != PathingBlockType.AIR) { + int i = getPositionIndex(x, y, z); + if (data.get(i) || data.get(i + 1)) { heightMap[index] = y; break; } From 324c3a27058e2468acd8d76cac978cacb5a87c3d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:04:51 -0700 Subject: [PATCH 044/165] S A N I K --- src/main/java/baritone/chunk/CachedChunk.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index 50e543a8..eb1882f8 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -184,7 +184,7 @@ public final class CachedChunk implements IBlockTypeAccess { * @return The bit index */ public static int getPositionIndex(int x, int y, int z) { - return (x << 1) + (z << 5) + (y << 9); + return (x << 1) | (z << 5) | (y << 9); } /** From a33b515871123400da95f9551b46e5e714751528 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:15:20 -0700 Subject: [PATCH 045/165] fixed chunk packing bug --- src/main/java/baritone/chunk/CachedChunk.java | 5 ++++- src/main/java/baritone/chunk/ChunkPacker.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedChunk.java b/src/main/java/baritone/chunk/CachedChunk.java index eb1882f8..418a015e 100644 --- a/src/main/java/baritone/chunk/CachedChunk.java +++ b/src/main/java/baritone/chunk/CachedChunk.java @@ -121,7 +121,10 @@ public final class CachedChunk implements IBlockTypeAccess { if (heightMap[internalPos] == y) { // we have this exact block, it's a surface block IBlockState state = ChunkPacker.stringToBlock(overview[internalPos]).getDefaultState(); - //System.out.println("Saying that " + x + "," + y + "," + z + " is " + state); + /*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state); + if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) { + throw new IllegalStateException("failed " + Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16)); + }*/ return state; } PathingBlockType type = getType(x, y, z); diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 3cd0b415..e020e67b 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -71,7 +71,7 @@ public final class ChunkPacker implements Helper { for (int x = 0; x < 16; x++) { for (int y = 255; y >= 0; y--) { int index = CachedChunk.getPositionIndex(x, y, z); - if (!bitSet.get(index) && !bitSet.get(index + 1)) { + if (bitSet.get(index) || bitSet.get(index + 1)) { String name = blockToString(chunk.getBlockState(x, y, z).getBlock()); blockNames[z << 4 | x] = name; continue outerLoop; From d433cbb90bcbdf58c301c262f36aff67964eccc4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:56:21 -0700 Subject: [PATCH 046/165] no more against array creation --- .../baritone/pathing/movement/Movement.java | 3 ++ .../movement/movements/MovementAscend.java | 34 +++++++------------ .../movement/movements/MovementTraverse.java | 32 +++++++---------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index ce730b00..44c9d5a3 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -28,6 +28,7 @@ import baritone.utils.*; import net.minecraft.block.Block; import net.minecraft.block.BlockLadder; import net.minecraft.block.BlockVine; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -40,6 +41,8 @@ import static baritone.utils.InputOverrideHandler.Input; public abstract class Movement implements Helper, MovementHelper { + protected static final EnumFacing[] HORIZONTALS = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST}; + private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING); protected final BlockPos src; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index dc4476f3..5afa8243 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -39,29 +39,10 @@ import java.util.Objects; public class MovementAscend extends Movement { - private BlockPos[] against = new BlockPos[3]; private int ticksWithoutPlacement = 0; public MovementAscend(BlockPos src, BlockPos dest) { super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); - - BlockPos placementLocation = positionToPlace; // dest.down() - int i = 0; - if (!placementLocation.north().equals(src)) - against[i++] = placementLocation.north(); - - if (!placementLocation.south().equals(src)) - against[i++] = placementLocation.south(); - - if (!placementLocation.east().equals(src)) - against[i++] = placementLocation.east(); - - if (!placementLocation.west().equals(src)) - against[i] = placementLocation.west(); - - // TODO: add ability to place against .down() as well as the cardinal directions - // useful for when you are starting a staircase without anything to place against - // Counterpoint to the above TODO ^ you should move then pillar instead of ascend } @Override @@ -80,7 +61,14 @@ public class MovementAscend extends Movement { if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) { return COST_INF; } - for (BlockPos against1 : against) { + // TODO: add ability to place against .down() as well as the cardinal directions + // useful for when you are starting a staircase without anything to place against + // Counterpoint to the above TODO ^ you should move then pillar instead of ascend + for (int i = 0; i < 4; i++) { + BlockPos against1 = positionToPlace.offset(HORIZONTALS[i]); + if (against1.equals(src)) { + continue; + } if (BlockStateInterface.get(against1).isBlockNormalCube()) { return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } @@ -136,7 +124,11 @@ public class MovementAscend extends Movement { } if (!MovementHelper.canWalkOn(positionToPlace)) { - for (BlockPos anAgainst : against) { + for (int i = 0; i < 4; i++) { + BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]); + if (anAgainst.equals(src)) { + continue; + } if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) { if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block return state.setStatus(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 6d09dee8..7a45c8bc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -37,8 +37,6 @@ import java.util.Objects; public class MovementTraverse extends Movement { - private BlockPos[] against = new BlockPos[3]; - /** * Did we have to place a bridge block or was it always there */ @@ -46,21 +44,6 @@ public class MovementTraverse extends Movement { public MovementTraverse(BlockPos from, BlockPos to) { super(from, to, new BlockPos[]{to.up(), to}, to.down()); - int i = 0; - - if (!to.north().equals(from)) - against[i++] = to.north().down(); - - if (!to.south().equals(from)) - against[i++] = to.south().down(); - - if (!to.east().equals(from)) - against[i++] = to.east().down(); - - if (!to.west().equals(from)) - against[i] = to.west().down(); - - //note: do NOT add ability to place against .down().down() } @Override @@ -114,7 +97,13 @@ public class MovementTraverse extends Movement { return COST_INF; } double WC = throughWater ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST; - for (BlockPos against1 : against) { + for (int i = 0; i < 4; i++) { + BlockPos against1 = dest.offset(HORIZONTALS[i]); + if (against1.equals(src)) { + continue; + } + against1 = against1.down(); + // 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 if (BlockStateInterface.get(against1).isBlockNormalCube()) { return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } @@ -206,7 +195,12 @@ public class MovementTraverse extends Movement { return state; } else { wasTheBridgeBlockAlwaysThere = false; - for (BlockPos against1 : against) { + for (int i = 0; i < 4; i++) { + BlockPos against1 = dest.offset(HORIZONTALS[i]); + if (against1.equals(src)) { + continue; + } + against1 = against1.down(); if (BlockStateInterface.get(against1).isBlockNormalCube()) { if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block displayChatMessageRaw("bb pls get me some blocks. dirt or cobble"); From a3e5714e91fb53143bdbebcf43db67115304d1dd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 15:01:24 -0700 Subject: [PATCH 047/165] collect canPlaceAgainst into one place --- src/main/java/baritone/pathing/movement/MovementHelper.java | 6 ++++++ .../baritone/pathing/movement/movements/MovementAscend.java | 4 ++-- .../pathing/movement/movements/MovementTraverse.java | 5 ++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 72fc9f5b..142f5d98 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -224,6 +224,12 @@ public interface MovementHelper extends ActionCosts, Helper { 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 + return state.isBlockNormalCube(); + } + static double getMiningDurationTicks(CalculationContext context, BlockPos position, boolean includeFalling) { IBlockState state = BlockStateInterface.get(position); return getMiningDurationTicks(context, position, state, includeFalling); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 5afa8243..af29a887 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 (against1.equals(src)) { continue; } - if (BlockStateInterface.get(against1).isBlockNormalCube()) { + if (MovementHelper.canPlaceAgainst(against1)) { return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } } @@ -129,7 +129,7 @@ public class MovementAscend extends Movement { if (anAgainst.equals(src)) { continue; } - if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) { + if (MovementHelper.canPlaceAgainst(anAgainst)) { if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block return state.setStatus(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 7a45c8bc..b1eac4e9 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -103,8 +103,7 @@ public class MovementTraverse extends Movement { continue; } against1 = against1.down(); - // 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 - if (BlockStateInterface.get(against1).isBlockNormalCube()) { + if (MovementHelper.canPlaceAgainst(against1)) { return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } } @@ -201,7 +200,7 @@ public class MovementTraverse extends Movement { continue; } against1 = against1.down(); - if (BlockStateInterface.get(against1).isBlockNormalCube()) { + 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"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); From f99abd6170b564b105020e93dddd11b317638285 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 15:24:43 -0700 Subject: [PATCH 048/165] fix world event post not firing for exit --- .../baritone/api/event/GameEventHandler.java | 3 +-- .../baritone/launch/mixins/MixinMinecraft.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 22da9430..88cd0560 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -35,10 +35,10 @@ package baritone.api.event; import baritone.Baritone; -import baritone.chunk.WorldProvider; import baritone.api.event.events.*; import baritone.api.event.events.type.EventState; import baritone.api.event.listener.IGameEventListener; +import baritone.chunk.WorldProvider; import baritone.utils.Helper; import baritone.utils.InputOverrideHandler; import baritone.utils.interfaces.Toggleable; @@ -135,7 +135,6 @@ public final class GameEventHandler implements IGameEventListener, Helper { switch (event.getState()) { case PRE: - cache.closeWorld(); break; case POST: cache.closeWorld(); diff --git a/src/main/java/baritone/launch/mixins/MixinMinecraft.java b/src/main/java/baritone/launch/mixins/MixinMinecraft.java index 0f0052bb..49c587ba 100755 --- a/src/main/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/main/java/baritone/launch/mixins/MixinMinecraft.java @@ -18,11 +18,11 @@ package baritone.launch.mixins; import baritone.Baritone; -import baritone.behavior.impl.PathingBehavior; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.TickEvent; import baritone.api.event.events.WorldEvent; import baritone.api.event.events.type.EventState; +import baritone.behavior.impl.PathingBehavior; import baritone.utils.ExampleBaritoneControl; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -48,9 +48,12 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(Minecraft.class) public class MixinMinecraft { - @Shadow private int leftClickCounter; - @Shadow public EntityPlayerSP player; - @Shadow public WorldClient world; + @Shadow + private int leftClickCounter; + @Shadow + public EntityPlayerSP player; + @Shadow + public WorldClient world; @Inject( method = "init", @@ -108,8 +111,9 @@ public class MixinMinecraft { ) private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { // If we're unloading the world but one doesn't exist, ignore it - if (this.world == null && world == null) + if (this.world == null && world == null) { return; + } Baritone.INSTANCE.getGameEventHandler().onWorldEvent( new WorldEvent( @@ -124,9 +128,7 @@ public class MixinMinecraft { at = @At("RETURN") ) private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { - // If we're unloading the world but one doesn't exist, ignore it - if (this.world == null && world == null) - return; + // still fire event for both null, as that means we've just finished exiting a world Baritone.INSTANCE.getGameEventHandler().onWorldEvent( new WorldEvent( From 340b1558e40f79bc9590fd095e727582575814b2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 15:53:29 -0700 Subject: [PATCH 049/165] debug cosmetic improvements --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 2dca7bb8..eca57ea5 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -183,13 +183,14 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared + System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i]); 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)"); System.out.println("But I'm going to do it anyway, because yolo"); } - System.out.println("Path goes for " + dist + " blocks"); + System.out.println("Path goes for " + Math.sqrt(dist) + " blocks"); currentlyRunning = null; return Optional.of(new Path(startNode, bestSoFar[i], numNodes)); } From 23cbef102dae714a17c5c30f31a679d99a92e9f4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 16:15:24 -0700 Subject: [PATCH 050/165] more debug info --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 6 +++++- .../baritone/pathing/calc/openset/BinaryHeapOpenSet.java | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index eca57ea5..383c3b90 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -75,6 +75,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); long lastPrintout = 0; int numNodes = 0; + int numMovementsConsidered = 0; int numEmptyChunk = 0; boolean favoring = favoredPositions.isPresent(); int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior @@ -125,6 +126,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { double actionCost = movementToGetToNeighbor.getCost(calcContext); //long costEnd = System.nanoTime(); //System.out.println(movementToGetToNeighbor.getClass() + "" + (costEnd - costStart)); + numMovementsConsidered++; if (actionCost >= ActionCosts.COST_INF) { continue; } @@ -173,6 +175,9 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { currentlyRunning = null; return Optional.empty(); } + System.out.println(numMovementsConsidered + " movements considered"); + System.out.println("Open set size: " + ((BinaryHeapOpenSet) openSet).size()); + System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); double bestDist = 0; for (int i = 0; i < bestSoFar.length; i++) { if (bestSoFar[i] == null) { @@ -183,7 +188,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i]); if (COEFFICIENTS[i] >= 3) { System.out.println("Warning: cost coefficient is greater than three! Probably means that"); diff --git a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java index 80c3965a..b81145f3 100644 --- a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java @@ -52,6 +52,10 @@ public class BinaryHeapOpenSet implements IOpenSet { this.array = new PathNode[size]; } + public int size() { + return size; + } + @Override public final void insert(PathNode value) { if (size >= array.length - 1) { From e553ee93b82a8669f3cd975e2dd0a8d8667f3541 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 28 Aug 2018 21:10:41 -0700 Subject: [PATCH 051/165] 20% improvement to cached chunk check performance --- .../utils/pathing/PathingBlockType.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/utils/pathing/PathingBlockType.java b/src/main/java/baritone/utils/pathing/PathingBlockType.java index a05b0b2b..61dbf2fc 100644 --- a/src/main/java/baritone/utils/pathing/PathingBlockType.java +++ b/src/main/java/baritone/utils/pathing/PathingBlockType.java @@ -23,7 +23,7 @@ package baritone.utils.pathing; */ public enum PathingBlockType { - AIR (0b00), + AIR(0b00), WATER(0b01), AVOID(0b10), SOLID(0b11); @@ -31,7 +31,7 @@ public enum PathingBlockType { private final boolean[] bits; PathingBlockType(int bits) { - this.bits = new boolean[] { + this.bits = new boolean[]{ (bits & 0b10) != 0, (bits & 0b01) != 0 }; @@ -42,11 +42,18 @@ public enum PathingBlockType { } public static PathingBlockType fromBits(boolean b1, boolean b2) { - for (PathingBlockType type : values()) - if (type.bits[0] == b1 && type.bits[1] == b2) - return type; - - // This will never happen, but if it does, assume it's just AIR - return PathingBlockType.AIR; + if (b1) { + if (b2) { + return PathingBlockType.SOLID; + } else { + return PathingBlockType.AVOID; + } + } else { + if (b2) { + return PathingBlockType.WATER; + } else { + return PathingBlockType.AIR; + } + } } } From 8d1570a11bbc313a6e45288f33d462d4c5a16738 Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 28 Aug 2018 21:14:50 -0700 Subject: [PATCH 052/165] cherry pick 3x faster cache check --- src/main/java/baritone/chunk/CachedRegion.java | 4 ++++ src/main/java/baritone/chunk/CachedWorld.java | 14 +++++++++++++- .../baritone/pathing/calc/AStarPathFinder.java | 6 ++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 66204d5a..3df6d68a 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -77,6 +77,10 @@ public final class CachedRegion implements IBlockTypeAccess { return null; } + public final boolean isCached(int x, int z) { + return chunks[x >> 4][z >> 4] != null; + } + public final LinkedList getLocationsOf(String block) { LinkedList res = new LinkedList<>(); for (int chunkX = 0; chunkX < 32; chunkX++) { diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index 42b4c13d..703eab0d 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -59,7 +59,8 @@ public final class CachedWorld implements IBlockTypeAccess { if (!Files.exists(directory)) { try { Files.createDirectories(directory); - } catch (IOException ignored) {} + } catch (IOException ignored) { + } } this.directory = directory.toString(); System.out.println("Cached world directory: " + directory); @@ -102,6 +103,17 @@ public final class CachedWorld implements IBlockTypeAccess { return region.getBlock(x & 511, y, z & 511); } + public final boolean isCached(BlockPos pos) { + int x = pos.getX(); + int z = pos.getZ(); + CachedRegion region = getRegion(x >> 9, z >> 9); + if (region == null) { + return false; + } + 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/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 383c3b90..c708d3e9 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -18,6 +18,7 @@ package baritone.pathing.calc; import baritone.Baritone; +import baritone.chunk.CachedWorld; import baritone.chunk.WorldProvider; import baritone.pathing.calc.openset.BinaryHeapOpenSet; import baritone.pathing.calc.openset.IOpenSet; @@ -70,6 +71,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { CalculationContext calcContext = new CalculationContext(); HashSet favored = favoredPositions.orElse(null); currentlyRunning = this; + CachedWorld world = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null); long startTime = System.currentTimeMillis(); boolean slowPath = Baritone.settings().slowPath.get(); long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); @@ -112,8 +114,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); boolean isPositionCached = false; - if (WorldProvider.INSTANCE.getCurrentWorld() != null) { - if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { + if (world != null) { + if (world.isCached(dest)) { isPositionCached = true; } } From fb04ec6ff4e84950d0e8169665a910f3202b4f1f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 11:29:26 -0700 Subject: [PATCH 053/165] chunk check optimization --- .../pathing/calc/AStarPathFinder.java | 19 +++++++++++-------- .../utils/pathing/BetterBlockPos.java | 6 +++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index c708d3e9..8d0a6989 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -113,15 +113,18 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { continue; } BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); - boolean isPositionCached = false; - if (world != null) { - if (world.isCached(dest)) { - isPositionCached = true; + if (dest.x >> 4 != currentNodePos.x >> 4 || dest.z >> 4 != currentNodePos.z >> 4) { + // only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement + boolean isPositionCached = false; + if (world != null) { + if (world.isCached(dest)) { + isPositionCached = true; + } + } + if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { + numEmptyChunk++; + continue; } - } - if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { - numEmptyChunk++; - continue; } //long costStart = System.nanoTime(); // TODO cache cost diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 93512984..8518f668 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -27,9 +27,9 @@ import net.minecraft.util.math.Vec3i; * @author leijurv */ public class BetterBlockPos extends BlockPos { - private final int x; - private final int y; - private final int z; + public final int x; + public final int y; + public final int z; private final int hashCode; public BetterBlockPos(int x, int y, int z) { From 81b0e14c9a56aeeec9073aa6b3cb0c6b098aebd7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 11:53:37 -0700 Subject: [PATCH 054/165] more debug info --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 8d0a6989..1f441bd6 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -101,6 +101,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; + displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes)); } //long constructStart = System.nanoTime(); @@ -193,7 +194,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.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i]); + displayChatMessageRaw("Took " + (System.currentTimeMillis() - 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)"); From 0342136edc207ed1574393c9129af519259347c0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 12:19:21 -0700 Subject: [PATCH 055/165] fix chunk cache check performance, fixes #106 --- .../pathing/calc/AStarPathFinder.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 1f441bd6..0a146ff0 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -32,9 +32,9 @@ import baritone.pathing.path.IPath; import baritone.utils.Helper; import baritone.utils.pathing.BetterBlockPos; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; import java.util.Collection; import java.util.HashSet; @@ -71,11 +71,12 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { CalculationContext calcContext = new CalculationContext(); HashSet favored = favoredPositions.orElse(null); currentlyRunning = this; - CachedWorld world = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null); + CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null); + ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); long startTime = System.currentTimeMillis(); boolean slowPath = Baritone.settings().slowPath.get(); long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); - long lastPrintout = 0; + //long lastPrintout = 0; int numNodes = 0; int numMovementsConsidered = 0; int numEmptyChunk = 0; @@ -95,10 +96,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { mostRecentConsidered = currentNode; BetterBlockPos currentNodePos = currentNode.pos; numNodes++; - if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second + /*if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second System.out.println("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far"); lastPrintout = System.currentTimeMillis(); - } + }*/ if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered"); @@ -114,18 +115,17 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { continue; } BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); - if (dest.x >> 4 != currentNodePos.x >> 4 || dest.z >> 4 != currentNodePos.z >> 4) { + int chunkX = currentNodePos.x >> 4; + int chunkZ = currentNodePos.z >> 4; + if (dest.x >> 4 != chunkX || dest.z >> 4 != chunkZ) { // only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement - boolean isPositionCached = false; - if (world != null) { - if (world.isCached(dest)) { - isPositionCached = true; + if (chunkProvider.getLoadedChunk(chunkX, chunkZ) == null) { + // see issue #106 + if (cachedWorld == null || !cachedWorld.isCached(dest)) { + numEmptyChunk++; + continue; } } - if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { - numEmptyChunk++; - continue; - } } //long costStart = System.nanoTime(); // TODO cache cost From 5c5507cc9e032664480558b6b324b1862ef06997 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 12:25:03 -0700 Subject: [PATCH 056/165] readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5260cdc1..2748cb4f 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,12 @@ Baritone.settings().pathTimeoutMS.value = 2000L; PathingBehavior.INSTANCE.setGoal(new GoalXZ(10000, 20000)); PathingBehavior.INSTANCE.path(); -``` \ No newline at end of file +``` + +# Can I use Baritone as a library in my hacked client? + +Sure! + +# How is it so fast? + +Magic \ No newline at end of file From cebdd76ca7fbd86b82f40852b207b2c6883f1b2d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 13:21:54 -0700 Subject: [PATCH 057/165] node map performance, fixes #107 --- .../pathing/calc/AbstractNodeCostSearch.java | 16 +++++++++++----- .../baritone/utils/pathing/BetterBlockPos.java | 12 ++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 18b8050f..b8f13f1e 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -20,10 +20,9 @@ package baritone.pathing.calc; import baritone.pathing.goals.Goal; import baritone.pathing.path.IPath; import baritone.utils.pathing.BetterBlockPos; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.util.math.BlockPos; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; /** @@ -42,7 +41,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { protected final Goal goal; - protected final Map map; + private final Long2ObjectOpenHashMap map; // see issue #107 protected PathNode startNode; @@ -69,7 +68,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { AbstractNodeCostSearch(BlockPos start, Goal goal) { this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ()); this.goal = goal; - this.map = new HashMap<>(); + this.map = new Long2ObjectOpenHashMap<>(); } public void cancel() { @@ -112,7 +111,14 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * @return The associated node */ protected PathNode getNodeAtPosition(BetterBlockPos pos) { - return map.computeIfAbsent(pos, p -> new PathNode(p, goal)); + // see issue #107 + long hashCode = pos.hashCode; + PathNode node = map.get(hashCode); + if (node == null) { + node = new PathNode(pos, goal); + map.put(hashCode, node); + } + return node; } @Override diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 8518f668..6e4fc599 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -30,7 +30,7 @@ public class BetterBlockPos extends BlockPos { public final int x; public final int y; public final int z; - private final int hashCode; + public final long hashCode; public BetterBlockPos(int x, int y, int z) { super(x, y, z); @@ -48,10 +48,10 @@ public class BetterBlockPos extends BlockPos { * * That's why we grab out the X, Y, Z and calculate our own hashcode */ - int hash = 3241; - hash = 3457689 * hash + x; - hash = 8734625 * hash + y; - hash = 2873465 * hash + z; + long hash = 3241; + hash = 3457689L * hash + x; + hash = 8734625L * hash + y; + hash = 2873465L * hash + z; this.hashCode = hash; } @@ -61,7 +61,7 @@ public class BetterBlockPos extends BlockPos { @Override public final int hashCode() { - return hashCode; + return (int) hashCode; } @Override From 95cda79ef149bd488f6fa464276a4c4b0ff7b10c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 15:35:41 -0700 Subject: [PATCH 058/165] small open set change --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 5 ++--- .../baritone/pathing/calc/openset/BinaryHeapOpenSet.java | 2 +- .../baritone/pathing/calc/openset/LinkedListOpenSet.java | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 0a146ff0..f3e70673 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -21,7 +21,6 @@ import baritone.Baritone; import baritone.chunk.CachedWorld; import baritone.chunk.WorldProvider; import baritone.pathing.calc.openset.BinaryHeapOpenSet; -import baritone.pathing.calc.openset.IOpenSet; import baritone.pathing.goals.Goal; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.CalculationContext; @@ -60,7 +59,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { startNode = getNodeAtPosition(start); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; - IOpenSet openSet = new BinaryHeapOpenSet(); + BinaryHeapOpenSet openSet = new BinaryHeapOpenSet(); openSet.insert(startNode); startNode.isOpen = true; bestSoFar = new PathNode[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i]) @@ -182,7 +181,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { return Optional.empty(); } System.out.println(numMovementsConsidered + " movements considered"); - System.out.println("Open set size: " + ((BinaryHeapOpenSet) openSet).size()); + System.out.println("Open set size: " + openSet.size()); System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); double bestDist = 0; for (int i = 0; i < bestSoFar.length; i++) { diff --git a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java index b81145f3..da2357d9 100644 --- a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java @@ -26,7 +26,7 @@ import java.util.Arrays; * * @author leijurv */ -public class BinaryHeapOpenSet implements IOpenSet { +public final class BinaryHeapOpenSet implements IOpenSet { /** * The initial capacity of the heap (2^10) diff --git a/src/main/java/baritone/pathing/calc/openset/LinkedListOpenSet.java b/src/main/java/baritone/pathing/calc/openset/LinkedListOpenSet.java index 49ee23d7..8ff5a674 100644 --- a/src/main/java/baritone/pathing/calc/openset/LinkedListOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/LinkedListOpenSet.java @@ -22,10 +22,11 @@ import baritone.pathing.calc.PathNode; /** * A linked list implementation of an open set. This is the original implementation from MineBot. * It has incredibly fast insert performance, at the cost of O(n) removeLowest. + * It sucks. BinaryHeapOpenSet results in more than 10x more nodes considered in 4 seconds. * * @author leijurv */ -public class LinkedListOpenSet implements IOpenSet { +class LinkedListOpenSet implements IOpenSet { private Node first = null; @Override From be303f2e57cf4892bc50da2c4c2484509609c81e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 29 Aug 2018 16:13:14 -0700 Subject: [PATCH 059/165] crucial performance optimization --- .../pathing/calc/openset/BinaryHeapOpenSet.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java index da2357d9..47d370c6 100644 --- a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java @@ -108,14 +108,13 @@ public final class BinaryHeapOpenSet implements IOpenSet { int smallerChild = 2; double cost = val.combinedCost; do { - int right = smallerChild + 1; PathNode smallerChildNode = array[smallerChild]; double smallerChildCost = smallerChildNode.combinedCost; - if (right <= size) { - PathNode rightChildNode = array[right]; + if (smallerChild < size) { + PathNode rightChildNode = array[smallerChild + 1]; double rightChildCost = rightChildNode.combinedCost; if (smallerChildCost > rightChildCost) { - smallerChild = right; + smallerChild++; smallerChildCost = rightChildCost; smallerChildNode = rightChildNode; } @@ -128,8 +127,7 @@ public final class BinaryHeapOpenSet implements IOpenSet { val.heapPosition = smallerChild; smallerChildNode.heapPosition = index; index = smallerChild; - smallerChild = index << 1; - } while (smallerChild <= size); + } while ((smallerChild <<= 1) <= size); return result; } } From b073d591fb3da39a5b40d39b021f33a9ef036919 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:22:57 -0500 Subject: [PATCH 060/165] Fix non-monotonic elapsed time checks, fixes #108 --- .../baritone/behavior/impl/MemoryBehavior.java | 4 ++-- src/main/java/baritone/chunk/CachedRegion.java | 4 ++-- src/main/java/baritone/chunk/CachedWorld.java | 8 ++++---- src/main/java/baritone/chunk/ChunkPacker.java | 4 ++-- .../baritone/pathing/calc/AStarPathFinder.java | 14 +++++++------- .../java/baritone/pathing/path/PathExecutor.java | 4 ++-- src/main/java/baritone/utils/PathRenderer.java | 2 +- .../pathing/calc/openset/OpenSetsTest.java | 8 ++++---- .../utils/pathing/BetterBlockPosTest.java | 16 ++++++++-------- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MemoryBehavior.java b/src/main/java/baritone/behavior/impl/MemoryBehavior.java index 2edb9ec3..8f43a8e8 100644 --- a/src/main/java/baritone/behavior/impl/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/impl/MemoryBehavior.java @@ -59,7 +59,7 @@ public class MemoryBehavior extends Behavior { TileEntityLockable lockable = (TileEntityLockable) tileEntity; int size = lockable.getSizeInventory(); - this.futureInventories.add(new FutureInventory(System.currentTimeMillis(), size, lockable.getGuiID(), tileEntity.getPos())); + this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), tileEntity.getPos())); } } @@ -81,7 +81,7 @@ public class MemoryBehavior extends Behavior { SPacketOpenWindow packet = event.cast(); // Remove any entries that were created over a second ago, this should make up for INSANE latency - this.futureInventories.removeIf(i -> System.currentTimeMillis() - i.time > 1000); + this.futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000); this.futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 3df6d68a..e15164e4 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -183,7 +183,7 @@ public final class CachedRegion implements IBlockTypeAccess { return; System.out.println("Loading region " + x + "," + z + " from disk " + path); - long start = System.currentTimeMillis(); + long start = System.nanoTime() / 1000000L; try ( FileInputStream fileIn = new FileInputStream(regionFile.toFile()); @@ -266,7 +266,7 @@ public final class CachedRegion implements IBlockTypeAccess { } } hasUnsavedChanges = false; - long end = System.currentTimeMillis(); + long end = System.nanoTime() / 1000000L; System.out.println("Loaded region successfully in " + (end - start) + "ms"); } catch (IOException ex) { ex.printStackTrace(); diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index 703eab0d..f3e1ca1f 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -153,22 +153,22 @@ public final class CachedWorld implements IBlockTypeAccess { System.out.println("Not saving to disk; chunk caching is disabled."); return; } - long start = System.currentTimeMillis(); + long start = System.nanoTime() / 1000000L; this.cachedRegions.values().parallelStream().forEach(region -> { if (region != null) region.save(this.directory); }); - long now = System.currentTimeMillis(); + long now = System.nanoTime() / 1000000L; System.out.println("World save took " + (now - start) + "ms"); } public final void reloadAllFromDisk() { - long start = System.currentTimeMillis(); + long start = System.nanoTime() / 1000000L; this.cachedRegions.values().forEach(region -> { if (region != null) region.load(this.directory); }); - long now = System.currentTimeMillis(); + long now = System.nanoTime() / 1000000L; System.out.println("World load took " + (now - start) + "ms"); } diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index e020e67b..90cdf02a 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -39,7 +39,7 @@ public final class ChunkPacker implements Helper { private ChunkPacker() {} public static CachedChunk pack(Chunk chunk) { - long start = System.currentTimeMillis(); + long start = System.nanoTime() / 1000000L; Map> specialBlocks = new HashMap<>(); BitSet bitSet = new BitSet(CachedChunk.SIZE); @@ -63,7 +63,7 @@ public final class ChunkPacker implements Helper { e.printStackTrace(); } //System.out.println("Packed special blocks: " + specialBlocks); - long end = System.currentTimeMillis(); + long end = System.nanoTime() / 1000000L; //System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z); String[] blockNames = new String[256]; for (int z = 0; z < 16; z++) { diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index f3e70673..e5ebe184 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -72,7 +72,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(); - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); //long lastPrintout = 0; @@ -83,7 +83,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); - while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) { + while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) { if (slowPath) { try { Thread.sleep(Baritone.settings().slowPathTimeDelayMS.get()); @@ -95,13 +95,13 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { mostRecentConsidered = currentNode; BetterBlockPos currentNodePos = currentNode.pos; numNodes++; - /*if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second + /*if ((lastPrintout + 1000) - System.nanoTime() / 1000000L < 0) {//print once a second System.out.println("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far"); - lastPrintout = System.currentTimeMillis(); + lastPrintout = System.nanoTime() / 1000000L; }*/ if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; - displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered"); + displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes)); } //long constructStart = System.nanoTime(); @@ -182,7 +182,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } System.out.println(numMovementsConsidered + " movements considered"); System.out.println("Open set size: " + openSet.size()); - System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second"); + System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second"); double bestDist = 0; for (int i = 0; i < bestSoFar.length; i++) { if (bestSoFar[i] == null) { @@ -193,7 +193,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.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); + displayChatMessageRaw("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)"); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 88c9df26..1e977b92 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -163,7 +163,7 @@ public class PathExecutor implements Helper { } } }*/ - long start = System.currentTimeMillis(); + long start = System.nanoTime() / 1000000L; for (int i = pathPosition - 10; i < pathPosition + 10; i++) { if (i >= 0 && i < path.movements().size()) { Movement m = path.movements().get(i); @@ -198,7 +198,7 @@ public class PathExecutor implements Helper { toWalkInto = newWalkInto; recalcBP = false; } - long end = System.currentTimeMillis(); + long end = System.nanoTime() / 1000000L; if (end - start > 0) { //displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms"); } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 04a95f1e..1ec5373b 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -188,7 +188,7 @@ public final class PathRenderer implements Helper { maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = Math.sin((System.currentTimeMillis() % 2000L) / 2000F * Math.PI * 2); + double y = Math.sin(((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2); y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; diff --git a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java index afdebfdb..6812f90d 100644 --- a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java +++ b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java @@ -42,7 +42,7 @@ public class OpenSetsTest { public void removeAndTest(int amount, IOpenSet[] test, Optional> mustContain) { double[][] results = new double[test.length][amount]; for (int i = 0; i < test.length; i++) { - long before = System.currentTimeMillis(); + long before = System.nanoTime() / 1000000L; for (int j = 0; j < amount; j++) { PathNode pn = test[i].removeLowest(); if (mustContain.isPresent() && !mustContain.get().contains(pn)) { @@ -50,7 +50,7 @@ public class OpenSetsTest { } results[i][j] = pn.combinedCost; } - System.out.println(test[i].getClass() + " " + (System.currentTimeMillis() - before)); + System.out.println(test[i].getClass() + " " + (System.nanoTime() / 1000000L - before)); } for (int j = 0; j < amount; j++) { for (int i = 1; i < test.length; i++) { @@ -104,10 +104,10 @@ public class OpenSetsTest { System.out.println("Insertion"); for (IOpenSet set : test) { - long before = System.currentTimeMillis(); + long before = System.nanoTime() / 1000000L; for (int i = 0; i < size; i++) set.insert(toInsert[i]); - System.out.println(set.getClass() + " " + (System.currentTimeMillis() - before)); + System.out.println(set.getClass() + " " + (System.nanoTime() / 1000000L - before)); //all three take either 0 or 1ms to insert up to 10,000 nodes //linkedlist takes 0ms most often (because there's no array resizing or allocation there, just pointer shuffling) } diff --git a/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java b/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java index 381060f4..758812f2 100644 --- a/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java +++ b/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java @@ -44,21 +44,21 @@ public class BetterBlockPosTest { } catch (InterruptedException e) { e.printStackTrace(); } - long before1 = System.currentTimeMillis(); + long before1 = System.nanoTime() / 1000000L; for (int i = 0; i < 1000000; i++) { pos.up(); } - long after1 = System.currentTimeMillis(); + long after1 = System.nanoTime() / 1000000L; try { Thread.sleep(1000); // give GC some time } catch (InterruptedException e) { e.printStackTrace(); } - long before2 = System.currentTimeMillis(); + long before2 = System.nanoTime() / 1000000L; for (int i = 0; i < 1000000; i++) { pos2.up(); } - long after2 = System.currentTimeMillis(); + long after2 = System.nanoTime() / 1000000L; System.out.println((after1 - before1) + " " + (after2 - before2)); } @@ -70,7 +70,7 @@ public class BetterBlockPosTest { } catch (InterruptedException e) { e.printStackTrace(); } - long before1 = System.currentTimeMillis(); + long before1 = System.nanoTime() / 1000000L; for (int i = 0; i < 1000000; i++) { pos.up(0); pos.up(1); @@ -78,13 +78,13 @@ public class BetterBlockPosTest { pos.up(3); pos.up(4); } - long after1 = System.currentTimeMillis(); + long after1 = System.nanoTime() / 1000000L; try { Thread.sleep(1000); // give GC some time } catch (InterruptedException e) { e.printStackTrace(); } - long before2 = System.currentTimeMillis(); + long before2 = System.nanoTime() / 1000000L; for (int i = 0; i < 1000000; i++) { pos2.up(0); pos2.up(1); @@ -92,7 +92,7 @@ public class BetterBlockPosTest { pos2.up(3); pos2.up(4); } - long after2 = System.currentTimeMillis(); + long after2 = System.nanoTime() / 1000000L; System.out.println((after1 - before1) + " " + (after2 - before2)); } } \ No newline at end of file From 4b41c6b1d702470d7584d958d712a09cf6e110c3 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:32:16 -0500 Subject: [PATCH 061/165] Replace anonymous thread creation with runnable constructor --- src/main/java/baritone/chunk/CachedWorld.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index f3e1ca1f..56d8ef38 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -67,22 +67,20 @@ public final class CachedWorld implements IBlockTypeAccess { // Insert an invalid region element cachedRegions.put(0, null); new PackerThread().start(); - new Thread() { - public void run() { - try { - Thread.sleep(30000); - while (true) { - // since a region only saves if it's been modified since its last save - // saving every 10 minutes means that once it's time to exit - // we'll only have a couple regions to save - save(); - Thread.sleep(600000); - } - } catch (InterruptedException e) { - e.printStackTrace(); + new Thread(() -> { + try { + Thread.sleep(30000); + while (true) { + // since a region only saves if it's been modified since its last save + // saving every 10 minutes means that once it's time to exit + // we'll only have a couple regions to save + save(); + Thread.sleep(600000); } + } catch (InterruptedException e) { + e.printStackTrace(); } - }.start(); + }).start(); } public final void queueForPacking(Chunk chunk) { From 336b323697ebc523855106f9d033b5ce2c50ef12 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:45:16 -0500 Subject: [PATCH 062/165] Replace Math.X functions with MathHelper.X functions, fixes #111 --- src/main/java/baritone/pathing/goals/GoalXZ.java | 7 ++++--- src/main/java/baritone/utils/PathRenderer.java | 3 ++- src/main/java/baritone/utils/Utils.java | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/pathing/goals/GoalXZ.java b/src/main/java/baritone/pathing/goals/GoalXZ.java index de48da83..8abfb221 100644 --- a/src/main/java/baritone/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/pathing/goals/GoalXZ.java @@ -20,6 +20,7 @@ package baritone.pathing.goals; import baritone.Baritone; import baritone.utils.Utils; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; /** @@ -88,9 +89,9 @@ public class GoalXZ implements Goal { } public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) { - double theta = Utils.degToRad(yaw); - double x = origin.x - Math.sin(theta) * distance; - double z = origin.z + Math.cos(theta) * distance; + float theta = (float) Utils.degToRad(yaw); + double x = origin.x - MathHelper.sin(theta) * distance; + double z = origin.z + MathHelper.cos(theta) * distance; return new GoalXZ((int) x, (int) z); } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 1ec5373b..6fd3466e 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -34,6 +34,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import java.awt.*; import java.util.Collection; @@ -188,7 +189,7 @@ public final class PathRenderer implements Helper { maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = Math.sin(((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2); + double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2)); y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; diff --git a/src/main/java/baritone/utils/Utils.java b/src/main/java/baritone/utils/Utils.java index eea18643..9f1ac3b3 100755 --- a/src/main/java/baritone/utils/Utils.java +++ b/src/main/java/baritone/utils/Utils.java @@ -54,9 +54,9 @@ public final class Utils { */ public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) { double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z}; - double yaw = Math.atan2(delta[0], -delta[2]); + double yaw = MathHelper.atan2(delta[0], -delta[2]); double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]); - double pitch = Math.atan2(delta[1], dist); + double pitch = MathHelper.atan2(delta[1], dist); return new Rotation( (float) radToDeg(yaw), (float) radToDeg(pitch) From 532024248f12a7fc8b6fb643cf933b992b25a2fa Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:53:37 -0500 Subject: [PATCH 063/165] Actual soul sand walk cost, fixes #7 --- src/main/java/baritone/pathing/movement/ActionCosts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/ActionCosts.java b/src/main/java/baritone/pathing/movement/ActionCosts.java index c9bbd361..584ab1cb 100644 --- a/src/main/java/baritone/pathing/movement/ActionCosts.java +++ b/src/main/java/baritone/pathing/movement/ActionCosts.java @@ -24,7 +24,7 @@ public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieI */ double WALK_ONE_BLOCK_COST = 20 / 4.317; // 4.633 double WALK_ONE_IN_WATER_COST = 20 / 2.2; - double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_IN_WATER_COST; // TODO issue #7 + double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_BLOCK_COST * 0.5; // 0.4 in BlockSoulSand but effectively about half double LADDER_UP_ONE_COST = 20 / 2.35; double LADDER_DOWN_ONE_COST = 20 / 3.0; double SNEAK_ONE_BLOCK_COST = 20 / 1.3; From 51593a95e49221d025b87637f610900b433dc6d7 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:56:36 -0500 Subject: [PATCH 064/165] Add soul sand sprinting cost, @leijurv should implement it im lazy --- src/main/java/baritone/pathing/movement/ActionCosts.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/baritone/pathing/movement/ActionCosts.java b/src/main/java/baritone/pathing/movement/ActionCosts.java index 584ab1cb..9baff727 100644 --- a/src/main/java/baritone/pathing/movement/ActionCosts.java +++ b/src/main/java/baritone/pathing/movement/ActionCosts.java @@ -25,6 +25,7 @@ public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieI double WALK_ONE_BLOCK_COST = 20 / 4.317; // 4.633 double WALK_ONE_IN_WATER_COST = 20 / 2.2; double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_BLOCK_COST * 0.5; // 0.4 in BlockSoulSand but effectively about half + double SPRINT_ONE_OVER_SOUL_SAND_COST = WALK_ONE_OVER_SOUL_SAND_COST / 0.75; double LADDER_UP_ONE_COST = 20 / 2.35; double LADDER_DOWN_ONE_COST = 20 / 3.0; double SNEAK_ONE_BLOCK_COST = 20 / 1.3; From 1734caeed8ac1790caec4f8a5b2142233271bb75 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 18:59:22 -0500 Subject: [PATCH 065/165] Minor MovementDiagonal cleanup --- .../pathing/movement/movements/MovementDiagonal.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 384cf6be..023197c1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -106,18 +106,12 @@ public class MovementDiagonal extends Movement { return COST_INF; } if (optionA == 0) { - if (MovementHelper.avoidWalkingInto(pb2.getBlock())) { - return COST_INF; - } - if (MovementHelper.avoidWalkingInto(pb3.getBlock())) { + if (MovementHelper.avoidWalkingInto(pb2.getBlock()) || MovementHelper.avoidWalkingInto(pb3.getBlock())) { return COST_INF; } } if (optionB == 0) { - if (MovementHelper.avoidWalkingInto(pb0.getBlock())) { - return COST_INF; - } - if (MovementHelper.avoidWalkingInto(pb1.getBlock())) { + if (MovementHelper.avoidWalkingInto(pb0.getBlock()) || MovementHelper.avoidWalkingInto(pb1.getBlock())) { return COST_INF; } } From 606581b0449398e1a2dca2bce805aa64779b8e5c Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 29 Aug 2018 20:35:57 -0500 Subject: [PATCH 066/165] Wrap immutable list in normal arraylist to fix errors with adding --- src/main/java/baritone/Settings.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 75aaddc9..79bbec6b 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -65,11 +65,11 @@ public class Settings { /** * Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.) */ - public Setting> acceptableThrowawayItems = new Setting<>(Arrays.asList( + public Setting> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList( Item.getItemFromBlock(Blocks.DIRT), Item.getItemFromBlock(Blocks.COBBLESTONE), Item.getItemFromBlock(Blocks.NETHERRACK) - )); + ))); /** * Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real From aa3a8338e6962aca1565cbb063c51571306a92ad Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 30 Aug 2018 16:43:05 -0700 Subject: [PATCH 067/165] stop sprinting off ledges, fixes #110 --- src/main/java/baritone/pathing/path/PathExecutor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 1e977b92..76fcc3c1 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.event.events.TickEvent; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.Movement; +import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementDiagonal; @@ -285,7 +286,7 @@ public class PathExecutor implements Helper { } } if (next instanceof MovementTraverse) { - if (next.getDirection().down().equals(movement.getDirection())) { + if (next.getDirection().down().equals(movement.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) { if (playerFeet().equals(movement.getDest())) { pathPosition++; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); From 7cd0b186a9eb274ff2fa37a690ad004abd11db9e Mon Sep 17 00:00:00 2001 From: leijurv Date: Fri, 31 Aug 2018 08:13:16 -0700 Subject: [PATCH 068/165] lava hurts just as much as magma when cutting over --- .../pathing/movement/movements/MovementDiagonal.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 023197c1..1ce5537f 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 net.minecraft.block.Block; import net.minecraft.block.BlockMagma; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -90,10 +91,12 @@ public class MovementDiagonal extends Movement { if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - if (BlockStateInterface.get(positionsToBreak[2].down()).getBlock() instanceof BlockMagma) { + Block cuttingOver1 = BlockStateInterface.get(positionsToBreak[2].down()).getBlock(); + if (cuttingOver1 instanceof BlockMagma || BlockStateInterface.isLava(cuttingOver1)) { return COST_INF; } - if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) { + Block cuttingOver2 = BlockStateInterface.get(positionsToBreak[4].down()).getBlock(); + if (cuttingOver2 instanceof BlockMagma || BlockStateInterface.isLava(cuttingOver2)) { return COST_INF; } IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); From a93af3404bfa555e087e3e890c6a92801557709f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 31 Aug 2018 11:51:43 -0700 Subject: [PATCH 069/165] cache chunk in BlockStateInterface, fixes #113 --- .../java/baritone/utils/BlockStateInterface.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index a1013d7f..f21ddc50 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -30,6 +30,8 @@ import net.minecraft.world.chunk.Chunk; public class BlockStateInterface implements Helper { + private static Chunk prev = null; + public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability // Invalid vertical position @@ -37,8 +39,18 @@ public class BlockStateInterface implements Helper { return Blocks.AIR.getDefaultState(); if (!Baritone.settings().pathThroughCachedOnly.get()) { + Chunk cached = prev; + // there's great cache locality in block state lookups + // generally it's within each movement + // 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); + } Chunk chunk = mc.world.getChunk(pos); if (chunk.isLoaded()) { + prev = chunk; return chunk.getBlockState(pos); } } From f10e010e201f7ad572e799733dd3c7353d74567c Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 31 Aug 2018 16:32:15 -0500 Subject: [PATCH 070/165] GoalNear#toString --- src/main/java/baritone/pathing/goals/GoalNear.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index d19fadf8..2ec6bf1d 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -51,4 +51,14 @@ public class GoalNear implements Goal { public BlockPos getGoalPos() { return new BlockPos(x, y, z); } + + @Override + public String toString() { + return "GoalNear{" + + "x=" + x + + ", y=" + y + + ", z=" + z + + ", rangeSq=" + rangeSq + + '}'; + } } From 3f688bc45ecf982cb5cfbddfd6441b662da9d028 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 31 Aug 2018 14:58:23 -0700 Subject: [PATCH 071/165] spam chat less --- src/main/java/baritone/behavior/impl/PathingBehavior.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 4b5f1f43..e7c20c61 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -203,6 +203,12 @@ public class PathingBehavior extends Behavior { * @return true if this call started path calculation, false if it was already calculating or executing a path */ public boolean path() { + if (goal == null) { + return false; + } + if (goal.isInGoal(playerFeet())) { + return false; + } synchronized (pathPlanLock) { if (current != null) { return false; From 24c5c5d2381508a1aeeb5dbf1ea635c128b56cb1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 31 Aug 2018 15:21:59 -0700 Subject: [PATCH 072/165] instant cancel when more than 3 blocks away --- .../java/baritone/pathing/path/PathExecutor.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 76fcc3c1..4adda1f2 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementDiagonal; +import baritone.pathing.movement.movements.MovementFall; import baritone.pathing.movement.movements.MovementTraverse; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; @@ -46,6 +47,7 @@ import static baritone.pathing.movement.MovementState.MovementStatus.*; * @author leijurv */ public class PathExecutor implements Helper { + private static final double MAX_MAX_DIST_FROM_PATH = 3; private static final double MAX_DIST_FROM_PATH = 2; private static final double MAX_TICKS_AWAY = 200; // ten seconds. ok to decrease this, but it must be at least 110, see issue #102 private final IPath path; @@ -132,6 +134,17 @@ public class PathExecutor implements Helper { } else { ticksAway = 0; } + 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"); + pathPosition = path.length() + 3; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + failed = true; + return false; + } + } + } //this commented block is literally cursed. /*Out.log(actions.get(pathPosition)); if (pathPosition < actions.size() - 1) {//if there are two ActionBridges in a row and they are at right angles, walk diagonally. This makes it so you walk at 45 degrees along a zigzag path instead of doing inefficient zigging and zagging From 791eb886c0f900e8d423031dd893e18d73f2536b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 31 Aug 2018 16:50:25 -0700 Subject: [PATCH 073/165] bugfix --- 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 4adda1f2..dcecaeda 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -136,7 +136,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 + if (pathPosition == 0 || !(path.movements().get(pathPosition - 1) instanceof MovementFall)) { // might have overshot the landing displayChatMessageRaw("too far from path"); pathPosition = path.length() + 3; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); From 3c25e2b685c4160f7c0d4367f6f898487e463ede Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 11:19:42 -0700 Subject: [PATCH 074/165] fix part of oscillation --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index e5ebe184..a437d67e 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -169,6 +169,9 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { for (int i = 0; i < bestSoFar.length; i++) { double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i]; if (heuristic < bestHeuristicSoFar[i]) { + if (bestHeuristicSoFar[i] - heuristic < 0.01 && minimumImprovementRepropagation) { + continue; + } bestHeuristicSoFar[i] = heuristic; bestSoFar[i] = neighbor; } From 0b892e05cb6b805a78fb096f9b97a43ed730028c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 11:30:02 -0700 Subject: [PATCH 075/165] goto next to block, not in it, fixes #116 --- .../utils/ExampleBaritoneControl.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 542ea323..58847d3d 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -37,8 +37,10 @@ import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.EmptyChunk; import java.util.*; +import java.util.stream.Collectors; public class ExampleBaritoneControl extends Behavior { public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl(); @@ -221,8 +223,27 @@ 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()); + String mining = waypointType; + //displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); + List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1)); + if (locs.isEmpty()) { + displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + return; + } + BlockPos playerFeet = playerFeet(); + locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); + + // remove any that are within loaded chunks that aren't actually what we want + locs.removeAll(locs.stream() + .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) + .filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining)) + .collect(Collectors.toList())); + if (locs.size() > 30) { + locs = locs.subList(0, 30); + } + PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new))); + PathingBehavior.INSTANCE.path(); return; } Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag); From e354227635906d3c5a836a76473cf0ef8075d2c6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 11:31:42 -0700 Subject: [PATCH 076/165] allow goto blocks that end in s --- src/main/java/baritone/utils/ExampleBaritoneControl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 58847d3d..8b262f0a 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -217,7 +217,7 @@ public class ExampleBaritoneControl extends Behavior { } if (msg.toLowerCase().startsWith("goto")) { String waypointType = msg.toLowerCase().substring(4).trim(); - if (waypointType.endsWith("s")) { + if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) { // for example, "show deaths" waypointType = waypointType.substring(0, waypointType.length() - 1); } From aca487f97ea2811d2e1fa4d7ca190c4ca9598cbc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 12:16:55 -0700 Subject: [PATCH 077/165] fix behavior when all have been mined --- src/main/java/baritone/behavior/impl/MineBehavior.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index e59058a8..32f92877 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -55,11 +55,6 @@ public class MineBehavior extends Behavior { return; } List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1)); - if (locs.isEmpty()) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); - cancel(); - return; - } BlockPos playerFeet = playerFeet(); locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); @@ -71,6 +66,11 @@ public class MineBehavior extends Behavior { if (locs.size() > 30) { locs = locs.subList(0, 30); } + if (locs.isEmpty()) { + displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + cancel(); + return; + } PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalTwoBlocks::new).toArray(Goal[]::new))); PathingBehavior.INSTANCE.path(); } From c0bc7b5ecd1e86d1473fd55f59628ffbaef638a6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 12:26:55 -0700 Subject: [PATCH 078/165] fix strange issue when exiting and entering the same world --- src/main/java/baritone/api/event/GameEventHandler.java | 3 +++ src/main/java/baritone/utils/BlockStateInterface.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 88cd0560..45e86885 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -39,6 +39,7 @@ import baritone.api.event.events.*; import baritone.api.event.events.type.EventState; import baritone.api.event.listener.IGameEventListener; import baritone.chunk.WorldProvider; +import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.InputOverrideHandler; import baritone.utils.interfaces.Toggleable; @@ -133,6 +134,8 @@ public final class GameEventHandler implements IGameEventListener, Helper { public final void onWorldEvent(WorldEvent event) { WorldProvider cache = WorldProvider.INSTANCE; + BlockStateInterface.clearCachedChunk(); + switch (event.getState()) { case PRE: break; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index f21ddc50..cd3ca646 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -31,7 +31,7 @@ import net.minecraft.world.chunk.Chunk; public class BlockStateInterface implements Helper { private static Chunk prev = null; - + public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability // Invalid vertical position @@ -66,6 +66,10 @@ public class BlockStateInterface implements Helper { return Blocks.AIR.getDefaultState(); } + public static void clearCachedChunk() { + prev = null; + } + public static Block getBlock(BlockPos pos) { return get(pos).getBlock(); } From 76cdad2223b1536c9f7ec86aaabe8403f132bd03 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 12:47:43 -0700 Subject: [PATCH 079/165] properly place on soul sand, fixes #118 --- .../pathing/movement/movements/MovementTraverse.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index b1eac4e9..5c1e35fb 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -206,6 +206,16 @@ public class MovementTraverse extends Movement { return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } state.setInput(InputOverrideHandler.Input.SNEAK, true); + if (BlockStateInterface.get(playerFeet().down()).getBlock().equals(Blocks.SOUL_SAND)) { // see issue #118 + double dist = Math.max(Math.abs(dest.getX() + 0.5 - player().posX), Math.abs(dest.getZ() + 0.5 - player().posZ)); + if (dist < 0.85) { // 0.5 + 0.3 + epsilon + MovementHelper.moveTowards(state, dest); + state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false); + state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); + return state; + } + } + state.setInput(InputOverrideHandler.Input.MOVE_BACK, false); double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D; double faceY = (dest.getY() + against1.getY()) * 0.5D; double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D; From 8d46c36269dc21b436f1967b41966ce08fcdd61a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 13:20:27 -0700 Subject: [PATCH 080/165] you can walk on chests --- src/main/java/baritone/pathing/movement/MovementHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 142f5d98..909c21a7 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -195,6 +195,9 @@ public interface MovementHelper extends ActionCosts, Helper { 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 BlockAir) { return false; } From e705f9808b9e1432466376787896e4a1dca98ff6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 14:45:57 -0700 Subject: [PATCH 081/165] add force cancel --- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 6 ++++++ src/main/java/baritone/utils/ExampleBaritoneControl.java | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index b8f13f1e..2894b989 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -17,6 +17,7 @@ package baritone.pathing.calc; +import baritone.behavior.impl.PathingBehavior; import baritone.pathing.goals.Goal; import baritone.pathing.path.IPath; import baritone.utils.pathing.BetterBlockPos; @@ -121,6 +122,11 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { return node; } + public static void forceCancel() { + PathingBehavior.INSTANCE.cancel(); + currentlyRunning = null; + } + @Override public Optional pathToMostRecentNodeConsidered() { return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0)); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 8b262f0a..e695ff49 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -28,6 +28,7 @@ import baritone.chunk.ChunkPacker; import baritone.chunk.Waypoint; import baritone.chunk.WorldProvider; import baritone.pathing.calc.AStarPathFinder; +import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.goals.*; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.CalculationContext; @@ -117,6 +118,12 @@ public class ExampleBaritoneControl extends Behavior { displayChatMessageRaw("ok canceled"); return; } + if (msg.toLowerCase().equals("forcecancel")) { + AbstractNodeCostSearch.forceCancel(); + event.cancel(); + displayChatMessageRaw("ok force canceled"); + return; + } if (msg.toLowerCase().equals("invert")) { Goal goal = PathingBehavior.INSTANCE.getGoal(); BlockPos runAwayFrom; From 2e22f1cf54a0dd022547bc0b9614dbc231c96fa1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Sep 2018 14:47:46 -0700 Subject: [PATCH 082/165] hopefully make currentlyRunning more resilient --- .../pathing/calc/AbstractNodeCostSearch.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 2894b989..3960a376 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -81,9 +81,19 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); } this.cancelRequested = false; - Optional path = calculate0(); - isFinished = true; - return path; + try { + Optional path = calculate0(); + isFinished = true; + return path; + } catch (Exception e) { + currentlyRunning = null; + isFinished = true; + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } else { + throw new RuntimeException(e); + } + } } protected abstract Optional calculate0(); From 1f97daf391e9ed70f47f673e5bf437147b70b23c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 07:18:57 -0700 Subject: [PATCH 083/165] clean up the clutter --- .../java/baritone/pathing/calc/AStarPathFinder.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index a437d67e..0af6f0fe 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -95,20 +95,13 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { mostRecentConsidered = currentNode; BetterBlockPos currentNodePos = currentNode.pos; numNodes++; - /*if ((lastPrintout + 1000) - System.nanoTime() / 1000000L < 0) {//print once a second - System.out.println("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far"); - lastPrintout = System.nanoTime() / 1000000L; - }*/ if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes)); } - //long constructStart = System.nanoTime(); Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order shuffle(possibleMovements); - //long constructEnd = System.nanoTime(); - //System.out.println(constructEnd - constructStart); for (Movement movementToGetToNeighbor : possibleMovements) { if (movementToGetToNeighbor == null) { continue; @@ -126,11 +119,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } } } - //long costStart = System.nanoTime(); // TODO cache cost double actionCost = movementToGetToNeighbor.getCost(calcContext); - //long costEnd = System.nanoTime(); - //System.out.println(movementToGetToNeighbor.getClass() + "" + (costEnd - costStart)); numMovementsConsidered++; if (actionCost >= ActionCosts.COST_INF) { continue; From 3afd8368220c24b80256f357bc9c8db0cadd2b44 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 09:22:51 -0700 Subject: [PATCH 084/165] only offset down if doing so would put us on solid ground --- src/main/java/baritone/behavior/impl/PathingBehavior.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index e7c20c61..075d8d6f 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -27,6 +27,7 @@ import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; import baritone.pathing.goals.*; +import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.IPath; import baritone.pathing.path.PathExecutor; import baritone.utils.BlockStateInterface; @@ -226,7 +227,7 @@ public class PathingBehavior extends Behavior { public BlockPos pathStart() { BlockPos feet = playerFeet(); - if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR)) { + if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) { return feet.down(); } return feet; From 462ccad885941235b65fbbdbb323b782630276ce Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 10:43:34 -0700 Subject: [PATCH 085/165] use initial estimate from calculation phase --- .../baritone/pathing/path/PathExecutor.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index dcecaeda..ce86b4d0 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -217,17 +217,9 @@ public class PathExecutor implements Helper { //displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms"); } Movement movement = path.movements().get(pathPosition); - double currentCost = movement.recalculateCost(); - if (currentCost >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling."); - pathPosition = path.length() + 3; - failed = true; - Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); - return true; - } if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; - currentMovementInitialCostEstimate = currentCost; // do this only once, when the movement starts + currentMovementInitialCostEstimate = movement.getCost(null); // do this only once, when the movement starts for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { if (path.movements().get(pathPosition + i).recalculateCost() >= ActionCosts.COST_INF) { displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); @@ -238,6 +230,14 @@ 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."); + pathPosition = path.length() + 3; + failed = true; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + return true; + } MovementState.MovementStatus movementStatus = movement.update(); if (movementStatus == UNREACHABLE || movementStatus == FAILED) { displayChatMessageRaw("Movement returns status " + movementStatus); From e58c43305cc1cb679f34cb6064a65162ad488f90 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 10:45:07 -0700 Subject: [PATCH 086/165] typo --- FEATURES.md | 15 +++++++++++++++ .../baritone/utils/ExampleBaritoneControl.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 FEATURES.md diff --git a/FEATURES.md b/FEATURES.md new file mode 100644 index 00000000..3f90dae2 --- /dev/null +++ b/FEATURES.md @@ -0,0 +1,15 @@ +# Pathing features +- Long distance pathing and splicing. Baritone calculates paths in segments + +# Goals +The pathing goal can be set to any of these options +- GoalBlock - one specific block that the player should stand inside at foot level +- GoalXZ - an X and a Z coordinate, used for long distance pathing +- GoalYLevel - a Y coordinate +- GoalTwoBlocks - a block position that the player should stand in, either at foot or eye level +- GoalGetToBlock - a block position that the player should stand adjacent to, below, or on top of +- GoalNear - a block position that the player should get within a certain radius of, used for following entities + +And finally GoalComposite. GoalComposite is a list of other goals, any one of which satisfies the goal. For example, `mine diamond_ore` creates a GoalComposite of GoalTwoBlock s for every diamond ore location it knows of. + + diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index e695ff49..854950da 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -188,7 +188,7 @@ public class ExampleBaritoneControl extends Behavior { if (msg.toLowerCase().startsWith("mine")) { String blockType = msg.toLowerCase().substring(4).trim(); MineBehavior.INSTANCE.mine(blockType); - displayChatMessageRaw("Started mining blocks of type" + blockType); + displayChatMessageRaw("Started mining blocks of type " + blockType); event.cancel(); return; } From f3bd50dc3658712ff0f21aa3747289c64e2bcd5c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 10:46:54 -0700 Subject: [PATCH 087/165] disable load boundary cutoff by default, fixes #114 --- src/main/java/baritone/Settings.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 79bbec6b..7f386bcb 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -122,8 +122,9 @@ public class Settings { /** * After calculating a path (potentially through cached chunks), artificially cut it off to just the part that is * entirely within currently loaded chunks. Improves path safety because cached chunks are heavily simplified. + * See issue #114 for why this is disabled. */ - public Setting cutoffAtLoadBoundary = new Setting<>(true); + public Setting cutoffAtLoadBoundary = new Setting<>(false); /** * Stop 5 movements before anything that made the path COST_INF. From 17b27af09fbdd935b5beb6ad0adec6bb4cec22c8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:09:28 -0700 Subject: [PATCH 088/165] more features --- FEATURES.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index 3f90dae2..19f3b81d 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1,5 +1,13 @@ # Pathing features -- Long distance pathing and splicing. Baritone calculates paths in segments +- Long distance pathing and splicing. Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end. +- Chunk caching. Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. +- Block breaking. Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. +- Block placing. Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. +- Falling. Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. +- Vines and ladders. Baritone understands how to climb and descend vines and ladders. +- Fence gates and doors. +- 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). +- # Goals The pathing goal can be set to any of these options @@ -13,3 +21,5 @@ The pathing goal can be set to any of these options And finally GoalComposite. GoalComposite is a list of other goals, any one of which satisfies the goal. For example, `mine diamond_ore` creates a GoalComposite of GoalTwoBlock s for every diamond ore location it knows of. +# Future features +(things it doesn't have yet) \ No newline at end of file From 262b33f3228b20b0877622cbe1482681aee2cf97 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:14:57 -0700 Subject: [PATCH 089/165] pathing method and upcoming features --- FEATURES.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 19f3b81d..0bf4aca5 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -7,7 +7,14 @@ - Vines and ladders. Baritone understands how to climb and descend vines and ladders. - Fence gates and doors. - 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). -- + +# Pathing method +Baritone uses a modified version of A*. + +- Incremental cost backoff. Since most of the time Baritone only knows the terrain up to the render distance, it can't calculate a full path to the goal. Therefore it needs to select a segment to execute first (assuming it will calculate the next segment at the end of this one). It uses incremental cost backoff to select the best node by varying metrics, then paths to that node. This is unchanged from MineBot and I made a write-up that still applies. +- Minimum improvement repropagation. The pathfinder ignores alternate routes that provide minimal improvements (less than 0.01 ticks of improvement), because the calculation cost of repropagating this to all connected nodes is much higher than the half-millisecond path time improvement it would get. +- Backtrack cost favoring. While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. + # Goals The pathing goal can be set to any of these options @@ -22,4 +29,9 @@ And finally GoalComposite. GoalComposite is a list of other goals, any one of wh # Future features -(things it doesn't have yet) \ No newline at end of file +(things it doesn't have yet) +- Trapdoors +- Boats +- Horses / pigs +- Sprint jumping in a 1x2 corridor +- Parkour (jumping over gaps of any length) \ No newline at end of file From 1f73fe8c795fe30c68fbf6597cc799d4b19319a2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:15:43 -0700 Subject: [PATCH 090/165] add link to features --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2748cb4f..3a174662 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A Minecraft bot. This project is an updated version of [Minebot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. +Features + # Setup - Open the project in IntelliJ as a Gradle project - Run the Gradle task `setupDecompWorkspace` From 5ed40ff50d1e4e12f28ef9aef98a21c7b1a45f6c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:18:27 -0700 Subject: [PATCH 091/165] better list --- FEATURES.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 0bf4aca5..6437c30f 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1,29 +1,29 @@ # Pathing features -- Long distance pathing and splicing. Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end. -- Chunk caching. Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. -- Block breaking. Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. -- Block placing. Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. -- Falling. Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. -- Vines and ladders. Baritone understands how to climb and descend vines and ladders. -- Fence gates and doors. -- 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). +- **Long distance pathing and splicing** Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end. +- **Chunk caching** Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. +- **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. +- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. +- **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. +- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. +- **Fence gates and doors** +- **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). # Pathing method Baritone uses a modified version of A*. -- Incremental cost backoff. Since most of the time Baritone only knows the terrain up to the render distance, it can't calculate a full path to the goal. Therefore it needs to select a segment to execute first (assuming it will calculate the next segment at the end of this one). It uses incremental cost backoff to select the best node by varying metrics, then paths to that node. This is unchanged from MineBot and I made a write-up that still applies. -- Minimum improvement repropagation. The pathfinder ignores alternate routes that provide minimal improvements (less than 0.01 ticks of improvement), because the calculation cost of repropagating this to all connected nodes is much higher than the half-millisecond path time improvement it would get. -- Backtrack cost favoring. While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. +- **Incremental cost backoff** Since most of the time Baritone only knows the terrain up to the render distance, it can't calculate a full path to the goal. Therefore it needs to select a segment to execute first (assuming it will calculate the next segment at the end of this one). It uses incremental cost backoff to select the best node by varying metrics, then paths to that node. This is unchanged from MineBot and I made a write-up that still applies. In essence, it keeps track of the best node by various increasing coefficients, then picks the node with the least coefficient that goes at least 5 blocks from the starting position. +- **Minimum improvement repropagation** The pathfinder ignores alternate routes that provide minimal improvements (less than 0.01 ticks of improvement), because the calculation cost of repropagating this to all connected nodes is much higher than the half-millisecond path time improvement it would get. +- **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. # Goals The pathing goal can be set to any of these options -- GoalBlock - one specific block that the player should stand inside at foot level -- GoalXZ - an X and a Z coordinate, used for long distance pathing -- GoalYLevel - a Y coordinate -- GoalTwoBlocks - a block position that the player should stand in, either at foot or eye level -- GoalGetToBlock - a block position that the player should stand adjacent to, below, or on top of -- GoalNear - a block position that the player should get within a certain radius of, used for following entities +- **GoalBlock** one specific block that the player should stand inside at foot level +- **GoalXZ** an X and a Z coordinate, used for long distance pathing +- **GoalYLevel** a Y coordinate +- **GoalTwoBlocks** a block position that the player should stand in, either at foot or eye level +- **GoalGetToBlock** a block position that the player should stand adjacent to, below, or on top of +- **GoalNear** a block position that the player should get within a certain radius of, used for following entities And finally GoalComposite. GoalComposite is a list of other goals, any one of which satisfies the goal. For example, `mine diamond_ore` creates a GoalComposite of GoalTwoBlock s for every diamond ore location it knows of. From 1cb25e29c71cd6d94d1f1c810111ce2760e2a4ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:25:44 -0700 Subject: [PATCH 092/165] add links --- FEATURES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 6437c30f..3ff4c917 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1,6 +1,6 @@ # Pathing features - **Long distance pathing and splicing** Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end. -- **Chunk caching** Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. +- **Chunk caching** Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. Example - **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. - **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. @@ -13,7 +13,7 @@ Baritone uses a modified version of A*. - **Incremental cost backoff** Since most of the time Baritone only knows the terrain up to the render distance, it can't calculate a full path to the goal. Therefore it needs to select a segment to execute first (assuming it will calculate the next segment at the end of this one). It uses incremental cost backoff to select the best node by varying metrics, then paths to that node. This is unchanged from MineBot and I made a write-up that still applies. In essence, it keeps track of the best node by various increasing coefficients, then picks the node with the least coefficient that goes at least 5 blocks from the starting position. - **Minimum improvement repropagation** The pathfinder ignores alternate routes that provide minimal improvements (less than 0.01 ticks of improvement), because the calculation cost of repropagating this to all connected nodes is much higher than the half-millisecond path time improvement it would get. -- **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. +- **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. Example # Goals From 6389917898c709044e3bad4017c68a9dbaccccfb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:39:13 -0700 Subject: [PATCH 093/165] more features --- FEATURES.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 3ff4c917..681e11a0 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1,12 +1,13 @@ # Pathing features -- **Long distance pathing and splicing** Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end. -- **Chunk caching** Baritone simplifies chunks to an internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. Example +- **Long distance pathing and splicing** Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end, so that it's moving towards the goal at all times. +- **Chunk caching** Baritone simplifies chunks to a compacted internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. Example - **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. -- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. +- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. -- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. +- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). - **Fence gates and doors** - **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. # Pathing method Baritone uses a modified version of A*. @@ -15,9 +16,12 @@ Baritone uses a modified version of A*. - **Minimum improvement repropagation** The pathfinder ignores alternate routes that provide minimal improvements (less than 0.01 ticks of improvement), because the calculation cost of repropagating this to all connected nodes is much higher than the half-millisecond path time improvement it would get. - **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment slightly, as a tiebreaker. This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. Example +# Configuring Baritone +All the settings and documentation are here. +To change a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `pathTimeoutMS 250`). It's case insensitive. # Goals -The pathing goal can be set to any of these options +The pathing goal can be set to any of these options: - **GoalBlock** one specific block that the player should stand inside at foot level - **GoalXZ** an X and a Z coordinate, used for long distance pathing - **GoalYLevel** a Y coordinate @@ -25,11 +29,11 @@ The pathing goal can be set to any of these options - **GoalGetToBlock** a block position that the player should stand adjacent to, below, or on top of - **GoalNear** a block position that the player should get within a certain radius of, used for following entities -And finally GoalComposite. GoalComposite is a list of other goals, any one of which satisfies the goal. For example, `mine diamond_ore` creates a GoalComposite of GoalTwoBlock s for every diamond ore location it knows of. +And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one of which satisfies the goal. For example, `mine diamond_ore` creates a `GoalComposite` of `GoalTwoBlocks`s for every diamond ore location it knows of. # Future features -(things it doesn't have yet) +(things it doesn't have yet, and things it may not ever have) - Trapdoors - Boats - Horses / pigs From 5caa0542ba84ef5aa7a58cca448810a178667ebc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 11:48:10 -0700 Subject: [PATCH 094/165] ascend should clear the replaceable block in the way --- .../baritone/pathing/movement/movements/MovementAscend.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index af29a887..a50dfba8 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -150,6 +150,8 @@ public class MovementAscend extends Movement { // After 20 ticks without placement, we might be standing in the way, move back state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); } + } else { + state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true); // break whatever replaceable block is in the way } System.out.println("Trying to look at " + anAgainst + ", actually looking at" + selectedBlock); }); From 8d62f754a7a77c53234f9dd94da5b66a4c8bc617 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 12:04:48 -0700 Subject: [PATCH 095/165] crucial performance optimization --- src/main/java/baritone/chunk/ChunkPacker.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 90cdf02a..23908344 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -21,7 +21,6 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.block.Block; -import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -114,7 +113,7 @@ public final class ChunkPacker implements Helper { // however, this failed in the nether when you were near a nether fortress // because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape // this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors - if (block instanceof BlockAir) { + if (block == Blocks.AIR) { return PathingBlockType.AIR; } From e8b108fde81c077bfb8a96199c3322804c46773c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 12:06:00 -0700 Subject: [PATCH 096/165] removePrefix --- src/main/java/baritone/Settings.java | 5 +++++ src/main/java/baritone/utils/ExampleBaritoneControl.java | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 7f386bcb..d7d23c59 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -218,6 +218,11 @@ public class Settings { */ public Setting chatControl = new Setting<>(true); + /** + * A second override over chatControl to force it on + */ + public Setting removePrefix = new Setting<>(false); + /** * Render the path */ diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 854950da..75a36994 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -57,7 +57,9 @@ public class ExampleBaritoneControl extends Behavior { @Override public void onSendChatMessage(ChatEvent event) { if (!Baritone.settings().chatControl.get()) { - return; + if (!Baritone.settings().removePrefix.get()) { + return; + } } String msg = event.getMessage(); if (Baritone.settings().prefix.get()) { From 115b8553b257f3c98f5644c0bf22b824a7718334 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 2 Sep 2018 14:18:11 -0500 Subject: [PATCH 097/165] Make Baritone initialization listeners consumers --- src/main/java/baritone/Baritone.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index bd678dd8..5baacec8 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; /** * @author Brady @@ -52,9 +53,9 @@ public enum Baritone { private File dir; /** - * List of runnables to be called after Baritone has initialized + * List of consumers to be called after Baritone has initialized */ - private List onInitRunnables; + private List> onInitConsumers; /** * Whether or not Baritone is active @@ -62,7 +63,7 @@ public enum Baritone { private boolean active; Baritone() { - this.onInitRunnables = new ArrayList<>(); + this.onInitConsumers = new ArrayList<>(); } public synchronized void init() { @@ -91,7 +92,7 @@ public enum Baritone { this.active = true; this.initialized = true; - this.onInitRunnables.forEach(Runnable::run); + this.onInitConsumers.forEach(consumer -> consumer.accept(this)); } public final boolean isInitialized() { @@ -131,7 +132,7 @@ public enum Baritone { return this.dir; } - public final void registerInitListener(Runnable runnable) { - this.onInitRunnables.add(runnable); + public final void registerInitListener(Consumer runnable) { + this.onInitConsumers.add(runnable); } } From 0e6d61e90774129646d4168de69b0c2ed41f0e12 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 2 Sep 2018 14:21:34 -0500 Subject: [PATCH 098/165] Consolidate rayTraceTowards into RayTraceUtils, fixes #121 --- .../behavior/impl/LookBehaviorUtils.java | 19 ++----------------- .../java/baritone/utils/RayTraceUtils.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java b/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java index fd75c478..91b046e0 100644 --- a/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java +++ b/src/main/java/baritone/behavior/impl/LookBehaviorUtils.java @@ -17,10 +17,7 @@ package baritone.behavior.impl; -import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; -import baritone.utils.Rotation; -import baritone.utils.Utils; +import baritone.utils.*; import net.minecraft.block.BlockFire; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.*; @@ -87,18 +84,6 @@ public final class LookBehaviorUtils implements Helper { return Optional.empty(); } - private static RayTraceResult rayTraceTowards(Rotation rotation) { - double blockReachDistance = mc.playerController.getBlockReachDistance(); - Vec3d start = mc.player.getPositionEyes(1.0F); - Vec3d direction = calcVec3dFromRotation(rotation); - Vec3d end = start.add( - direction.x * blockReachDistance, - direction.y * blockReachDistance, - direction.z * blockReachDistance - ); - return mc.world.rayTraceBlocks(start, end, false, false, true); - } - /** * Checks if coordinate is reachable with the given block-face rotation offset * @@ -108,7 +93,7 @@ public final class LookBehaviorUtils implements Helper { */ protected static Optional reachableOffset(BlockPos pos, Vec3d offsetPos) { Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offsetPos); - RayTraceResult result = rayTraceTowards(rotation); + RayTraceResult result = RayTraceUtils.rayTraceTowards(rotation); System.out.println(result); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { if (result.getBlockPos().equals(pos)) { diff --git a/src/main/java/baritone/utils/RayTraceUtils.java b/src/main/java/baritone/utils/RayTraceUtils.java index f6547454..123e283d 100644 --- a/src/main/java/baritone/utils/RayTraceUtils.java +++ b/src/main/java/baritone/utils/RayTraceUtils.java @@ -18,6 +18,9 @@ package baritone.utils; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; + +import static baritone.behavior.impl.LookBehaviorUtils.calcVec3dFromRotation; /** * @author Brady @@ -44,4 +47,16 @@ public final class RayTraceUtils implements Helper { return result; } + + public static RayTraceResult rayTraceTowards(Rotation rotation) { + double blockReachDistance = mc.playerController.getBlockReachDistance(); + Vec3d start = mc.player.getPositionEyes(1.0F); + Vec3d direction = calcVec3dFromRotation(rotation); + Vec3d end = start.add( + direction.x * blockReachDistance, + direction.y * blockReachDistance, + direction.z * blockReachDistance + ); + return mc.world.rayTraceBlocks(start, end, false, false, true); + } } From 639ec3898167a24f538229270809a6a18484d4cc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 12:55:18 -0700 Subject: [PATCH 099/165] features --- FEATURES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index 681e11a0..0796919c 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -37,5 +37,9 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o - Trapdoors - Boats - Horses / pigs +- Slabs (double, top, and bottom) - Sprint jumping in a 1x2 corridor -- Parkour (jumping over gaps of any length) \ No newline at end of file +- Stairs +- Parkour (jumping over gaps of any length) + +See issues for more. \ No newline at end of file From 7ed13bf358384b49f149f29471a86c5406a6992e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 13:05:06 -0700 Subject: [PATCH 100/165] features --- FEATURES.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 0796919c..8147fc22 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -33,13 +33,17 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o # Future features -(things it doesn't have yet, and things it may not ever have) +Things it doesn't have yet - Trapdoors -- Boats -- Horses / pigs - Slabs (double, top, and bottom) - Sprint jumping in a 1x2 corridor - Stairs -- Parkour (jumping over gaps of any length) -See issues for more. \ No newline at end of file +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 +- Horses (2x3 path instead of 1x2) +- Elytra From 9e272824c5b5394b7cb1017d51a28b32b1582459 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 13:34:15 -0700 Subject: [PATCH 101/165] traverse should also break the block in the way --- .../baritone/pathing/movement/movements/MovementTraverse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 5c1e35fb..a959455b 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -255,7 +255,7 @@ public class MovementTraverse extends Movement { return state; } // Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt()); - return state; + return state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true); } else { MovementHelper.moveTowards(state, positionsToBreak[0]); return state; From da5460413c44114a0f68717e2117e84dc387c697 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 13:51:38 -0700 Subject: [PATCH 102/165] segment based timeout, and slowpath warning --- src/main/java/baritone/Settings.java | 7 ++++++- src/main/java/baritone/behavior/impl/PathingBehavior.java | 8 +++++++- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 7 +++++-- .../baritone/pathing/calc/AbstractNodeCostSearch.java | 6 +++--- src/main/java/baritone/pathing/calc/IPathFinder.java | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index d7d23c59..78c2d4b3 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -185,7 +185,12 @@ public class Settings { /** * Pathing can never take longer than this */ - public Setting pathTimeoutMS = new Setting<>(4000L); + public Setting pathTimeoutMS = new Setting<>(2000L); + + /** + * Planning ahead while executing a segment can never take longer than this + */ + public Setting planAheadTimeoutMS = new Setting<>(4000L); /** * For debugging, consider nodes much much slower diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 075d8d6f..fa651a87 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -324,9 +324,15 @@ public class PathingBehavior extends Behavior { goal = new GoalXZ(pos.getX(), pos.getZ()); } } + long timeout; + if (current == null) { + timeout = Baritone.settings().pathTimeoutMS.get(); + } else { + timeout = Baritone.settings().planAheadTimeoutMS.get(); + } try { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); - return pf.calculate(); + return pf.calculate(timeout); } catch (Exception e) { displayChatMessageRaw("Pathing exception: " + e); e.printStackTrace(); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 0af6f0fe..fa8b5076 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -55,7 +55,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } @Override - protected Optional calculate0() { + protected Optional calculate0(long timeout) { startNode = getNodeAtPosition(start); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; @@ -74,7 +74,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); - long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); + if (slowPath) { + displayChatMessageRaw("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; int numNodes = 0; int numMovementsConsidered = 0; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 3960a376..5804cb1a 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -76,13 +76,13 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { cancelRequested = true; } - public synchronized Optional calculate() { + public synchronized Optional calculate(long timeout) { if (isFinished) { throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); } this.cancelRequested = false; try { - Optional path = calculate0(); + Optional path = calculate0(timeout); isFinished = true; return path; } catch (Exception e) { @@ -96,7 +96,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { } } - protected abstract Optional calculate0(); + protected abstract Optional calculate0(long timeout); /** * Determines the distance squared from the specified node to the start diff --git a/src/main/java/baritone/pathing/calc/IPathFinder.java b/src/main/java/baritone/pathing/calc/IPathFinder.java index bbcc7bda..dceee65d 100644 --- a/src/main/java/baritone/pathing/calc/IPathFinder.java +++ b/src/main/java/baritone/pathing/calc/IPathFinder.java @@ -39,7 +39,7 @@ public interface IPathFinder { * * @return The final path */ - Optional calculate(); + Optional calculate(long timeout); /** * Intended to be called concurrently with calculatePath from a different thread to tell if it's finished yet From c63ccc3dcb94636ca0c492c74ab56044a0f578a9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:10:27 -0700 Subject: [PATCH 103/165] can walk through should be cached as air, fixes #124 --- src/main/java/baritone/chunk/ChunkPacker.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 23908344..fef3c0a5 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -21,6 +21,9 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.block.Block; +import net.minecraft.block.BlockDoublePlant; +import net.minecraft.block.BlockFlower; +import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -113,7 +116,7 @@ public final class ChunkPacker implements Helper { // however, this failed in the nether when you were near a nether fortress // because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape // this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors - if (block == Blocks.AIR) { + if (block == Blocks.AIR || block instanceof BlockTallGrass || block instanceof BlockDoublePlant || block instanceof BlockFlower) { return PathingBlockType.AIR; } From f75188b24d7f727155afac0bca91faea860b90fe Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:12:33 -0700 Subject: [PATCH 104/165] fix cost cache overwrite in path executor --- src/main/java/baritone/pathing/movement/Movement.java | 4 ++++ src/main/java/baritone/pathing/path/PathExecutor.java | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 44c9d5a3..715bfd68 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -100,6 +100,10 @@ public abstract class Movement implements Helper, MovementHelper { return getCost(null); } + public double calculateCostWithoutCaching() { + return calculateCost0(new CalculationContext()); + } + /** * Handles the execution of the latest Movement * State, and offers a Status to the calling class. diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index ce86b4d0..88ca6e30 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -219,9 +219,10 @@ public class PathExecutor implements Helper { Movement movement = path.movements().get(pathPosition); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; - currentMovementInitialCostEstimate = movement.getCost(null); // do this only once, when the movement starts + // do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now + 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).recalculateCost() >= ActionCosts.COST_INF) { + 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."); pathPosition = path.length() + 3; failed = true; From 8c58dcb41f99f8425ef80cc5524da68c05d2472a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:13:41 -0700 Subject: [PATCH 105/165] remove unused circle ci config --- .circleci/config.yml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index d9cdd911..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,43 +0,0 @@ -# Java Gradle CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-java/ for more details -# -version: 2 -jobs: - build: - docker: - # specify the version you desire here - - image: circleci/openjdk:8-jdk - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 - - working_directory: ~/repo - - environment: - # Customize the JVM maximum heap limit - JVM_OPTS: -Xmx3200m - TERM: dumb - - steps: - - checkout - - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-{{ checksum "build.gradle" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - run: gradle dependencies - - - save_cache: - paths: - - ~/.gradle - key: v1-dependencies-{{ checksum "build.gradle" }} - - # run tests! - - run: gradle test - From 41c03cbf365aa980678b6c01ca719d77aa422bba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:19:21 -0700 Subject: [PATCH 106/165] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3a174662..29771860 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. - Select the "Minecraft Client" launch config and run ## Command Line +On Mac OSX and Linux, use `./gradlew` instead of `gradlew`. ``` $ gradlew setupDecompWorkspace $ gradlew --refresh-dependencies From a1aaaef67f4315a400ca4013a22658a3500b3101 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:46:03 -0700 Subject: [PATCH 107/165] include sponge in runtime --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7dd75be8..bdb3c311 100755 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ repositories { } dependencies { - implementation ('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + runtime implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { // Mixin includes a lot of dependencies that are too up-to-date exclude module: 'launchwrapper' exclude module: 'guava' From 7fd0d5799d72e3bb60cdf6e1d7520a7f75aa5f83 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:46:41 -0700 Subject: [PATCH 108/165] travis start --- .travis.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..dff5f3a5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: java From 12ec7ea990667fdc996da255b82360c67f80ad7b Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 2 Sep 2018 18:01:41 -0500 Subject: [PATCH 109/165] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 29771860..c3dd39ab 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,12 @@ PathingBehavior.INSTANCE.setGoal(new GoalXZ(10000, 20000)); PathingBehavior.INSTANCE.path(); ``` -# Can I use Baritone as a library in my hacked client? +# FAQ + +## Can I use Baritone as a library in my hacked client? Sure! -# How is it so fast? +## How is it so fast? -Magic \ No newline at end of file +Magic From 5dbf1014b313b36d416d5e11f051c0e25131f19c Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 2 Sep 2018 21:28:55 -0500 Subject: [PATCH 110/165] Fix usage of characters that can't be mapped to ascii --- src/main/java/baritone/utils/Helper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index c973b1ca..ffb0f21b 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -33,7 +33,13 @@ import net.minecraft.util.text.TextFormatting; */ public interface Helper { - ITextComponent MESSAGE_PREFIX = new TextComponentString("§5[§dBaritone§5]§7"); + ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format( + "%s[%sBaritone%s]%s", + TextFormatting.DARK_PURPLE, + TextFormatting.LIGHT_PURPLE, + TextFormatting.DARK_PURPLE, + TextFormatting.GRAY + )); Minecraft mc = Minecraft.getMinecraft(); From 31a87a8938e5b4fd4a2d71cee7d72a6926b78e04 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 2 Sep 2018 23:26:57 -0500 Subject: [PATCH 111/165] Added travis badge to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c3dd39ab..63bc2c8b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![](https://travis-ci.com/cabaletta/baritone.svg?branch=master) + # Baritone A Minecraft bot. This project is an updated version of [Minebot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. From bac07ce1006b9a123bc188d2ad4ce2d685be3bcf Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:15:18 -0700 Subject: [PATCH 112/165] slabs --- src/main/java/baritone/chunk/ChunkPacker.java | 15 ++++---- .../baritone/pathing/movement/Movement.java | 20 +--------- .../pathing/movement/MovementHelper.java | 7 +++- .../movement/movements/MovementAscend.java | 37 +++++++++++++++++-- .../movement/movements/MovementDescend.java | 12 +++--- .../movement/movements/MovementDiagonal.java | 6 ++- .../movement/movements/MovementDownward.java | 5 +-- .../movement/movements/MovementFall.java | 6 +++ .../movement/movements/MovementPillar.java | 18 ++++++--- .../movement/movements/MovementTraverse.java | 9 +++-- src/main/java/baritone/utils/Helper.java | 8 ++-- 11 files changed, 91 insertions(+), 52 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index fef3c0a5..e52f6a54 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -20,10 +20,7 @@ package baritone.chunk; import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoublePlant; -import net.minecraft.block.BlockFlower; -import net.minecraft.block.BlockTallGrass; +import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -50,10 +47,11 @@ public final class ChunkPacker implements Helper { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int index = CachedChunk.getPositionIndex(x, y, z); - Block block = chunk.getBlockState(x, y, z).getBlock(); - boolean[] bits = getPathingBlockType(block).getBits(); + IBlockState state = chunk.getBlockState(x, y, z); + boolean[] bits = getPathingBlockType(state).getBits(); bitSet.set(index, bits[0]); bitSet.set(index + 1, bits[1]); + Block block = state.getBlock(); if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) { String name = blockToString(block); specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z)); @@ -103,13 +101,14 @@ public final class ChunkPacker implements Helper { return Block.getBlockFromName(name); } - private static PathingBlockType getPathingBlockType(Block block) { + private static PathingBlockType getPathingBlockType(IBlockState state) { + Block block = state.getBlock(); if (block.equals(Blocks.WATER)) { // only water source blocks are plausibly usable, flowing water should be avoid return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER)) { + if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || (block instanceof BlockSlab && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM)) { return PathingBlockType.AVOID; } // We used to do an AABB check here diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 715bfd68..9d2f5869 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -21,13 +21,7 @@ import baritone.Baritone; import baritone.behavior.impl.LookBehavior; import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.MovementState.MovementStatus; -import baritone.pathing.movement.movements.MovementDownward; -import baritone.pathing.movement.movements.MovementPillar; -import baritone.pathing.movement.movements.MovementTraverse; import baritone.utils.*; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -78,21 +72,11 @@ public abstract class Movement implements Helper, MovementHelper { if (cost == null) { if (context == null) context = new CalculationContext(); - cost = calculateCost0(context); + cost = calculateCost(context); } return cost; } - private double calculateCost0(CalculationContext context) { - if (!(this instanceof MovementPillar) && !(this instanceof MovementTraverse) && !(this instanceof MovementDownward)) { - Block fromDown = BlockStateInterface.get(src.down()).getBlock(); - if (fromDown instanceof BlockLadder || fromDown instanceof BlockVine) { - return COST_INF; - } - } - return calculateCost(context); - } - protected abstract double calculateCost(CalculationContext context); public double recalculateCost() { @@ -101,7 +85,7 @@ public abstract class Movement implements Helper, MovementHelper { } public double calculateCostWithoutCaching() { - return calculateCost0(new CalculationContext()); + 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 909c21a7..3b5aa748 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -186,6 +186,9 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean canWalkOn(BlockPos pos, IBlockState state) { Block block = state.getBlock(); + if (block == Blocks.AIR) { + return false; + } if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this return true; } @@ -198,8 +201,8 @@ public interface MovementHelper extends ActionCosts, Helper { if (Blocks.ENDER_CHEST.equals(block) || Blocks.CHEST.equals(block)) { return true; } - if (block instanceof BlockAir) { - return false; + if (block instanceof BlockSlab) { + return true; } if (BlockStateInterface.isWater(block)) { if (BlockStateInterface.isFlowing(state)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index a50dfba8..bc94ca48 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -28,6 +28,7 @@ import baritone.utils.InputOverrideHandler; import baritone.utils.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; @@ -53,7 +54,31 @@ public class MovementAscend extends Movement { @Override protected double calculateCost(CalculationContext context) { + IBlockState srcDown = BlockStateInterface.get(src.down()); + if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) { + return COST_INF; + } + // we can jump from soul sand, but not from a bottom slab + // the only thing we can ascend onto from a bottom slab is another bottom slab + boolean jumpingFromBottomSlab = false; + if (srcDown.getBlock() instanceof BlockSlab) { + BlockSlab jumpingFrom = (BlockSlab) srcDown.getBlock(); + if (!jumpingFrom.isDouble()) { + jumpingFromBottomSlab = srcDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; + } + } IBlockState toPlace = BlockStateInterface.get(positionToPlace); + boolean jumpingToBottomSlab = false; + if (toPlace.getBlock() instanceof BlockSlab) { + BlockSlab jumpingTo = (BlockSlab) toPlace.getBlock(); + if (!jumpingTo.isDouble() && toPlace.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + jumpingToBottomSlab = true; + } else if (jumpingFromBottomSlab) { + return COST_INF; + } + } else if (jumpingFromBottomSlab) { + return COST_INF; + } if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!context.hasThrowaway()) { return COST_INF; @@ -96,9 +121,11 @@ public class MovementAscend extends Movement { // it's possible srcUp is AIR from the start, and srcUp2 is falling // and in that scenario, when we arrive and break srcUp2, that lets srcUp3 fall on us and suffocate us } - // TODO maybe change behavior if src.down() is soul sand? double walk = WALK_ONE_BLOCK_COST; - if (toPlace.getBlock().equals(Blocks.SOUL_SAND)) { + if (jumpingToBottomSlab && !jumpingFromBottomSlab) { + return walk + getTotalHardnessOfBlocksToBreak(context); // we don't hit space we just walk into the slab + } + if (!jumpingToBottomSlab && toPlace.getBlock().equals(Blocks.SOUL_SAND)) { walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST; } // we hit space immediately on entering this action @@ -123,7 +150,8 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.SUCCESS); } - if (!MovementHelper.canWalkOn(positionToPlace)) { + IBlockState jumpingOnto = BlockStateInterface.get(positionToPlace); + if (!MovementHelper.canWalkOn(positionToPlace, jumpingOnto)) { for (int i = 0; i < 4; i++) { BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]); if (anAgainst.equals(src)) { @@ -161,6 +189,9 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); + if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM && !(BlockStateInterface.get(src.down()).getBlock() instanceof BlockSlab)) { + return state; // don't jump while walking from a non slab into a bottom slab + } if (headBonkClear()) { return state.setInput(InputOverrideHandler.Input.JUMP, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 7a07abb1..8ab66af1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -25,8 +25,6 @@ import baritone.pathing.movement.MovementState.MovementStatus; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; @@ -44,18 +42,22 @@ public class MovementDescend extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkOn(positionToPlace)) { return COST_INF; } Block tmp1 = BlockStateInterface.get(dest).getBlock(); - if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) { + if (tmp1 == Blocks.LADDER || tmp1 == Blocks.VINE) { return COST_INF; } // we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) double walk = WALK_OFF_BLOCK_COST; - if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { + if (fromDown == Blocks.SOUL_SAND) { // use this ratio to apply the soul sand speed penalty to our 0.8 block distance - walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST; + walk = WALK_ONE_OVER_SOUL_SAND_COST; } return walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST) + getTotalHardnessOfBlocksToBreak(context); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 1ce5537f..2bf8bdf1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -75,6 +75,10 @@ public class MovementDiagonal extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) { return COST_INF; } @@ -88,7 +92,7 @@ public class MovementDiagonal extends Movement { if (destWalkOn.getBlock().equals(Blocks.SOUL_SAND)) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { + if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } Block cuttingOver1 = BlockStateInterface.get(positionsToBreak[2].down()).getBlock(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index ece2c8f5..13555399 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -23,9 +23,8 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; public class MovementDownward extends Movement { @@ -49,7 +48,7 @@ public class MovementDownward extends Movement { } IBlockState d = BlockStateInterface.get(dest); Block td = d.getBlock(); - boolean ladder = td instanceof BlockLadder || td instanceof BlockVine; + boolean ladder = td == Blocks.LADDER || td == Blocks.VINE; if (ladder) { return LADDER_DOWN_ONE_COST; } else { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index ee019c98..95509574 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -25,7 +25,9 @@ import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; +import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -43,6 +45,10 @@ public class MovementFall extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkOn(dest.down())) { return COST_INF; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index d7ff3016..fecd79ec 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -47,11 +47,16 @@ public class MovementPillar extends Movement { protected double calculateCost(CalculationContext context) { Block fromDown = BlockStateInterface.get(src).getBlock(); boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine; - Block fromDownDown = BlockStateInterface.get(src.down()).getBlock(); + IBlockState fromDownDown = BlockStateInterface.get(src.down()); if (!ladder) { - if (fromDownDown instanceof BlockLadder || fromDownDown instanceof BlockVine) { + if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { return COST_INF; } + if (fromDownDown.getBlock() instanceof BlockSlab) { + if (!((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + return COST_INF; // can't pillar up from a bottom slab onto a non ladder + } + } } if (!context.hasThrowaway() && !ladder) { return COST_INF; @@ -87,7 +92,7 @@ public class MovementPillar extends Movement { //} } } - if (fromDown instanceof BlockLiquid || fromDownDown instanceof BlockLiquid) {//can't pillar on water or in water + if (fromDown instanceof BlockLiquid || fromDownDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water return COST_INF; } if (ladder) { @@ -142,9 +147,12 @@ public class MovementPillar extends Movement { return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } - if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) + if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { return state.setStatus(MovementState.MovementStatus.SUCCESS); - + } + if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + state.setInput(InputOverrideHandler.Input.JUMP, true); + } /* if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) { Baritone.moveTowardsBlock(from); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index a959455b..af0b7b27 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -85,7 +85,7 @@ public class MovementTraverse extends Movement { return WC + hardness1 + hardness2; } else {//this is a bridge, so we need to place a block Block srcDown = BlockStateInterface.get(src.down()).getBlock(); - if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) { + if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { return COST_INF; } if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionToPlace, destOn)) { @@ -107,8 +107,8 @@ public class MovementTraverse extends Movement { return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } } - if (Blocks.SOUL_SAND.equals(srcDown)) { - return COST_INF; // can't sneak and backplace against soul sand =/ + if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && !((BlockSlab) srcDown).isDouble())) { + return COST_INF; // can't sneak and backplace against soul sand or half slabs =/ } WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); @@ -206,7 +206,8 @@ public class MovementTraverse extends Movement { return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } state.setInput(InputOverrideHandler.Input.SNEAK, true); - if (BlockStateInterface.get(playerFeet().down()).getBlock().equals(Blocks.SOUL_SAND)) { // see issue #118 + Block standingOn = BlockStateInterface.get(playerFeet().down()).getBlock(); + if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - player().posX), Math.abs(dest.getZ() + 0.5 - player().posZ)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon MovementHelper.moveTowards(state, dest); diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index c973b1ca..63fc6df7 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import net.minecraft.block.BlockSlab; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; @@ -47,10 +48,11 @@ public interface Helper { default BlockPos playerFeet() { // TODO find a better way to deal with soul sand!!!!! - return new BlockPos(player().posX, player().posY + 0.1251, player().posZ); - /*if (BlockStateInterface.get(feet).getBlock().equals(Blocks.SOUL_SAND) && player().posY > feet.getY() + 0.874999) { + BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ); + if (BlockStateInterface.get(feet).getBlock() instanceof BlockSlab) { return feet.up(); - }*/ + } + return feet; } default Vec3d playerFeetAsVec() { From 16f88aa858c2f7d6a4f2c26f4b6a631be04d1875 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:18:30 -0700 Subject: [PATCH 113/165] setting --- src/main/java/baritone/Settings.java | 6 ++++++ src/main/java/baritone/pathing/movement/MovementHelper.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 78c2d4b3..2e6f0e39 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -77,6 +77,12 @@ public class Settings { */ public Setting allowVines = new Setting<>(false); + /** + * Slab behavior is complicated, disable this for higher path reliability. Leave enabled if you have bottom slabs + * everywhere in your base. + */ + public Setting allowWalkOnBottomSlab = new Setting<>(true); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 3b5aa748..5561f365 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -202,6 +202,12 @@ public interface MovementHelper extends ActionCosts, Helper { 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; + } return true; } if (BlockStateInterface.isWater(block)) { From d328438cf2266097ed3a707af30428073b967b53 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:21:26 -0700 Subject: [PATCH 114/165] no falling onto half slab --- .../pathing/movement/movements/MovementFall.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 95509574..0cb9780a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -27,6 +27,8 @@ import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -49,9 +51,15 @@ public class MovementFall extends Movement { if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { return COST_INF; } - if (!MovementHelper.canWalkOn(dest.down())) { + IBlockState fallOnto = BlockStateInterface.get(dest.down()); + if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) { return COST_INF; } + if (fallOnto.getBlock() instanceof BlockSlab) { + if (!((BlockSlab) fallOnto.getBlock()).isDouble() && fallOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect + } + } double placeBucketCost = 0.0; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { if (!context.hasWaterBucket()) { From 7473e34602a32324714d3d603007b5d78043e040 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:24:44 -0700 Subject: [PATCH 115/165] check for top or double slab --- .../pathing/movement/movements/MovementAscend.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index bc94ca48..46162806 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -189,8 +189,11 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM && !(BlockStateInterface.get(src.down()).getBlock() instanceof BlockSlab)) { - return state; // don't jump while walking from a non slab into a bottom slab + if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + IBlockState from = BlockStateInterface.get(src.down()); + if (!(from.getBlock() instanceof BlockSlab) || ((BlockSlab) from.getBlock()).isDouble() || from.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP) { + return state; // don't jump while walking from a non double slab into a bottom slab + } } if (headBonkClear()) { From 5151c7770365d3cea12742c25fa471094dc3af2d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:25:44 -0700 Subject: [PATCH 116/165] Move badge below header --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63bc2c8b..d69f76e9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ +# Baritone ![](https://travis-ci.com/cabaletta/baritone.svg?branch=master) -# Baritone A Minecraft bot. This project is an updated version of [Minebot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. From 4b2f98ccfd16b29c3d431a91d7f68cf029f165e1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:50:26 -0700 Subject: [PATCH 117/165] consolidate and simplify into MovementHelper.isBottomSlab --- src/main/java/baritone/chunk/ChunkPacker.java | 7 +++-- .../pathing/movement/MovementHelper.java | 10 +++++++ .../movement/movements/MovementAscend.java | 29 +++++-------------- .../movement/movements/MovementFall.java | 7 ++--- .../movement/movements/MovementPillar.java | 2 +- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index e52f6a54..82a36709 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -20,7 +20,10 @@ package baritone.chunk; import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockDoublePlant; +import net.minecraft.block.BlockFlower; +import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -108,7 +111,7 @@ public final class ChunkPacker implements Helper { return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || (block instanceof BlockSlab && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM)) { + if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || MovementHelper.isBottomSlab(state)) { return PathingBlockType.AVOID; } // We used to do an AABB check here diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 5561f365..3e019745 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -270,6 +270,16 @@ public interface MovementHelper extends ActionCosts, Helper { return 0; // we won't actually mine it, so don't check fallings above } + static boolean isBottomSlab(IBlockState state) { + return state.getBlock() instanceof BlockSlab + && !((BlockSlab) state.getBlock()).isDouble() + && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; + } + + static boolean isBottomSlab(BlockPos pos) { + return isBottomSlab(BlockStateInterface.get(pos)); + } + /** * The entity the player is currently looking at * diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 46162806..d666ff6a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -28,7 +28,6 @@ import baritone.utils.InputOverrideHandler; import baritone.utils.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; -import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; @@ -59,25 +58,12 @@ public class MovementAscend extends Movement { return COST_INF; } // we can jump from soul sand, but not from a bottom slab - // the only thing we can ascend onto from a bottom slab is another bottom slab - boolean jumpingFromBottomSlab = false; - if (srcDown.getBlock() instanceof BlockSlab) { - BlockSlab jumpingFrom = (BlockSlab) srcDown.getBlock(); - if (!jumpingFrom.isDouble()) { - jumpingFromBottomSlab = srcDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; - } - } + boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown); IBlockState toPlace = BlockStateInterface.get(positionToPlace); - boolean jumpingToBottomSlab = false; - if (toPlace.getBlock() instanceof BlockSlab) { - BlockSlab jumpingTo = (BlockSlab) toPlace.getBlock(); - if (!jumpingTo.isDouble() && toPlace.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - jumpingToBottomSlab = true; - } else if (jumpingFromBottomSlab) { - return COST_INF; - } - } else if (jumpingFromBottomSlab) { - return COST_INF; + boolean jumpingToBottomSlab = MovementHelper.isBottomSlab(toPlace); + + if (jumpingFromBottomSlab && !jumpingToBottomSlab) { + return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab } if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!context.hasThrowaway()) { @@ -189,9 +175,8 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - IBlockState from = BlockStateInterface.get(src.down()); - if (!(from.getBlock() instanceof BlockSlab) || ((BlockSlab) from.getBlock()).isDouble() || from.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP) { + if (MovementHelper.isBottomSlab(jumpingOnto)) { + if (!MovementHelper.isBottomSlab(src.down())) { return state; // don't jump while walking from a non double slab into a bottom slab } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 0cb9780a..e82640d2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -27,7 +27,6 @@ import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; -import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -55,10 +54,8 @@ public class MovementFall extends Movement { if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) { return COST_INF; } - if (fallOnto.getBlock() instanceof BlockSlab) { - if (!((BlockSlab) fallOnto.getBlock()).isDouble() && fallOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect - } + if (MovementHelper.isBottomSlab(fallOnto)) { + return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect } double placeBucketCost = 0.0; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index fecd79ec..481553fa 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -150,7 +150,7 @@ public class MovementPillar extends Movement { if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { return state.setStatus(MovementState.MovementStatus.SUCCESS); } - if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + if (MovementHelper.isBottomSlab(src.down())) { state.setInput(InputOverrideHandler.Input.JUMP, true); } /* From c2fc241d893fa2ef592324c5f900375e406cf73e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 10:04:48 -0700 Subject: [PATCH 118/165] impact integration instructions --- IMPACT.md | 16 ++++++++++++++++ README.md | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 IMPACT.md diff --git a/IMPACT.md b/IMPACT.md new file mode 100644 index 00000000..52934a64 --- /dev/null +++ b/IMPACT.md @@ -0,0 +1,16 @@ +# Integration between Baritone and Impact + +Baritone will be in Impact 4.4 with nice integrations with its hacks, but if you're impatient you can run Baritone on top of Impact 4.3 right now. + +First, 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. + +Then, copy it into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. + +Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. + +- Add the Baritone tweak class to line 7 "minecraftArguments" like so: `"minecraftArguments": " ... --tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine",`. You need the Optifine tweaker even though there is no Optifine involved, for reasons I don't quite understand. +- Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0" },` between Impact and ClientAPI, which should be between lines 15 and 16. + +Restart the Minecraft launcher, then load Impact 4.3 as normal, and it should now include Baritone. \ No newline at end of file diff --git a/README.md b/README.md index d69f76e9..63d241e4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. Features +Baritone + Impact + # Setup - Open the project in IntelliJ as a Gradle project - Run the Gradle task `setupDecompWorkspace` From b3b9bb8aa523c8df64b1f0b9d88b5ea023735b0a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 10:11:42 -0700 Subject: [PATCH 119/165] prebuilt jar --- IMPACT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IMPACT.md b/IMPACT.md index 52934a64..29b15aea 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -2,11 +2,11 @@ Baritone will be in Impact 4.4 with nice integrations with its hacks, but if you're impatient you can run Baritone on top of Impact 4.3 right now. -First, clone and setup Baritone (instructions in main README.md). +You can either build Baritone yourself, or download the jar from Septmeber 3 from here -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. +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. -Then, copy it into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. +Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. From dcfc7a1bd6c10a2e5710f94f2aed94abcbdaf5ff Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 10:13:11 -0700 Subject: [PATCH 120/165] added note --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index 29b15aea..7e1cc6a4 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -6,7 +6,7 @@ You can either build Baritone yourself, or download the jar from Septmeber 3 fro 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. -Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. +Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. Note the rename from `baritone-1.0.0.jar` to `baritone-1.0.jar`. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. From da67c4aca9075f50a431eeb51eb27b19edaad2dd Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Sep 2018 12:42:00 -0500 Subject: [PATCH 121/165] Make some changes to the Impact installation --- IMPACT.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IMPACT.md b/IMPACT.md index 7e1cc6a4..b57a0dfe 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -2,15 +2,15 @@ Baritone will be in Impact 4.4 with nice integrations with its hacks, 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 Septmeber 3 from here +You can either build Baritone yourself, or download the jar from Steptember 3 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. -Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. Note the rename from `baritone-1.0.0.jar` to `baritone-1.0.jar`. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0/baritone-1.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0` in libraries first. +Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0.0/baritone-1.0.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0.0` in libraries first. Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. - Add the Baritone tweak class to line 7 "minecraftArguments" like so: `"minecraftArguments": " ... --tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine",`. You need the Optifine tweaker even though there is no Optifine involved, for reasons I don't quite understand. -- Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0" },` between Impact and ClientAPI, which should be between lines 15 and 16. +- Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0.0" },` between Impact and ClientAPI, which should be between lines 15 and 16. -Restart the Minecraft launcher, then load Impact 4.3 as normal, and it should now include Baritone. \ No newline at end of file +Restart the Minecraft launcher, then load Impact 4.3 as normal, and it should now include Baritone. From ba7dc46442039fc45d013629bf7b2fb1af95acff Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Sep 2018 12:43:27 -0500 Subject: [PATCH 122/165] Another Impact install update --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index b57a0dfe..44a3fc0a 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -8,7 +8,7 @@ To build it yourself, clone and setup Baritone (instructions in main README.md). Copy the jar into place. It should be `build/libs/baritone-1.0.0.jar` in baritone. Copy it to your libraries in your Minecraft install. For example, on Mac I do `cp Documents/baritone/build/libs/baritone-1.0.0.jar Library/Application\ Support/minecraft/libraries/cabaletta/baritone/1.0.0/baritone-1.0.0.jar`. The first time you'll need to make the directory `cabaletta/baritone/1.0.0` in libraries first. -Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json`. +Then, we'll need to modify the Impact launch json. Open `minecraft/versions/1.12.2-Impact_4.3/1.12.2-Impact_4.3.json` or copy your existing installation and rename the version folder, json, and id in the json. - Add the Baritone tweak class to line 7 "minecraftArguments" like so: `"minecraftArguments": " ... --tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine",`. You need the Optifine tweaker even though there is no Optifine involved, for reasons I don't quite understand. - Add the Baritone library. Insert `{ "name": "cabaletta:baritone:1.0.0" },` between Impact and ClientAPI, which should be between lines 15 and 16. From 53d9d3da5e4360fec52a7e625a39f2333a3aaa4f Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Sep 2018 12:58:21 -0500 Subject: [PATCH 123/165] lol --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index 44a3fc0a..859a2423 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -2,7 +2,7 @@ Baritone will be in Impact 4.4 with nice integrations with its hacks, 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 Steptember 3 from here +You can either build Baritone yourself, or download the jar from September 3 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 bfd41f94734ddf02f0b52be39ccafae96c4949d4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 11:27:59 -0700 Subject: [PATCH 124/165] stairs --- src/main/java/baritone/pathing/movement/MovementHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 3e019745..80026c6f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -210,6 +210,9 @@ public interface MovementHelper extends ActionCosts, Helper { } return true; } + if (block instanceof BlockStairs) { + return true; + } if (BlockStateInterface.isWater(block)) { if (BlockStateInterface.isFlowing(state)) { return false; From 6eb293c97a37f098d67af874e0b428d06d660e8a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 11:33:02 -0700 Subject: [PATCH 125/165] update documentation --- FEATURES.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 8147fc22..436aefc8 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -5,7 +5,8 @@ - **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. - **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). -- **Fence gates and doors** +- **Opening fence gates and doors** +- **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. @@ -35,9 +36,7 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o # Future features Things it doesn't have yet - Trapdoors -- Slabs (double, top, and bottom) - Sprint jumping in a 1x2 corridor -- Stairs See issues for more. From 4690bcb5ac236f596131d28844fa2b4891ca24d9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 11:43:06 -0700 Subject: [PATCH 126/165] add example --- FEATURES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index 8147fc22..d75cca87 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -2,7 +2,7 @@ - **Long distance pathing and splicing** Baritone calculates paths in segments, and precalculates the next segment when the current one is about to end, so that it's moving towards the goal at all times. - **Chunk caching** Baritone simplifies chunks to a compacted internal 2-bit representation (AIR, SOLID, WATER, AVOID) and stores them in RAM for better very-long-distance pathing. There is also an option to save these cached chunks to disk. Example - **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it. -- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. +- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. Example - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. - **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). - **Fence gates and doors** From 574fd05376cbea1b7bf1c46c6fe722813c5ac7ef Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 12:03:49 -0700 Subject: [PATCH 127/165] fix bucket check, fixes #128 --- .../baritone/pathing/movement/movements/MovementFall.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index ee019c98..7061d2f2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -26,6 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; import net.minecraft.block.BlockFalling; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -96,7 +97,7 @@ public class MovementFall extends Movement { BlockPos playerFeet = playerFeet(); Rotation targetRotation = null; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { - if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { + if (!InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) || world().provider.isNether()) { state.setStatus(MovementStatus.UNREACHABLE); return state; } @@ -119,7 +120,7 @@ public class MovementFall extends Movement { } if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.094 // lilypads || BlockStateInterface.isWater(dest))) { - if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) { + 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) { return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); From 53f2ab5901cf143a3b29e869838df51954dba865 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 12:06:58 -0700 Subject: [PATCH 128/165] fix badge link destination --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63d241e4..b95cc957 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Baritone -![](https://travis-ci.com/cabaletta/baritone.svg?branch=master) +[![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone) A Minecraft bot. This project is an updated version of [Minebot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. From dd1a20a04792f0fb1c5d5669fce3bd23142da151 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 16:14:14 -0700 Subject: [PATCH 129/165] final makes things faster --- 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 6e4fc599..ec8891f4 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; * * @author leijurv */ -public class BetterBlockPos extends BlockPos { +public final class BetterBlockPos extends BlockPos { public final int x; public final int y; public final int z; From 07a9829865c47501de76fabac43ffabb7877c2c1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 16:24:43 -0700 Subject: [PATCH 130/165] accurate debug --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index fa8b5076..73442998 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -200,7 +200,7 @@ 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 " + bestDist + " blocks"); + 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 =("); currentlyRunning = null; return Optional.empty(); From bfafca541fc9b2edadde20215883e428d130e837 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 17:01:04 -0700 Subject: [PATCH 131/165] add proguard --- proguard.pro | 360 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 proguard.pro diff --git a/proguard.pro b/proguard.pro new file mode 100644 index 00000000..7e09a64a --- /dev/null +++ b/proguard.pro @@ -0,0 +1,360 @@ +-injars baritone-1.0.0.jar +-outjars Obfuscated + +-libraryjars '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/rt.jar' + +-libraryjars 'tempLibraries/1.12.2.jar' + +-libraryjars 'tempLibraries/authlib-1.5.25.jar' +-libraryjars 'tempLibraries/codecjorbis-20101023.jar' +-libraryjars 'tempLibraries/codecwav-20101023.jar' +-libraryjars 'tempLibraries/commons-codec-1.10.jar' +-libraryjars 'tempLibraries/commons-compress-1.8.1.jar' +-libraryjars 'tempLibraries/commons-io-2.5.jar' +-libraryjars 'tempLibraries/commons-lang3-3.5.jar' +-libraryjars 'tempLibraries/commons-logging-1.1.3.jar' +-libraryjars 'tempLibraries/fastutil-7.1.0.jar' +-libraryjars 'tempLibraries/gson-2.8.0.jar' +-libraryjars 'tempLibraries/guava-21.0.jar' +-libraryjars 'tempLibraries/httpclient-4.3.3.jar' +-libraryjars 'tempLibraries/httpcore-4.3.2.jar' +-libraryjars 'tempLibraries/icu4j-core-mojang-51.2.jar' +-libraryjars 'tempLibraries/java-objc-bridge-1.0.0-natives-osx.jar' +-libraryjars 'tempLibraries/java-objc-bridge-1.0.0.jar' +-libraryjars 'tempLibraries/jinput-2.0.5.jar' +-libraryjars 'tempLibraries/jinput-platform-2.0.5-natives-osx.jar' +-libraryjars 'tempLibraries/jna-4.4.0.jar' +-libraryjars 'tempLibraries/jopt-simple-5.0.3.jar' +-libraryjars 'tempLibraries/jsr305-3.0.1-sources.jar' +-libraryjars 'tempLibraries/jsr305-3.0.1.jar' +-libraryjars 'tempLibraries/jutils-1.0.0.jar' +-libraryjars 'tempLibraries/libraryjavasound-20101123.jar' +-libraryjars 'tempLibraries/librarylwjglopenal-20100824.jar' +-libraryjars 'tempLibraries/log4j-api-2.8.1.jar' +-libraryjars 'tempLibraries/log4j-core-2.8.1.jar' +-libraryjars 'tempLibraries/lwjgl-2.9.2-nightly-20140822.jar' +-libraryjars 'tempLibraries/lwjgl-platform-2.9.2-nightly-20140822-natives-osx.jar' +-libraryjars 'tempLibraries/lwjgl_util-2.9.2-nightly-20140822.jar' +-libraryjars 'tempLibraries/netty-all-4.1.9.Final.jar' +-libraryjars 'tempLibraries/oshi-core-1.1.jar' +-libraryjars 'tempLibraries/patchy-1.1.jar' +-libraryjars 'tempLibraries/platform-3.4.0.jar' +-libraryjars 'tempLibraries/realms-1.10.22.jar' +-libraryjars 'tempLibraries/soundsystem-20120107.jar' +-libraryjars 'tempLibraries/text2speech-1.10.3.jar' + +-libraryjars 'tempLibraries/mixin-0.7.8-SNAPSHOT.jar' +-libraryjars 'tempLibraries/launchwrapper-1.12.jar' + +-keepattributes Signature +-keepattributes *Annotation* + +-optimizationpasses 20 +-verbose + +-allowaccessmodification +-mergeinterfacesaggressively +-overloadaggressively +-flattenpackagehierarchy +-repackageclasses +-dontusemixedcaseclassnames + +-overloadaggressively + +-repackageclasses 'baritone' + +-keep class baritone.behavior.** { *; } +-keep class baritone.api.** { *; } +-keep class baritone.* { *; } +-keep class baritone.pathing.goals.** { *; } + +-keep class baritone.launch.** { *; } + +# Keep - Applications. Keep all application classes, along with their 'main' +# methods. +-keepclasseswithmembers public class * { + public static void main(java.lang.String[]); +} + +# Also keep - Enumerations. Keep the special static methods that are required in +# enumeration classes. +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Also keep - Database drivers. Keep all implementations of java.sql.Driver. +-keep class * extends java.sql.Driver + +# Also keep - Swing UI L&F. Keep all extensions of javax.swing.plaf.ComponentUI, +# along with the special 'createUI' method. +-keep class * extends javax.swing.plaf.ComponentUI { + public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); +} + +# Keep names - Native method names. Keep all native class/method names. +-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * { + native ; +} + +# Remove - System method calls. Remove all invocations of System +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.System { + public static long currentTimeMillis(); + static java.lang.Class getCallerClass(); + public static int identityHashCode(java.lang.Object); + public static java.lang.SecurityManager getSecurityManager(); + public static java.util.Properties getProperties(); + public static java.lang.String getProperty(java.lang.String); + public static java.lang.String getenv(java.lang.String); + public static java.lang.String mapLibraryName(java.lang.String); + public static java.lang.String getProperty(java.lang.String,java.lang.String); +} + +# Remove - Math method calls. Remove all invocations of Math +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.Math { + public static double sin(double); + public static double cos(double); + public static double tan(double); + public static double asin(double); + public static double acos(double); + public static double atan(double); + public static double toRadians(double); + public static double toDegrees(double); + public static double exp(double); + public static double log(double); + public static double log10(double); + public static double sqrt(double); + public static double cbrt(double); + public static double IEEEremainder(double,double); + public static double ceil(double); + public static double floor(double); + public static double rint(double); + public static double atan2(double,double); + public static double pow(double,double); + public static int round(float); + public static long round(double); + public static double random(); + public static int abs(int); + public static long abs(long); + public static float abs(float); + public static double abs(double); + public static int max(int,int); + public static long max(long,long); + public static float max(float,float); + public static double max(double,double); + public static int min(int,int); + public static long min(long,long); + public static float min(float,float); + public static double min(double,double); + public static double ulp(double); + public static float ulp(float); + public static double signum(double); + public static float signum(float); + public static double sinh(double); + public static double cosh(double); + public static double tanh(double); + public static double hypot(double,double); + public static double expm1(double); + public static double log1p(double); +} + +# Remove - Number method calls. Remove all invocations of Number +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.* extends java.lang.Number { + public static java.lang.String toString(byte); + public static java.lang.Byte valueOf(byte); + public static byte parseByte(java.lang.String); + public static byte parseByte(java.lang.String,int); + public static java.lang.Byte valueOf(java.lang.String,int); + public static java.lang.Byte valueOf(java.lang.String); + public static java.lang.Byte decode(java.lang.String); + public int compareTo(java.lang.Byte); + public static java.lang.String toString(short); + public static short parseShort(java.lang.String); + public static short parseShort(java.lang.String,int); + public static java.lang.Short valueOf(java.lang.String,int); + public static java.lang.Short valueOf(java.lang.String); + public static java.lang.Short valueOf(short); + public static java.lang.Short decode(java.lang.String); + public static short reverseBytes(short); + public int compareTo(java.lang.Short); + public static java.lang.String toString(int,int); + public static java.lang.String toHexString(int); + public static java.lang.String toOctalString(int); + public static java.lang.String toBinaryString(int); + public static java.lang.String toString(int); + public static int parseInt(java.lang.String,int); + public static int parseInt(java.lang.String); + public static java.lang.Integer valueOf(java.lang.String,int); + public static java.lang.Integer valueOf(java.lang.String); + public static java.lang.Integer valueOf(int); + public static java.lang.Integer getInteger(java.lang.String); + public static java.lang.Integer getInteger(java.lang.String,int); + public static java.lang.Integer getInteger(java.lang.String,java.lang.Integer); + public static java.lang.Integer decode(java.lang.String); + public static int highestOneBit(int); + public static int lowestOneBit(int); + public static int numberOfLeadingZeros(int); + public static int numberOfTrailingZeros(int); + public static int bitCount(int); + public static int rotateLeft(int,int); + public static int rotateRight(int,int); + public static int reverse(int); + public static int signum(int); + public static int reverseBytes(int); + public int compareTo(java.lang.Integer); + public static java.lang.String toString(long,int); + public static java.lang.String toHexString(long); + public static java.lang.String toOctalString(long); + public static java.lang.String toBinaryString(long); + public static java.lang.String toString(long); + public static long parseLong(java.lang.String,int); + public static long parseLong(java.lang.String); + public static java.lang.Long valueOf(java.lang.String,int); + public static java.lang.Long valueOf(java.lang.String); + public static java.lang.Long valueOf(long); + public static java.lang.Long decode(java.lang.String); + public static java.lang.Long getLong(java.lang.String); + public static java.lang.Long getLong(java.lang.String,long); + public static java.lang.Long getLong(java.lang.String,java.lang.Long); + public static long highestOneBit(long); + public static long lowestOneBit(long); + public static int numberOfLeadingZeros(long); + public static int numberOfTrailingZeros(long); + public static int bitCount(long); + public static long rotateLeft(long,int); + public static long rotateRight(long,int); + public static long reverse(long); + public static int signum(long); + public static long reverseBytes(long); + public int compareTo(java.lang.Long); + public static java.lang.String toString(float); + public static java.lang.String toHexString(float); + public static java.lang.Float valueOf(java.lang.String); + public static java.lang.Float valueOf(float); + public static float parseFloat(java.lang.String); + public static boolean isNaN(float); + public static boolean isInfinite(float); + public static int floatToIntBits(float); + public static int floatToRawIntBits(float); + public static float intBitsToFloat(int); + public static int compare(float,float); + public boolean isNaN(); + public boolean isInfinite(); + public int compareTo(java.lang.Float); + public static java.lang.String toString(double); + public static java.lang.String toHexString(double); + public static java.lang.Double valueOf(java.lang.String); + public static java.lang.Double valueOf(double); + public static double parseDouble(java.lang.String); + public static boolean isNaN(double); + public static boolean isInfinite(double); + public static long doubleToLongBits(double); + public static long doubleToRawLongBits(double); + public static double longBitsToDouble(long); + public static int compare(double,double); + public boolean isNaN(); + public boolean isInfinite(); + public int compareTo(java.lang.Double); + public byte byteValue(); + public short shortValue(); + public int intValue(); + public long longValue(); + public float floatValue(); + public double doubleValue(); + public int compareTo(java.lang.Object); + public boolean equals(java.lang.Object); + public int hashCode(); + public java.lang.String toString(); +} + +# Remove - String method calls. Remove all invocations of String +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.String { + public static java.lang.String copyValueOf(char[]); + public static java.lang.String copyValueOf(char[],int,int); + public static java.lang.String valueOf(boolean); + public static java.lang.String valueOf(char); + public static java.lang.String valueOf(char[]); + public static java.lang.String valueOf(char[],int,int); + public static java.lang.String valueOf(double); + public static java.lang.String valueOf(float); + public static java.lang.String valueOf(int); + public static java.lang.String valueOf(java.lang.Object); + public static java.lang.String valueOf(long); + public boolean contentEquals(java.lang.StringBuffer); + public boolean endsWith(java.lang.String); + public boolean equalsIgnoreCase(java.lang.String); + public boolean equals(java.lang.Object); + public boolean matches(java.lang.String); + public boolean regionMatches(boolean,int,java.lang.String,int,int); + public boolean regionMatches(int,java.lang.String,int,int); + public boolean startsWith(java.lang.String); + public boolean startsWith(java.lang.String,int); + public byte[] getBytes(); + public byte[] getBytes(java.lang.String); + public char charAt(int); + public char[] toCharArray(); + public int compareToIgnoreCase(java.lang.String); + public int compareTo(java.lang.Object); + public int compareTo(java.lang.String); + public int hashCode(); + public int indexOf(int); + public int indexOf(int,int); + public int indexOf(java.lang.String); + public int indexOf(java.lang.String,int); + public int lastIndexOf(int); + public int lastIndexOf(int,int); + public int lastIndexOf(java.lang.String); + public int lastIndexOf(java.lang.String,int); + public int length(); + public java.lang.CharSequence subSequence(int,int); + public java.lang.String concat(java.lang.String); + public java.lang.String replaceAll(java.lang.String,java.lang.String); + public java.lang.String replace(char,char); + public java.lang.String replaceFirst(java.lang.String,java.lang.String); + public java.lang.String[] split(java.lang.String); + public java.lang.String[] split(java.lang.String,int); + public java.lang.String substring(int); + public java.lang.String substring(int,int); + public java.lang.String toLowerCase(); + public java.lang.String toLowerCase(java.util.Locale); + public java.lang.String toString(); + public java.lang.String toUpperCase(); + public java.lang.String toUpperCase(java.util.Locale); + public java.lang.String trim(); +} + +# Remove - StringBuffer method calls. Remove all invocations of StringBuffer +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.StringBuffer { + public java.lang.String toString(); + public char charAt(int); + public int capacity(); + public int codePointAt(int); + public int codePointBefore(int); + public int indexOf(java.lang.String,int); + public int lastIndexOf(java.lang.String); + public int lastIndexOf(java.lang.String,int); + public int length(); + public java.lang.String substring(int); + public java.lang.String substring(int,int); +} + +# Remove - StringBuilder method calls. Remove all invocations of StringBuilder +# methods without side effects whose return values are not used. +-assumenosideeffects public class java.lang.StringBuilder { + public java.lang.String toString(); + public char charAt(int); + public int capacity(); + public int codePointAt(int); + public int codePointBefore(int); + public int indexOf(java.lang.String,int); + public int lastIndexOf(java.lang.String); + public int lastIndexOf(java.lang.String,int); + public int length(); + public java.lang.String substring(int); + public java.lang.String substring(int,int); +} From a2f0a1839a870d9e1f4e48de40ab817899ce88c2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 20:42:28 -0700 Subject: [PATCH 132/165] fix goal get to block --- .../pathing/goals/GoalGetToBlock.java | 43 ++++++++++------ .../pathing/goals/GoalGetToBlockTest.java | 49 +++++++++++++++++++ 2 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index 9c847918..ed927a12 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -17,32 +17,47 @@ package baritone.pathing.goals; -import net.minecraft.util.EnumFacing; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; + /** * Don't get into the block, but get directly adjacent to it. Useful for chests. * * @author avecowa */ -public class GoalGetToBlock extends GoalComposite { +public class GoalGetToBlock implements Goal { - private final BlockPos pos; + private final int x; + private final int y; + private final int z; public GoalGetToBlock(BlockPos pos) { - super(adjacentBlocks(pos)); - this.pos = pos; - } - - private static BlockPos[] adjacentBlocks(BlockPos pos) { - BlockPos[] sides = new BlockPos[6]; - for (int i = 0; i < 6; i++) { - sides[i] = pos.offset(EnumFacing.values()[i]); - } - return sides; + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); } public BlockPos getGoalPos() { - return pos; + return new BetterBlockPos(x, y, z); + } + + @Override + public boolean isInGoal(BlockPos pos) { + int xDiff = pos.getX() - this.x; + int yDiff = pos.getY() - this.y; + int zDiff = pos.getZ() - this.z; + if (yDiff == -2 && xDiff == 0 && zDiff == 0) { + return true; + } + return Math.abs(xDiff) + Math.abs(yDiff) + Math.abs(zDiff) <= 1; + } + + @Override + public double heuristic(BlockPos pos) { + int xDiff = pos.getX() - this.x; + int yDiff = pos.getY() - this.y; + int zDiff = pos.getZ() - this.z; + return GoalBlock.calculate(xDiff, yDiff, zDiff); } } diff --git a/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java new file mode 100644 index 00000000..3c3905aa --- /dev/null +++ b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java @@ -0,0 +1,49 @@ +/* + * 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.goals; + +import net.minecraft.util.math.BlockPos; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertTrue; + +public class GoalGetToBlockTest { + + @Test + public void isInGoal() { + List acceptableOffsets = new ArrayList<>(Arrays.asList("0,0,0", "0,0,1", "0,0,-1", "1,0,0", "-1,0,0", "0,1,0", "0,-1,0", "0,-2,0")); + for (int x = -10; x <= 10; x++) { + for (int y = -10; y <= 10; y++) { + for (int z = -10; z <= 10; z++) { + boolean inGoal = new GoalGetToBlock(new BlockPos(0, 0, 0)).isInGoal(new BlockPos(x, y, z)); + String repr = x + "," + y + "," + z; + System.out.println(repr + " " + inGoal); + if (inGoal) { + assertTrue(repr, acceptableOffsets.contains(repr)); + acceptableOffsets.remove(repr); + } + } + } + } + assertTrue(acceptableOffsets.toString(), acceptableOffsets.isEmpty()); + } +} \ No newline at end of file From 5cfb270a32f36910d5219c4a2718a29519aa5f60 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 08:48:55 -0700 Subject: [PATCH 133/165] update proguard --- proguard.pro | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/proguard.pro b/proguard.pro index 7e09a64a..7f0cfcdc 100644 --- a/proguard.pro +++ b/proguard.pro @@ -1,6 +1,36 @@ -injars baritone-1.0.0.jar -outjars Obfuscated + +-keepattributes Signature +-keepattributes *Annotation* + +-optimizationpasses 20 +-verbose + +-allowaccessmodification # anything not kept can be changed from public to private and inlined etc +-mergeinterfacesaggressively +-overloadaggressively +-dontusemixedcaseclassnames + +# instead of obfing to a, b, c, obf to baritone.a, baritone.b, baritone.c so as to not conflict with mcp +-flattenpackagehierarchy +-repackageclasses 'baritone' + +#-keep class baritone.behavior.** { *; } +#-keep class baritone.api.** { *; } +#-keep class baritone.* { *; } +#-keep class baritone.pathing.goals.** { *; } + +# setting names are reflected from field names, so keep field names +-keepclassmembers class baritone.Settings { + public ; +} + +# need to keep mixin names +-keep class baritone.launch.** { *; } + +# copy all necessary libraries into tempLibraries to build -libraryjars '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/rt.jar' -libraryjars 'tempLibraries/1.12.2.jar' @@ -46,29 +76,8 @@ -libraryjars 'tempLibraries/mixin-0.7.8-SNAPSHOT.jar' -libraryjars 'tempLibraries/launchwrapper-1.12.jar' --keepattributes Signature --keepattributes *Annotation* --optimizationpasses 20 --verbose --allowaccessmodification --mergeinterfacesaggressively --overloadaggressively --flattenpackagehierarchy --repackageclasses --dontusemixedcaseclassnames - --overloadaggressively - --repackageclasses 'baritone' - --keep class baritone.behavior.** { *; } --keep class baritone.api.** { *; } --keep class baritone.* { *; } --keep class baritone.pathing.goals.** { *; } - --keep class baritone.launch.** { *; } # Keep - Applications. Keep all application classes, along with their 'main' # methods. From 2452a69089af1ae7b04248163c04c3114b2b5bca Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 08:50:42 -0700 Subject: [PATCH 134/165] mine many block types at once --- .../java/baritone/behavior/impl/MineBehavior.java | 14 +++++++++----- .../baritone/utils/ExampleBaritoneControl.java | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 32f92877..f34aa480 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -44,7 +45,7 @@ public class MineBehavior extends Behavior { private MineBehavior() { } - String mining; + List mining; @Override public void onTick(TickEvent event) { @@ -54,14 +55,17 @@ public class MineBehavior extends Behavior { if (mining == null) { return; } - List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1)); + List locs = new ArrayList<>(); + for (String m : mining) { + locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1)); + } BlockPos playerFeet = playerFeet(); locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); // remove any that are within loaded chunks that aren't actually what we want locs.removeAll(locs.stream() .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) - .filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining)) + .filter(pos -> !mining.contains(ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).toLowerCase())) .collect(Collectors.toList())); if (locs.size() > 30) { locs = locs.subList(0, 30); @@ -75,8 +79,8 @@ public class MineBehavior extends Behavior { PathingBehavior.INSTANCE.path(); } - public void mine(String mining) { - this.mining = mining; + public void mine(String... mining) { + this.mining = new ArrayList<>(Arrays.asList(mining)); } public void cancel() { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 75a36994..5bc75d3f 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -189,8 +189,8 @@ public class ExampleBaritoneControl extends Behavior { } if (msg.toLowerCase().startsWith("mine")) { String blockType = msg.toLowerCase().substring(4).trim(); - MineBehavior.INSTANCE.mine(blockType); - displayChatMessageRaw("Started mining blocks of type " + blockType); + MineBehavior.INSTANCE.mine(blockType.split(" ")); + displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockType.split(" "))); event.cancel(); return; } From f51bcc8b8919709139670f541d96918676eb7a32 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 08:51:58 -0700 Subject: [PATCH 135/165] forgot null check --- src/main/java/baritone/behavior/impl/MineBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index f34aa480..1e1fdb08 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -80,7 +80,7 @@ public class MineBehavior extends Behavior { } public void mine(String... mining) { - this.mining = new ArrayList<>(Arrays.asList(mining)); + this.mining = mining == null ? null : new ArrayList<>(Arrays.asList(mining)); } public void cancel() { From 438392840b75c5296e8c580e245d33563cbf3ab5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 08:56:34 -0700 Subject: [PATCH 136/165] possible fix to concurrentmodificationexception on path start --- src/main/java/baritone/Baritone.java | 2 ++ src/main/java/baritone/utils/ToolSet.java | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 5baacec8..0b571264 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,6 +21,7 @@ import baritone.api.event.GameEventHandler; import baritone.behavior.Behavior; import baritone.behavior.impl.*; import baritone.utils.InputOverrideHandler; +import baritone.utils.ToolSet; import net.minecraft.client.Minecraft; import java.io.File; @@ -81,6 +82,7 @@ public enum Baritone { registerBehavior(LocationTrackingBehavior.INSTANCE); registerBehavior(FollowBehavior.INSTANCE); registerBehavior(MineBehavior.INSTANCE); + this.gameEventHandler.registerEventListener(ToolSet.INTERNAL_EVENT_LISTENER); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 415d8ebd..ce24b708 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -17,7 +17,6 @@ package baritone.utils; -import baritone.Baritone; import baritone.api.event.events.ItemSlotEvent; import baritone.api.event.listener.AbstractGameEventListener; import net.minecraft.block.Block; @@ -46,11 +45,7 @@ public class ToolSet implements Helper { /** * Instance of the internal event listener used to hook into Baritone's event bus */ - private static final InternalEventListener INTERNAL_EVENT_LISTENER = new InternalEventListener(); - - static { - Baritone.INSTANCE.getGameEventHandler().registerEventListener(INTERNAL_EVENT_LISTENER); - } + public static final InternalEventListener INTERNAL_EVENT_LISTENER = new InternalEventListener(); /** * A list of tools on the hotbar that should be considered. From 424113f052d8612c79db6c03a0b8db65688e5609 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 09:55:56 -0700 Subject: [PATCH 137/165] don't sprint if hunger is too low --- src/main/java/baritone/pathing/path/PathExecutor.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 88ca6e30..818f9bbb 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -19,10 +19,7 @@ package baritone.pathing.path; import baritone.Baritone; import baritone.api.event.events.TickEvent; -import baritone.pathing.movement.ActionCosts; -import baritone.pathing.movement.Movement; -import baritone.pathing.movement.MovementHelper; -import baritone.pathing.movement.MovementState; +import baritone.pathing.movement.*; import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementDiagonal; import baritone.pathing.movement.movements.MovementFall; @@ -274,7 +271,7 @@ public class PathExecutor implements Helper { } private void sprintIfRequested() { - if (!Baritone.settings().allowSprint.get()) { + if (!new CalculationContext().canSprint()) { player().setSprinting(false); return; } From ebd4930fe476dcd740e24536a4b8759c680fe3bf Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 09:57:19 -0700 Subject: [PATCH 138/165] fix horrendous typo --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index 859a2423..95faedc6 100644 --- a/IMPACT.md +++ b/IMPACT.md @@ -1,6 +1,6 @@ # Integration between Baritone and Impact -Baritone will be in Impact 4.4 with nice integrations with its hacks, but if you're impatient you can run Baritone on top of Impact 4.3 right now. +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 3 from here From 3fd1063e3c43e5fdeaf2028cb5e9af1478dd0f7b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 10:06:48 -0700 Subject: [PATCH 139/165] cache on block not blockstate --- src/main/java/baritone/utils/ToolSet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 415d8ebd..a5684280 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -72,10 +72,10 @@ public class ToolSet implements Helper { private Map slotCache = new HashMap<>(); /** - * A cache mapping a {@link IBlockState} to how long it will take to break + * A cache mapping a {@link Block} to how long it will take to break * with this toolset, given the optimum tool is used. */ - private Map breakStrengthCache = new HashMap<>(); + private Map breakStrengthCache = new HashMap<>(); /** * Create a toolset from the current player's inventory (but don't calculate any hardness values just yet) @@ -146,7 +146,7 @@ public class ToolSet implements Helper { * @return how long it would take in ticks */ public double getStrVsBlock(IBlockState state, BlockPos pos) { - return this.breakStrengthCache.computeIfAbsent(state, s -> calculateStrVsBlock(s, pos)); + return this.breakStrengthCache.computeIfAbsent(state.getBlock(), b -> calculateStrVsBlock(state, pos)); } /** From 288e57d275a90b78ba32f5de61450a15a99cd988 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 13:20:49 -0700 Subject: [PATCH 140/165] fix warning --- src/main/java/baritone/behavior/impl/MineBehavior.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 1e1fdb08..185cacd2 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -80,11 +80,11 @@ public class MineBehavior extends Behavior { } public void mine(String... mining) { - this.mining = mining == null ? null : new ArrayList<>(Arrays.asList(mining)); + this.mining = mining == null || mining.length == 0 ? null : new ArrayList<>(Arrays.asList(mining)); } public void cancel() { PathingBehavior.INSTANCE.cancel(); - mine(null); + mine(); } } From 9f156e8e2797cd4b4ad94745f0cf1617f868a99c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 13:23:26 -0700 Subject: [PATCH 141/165] updated dropbox file name and link --- IMPACT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMPACT.md b/IMPACT.md index 95faedc6..7fa22435 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 3 from here +You can either build Baritone yourself, or download the jar from September 4 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 0bd3f9f68010861c38cae7af1f2bb650210c707f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 13:57:56 -0700 Subject: [PATCH 142/165] fix water fall logic --- .../java/baritone/pathing/movement/MovementHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 80026c6f..82b20c41 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -214,13 +214,14 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } if (BlockStateInterface.isWater(block)) { - if (BlockStateInterface.isFlowing(state)) { - return false; - } Block up = BlockStateInterface.get(pos.up()).getBlock(); if (up instanceof BlockLilyPad) { return true; } + if (BlockStateInterface.isFlowing(state)) { + // the only scenario in which we can walk on flowing water is if it's under still water with jesus off + return BlockStateInterface.isWater(up) && !Baritone.settings().assumeWalkOnWater.get(); + } // if assumeWalkOnWater is on, we can only walk on water if there isn't water above it // if assumeWalkOnWater is off, we can only walk on water if there is water above it return BlockStateInterface.isWater(up) ^ Baritone.settings().assumeWalkOnWater.get(); From 7cc23bc89bb12e3e718453397cacaa92cb1b7cda Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:03:59 -0700 Subject: [PATCH 143/165] scan for uninteresting blocks in loaded chunks, fixes #99 --- .../baritone/behavior/impl/MineBehavior.java | 43 ++++++--- .../java/baritone/chunk/WorldScanner.java | 92 +++++++++++++++++++ .../utils/ExampleBaritoneControl.java | 32 +++---- 3 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 src/main/java/baritone/chunk/WorldScanner.java diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 185cacd2..bbd1c594 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -19,8 +19,10 @@ package baritone.behavior.impl; import baritone.api.event.events.TickEvent; import baritone.behavior.Behavior; +import baritone.chunk.CachedChunk; import baritone.chunk.ChunkPacker; import baritone.chunk.WorldProvider; +import baritone.chunk.WorldScanner; import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; @@ -55,21 +57,7 @@ public class MineBehavior extends Behavior { if (mining == null) { return; } - List locs = new ArrayList<>(); - for (String m : mining) { - locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1)); - } - BlockPos playerFeet = playerFeet(); - locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); - - // remove any that are within loaded chunks that aren't actually what we want - locs.removeAll(locs.stream() - .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) - .filter(pos -> !mining.contains(ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).toLowerCase())) - .collect(Collectors.toList())); - if (locs.size() > 30) { - locs = locs.subList(0, 30); - } + List locs = scanFor(mining, 64); if (locs.isEmpty()) { displayChatMessageRaw("No locations for " + mining + " known, cancelling"); cancel(); @@ -79,6 +67,31 @@ public class MineBehavior extends Behavior { PathingBehavior.INSTANCE.path(); } + public static List scanFor(List mining, int max) { + List locs = new ArrayList<>(); + List uninteresting = new ArrayList<>(); + for (String m : mining) { + if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(ChunkPacker.stringToBlock(m))) { + locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1)); + } else { + uninteresting.add(m); + } + } + locs.addAll(WorldScanner.INSTANCE.scanLoadedChunks(uninteresting, max)); + BlockPos playerFeet = MineBehavior.INSTANCE.playerFeet(); + locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); + + // remove any that are within loaded chunks that aren't actually what we want + locs.removeAll(locs.stream() + .filter(pos -> !(MineBehavior.INSTANCE.world().getChunk(pos) instanceof EmptyChunk)) + .filter(pos -> !mining.contains(ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).toLowerCase())) + .collect(Collectors.toList())); + if (locs.size() > max) { + locs = locs.subList(0, max); + } + return locs; + } + public void mine(String... mining) { this.mining = mining == null || mining.length == 0 ? null : new ArrayList<>(Arrays.asList(mining)); } diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java new file mode 100644 index 00000000..62e20944 --- /dev/null +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -0,0 +1,92 @@ +/* + * 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.chunk; + +import baritone.utils.Helper; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.multiplayer.ChunkProviderClient; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.BlockStateContainer; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; + +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +public enum WorldScanner implements Helper { + INSTANCE; + + public List scanLoadedChunks(List blockTypes, int max) { + List asBlocks = blockTypes.stream().map(ChunkPacker::stringToBlock).collect(Collectors.toList()); + if (asBlocks.contains(null)) { + throw new IllegalStateException("Invalid block name should have been caught earlier: " + blockTypes.toString()); + } + LinkedList res = new LinkedList<>(); + ChunkProviderClient chunkProvider = world().getChunkProvider(); + + int playerChunkX = playerFeet().getX() >> 4; + int playerChunkZ = playerFeet().getZ() >> 4; + + int searchRadius = 0; + while (true) { + boolean allUnloaded = true; + for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) { + for (int zoff = -searchRadius; zoff <= searchRadius; zoff++) { + int distance = xoff * xoff + zoff * zoff; + if (distance != searchRadius) { + continue; + } + int chunkX = xoff + playerChunkX; + int chunkZ = zoff + playerChunkZ; + Chunk chunk = chunkProvider.getLoadedChunk(chunkX, chunkZ); + if (chunk == null) { + continue; + } + allUnloaded = false; + ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + for (int y0 = 0; y0 < 16; y0++) { + ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; + if (extendedblockstorage == null) { + continue; + } + BlockStateContainer bsc = extendedblockstorage.getData(); + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + IBlockState state = bsc.get(x, y, z); + if (asBlocks.contains(state.getBlock())) { + res.add(new BlockPos(chunkX * 16 + x, y0 * 16 + y, chunkZ * 16 + z)); + } + } + } + } + } + } + } + if (allUnloaded) { + return res; + } + if (res.size() >= max) { + return res; + } + searchRadius++; + } + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 5bc75d3f..16dabf4f 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -38,10 +38,8 @@ import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; import java.util.*; -import java.util.stream.Collectors; public class ExampleBaritoneControl extends Behavior { public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl(); @@ -188,9 +186,16 @@ public class ExampleBaritoneControl extends Behavior { return; } if (msg.toLowerCase().startsWith("mine")) { - String blockType = msg.toLowerCase().substring(4).trim(); - MineBehavior.INSTANCE.mine(blockType.split(" ")); - displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockType.split(" "))); + 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"); + event.cancel(); + return; + } + } + MineBehavior.INSTANCE.mine(blockTypes); + displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes)); event.cancel(); return; } @@ -235,21 +240,14 @@ public class ExampleBaritoneControl extends Behavior { String mining = waypointType; //displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); - List locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1)); - if (locs.isEmpty()) { + if (ChunkPacker.stringToBlock(mining) == null) { displayChatMessageRaw("No locations for " + mining + " known, cancelling"); return; } - BlockPos playerFeet = playerFeet(); - locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); - - // remove any that are within loaded chunks that aren't actually what we want - locs.removeAll(locs.stream() - .filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk)) - .filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining)) - .collect(Collectors.toList())); - if (locs.size() > 30) { - locs = locs.subList(0, 30); + List locs = MineBehavior.scanFor(Arrays.asList(mining), 64); + if (locs.isEmpty()) { + displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + return; } PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new))); PathingBehavior.INSTANCE.path(); From 4f07d655d6b88247c811a14961b8366c63e3f704 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:08:21 -0700 Subject: [PATCH 144/165] don't scan empty --- src/main/java/baritone/behavior/impl/MineBehavior.java | 8 +++++++- src/main/java/baritone/chunk/WorldScanner.java | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index bbd1c594..d4b09b7b 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -70,6 +70,7 @@ public class MineBehavior extends Behavior { public static List scanFor(List mining, int max) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); + //long b = System.currentTimeMillis(); for (String m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(ChunkPacker.stringToBlock(m))) { locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1)); @@ -77,7 +78,12 @@ public class MineBehavior extends Behavior { uninteresting.add(m); } } - locs.addAll(WorldScanner.INSTANCE.scanLoadedChunks(uninteresting, max)); + //System.out.println("Scan of cached chunks took " + (System.currentTimeMillis() - b) + "ms"); + if (!uninteresting.isEmpty()) { + //long before = System.currentTimeMillis(); + locs.addAll(WorldScanner.INSTANCE.scanLoadedChunks(uninteresting, max)); + //System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms"); + } BlockPos playerFeet = MineBehavior.INSTANCE.playerFeet(); locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index 62e20944..fe3c0ea5 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -39,6 +39,9 @@ public enum WorldScanner implements Helper { throw new IllegalStateException("Invalid block name should have been caught earlier: " + blockTypes.toString()); } LinkedList res = new LinkedList<>(); + if (asBlocks.isEmpty()) { + return res; + } ChunkProviderClient chunkProvider = world().getChunkProvider(); int playerChunkX = playerFeet().getX() >> 4; From 8c9bb85d4b5982f1962dba52a4388d2a8882b164 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 4 Sep 2018 17:18:30 -0500 Subject: [PATCH 145/165] Fully separate dependency on launch package from other packages --- .../java/baritone/chunk/WorldProvider.java | 4 +- .../launch/mixins/MixinAnvilChunkLoader.java | 41 +++++++++++++++++++ .../mixins/MixinChunkProviderServer.java | 40 ++++++++++++++++++ .../accessor/IAnvilChunkLoader.java | 9 +--- .../accessor/IChunkProviderServer.java | 8 +--- src/main/resources/mixins.baritone.json | 7 ++-- 6 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java create mode 100644 src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java rename src/main/java/baritone/{launch/mixins => utils}/accessor/IAnvilChunkLoader.java (74%) rename src/main/java/baritone/{launch/mixins => utils}/accessor/IChunkProviderServer.java (76%) diff --git a/src/main/java/baritone/chunk/WorldProvider.java b/src/main/java/baritone/chunk/WorldProvider.java index 709ddff8..275b6ac1 100644 --- a/src/main/java/baritone/chunk/WorldProvider.java +++ b/src/main/java/baritone/chunk/WorldProvider.java @@ -18,8 +18,8 @@ package baritone.chunk; import baritone.Baritone; -import baritone.launch.mixins.accessor.IAnvilChunkLoader; -import baritone.launch.mixins.accessor.IChunkProviderServer; +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; diff --git a/src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java b/src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java new file mode 100644 index 00000000..96f38b87 --- /dev/null +++ b/src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java @@ -0,0 +1,41 @@ +/* + * 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.utils.accessor.IAnvilChunkLoader; +import net.minecraft.world.chunk.storage.AnvilChunkLoader; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.io.File; + +/** + * @author Brady + * @since 9/4/2018 + */ +@Mixin(AnvilChunkLoader.class) +public class MixinAnvilChunkLoader implements IAnvilChunkLoader { + + @Shadow @Final private File chunkSaveLocation; + + @Override + public File getChunkSaveLocation() { + return this.chunkSaveLocation; + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java b/src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java new file mode 100644 index 00000000..9a454d01 --- /dev/null +++ b/src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java @@ -0,0 +1,40 @@ +/* + * 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.utils.accessor.IChunkProviderServer; +import net.minecraft.world.chunk.storage.IChunkLoader; +import net.minecraft.world.gen.ChunkProviderServer; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +/** + * @author Brady + * @since 9/4/2018 + */ +@Mixin(ChunkProviderServer.class) +public class MixinChunkProviderServer implements IChunkProviderServer { + + @Shadow @Final private IChunkLoader chunkLoader; + + @Override + public IChunkLoader getChunkLoader() { + return this.chunkLoader; + } +} diff --git a/src/main/java/baritone/launch/mixins/accessor/IAnvilChunkLoader.java b/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java similarity index 74% rename from src/main/java/baritone/launch/mixins/accessor/IAnvilChunkLoader.java rename to src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java index 3972ff32..900e3fb4 100644 --- a/src/main/java/baritone/launch/mixins/accessor/IAnvilChunkLoader.java +++ b/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java @@ -15,11 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.launch.mixins.accessor; - -import net.minecraft.world.chunk.storage.AnvilChunkLoader; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +package baritone.utils.accessor; import java.io.File; @@ -27,8 +23,7 @@ import java.io.File; * @author Brady * @since 8/4/2018 11:36 AM */ -@Mixin(AnvilChunkLoader.class) public interface IAnvilChunkLoader { - @Accessor File getChunkSaveLocation(); + File getChunkSaveLocation(); } diff --git a/src/main/java/baritone/launch/mixins/accessor/IChunkProviderServer.java b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java similarity index 76% rename from src/main/java/baritone/launch/mixins/accessor/IChunkProviderServer.java rename to src/main/java/baritone/utils/accessor/IChunkProviderServer.java index 460014fc..bb3dcb5e 100644 --- a/src/main/java/baritone/launch/mixins/accessor/IChunkProviderServer.java +++ b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java @@ -15,19 +15,15 @@ * along with Baritone. If not, see . */ -package baritone.launch.mixins.accessor; +package baritone.utils.accessor; import net.minecraft.world.chunk.storage.IChunkLoader; -import net.minecraft.world.gen.ChunkProviderServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; /** * @author Brady * @since 8/4/2018 11:33 AM */ -@Mixin(ChunkProviderServer.class) public interface IChunkProviderServer { - @Accessor IChunkLoader getChunkLoader(); + IChunkLoader getChunkLoader(); } diff --git a/src/main/resources/mixins.baritone.json b/src/main/resources/mixins.baritone.json index c0b5d3bb..989c9355 100755 --- a/src/main/resources/mixins.baritone.json +++ b/src/main/resources/mixins.baritone.json @@ -8,7 +8,9 @@ "maxShiftBy": 2 }, "client": [ + "MixinAnvilChunkLoader", "MixinBlockPos", + "MixinChunkProviderServer", "MixinEntity", "MixinEntityPlayerSP", "MixinEntityRenderer", @@ -20,9 +22,6 @@ "MixinMinecraft", "MixinNetHandlerPlayClient", "MixinNetworkManager", - "MixinWorldClient", - - "accessor.IAnvilChunkLoader", - "accessor.IChunkProviderServer" + "MixinWorldClient" ] } \ No newline at end of file From e7d41ba4fc9a95a38a26997e25206351c7d809db Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:18:51 -0700 Subject: [PATCH 146/165] optimize chunk packer with extended block storage --- src/main/java/baritone/chunk/ChunkPacker.java | 63 +++++++++++++++---- .../java/baritone/chunk/WorldScanner.java | 5 +- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 82a36709..4622369c 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -28,7 +28,9 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import java.util.*; @@ -40,28 +42,65 @@ public final class ChunkPacker implements Helper { private ChunkPacker() {} + private static BitSet originalPacker(Chunk chunk) { + BitSet bitSet = new BitSet(CachedChunk.SIZE); + for (int y = 0; y < 256; y++) { + for (int z = 0; z < 16; z++) { + for (int x = 0; x < 16; x++) { + int index = CachedChunk.getPositionIndex(x, y, z); + IBlockState state = chunk.getBlockState(x, y, z); + boolean[] bits = getPathingBlockType(state).getBits(); + bitSet.set(index, bits[0]); + bitSet.set(index + 1, bits[1]); + } + } + } + return bitSet; + } + public static CachedChunk pack(Chunk chunk) { long start = System.nanoTime() / 1000000L; Map> specialBlocks = new HashMap<>(); BitSet bitSet = new BitSet(CachedChunk.SIZE); try { - for (int y = 0; y < 256; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - int index = CachedChunk.getPositionIndex(x, y, z); - IBlockState state = chunk.getBlockState(x, y, z); - boolean[] bits = getPathingBlockType(state).getBits(); - bitSet.set(index, bits[0]); - bitSet.set(index + 1, bits[1]); - Block block = state.getBlock(); - if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) { - String name = blockToString(block); - specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z)); + ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + for (int y0 = 0; y0 < 16; y0++) { + ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; + if (extendedblockstorage == null) { + // any 16x16x16 area that's all air will have null storage + // for example, in an ocean biome, with air from y=64 to y=256 + // the first 4 extended blocks storages will be full + // and the remaining 12 will be null + + // since the index into the bitset is calculated from the x y and z + // and doesn't function as an append, we can entirely skip the scanning + // since a bitset is initialized to all zero, and air is saved as zeros + continue; + } + BlockStateContainer bsc = extendedblockstorage.getData(); + int yReal = y0 << 4; + for (int x = 0; x < 16; x++) { + for (int y1 = 0; y1 < 16; y1++) { + for (int z = 0; z < 16; z++) { + int y = y1 | yReal; + int index = CachedChunk.getPositionIndex(x, y, z); + IBlockState state = bsc.get(x, y1, z); + boolean[] bits = getPathingBlockType(state).getBits(); + bitSet.set(index, bits[0]); + bitSet.set(index + 1, bits[1]); + Block block = state.getBlock(); + if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) { + String name = blockToString(block); + specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z)); + } } } } } + /*if (!bitSet.equals(originalPacker(chunk))) { + throw new IllegalStateException(); + }*/ } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index fe3c0ea5..120d6635 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -64,18 +64,21 @@ public enum WorldScanner implements Helper { } allUnloaded = false; ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + chunkX = chunkX << 4; + chunkZ = chunkZ << 4; for (int y0 = 0; y0 < 16; y0++) { ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; if (extendedblockstorage == null) { continue; } + int yReal = y0 << 4; BlockStateContainer bsc = extendedblockstorage.getData(); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { IBlockState state = bsc.get(x, y, z); if (asBlocks.contains(state.getBlock())) { - res.add(new BlockPos(chunkX * 16 + x, y0 * 16 + y, chunkZ * 16 + z)); + res.add(new BlockPos(chunkX | x, yReal | y, chunkZ | z)); } } } From 69d8bd56fa3c54e7668725c9e507319a6107ceef Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:23:54 -0700 Subject: [PATCH 147/165] rearranged loop order --- src/main/java/baritone/chunk/ChunkPacker.java | 10 ++++++---- src/main/java/baritone/chunk/WorldScanner.java | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index 4622369c..583dddc0 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -80,10 +80,12 @@ public final class ChunkPacker implements Helper { } BlockStateContainer bsc = extendedblockstorage.getData(); int yReal = y0 << 4; - for (int x = 0; x < 16; x++) { - for (int y1 = 0; y1 < 16; y1++) { - for (int z = 0; z < 16; z++) { - int y = y1 | yReal; + // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; + // for better cache locality, iterate in that order + for (int y1 = 0; y1 < 16; y1++) { + int y = y1 | yReal; + for (int z = 0; z < 16; z++) { + for (int x = 0; x < 16; x++) { int index = CachedChunk.getPositionIndex(x, y, z); IBlockState state = bsc.get(x, y1, z); boolean[] bits = getPathingBlockType(state).getBits(); diff --git a/src/main/java/baritone/chunk/WorldScanner.java b/src/main/java/baritone/chunk/WorldScanner.java index 120d6635..cf4fb117 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -73,9 +73,11 @@ public enum WorldScanner implements Helper { } int yReal = y0 << 4; BlockStateContainer bsc = extendedblockstorage.getData(); - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { + // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; + // for better cache locality, iterate in that order + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + for (int x = 0; x < 16; x++) { IBlockState state = bsc.get(x, y, z); if (asBlocks.contains(state.getBlock())) { res.add(new BlockPos(chunkX | x, yReal | y, chunkZ | z)); From 2bb01fdd208756846ab1b4b3cc2a56db9050b11b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:33:38 -0700 Subject: [PATCH 148/165] decrease scan rate --- .../java/baritone/behavior/impl/MineBehavior.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index d4b09b7b..0b4b3b2a 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -17,7 +17,7 @@ package baritone.behavior.impl; -import baritone.api.event.events.TickEvent; +import baritone.api.event.events.PathEvent; import baritone.behavior.Behavior; import baritone.chunk.CachedChunk; import baritone.chunk.ChunkPacker; @@ -50,10 +50,11 @@ public class MineBehavior extends Behavior { List mining; @Override - public void onTick(TickEvent event) { - if (event.getType() == TickEvent.Type.OUT) { - return; - } + public void onPathEvent(PathEvent event) { + updateGoal(); + } + + public void updateGoal() { if (mining == null) { return; } @@ -100,6 +101,7 @@ public class MineBehavior extends Behavior { public void mine(String... mining) { this.mining = mining == null || mining.length == 0 ? null : new ArrayList<>(Arrays.asList(mining)); + updateGoal(); } public void cancel() { From 0c4fd39845c96cb06508c9d7f7d2c73cea9508e1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 15:53:11 -0700 Subject: [PATCH 149/165] better error message --- src/main/java/baritone/utils/ExampleBaritoneControl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 16dabf4f..9c28f058 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -105,7 +105,11 @@ public class ExampleBaritoneControl extends Behavior { } if (msg.equals("path")) { if (!PathingBehavior.INSTANCE.path()) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + if (PathingBehavior.INSTANCE.getGoal() == null) { + displayChatMessageRaw("No goal."); + } else { + displayChatMessageRaw("Currently executing a path. Please cancel it first."); + } } event.cancel(); return; From 81ffbddc94197052e69fc89c9930ecaa67984f18 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 16:02:31 -0700 Subject: [PATCH 150/165] start with more than one chunk --- 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 cf4fb117..09edd1e5 100644 --- a/src/main/java/baritone/chunk/WorldScanner.java +++ b/src/main/java/baritone/chunk/WorldScanner.java @@ -47,7 +47,7 @@ public enum WorldScanner implements Helper { int playerChunkX = playerFeet().getX() >> 4; int playerChunkZ = playerFeet().getZ() >> 4; - int searchRadius = 0; + int searchRadius = 2; while (true) { boolean allUnloaded = true; for (int xoff = -searchRadius; xoff <= searchRadius; xoff++) { From d40418d344e9f7813560ef9e22059cf09653187f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 16:04:44 -0700 Subject: [PATCH 151/165] move updateState after calculateCost for consistency with every other movement --- .../movement/movements/MovementDiagonal.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 2bf8bdf1..b71909d1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -50,29 +50,6 @@ public class MovementDiagonal extends Movement { super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } - @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 (playerFeet().equals(dest)) { - state.setStatus(MovementState.MovementStatus.SUCCESS); - return state; - } - if (!BlockStateInterface.isLiquid(playerFeet())) { - state.setInput(InputOverrideHandler.Input.SPRINT, true); - } - MovementHelper.moveTowards(state, dest); - return state; - } - @Override protected double calculateCost(CalculationContext context) { Block fromDown = BlockStateInterface.get(src.down()).getBlock(); @@ -139,6 +116,29 @@ public class MovementDiagonal extends Movement { return multiplier * SQRT_2; } + @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 (playerFeet().equals(dest)) { + state.setStatus(MovementState.MovementStatus.SUCCESS); + return state; + } + if (!BlockStateInterface.isLiquid(playerFeet())) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); + } + MovementHelper.moveTowards(state, dest); + return state; + } + @Override protected boolean prepared(MovementState state) { return true; From 40e86df0801227eab41470478a2aae2bf1189bab Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 4 Sep 2018 18:06:17 -0500 Subject: [PATCH 152/165] Remove unnecessary abstract mixin class modifiers --- src/main/java/baritone/launch/mixins/MixinBlockPos.java | 2 +- src/main/java/baritone/launch/mixins/MixinKeyBinding.java | 2 +- src/main/java/baritone/launch/mixins/MixinNetworkManager.java | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/launch/mixins/MixinBlockPos.java b/src/main/java/baritone/launch/mixins/MixinBlockPos.java index 1cf52132..49e01c96 100644 --- a/src/main/java/baritone/launch/mixins/MixinBlockPos.java +++ b/src/main/java/baritone/launch/mixins/MixinBlockPos.java @@ -29,7 +29,7 @@ import javax.annotation.Nonnull; * @since 8/25/2018 */ @Mixin(BlockPos.class) -public abstract class MixinBlockPos extends Vec3i { +public class MixinBlockPos extends Vec3i { public MixinBlockPos(int xIn, int yIn, int zIn) { super(xIn, yIn, zIn); diff --git a/src/main/java/baritone/launch/mixins/MixinKeyBinding.java b/src/main/java/baritone/launch/mixins/MixinKeyBinding.java index 085ddc74..db850188 100755 --- a/src/main/java/baritone/launch/mixins/MixinKeyBinding.java +++ b/src/main/java/baritone/launch/mixins/MixinKeyBinding.java @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; * @since 7/31/2018 11:44 PM */ @Mixin(KeyBinding.class) -public abstract class MixinKeyBinding { +public class MixinKeyBinding { @Inject( method = "isKeyDown", diff --git a/src/main/java/baritone/launch/mixins/MixinNetworkManager.java b/src/main/java/baritone/launch/mixins/MixinNetworkManager.java index 472d4f04..46664e7c 100644 --- a/src/main/java/baritone/launch/mixins/MixinNetworkManager.java +++ b/src/main/java/baritone/launch/mixins/MixinNetworkManager.java @@ -37,12 +37,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; * @since 8/6/2018 9:30 PM */ @Mixin(NetworkManager.class) -public abstract class MixinNetworkManager { +public class MixinNetworkManager { @Shadow private Channel channel; - @Shadow protected abstract void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_) throws Exception; - @Inject( method = "dispatchPacket", at = @At("HEAD") From 1e6599cc4222a2055cee4305dd40f06fb2137c2b Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 4 Sep 2018 18:08:29 -0500 Subject: [PATCH 153/165] Consolidate plugins in build.gradle --- build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index bdb3c311..a3717498 100755 --- a/build.gradle +++ b/build.gradle @@ -38,15 +38,14 @@ buildscript { } apply plugin: 'java' +apply plugin: 'net.minecraftforge.gradle.tweaker-client' +apply plugin: 'org.spongepowered.mixin' sourceCompatibility = targetCompatibility = '1.8' compileJava { sourceCompatibility = targetCompatibility = '1.8' } -apply plugin: 'net.minecraftforge.gradle.tweaker-client' -apply plugin: 'org.spongepowered.mixin' - minecraft { version = '1.12.2' mappings = 'snapshot_20180731' From a45f291d6721170cb7b802ba466b59d7982c5c26 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 16:19:10 -0700 Subject: [PATCH 154/165] vine and ladder fixes --- .../movement/movements/MovementTraverse.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index af0b7b27..12eda431 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -57,15 +57,16 @@ public class MovementTraverse extends Movement { IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]); IBlockState destOn = BlockStateInterface.get(positionToPlace); + Block srcDown = BlockStateInterface.getBlock(src.down()); if (MovementHelper.canWalkOn(positionToPlace, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) { WC = WALK_ONE_IN_WATER_COST; } else { - if (Blocks.SOUL_SAND.equals(destOn.getBlock())) { + if (destOn.getBlock() == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - if (Blocks.SOUL_SAND.equals(BlockStateInterface.get(src.down()).getBlock())) { + if (srcDown == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } } @@ -82,9 +83,12 @@ public class MovementTraverse extends Movement { } return WC; } + if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { + hardness1 *= 5; + hardness2 *= 5; + } return WC + hardness1 + hardness2; } else {//this is a bridge, so we need to place a block - Block srcDown = BlockStateInterface.get(src.down()).getBlock(); if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { return COST_INF; } @@ -130,6 +134,8 @@ public class MovementTraverse extends Movement { return state; } + state.setInput(InputOverrideHandler.Input.SNEAK, false); + Block fd = BlockStateInterface.get(src.down()).getBlock(); boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); @@ -186,7 +192,7 @@ public class MovementTraverse extends Movement { state.setInput(InputOverrideHandler.Input.SPRINT, true); } Block destDown = BlockStateInterface.get(dest.down()).getBlock(); - if (ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { + if (whereAmI.getY() != dest.getY() && ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { new MovementPillar(dest.down(), dest).updateState(state); // i'm sorry return state; } @@ -264,4 +270,15 @@ public class MovementTraverse extends Movement { } } } + + @Override + protected boolean prepared(MovementState state) { + if (playerFeet().equals(src) || playerFeet().equals(src.down())) { + Block block = BlockStateInterface.getBlock(src.down()); + if (block == Blocks.LADDER || block == Blocks.VINE) { + state.setInput(InputOverrideHandler.Input.SNEAK, true); + } + } + return super.prepared(state); + } } From bba2458f8eb8d51fb3d3301ffb06ebbf155419ba Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 4 Sep 2018 18:48:00 -0500 Subject: [PATCH 155/165] Separate "launch" into another SourceSet --- build.gradle | 12 +- .../java/baritone/launch/BaritoneTweaker.java | 142 +++---- .../baritone/launch/BaritoneTweakerForge.java | 88 ++--- .../launch/BaritoneTweakerOptifine.java | 68 ++-- .../launch/mixins/MixinAnvilChunkLoader.java | 17 + .../baritone/launch/mixins/MixinBlockPos.java | 0 .../mixins/MixinChunkProviderServer.java | 17 + .../baritone/launch/mixins/MixinEntity.java | 0 .../launch/mixins/MixinEntityPlayerSP.java | 0 .../launch/mixins/MixinEntityRenderer.java | 0 .../launch/mixins/MixinGameSettings.java | 88 ++--- .../launch/mixins/MixinGuiContainer.java | 94 ++--- .../launch/mixins/MixinGuiScreen.java | 96 ++--- .../launch/mixins/MixinInventoryPlayer.java | 0 .../launch/mixins/MixinKeyBinding.java | 86 ++--- .../launch/mixins/MixinMinecraft.java | 352 +++++++++--------- .../mixins/MixinNetHandlerPlayClient.java | 0 .../launch/mixins/MixinNetworkManager.java | 0 .../launch/mixins/MixinWorldClient.java | 0 .../resources/mixins.baritone.json | 52 +-- 20 files changed, 578 insertions(+), 534 deletions(-) rename src/{main => launch}/java/baritone/launch/BaritoneTweaker.java (97%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/BaritoneTweakerForge.java (97%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/BaritoneTweakerOptifine.java (96%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinAnvilChunkLoader.java (65%) rename src/{main => launch}/java/baritone/launch/mixins/MixinBlockPos.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinChunkProviderServer.java (65%) rename src/{main => launch}/java/baritone/launch/mixins/MixinEntity.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinEntityPlayerSP.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinEntityRenderer.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinGameSettings.java (97%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinGuiContainer.java (96%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinGuiScreen.java (96%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinInventoryPlayer.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinKeyBinding.java (97%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinMinecraft.java (97%) mode change 100755 => 100644 rename src/{main => launch}/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinNetworkManager.java (100%) rename src/{main => launch}/java/baritone/launch/mixins/MixinWorldClient.java (100%) rename src/{main => launch}/resources/mixins.baritone.json (95%) mode change 100755 => 100644 diff --git a/build.gradle b/build.gradle index a3717498..86c29def 100755 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,12 @@ compileJava { sourceCompatibility = targetCompatibility = '1.8' } +sourceSets { + launch { + compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output + } +} + minecraft { version = '1.12.2' mappings = 'snapshot_20180731' @@ -64,7 +70,7 @@ repositories { } dependencies { - runtime implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { // Mixin includes a lot of dependencies that are too up-to-date exclude module: 'launchwrapper' exclude module: 'guava' @@ -79,3 +85,7 @@ mixin { defaultObfuscationEnv notch add sourceSets.main, 'mixins.baritone.refmap.json' } + +jar { + from sourceSets.launch.output +} diff --git a/src/main/java/baritone/launch/BaritoneTweaker.java b/src/launch/java/baritone/launch/BaritoneTweaker.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/baritone/launch/BaritoneTweaker.java rename to src/launch/java/baritone/launch/BaritoneTweaker.java index 04941f79..e281ece3 --- a/src/main/java/baritone/launch/BaritoneTweaker.java +++ b/src/launch/java/baritone/launch/BaritoneTweaker.java @@ -1,71 +1,71 @@ -/* - * 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; - -import net.minecraft.launchwrapper.ITweaker; -import net.minecraft.launchwrapper.LaunchClassLoader; -import org.spongepowered.asm.launch.MixinBootstrap; -import org.spongepowered.asm.mixin.MixinEnvironment; -import org.spongepowered.asm.mixin.Mixins; -import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Brady - * @since 7/31/2018 9:59 PM - */ -public class BaritoneTweaker implements ITweaker { - - List args; - - @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); - } - - @Override - public void injectIntoClassLoader(LaunchClassLoader classLoader) { - MixinBootstrap.init(); - MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT); - MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.NOTCH); - Mixins.addConfiguration("mixins.baritone.json"); - } - - @Override - public final String getLaunchTarget() { - return "net.minecraft.client.main.Main"; - } - - @Override - public final String[] getLaunchArguments() { - return this.args.toArray(new String[0]); - } - - private void addArg(String label, String value) { - if (!args.contains("--" + label) && value != null) { - this.args.add("--" + label); - this.args.add(value); - } - } -} +/* + * 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; + +import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.LaunchClassLoader; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.asm.mixin.Mixins; +import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Brady + * @since 7/31/2018 9:59 PM + */ +public class BaritoneTweaker implements ITweaker { + + List args; + + @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); + } + + @Override + public void injectIntoClassLoader(LaunchClassLoader classLoader) { + MixinBootstrap.init(); + MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT); + MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.NOTCH); + Mixins.addConfiguration("mixins.baritone.json"); + } + + @Override + public final String getLaunchTarget() { + return "net.minecraft.client.main.Main"; + } + + @Override + public final String[] getLaunchArguments() { + return this.args.toArray(new String[0]); + } + + private void addArg(String label, String value) { + if (!args.contains("--" + label) && value != null) { + this.args.add("--" + label); + this.args.add(value); + } + } +} diff --git a/src/main/java/baritone/launch/BaritoneTweakerForge.java b/src/launch/java/baritone/launch/BaritoneTweakerForge.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/baritone/launch/BaritoneTweakerForge.java rename to src/launch/java/baritone/launch/BaritoneTweakerForge.java index 9a45520c..c1699058 --- a/src/main/java/baritone/launch/BaritoneTweakerForge.java +++ b/src/launch/java/baritone/launch/BaritoneTweakerForge.java @@ -1,44 +1,44 @@ -/* - * 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; - -import net.minecraft.launchwrapper.LaunchClassLoader; -import org.spongepowered.asm.mixin.MixinEnvironment; -import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Brady - * @since 7/31/2018 10:09 PM - */ -public class BaritoneTweakerForge extends BaritoneTweaker { - - @Override - public final void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - this.args = new ArrayList<>(); - } - - @Override - public final void injectIntoClassLoader(LaunchClassLoader classLoader) { - super.injectIntoClassLoader(classLoader); - MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.SEARGE); - } -} +/* + * 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; + +import net.minecraft.launchwrapper.LaunchClassLoader; +import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Brady + * @since 7/31/2018 10:09 PM + */ +public class BaritoneTweakerForge extends BaritoneTweaker { + + @Override + public final void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + this.args = new ArrayList<>(); + } + + @Override + public final void injectIntoClassLoader(LaunchClassLoader classLoader) { + super.injectIntoClassLoader(classLoader); + MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.SEARGE); + } +} diff --git a/src/main/java/baritone/launch/BaritoneTweakerOptifine.java b/src/launch/java/baritone/launch/BaritoneTweakerOptifine.java old mode 100755 new mode 100644 similarity index 96% rename from src/main/java/baritone/launch/BaritoneTweakerOptifine.java rename to src/launch/java/baritone/launch/BaritoneTweakerOptifine.java index 380a0b0f..8d0872aa --- a/src/main/java/baritone/launch/BaritoneTweakerOptifine.java +++ b/src/launch/java/baritone/launch/BaritoneTweakerOptifine.java @@ -1,34 +1,34 @@ -/* - * 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; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Brady - * @since 7/31/2018 10:10 PM - */ -public class BaritoneTweakerOptifine extends BaritoneTweaker { - - @Override - public final void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - this.args = new ArrayList<>(); - } -} +/* + * 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; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Brady + * @since 7/31/2018 10:10 PM + */ +public class BaritoneTweakerOptifine extends BaritoneTweaker { + + @Override + public final void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + this.args = new ArrayList<>(); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java b/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java similarity index 65% rename from src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java rename to src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java index 96f38b87..3133c9cd 100644 --- a/src/main/java/baritone/launch/mixins/MixinAnvilChunkLoader.java +++ b/src/launch/java/baritone/launch/mixins/MixinAnvilChunkLoader.java @@ -15,6 +15,23 @@ * 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.launch.mixins; import baritone.utils.accessor.IAnvilChunkLoader; diff --git a/src/main/java/baritone/launch/mixins/MixinBlockPos.java b/src/launch/java/baritone/launch/mixins/MixinBlockPos.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinBlockPos.java rename to src/launch/java/baritone/launch/mixins/MixinBlockPos.java diff --git a/src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java b/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java similarity index 65% rename from src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java rename to src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java index 9a454d01..41f90481 100644 --- a/src/main/java/baritone/launch/mixins/MixinChunkProviderServer.java +++ b/src/launch/java/baritone/launch/mixins/MixinChunkProviderServer.java @@ -15,6 +15,23 @@ * 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.launch.mixins; import baritone.utils.accessor.IChunkProviderServer; diff --git a/src/main/java/baritone/launch/mixins/MixinEntity.java b/src/launch/java/baritone/launch/mixins/MixinEntity.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinEntity.java rename to src/launch/java/baritone/launch/mixins/MixinEntity.java diff --git a/src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java b/src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinEntityPlayerSP.java rename to src/launch/java/baritone/launch/mixins/MixinEntityPlayerSP.java diff --git a/src/main/java/baritone/launch/mixins/MixinEntityRenderer.java b/src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinEntityRenderer.java rename to src/launch/java/baritone/launch/mixins/MixinEntityRenderer.java diff --git a/src/main/java/baritone/launch/mixins/MixinGameSettings.java b/src/launch/java/baritone/launch/mixins/MixinGameSettings.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/baritone/launch/mixins/MixinGameSettings.java rename to src/launch/java/baritone/launch/mixins/MixinGameSettings.java index b68cce51..f5bae8ef --- a/src/main/java/baritone/launch/mixins/MixinGameSettings.java +++ b/src/launch/java/baritone/launch/mixins/MixinGameSettings.java @@ -1,44 +1,44 @@ -/* - * 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 net.minecraft.client.settings.GameSettings; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -/** - * @author Brady - * @since 8/1/2018 12:28 AM - */ -@Mixin(GameSettings.class) -public class MixinGameSettings { - - @Redirect( - method = "isKeyDown", - at = @At( - value = "INVOKE", - target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", - remap = false - ) - ) - private static boolean isKeyDown(int keyCode) { - return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); - } -} +/* + * 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 net.minecraft.client.settings.GameSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * @author Brady + * @since 8/1/2018 12:28 AM + */ +@Mixin(GameSettings.class) +public class MixinGameSettings { + + @Redirect( + method = "isKeyDown", + at = @At( + value = "INVOKE", + target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", + remap = false + ) + ) + private static boolean isKeyDown(int keyCode) { + return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinGuiContainer.java b/src/launch/java/baritone/launch/mixins/MixinGuiContainer.java old mode 100755 new mode 100644 similarity index 96% rename from src/main/java/baritone/launch/mixins/MixinGuiContainer.java rename to src/launch/java/baritone/launch/mixins/MixinGuiContainer.java index dd9bf715..c2c62d76 --- a/src/main/java/baritone/launch/mixins/MixinGuiContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinGuiContainer.java @@ -1,47 +1,47 @@ -/* - * 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 net.minecraft.client.gui.inventory.GuiContainer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -/** - * @author Brady - * @since 7/31/2018 10:47 PM - */ -@Mixin(GuiContainer.class) -public class MixinGuiContainer { - - @Redirect( - method = { - "mouseClicked", - "mouseReleased" - }, - at = @At( - value = "INVOKE", - target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", - remap = false - ) - ) - private boolean isKeyDown(int keyCode) { - return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); - } -} +/* + * 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 net.minecraft.client.gui.inventory.GuiContainer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * @author Brady + * @since 7/31/2018 10:47 PM + */ +@Mixin(GuiContainer.class) +public class MixinGuiContainer { + + @Redirect( + method = { + "mouseClicked", + "mouseReleased" + }, + at = @At( + value = "INVOKE", + target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", + remap = false + ) + ) + private boolean isKeyDown(int keyCode) { + return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinGuiScreen.java b/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java old mode 100755 new mode 100644 similarity index 96% rename from src/main/java/baritone/launch/mixins/MixinGuiScreen.java rename to src/launch/java/baritone/launch/mixins/MixinGuiScreen.java index 47877058..11a3e7f4 --- a/src/main/java/baritone/launch/mixins/MixinGuiScreen.java +++ b/src/launch/java/baritone/launch/mixins/MixinGuiScreen.java @@ -1,48 +1,48 @@ -/* - * 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 net.minecraft.client.gui.GuiScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -/** - * @author Brady - * @since 7/31/2018 10:38 PM - */ -@Mixin(GuiScreen.class) -public class MixinGuiScreen { - - @Redirect( - method = { - "isCtrlKeyDown", - "isShiftKeyDown", - "isAltKeyDown" - }, - at = @At( - value = "INVOKE", - target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", - remap = false - ) - ) - private static boolean isKeyDown(int keyCode) { - return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); - } -} +/* + * 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 net.minecraft.client.gui.GuiScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * @author Brady + * @since 7/31/2018 10:38 PM + */ +@Mixin(GuiScreen.class) +public class MixinGuiScreen { + + @Redirect( + method = { + "isCtrlKeyDown", + "isShiftKeyDown", + "isAltKeyDown" + }, + at = @At( + value = "INVOKE", + target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", + remap = false + ) + ) + private static boolean isKeyDown(int keyCode) { + return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java b/src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinInventoryPlayer.java rename to src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java diff --git a/src/main/java/baritone/launch/mixins/MixinKeyBinding.java b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/baritone/launch/mixins/MixinKeyBinding.java rename to src/launch/java/baritone/launch/mixins/MixinKeyBinding.java index db850188..838802cd --- a/src/main/java/baritone/launch/mixins/MixinKeyBinding.java +++ b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java @@ -1,43 +1,43 @@ -/* - * 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 net.minecraft.client.settings.KeyBinding; -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.CallbackInfoReturnable; - -/** - * @author Brady - * @since 7/31/2018 11:44 PM - */ -@Mixin(KeyBinding.class) -public class MixinKeyBinding { - - @Inject( - method = "isKeyDown", - at = @At("HEAD"), - cancellable = true - ) - private void isKeyDown(CallbackInfoReturnable cir) { - if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) - cir.setReturnValue(true); - } -} +/* + * 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 net.minecraft.client.settings.KeyBinding; +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.CallbackInfoReturnable; + +/** + * @author Brady + * @since 7/31/2018 11:44 PM + */ +@Mixin(KeyBinding.class) +public class MixinKeyBinding { + + @Inject( + method = "isKeyDown", + at = @At("HEAD"), + cancellable = true + ) + private void isKeyDown(CallbackInfoReturnable cir) { + if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) + cir.setReturnValue(true); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java old mode 100755 new mode 100644 similarity index 97% rename from src/main/java/baritone/launch/mixins/MixinMinecraft.java rename to src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 49c587ba..bc419516 --- a/src/main/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -1,176 +1,176 @@ -/* - * 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.BlockInteractEvent; -import baritone.api.event.events.TickEvent; -import baritone.api.event.events.WorldEvent; -import baritone.api.event.events.type.EventState; -import baritone.behavior.impl.PathingBehavior; -import baritone.utils.ExampleBaritoneControl; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -/** - * @author Brady - * @since 7/31/2018 10:51 PM - */ -@Mixin(Minecraft.class) -public class MixinMinecraft { - - @Shadow - private int leftClickCounter; - @Shadow - public EntityPlayerSP player; - @Shadow - public WorldClient world; - - @Inject( - method = "init", - at = @At("RETURN") - ) - private void init(CallbackInfo ci) { - Baritone.INSTANCE.init(); - ExampleBaritoneControl.INSTANCE.initAndRegister(); - } - - @Inject( - method = "runTick", - at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/GuiScreen;", - ordinal = 5, - shift = At.Shift.BY, - by = -3 - ) - ) - private void runTick(CallbackInfo ci) { - Minecraft mc = (Minecraft) (Object) this; - Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent( - EventState.PRE, - (mc.player != null && mc.world != null) - ? TickEvent.Type.IN - : TickEvent.Type.OUT - )); - } - - @Redirect( - method = "runTickKeyboard", - at = @At( - value = "INVOKE", - target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", - remap = false - ) - ) - private boolean Keyboard$isKeyDown(int keyCode) { - return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); - } - - @Inject( - method = "processKeyBinds", - at = @At("HEAD") - ) - private void runTickKeyboard(CallbackInfo ci) { - Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds(); - } - - @Inject( - method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", - at = @At("HEAD") - ) - private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { - // If we're unloading the world but one doesn't exist, ignore it - if (this.world == null && world == null) { - return; - } - - Baritone.INSTANCE.getGameEventHandler().onWorldEvent( - new WorldEvent( - world, - EventState.PRE - ) - ); - } - - @Inject( - method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", - at = @At("RETURN") - ) - private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { - // still fire event for both null, as that means we've just finished exiting a world - - Baritone.INSTANCE.getGameEventHandler().onWorldEvent( - new WorldEvent( - world, - EventState.POST - ) - ); - } - - @Redirect( - method = "runTick", - at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "net/minecraft/client/gui/GuiScreen.allowUserInput:Z" - ) - ) - private boolean isAllowUserInput(GuiScreen screen) { - return (PathingBehavior.INSTANCE.getCurrent() != null && player != null) || screen.allowUserInput; - } - - @Inject( - method = "clickMouse", - at = @At( - value = "INVOKE", - target = "net/minecraft/client/multiplayer/PlayerControllerMP.clickBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)Z" - ), - locals = LocalCapture.CAPTURE_FAILHARD - ) - private void onBlockBreak(CallbackInfo ci, BlockPos pos) { - Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK)); - } - - @Inject( - method = "rightClickMouse", - at = @At( - value = "INVOKE", - target = "net/minecraft/client/entity/EntityPlayerSP.swingArm(Lnet/minecraft/util/EnumHand;)V" - ), - locals = LocalCapture.CAPTURE_FAILHARD - ) - private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) { - Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE)); - } -} +/* + * 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.BlockInteractEvent; +import baritone.api.event.events.TickEvent; +import baritone.api.event.events.WorldEvent; +import baritone.api.event.events.type.EventState; +import baritone.behavior.impl.PathingBehavior; +import baritone.utils.ExampleBaritoneControl; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.lib.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +/** + * @author Brady + * @since 7/31/2018 10:51 PM + */ +@Mixin(Minecraft.class) +public class MixinMinecraft { + + @Shadow + private int leftClickCounter; + @Shadow + public EntityPlayerSP player; + @Shadow + public WorldClient world; + + @Inject( + method = "init", + at = @At("RETURN") + ) + private void init(CallbackInfo ci) { + Baritone.INSTANCE.init(); + ExampleBaritoneControl.INSTANCE.initAndRegister(); + } + + @Inject( + method = "runTick", + at = @At( + value = "FIELD", + opcode = Opcodes.GETFIELD, + target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/GuiScreen;", + ordinal = 5, + shift = At.Shift.BY, + by = -3 + ) + ) + private void runTick(CallbackInfo ci) { + Minecraft mc = (Minecraft) (Object) this; + Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent( + EventState.PRE, + (mc.player != null && mc.world != null) + ? TickEvent.Type.IN + : TickEvent.Type.OUT + )); + } + + @Redirect( + method = "runTickKeyboard", + at = @At( + value = "INVOKE", + target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", + remap = false + ) + ) + private boolean Keyboard$isKeyDown(int keyCode) { + return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); + } + + @Inject( + method = "processKeyBinds", + at = @At("HEAD") + ) + private void runTickKeyboard(CallbackInfo ci) { + Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds(); + } + + @Inject( + method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + at = @At("HEAD") + ) + private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { + // If we're unloading the world but one doesn't exist, ignore it + if (this.world == null && world == null) { + return; + } + + Baritone.INSTANCE.getGameEventHandler().onWorldEvent( + new WorldEvent( + world, + EventState.PRE + ) + ); + } + + @Inject( + method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + at = @At("RETURN") + ) + private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { + // still fire event for both null, as that means we've just finished exiting a world + + Baritone.INSTANCE.getGameEventHandler().onWorldEvent( + new WorldEvent( + world, + EventState.POST + ) + ); + } + + @Redirect( + method = "runTick", + at = @At( + value = "FIELD", + opcode = Opcodes.GETFIELD, + target = "net/minecraft/client/gui/GuiScreen.allowUserInput:Z" + ) + ) + private boolean isAllowUserInput(GuiScreen screen) { + return (PathingBehavior.INSTANCE.getCurrent() != null && player != null) || screen.allowUserInput; + } + + @Inject( + method = "clickMouse", + at = @At( + value = "INVOKE", + target = "net/minecraft/client/multiplayer/PlayerControllerMP.clickBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)Z" + ), + locals = LocalCapture.CAPTURE_FAILHARD + ) + private void onBlockBreak(CallbackInfo ci, BlockPos pos) { + Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK)); + } + + @Inject( + method = "rightClickMouse", + at = @At( + value = "INVOKE", + target = "net/minecraft/client/entity/EntityPlayerSP.swingArm(Lnet/minecraft/util/EnumHand;)V" + ), + locals = LocalCapture.CAPTURE_FAILHARD + ) + private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) { + Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE)); + } +} diff --git a/src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java rename to src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java diff --git a/src/main/java/baritone/launch/mixins/MixinNetworkManager.java b/src/launch/java/baritone/launch/mixins/MixinNetworkManager.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinNetworkManager.java rename to src/launch/java/baritone/launch/mixins/MixinNetworkManager.java diff --git a/src/main/java/baritone/launch/mixins/MixinWorldClient.java b/src/launch/java/baritone/launch/mixins/MixinWorldClient.java similarity index 100% rename from src/main/java/baritone/launch/mixins/MixinWorldClient.java rename to src/launch/java/baritone/launch/mixins/MixinWorldClient.java diff --git a/src/main/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json old mode 100755 new mode 100644 similarity index 95% rename from src/main/resources/mixins.baritone.json rename to src/launch/resources/mixins.baritone.json index 989c9355..7f9bda48 --- a/src/main/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -1,27 +1,27 @@ -{ - "required": true, - "package": "baritone.launch.mixins", - "refmap": "mixins.baritone.refmap.json", - "compatibilityLevel": "JAVA_8", - "verbose": false, - "injectors": { - "maxShiftBy": 2 - }, - "client": [ - "MixinAnvilChunkLoader", - "MixinBlockPos", - "MixinChunkProviderServer", - "MixinEntity", - "MixinEntityPlayerSP", - "MixinEntityRenderer", - "MixinGameSettings", - "MixinGuiContainer", - "MixinGuiScreen", - "MixinInventoryPlayer", - "MixinKeyBinding", - "MixinMinecraft", - "MixinNetHandlerPlayClient", - "MixinNetworkManager", - "MixinWorldClient" - ] +{ + "required": true, + "package": "baritone.launch.mixins", + "refmap": "mixins.baritone.refmap.json", + "compatibilityLevel": "JAVA_8", + "verbose": false, + "injectors": { + "maxShiftBy": 2 + }, + "client": [ + "MixinAnvilChunkLoader", + "MixinBlockPos", + "MixinChunkProviderServer", + "MixinEntity", + "MixinEntityPlayerSP", + "MixinEntityRenderer", + "MixinGameSettings", + "MixinGuiContainer", + "MixinGuiScreen", + "MixinInventoryPlayer", + "MixinKeyBinding", + "MixinMinecraft", + "MixinNetHandlerPlayClient", + "MixinNetworkManager", + "MixinWorldClient" + ] } \ No newline at end of file From 2cf9a3a74bb3de1fed446f32824d1bde4e1ff3e6 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 4 Sep 2018 18:50:53 -0500 Subject: [PATCH 156/165] Fix bad refmap SourceSet link --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 86c29def..8a2639f8 100755 --- a/build.gradle +++ b/build.gradle @@ -83,7 +83,7 @@ dependencies { mixin { defaultObfuscationEnv notch - add sourceSets.main, 'mixins.baritone.refmap.json' + add sourceSets.launch, 'mixins.baritone.refmap.json' } jar { From de84a49391f37b54a7eb2dc2b494357029b7657e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 17:13:42 -0700 Subject: [PATCH 157/165] fix tool set once and for all, fixes #136 --- .../launch/mixins/MixinInventoryPlayer.java | 62 ------- src/launch/resources/mixins.baritone.json | 1 - src/main/java/baritone/Baritone.java | 2 - src/main/java/baritone/Settings.java | 5 + .../baritone/api/event/GameEventHandler.java | 5 - .../listener/AbstractGameEventListener.java | 3 - .../event/listener/IGameEventListener.java | 10 -- .../baritone/pathing/movement/Movement.java | 2 +- .../pathing/movement/MovementHelper.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 156 ++++++------------ 10 files changed, 58 insertions(+), 190 deletions(-) delete mode 100644 src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java diff --git a/src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java b/src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java deleted file mode 100644 index dfaa4b19..00000000 --- a/src/launch/java/baritone/launch/mixins/MixinInventoryPlayer.java +++ /dev/null @@ -1,62 +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.launch.mixins; - -import baritone.Baritone; -import baritone.api.event.events.ItemSlotEvent; -import net.minecraft.entity.player.InventoryPlayer; -import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -/** - * @author Brady - * @since 8/20/2018 - */ -@Mixin(InventoryPlayer.class) -public class MixinInventoryPlayer { - - @Redirect( - method = "getDestroySpeed", - at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "net/minecraft/entity/player/InventoryPlayer.currentItem:I" - ) - ) - private int getDestroySpeed$getCurrentItem(InventoryPlayer inventory) { - ItemSlotEvent event = new ItemSlotEvent(inventory.currentItem); - Baritone.INSTANCE.getGameEventHandler().onQueryItemSlotForBlocks(event); - return event.getSlot(); - } - - @Redirect( - method = "canHarvestBlock", - at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "net/minecraft/entity/player/InventoryPlayer.currentItem:I" - ) - ) - private int canHarvestBlock$getCurrentItem(InventoryPlayer inventory) { - ItemSlotEvent event = new ItemSlotEvent(inventory.currentItem); - Baritone.INSTANCE.getGameEventHandler().onQueryItemSlotForBlocks(event); - return event.getSlot(); - } -} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index 7f9bda48..b1a8ed31 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -17,7 +17,6 @@ "MixinGameSettings", "MixinGuiContainer", "MixinGuiScreen", - "MixinInventoryPlayer", "MixinKeyBinding", "MixinMinecraft", "MixinNetHandlerPlayClient", diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 0b571264..5baacec8 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,7 +21,6 @@ import baritone.api.event.GameEventHandler; import baritone.behavior.Behavior; import baritone.behavior.impl.*; import baritone.utils.InputOverrideHandler; -import baritone.utils.ToolSet; import net.minecraft.client.Minecraft; import java.io.File; @@ -82,7 +81,6 @@ public enum Baritone { registerBehavior(LocationTrackingBehavior.INSTANCE); registerBehavior(FollowBehavior.INSTANCE); registerBehavior(MineBehavior.INSTANCE); - this.gameEventHandler.registerEventListener(ToolSet.INTERNAL_EVENT_LISTENER); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 2e6f0e39..1eed4333 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); + /** + * For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly. + */ + public Setting considerPotionEffects = new Setting<>(true); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. diff --git a/src/main/java/baritone/api/event/GameEventHandler.java b/src/main/java/baritone/api/event/GameEventHandler.java index 45e86885..1ec2d834 100644 --- a/src/main/java/baritone/api/event/GameEventHandler.java +++ b/src/main/java/baritone/api/event/GameEventHandler.java @@ -159,11 +159,6 @@ public final class GameEventHandler implements IGameEventListener, Helper { dispatch(listener -> listener.onReceivePacket(event)); } - @Override - public final void onQueryItemSlotForBlocks(ItemSlotEvent event) { - dispatch(listener -> listener.onQueryItemSlotForBlocks(event)); - } - @Override public void onPlayerRelativeMove(RelativeMoveEvent event) { dispatch(listener -> listener.onPlayerRelativeMove(event)); diff --git a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java index b47468bd..3b228e9d 100644 --- a/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -74,9 +74,6 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onReceivePacket(PacketEvent event) {} - @Override - default void onQueryItemSlotForBlocks(ItemSlotEvent event) {} - @Override default void onPlayerRelativeMove(RelativeMoveEvent event) {} diff --git a/src/main/java/baritone/api/event/listener/IGameEventListener.java b/src/main/java/baritone/api/event/listener/IGameEventListener.java index 9be19aab..81f91774 100644 --- a/src/main/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/api/event/listener/IGameEventListener.java @@ -36,7 +36,6 @@ package baritone.api.event.listener; import baritone.api.event.events.*; import io.netty.util.concurrent.GenericFutureListener; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiGameOver; @@ -44,7 +43,6 @@ 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.player.InventoryPlayer; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.util.text.ITextComponent; @@ -120,14 +118,6 @@ public interface IGameEventListener { */ void onReceivePacket(PacketEvent event); - /** - * Run when a query is made for a player's inventory current slot in the context of blocks - * - * @see InventoryPlayer#getDestroySpeed(IBlockState) - * @see InventoryPlayer#canHarvestBlock(IBlockState) - */ - void onQueryItemSlotForBlocks(ItemSlotEvent event); - /** * Run once per game tick from before and after the player's moveRelative method is called * diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 9d2f5869..5eba39ab 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -149,7 +149,7 @@ public abstract class Movement implements Helper, MovementHelper { somethingInTheWay = true; Optional reachable = LookBehaviorUtils.reachable(blockPos); if (reachable.isPresent()) { - player().inventory.currentItem = new ToolSet().getBestSlot(BlockStateInterface.get(blockPos)); + MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos)); state.setTarget(new MovementState.MovementTarget(reachable.get(), true)).setInput(Input.CLICK_LEFT, true); return false; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 82b20c41..06c880d8 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -261,7 +261,7 @@ public interface MovementHelper extends ActionCosts, Helper { return COST_INF; } 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 result = m / context.getToolSet().getStrVsBlock(state, position); + double result = m / context.getToolSet().getStrVsBlock(state); if (includeFalling) { BlockPos up = position.up(); IBlockState above = BlockStateInterface.get(up); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index e8243ba6..8a97980c 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -17,55 +17,24 @@ package baritone.utils; -import baritone.api.event.events.ItemSlotEvent; -import baritone.api.event.listener.AbstractGameEventListener; +import baritone.Baritone; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.item.Item; -import net.minecraft.item.ItemAir; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.init.Enchantments; +import net.minecraft.init.MobEffects; import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemTool; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; /** * A cached list of the best tools on the hotbar for any block * - * @author avecowa, Brady + * @author avecowa, Brady, leijurv */ public class ToolSet implements Helper { - /** - * Instance of the internal event listener used to hook into Baritone's event bus - */ - public static final InternalEventListener INTERNAL_EVENT_LISTENER = new InternalEventListener(); - - /** - * A list of tools on the hotbar that should be considered. - * Note that if there are no tools on the hotbar this list will still have one (null) entry. - */ - private List tools; - - /** - * A mapping from the tools array to what hotbar slots the tool is actually in. - * tools.get(i) will be on your hotbar in slot slots.get(i) - */ - private List slots; - - /** - * A mapping from a block to which tool index is best for it. - * The values in this map are *not* hotbar slots indexes, they need to be looked up in slots - * in order to be converted into hotbar slots. - */ - private Map slotCache = new HashMap<>(); - /** * A cache mapping a {@link Block} to how long it will take to break * with this toolset, given the optimum tool is used. @@ -75,30 +44,7 @@ public class ToolSet implements Helper { /** * Create a toolset from the current player's inventory (but don't calculate any hardness values just yet) */ - public ToolSet() { - EntityPlayerSP p = Minecraft.getMinecraft().player; - NonNullList inv = p.inventory.mainInventory; - tools = new ArrayList<>(); - slots = new ArrayList<>(); - boolean fnull = false; - for (byte i = 0; i < 9; i++) { - if (!fnull || ((!(inv.get(i).getItem() instanceof ItemAir)) && inv.get(i).getItem() instanceof ItemTool)) { - tools.add(inv.get(i).getItem() instanceof ItemTool ? (ItemTool) inv.get(i).getItem() : null); - slots.add(i); - fnull |= (inv.get(i).getItem() instanceof ItemAir) || (!inv.get(i).getItem().isDamageable()); - } - } - } - - /** - * A caching wrapper around getBestToolIndex - * - * @param state the blockstate to be mined - * @return get which tool on the hotbar is best for mining it - */ - public Item getBestTool(IBlockState state) { - return tools.get(slotCache.computeIfAbsent(state.getBlock(), block -> getBestToolIndex(state))); - } + public ToolSet() {} /** * Calculate which tool on the hotbar is best for mining @@ -106,15 +52,11 @@ public class ToolSet implements Helper { * @param b the blockstate to be mined * @return a byte indicating the index in the tools array that worked best */ - private byte getBestToolIndex(IBlockState b) { + public byte getBestSlot(IBlockState b) { byte best = 0; - float value = -1; - for (byte i = 0; i < tools.size(); i++) { - Item item = tools.get(i); - if (item == null) - continue; - - float v = item.getDestroySpeed(new ItemStack(item), b); + double value = -1; + for (byte i = 0; i < 9; i++) { + double v = calculateStrVsBlock(i, b); if (v > value || value == -1) { value = v; best = i; @@ -123,25 +65,14 @@ public class ToolSet implements Helper { return best; } - /** - * Get which hotbar slot should be selected for fastest mining - * - * @param state the blockstate to be mined - * @return a byte indicating which hotbar slot worked best - */ - public byte getBestSlot(IBlockState state) { - return slots.get(slotCache.computeIfAbsent(state.getBlock(), block -> getBestToolIndex(state))); - } - /** * Using the best tool on the hotbar, how long would it take to mine this block * * @param state the blockstate to be mined - * @param pos the blockpos to be mined * @return how long it would take in ticks */ - public double getStrVsBlock(IBlockState state, BlockPos pos) { - return this.breakStrengthCache.computeIfAbsent(state.getBlock(), b -> calculateStrVsBlock(state, pos)); + public double getStrVsBlock(IBlockState state) { + return this.breakStrengthCache.computeIfAbsent(state.getBlock(), b -> calculateStrVsBlock(getBestSlot(state), state)); } /** @@ -149,36 +80,51 @@ public class ToolSet implements Helper { * in this toolset is used. * * @param state the blockstate to be mined - * @param pos the blockpos to be mined * @return how long it would take in ticks */ - private double calculateStrVsBlock(IBlockState state, BlockPos pos) { + private double calculateStrVsBlock(byte slot, IBlockState state) { // Calculate the slot with the best item - byte slot = this.getBestSlot(state); + ItemStack contents = player().inventory.getStackInSlot(slot); - INTERNAL_EVENT_LISTENER.setOverrideSlot(slot); - - // Calculate the relative hardness of the block to the player - float hardness = state.getPlayerRelativeBlockHardness(player(), world(), pos); - - // Restore the old slot - INTERNAL_EVENT_LISTENER.setOverrideSlot(-1); - - return hardness; - } - - private static final class InternalEventListener implements AbstractGameEventListener { - - private int overrideSlot; - - @Override - public void onQueryItemSlotForBlocks(ItemSlotEvent event) { - if (this.overrideSlot >= 0) - event.setSlot(this.overrideSlot); + float blockHard = state.getBlockHardness(null, null); + if (blockHard < 0) { + return 0; } - final void setOverrideSlot(int overrideSlot) { - this.overrideSlot = overrideSlot; + float speed = contents.getDestroySpeed(state); + if (speed > 1) { + int effLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, contents); + if (effLevel > 0 && !contents.isEmpty()) { + speed += effLevel * effLevel + 1; + } + } + + if (Baritone.settings().considerPotionEffects.get()) { + if (player().isPotionActive(MobEffects.HASTE)) { + speed *= 1 + (player().getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2; + } + if (player().isPotionActive(MobEffects.MINING_FATIGUE)) { + switch (player().getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) { + case 0: + speed *= 0.3; + break; + case 1: + speed *= 0.09; + break; + case 2: + speed *= 0.0027; + break; + default: + speed *= 0.00081; + break; + } + } + } + speed /= blockHard; + if (state.getMaterial().isToolNotRequired() || (!contents.isEmpty() && contents.canHarvestBlock(state))) { + return speed / 30; + } else { + return speed / 100; } } } From db3aa5a7143c79f765638a73b90fbbfc07a55d7e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Sep 2018 19:52:06 -0700 Subject: [PATCH 158/165] lets allow it, fixes #137 --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 06c880d8..6897d5a4 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -55,9 +55,7 @@ public interface MovementHelper extends ActionCosts, Helper { || 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)) - || (!(b instanceof BlockLilyPad && BlockStateInterface.isWater(below)) && below instanceof BlockLiquid);//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid - // TODO revisit this. why is it not okay to break non-lilypads that are right above water? + || BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)); } /** From 008422680dfd03b220cbb44f87f548f3549a3631 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Sep 2018 21:08:18 -0700 Subject: [PATCH 159/165] that should NOT have been there --- .../java/baritone/pathing/movement/CalculationContext.java | 1 - .../baritone/pathing/movement/movements/MovementParkour.java | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/main/java/baritone/pathing/movement/movements/MovementParkour.java diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 2aca1f82..bd05ec5e 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -46,7 +46,6 @@ public class CalculationContext implements Helper { } public CalculationContext(ToolSet toolSet) { - player().setSprinting(true); this.toolSet = toolSet; this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(false); this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether(); 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..56d7cbce --- /dev/null +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -0,0 +1,4 @@ +package baritone.pathing.movement.movements; + +public class MovementParkour { +} From 8a7013d8d3963884a8dff8cf113766f604e7128b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Sep 2018 21:31:36 -0700 Subject: [PATCH 160/165] add readme for gradlew run --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index b95cc957..ba4897ee 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,14 @@ the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. ## Command Line On Mac OSX and Linux, use `./gradlew` instead of `gradlew`. + +Running Baritone: + +``` +$ gradlew run +``` + +Setting up for IntelliJ: ``` $ gradlew setupDecompWorkspace $ gradlew --refresh-dependencies From e51c729acbd59ac49a58596ef956407b0a7e225c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Sep 2018 21:31:10 -0700 Subject: [PATCH 161/165] update in progress --- FEATURES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index 998b546a..397755eb 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -37,11 +37,11 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o Things it doesn't have yet - Trapdoors - Sprint jumping in a 1x2 corridor +- Parkour (jumping over gaps of any length) [IN PROGRESS] 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 - Horses (2x3 path instead of 1x2) From 0d515b336f1637b5dc633c89c2f466130581b416 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 10:50:49 -0700 Subject: [PATCH 162/165] can get to block at eye level adjacent too --- src/main/java/baritone/pathing/goals/GoalGetToBlock.java | 3 +++ src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index ed927a12..bc32c5ca 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -50,6 +50,9 @@ public class GoalGetToBlock implements Goal { if (yDiff == -2 && xDiff == 0 && zDiff == 0) { return true; } + if (yDiff == -1) { + yDiff = 0; + } return Math.abs(xDiff) + Math.abs(yDiff) + Math.abs(zDiff) <= 1; } diff --git a/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java index 3c3905aa..a908a8dd 100644 --- a/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java +++ b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java @@ -30,7 +30,7 @@ public class GoalGetToBlockTest { @Test public void isInGoal() { - List acceptableOffsets = new ArrayList<>(Arrays.asList("0,0,0", "0,0,1", "0,0,-1", "1,0,0", "-1,0,0", "0,1,0", "0,-1,0", "0,-2,0")); + List acceptableOffsets = new ArrayList<>(Arrays.asList("0,0,0", "0,0,1", "0,0,-1", "1,0,0", "-1,0,0", "0,-1,1", "0,-1,-1", "1,-1,0", "-1,-1,0", "0,1,0", "0,-1,0", "0,-2,0")); for (int x = -10; x <= 10; x++) { for (int y = -10; y <= 10; y++) { for (int z = -10; z <= 10; z++) { From 439ff92727699e4c04f6f509141c579089a11098 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 13:33:51 -0700 Subject: [PATCH 163/165] crucial performance optimization --- src/main/java/baritone/pathing/goals/GoalGetToBlock.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index bc32c5ca..30937772 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -47,11 +47,8 @@ public class GoalGetToBlock implements Goal { int xDiff = pos.getX() - this.x; int yDiff = pos.getY() - this.y; int zDiff = pos.getZ() - this.z; - if (yDiff == -2 && xDiff == 0 && zDiff == 0) { - return true; - } - if (yDiff == -1) { - yDiff = 0; + if (yDiff < 0) { + yDiff++; } return Math.abs(xDiff) + Math.abs(yDiff) + Math.abs(zDiff) <= 1; } From dcad5fb79e5f7ee24546a95c13169c63c909c65a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Sep 2018 13:34:34 -0700 Subject: [PATCH 164/165] shouldn't be on master yet --- .../baritone/pathing/movement/movements/MovementParkour.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/main/java/baritone/pathing/movement/movements/MovementParkour.java diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java deleted file mode 100644 index 56d7cbce..00000000 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ /dev/null @@ -1,4 +0,0 @@ -package baritone.pathing.movement.movements; - -public class MovementParkour { -} From 99323463e3ebfd2cd13c70074ffb59588de3afe8 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 7 Sep 2018 19:00:36 -0500 Subject: [PATCH 165/165] Fix improper treatment of unbreakable blocks --- .../java/baritone/pathing/movement/MovementHelper.java | 6 +++++- src/main/java/baritone/utils/ToolSet.java | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6897d5a4..49fc5968 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -259,7 +259,11 @@ public interface MovementHelper extends ActionCosts, Helper { return COST_INF; } 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 result = m / context.getToolSet().getStrVsBlock(state); + double strVsBlock = context.getToolSet().getStrVsBlock(state); + if (strVsBlock < 0) + return COST_INF; + + double result = m / strVsBlock; if (includeFalling) { BlockPos up = position.up(); IBlockState above = BlockStateInterface.get(up); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 8a97980c..e31fe09e 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -77,7 +77,7 @@ public class ToolSet implements Helper { /** * Calculates how long would it take to mine the specified block given the best tool - * in this toolset is used. + * in this toolset is used. A negative value is returned if the specified block is unbreakable. * * @param state the blockstate to be mined * @return how long it would take in ticks @@ -87,9 +87,8 @@ public class ToolSet implements Helper { ItemStack contents = player().inventory.getStackInSlot(slot); float blockHard = state.getBlockHardness(null, null); - if (blockHard < 0) { - return 0; - } + if (blockHard < 0) + return -1; float speed = contents.getDestroySpeed(state); if (speed > 1) {