From 93217a3ae3ec6c653506ea5c2ccbbebba59cf2f2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 24 Nov 2018 22:04:36 -0800 Subject: [PATCH 001/140] this is just not possible --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index d00619211..989fda553 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -143,9 +143,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode); double tentativeCost = currentNode.cost + actionCost; if (tentativeCost < neighbor.cost) { - if (tentativeCost < 0) { - throw new IllegalStateException(moves + " overflowed into negative " + actionCost + " " + neighbor.cost + " " + tentativeCost); - } double improvementBy = neighbor.cost - tentativeCost; // there are floating point errors caused by random combinations of traverse and diagonal over a flat area // that means that sometimes there's a cost improvement of like 10 ^ -16 From 2b56d68f7d1c99b3afbc273a808bed6c39569908 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 11:53:51 -0800 Subject: [PATCH 002/140] many fixes to segment calculator, and chat demo usage --- .../baritone/behavior/PathingBehavior.java | 12 ++++++---- src/main/java/baritone/cache/CachedWorld.java | 4 ++++ .../baritone/pathing/path/SplicedPath.java | 3 ++- .../utils/ExampleBaritoneControl.java | 18 +++++++++++++++ .../utils/pathing/SegmentedCalculator.java | 23 +++++++++++++++++-- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 42186b5b2..3e8c3595a 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -330,12 +330,16 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } } + public void secretCursedFunctionDoNotCall(IPath path) { + current = new PathExecutor(this, path); + } + /** * See issue #209 * * @return The starting {@link BlockPos} for a new path */ - public BlockPos pathStart() { // TODO move to a helper or util class + public BetterBlockPos pathStart() { // TODO move to a helper or util class BetterBlockPos feet = ctx.playerFeet(); if (!MovementHelper.canWalkOn(ctx, feet.down())) { if (ctx.player().onGround) { @@ -406,7 +410,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.get(); } CalculationContext context = new CalculationContext(baritone); // not safe to create on the other thread, it looks up a lot of stuff in minecraft - AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context); + AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context, true); if (!Objects.equals(pathfinder.getGoal(), goal)) { logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); } @@ -480,9 +484,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, }); } - public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) { + public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context, boolean allowSimplifyUnloaded) { Goal transformed = goal; - if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { + if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos && allowSimplifyUnloaded) { BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); if (context.world().getChunk(pos) instanceof EmptyChunk) { transformed = new GoalXZ(pos.getX(), pos.getZ()); diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 31bcceaba..e9caddfe7 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -255,6 +255,10 @@ public final class CachedWorld implements ICachedWorld, Helper { }); } + public void tryLoadFromDisk(int regionX, int regionZ) { + getOrCreateRegion(regionX, regionZ); + } + /** * Returns the region ID based on the region coordinates. 0 will be * returned if the specified region coordinates are out of bounds. diff --git a/src/main/java/baritone/pathing/path/SplicedPath.java b/src/main/java/baritone/pathing/path/SplicedPath.java index 92610c863..f32637180 100644 --- a/src/main/java/baritone/pathing/path/SplicedPath.java +++ b/src/main/java/baritone/pathing/path/SplicedPath.java @@ -77,6 +77,7 @@ public class SplicedPath extends PathBase { for (int i = 0; i < first.length() - 1; i++) { // overlap in the very last element is fine (and required) so only go up to first.length() - 1 if (secondPos.contains(first.positions().get(i))) { firstPositionInSecond = i; + break; } } if (firstPositionInSecond != -1) { @@ -94,7 +95,7 @@ public class SplicedPath extends PathBase { List movements = new ArrayList<>(); positions.addAll(first.positions().subList(0, firstPositionInSecond + 1)); movements.addAll(first.movements().subList(0, firstPositionInSecond)); - + positions.addAll(second.positions().subList(positionInSecond + 1, second.length())); movements.addAll(second.movements().subList(positionInSecond, second.length() - 1)); return Optional.of(new SplicedPath(positions, movements, first.getNumNodesConsidered() + second.getNumNodesConsidered(), first.getGoal())); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 93e2742a8..6b2c74482 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -32,6 +32,7 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.process.CustomGoalProcess; +import baritone.utils.pathing.SegmentedCalculator; import net.minecraft.block.Block; import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.entity.Entity; @@ -202,6 +203,23 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } return true; } + if (msg.equals("fullpath")) { + if (pathingBehavior.getGoal() == null) { + logDirect("No goal."); + } else { + logDirect("Started segmented calculator"); + SegmentedCalculator.calculateSegmentsThreaded(pathingBehavior.pathStart(), pathingBehavior.getGoal(), new CalculationContext(baritone), ipath -> { + logDirect("Found a path"); + logDirect("Ends at " + ipath.getDest()); + logDirect("Length " + ipath.length()); + logDirect("Estimated time " + ipath.ticksRemainingFrom(0)); + pathingBehavior.secretCursedFunctionDoNotCall(ipath); // it's okay when *I* do it + }, () -> { + logDirect("Path calculation failed, no path"); + }); + } + return true; + } if (msg.equals("repack") || msg.equals("rescan")) { ChunkProviderClient cli = (ChunkProviderClient) ctx.world().getChunkProvider(); int playerChunkX = ctx.playerFeet().getX() >> 4; diff --git a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java index 75dd0282a..d3f6703e5 100644 --- a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java +++ b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java @@ -23,9 +23,11 @@ import baritone.api.pathing.goals.Goal; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.PathCalculationResult; import baritone.behavior.PathingBehavior; +import baritone.cache.CachedWorld; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.path.SplicedPath; +import net.minecraft.util.EnumFacing; import java.util.Optional; import java.util.function.Consumer; @@ -52,8 +54,8 @@ public class SegmentedCalculator { PathCalculationResult result = segment(soFar); switch (result.getType()) { case SUCCESS_SEGMENT: + case SUCCESS_TO_GOAL: break; - case SUCCESS_TO_GOAL: // if we've gotten all the way to the goal, we're done case FAILURE: // if path calculation failed, we're done case EXCEPTION: // if path calculation threw an exception, we're done return soFar; @@ -62,13 +64,30 @@ public class SegmentedCalculator { } IPath segment = result.getPath().get(); // path calculation result type is SUCCESS_SEGMENT, so the path must be present IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).get()).orElse(segment); + loadAdjacent(combined.getDest().getX(), combined.getDest().getZ()); soFar = Optional.of(combined); + if (result.getType() == PathCalculationResult.Type.SUCCESS_TO_GOAL) { + return soFar; + } + } + } + + private void loadAdjacent(int blockX, int blockZ) { + BetterBlockPos bp = new BetterBlockPos(blockX, 64, blockZ); + CachedWorld cached = (CachedWorld) context.getBaritone().getPlayerContext().worldData().getCachedWorld(); + for (int i = 0; i < 4; i++) { + // pathing thread is not allowed to load new cached regions from disk + // it checks if every chunk is loaded before getting blocks from it + // so you see path segments ending at multiples of 512 (plus or minus one) on either x or z axis + // this loads every adjacent chunk to the segment end, so it can continue into the next cached region + BetterBlockPos toLoad = bp.offset(EnumFacing.byHorizontalIndex(i), 16); + cached.tryLoadFromDisk(toLoad.x >> 9, toLoad.z >> 9); } } private PathCalculationResult segment(Optional previous) { BetterBlockPos segmentStart = previous.map(IPath::getDest).orElse(start); // <-- e p i c - AbstractNodeCostSearch search = PathingBehavior.createPathfinder(segmentStart, goal, previous.orElse(null), context); + AbstractNodeCostSearch search = PathingBehavior.createPathfinder(segmentStart, goal, previous.orElse(null), context, false); return search.calculate(Baritone.settings().primaryTimeoutMS.get(), Baritone.settings().failureTimeoutMS.get()); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer } From 943b75455b8759f4d7774afa6fb3d0563ba7b051 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 12:13:49 -0800 Subject: [PATCH 003/140] no point if you don't copy it, really fixes #210 --- src/main/java/baritone/utils/BlockStateInterface.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index b6b264d0d..96493e002 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -23,6 +23,7 @@ import baritone.cache.CachedRegion; import baritone.cache.WorldData; import baritone.utils.accessor.IChunkProviderClient; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -53,7 +54,7 @@ public class BlockStateInterface { public BlockStateInterface(World world, WorldData worldData) { this.worldData = worldData; - this.loadedChunks = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks(); + this.loadedChunks = new Long2ObjectOpenHashMap<>(((IChunkProviderClient) world.getChunkProvider()).loadedChunks()); // make a copy that we can safely access from another thread if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } From 2ba0e6ada673e7952aa1fd650646a1e27a55a070 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:19:04 -0800 Subject: [PATCH 004/140] don't create a new bsi hundreds of times a tick maybe? --- .../api/pathing/movement/IMovement.java | 8 ------- .../baritone/pathing/movement/Movement.java | 13 ++++------- .../movement/movements/MovementDiagonal.java | 9 ++++---- .../baritone/pathing/path/PathExecutor.java | 23 +++++++++++-------- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/api/java/baritone/api/pathing/movement/IMovement.java b/src/api/java/baritone/api/pathing/movement/IMovement.java index 7b3eca5ff..c9b9ea4ba 100644 --- a/src/api/java/baritone/api/pathing/movement/IMovement.java +++ b/src/api/java/baritone/api/pathing/movement/IMovement.java @@ -20,8 +20,6 @@ package baritone.api.pathing.movement; import baritone.api.utils.BetterBlockPos; import net.minecraft.util.math.BlockPos; -import java.util.List; - /** * @author Brady * @since 10/8/2018 @@ -58,10 +56,4 @@ public interface IMovement { BetterBlockPos getDest(); BlockPos getDirection(); - - List toBreak(); - - List toPlace(); - - List toWalkInto(); } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index a3e841c6c..f0f206484 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -244,14 +244,13 @@ public abstract class Movement implements IMovement, MovementHelper { toWalkIntoCached = null; } - @Override - public List toBreak() { + public List toBreak(BlockStateInterface bsi) { if (toBreakCached != null) { return toBreakCached; } List result = new ArrayList<>(); for (BetterBlockPos positionToBreak : positionsToBreak) { - if (!MovementHelper.canWalkThrough(ctx, positionToBreak)) { + if (!MovementHelper.canWalkThrough(bsi, positionToBreak.x, positionToBreak.y, positionToBreak.z)) { result.add(positionToBreak); } } @@ -259,21 +258,19 @@ public abstract class Movement implements IMovement, MovementHelper { return result; } - @Override - public List toPlace() { + public List toPlace(BlockStateInterface bsi) { if (toPlaceCached != null) { return toPlaceCached; } List result = new ArrayList<>(); - if (positionToPlace != null && !MovementHelper.canWalkOn(ctx, positionToPlace)) { + if (positionToPlace != null && !MovementHelper.canWalkOn(bsi, positionToPlace.x, positionToPlace.y, positionToPlace.z)) { result.add(positionToPlace); } toPlaceCached = result; return result; } - @Override - public List toWalkInto() { // overridden by movementdiagonal + public List toWalkInto(BlockStateInterface bsi) { // overridden by movementdiagonal if (toWalkIntoCached == null) { toWalkIntoCached = new ArrayList<>(); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 4a098380f..493852730 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -25,6 +25,7 @@ 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 net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -158,13 +159,13 @@ public class MovementDiagonal extends Movement { } @Override - public List toBreak() { + public List toBreak(BlockStateInterface bsi) { if (toBreakCached != null) { return toBreakCached; } List result = new ArrayList<>(); for (int i = 4; i < 6; i++) { - if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(bsi, positionsToBreak[i].x, positionsToBreak[i].y, positionsToBreak[i].z)) { result.add(positionsToBreak[i]); } } @@ -173,13 +174,13 @@ public class MovementDiagonal extends Movement { } @Override - public List toWalkInto() { + public List toWalkInto(BlockStateInterface bsi) { if (toWalkIntoCached == null) { toWalkIntoCached = new ArrayList<>(); } List result = new ArrayList<>(); for (int i = 0; i < 4; i++) { - if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(bsi, positionsToBreak[i].x, positionsToBreak[i].y, positionsToBreak[i].z)) { result.add(positionsToBreak[i]); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 171dd769a..b17cd2818 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -30,6 +30,7 @@ import baritone.api.utils.input.Input; import baritone.behavior.PathingBehavior; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; +import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; @@ -186,22 +187,23 @@ public class PathExecutor implements IPathExecutor, Helper { } }*/ //long start = System.nanoTime() / 1000000L; + BlockStateInterface bsi = new BlockStateInterface(ctx); for (int i = pathPosition - 10; i < pathPosition + 10; i++) { if (i < 0 || i >= path.movements().size()) { continue; } - IMovement m = path.movements().get(i); - HashSet prevBreak = new HashSet<>(m.toBreak()); - HashSet prevPlace = new HashSet<>(m.toPlace()); - HashSet prevWalkInto = new HashSet<>(m.toWalkInto()); + Movement m = (Movement) path.movements().get(i); + HashSet prevBreak = new HashSet<>(m.toBreak(bsi)); + HashSet prevPlace = new HashSet<>(m.toPlace(bsi)); + HashSet prevWalkInto = new HashSet<>(m.toWalkInto(bsi)); m.resetBlockCache(); - if (!prevBreak.equals(new HashSet<>(m.toBreak()))) { + if (!prevBreak.equals(new HashSet<>(m.toBreak(bsi)))) { recalcBP = true; } - if (!prevPlace.equals(new HashSet<>(m.toPlace()))) { + if (!prevPlace.equals(new HashSet<>(m.toPlace(bsi)))) { recalcBP = true; } - if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto()))) { + if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto(bsi)))) { recalcBP = true; } } @@ -210,9 +212,10 @@ public class PathExecutor implements IPathExecutor, Helper { HashSet newPlace = new HashSet<>(); HashSet newWalkInto = new HashSet<>(); for (int i = pathPosition; i < path.movements().size(); i++) { - newBreak.addAll(path.movements().get(i).toBreak()); - newPlace.addAll(path.movements().get(i).toPlace()); - newWalkInto.addAll(path.movements().get(i).toWalkInto()); + Movement movement = (Movement) path.movements().get(i); + newBreak.addAll(movement.toBreak(bsi)); + newPlace.addAll(movement.toPlace(bsi)); + newWalkInto.addAll(movement.toWalkInto(bsi)); } toBreak = newBreak; toPlace = newPlace; From f9a3a3b78bc0229f266745b3cbabd6e11040c4bb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:30:37 -0800 Subject: [PATCH 005/140] main thread bsi creation doesn't need to copy loaded chunks --- .../java/baritone/behavior/PathingBehavior.java | 2 +- .../pathing/movement/CalculationContext.java | 6 +++++- .../java/baritone/process/GetToBlockProcess.java | 2 +- src/main/java/baritone/process/MineProcess.java | 2 +- .../java/baritone/utils/BlockStateInterface.java | 15 ++++++++++++--- .../baritone/utils/ExampleBaritoneControl.java | 2 +- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 3e8c3595a..1a4b12b9b 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -409,7 +409,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, primaryTimeout = Baritone.settings().planAheadPrimaryTimeoutMS.get(); failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.get(); } - CalculationContext context = new CalculationContext(baritone); // not safe to create on the other thread, it looks up a lot of stuff in minecraft + CalculationContext context = new CalculationContext(baritone, true); // not safe to create on the other thread, it looks up a lot of stuff in minecraft AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context, true); if (!Objects.equals(pathfinder.getGoal(), goal)) { logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index cb4727cc1..ace7670c1 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -60,11 +60,15 @@ public class CalculationContext { private final BetterWorldBorder worldBorder; public CalculationContext(IBaritone baritone) { + this(baritone, false); + } + + public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) { this.baritone = baritone; this.player = baritone.getPlayerContext().player(); this.world = baritone.getPlayerContext().world(); this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld(); - this.bsi = new BlockStateInterface(world, worldData); // TODO TODO TODO + this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO // new CalculationContext() needs to happen, can't add an argument (i'll beat you), can we get the world provider from currentlyTicking? this.toolSet = new ToolSet(player); this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 95f2122b3..920e57433 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -77,7 +77,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain List current = new ArrayList<>(knownLocations); - CalculationContext context = new CalculationContext(baritone); + CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(current, context)); } Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 4ea753871..8b93d1cb6 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -89,7 +89,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain List curr = new ArrayList<>(knownOreLocations); - CalculationContext context = new CalculationContext(baritone); + CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.get()) { diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 96493e002..be49c97c9 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -49,12 +49,21 @@ public class BlockStateInterface { private static final IBlockState AIR = Blocks.AIR.getDefaultState(); public BlockStateInterface(IPlayerContext ctx) { - this(ctx.world(), (WorldData) ctx.worldData()); + this(ctx, false); } - public BlockStateInterface(World world, WorldData worldData) { + public BlockStateInterface(IPlayerContext ctx, boolean copyLoadedChunks) { + this(ctx.world(), (WorldData) ctx.worldData(), copyLoadedChunks); + } + + public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) { this.worldData = worldData; - this.loadedChunks = new Long2ObjectOpenHashMap<>(((IChunkProviderClient) world.getChunkProvider()).loadedChunks()); // make a copy that we can safely access from another thread + Long2ObjectMap worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks(); + if (copyLoadedChunks) { + this.loadedChunks = new Long2ObjectOpenHashMap<>(worldLoaded); // make a copy that we can safely access from another thread + } else { + this.loadedChunks = worldLoaded; // this will only be used on the main thread + } if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 6b2c74482..2c112ee3b 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -208,7 +208,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("No goal."); } else { logDirect("Started segmented calculator"); - SegmentedCalculator.calculateSegmentsThreaded(pathingBehavior.pathStart(), pathingBehavior.getGoal(), new CalculationContext(baritone), ipath -> { + SegmentedCalculator.calculateSegmentsThreaded(pathingBehavior.pathStart(), pathingBehavior.getGoal(), new CalculationContext(baritone, true), ipath -> { logDirect("Found a path"); logDirect("Ends at " + ipath.getDest()); logDirect("Length " + ipath.length()); From 14daf2ce85160a6b746ae0826075640af311b99b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:50:22 -0800 Subject: [PATCH 006/140] unneeded, and was allocating thousands of sets a second --- src/main/java/baritone/pathing/movement/MovementHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 917adc7c2..581b0d0f4 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -465,7 +465,6 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean isFlowing(IBlockState state) { // Will be IFluidState in 1.13 return state.getBlock() instanceof BlockLiquid - && state.getPropertyKeys().contains(BlockLiquid.LEVEL) && state.getValue(BlockLiquid.LEVEL) != 0; } } From 06dd07dbc67b01cc6fa51c01ba7568af76aeb631 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:57:08 -0800 Subject: [PATCH 007/140] believe it or not, this saves thousands of object allocations per second --- src/api/java/baritone/api/utils/VecUtils.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/utils/VecUtils.java b/src/api/java/baritone/api/utils/VecUtils.java index 090cb9d7f..1df011632 100644 --- a/src/api/java/baritone/api/utils/VecUtils.java +++ b/src/api/java/baritone/api/utils/VecUtils.java @@ -81,10 +81,9 @@ public final class VecUtils { * @see #getBlockPosCenter(BlockPos) */ public static double distanceToCenter(BlockPos pos, double x, double y, double z) { - Vec3d center = getBlockPosCenter(pos); - double xdiff = x - center.x; - double ydiff = y - center.y; - double zdiff = z - center.z; + double xdiff = pos.getX() + 0.5 - x; + double ydiff = pos.getY() + 0.5 - y; + double zdiff = pos.getZ() + 0.5 - z; return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); } From cf2765e017d218a465c29901806647ed6439dbcb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:57:54 -0800 Subject: [PATCH 008/140] thousands here too, on long paths --- src/api/java/baritone/api/pathing/calc/IPath.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/pathing/calc/IPath.java b/src/api/java/baritone/api/pathing/calc/IPath.java index 133de5efc..8f0cb68ed 100644 --- a/src/api/java/baritone/api/pathing/calc/IPath.java +++ b/src/api/java/baritone/api/pathing/calc/IPath.java @@ -109,8 +109,9 @@ public interface IPath { default double ticksRemainingFrom(int pathPosition) { double sum = 0; //this is fast because we aren't requesting recalculation, it's just cached - for (int i = pathPosition; i < movements().size(); i++) { - sum += movements().get(i).getCost(); + List movements = movements(); + for (int i = pathPosition; i < movements.size(); i++) { + sum += movements.get(i).getCost(); } return sum; } From d9effc4a299f5cad54b6a6f2b9acb7b46589f505 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:59:47 -0800 Subject: [PATCH 009/140] avoid creating thousands of unmodifiable lists just to get their size --- src/main/java/baritone/pathing/path/SplicedPath.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/baritone/pathing/path/SplicedPath.java b/src/main/java/baritone/pathing/path/SplicedPath.java index f32637180..f2187fe77 100644 --- a/src/main/java/baritone/pathing/path/SplicedPath.java +++ b/src/main/java/baritone/pathing/path/SplicedPath.java @@ -62,6 +62,11 @@ public class SplicedPath extends PathBase { return numNodes; } + @Override + public int length() { + return path.size(); + } + public static Optional trySplice(IPath first, IPath second, boolean allowOverlapCutoff) { if (second == null || first == null) { return Optional.empty(); From 6d1130d2c3eadcfbfa880edb791940cf6b3c5305 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 26 Nov 2018 07:52:00 -0800 Subject: [PATCH 010/140] favored lookup performance --- .../java/baritone/behavior/PathingBehavior.java | 13 +++++++++---- .../java/baritone/pathing/calc/AStarPathFinder.java | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 1a4b12b9b..106f52cc7 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -37,12 +37,15 @@ import baritone.pathing.path.CutoffPath; import baritone.pathing.path.PathExecutor; import baritone.utils.Helper; import baritone.utils.PathRenderer; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.LinkedBlockingQueue; -import java.util.stream.Collectors; public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper { @@ -492,9 +495,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, transformed = new GoalXZ(pos.getX(), pos.getZ()); } } - HashSet favoredPositions = null; + LongOpenHashSet favoredPositions = null; if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) { - favoredPositions = previous.positions().stream().map(BetterBlockPos::longHash).collect(Collectors.toCollection(HashSet::new)); + LongOpenHashSet tmp = new LongOpenHashSet(); + previous.positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos))); + favoredPositions = tmp; } return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 989fda553..d7292da71 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -28,6 +28,7 @@ import baritone.pathing.movement.Moves; import baritone.utils.Helper; import baritone.utils.pathing.BetterWorldBorder; import baritone.utils.pathing.MutableMoveResult; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import java.util.HashSet; import java.util.Optional; @@ -39,10 +40,10 @@ import java.util.Optional; */ public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper { - private final HashSet favoredPositions; + private final LongOpenHashSet favoredPositions; private final CalculationContext calcContext; - public AStarPathFinder(int startX, int startY, int startZ, Goal goal, HashSet favoredPositions, CalculationContext context) { + public AStarPathFinder(int startX, int startY, int startZ, Goal goal, LongOpenHashSet favoredPositions, CalculationContext context) { super(startX, startY, startZ, goal, context); this.favoredPositions = favoredPositions; this.calcContext = context; @@ -63,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestSoFar[i] = startNode; } MutableMoveResult res = new MutableMoveResult(); - HashSet favored = favoredPositions; + LongOpenHashSet favored = favoredPositions; BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); From f25786635bde9539ec745b4b45b28994a0d0b269 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 26 Nov 2018 07:58:10 -0800 Subject: [PATCH 011/140] over 10k less objects per second --- src/main/java/baritone/cache/ChunkPacker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index cd072bb6f..f83d374e5 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -39,6 +39,8 @@ import java.util.*; */ public final class ChunkPacker { + private static final Map resourceCache = new HashMap<>(); + private ChunkPacker() {} public static CachedChunk pack(Chunk chunk) { @@ -120,7 +122,7 @@ public final class ChunkPacker { } public static Block stringToBlock(String name) { - return Block.getBlockFromName(name.contains(":") ? name : "minecraft:" + name); + return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n)); } private static PathingBlockType getPathingBlockType(IBlockState state) { From 58d91342865ab2baf2a6c61f094a590b5cfcd2bd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 26 Nov 2018 15:01:34 -0800 Subject: [PATCH 012/140] fix behavior around cocoa pods and vines, fixes #277 --- .../java/baritone/pathing/movement/MovementHelper.java | 3 ++- .../pathing/movement/movements/MovementDiagonal.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 581b0d0f4..30f48b3bb 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -70,7 +70,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.AIR) { // early return for most common case return true; } - if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA) { return false; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -139,6 +139,7 @@ public interface MovementHelper extends ActionCosts, Helper { || block == Blocks.WEB || block == Blocks.VINE || block == Blocks.LADDER + || block == Blocks.COCOA || block instanceof BlockDoor || block instanceof BlockFenceGate || block instanceof BlockSnow diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 493852730..afe5a976c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -116,7 +116,8 @@ public class MovementDiagonal extends Movement { return COST_INF; } boolean water = false; - if (MovementHelper.isWater(context.getBlock(x, y, z)) || MovementHelper.isWater(destInto.getBlock())) { + Block startIn = context.getBlock(x, y, z); + if (MovementHelper.isWater(startIn) || MovementHelper.isWater(destInto.getBlock())) { // Ignore previous multiplier // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Not even touching the blocks below @@ -125,6 +126,10 @@ public class MovementDiagonal extends Movement { } if (optionA != 0 || optionB != 0) { multiplier *= SQRT_2 - 0.001; // TODO tune + if (startIn == Blocks.LADDER || startIn == Blocks.VINE) { + // edging around doesn't work if doing so would climb a ladder or vine instead of moving sideways + return COST_INF; + } } if (context.canSprint() && !water) { // If we aren't edging around anything, and we aren't in water From a8404a728631cd1ac91b3a7096841b74b10d786c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 26 Nov 2018 15:32:28 -0800 Subject: [PATCH 013/140] only walk through supported snow, fixes #276 --- src/main/java/baritone/pathing/movement/MovementHelper.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 30f48b3bb..9d31a3791 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -92,7 +92,11 @@ public interface MovementHelper extends ActionCosts, Helper { if (snow) { // the check in BlockSnow.isPassable is layers < 5 // while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling - return state.getValue(BlockSnow.LAYERS) < 3; + if (state.getValue(BlockSnow.LAYERS) >= 3) { + return false; + } + // ok, it's low enough we could walk through it, but is it supported? + return canWalkOn(bsi, x, y - 1, z); } if (trapdoor) { return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable From 043d6ffd2088eda7e085d9b84806698a461b3c43 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 27 Nov 2018 10:37:48 -0800 Subject: [PATCH 014/140] improve pathingbehavior resiliency --- src/main/java/baritone/behavior/PathingBehavior.java | 4 +++- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 106f52cc7..c6c8042ff 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -470,7 +470,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, queuePathEvent(PathEvent.NEXT_CALC_FAILED); } } else { - throw new IllegalStateException("I have no idea what to do with this path"); + //throw new IllegalStateException("I have no idea what to do with this path"); + // no point in throwing an exception here, and it gets it stuck with inProgress being not null + logDirect("Warning: PathingBehaivor illegal state! Discarding invalid path!"); } } if (talkAboutIt && current != null && current.getPath() != null) { diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index f2dcf4b19..2a1681b75 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -86,7 +86,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { @Override public synchronized PathCalculationResult calculate(long primaryTimeout, long failureTimeout) { if (isFinished) { - throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); + throw new IllegalStateException("Path finder cannot be reused!"); } cancelRequested = false; try { From 6f7729e34ea68be69ff5fb4d178f6a0ad79ecfe8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 28 Nov 2018 18:21:27 -0800 Subject: [PATCH 015/140] add missing synchronized blocks --- .../baritone/behavior/PathingBehavior.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index c6c8042ff..bd2146b85 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -280,11 +280,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } public void softCancelIfSafe() { - if (!isSafeToCancel()) { - return; + synchronized (pathPlanLock) { + if (!isSafeToCancel()) { + return; + } + current = null; + next = null; } - current = null; - next = null; cancelRequested = true; getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours // do everything BUT clear keys @@ -293,8 +295,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, // just cancel the current path public void secretInternalSegmentCancel() { queuePathEvent(PathEvent.CANCELED); - current = null; - next = null; + synchronized (pathPlanLock) { + current = null; + next = null; + } baritone.getInputOverrideHandler().clearAllKeys(); getInProgress().ifPresent(AbstractNodeCostSearch::cancel); baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); @@ -334,7 +338,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } public void secretCursedFunctionDoNotCall(IPath path) { - current = new PathExecutor(this, path); + synchronized (pathPlanLock) { + current = new PathExecutor(this, path); + } } /** From 5daaaf5282455ddda314fd3e030909efbc41445d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 29 Nov 2018 15:33:35 -0800 Subject: [PATCH 016/140] add settings reset command --- src/api/java/baritone/api/Settings.java | 6 ++++++ src/main/java/baritone/utils/ExampleBaritoneControl.java | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index a835ed73f..1a3fef080 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -553,6 +553,12 @@ public class Settings { */ public final List> allSettings; + public void reset() { + for (Setting setting : allSettings) { + setting.value = setting.defaultValue; + } + } + public class Setting { public T value; public final T defaultValue; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 2c112ee3b..958af7765 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -277,6 +277,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { }); return true; } + if (msg.equals("reset")) { + Baritone.settings().reset(); + logDirect("Baritone settings reset"); + return true; + } if (msg.startsWith("followplayers")) { baritone.getFollowProcess().follow(EntityPlayer.class::isInstance); // O P P A logDirect("Following any players"); From 6a402b4a2bd6867e2fdff0348bc4b63300f7095d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 29 Nov 2018 20:36:19 -0800 Subject: [PATCH 017/140] fix the fire thing in a slightly different way --- src/api/java/baritone/api/utils/Rotation.java | 11 +++++++++++ src/main/java/baritone/pathing/movement/Movement.java | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java index ea10c7ec6..28afbf658 100644 --- a/src/api/java/baritone/api/utils/Rotation.java +++ b/src/api/java/baritone/api/utils/Rotation.java @@ -110,6 +110,17 @@ public class Rotation { ); } + /** + * Is really close to + * + * @param other another rotation + * @return are they really close + */ + public boolean isReallyCloseTo(Rotation other) { + float yawDiff = Math.abs(this.yaw - other.yaw); // you cant fool me + return (yawDiff < 0.01 || yawDiff > 359.9) && Math.abs(this.pitch - other.pitch) < 0.01; + } + /** * Clamps the specified pitch value between -90 and 90. * diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index f0f206484..4105b5e70 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -151,9 +151,10 @@ public abstract class Movement implements IMovement, MovementHelper { somethingInTheWay = true; Optional reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance()); if (reachable.isPresent()) { + Rotation rotTowardsBlock = reachable.get(); MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos)); - state.setTarget(new MovementState.MovementTarget(reachable.get(), true)); - if (Objects.equals(ctx.getSelectedBlock().orElse(null), blockPos)) { + state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true)); + if (Objects.equals(ctx.getSelectedBlock().orElse(null), blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) { state.setInput(Input.CLICK_LEFT, true); } return false; From 5ef03ba1d570072ebe9e8716932eabf8cce3e009 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 30 Nov 2018 23:06:16 -0800 Subject: [PATCH 018/140] didn't make sense like that --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fa8a2c96..904f3d61c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Building Baritone: $ gradlew build ``` -For example, to replace out Impact 4.4's Baritone build with a customized one, switch to the `impact4.4-compat` branch, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`). +To replace out Impact 4.4's Baritone build with a customized one, switch to the `impact4.4-compat` branch, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`). ## IntelliJ's Gradle UI - Open the project in IntelliJ as a Gradle project From a017e14a48dc7770991edc541c971501488720a0 Mon Sep 17 00:00:00 2001 From: babbaj Date: Sat, 1 Dec 2018 06:31:40 -0500 Subject: [PATCH 019/140] give proguard the right jar based on mapping type --- .../baritone/gradle/task/ProguardTask.java | 105 ++++++++++++++++-- .../baritone/gradle/util/MappingType.java | 9 ++ .../baritone/gradle/util/ReobfWrapper.java | 40 +++++++ scripts/proguard.pro | 5 +- 4 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 buildSrc/src/main/java/baritone/gradle/util/MappingType.java create mode 100644 buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 350f74469..bae59bb70 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -18,10 +18,17 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; +import baritone.gradle.util.MappingType; +import baritone.gradle.util.ReobfWrapper; import com.google.gson.*; +import java.lang.reflect.Field; +import java.nio.file.StandardCopyOption; +import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; +import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.internal.plugins.DefaultConvention; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; import org.gradle.internal.Pair; @@ -163,15 +170,13 @@ public class ProguardTask extends BaritoneGradleTask { // Iterate the required libraries to copy them to tempLibraries for (String lib : this.requiredLibraries) { - // Download the version jar from the URL acquired from the version manifest - if (lib.startsWith("minecraft")) { - String version = lib.split("-")[1]; - Path versionJar = getTemporaryFile("tempLibraries/" + lib + ".jar"); - if (!Files.exists(versionJar)) { - JsonObject versionJson = PARSER.parse(new InputStreamReader(new URL(this.versionDownloadMap.get(version)).openStream())).getAsJsonObject(); - String url = versionJson.getAsJsonObject("downloads").getAsJsonObject("client").getAsJsonPrimitive("url").getAsString(); - write(new URL(url).openStream(), versionJar); - } + // copy from the forgegradle cache + if (lib.equals("minecraft")) { + final Path cachedJar = getMinecraftJar(); + final Path inTempDir = getTemporaryFile("tempLibraries/" + "minecraft.jar"); + // TODO: maybe try not to copy every time + Files.copy(cachedJar, inTempDir, StandardCopyOption.REPLACE_EXISTING); + continue; } @@ -195,6 +200,88 @@ public class ProguardTask extends BaritoneGradleTask { } } + // a bunch of bullshit to get the path to the cached jar + private Path getMinecraftJar() throws Exception { + MappingType mappingType; + try { + mappingType = getMappingType(); + } catch (Exception e) { + System.err.println("Failed to get mapping type, assuming NOTCH"); + mappingType = MappingType.SEARGE; + } + + String suffix; + switch (mappingType) { + case NOTCH: + suffix = ""; + break; + case SEARGE: + suffix = "-srgBin"; + break; + case CUSTOM: + throw new IllegalStateException("custom mappings not supported"); + default: + throw new IllegalStateException("Unknown mapping type: " + mappingType); + } + + DefaultConvention convention = (DefaultConvention)this.getProject().getConvention(); + final Object extension = convention.getAsMap().get("minecraft"); + Objects.requireNonNull(extension); + + // for some reason cant use Class.forName + Class class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); + Field f_replacer = class_baseExtension.getDeclaredField("replacer"); + f_replacer.setAccessible(true); + final Object replacer = f_replacer.get(extension); + Class class_replacementProvider = replacer.getClass(); + Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap"); + replacement_replaceMap.setAccessible(true); + + final Map replacements = (Map)replacement_replaceMap.get(replacer); + final String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; + final String mcVersion = replacements.get("MC_VERSION").toString(); + final String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); + final String fullJarName = "minecraft" + "-" + mcVersion + suffix + ".jar"; + + final String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); + + String jarPath; + if (mappingType == MappingType.SEARGE) { + jarPath = String.format("%s/%s/%s", baseDir, mcpInsert, fullJarName); + + } else { + jarPath = baseDir + fullJarName; + } + jarPath = jarPath + .replace("/", File.separator) + .replace("\\", File.separator);// fucking regex + + return new File(jarPath).toPath(); + } + + // throws IllegalStateException if mapping type is ambiguous or it fails to find it + private MappingType getMappingType() { + // if it fails to find this then its probably a forgegradle version problem + final Set reobf = (NamedDomainObjectContainer) this.getProject().getExtensions().getByName("reobf"); + + final List mappingTypes = getUsedMappingTypes(reobf); + final long mappingTypesUsed = mappingTypes.size(); + if (mappingTypesUsed == 0) + throw new IllegalStateException("Failed to find mapping type (no jar task?)"); + if (mappingTypesUsed > 1) + throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)"); + + return mappingTypes.get(0); + } + + private List getUsedMappingTypes(Set reobf) { + return reobf.stream() + .map(ReobfWrapper::new) + .map(ReobfWrapper::getMappingType) + .distinct() + .collect(Collectors.toList()); + } + private void proguardApi() throws Exception { runProguard(getTemporaryFile(PROGUARD_API_CONFIG)); Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString()); diff --git a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java new file mode 100644 index 000000000..1de59d76b --- /dev/null +++ b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java @@ -0,0 +1,9 @@ +package baritone.gradle.util; + +// this should be the same as in ForgeGradle +// credit 2 asmlibgradle (i made this btw) +public enum MappingType { + SEARGE, + NOTCH, + CUSTOM // forgegradle +} \ No newline at end of file diff --git a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java new file mode 100644 index 000000000..128a19412 --- /dev/null +++ b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java @@ -0,0 +1,40 @@ +package baritone.gradle.util; + +import java.lang.reflect.Field; +import java.util.Objects; + +public class ReobfWrapper { + + private final Object instance; + private final Class type; + + public ReobfWrapper(Object instance) { + this.instance = instance; + Objects.requireNonNull(instance); + this.type = instance.getClass(); + } + + public String getName() { + try { + Field nameField = type.getDeclaredField("name"); + nameField.setAccessible(true); + return (String)nameField.get(this.instance); + } catch (ReflectiveOperationException ex) { + throw new Error(ex); + } + } + + public MappingType getMappingType() { + try { + Field enumField = type.getDeclaredField("mappingType"); + enumField.setAccessible(true); + Enum meme = (Enum) enumField.get(this.instance); + MappingType mappingType = MappingType.values()[meme.ordinal()]; + if (!meme.name().equals(mappingType.name())) + throw new IllegalStateException("ForgeGradle ReobfMappingType is not equivalent to MappingType (version error?)"); + return mappingType; + } catch (ReflectiveOperationException ex) { + throw new Error(ex); + } + } +} \ No newline at end of file diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 270a06317..24650dda4 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -31,7 +31,10 @@ # copy all necessary libraries into tempLibraries to build --libraryjars 'tempLibraries/minecraft-1.12.2.jar' +-libraryjars 'tempLibraries/minecraft.jar' + +# The correct jar will be copied from the forgegradle cache based on the mapping type being compiled with +#-libraryjars 'tempLibraries/minecraft.jar' -libraryjars 'tempLibraries/SimpleTweaker-1.2.jar' From 0a2e45b64bbe73c50c9d68a639030d41e6dc38b5 Mon Sep 17 00:00:00 2001 From: babbaj Date: Sat, 1 Dec 2018 06:42:21 -0500 Subject: [PATCH 020/140] make codacy happy --- buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index bae59bb70..f9da31180 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -175,7 +175,7 @@ public class ProguardTask extends BaritoneGradleTask { final Path cachedJar = getMinecraftJar(); final Path inTempDir = getTemporaryFile("tempLibraries/" + "minecraft.jar"); // TODO: maybe try not to copy every time - Files.copy(cachedJar, inTempDir, StandardCopyOption.REPLACE_EXISTING); + Files.copy(cachedJar, inTempDir, REPLACE_EXISTING); continue; } From f2e02794b8d50c7a726b35b71db107fbd7010d57 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Dec 2018 10:04:49 -0800 Subject: [PATCH 021/140] tweak block scanning, fixes #200 --- src/main/java/baritone/cache/CachedChunk.java | 2 +- src/main/java/baritone/cache/ChunkPacker.java | 5 +---- src/main/java/baritone/process/MineProcess.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java index 1e55cb646..ebf0bfc95 100644 --- a/src/main/java/baritone/cache/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -35,7 +35,7 @@ public final class CachedChunk { static { HashSet temp = new HashSet<>(); - temp.add(Blocks.DIAMOND_ORE); + //temp.add(Blocks.DIAMOND_ORE); temp.add(Blocks.DIAMOND_BLOCK); //temp.add(Blocks.COAL_ORE); temp.add(Blocks.COAL_BLOCK); diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index f83d374e5..60ac63315 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -93,10 +93,7 @@ public final class ChunkPacker { IBlockState[] blocks = new IBlockState[256]; for (int z = 0; z < 16; z++) { - // @formatter:off - https: -//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html - // @formatter:on + https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html for (int x = 0; x < 16; x++) { for (int y = 255; y >= 0; y--) { int index = CachedChunk.getPositionIndex(x, y, z); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 8b93d1cb6..9347dba24 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -210,7 +210,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro //long b = System.currentTimeMillis(); for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { - locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 1)); + locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2)); } else { uninteresting.add(m); } From 7f73b4554aaa82d257a9c7e87166cb40de2c7983 Mon Sep 17 00:00:00 2001 From: 0x22 <0x22@futureclient.net> Date: Sat, 1 Dec 2018 13:22:11 -0500 Subject: [PATCH 022/140] Feed codacy and leijurv at the same time? --- build.gradle | 1 - .../baritone/gradle/task/ProguardTask.java | 51 +++--------- .../baritone/gradle/util/MappingType.java | 30 +++++-- .../baritone/gradle/util/ReobfWrapper.java | 79 ++++++++++++------- scripts/proguard.pro | 4 +- 5 files changed, 90 insertions(+), 75 deletions(-) diff --git a/build.gradle b/build.gradle index e0b556a24..80a2de1c7 100755 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,6 @@ jar { task proguard(type: ProguardTask) { url 'https://downloads.sourceforge.net/project/proguard/proguard/6.0/proguard6.0.3.zip' extract 'proguard6.0.3/lib/proguard.jar' - versionManifest 'https://launchermeta.mojang.com/mc/game/version_manifest.json' } task createDist(type: CreateDistTask, dependsOn: proguard) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index f9da31180..84f9663ba 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -20,9 +20,7 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; import baritone.gradle.util.MappingType; import baritone.gradle.util.ReobfWrapper; -import com.google.gson.*; import java.lang.reflect.Field; -import java.nio.file.StandardCopyOption; import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.gradle.api.NamedDomainObjectContainer; @@ -59,10 +57,6 @@ public class ProguardTask extends BaritoneGradleTask { @Input private String extract; - @Input - private String versionManifest; - - private Map versionDownloadMap; private List requiredLibraries; @TaskAction @@ -74,7 +68,6 @@ public class ProguardTask extends BaritoneGradleTask { downloadProguard(); extractProguard(); generateConfigs(); - downloadVersionManifest(); acquireDependencies(); proguardApi(); proguardStandalone(); @@ -139,20 +132,6 @@ public class ProguardTask extends BaritoneGradleTask { }); } - private void downloadVersionManifest() throws Exception { - Path manifestJson = getTemporaryFile(VERSION_MANIFEST); - write(new URL(this.versionManifest).openStream(), manifestJson); - - // Place all the versions in the map with their download URL - this.versionDownloadMap = new HashMap<>(); - JsonObject json = readJson(Files.readAllLines(manifestJson)).getAsJsonObject(); - JsonArray versions = json.getAsJsonArray("versions"); - versions.forEach(element -> { - JsonObject object = element.getAsJsonObject(); - this.versionDownloadMap.put(object.get("id").getAsString(), object.get("url").getAsString()); - }); - } - private void acquireDependencies() throws Exception { // Create a map of all of the dependencies that we are able to access in this project @@ -173,7 +152,7 @@ public class ProguardTask extends BaritoneGradleTask { // copy from the forgegradle cache if (lib.equals("minecraft")) { final Path cachedJar = getMinecraftJar(); - final Path inTempDir = getTemporaryFile("tempLibraries/" + "minecraft.jar"); + final Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar"); // TODO: maybe try not to copy every time Files.copy(cachedJar, inTempDir, REPLACE_EXISTING); @@ -200,14 +179,14 @@ public class ProguardTask extends BaritoneGradleTask { } } - // a bunch of bullshit to get the path to the cached jar + // a bunch of epic stuff to get the path to the cached jar private Path getMinecraftJar() throws Exception { MappingType mappingType; try { mappingType = getMappingType(); } catch (Exception e) { - System.err.println("Failed to get mapping type, assuming NOTCH"); - mappingType = MappingType.SEARGE; + System.err.println("Failed to get mapping type, assuming NOTCH."); + mappingType = MappingType.NOTCH; } String suffix; @@ -219,12 +198,12 @@ public class ProguardTask extends BaritoneGradleTask { suffix = "-srgBin"; break; case CUSTOM: - throw new IllegalStateException("custom mappings not supported"); + throw new IllegalStateException("Custom mappings not supported!"); default: throw new IllegalStateException("Unknown mapping type: " + mappingType); } - DefaultConvention convention = (DefaultConvention)this.getProject().getConvention(); + DefaultConvention convention = (DefaultConvention) this.getProject().getConvention(); final Object extension = convention.getAsMap().get("minecraft"); Objects.requireNonNull(extension); @@ -237,24 +216,23 @@ public class ProguardTask extends BaritoneGradleTask { Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap"); replacement_replaceMap.setAccessible(true); - final Map replacements = (Map)replacement_replaceMap.get(replacer); + final Map replacements = (Map) replacement_replaceMap.get(replacer); final String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; final String mcVersion = replacements.get("MC_VERSION").toString(); final String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); - final String fullJarName = "minecraft" + "-" + mcVersion + suffix + ".jar"; + final String fullJarName = "minecraft-" + mcVersion + suffix + ".jar"; final String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); String jarPath; if (mappingType == MappingType.SEARGE) { jarPath = String.format("%s/%s/%s", baseDir, mcpInsert, fullJarName); - } else { jarPath = baseDir + fullJarName; } jarPath = jarPath - .replace("/", File.separator) - .replace("\\", File.separator);// fucking regex + .replace("/", File.separator) + .replace("\\", File.separator); // hecking regex return new File(jarPath).toPath(); } @@ -266,10 +244,11 @@ public class ProguardTask extends BaritoneGradleTask { final List mappingTypes = getUsedMappingTypes(reobf); final long mappingTypesUsed = mappingTypes.size(); - if (mappingTypesUsed == 0) + if (mappingTypesUsed == 0) { throw new IllegalStateException("Failed to find mapping type (no jar task?)"); - if (mappingTypesUsed > 1) + } if (mappingTypesUsed > 1) { throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)"); + } return mappingTypes.get(0); } @@ -306,10 +285,6 @@ public class ProguardTask extends BaritoneGradleTask { this.extract = extract; } - public void setVersionManifest(String versionManifest) { - this.versionManifest = versionManifest; - } - private void runProguard(Path config) throws Exception { // Delete the existing proguard output file. Proguard probably handles this already, but why not do it ourselves if (Files.exists(this.proguardOut)) { diff --git a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java index 1de59d76b..4a6c10ffb 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java +++ b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java @@ -1,9 +1,29 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + package baritone.gradle.util; -// this should be the same as in ForgeGradle -// credit 2 asmlibgradle (i made this btw) +/** + * All credits go to AsmLibGradle and its contributors. + * + * @see Original Source + */ public enum MappingType { - SEARGE, - NOTCH, - CUSTOM // forgegradle + SEARGE, + NOTCH, + CUSTOM // forgegradle } \ No newline at end of file diff --git a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java index 128a19412..92f38a9f9 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java +++ b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java @@ -1,40 +1,63 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + package baritone.gradle.util; import java.lang.reflect.Field; import java.util.Objects; +/** + * All credits go to AsmLibGradle and its contributors. + * + * @see Original Source + */ public class ReobfWrapper { - private final Object instance; - private final Class type; + private final Object instance; + private final Class type; - public ReobfWrapper(Object instance) { - this.instance = instance; - Objects.requireNonNull(instance); - this.type = instance.getClass(); - } - - public String getName() { - try { - Field nameField = type.getDeclaredField("name"); - nameField.setAccessible(true); - return (String)nameField.get(this.instance); - } catch (ReflectiveOperationException ex) { - throw new Error(ex); + public ReobfWrapper(Object instance) { + this.instance = instance; + Objects.requireNonNull(instance); + this.type = instance.getClass(); } - } - public MappingType getMappingType() { - try { - Field enumField = type.getDeclaredField("mappingType"); - enumField.setAccessible(true); - Enum meme = (Enum) enumField.get(this.instance); - MappingType mappingType = MappingType.values()[meme.ordinal()]; - if (!meme.name().equals(mappingType.name())) - throw new IllegalStateException("ForgeGradle ReobfMappingType is not equivalent to MappingType (version error?)"); - return mappingType; - } catch (ReflectiveOperationException ex) { - throw new Error(ex); + public String getName() { + try { + Field nameField = type.getDeclaredField("name"); + nameField.setAccessible(true); + return (String) nameField.get(this.instance); + } catch (ReflectiveOperationException ex) { + throw new IllegalStateException(ex); + } + } + + public MappingType getMappingType() { + try { + Field enumField = type.getDeclaredField("mappingType"); + enumField.setAccessible(true); + Enum aEnum = (Enum) enumField.get(this.instance); + MappingType mappingType = MappingType.values()[aEnum.ordinal()]; + if (!aEnum.name().equals(mappingType.name())) { + throw new IllegalStateException("ForgeGradle ReobfMappingType is not equivalent to MappingType (version error?)"); + } + return mappingType; + } catch (ReflectiveOperationException ex) { + throw new IllegalStateException(ex); + } } - } } \ No newline at end of file diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 24650dda4..07e1ec414 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -31,10 +31,8 @@ # copy all necessary libraries into tempLibraries to build --libraryjars 'tempLibraries/minecraft.jar' - # The correct jar will be copied from the forgegradle cache based on the mapping type being compiled with -#-libraryjars 'tempLibraries/minecraft.jar' +-libraryjars 'tempLibraries/minecraft.jar' -libraryjars 'tempLibraries/SimpleTweaker-1.2.jar' From 07ce0a47f7f02bdfcebbf8c75b7237fd41c7c6de Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Dec 2018 10:45:58 -0800 Subject: [PATCH 023/140] cleanup --- .../baritone/gradle/task/ProguardTask.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 84f9663ba..235b0d31d 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -20,8 +20,6 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; import baritone.gradle.util.MappingType; import baritone.gradle.util.ReobfWrapper; -import java.lang.reflect.Field; -import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.artifacts.Configuration; @@ -32,12 +30,14 @@ import org.gradle.api.tasks.TaskAction; import org.gradle.internal.Pair; import java.io.*; +import java.lang.reflect.Field; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -151,8 +151,8 @@ public class ProguardTask extends BaritoneGradleTask { for (String lib : this.requiredLibraries) { // copy from the forgegradle cache if (lib.equals("minecraft")) { - final Path cachedJar = getMinecraftJar(); - final Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar"); + Path cachedJar = getMinecraftJar(); + Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar"); // TODO: maybe try not to copy every time Files.copy(cachedJar, inTempDir, REPLACE_EXISTING); @@ -204,25 +204,25 @@ public class ProguardTask extends BaritoneGradleTask { } DefaultConvention convention = (DefaultConvention) this.getProject().getConvention(); - final Object extension = convention.getAsMap().get("minecraft"); + Object extension = convention.getAsMap().get("minecraft"); Objects.requireNonNull(extension); // for some reason cant use Class.forName Class class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); Field f_replacer = class_baseExtension.getDeclaredField("replacer"); f_replacer.setAccessible(true); - final Object replacer = f_replacer.get(extension); + Object replacer = f_replacer.get(extension); Class class_replacementProvider = replacer.getClass(); Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap"); replacement_replaceMap.setAccessible(true); - final Map replacements = (Map) replacement_replaceMap.get(replacer); - final String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; - final String mcVersion = replacements.get("MC_VERSION").toString(); - final String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); - final String fullJarName = "minecraft-" + mcVersion + suffix + ".jar"; + Map replacements = (Map) replacement_replaceMap.get(replacer); + String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; + String mcVersion = replacements.get("MC_VERSION").toString(); + String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); + String fullJarName = "minecraft-" + mcVersion + suffix + ".jar"; - final String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); + String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); String jarPath; if (mappingType == MappingType.SEARGE) { @@ -240,13 +240,14 @@ public class ProguardTask extends BaritoneGradleTask { // throws IllegalStateException if mapping type is ambiguous or it fails to find it private MappingType getMappingType() { // if it fails to find this then its probably a forgegradle version problem - final Set reobf = (NamedDomainObjectContainer) this.getProject().getExtensions().getByName("reobf"); + Set reobf = (NamedDomainObjectContainer) this.getProject().getExtensions().getByName("reobf"); - final List mappingTypes = getUsedMappingTypes(reobf); - final long mappingTypesUsed = mappingTypes.size(); + List mappingTypes = getUsedMappingTypes(reobf); + long mappingTypesUsed = mappingTypes.size(); if (mappingTypesUsed == 0) { throw new IllegalStateException("Failed to find mapping type (no jar task?)"); - } if (mappingTypesUsed > 1) { + } + if (mappingTypesUsed > 1) { throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)"); } @@ -255,10 +256,10 @@ public class ProguardTask extends BaritoneGradleTask { private List getUsedMappingTypes(Set reobf) { return reobf.stream() - .map(ReobfWrapper::new) - .map(ReobfWrapper::getMappingType) - .distinct() - .collect(Collectors.toList()); + .map(ReobfWrapper::new) + .map(ReobfWrapper::getMappingType) + .distinct() + .collect(Collectors.toList()); } private void proguardApi() throws Exception { @@ -314,7 +315,7 @@ public class ProguardTask extends BaritoneGradleTask { while ((line = reader.readLine()) != null) { System.out.println(line); } - } catch (final Exception e) { + } catch (Exception e) { e.printStackTrace(); } }).start(); From 57a3330200f5644f829df8e441b833d0a843fd7c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 1 Dec 2018 10:49:14 -0800 Subject: [PATCH 024/140] don't splice if not on ground --- src/main/java/baritone/pathing/path/PathExecutor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index b17cd2818..15948d456 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -349,6 +349,9 @@ public class PathExecutor implements IPathExecutor, Helper { * Regardless of current path position, snap to the current player feet if possible */ public boolean snipsnapifpossible() { + if (!ctx.player().onGround) { + return false; + } int index = path.positions().indexOf(ctx.playerFeet()); if (index == -1) { return false; From 5a97c512f796ee41569c9c0700c71d92d31af42a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 16:05:21 -0800 Subject: [PATCH 025/140] fix rare exception --- src/main/java/baritone/utils/Helper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 0687d5601..9fc5aee32 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -67,6 +67,6 @@ public interface Helper { ITextComponent component = MESSAGE_PREFIX.createCopy(); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(new TextComponentString(" " + message)); - Baritone.settings().logger.get().accept(component); + Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component)); } } From 1a6c0cd4d9495d32405c972295ab234c32030479 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 18:27:49 -0800 Subject: [PATCH 026/140] avoid mobs and spawners, fixes #162, fixes #240, fixes #278 --- src/api/java/baritone/api/Settings.java | 25 ++++++++ .../baritone/behavior/PathingBehavior.java | 13 +++-- .../pathing/calc/AStarPathFinder.java | 17 +++--- .../utils/pathing/AvoidanceHelper.java | 58 +++++++++++++++++++ 4 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 src/main/java/baritone/utils/pathing/AvoidanceHelper.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1a3fef080..fcaea2893 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -158,6 +158,31 @@ public class Settings { */ public Setting backtrackCostFavoringCoefficient = new Setting<>(0.5); + /** + * Toggle the following 4 settings + *

+ * They have a noticable performance impact, so they default off + */ + public Setting avoidance = new Setting<>(false); + /** + * Set to 1.0 to effectively disable this feature + *

+ * Set below 1.0 to go out of your way to walk near mob spawners + */ + public Setting mobSpawnerAvoidanceCoefficient = new Setting<>(2.0); + + public Setting mobSpawnerAvoidanceRadius = new Setting<>(16); + + /** + * Set to 1.0 to effectively disable this feature + *

+ * Set below 1.0 to go out of your way to walk near mobs + */ + public Setting mobAvoidanceCoefficient = new Setting<>(1.5); + + public Setting mobAvoidanceRadius = new Setting<>(8); + + /** * Don't repropagate cost improvements below 0.01 ticks. They're all just floating point inaccuracies, * and there's no point. diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index bd2146b85..ec83a2687 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -37,7 +37,8 @@ import baritone.pathing.path.CutoffPath; import baritone.pathing.path.PathExecutor; import baritone.utils.Helper; import baritone.utils.PathRenderer; -import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import baritone.utils.pathing.AvoidanceHelper; +import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -503,12 +504,12 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, transformed = new GoalXZ(pos.getX(), pos.getZ()); } } - LongOpenHashSet favoredPositions = null; - if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) { - LongOpenHashSet tmp = new LongOpenHashSet(); - previous.positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos))); - favoredPositions = tmp; + Long2DoubleOpenHashMap favoredPositions = new Long2DoubleOpenHashMap(); + double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); + if (coeff != 1D && previous != null) { + previous.positions().forEach(pos -> favoredPositions.put(BetterBlockPos.longHash(pos), coeff)); } + AvoidanceHelper.INSTANCE.apply(favoredPositions, context.getBaritone().getPlayerContext()); return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index d7292da71..14b17b805 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -28,9 +28,8 @@ import baritone.pathing.movement.Moves; import baritone.utils.Helper; import baritone.utils.pathing.BetterWorldBorder; import baritone.utils.pathing.MutableMoveResult; -import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; -import java.util.HashSet; import java.util.Optional; /** @@ -40,10 +39,10 @@ import java.util.Optional; */ public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper { - private final LongOpenHashSet favoredPositions; + private final Long2DoubleOpenHashMap favoredPositions; private final CalculationContext calcContext; - public AStarPathFinder(int startX, int startY, int startZ, Goal goal, LongOpenHashSet favoredPositions, CalculationContext context) { + public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Long2DoubleOpenHashMap favoredPositions, CalculationContext context) { super(startX, startY, startZ, goal, context); this.favoredPositions = favoredPositions; this.calcContext = context; @@ -64,7 +63,8 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestSoFar[i] = startNode; } MutableMoveResult res = new MutableMoveResult(); - LongOpenHashSet favored = favoredPositions; + Long2DoubleOpenHashMap favored = favoredPositions; + favored.defaultReturnValue(1.0D); BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); @@ -77,7 +77,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel int numNodes = 0; int numMovementsConsidered = 0; int numEmptyChunk = 0; - boolean favoring = favored != null; + boolean favoring = favored != null && !favored.isEmpty(); 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(); @@ -137,9 +137,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset)); } long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z); - if (favoring && favored.contains(hashCode)) { + favored.get(hashCode); + if (favoring) { // see issue #18 - actionCost *= favorCoeff; + actionCost *= favored.get(hashCode); } PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode); double tentativeCost = currentNode.cost + actionCost; diff --git a/src/main/java/baritone/utils/pathing/AvoidanceHelper.java b/src/main/java/baritone/utils/pathing/AvoidanceHelper.java new file mode 100644 index 000000000..0201eef28 --- /dev/null +++ b/src/main/java/baritone/utils/pathing/AvoidanceHelper.java @@ -0,0 +1,58 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.pathing; + +import baritone.Baritone; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.IPlayerContext; +import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.util.math.BlockPos; + +public enum AvoidanceHelper { + INSTANCE; + + public void apply(Long2DoubleOpenHashMap map, IPlayerContext ctx) { + if (!Baritone.settings().avoidance.get()) { + return; + } + long start = System.currentTimeMillis(); + double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.get(); + double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.get(); + if (mobSpawnerCoeff != 1.0D) { + ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> sphere(mobspawner, Baritone.settings().mobSpawnerAvoidanceRadius.get(), map, mobSpawnerCoeff)); + } + if (mobCoeff != 1.0D) { + ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> sphere(new BlockPos(entity), Baritone.settings().mobAvoidanceRadius.get(), map, mobCoeff)); + } + long end = System.currentTimeMillis(); + System.out.println("Took " + (end - start) + "ms to generate avoidance of " + map.size() + " blocks"); + } + + private void sphere(BlockPos center, int radius, Long2DoubleOpenHashMap map, double coeff) { + for (int x = -radius; x <= radius; x++) { + for (int y = -radius; y <= radius; y++) { + for (int z = -radius; z <= radius; z++) { + if (x * x + y * y + z * z <= radius * radius) { + map.put(BetterBlockPos.longHash(center.getX() + x, center.getY() + y, center.getZ() + z), coeff); + } + } + } + } + } +} From 36cfcbbbe3cfcb0d6b609da31cf6306e22cdbaa7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 19:25:59 -0800 Subject: [PATCH 027/140] avoidances --- .../baritone/behavior/PathingBehavior.java | 12 +-- .../pathing/calc/AStarPathFinder.java | 16 +-- .../{AvoidanceHelper.java => Avoidance.java} | 51 +++++++-- .../java/baritone/utils/pathing/Favoring.java | 100 ++++++++++++++++++ 4 files changed, 151 insertions(+), 28 deletions(-) rename src/main/java/baritone/utils/pathing/{AvoidanceHelper.java => Avoidance.java} (51%) create mode 100644 src/main/java/baritone/utils/pathing/Favoring.java diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index ec83a2687..53bea7055 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -37,8 +37,7 @@ import baritone.pathing.path.CutoffPath; import baritone.pathing.path.PathExecutor; import baritone.utils.Helper; import baritone.utils.PathRenderer; -import baritone.utils.pathing.AvoidanceHelper; -import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; +import baritone.utils.pathing.Favoring; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -504,13 +503,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, transformed = new GoalXZ(pos.getX(), pos.getZ()); } } - Long2DoubleOpenHashMap favoredPositions = new Long2DoubleOpenHashMap(); - double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); - if (coeff != 1D && previous != null) { - previous.positions().forEach(pos -> favoredPositions.put(BetterBlockPos.longHash(pos), coeff)); - } - AvoidanceHelper.INSTANCE.apply(favoredPositions, context.getBaritone().getPlayerContext()); - return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context); + Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous); + return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoring, context); } @Override diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 14b17b805..06f25d9c6 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -27,8 +27,8 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Moves; import baritone.utils.Helper; import baritone.utils.pathing.BetterWorldBorder; +import baritone.utils.pathing.Favoring; import baritone.utils.pathing.MutableMoveResult; -import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import java.util.Optional; @@ -39,12 +39,12 @@ import java.util.Optional; */ public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper { - private final Long2DoubleOpenHashMap favoredPositions; + private final Favoring favoring; private final CalculationContext calcContext; - public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Long2DoubleOpenHashMap favoredPositions, CalculationContext context) { + public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Favoring favoring, CalculationContext context) { super(startX, startY, startZ, goal, context); - this.favoredPositions = favoredPositions; + this.favoring = favoring; this.calcContext = context; } @@ -63,8 +63,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestSoFar[i] = startNode; } MutableMoveResult res = new MutableMoveResult(); - Long2DoubleOpenHashMap favored = favoredPositions; - favored.defaultReturnValue(1.0D); + Favoring favored = favoring; BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); @@ -97,6 +96,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel mostRecentConsidered = currentNode; numNodes++; if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { + favored.printStats(); logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext)); } @@ -137,10 +137,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset)); } long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z); - favored.get(hashCode); if (favoring) { // see issue #18 - actionCost *= favored.get(hashCode); + actionCost *= favored.calculate(res.x, res.y, res.z, hashCode); } PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode); double tentativeCost = currentNode.cost + actionCost; @@ -178,6 +177,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel } } } + favored.printStats(); if (cancelRequested) { return Optional.empty(); } diff --git a/src/main/java/baritone/utils/pathing/AvoidanceHelper.java b/src/main/java/baritone/utils/pathing/Avoidance.java similarity index 51% rename from src/main/java/baritone/utils/pathing/AvoidanceHelper.java rename to src/main/java/baritone/utils/pathing/Avoidance.java index 0201eef28..921708494 100644 --- a/src/main/java/baritone/utils/pathing/AvoidanceHelper.java +++ b/src/main/java/baritone/utils/pathing/Avoidance.java @@ -24,32 +24,61 @@ import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.entity.monster.EntityMob; import net.minecraft.util.math.BlockPos; -public enum AvoidanceHelper { - INSTANCE; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; - public void apply(Long2DoubleOpenHashMap map, IPlayerContext ctx) { +public class Avoidance { + public final int centerX; + public final int centerY; + public final int centerZ; + public final double coefficient; + public final int radius; + public final int radiusSq; + + public Avoidance(BlockPos center, double coefficient, int radius) { + this(center.getX(), center.getY(), center.getZ(), coefficient, radius); + } + + public Avoidance(int centerX, int centerY, int centerZ, double coefficient, int radius) { + this.centerX = centerX; + this.centerY = centerY; + this.centerZ = centerZ; + this.coefficient = coefficient; + this.radius = radius; + this.radiusSq = radius * radius; + } + + public double coefficient(int x, int y, int z) { + int xDiff = x - centerX; + int yDiff = y - centerY; + int zDiff = z - centerZ; + return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff <= radiusSq ? coefficient : 1.0D; + } + + public static List create(IPlayerContext ctx) { if (!Baritone.settings().avoidance.get()) { - return; + return Collections.emptyList(); } - long start = System.currentTimeMillis(); + List res = new ArrayList<>(); double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.get(); double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.get(); if (mobSpawnerCoeff != 1.0D) { - ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> sphere(mobspawner, Baritone.settings().mobSpawnerAvoidanceRadius.get(), map, mobSpawnerCoeff)); + ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.get()))); } if (mobCoeff != 1.0D) { - ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> sphere(new BlockPos(entity), Baritone.settings().mobAvoidanceRadius.get(), map, mobCoeff)); + ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.get()))); } - long end = System.currentTimeMillis(); - System.out.println("Took " + (end - start) + "ms to generate avoidance of " + map.size() + " blocks"); + return res; } - private void sphere(BlockPos center, int radius, Long2DoubleOpenHashMap map, double coeff) { + public void applySpherical(Long2DoubleOpenHashMap map) { for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { if (x * x + y * y + z * z <= radius * radius) { - map.put(BetterBlockPos.longHash(center.getX() + x, center.getY() + y, center.getZ() + z), coeff); + long hash = BetterBlockPos.longHash(centerX + x, centerY + y, centerZ + z); + map.put(hash, map.get(hash) * coefficient); } } } diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java new file mode 100644 index 000000000..e39d3165b --- /dev/null +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -0,0 +1,100 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.pathing; + +import baritone.Baritone; +import baritone.api.pathing.calc.IPath; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.IPlayerContext; +import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; + +import java.util.List; + +public class Favoring { + private final LongOpenHashSet backtrackFavored = new LongOpenHashSet(); + private final double backtrackCoefficient; + + private final List avoidances; + + private final Long2DoubleOpenHashMap favorings = new Long2DoubleOpenHashMap(); + + private long mapMethodNano = 0; + private long hybridMethodNano = 0; + + + public Favoring(IPlayerContext ctx, IPath previous) { + long start = System.currentTimeMillis(); + backtrackCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.get(); + if (backtrackCoefficient != 1D && previous != null) { + previous.positions().forEach(pos -> backtrackFavored.add(BetterBlockPos.longHash(pos))); + } + + avoidances = Avoidance.create(ctx); + long end = System.currentTimeMillis(); + System.out.println("Hybrid method init took " + (end - start) + "ms"); + + favorings.defaultReturnValue(1.0D); + backtrackFavored.forEach(l -> favorings.put((long) l, backtrackCoefficient)); + for (Avoidance avoid : avoidances) { + avoid.applySpherical(favorings); + } + long end2 = System.currentTimeMillis(); + System.out.println("Map method init took " + (end2 - end) + "ms"); + System.out.println("Size: " + favorings.size()); + } + + public void printStats() { + System.out.println("Map method nanos: " + mapMethodNano); + System.out.println("Hybrid method nano: " + hybridMethodNano); + } + + public boolean isEmpty() { + return backtrackFavored.isEmpty() && favorings.isEmpty() && avoidances.isEmpty(); + } + + public double calculate(int x, int y, int z, long hash) { + long start = System.nanoTime(); + double result = calculateMap(x, y, z, hash); + long mid = System.nanoTime(); + double result2 = calculateHybrid(x, y, z, hash); + long end = System.nanoTime(); + mapMethodNano += mid - start; + hybridMethodNano += end - mid; + if (result != result2) { + System.out.println("NO MATCH " + result + " " + result2); + } + return result; + } + + + public double calculateMap(int x, int y, int z, long hash) { + return favorings.get(hash); + } + + public double calculateHybrid(int x, int y, int z, long hash) { + double result = 1.0D; + if (backtrackFavored.contains(hash)) { + result *= backtrackCoefficient; + } + for (Avoidance avoid : avoidances) { + result *= avoid.coefficient(x, y, z); + } + return result; + } +} From 17207d44e66bd9fcd70a11889bf813a254ec1567 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 19:39:10 -0800 Subject: [PATCH 028/140] pick map over hybrid, due to performance --- .../baritone/behavior/PathingBehavior.java | 6 +- .../pathing/calc/AStarPathFinder.java | 7 +- .../baritone/utils/pathing/Avoidance.java | 12 ++-- .../java/baritone/utils/pathing/Favoring.java | 71 ++++--------------- .../utils/pathing/SegmentedCalculator.java | 4 +- 5 files changed, 27 insertions(+), 73 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 53bea7055..856dd6a4e 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -419,7 +419,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.get(); } CalculationContext context = new CalculationContext(baritone, true); // not safe to create on the other thread, it looks up a lot of stuff in minecraft - AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context, true); + AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context); if (!Objects.equals(pathfinder.getGoal(), goal)) { logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); } @@ -495,9 +495,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, }); } - public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context, boolean allowSimplifyUnloaded) { + public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) { Goal transformed = goal; - if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos && allowSimplifyUnloaded) { + if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); if (context.world().getChunk(pos) instanceof EmptyChunk) { transformed = new GoalXZ(pos.getX(), pos.getZ()); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 06f25d9c6..4b57abf1c 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -76,9 +76,8 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel int numNodes = 0; int numMovementsConsidered = 0; int numEmptyChunk = 0; - boolean favoring = favored != null && !favored.isEmpty(); + boolean favoring = !favored.isEmpty(); 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 && !cancelRequested) { long now = System.nanoTime() / 1000000L; @@ -96,7 +95,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel mostRecentConsidered = currentNode; numNodes++; if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { - favored.printStats(); logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext)); } @@ -139,7 +137,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z); if (favoring) { // see issue #18 - actionCost *= favored.calculate(res.x, res.y, res.z, hashCode); + actionCost *= favored.calculate(hashCode); } PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode); double tentativeCost = currentNode.cost + actionCost; @@ -177,7 +175,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel } } } - favored.printStats(); if (cancelRequested) { return Optional.empty(); } diff --git a/src/main/java/baritone/utils/pathing/Avoidance.java b/src/main/java/baritone/utils/pathing/Avoidance.java index 921708494..1f61dc57a 100644 --- a/src/main/java/baritone/utils/pathing/Avoidance.java +++ b/src/main/java/baritone/utils/pathing/Avoidance.java @@ -29,12 +29,12 @@ import java.util.Collections; import java.util.List; public class Avoidance { - public final int centerX; - public final int centerY; - public final int centerZ; - public final double coefficient; - public final int radius; - public final int radiusSq; + private final int centerX; + private final int centerY; + private final int centerZ; + private final double coefficient; + private final int radius; + private final int radiusSq; public Avoidance(BlockPos center, double coefficient, int radius) { this(center.getX(), center.getY(), center.getZ(), coefficient, radius); diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java index e39d3165b..de80f442d 100644 --- a/src/main/java/baritone/utils/pathing/Favoring.java +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -22,79 +22,36 @@ import baritone.api.pathing.calc.IPath; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.IPlayerContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; -import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import java.util.List; -public class Favoring { - private final LongOpenHashSet backtrackFavored = new LongOpenHashSet(); - private final double backtrackCoefficient; - - private final List avoidances; - - private final Long2DoubleOpenHashMap favorings = new Long2DoubleOpenHashMap(); - - private long mapMethodNano = 0; - private long hybridMethodNano = 0; - +public final class Favoring { + private List avoidances; + private final Long2DoubleOpenHashMap favorings; public Favoring(IPlayerContext ctx, IPath previous) { - long start = System.currentTimeMillis(); - backtrackCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.get(); - if (backtrackCoefficient != 1D && previous != null) { - previous.positions().forEach(pos -> backtrackFavored.add(BetterBlockPos.longHash(pos))); - } - + this(previous); avoidances = Avoidance.create(ctx); - long end = System.currentTimeMillis(); - System.out.println("Hybrid method init took " + (end - start) + "ms"); - - favorings.defaultReturnValue(1.0D); - backtrackFavored.forEach(l -> favorings.put((long) l, backtrackCoefficient)); for (Avoidance avoid : avoidances) { avoid.applySpherical(favorings); } - long end2 = System.currentTimeMillis(); - System.out.println("Map method init took " + (end2 - end) + "ms"); - System.out.println("Size: " + favorings.size()); + System.out.println("Favoring size: " + favorings.size()); } - public void printStats() { - System.out.println("Map method nanos: " + mapMethodNano); - System.out.println("Hybrid method nano: " + hybridMethodNano); + public Favoring(IPath previous) { // create one just from previous path, no mob avoidances + favorings = new Long2DoubleOpenHashMap(); + favorings.defaultReturnValue(1.0D); + double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); + if (coeff != 1D && previous != null) { + previous.positions().forEach(pos -> favorings.put(BetterBlockPos.longHash(pos), coeff)); + } } public boolean isEmpty() { - return backtrackFavored.isEmpty() && favorings.isEmpty() && avoidances.isEmpty(); + return favorings.isEmpty(); } - public double calculate(int x, int y, int z, long hash) { - long start = System.nanoTime(); - double result = calculateMap(x, y, z, hash); - long mid = System.nanoTime(); - double result2 = calculateHybrid(x, y, z, hash); - long end = System.nanoTime(); - mapMethodNano += mid - start; - hybridMethodNano += end - mid; - if (result != result2) { - System.out.println("NO MATCH " + result + " " + result2); - } - return result; - } - - - public double calculateMap(int x, int y, int z, long hash) { + public double calculate(long hash) { return favorings.get(hash); } - - public double calculateHybrid(int x, int y, int z, long hash) { - double result = 1.0D; - if (backtrackFavored.contains(hash)) { - result *= backtrackCoefficient; - } - for (Avoidance avoid : avoidances) { - result *= avoid.coefficient(x, y, z); - } - return result; - } } diff --git a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java index d3f6703e5..e1d6dd106 100644 --- a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java +++ b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java @@ -22,8 +22,8 @@ import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.Goal; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.PathCalculationResult; -import baritone.behavior.PathingBehavior; import baritone.cache.CachedWorld; +import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.path.SplicedPath; @@ -87,7 +87,7 @@ public class SegmentedCalculator { private PathCalculationResult segment(Optional previous) { BetterBlockPos segmentStart = previous.map(IPath::getDest).orElse(start); // <-- e p i c - AbstractNodeCostSearch search = PathingBehavior.createPathfinder(segmentStart, goal, previous.orElse(null), context, false); + AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous.orElse(null)), context); // this is on another thread, so cannot include mob avoidances. return search.calculate(Baritone.settings().primaryTimeoutMS.get(), Baritone.settings().failureTimeoutMS.get()); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer } From 3cb19848927be686239d09b5e320cd03f796b4dd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 19:40:23 -0800 Subject: [PATCH 029/140] only apply static cutoff to protrusion beyond min length --- src/main/java/baritone/utils/pathing/PathBase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index aaf368957..15d0e7bc4 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -39,14 +39,15 @@ public abstract class PathBase implements IPath { @Override public IPath staticCutoff(Goal destination) { - if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) { + int min = BaritoneAPI.getSettings().pathCutoffMinimumLength.get(); + if (length() < min) { return this; } if (destination == null || destination.isInGoal(getDest())) { return this; } double factor = BaritoneAPI.getSettings().pathCutoffFactor.get(); - int newLength = (int) ((length() - 1) * factor); + int newLength = (int) ((length() - 1 - min) * factor) + min; return new CutoffPath(this, newLength); } } From d2413e1677dd2546edf67cc269411aea0c2f9b9c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Dec 2018 19:56:35 -0800 Subject: [PATCH 030/140] lol --- src/api/java/baritone/api/pathing/calc/IPath.java | 5 +++-- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- src/main/java/baritone/utils/pathing/PathBase.java | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/pathing/calc/IPath.java b/src/api/java/baritone/api/pathing/calc/IPath.java index 8f0cb68ed..63c01101e 100644 --- a/src/api/java/baritone/api/pathing/calc/IPath.java +++ b/src/api/java/baritone/api/pathing/calc/IPath.java @@ -21,7 +21,6 @@ import baritone.api.Settings; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.movement.IMovement; import baritone.api.utils.BetterBlockPos; -import net.minecraft.world.World; import java.util.HashSet; import java.util.List; @@ -119,10 +118,12 @@ public interface IPath { /** * Cuts off this path at the loaded chunk border, and returns the resulting path. Default * implementation just returns this path, without the intended functionality. + *

+ * The argument is supposed to be a BlockStateInterface LOL LOL LOL LOL LOL * * @return The result of this cut-off operation */ - default IPath cutoffAtLoadedChunks(World world) { + default IPath cutoffAtLoadedChunks(Object bsi) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 856dd6a4e..0d88dbe19 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -433,7 +433,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, Optional path = calcResult.getPath(); if (Baritone.settings().cutoffAtLoadBoundary.get()) { path = path.map(p -> { - IPath result = p.cutoffAtLoadedChunks(context.world()); + IPath result = p.cutoffAtLoadedChunks(context.bsi()); if (result instanceof CutoffPath) { logDebug("Cutting off path at edge of loaded chunks"); diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 15d0e7bc4..129e07358 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -21,16 +21,16 @@ import baritone.api.BaritoneAPI; import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.Goal; import baritone.pathing.path.CutoffPath; +import baritone.utils.BlockStateInterface; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.EmptyChunk; public abstract class PathBase implements IPath { @Override - public IPath cutoffAtLoadedChunks(World world) { + public PathBase cutoffAtLoadedChunks(Object bsi0) { + BlockStateInterface bsi = (BlockStateInterface) bsi0; for (int i = 0; i < positions().size(); i++) { BlockPos pos = positions().get(i); - if (world.getChunk(pos) instanceof EmptyChunk) { + if (!bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ())) { return new CutoffPath(this, i); } } @@ -38,7 +38,7 @@ public abstract class PathBase implements IPath { } @Override - public IPath staticCutoff(Goal destination) { + public PathBase staticCutoff(Goal destination) { int min = BaritoneAPI.getSettings().pathCutoffMinimumLength.get(); if (length() < min) { return this; From d058cbf501b866f3f6370a72cea636a27cd7ba38 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 13:34:39 -0800 Subject: [PATCH 031/140] revert static cutoff, and fix goal comparisons in splice --- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- src/main/java/baritone/pathing/path/SplicedPath.java | 2 +- src/main/java/baritone/process/CustomGoalProcess.java | 2 +- src/main/java/baritone/utils/pathing/PathBase.java | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 0d88dbe19..066a47d41 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -420,7 +420,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } CalculationContext context = new CalculationContext(baritone, true); // not safe to create on the other thread, it looks up a lot of stuff in minecraft AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context); - if (!Objects.equals(pathfinder.getGoal(), goal)) { + if (!Objects.equals(pathfinder.getGoal(), goal)) { // will return the exact same object if simplification didn't happen logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); } inProgress = pathfinder; diff --git a/src/main/java/baritone/pathing/path/SplicedPath.java b/src/main/java/baritone/pathing/path/SplicedPath.java index f2187fe77..b3c497fd7 100644 --- a/src/main/java/baritone/pathing/path/SplicedPath.java +++ b/src/main/java/baritone/pathing/path/SplicedPath.java @@ -71,7 +71,7 @@ public class SplicedPath extends PathBase { if (second == null || first == null) { return Optional.empty(); } - if (!Objects.equals(first.getGoal(), second.getGoal())) { + if (!first.getGoal().toString().equals(second.getGoal().toString())) { return Optional.empty(); } if (!first.getDest().equals(second.getSrc())) { diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index 65f0ba7a8..a07e4aa44 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -74,7 +74,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { switch (this.state) { case GOAL_SET: - if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), this.goal)) { + if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal() + "", this.goal + "")) { this.state = State.NONE; } return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 129e07358..89f80207f 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -39,15 +39,14 @@ public abstract class PathBase implements IPath { @Override public PathBase staticCutoff(Goal destination) { - int min = BaritoneAPI.getSettings().pathCutoffMinimumLength.get(); - if (length() < min) { + if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) { return this; } if (destination == null || destination.isInGoal(getDest())) { return this; } double factor = BaritoneAPI.getSettings().pathCutoffFactor.get(); - int newLength = (int) ((length() - 1 - min) * factor) + min; + int newLength = (int) ((length() - 1) * factor); return new CutoffPath(this, newLength); } } From eedf993d7a8d679b03b71cb2206ec725473fa95d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 13:40:38 -0800 Subject: [PATCH 032/140] remove goal equality condition for path splicing --- src/main/java/baritone/pathing/path/SplicedPath.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/baritone/pathing/path/SplicedPath.java b/src/main/java/baritone/pathing/path/SplicedPath.java index b3c497fd7..686a15f09 100644 --- a/src/main/java/baritone/pathing/path/SplicedPath.java +++ b/src/main/java/baritone/pathing/path/SplicedPath.java @@ -71,9 +71,6 @@ public class SplicedPath extends PathBase { if (second == null || first == null) { return Optional.empty(); } - if (!first.getGoal().toString().equals(second.getGoal().toString())) { - return Optional.empty(); - } if (!first.getDest().equals(second.getSrc())) { return Optional.empty(); } From 58a5720b6b1fee6694ab809d007d89bd69b9e7b1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 13:55:54 -0800 Subject: [PATCH 033/140] reduce reliability in what chunks are loaded when --- src/main/java/baritone/utils/BaritoneAutoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index d86a36c4a..be869c3b2 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -39,7 +39,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { public static final boolean ENABLE_AUTO_TEST = "true".equals(System.getenv("BARITONE_AUTO_TEST")); private static final long TEST_SEED = -928872506371745L; private static final BlockPos STARTING_POSITION = new BlockPos(0, 65, 0); - private static final Goal GOAL = new GoalBlock(69, 121, 420); + private static final Goal GOAL = new GoalBlock(69, 69, 420); private static final int MAX_TICKS = 3500; /** From 8e2df3a030e3fd1ebc70fe5c5157c1a4aa058a0c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 14:08:44 -0800 Subject: [PATCH 034/140] reinstate proper static cutoff behavior --- src/main/java/baritone/utils/pathing/PathBase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 89f80207f..27c5db67c 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -39,14 +39,15 @@ public abstract class PathBase implements IPath { @Override public PathBase staticCutoff(Goal destination) { - if (length() < BaritoneAPI.getSettings().pathCutoffMinimumLength.get()) { + int min = BaritoneAPI.getSettings().pathCutoffMinimumLength.get(); + if (length() < min) { return this; } if (destination == null || destination.isInGoal(getDest())) { return this; } double factor = BaritoneAPI.getSettings().pathCutoffFactor.get(); - int newLength = (int) ((length() - 1) * factor); + int newLength = (int) ((length() - 1) * factor) + min; return new CutoffPath(this, newLength); } } From 4c96759ed51827468b9248bd72aeb04beb57c90c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 14:09:05 -0800 Subject: [PATCH 035/140] tighten auto test time limit --- src/main/java/baritone/utils/BaritoneAutoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index be869c3b2..2e4a5706a 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -40,7 +40,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { private static final long TEST_SEED = -928872506371745L; private static final BlockPos STARTING_POSITION = new BlockPos(0, 65, 0); private static final Goal GOAL = new GoalBlock(69, 69, 420); - private static final int MAX_TICKS = 3500; + private static final int MAX_TICKS = 3300; /** * Called right after the {@link GameSettings} object is created in the {@link Minecraft} instance. From 147df1ffb262518ed7a1c0a37d28300eb87ceb34 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 16:15:22 -0600 Subject: [PATCH 036/140] Probably fixes 265 --- src/api/java/baritone/api/utils/Rotation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java index 28afbf658..7f93547b5 100644 --- a/src/api/java/baritone/api/utils/Rotation.java +++ b/src/api/java/baritone/api/utils/Rotation.java @@ -142,7 +142,7 @@ public class Rotation { if (newYaw < -180F) { newYaw += 360F; } - if (newYaw >= 180F) { + if (newYaw > 180F) { newYaw -= 360F; } return newYaw; From e25bf9f077669e9a8ec3daad49f1b84b3f3c133d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 14:20:30 -0800 Subject: [PATCH 037/140] my fault --- src/main/java/baritone/utils/pathing/PathBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 27c5db67c..129e07358 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -47,7 +47,7 @@ public abstract class PathBase implements IPath { return this; } double factor = BaritoneAPI.getSettings().pathCutoffFactor.get(); - int newLength = (int) ((length() - 1) * factor) + min; + int newLength = (int) ((length() - 1 - min) * factor) + min; return new CutoffPath(this, newLength); } } From b0066a93ca4e27e9815d2fec63aa4638211be2b1 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 16:42:05 -0600 Subject: [PATCH 038/140] GoalXZ beacon render setting --- src/api/java/baritone/api/Settings.java | 6 +++++ .../java/baritone/utils/PathRenderer.java | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index fcaea2893..f186f51b9 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -353,6 +353,12 @@ public class Settings { */ public Setting renderGoalIgnoreDepth = new Setting<>(true); + /** + * Renders X/Z type Goals with the vanilla beacon beam effect. Combining this with + * {@link #renderGoalIgnoreDepth} will cause strange render clipping. + */ + public Setting renderGoalXZBeacon = new Setting<>(false); + /** * Ignore depth when rendering the selection boxes (to break, to place, to walk into) */ diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index e14c14da6..f740cdf60 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -33,6 +33,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; @@ -297,6 +298,31 @@ public final class PathRenderer implements Helper { } else if (goal instanceof GoalXZ) { GoalXZ goalPos = (GoalXZ) goal; + if (Baritone.settings().renderGoalXZBeacon.get()) { + mc.getTextureManager().bindTexture(TileEntityBeaconRenderer.TEXTURE_BEACON_BEAM); + + if (Baritone.settings().renderGoalIgnoreDepth.get()) { + GlStateManager.disableDepth(); + } + + TileEntityBeaconRenderer.renderBeamSegment( + goalPos.getX() - renderPosX, + -renderPosY, + goalPos.getZ() - renderPosZ, + partialTicks, + 1.0, + player.world.getTotalWorldTime(), + 0, + 256, + color.getColorComponents(null) + ); + + if (Baritone.settings().renderGoalIgnoreDepth.get()) { + GlStateManager.enableDepth(); + } + return; + } + minX = goalPos.getX() + 0.002 - renderPosX; maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; From 0236cb35d9a792816e5fd55ef2b80b2cf6134530 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 14:49:16 -0800 Subject: [PATCH 039/140] overhaul memory --- src/api/java/baritone/api/IBaritone.java | 7 - .../IContainerMemory.java} | 5 +- .../IRememberedInventory.java | 2 +- .../java/baritone/api/cache/IWorldData.java | 6 + src/main/java/baritone/Baritone.java | 5 - .../baritone/behavior/MemoryBehavior.java | 131 ++++++------------ .../java/baritone/cache/ContainerMemory.java | 106 ++++++++++++++ src/main/java/baritone/cache/WorldData.java | 8 ++ 8 files changed, 169 insertions(+), 101 deletions(-) rename src/api/java/baritone/api/{behavior/IMemoryBehavior.java => cache/IContainerMemory.java} (90%) rename src/api/java/baritone/api/{behavior/memory => cache}/IRememberedInventory.java (96%) create mode 100644 src/main/java/baritone/cache/ContainerMemory.java diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 5ca54a25b..bbff9f9bf 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -18,7 +18,6 @@ package baritone.api; import baritone.api.behavior.ILookBehavior; -import baritone.api.behavior.IMemoryBehavior; import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.event.listener.IEventBus; @@ -47,12 +46,6 @@ public interface IBaritone { */ ILookBehavior getLookBehavior(); - /** - * @return The {@link IMemoryBehavior} instance - * @see IMemoryBehavior - */ - IMemoryBehavior getMemoryBehavior(); - /** * @return The {@link IMineProcess} instance * @see IMineProcess diff --git a/src/api/java/baritone/api/behavior/IMemoryBehavior.java b/src/api/java/baritone/api/cache/IContainerMemory.java similarity index 90% rename from src/api/java/baritone/api/behavior/IMemoryBehavior.java rename to src/api/java/baritone/api/cache/IContainerMemory.java index 6b6df1ddd..5c19d43b9 100644 --- a/src/api/java/baritone/api/behavior/IMemoryBehavior.java +++ b/src/api/java/baritone/api/cache/IContainerMemory.java @@ -15,9 +15,8 @@ * along with Baritone. If not, see . */ -package baritone.api.behavior; +package baritone.api.cache; -import baritone.api.behavior.memory.IRememberedInventory; import net.minecraft.util.math.BlockPos; import java.util.Map; @@ -26,7 +25,7 @@ import java.util.Map; * @author Brady * @since 9/23/2018 */ -public interface IMemoryBehavior extends IBehavior { +public interface IContainerMemory { /** * Gets a remembered inventory by its block position. diff --git a/src/api/java/baritone/api/behavior/memory/IRememberedInventory.java b/src/api/java/baritone/api/cache/IRememberedInventory.java similarity index 96% rename from src/api/java/baritone/api/behavior/memory/IRememberedInventory.java rename to src/api/java/baritone/api/cache/IRememberedInventory.java index c57ded918..a7890fe3a 100644 --- a/src/api/java/baritone/api/behavior/memory/IRememberedInventory.java +++ b/src/api/java/baritone/api/cache/IRememberedInventory.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.api.behavior.memory; +package baritone.api.cache; import net.minecraft.item.ItemStack; diff --git a/src/api/java/baritone/api/cache/IWorldData.java b/src/api/java/baritone/api/cache/IWorldData.java index 1031ba929..3543dd397 100644 --- a/src/api/java/baritone/api/cache/IWorldData.java +++ b/src/api/java/baritone/api/cache/IWorldData.java @@ -36,4 +36,10 @@ public interface IWorldData { * @return The waypoint collection for this world */ IWaypointCollection getWaypoints(); + + /** + * @return The {@link IContainerMemory} instance + * @see IContainerMemory + */ + IContainerMemory getContainerMemory(); } diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 42403e844..3f7748423 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -174,11 +174,6 @@ public class Baritone implements IBaritone { return this.lookBehavior; } - @Override - public MemoryBehavior getMemoryBehavior() { - return this.memoryBehavior; - } - @Override public MineProcess getMineProcess() { return this.mineProcess; diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 845073676..d084eedce 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -18,17 +18,17 @@ package baritone.behavior; import baritone.Baritone; -import baritone.api.behavior.IMemoryBehavior; -import baritone.api.behavior.memory.IRememberedInventory; -import baritone.api.cache.IWorldData; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.type.EventState; +import baritone.cache.ContainerMemory; import baritone.cache.Waypoint; +import baritone.pathing.movement.CalculationContext; import baritone.utils.BlockStateInterface; +import net.minecraft.block.Block; import net.minecraft.block.BlockBed; -import net.minecraft.item.ItemStack; +import net.minecraft.init.Blocks; import net.minecraft.network.Packet; import net.minecraft.network.play.client.CPacketCloseWindow; import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; @@ -36,17 +36,19 @@ import net.minecraft.network.play.server.SPacketCloseWindow; import net.minecraft.network.play.server.SPacketOpenWindow; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityLockable; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import java.util.*; +import java.util.ArrayList; +import java.util.List; /** * @author Brady * @since 8/6/2018 */ -public final class MemoryBehavior extends Behavior implements IMemoryBehavior { +public final class MemoryBehavior extends Behavior { - private final Map worldDataContainers = new HashMap<>(); + private final List futureInventories = new ArrayList<>(); // this is per-bot public MemoryBehavior(Baritone baritone) { super(baritone); @@ -68,14 +70,27 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior { CPacketPlayerTryUseItemOnBlock packet = event.cast(); TileEntity tileEntity = ctx.world().getTileEntity(packet.getPos()); + if (tileEntity != null) { + System.out.println(tileEntity.getPos() + " " + packet.getPos()); + System.out.println(tileEntity); + } // Ensure the TileEntity is a container of some sort if (tileEntity instanceof TileEntityLockable) { TileEntityLockable lockable = (TileEntityLockable) tileEntity; int size = lockable.getSizeInventory(); + BlockPos position = tileEntity.getPos(); + BlockPos adj = neighboringConnectedBlock(position); + System.out.println(position + " " + adj); + if (adj != null) { + size *= 2; // double chest or double trapped chest + if (adj.getX() < position.getX() || adj.getZ() < position.getZ()) { + position = adj; // standardize on the lower coordinate, regardless of which side of the large chest we right clicked + } + } - this.getCurrentContainer().futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), tileEntity.getPos())); + this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), position)); } } @@ -92,22 +107,19 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior { if (event.getState() == EventState.PRE) { if (p instanceof SPacketOpenWindow) { SPacketOpenWindow packet = event.cast(); - - WorldDataContainer container = this.getCurrentContainer(); - // Remove any entries that were created over a second ago, this should make up for INSANE latency - container.futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000); + futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000); - container.futureInventories.stream() + System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId()); + + futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) .findFirst().ifPresent(matched -> { // Remove the future inventory - container.futureInventories.remove(matched); + futureInventories.remove(matched); // Setup the remembered inventory - RememberedInventory inventory = container.rememberedInventories.computeIfAbsent(matched.pos, pos -> new RememberedInventory()); - inventory.windowId = packet.getWindowId(); - inventory.size = packet.getSlotCount(); + getCurrentContainer().setup(matched.pos, packet.getWindowId(), packet.getSlotCount()); }); } @@ -129,43 +141,28 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior { baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet())); } - private Optional getInventoryFromWindow(int windowId) { - return this.getCurrentContainer().rememberedInventories.values().stream().filter(i -> i.windowId == windowId).findFirst(); - } private void updateInventory() { - getInventoryFromWindow(ctx.player().openContainer.windowId).ifPresent(inventory -> { - inventory.items.clear(); - inventory.items.addAll(ctx.player().openContainer.getInventory().subList(0, inventory.size)); - }); + getCurrentContainer().getInventoryFromWindow(ctx.player().openContainer.windowId).ifPresent(inventory -> inventory.updateFromOpenWindow(ctx)); } - private WorldDataContainer getCurrentContainer() { - return this.worldDataContainers.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), data -> new WorldDataContainer()); + private ContainerMemory getCurrentContainer() { + return (ContainerMemory) baritone.getWorldProvider().getCurrentWorld().getContainerMemory(); } - @Override - public final synchronized RememberedInventory getInventoryByPos(BlockPos pos) { - return this.getCurrentContainer().rememberedInventories.get(pos); - } - - @Override - public final synchronized Map getRememberedInventories() { - // make a copy since this map is modified from the packet thread - return new HashMap<>(this.getCurrentContainer().rememberedInventories); - } - - private static final class WorldDataContainer { - - /** - * Possible future inventories that we will be able to remember - */ - private final List futureInventories = new ArrayList<>(); - - /** - * The current remembered inventories - */ - private final Map rememberedInventories = new HashMap<>(); + private BlockPos neighboringConnectedBlock(BlockPos in) { + BlockStateInterface bsi = new CalculationContext(baritone).bsi(); + Block block = bsi.get0(in).getBlock(); + if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) { + return null; // other things that have contents, but can be placed adjacent without combining + } + for (int i = 0; i < 4; i++) { + BlockPos adj = in.offset(EnumFacing.byHorizontalIndex(i)); + if (bsi.get0(adj).getBlock() == block) { + return adj; + } + } + return null; } /** @@ -198,43 +195,7 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior { this.slots = slots; this.type = type; this.pos = pos; - } - } - - /** - * An inventory that we are aware of. - *

- * Associated with a {@link BlockPos} in {@link WorldDataContainer#rememberedInventories}. - */ - public static class RememberedInventory implements IRememberedInventory { - - /** - * The list of items in the inventory - */ - private final List items; - - /** - * The last known window ID of the inventory - */ - private int windowId; - - /** - * The size of the inventory - */ - private int size; - - private RememberedInventory() { - this.items = new ArrayList<>(); - } - - @Override - public final List getContents() { - return Collections.unmodifiableList(this.items); - } - - @Override - public final int getSize() { - return this.size; + System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos); } } } diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java new file mode 100644 index 000000000..30f2480b5 --- /dev/null +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -0,0 +1,106 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.cache; + +import baritone.api.cache.IContainerMemory; +import baritone.api.cache.IRememberedInventory; +import baritone.api.utils.IPlayerContext; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; + +import java.nio.file.Path; +import java.util.*; + +public class ContainerMemory implements IContainerMemory { + public ContainerMemory(Path saveTo) { + // eventually + } + + /** + * The current remembered inventories + */ + private final Map inventories = new HashMap<>(); + + public synchronized void setup(BlockPos pos, int windowId, int slotCount) { + RememberedInventory inventory = inventories.computeIfAbsent(pos, x -> new RememberedInventory()); + inventory.windowId = windowId; + inventory.size = slotCount; + } + + public synchronized Optional getInventoryFromWindow(int windowId) { + return inventories.values().stream().filter(i -> i.windowId == windowId).findFirst(); + } + + @Override + public final synchronized RememberedInventory getInventoryByPos(BlockPos pos) { + return inventories.get(pos); + } + + @Override + public final synchronized Map getRememberedInventories() { + // make a copy since this map is modified from the packet thread + return new HashMap<>(inventories); + } + + /** + * An inventory that we are aware of. + *

+ * Associated with a {@link BlockPos} in {@link WorldDataContainer#rememberedInventories}. + */ + public static class RememberedInventory implements IRememberedInventory { + + /** + * The list of items in the inventory + */ + private final List items; + + /** + * The last known window ID of the inventory + */ + private int windowId; + + /** + * The size of the inventory + */ + private int size; + + private RememberedInventory() { + this.items = new ArrayList<>(); + } + + @Override + public final List getContents() { + return Collections.unmodifiableList(this.items); + } + + @Override + public final int getSize() { + return this.size; + } + + public int getWindowId() { + return this.windowId; + } + + public void updateFromOpenWindow(IPlayerContext ctx) { + items.clear(); + items.addAll(ctx.player().openContainer.getInventory().subList(0, size)); + System.out.println("Saved " + items); + } + } +} diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index 897a0d87c..84fd6ff1a 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -19,6 +19,7 @@ package baritone.cache; import baritone.Baritone; import baritone.api.cache.ICachedWorld; +import baritone.api.cache.IContainerMemory; import baritone.api.cache.IWaypointCollection; import baritone.api.cache.IWorldData; @@ -33,6 +34,7 @@ public class WorldData implements IWorldData { public final CachedWorld cache; private final Waypoints waypoints; + private final ContainerMemory containerMemory; //public final MapData map; public final Path directory; public final int dimension; @@ -41,6 +43,7 @@ public class WorldData implements IWorldData { this.directory = directory; this.cache = new CachedWorld(directory.resolve("cache"), dimension); this.waypoints = new Waypoints(directory.resolve("waypoints")); + this.containerMemory = new ContainerMemory(directory.resolve("containers")); this.dimension = dimension; } @@ -60,4 +63,9 @@ public class WorldData implements IWorldData { public IWaypointCollection getWaypoints() { return this.waypoints; } + + @Override + public IContainerMemory getContainerMemory() { + return this.containerMemory; + } } From 70b74d39fc00ae3b8b266623c318d6d24792f4f8 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 18:21:24 -0600 Subject: [PATCH 040/140] Fix broken javadoc --- src/main/java/baritone/cache/ContainerMemory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index 30f2480b5..52d1bf4fd 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -60,7 +60,7 @@ public class ContainerMemory implements IContainerMemory { /** * An inventory that we are aware of. *

- * Associated with a {@link BlockPos} in {@link WorldDataContainer#rememberedInventories}. + * Associated with a {@link BlockPos} in {@link ContainerMemory#inventories}. */ public static class RememberedInventory implements IRememberedInventory { From b22e93d6d07a6567e0f6a181492e69b67d703fb5 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 18:47:40 -0600 Subject: [PATCH 041/140] Fix javadoc errors --- .../pathing/calc/AbstractNodeCostSearch.java | 7 +++++++ .../java/baritone/pathing/movement/Movement.java | 7 ++++--- .../pathing/movement/MovementHelper.java | 16 ++++++++++++++-- .../java/baritone/pathing/path/PathExecutor.java | 2 ++ src/main/java/baritone/utils/Helper.java | 4 ++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 2a1681b75..490ab7a6d 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.pathing.calc.IPath; import baritone.api.pathing.calc.IPathFinder; import baritone.api.pathing.goals.Goal; +import baritone.api.utils.BetterBlockPos; import baritone.api.utils.PathCalculationResult; import baritone.pathing.movement.CalculationContext; import baritone.utils.Helper; @@ -135,9 +136,15 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * for the node mapped to the specified pos. If no node is found, * a new node is created. * + * @param x The x position of the node + * @param y The y position of the node + * @param z The z position of the node + * @param hashCode The hash code of the node, provided by {@link BetterBlockPos#longHash(int, int, int)} + * * @return The associated node * @see Issue #107 */ + protected PathNode getNodeAtPosition(int x, int y, int z, long hashCode) { PathNode node = map.get(hashCode); if (node == null) { diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 4105b5e70..7ba9f6eac 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -205,10 +205,11 @@ public abstract class Movement implements IMovement, MovementHelper { } /** - * Calculate latest movement state. - * Gets called once a tick. + * Calculate latest movement state. Gets called once a tick. * - * @return + * @param state The current state + * + * @return The new state */ public MovementState updateState(MovementState state) { if (!prepared(state)) { diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 9d31a3791..d56f19313 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -126,7 +126,11 @@ public interface MovementHelper extends ActionCosts, Helper { * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), * not including water, and not including ladders or vines or cobwebs (they slow us down) * - * @return + * @param context Calculation context to provide block state lookup + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position + * @return Whether or not the block at the specified position */ static boolean fullyPassable(CalculationContext context, int x, int y, int z) { return fullyPassable(context.get(x, y, z)); @@ -243,7 +247,13 @@ public interface MovementHelper extends ActionCosts, Helper { * through? Includes water because we know that we automatically jump on * water * - * @return + * @param bsi Block state provider + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position + * @param state The state of the block at the specified location + * + * @return Whether or not the specified block can be walked on */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { Block block = state.getBlock(); @@ -367,6 +377,7 @@ public interface MovementHelper extends ActionCosts, Helper { /** * AutoTool for a specific block * + * @param ctx The player context * @param b the blockstate to mine */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) { @@ -376,6 +387,7 @@ public interface MovementHelper extends ActionCosts, Helper { /** * AutoTool for a specific block with precomputed ToolSet data * + * @param ctx The player context * @param b the blockstate to mine * @param ts previously calculated ToolSet */ diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 15948d456..fa4c0e5f3 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -347,6 +347,8 @@ public class PathExecutor implements IPathExecutor, Helper { /** * Regardless of current path position, snap to the current player feet if possible + * + * @return Whether or not it was possible to snap to the current player feet */ public boolean snipsnapifpossible() { if (!ctx.player().onGround) { diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 9fc5aee32..9ee6ed59f 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -47,7 +47,7 @@ public interface Helper { /** * Send a message to chat only if chatDebug is on * - * @param message + * @param message The message to display in chat */ default void logDebug(String message) { if (!Baritone.settings().chatDebug.get()) { @@ -61,7 +61,7 @@ public interface Helper { /** * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) * - * @param message + * @param message The message to display in chat */ default void logDirect(String message) { ITextComponent component = MESSAGE_PREFIX.createCopy(); From 7ba987e7f71e88b6f3c8e93ae4d45b2523982d61 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 17:20:56 -0800 Subject: [PATCH 042/140] save containers and echests --- src/main/java/baritone/Baritone.java | 4 + .../baritone/behavior/MemoryBehavior.java | 86 ++++++++++++++++-- .../java/baritone/cache/ContainerMemory.java | 88 +++++++++++++++++-- src/main/java/baritone/cache/WorldData.java | 10 +++ .../java/baritone/cache/WorldProvider.java | 4 +- .../utils/ExampleBaritoneControl.java | 37 ++++++++ 6 files changed, 212 insertions(+), 17 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 3f7748423..1353dcc68 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -164,6 +164,10 @@ public class Baritone implements IBaritone { return this.playerContext; } + public MemoryBehavior getMemoryBehavior() { + return this.memoryBehavior; + } + @Override public FollowProcess getFollowProcess() { return this.followProcess; diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index d084eedce..06627d7e1 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -29,6 +29,7 @@ import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.BlockBed; import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.network.play.client.CPacketCloseWindow; import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; @@ -38,9 +39,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentTranslation; -import java.util.ArrayList; -import java.util.List; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; /** * @author Brady @@ -50,6 +54,8 @@ public final class MemoryBehavior extends Behavior { private final List futureInventories = new ArrayList<>(); // this is per-bot + private Integer enderChestWindowId; // nae nae + public MemoryBehavior(Baritone baritone) { super(baritone); } @@ -70,10 +76,7 @@ public final class MemoryBehavior extends Behavior { CPacketPlayerTryUseItemOnBlock packet = event.cast(); TileEntity tileEntity = ctx.world().getTileEntity(packet.getPos()); - if (tileEntity != null) { - System.out.println(tileEntity.getPos() + " " + packet.getPos()); - System.out.println(tileEntity); - } + // if tileEntity is an ender chest, we don't need to do anything. ender chests are treated the same regardless of what coordinate right clicked // Ensure the TileEntity is a container of some sort if (tileEntity instanceof TileEntityLockable) { @@ -96,6 +99,7 @@ public final class MemoryBehavior extends Behavior { if (p instanceof CPacketCloseWindow) { updateInventory(); + getCurrent().save(); } } } @@ -111,7 +115,14 @@ public final class MemoryBehavior extends Behavior { futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000); System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId()); - + System.out.println(packet.getWindowTitle()); + if (packet.getWindowTitle() instanceof TextComponentTranslation) { + // title is not customized (i.e. this isn't just a renamed shulker) + if (((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) { + enderChestWindowId = packet.getWindowId(); + return; + } + } futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) .findFirst().ifPresent(matched -> { @@ -125,6 +136,7 @@ public final class MemoryBehavior extends Behavior { if (p instanceof SPacketCloseWindow) { updateInventory(); + getCurrent().save(); } } } @@ -143,10 +155,24 @@ public final class MemoryBehavior extends Behavior { private void updateInventory() { - getCurrentContainer().getInventoryFromWindow(ctx.player().openContainer.windowId).ifPresent(inventory -> inventory.updateFromOpenWindow(ctx)); + int windowId = ctx.player().openContainer.windowId; + if (enderChestWindowId != null) { + if (windowId == enderChestWindowId) { + getCurrent().contents = ctx.player().openContainer.getInventory().subList(0, 27); + } else { + getCurrent().save(); + enderChestWindowId = null; + } + } + if (getCurrentContainer() != null) { + getCurrentContainer().getInventoryFromWindow(windowId).ifPresent(inventory -> inventory.updateFromOpenWindow(ctx)); + } } private ContainerMemory getCurrentContainer() { + if (baritone.getWorldProvider().getCurrentWorld() == null) { + return null; + } return (ContainerMemory) baritone.getWorldProvider().getCurrentWorld().getContainerMemory(); } @@ -198,4 +224,48 @@ public final class MemoryBehavior extends Behavior { System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos); } } + + public Optional> echest() { + return Optional.ofNullable(getCurrent().contents).map(Collections::unmodifiableList); + } + + public EnderChestMemory getCurrent() { + Path path = baritone.getWorldProvider().getCurrentWorld().directory; + return EnderChestMemory.getByServerAndPlayer(path.getParent(), ctx.player().getUniqueID()); + } + + public static class EnderChestMemory { + private static final Map memory = new HashMap<>(); + private final Path enderChest; + private List contents; + + private EnderChestMemory(Path enderChest) { + this.enderChest = enderChest; + System.out.println("Echest storing in " + enderChest); + try { + this.contents = ContainerMemory.readItemStacks(Files.readAllBytes(enderChest)); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("CANNOT read echest =( =("); + this.contents = null; + } + } + + public synchronized void save() { + System.out.println("Saving"); + if (contents != null) { + try { + enderChest.getParent().toFile().mkdir(); + Files.write(enderChest, ContainerMemory.writeItemStacks(contents)); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("CANNOT save echest =( =("); + } + } + } + + private static synchronized EnderChestMemory getByServerAndPlayer(Path serverStorage, UUID player) { + return memory.computeIfAbsent(serverStorage.resolve("echests").resolve(player.toString()), EnderChestMemory::new); + } + } } diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index 52d1bf4fd..8a638e4b9 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -20,22 +20,69 @@ package baritone.cache; import baritone.api.cache.IContainerMemory; import baritone.api.cache.IRememberedInventory; import baritone.api.utils.IPlayerContext; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.*; public class ContainerMemory implements IContainerMemory { - public ContainerMemory(Path saveTo) { - // eventually - } + private final Path saveTo; /** * The current remembered inventories */ private final Map inventories = new HashMap<>(); + + public ContainerMemory(Path saveTo) { + this.saveTo = saveTo; + try { + read(Files.readAllBytes(saveTo)); + } catch (Exception ex) { + ex.printStackTrace(); + inventories.clear(); + } + } + + private void read(byte[] bytes) throws IOException { + System.out.println("READ BYTES " + bytes.length); + PacketBuffer in = new PacketBuffer(Unpooled.wrappedBuffer(bytes)); + int chests = in.readInt(); + for (int i = 0; i < chests; i++) { + int x = in.readInt(); + int y = in.readInt(); + int z = in.readInt(); + System.out.println("Read x y z " + x + " " + y + " " + z); + RememberedInventory rem = new RememberedInventory(); + rem.items.addAll(readItemStacks(in)); + rem.size = rem.items.size(); + if (rem.items.isEmpty()) { + continue; // this only happens if the list has no elements, not if the list has elements that are all empty item stacks + } + inventories.put(new BlockPos(x, y, z), rem); + } + } + + public synchronized void save() throws IOException { + ByteBuf buf = Unpooled.buffer(); + PacketBuffer out = new PacketBuffer(buf); + out.writeInt(inventories.size()); + for (Map.Entry entry : inventories.entrySet()) { + out.writeInt(entry.getKey().getX()); + out.writeInt(entry.getKey().getY()); + out.writeInt(entry.getKey().getZ()); + writeItemStacks(entry.getValue().getContents()); + } + System.out.println("CONTAINER BYTES " + buf.array().length); + Files.write(saveTo, buf.array()); + } + public synchronized void setup(BlockPos pos, int windowId, int slotCount) { RememberedInventory inventory = inventories.computeIfAbsent(pos, x -> new RememberedInventory()); inventory.windowId = windowId; @@ -57,6 +104,36 @@ public class ContainerMemory implements IContainerMemory { return new HashMap<>(inventories); } + public static List readItemStacks(byte[] bytes) throws IOException { + PacketBuffer in = new PacketBuffer(Unpooled.wrappedBuffer(bytes)); + return readItemStacks(in); + } + + public static List readItemStacks(PacketBuffer in) throws IOException { + int count = in.readInt(); + System.out.println("Read count " + count); + List result = new ArrayList<>(); + for (int i = 0; i < count; i++) { + result.add(in.readItemStack()); + } + return result; + } + + public static byte[] writeItemStacks(List write) { + ByteBuf buf = Unpooled.buffer(); + PacketBuffer out = new PacketBuffer(buf); + writeItemStacks(write, out); + return buf.array(); + } + + public static void writeItemStacks(List write, PacketBuffer out) { + System.out.println("WRITING ITEM STACKS " + write.size() + " " + write); + out.writeInt(write.size()); + for (ItemStack stack : write) { + out.writeItemStack(stack); + } + } + /** * An inventory that we are aware of. *

@@ -93,14 +170,9 @@ public class ContainerMemory implements IContainerMemory { return this.size; } - public int getWindowId() { - return this.windowId; - } - public void updateFromOpenWindow(IPlayerContext ctx) { items.clear(); items.addAll(ctx.player().openContainer.getInventory().subList(0, size)); - System.out.println("Saved " + items); } } } diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index 84fd6ff1a..151edd4c4 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -23,6 +23,7 @@ import baritone.api.cache.IContainerMemory; import baritone.api.cache.IWaypointCollection; import baritone.api.cache.IWorldData; +import java.io.IOException; import java.nio.file.Path; /** @@ -52,6 +53,15 @@ public class WorldData implements IWorldData { System.out.println("Started saving the world in a new thread"); cache.save(); }); + Baritone.getExecutor().execute(() -> { + System.out.println("Started saving saved containers in a new thread"); + try { + containerMemory.save(); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("Failed to save saved containers"); + } + }); } @Override diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index fe33a4d13..83cf460d5 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -95,7 +95,9 @@ public class WorldProvider implements IWorldProvider, Helper { } System.out.println("Baritone world data dir: " + dir); - this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension)); + synchronized (worldCache) { + this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension)); + } } public final void closeWorld() { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 958af7765..508a5e1bc 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -19,6 +19,7 @@ package baritone.utils; import baritone.Baritone; import baritone.api.Settings; +import baritone.api.cache.IRememberedInventory; import baritone.api.cache.IWaypoint; import baritone.api.event.events.ChatEvent; import baritone.api.pathing.goals.*; @@ -37,6 +38,7 @@ import net.minecraft.block.Block; import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; @@ -282,6 +284,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Baritone settings reset"); return true; } + if (msg.equals("echest")) { + Optional> contents = baritone.getMemoryBehavior().echest(); + if (contents.isPresent()) { + logDirect("echest contents:"); + log(contents.get()); + } else { + logDirect("echest contents unknown"); + } + return true; + } + if (msg.equals("chests")) { + System.out.println(baritone.getWorldProvider()); + System.out.println(baritone.getWorldProvider().getCurrentWorld()); + + System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory()); + + System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories()); + + System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()); + + System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()); + for (Map.Entry entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) { + logDirect(entry.getKey() + ""); + log(entry.getValue().getContents()); + } + return true; + } if (msg.startsWith("followplayers")) { baritone.getFollowProcess().follow(EntityPlayer.class::isInstance); // O P P A logDirect("Following any players"); @@ -491,4 +520,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } return false; } + + private void log(List stacks) { + for (ItemStack stack : stacks) { + if (!stack.isEmpty()) { + logDirect(stack.getCount() + "x " + stack.getDisplayName() + "@" + stack.getItemDamage()); + } + } + } } From 5c83ee264820cacd9ae133918faf3afd8541095b Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 19:37:54 -0600 Subject: [PATCH 043/140] Fix API javadoc errors and make API only javadoc export --- build.gradle | 5 +++ .../baritone/api/cache/ICachedRegion.java | 4 +-- .../java/baritone/api/cache/IWorldData.java | 4 +-- .../event/listener/IGameEventListener.java | 31 ++++++++++++------- .../java/baritone/api/pathing/calc/IPath.java | 4 +++ .../api/pathing/calc/IPathFinder.java | 3 ++ .../java/baritone/api/pathing/goals/Goal.java | 8 +++++ .../baritone/api/utils/RayTraceUtils.java | 4 ++- .../baritone/api/utils/RotationUtils.java | 17 +++++----- src/api/java/baritone/api/utils/VecUtils.java | 3 +- 10 files changed, 59 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 80a2de1c7..99a17a3b5 100755 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,11 @@ mixin { add sourceSets.launch, 'mixins.baritone.refmap.json' } +javadoc { + source = sourceSets.api.allJava + classpath = sourceSets.api.compileClasspath +} + jar { from sourceSets.launch.output, sourceSets.api.output preserveFileTimestamps = false diff --git a/src/api/java/baritone/api/cache/ICachedRegion.java b/src/api/java/baritone/api/cache/ICachedRegion.java index 6b9048a57..cf63f54ba 100644 --- a/src/api/java/baritone/api/cache/ICachedRegion.java +++ b/src/api/java/baritone/api/cache/ICachedRegion.java @@ -37,12 +37,12 @@ public interface ICachedRegion extends IBlockTypeAccess { boolean isCached(int blockX, int blockZ); /** - * The X coordinate of this region + * @return The X coordinate of this region */ int getX(); /** - * The Z coordinate of this region + * @return The Z coordinate of this region */ int getZ(); } diff --git a/src/api/java/baritone/api/cache/IWorldData.java b/src/api/java/baritone/api/cache/IWorldData.java index 3543dd397..1eaade4c0 100644 --- a/src/api/java/baritone/api/cache/IWorldData.java +++ b/src/api/java/baritone/api/cache/IWorldData.java @@ -27,12 +27,12 @@ public interface IWorldData { * Returns the cached world for this world. A cached world is a simplified format * of a regular world, intended for use on multiplayer servers where chunks are not * traditionally stored to disk, allowing for long distance pathing with minimal disk usage. + * + * @return The cached world for this world */ ICachedWorld getCachedWorld(); /** - * Returns the waypoint collection for this world. - * * @return The waypoint collection for this world */ IWaypointCollection getWaypoints(); diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index c3b4e6880..5cca43a55 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -41,6 +41,8 @@ public interface IGameEventListener { * Run once per game tick before screen input is handled. * * @see Minecraft#runTick() + * + * @param event The event */ void onTick(TickEvent event); @@ -48,13 +50,13 @@ public interface IGameEventListener { * Run once per game tick from before and after the player rotation is sent to the server. * * @see EntityPlayerSP#onUpdate() + * + * @param event The event */ void onPlayerUpdate(PlayerUpdateEvent event); /** * Run once per game tick from before keybinds are processed. - * - * @see Minecraft#processKeyBinds() */ void onProcessKeyBinds(); @@ -62,6 +64,8 @@ public interface IGameEventListener { * Runs whenever the client player sends a message to the server. * * @see EntityPlayerSP#sendChatMessage(String) + * + * @param event The event */ void onSendChatMessage(ChatEvent event); @@ -69,6 +73,8 @@ public interface IGameEventListener { * Runs before and after whenever a chunk is either loaded, unloaded, or populated. * * @see WorldClient#doPreChunk(int, int, boolean) + * + * @param event The event */ void onChunkEvent(ChunkEvent event); @@ -77,7 +83,7 @@ public interface IGameEventListener { *

* Note: {@link GameSettings#anaglyph} has been removed in Minecraft 1.13 * - * @see EntityRenderer#renderWorldPass(int, float, long) + * @param event The event */ void onRenderPass(RenderEvent event); @@ -85,24 +91,28 @@ public interface IGameEventListener { * Runs before and after whenever a new world is loaded * * @see Minecraft#loadWorld(WorldClient, String) + * + * @param event The event */ void onWorldEvent(WorldEvent event); /** * Runs before a outbound packet is sent * - * @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[]) * @see Packet * @see GenericFutureListener + * + * @param event The event */ void onSendPacket(PacketEvent event); /** * Runs before an inbound packet is processed * - * @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[]) * @see Packet * @see GenericFutureListener + * + * @param event The event */ void onReceivePacket(PacketEvent event); @@ -111,30 +121,29 @@ public interface IGameEventListener { * and before and after the player jumps. * * @see Entity#moveRelative(float, float, float, float) - * @see EntityLivingBase#jump() + * + * @param event The event */ void onPlayerRotationMove(RotationMoveEvent event); /** * Called when the local player interacts with a block, whether it is breaking or opening/placing. * - * @see Minecraft#clickMouse() - * @see Minecraft#rightClickMouse() + * @param event The event */ void onBlockInteract(BlockInteractEvent event); /** * Called when the local player dies, as indicated by the creation of the {@link GuiGameOver} screen. * - * @see GuiGameOver(ITextComponent) - * @see ITextComponent + * @see GuiGameOver */ void onPlayerDeath(); /** * When the pathfinder's state changes * - * @param event + * @param event The event */ void onPathEvent(PathEvent event); } diff --git a/src/api/java/baritone/api/pathing/calc/IPath.java b/src/api/java/baritone/api/pathing/calc/IPath.java index 63c01101e..ec51861dc 100644 --- a/src/api/java/baritone/api/pathing/calc/IPath.java +++ b/src/api/java/baritone/api/pathing/calc/IPath.java @@ -51,6 +51,8 @@ public interface IPath { /** * This path is actually going to be executed in the world. Do whatever additional processing is required. * (as opposed to Path objects that are just constructed every frame for rendering) + * + * @return The result of path post processing */ default IPath postProcess() { throw new UnsupportedOperationException(); @@ -121,6 +123,7 @@ public interface IPath { *

* The argument is supposed to be a BlockStateInterface LOL LOL LOL LOL LOL * + * @param bsi The block state lookup, highly cursed * @return The result of this cut-off operation */ default IPath cutoffAtLoadedChunks(Object bsi) { @@ -131,6 +134,7 @@ public interface IPath { * Cuts off this path using the min length and cutoff factor settings, and returns the resulting path. * Default implementation just returns this path, without the intended functionality. * + * @param destination The end goal of this path * @return The result of this cut-off operation * @see Settings#pathCutoffMinimumLength * @see Settings#pathCutoffFactor diff --git a/src/api/java/baritone/api/pathing/calc/IPathFinder.java b/src/api/java/baritone/api/pathing/calc/IPathFinder.java index fa83295f7..7f73693fa 100644 --- a/src/api/java/baritone/api/pathing/calc/IPathFinder.java +++ b/src/api/java/baritone/api/pathing/calc/IPathFinder.java @@ -34,6 +34,9 @@ public interface IPathFinder { /** * Calculate the path in full. Will take several seconds. * + * @param primaryTimeout If a path is found, the path finder will stop after this amount of time + * @param failureTimeout If a path isn't found, the path finder will continue for this amount of time + * * @return The final path */ PathCalculationResult calculate(long primaryTimeout, long failureTimeout); diff --git a/src/api/java/baritone/api/pathing/goals/Goal.java b/src/api/java/baritone/api/pathing/goals/Goal.java index 38cfb9d78..1ecf2dfb9 100644 --- a/src/api/java/baritone/api/pathing/goals/Goal.java +++ b/src/api/java/baritone/api/pathing/goals/Goal.java @@ -30,6 +30,10 @@ public interface Goal { * Returns whether or not the specified position * meets the requirement for this goal based. * + * @param x The goal X position + * @param y The goal Y position + * @param z The goal Z position + * * @return Whether or not it satisfies this goal */ boolean isInGoal(int x, int y, int z); @@ -37,6 +41,10 @@ public interface Goal { /** * Estimate the number of ticks it will take to get to the goal * + * @param x The goal X position + * @param y The goal Y position + * @param z The goal Z position + * * @return The estimate number of ticks to satisfy the goal */ double heuristic(int x, int y, int z); diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java index 61086f3db..0fd1e4e01 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/api/java/baritone/api/utils/RayTraceUtils.java @@ -34,7 +34,9 @@ public final class RayTraceUtils { * any entity collisions can be ignored, because this method will not recognize if an * entity is in the way or not. The local player's block reach distance will be used. * - * @param rotation The rotation to raytrace towards + * @param entity The entity representing the raytrace source + * @param rotation The rotation to raytrace towards + * @param blockReachDistance The block reach distance of the entity * @return The calculated raytrace result */ public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) { diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 20cb0dde2..0649ff107 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -134,8 +134,9 @@ public final class RotationUtils { * side that is reachable. The return type will be {@link Optional#empty()} if the entity is * unable to reach any of the sides of the block. * - * @param entity The viewing entity - * @param pos The target block position + * @param entity The viewing entity + * @param pos The target block position + * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) { @@ -178,9 +179,10 @@ public final class RotationUtils { * the given offsetted position. The return type will be {@link Optional#empty()} if * the entity is unable to reach the block with the offset applied. * - * @param entity The viewing entity - * @param pos The target block position - * @param offsetPos The position of the block with the offset applied. + * @param entity The viewing entity + * @param pos The target block position + * @param offsetPos The position of the block with the offset applied. + * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) { @@ -202,8 +204,9 @@ public final class RotationUtils { * Determines if the specified entity is able to reach the specified block where it is * looking at the direct center of it's hitbox. * - * @param entity The viewing entity - * @param pos The target block position + * @param entity The viewing entity + * @param pos The target block position + * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance) { diff --git a/src/api/java/baritone/api/utils/VecUtils.java b/src/api/java/baritone/api/utils/VecUtils.java index 1df011632..4c35c05e8 100644 --- a/src/api/java/baritone/api/utils/VecUtils.java +++ b/src/api/java/baritone/api/utils/VecUtils.java @@ -36,7 +36,8 @@ public final class VecUtils { /** * Calculates the center of the block at the specified position's bounding box * - * @param pos The block position + * @param world The world that the block is in, used to provide the bounding box + * @param pos The block position * @return The center of the block's bounding box * @see #getBlockPosCenter(BlockPos) */ From 86d1512e5b9f282c97a20c21123622267f3ae825 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 19:58:37 -0600 Subject: [PATCH 044/140] Rename Waypoints to WaypointCollection --- .../cache/{Waypoints.java => WaypointCollection.java} | 4 ++-- src/main/java/baritone/cache/WorldData.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/baritone/cache/{Waypoints.java => WaypointCollection.java} (97%) diff --git a/src/main/java/baritone/cache/Waypoints.java b/src/main/java/baritone/cache/WaypointCollection.java similarity index 97% rename from src/main/java/baritone/cache/Waypoints.java rename to src/main/java/baritone/cache/WaypointCollection.java index 2122ddaf1..ef3196025 100644 --- a/src/main/java/baritone/cache/Waypoints.java +++ b/src/main/java/baritone/cache/WaypointCollection.java @@ -32,7 +32,7 @@ import java.util.stream.Collectors; * * @author leijurv */ -public class Waypoints implements IWaypointCollection { +public class WaypointCollection implements IWaypointCollection { /** * Magic value to detect invalid waypoint files @@ -42,7 +42,7 @@ public class Waypoints implements IWaypointCollection { private final Path directory; private final Map> waypoints; - Waypoints(Path directory) { + WaypointCollection(Path directory) { this.directory = directory; if (!Files.exists(directory)) { try { diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index 151edd4c4..30fe8bd0d 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -34,7 +34,7 @@ import java.nio.file.Path; public class WorldData implements IWorldData { public final CachedWorld cache; - private final Waypoints waypoints; + private final WaypointCollection waypoints; private final ContainerMemory containerMemory; //public final MapData map; public final Path directory; @@ -43,7 +43,7 @@ public class WorldData implements IWorldData { WorldData(Path directory, int dimension) { this.directory = directory; this.cache = new CachedWorld(directory.resolve("cache"), dimension); - this.waypoints = new Waypoints(directory.resolve("waypoints")); + this.waypoints = new WaypointCollection(directory.resolve("waypoints")); this.containerMemory = new ContainerMemory(directory.resolve("containers")); this.dimension = dimension; } From bfa086106531f0cfd735b42e60dc1b9478067c13 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 3 Dec 2018 20:45:19 -0600 Subject: [PATCH 045/140] Owned? --- src/api/java/baritone/api/event/events/ChunkEvent.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/event/events/ChunkEvent.java b/src/api/java/baritone/api/event/events/ChunkEvent.java index a74bed17b..f27475bce 100644 --- a/src/api/java/baritone/api/event/events/ChunkEvent.java +++ b/src/api/java/baritone/api/event/events/ChunkEvent.java @@ -31,7 +31,9 @@ public final class ChunkEvent { private final EventState state; /** - * The type of chunk event that occurred; + * The type of chunk event that occurred + * + * @see Type */ private final Type type; From f4161ed61c0073a74d3240c2551f942bf3ebd9ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 21:39:24 -0800 Subject: [PATCH 046/140] ......fixed....... --- .../java/baritone/cache/ContainerMemory.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index 8a638e4b9..e0662a2e4 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -70,17 +70,17 @@ public class ContainerMemory implements IContainerMemory { } public synchronized void save() throws IOException { - ByteBuf buf = Unpooled.buffer(); + ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE); PacketBuffer out = new PacketBuffer(buf); out.writeInt(inventories.size()); for (Map.Entry entry : inventories.entrySet()) { - out.writeInt(entry.getKey().getX()); - out.writeInt(entry.getKey().getY()); - out.writeInt(entry.getKey().getZ()); - writeItemStacks(entry.getValue().getContents()); + out = new PacketBuffer(out.writeInt(entry.getKey().getX())); + out = new PacketBuffer(out.writeInt(entry.getKey().getY())); + out = new PacketBuffer(out.writeInt(entry.getKey().getZ())); + out = writeItemStacks(entry.getValue().getContents(), out); } - System.out.println("CONTAINER BYTES " + buf.array().length); - Files.write(saveTo, buf.array()); + System.out.println("CONTAINER BYTES " + out.array().length); + Files.write(saveTo, out.array()); } public synchronized void setup(BlockPos pos, int windowId, int slotCount) { @@ -120,18 +120,20 @@ public class ContainerMemory implements IContainerMemory { } public static byte[] writeItemStacks(List write) { - ByteBuf buf = Unpooled.buffer(); + ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE); PacketBuffer out = new PacketBuffer(buf); - writeItemStacks(write, out); - return buf.array(); + out = writeItemStacks(write, out); + return out.array(); } - public static void writeItemStacks(List write, PacketBuffer out) { + public static PacketBuffer writeItemStacks(List write, PacketBuffer out) { System.out.println("WRITING ITEM STACKS " + write.size() + " " + write); - out.writeInt(write.size()); + out = new PacketBuffer(out.writeInt(write.size())); for (ItemStack stack : write) { - out.writeItemStack(stack); + System.out.println(out.writableBytes()); + out = out.writeItemStack(stack); } + return out; } /** From 16aee33bdff618d8d019fd5b4d6c94d17d0ea051 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Dec 2018 21:52:13 -0800 Subject: [PATCH 047/140] fix random crash --- src/main/java/baritone/cache/ContainerMemory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index e0662a2e4..b2b6d5967 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -62,6 +62,7 @@ public class ContainerMemory implements IContainerMemory { RememberedInventory rem = new RememberedInventory(); rem.items.addAll(readItemStacks(in)); rem.size = rem.items.size(); + rem.windowId = -1; if (rem.items.isEmpty()) { continue; // this only happens if the list has no elements, not if the list has elements that are all empty item stacks } From 2bd81b08c22a1b5169dd7d18913b0440153f0051 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Dec 2018 14:38:08 -0800 Subject: [PATCH 048/140] overhaul and fixes to cost calculation --- .../pathing/movement/CalculationContext.java | 12 ++++++ .../pathing/movement/MovementHelper.java | 21 +++++----- .../movement/movements/MovementAscend.java | 32 +++++++------- .../movement/movements/MovementDescend.java | 12 +++--- .../movement/movements/MovementDiagonal.java | 8 ++-- .../movement/movements/MovementDownward.java | 9 ++-- .../movement/movements/MovementParkour.java | 42 +++++++++---------- .../movement/movements/MovementPillar.java | 32 +++++++------- .../movement/movements/MovementTraverse.java | 18 ++++---- 9 files changed, 95 insertions(+), 91 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index ace7670c1..da60dda82 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -53,6 +53,8 @@ public class CalculationContext { private final boolean canSprint; private final double placeBlockCost; private final boolean allowBreak; + private final boolean allowParkour; + private final boolean allowParkourPlace; private final int maxFallHeightNoWater; private final int maxFallHeightBucket; private final double waterWalkSpeed; @@ -76,6 +78,8 @@ public class CalculationContext { this.canSprint = Baritone.settings().allowSprint.get() && player.getFoodStats().getFoodLevel() > 6; this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get(); this.allowBreak = Baritone.settings().allowBreak.get(); + this.allowParkour = Baritone.settings().allowParkour.get(); + this.allowParkourPlace = Baritone.settings().allowParkourPlace.get(); this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); int depth = EnchantmentHelper.getDepthStriderModifier(player); @@ -173,6 +177,14 @@ public class CalculationContext { return allowBreak; } + public boolean allowParkour() { + return allowParkour; + } + + public boolean allowParkourPlace() { + return allowParkourPlace; + } + public int maxFallHeightNoWater() { return maxFallHeightNoWater; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index d56f19313..1059a4415 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -127,9 +127,9 @@ public interface MovementHelper extends ActionCosts, Helper { * not including water, and not including ladders or vines or cobwebs (they slow us down) * * @param context Calculation context to provide block state lookup - * @param x The block's x position - * @param y The block's y position - * @param z The block's z position + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position * @return Whether or not the block at the specified position */ static boolean fullyPassable(CalculationContext context, int x, int y, int z) { @@ -247,12 +247,11 @@ public interface MovementHelper extends ActionCosts, Helper { * through? Includes water because we know that we automatically jump on * water * - * @param bsi Block state provider - * @param x The block's x position - * @param y The block's y position - * @param z The block's z position + * @param bsi Block state provider + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position * @param state The state of the block at the specified location - * * @return Whether or not the specified block can be walked on */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { @@ -378,7 +377,7 @@ public interface MovementHelper extends ActionCosts, Helper { * AutoTool for a specific block * * @param ctx The player context - * @param b the blockstate to mine + * @param b the blockstate to mine */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) { switchToBestToolFor(ctx, b, new ToolSet(ctx.player())); @@ -388,8 +387,8 @@ public interface MovementHelper extends ActionCosts, Helper { * AutoTool for a specific block with precomputed ToolSet data * * @param ctx The player context - * @param b the blockstate to mine - * @param ts previously calculated ToolSet + * @param b the blockstate to mine + * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts) { ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock()); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 0baef8819..be9c9c2a2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -57,18 +57,7 @@ public class MovementAscend extends Movement { } public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { - IBlockState srcDown = context.get(x, y - 1, z); - if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) { - return COST_INF; - } - // we can jump from soul sand, but not from a bottom slab - boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown); IBlockState toPlace = context.get(destX, y, destZ); - 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 - } boolean hasToPlace = false; if (!MovementHelper.canWalkOn(context.bsi(), destX, y, destZ, toPlace)) { if (!context.canPlaceThrowawayAt(destX, y, destZ)) { @@ -95,8 +84,8 @@ public class MovementAscend extends Movement { return COST_INF; } } - IBlockState srcUp2 = null; - if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi(), x, y + 1, z) || !((srcUp2 = context.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + IBlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi(), x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts @@ -114,6 +103,16 @@ 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 } + IBlockState srcDown = context.get(x, y - 1, z); + if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) { + return COST_INF; + } + // we can jump from soul sand, but not from a bottom slab + boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown); + 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 + } double walk; if (jumpingToBottomSlab) { if (jumpingFromBottomSlab) { @@ -136,10 +135,9 @@ public class MovementAscend extends Movement { if (hasToPlace) { totalCost += context.placeBlockCost(); } - if (srcUp2 == null) { - srcUp2 = context.get(x, y + 2, z); - } - totalCost += MovementHelper.getMiningDurationTicks(context, x, y + 2, z, srcUp2, false); // TODO MAKE ABSOLUTELY SURE we don't need includeFalling here, from the falling check above + // start with srcUp2 since we already have its state + // includeFalling isn't needed because of the falling check above -- if srcUp3 is falling we will have already exited with COST_INF if we'd actually have to break it + totalCost += MovementHelper.getMiningDurationTicks(context, x, y + 2, z, srcUp2, false); if (totalCost >= COST_INF) { return COST_INF; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index d868c5fc1..18a8d50f7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -63,11 +63,6 @@ public class MovementDescend extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { - Block fromDown = context.get(x, y - 1, z).getBlock(); - if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { - return; - } - double totalCost = 0; IBlockState destDown = context.get(destX, y - 1, destZ); totalCost += MovementHelper.getMiningDurationTicks(context, destX, y - 1, destZ, destDown, false); @@ -83,6 +78,11 @@ public class MovementDescend extends Movement { return; } + Block fromDown = context.get(x, y - 1, z).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return; + } + // A //SA // A @@ -107,7 +107,7 @@ public class MovementDescend extends Movement { double walk = WALK_OFF_BLOCK_COST; 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 *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST; } totalCost += walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST); res.x = destX; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index afe5a976c..1426b73bc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -58,10 +58,6 @@ public class MovementDiagonal extends Movement { } public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { - Block fromDown = context.get(x, y - 1, z).getBlock(); - if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { - return COST_INF; - } IBlockState destInto = context.get(destX, y, destZ); if (!MovementHelper.canWalkThrough(context.bsi(), destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi(), destX, y + 1, destZ)) { return COST_INF; @@ -75,6 +71,10 @@ public class MovementDiagonal extends Movement { if (destWalkOn.getBlock() == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } + Block fromDown = context.get(x, y - 1, z).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index f18fc538f..2855bcebf 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -51,14 +51,13 @@ public class MovementDownward extends Movement { if (!MovementHelper.canWalkOn(context.bsi(), x, y - 2, z)) { return COST_INF; } - IBlockState d = context.get(x, y - 1, z); - Block td = d.getBlock(); - boolean ladder = td == Blocks.LADDER || td == Blocks.VINE; - if (ladder) { + IBlockState down = context.get(x, y - 1, z); + Block downBlock = down.getBlock(); + if (downBlock == Blocks.LADDER || downBlock == Blocks.VINE) { return LADDER_DOWN_ONE_COST; } else { // 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, x, y - 1, z, d, false); + return FALL_N_BLOCKS_COST[1] + MovementHelper.getMiningDurationTicks(context, x, y - 1, z, down, false); } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 80d6feb4f..ebb780b6c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -17,7 +17,6 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; @@ -30,7 +29,6 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; import baritone.utils.pathing.MutableMoveResult; import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; @@ -65,24 +63,22 @@ public class MovementParkour extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, EnumFacing dir, MutableMoveResult res) { - if (!Baritone.settings().allowParkour.get()) { - return; - } - IBlockState standingOn = context.get(x, y - 1, z); - if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) { - return; - } - int xDiff = dir.getXOffset(); - int zDiff = dir.getZOffset(); - IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); - if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks - return; - } - if (MovementHelper.canWalkOn(context.bsi(), x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (!context.allowParkour()) { return; } + int xDiff = dir.getXOffset(); + int zDiff = dir.getZOffset(); if (!MovementHelper.fullyPassable(context, x + xDiff, y, z + zDiff)) { + // most common case at the top -- the adjacent block isn't air + return; + } + IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); + if (MovementHelper.canWalkOn(context.bsi(), x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + // second most common case -- we could just traverse not parkour + return; + } + if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return; } if (!MovementHelper.fullyPassable(context, x + xDiff, y + 1, z + zDiff)) { @@ -94,6 +90,10 @@ public class MovementParkour extends Movement { if (!MovementHelper.fullyPassable(context, x, y + 2, z)) { return; } + IBlockState standingOn = context.get(x, y - 1, z); + if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) { + return; + } int maxJump; if (standingOn.getBlock() == Blocks.SOUL_SAND) { maxJump = 2; // 1 block gap @@ -122,20 +122,16 @@ public class MovementParkour extends Movement { if (maxJump != 4) { return; } - if (!Baritone.settings().allowParkourPlace.get()) { - return; - } - if (!Baritone.settings().allowPlace.get()) { - Helper.HELPER.logDirect("allowParkourPlace enabled but allowPlace disabled?"); + if (!context.allowParkourPlace()) { return; } int destX = x + 4 * xDiff; int destZ = z + 4 * zDiff; - IBlockState toPlace = context.get(destX, y - 1, destZ); if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) { return; } - if (toPlace.getBlock() != Blocks.AIR && !MovementHelper.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y - 1, destZ, toPlace, context.world())) { + IBlockState toReplace = context.get(destX, y - 1, destZ); + if (toReplace.getBlock() != Blocks.AIR && !MovementHelper.isWater(toReplace.getBlock()) && !MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.world())) { return; } for (int i = 0; i < 5; i++) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 78a626286..03d01a558 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -47,33 +47,36 @@ public class MovementPillar extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - Block fromDown = context.get(x, y, z).getBlock(); - boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine; - IBlockState fromDownDown = context.get(x, y - 1, z); + Block from = context.get(x, y, z).getBlock(); + boolean ladder = from == Blocks.LADDER || from == Blocks.VINE; + IBlockState fromDown = context.get(x, y - 1, z); if (!ladder) { - if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { - return COST_INF; + if (fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE) { + return COST_INF; // can't pillar from a ladder or vine onto something that isn't also climbable } - if (fromDownDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { return COST_INF; // can't pillar up from a bottom slab onto a non ladder } } - if (fromDown instanceof BlockVine && !hasAgainst(context, x, y, z)) { + if (from instanceof BlockVine && !hasAgainst(context, x, y, z)) { // TODO this vine can't be climbed, but we could place a pillar still since vines are replacable, no? perhaps the pillar jump would be impossible because of the slowdown actually. return COST_INF; } IBlockState toBreak = context.get(x, y + 2, z); Block toBreakBlock = toBreak.getBlock(); - if (toBreakBlock instanceof BlockFenceGate) { + if (toBreakBlock instanceof BlockFenceGate) { // see issue #172 return COST_INF; } Block srcUp = null; - if (MovementHelper.isWater(toBreakBlock) && MovementHelper.isWater(fromDown)) { + if (MovementHelper.isWater(toBreakBlock) && MovementHelper.isWater(from)) { // TODO should this also be allowed if toBreakBlock is air? srcUp = context.get(x, y + 1, z).getBlock(); if (MovementHelper.isWater(srcUp)) { - return LADDER_UP_ONE_COST; + return LADDER_UP_ONE_COST; // allow ascending pillars of water, but only if we're already in one } } - if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) { + if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) { // we need to place a block where we started to jump on it + return COST_INF; + } + if (from instanceof BlockLiquid || fromDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water return COST_INF; } double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true); @@ -81,10 +84,10 @@ public class MovementPillar extends Movement { return COST_INF; } if (hardness != 0) { - if (toBreakBlock instanceof BlockLadder || toBreakBlock instanceof BlockVine) { + if (toBreakBlock == Blocks.LADDER || toBreakBlock == Blocks.VINE) { hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it } else { - IBlockState check = context.get(x, y + 3, z); + IBlockState check = context.get(x, y + 3, z); // the block on top of the one we're going to break, could it fall on us? if (check.getBlock() instanceof BlockFalling) { // see MovementAscend's identical check for breaking a falling block above our head if (srcUp == null) { @@ -103,9 +106,6 @@ public class MovementPillar extends Movement { //} } } - if (fromDown instanceof BlockLiquid || fromDownDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water - return COST_INF; - } if (ladder) { return LADDER_UP_ONE_COST + hardness * 5; } else { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index aa25b5b64..477f15d02 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -80,11 +80,11 @@ public class MovementTraverse extends Movement { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } } - double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); + double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false); if (hardness1 >= COST_INF) { return COST_INF; } - double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false); + double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break if (hardness1 == 0 && hardness2 == 0) { if (!water && context.canSprint()) { // If there's nothing in the way, and this isn't water, and we aren't sneak placing @@ -106,39 +106,39 @@ public class MovementTraverse extends Movement { if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.world())) { boolean throughWater = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock()); if (MovementHelper.isWater(destOn.getBlock()) && throughWater) { + // this happens when assume walk on water is true and this is a traverse in water, which isn't allowed return COST_INF; } if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) { return COST_INF; } - double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb0, false); + double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false); if (hardness1 >= COST_INF) { return COST_INF; } - double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb1, true); - + double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST; for (int i = 0; i < 4; i++) { int againstX = destX + HORIZONTALS[i].getXOffset(); int againstZ = destZ + HORIZONTALS[i].getZOffset(); - if (againstX == x && againstZ == z) { + if (againstX == x && againstZ == z) { // this would be a backplace continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { // found a side place option return WC + context.placeBlockCost() + hardness1 + hardness2; } } + // now that we've checked all possible directions to side place, we actually need to backplace 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 =/ } if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) { return COST_INF; // this is obviously impossible } - WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking + WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are sneak backplacing, we are sneaking lol return WC + context.placeBlockCost() + hardness1 + hardness2; } return COST_INF; - // Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock()); } } From 862746038d4e6e20df1b438e4515990d2df81ab1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Dec 2018 15:00:45 -0800 Subject: [PATCH 049/140] allow down placement, and fixes to replacable --- .../pathing/movement/CalculationContext.java | 6 +++++ .../pathing/movement/MovementHelper.java | 10 +++++---- .../movement/movements/MovementAscend.java | 22 +++++++++---------- .../movement/movements/MovementDescend.java | 3 +-- .../movement/movements/MovementParkour.java | 7 +++--- .../movement/movements/MovementPillar.java | 5 ++++- .../movement/movements/MovementTraverse.java | 2 +- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index da60dda82..f3b9a2284 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -55,6 +55,7 @@ public class CalculationContext { private final boolean allowBreak; private final boolean allowParkour; private final boolean allowParkourPlace; + private final boolean assumeWalkOnWater; private final int maxFallHeightNoWater; private final int maxFallHeightBucket; private final double waterWalkSpeed; @@ -80,6 +81,7 @@ public class CalculationContext { this.allowBreak = Baritone.settings().allowBreak.get(); this.allowParkour = Baritone.settings().allowParkour.get(); this.allowParkourPlace = Baritone.settings().allowParkourPlace.get(); + this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.get(); this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); int depth = EnchantmentHelper.getDepthStriderModifier(player); @@ -185,6 +187,10 @@ public class CalculationContext { return allowParkourPlace; } + public boolean assumeWalkOnWater() { + return assumeWalkOnWater; + } + public int maxFallHeightNoWater() { return maxFallHeightNoWater; } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 1059a4415..5f9549b83 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -35,8 +35,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.EmptyChunk; /** * Static helpers for cost calculation @@ -160,7 +158,7 @@ public interface MovementHelper extends ActionCosts, Helper { return block.isPassable(null, null); } - static boolean isReplacable(int x, int y, int z, IBlockState state, World world) { + static boolean isReplacable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { // for MovementTraverse and MovementAscend // block double plant defaults to true when the block doesn't match, so don't need to check that case // all other overrides just return true or false @@ -172,9 +170,13 @@ public interface MovementHelper extends ActionCosts, Helper { * } */ Block block = state.getBlock(); + if (block == Blocks.AIR || isWater(block)) { + // early return for common cases hehe + return true; + } if (block instanceof BlockSnow) { // as before, default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) - if (world.getChunk(x >> 4, z >> 4) instanceof EmptyChunk) { + if (!bsi.worldContainsLoadedChunk(x, z)) { return true; } return state.getValue(BlockSnow.LAYERS) == 1; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index be9c9c2a2..c3a34fd94 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -37,6 +37,8 @@ import net.minecraft.util.math.Vec3d; import java.util.Objects; +import static baritone.pathing.movement.movements.MovementParkour.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP; + public class MovementAscend extends Movement { private int ticksWithoutPlacement = 0; @@ -63,19 +65,17 @@ public class MovementAscend extends Movement { if (!context.canPlaceThrowawayAt(destX, y, destZ)) { return COST_INF; } - if (toPlace.getBlock() != Blocks.AIR && !MovementHelper.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y, destZ, toPlace, context.world())) { + if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi())) { return COST_INF; } - // 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++) { - int againstX = destX + HORIZONTALS[i].getXOffset(); - int againstZ = destZ + HORIZONTALS[i].getZOffset(); - if (againstX == x && againstZ == z) { + for (int i = 0; i < 5; i++) { + int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset(); + int againstY = y + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset(); + int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset(); + if (againstX == x && againstZ == z) { // we might be able to backplace now, but it doesn't matter because it will have been broken by the time we'd need to use it continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { hasToPlace = true; break; } @@ -164,8 +164,8 @@ public class MovementAscend extends Movement { IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace); if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) { - for (int i = 0; i < 4; i++) { - BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]); + for (int i = 0; i < 5; i++) { + BlockPos anAgainst = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]); if (anAgainst.equals(src)) { continue; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 18a8d50f7..68ebbb66f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -17,7 +17,6 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; @@ -138,7 +137,7 @@ public class MovementDescend extends Movement { if (ontoBlock.getBlock() == Blocks.WATER && !MovementHelper.isFlowing(ontoBlock) && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // TODO flowing check required here? // lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad // however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works) - if (Baritone.settings().assumeWalkOnWater.get()) { + if (context.assumeWalkOnWater()) { return; // TODO fix } // found a fall into water diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index ebb780b6c..5520d1c13 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -43,7 +43,7 @@ import java.util.Objects; public class MovementParkour extends Movement { - private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; + static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{}; private final EnumFacing direction; @@ -131,16 +131,17 @@ public class MovementParkour extends Movement { return; } IBlockState toReplace = context.get(destX, y - 1, destZ); - if (toReplace.getBlock() != Blocks.AIR && !MovementHelper.isWater(toReplace.getBlock()) && !MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.world())) { + if (!MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.bsi())) { return; } for (int i = 0; i < 5; i++) { int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset(); + int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset(); int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset(); if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { res.x = destX; res.y = y; res.z = destZ; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 03d01a558..0e6b023e3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -76,7 +76,10 @@ public class MovementPillar extends Movement { if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) { // we need to place a block where we started to jump on it return COST_INF; } - if (from instanceof BlockLiquid || fromDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water + if (from instanceof BlockLiquid || (fromDown.getBlock() instanceof BlockLiquid && context.assumeWalkOnWater())) { + // otherwise, if we're standing in water, we cannot pillar + // if we're standing on water and assumeWalkOnWater is true, we cannot pillar + // if we're standing on water and assumeWalkOnWater is false, we must have ascended to here, or sneak backplaced, so it is possible to pillar again return COST_INF; } double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 477f15d02..f71cec9d6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -103,7 +103,7 @@ public class MovementTraverse extends Movement { if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { return COST_INF; } - if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.world())) { + if (MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.bsi())) { boolean throughWater = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock()); if (MovementHelper.isWater(destOn.getBlock()) && throughWater) { // this happens when assume walk on water is true and this is a traverse in water, which isn't allowed From 21d8c11cfeb7cc0980f3ba7163f6bb29f5945d8a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Dec 2018 15:33:29 -0800 Subject: [PATCH 050/140] go in the opposite order --- .../baritone/pathing/movement/movements/MovementParkour.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 5520d1c13..949598ead 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -212,7 +212,7 @@ public class MovementParkour extends Movement { if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround) { BlockPos positionToPlace = dest.down(); - for (int i = 0; i < 5; i++) { + for (int i = 4; i >= 0; i--) { // go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory BlockPos against1 = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]); if (against1.up().equals(src.offset(direction, 3))) { // we can't turn around that fast continue; From 28c25864524cb4057cc897593eca6f35946cdf27 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Dec 2018 15:50:44 -0800 Subject: [PATCH 051/140] fix parkour place logic --- .../movement/movements/MovementParkour.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 949598ead..b1ab712ad 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -39,8 +39,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; -import java.util.Objects; - public class MovementParkour extends Movement { static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; @@ -228,15 +226,16 @@ public class MovementParkour extends Movement { RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance()); if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) { state.setTarget(new MovementState.MovementTarget(place, true)); + break; } - ctx.getSelectedBlock().ifPresent(selectedBlock -> { - EnumFacing side = ctx.objectMouseOver().sideHit; - if (Objects.equals(selectedBlock, against1) && selectedBlock.offset(side).equals(dest.down())) { - state.setInput(Input.CLICK_RIGHT, true); - } - }); } } + ctx.getSelectedBlock().ifPresent(selectedBlock -> { + EnumFacing side = ctx.objectMouseOver().sideHit; + if (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(dest.down())) { + state.setInput(Input.CLICK_RIGHT, true); + } + }); } if (dist == 3) { // this is a 2 block gap, dest = src + direction * 3 double xDiff = (src.x + 0.5) - ctx.player().posX; From 27603549433a28fc3eb8818868372ac4cfb9197f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Dec 2018 18:12:04 -0800 Subject: [PATCH 052/140] cool vine and ladder descending, fixes #159 --- .../pathing/calc/AStarPathFinder.java | 2 +- .../java/baritone/pathing/calc/PathNode.java | 3 ++ .../movement/movements/MovementDescend.java | 50 +++++++++++++------ .../movement/movements/MovementFall.java | 48 ++++++++++++++++-- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 4b57abf1c..bbc0738a8 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -121,7 +121,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel if (actionCost >= ActionCosts.COST_INF) { continue; } - if (actionCost <= 0) { + if (actionCost <= 0 || Double.isNaN(actionCost)) { throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); } if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index e12a2458a..dc2dbf906 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -73,6 +73,9 @@ public final class PathNode { this.previous = null; this.cost = ActionCosts.COST_INF; this.estimatedCostToGoal = goal.heuristic(x, y, z); + if (Double.isNaN(estimatedCostToGoal)) { + throw new IllegalStateException(goal + " calculated implausible heuristic"); + } this.isOpen = false; this.x = x; this.y = y; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 68ebbb66f..fc61a1eb5 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -115,66 +115,84 @@ public class MovementDescend extends Movement { res.cost = totalCost; } - public static void dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below, MutableMoveResult res) { + public static boolean dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below, MutableMoveResult res) { if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) { // if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall // but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column, // and potentially replace the water we're going to fall into - return; + return false; } if (!MovementHelper.canWalkThrough(context.bsi(), destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { - return; + return false; } + double costSoFar = 0; + int effectiveStartHeight = y; for (int fallHeight = 3; true; fallHeight++) { int newY = y - fallHeight; if (newY < 0) { // when pathing in the end, where you could plausibly fall into the void // this check prevents it from getting the block at y=-1 and crashing - return; + return false; } IBlockState ontoBlock = context.get(destX, newY, destZ); - double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[fallHeight] + frontBreak; - if (ontoBlock.getBlock() == Blocks.WATER && !MovementHelper.isFlowing(ontoBlock) && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // TODO flowing check required here? + int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY + double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar; + if (ontoBlock.getBlock() == Blocks.WATER && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad // however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works) if (context.assumeWalkOnWater()) { - return; // TODO fix + return false; // TODO fix + } + if (MovementHelper.isFlowing(ontoBlock)) { + return false; // TODO flowing check required here? + } + if (!MovementHelper.canWalkOn(context.bsi(), destX, newY - 1, destZ)) { + // we could punch right through the water into something else + return false; } // found a fall into water res.x = destX; res.y = newY; res.z = destZ; res.cost = tentativeCost;// TODO incorporate water swim up cost? - return; + return false; } if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) { - return; + return false; + } + if (unprotectedFallHeight <= 11 && (ontoBlock.getBlock() == Blocks.VINE || ontoBlock.getBlock() == Blocks.LADDER)) { + // if fall height is greater than or equal to 11, we don't actually grab on to vines or ladders. the more you know + // this effectively "resets" our falling speed + costSoFar += FALL_N_BLOCKS_COST[unprotectedFallHeight - 1];// we fall until the top of this block (not including this block) + costSoFar += LADDER_DOWN_ONE_COST; + effectiveStartHeight = newY; + continue; } if (MovementHelper.canWalkThrough(context.bsi(), destX, newY, destZ, ontoBlock)) { continue; } if (!MovementHelper.canWalkOn(context.bsi(), destX, newY, destZ, ontoBlock)) { - return; + return false; } if (MovementHelper.isBottomSlab(ontoBlock)) { - return; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect + return false; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect } - if (context.hasWaterBucket() && fallHeight <= context.maxFallHeightBucket() + 1) { + if (context.hasWaterBucket() && unprotectedFallHeight <= context.maxFallHeightBucket() + 1) { res.x = destX; res.y = newY + 1;// this is the block we're falling onto, so dest is +1 res.z = destZ; res.cost = tentativeCost + context.placeBlockCost(); - return; + return true; } - if (fallHeight <= context.maxFallHeightNoWater() + 1) { + if (unprotectedFallHeight <= context.maxFallHeightNoWater() + 1) { // fallHeight = 4 means onto.up() is 3 blocks down, which is the max res.x = destX; res.y = newY + 1; res.z = destZ; res.cost = tentativeCost; - return; + return false; } else { - return; + return false; } } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index ef89919bf..90b44c14c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -17,7 +17,6 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; @@ -31,12 +30,19 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.pathing.MutableMoveResult; +import net.minecraft.block.BlockLadder; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; + +import java.util.Optional; public class MovementFall extends Movement { @@ -57,6 +63,12 @@ public class MovementFall extends Movement { return result.cost; } + private boolean willPlaceBucket() { + CalculationContext context = new CalculationContext(baritone); + MutableMoveResult result = new MutableMoveResult(); + return MovementDescend.dynamicFallCost(context, src.x, src.y, src.z, dest.x, dest.z, 0, context.get(dest.x, src.y - 2, dest.z), result); + } + @Override public MovementState updateState(MovementState state) { super.updateState(state); @@ -67,7 +79,7 @@ public class MovementFall extends Movement { BlockPos playerFeet = ctx.playerFeet(); Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest)); Rotation targetRotation = null; - if (!MovementHelper.isWater(ctx, dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { + if (!MovementHelper.isWater(ctx, dest) && willPlaceBucket() && !playerFeet.equals(dest)) { if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().provider.isNether()) { return state.setStatus(MovementStatus.UNREACHABLE); } @@ -78,7 +90,7 @@ public class MovementFall extends Movement { targetRotation = new Rotation(toDest.getYaw(), 90.0F); RayTraceResult trace = ctx.objectMouseOver(); - if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && ctx.player().rotationPitch > 89.0F) { + if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) { state.setInput(Input.CLICK_RIGHT, true); } } @@ -107,12 +119,40 @@ public class MovementFall extends Movement { } } Vec3d destCenter = VecUtils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder) - if (Math.abs(ctx.player().posX - destCenter.x) > 0.15 || Math.abs(ctx.player().posZ - destCenter.z) > 0.15) { + if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) { + if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) { + state.setInput(Input.SNEAK, true); + } state.setInput(Input.MOVE_FORWARD, true); } + Vec3i avoid = Optional.ofNullable(avoid()).map(EnumFacing::getDirectionVec).orElse(null); + if (avoid == null) { + avoid = src.subtract(dest); + } else { + double dist = Math.abs(avoid.getX() * (destCenter.x - avoid.getX() / 2.0 - ctx.player().posX)) + Math.abs(avoid.getZ() * (destCenter.z - avoid.getZ() / 2.0 - ctx.player().posZ)); + if (dist < 0.6) { + state.setInput(Input.MOVE_FORWARD, true); + } else { + state.setInput(Input.SNEAK, false); + } + } + if (targetRotation == null) { + Vec3d destCenterOffset = new Vec3d(destCenter.x + 0.125 * avoid.getX(), destCenter.y, destCenter.z + 0.125 * avoid.getZ()); + state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), destCenterOffset), false)); + } return state; } + private EnumFacing avoid() { + for (int i = 0; i < 15; i++) { + IBlockState state = ctx.world().getBlockState(ctx.playerFeet().down(i)); + if (state.getBlock() == Blocks.LADDER) { + return state.getValue(BlockLadder.FACING); + } + } + return null; + } + @Override public boolean safeToCancel(MovementState state) { // if we haven't started walking off the edge yet, or if we're in the process of breaking blocks before doing the fall From 64eabf71f2c7d6142f1923b460aa2ffc9b992a85 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Dec 2018 08:29:32 -0800 Subject: [PATCH 053/140] traverse place against below --- .../java/baritone/pathing/movement/Movement.java | 2 +- .../pathing/movement/movements/MovementAscend.java | 2 -- .../pathing/movement/movements/MovementParkour.java | 1 - .../movement/movements/MovementTraverse.java | 13 +++++++------ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 7ba9f6eac..38cc329bb 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -36,6 +36,7 @@ import java.util.Optional; public abstract class Movement implements IMovement, MovementHelper { protected static final EnumFacing[] HORIZONTALS = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST}; + protected static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; protected final IBaritone baritone; protected final IPlayerContext ctx; @@ -208,7 +209,6 @@ public abstract class Movement implements IMovement, MovementHelper { * Calculate latest movement state. Gets called once a tick. * * @param state The current state - * * @return The new state */ public MovementState updateState(MovementState state) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index c3a34fd94..735c94b87 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -37,8 +37,6 @@ import net.minecraft.util.math.Vec3d; import java.util.Objects; -import static baritone.pathing.movement.movements.MovementParkour.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP; - public class MovementAscend extends Movement { private int ticksWithoutPlacement = 0; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index b1ab712ad..2d6e0b2f6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -41,7 +41,6 @@ import net.minecraft.util.math.Vec3d; public class MovementParkour extends Movement { - static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{}; private final EnumFacing direction; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index f71cec9d6..59720b91c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -118,13 +118,14 @@ public class MovementTraverse extends Movement { } double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST; - for (int i = 0; i < 4; i++) { - int againstX = destX + HORIZONTALS[i].getXOffset(); - int againstZ = destZ + HORIZONTALS[i].getZOffset(); + for (int i = 0; i < 5; i++) { + int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset(); + int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset(); + int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset(); if (againstX == x && againstZ == z) { // this would be a backplace continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { // found a side place option + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { // found a side place option return WC + context.placeBlockCost() + hardness1 + hardness2; } } @@ -241,8 +242,8 @@ public class MovementTraverse extends Movement { return state; } else { wasTheBridgeBlockAlwaysThere = false; - for (int i = 0; i < 4; i++) { - BlockPos against1 = dest.offset(HORIZONTALS[i]); + for (int i = 0; i < 5; i++) { + BlockPos against1 = dest.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]); if (against1.equals(src)) { continue; } From c79591325926633d84d55e0aacbd48ec79774df3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Dec 2018 10:21:56 -0800 Subject: [PATCH 054/140] fix splicing behavior around water --- .../java/baritone/pathing/path/PathExecutor.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index fa4c0e5f3..749a23e30 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -35,6 +35,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; +import net.minecraft.block.BlockLiquid; import net.minecraft.init.Blocks; import net.minecraft.util.Tuple; import net.minecraft.util.math.BlockPos; @@ -351,14 +352,22 @@ public class PathExecutor implements IPathExecutor, Helper { * @return Whether or not it was possible to snap to the current player feet */ public boolean snipsnapifpossible() { - if (!ctx.player().onGround) { + if (!ctx.player().onGround && !(ctx.world().getBlockState(ctx.playerFeet()).getBlock() instanceof BlockLiquid)) { + // if we're falling in the air, and not in water, don't splice return false; + } else { + // we are either onGround or in liquid + if (ctx.player().motionY < 0) { + // if we are strictly moving downwards (not stationary) + // we could be falling through water, which could be unsafe to splice + return false; // so don't + } } int index = path.positions().indexOf(ctx.playerFeet()); if (index == -1) { return false; } - pathPosition = index; + pathPosition = index; // jump directly to current position clearKeys(); return true; } From 101f7cb7e22cc96e3023af8416344e335a23c9d1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Dec 2018 10:22:18 -0800 Subject: [PATCH 055/140] move heuristic up to exactly equal SPRINT_ONE_BLOCK_COST --- src/api/java/baritone/api/Settings.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index f186f51b9..e909c1353 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -141,8 +141,10 @@ public class Settings { * metric gets better and better with each block, instead of slightly worse. *

* Finding the optimal path is worth it, so it's the default. + *

+ * This value is an expression instead of a literal so that it's exactly equal to SPRINT_ONE_BLOCK_COST defined in ActionCosts.java */ - public Setting costHeuristic = new Setting<>(3.5D); + public Setting costHeuristic = new Setting<>(20 / 5.612); // a bunch of obscure internal A* settings that you probably don't want to change /** From 87dbf1dbba770af62616f1c82ff2548f8a6caf9a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Dec 2018 17:59:32 -0800 Subject: [PATCH 056/140] fix false positive in check --- 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 749a23e30..0e3e9bea5 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -357,7 +357,7 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } else { // we are either onGround or in liquid - if (ctx.player().motionY < 0) { + if (ctx.player().motionY < -0.1) { // if we are strictly moving downwards (not stationary) // we could be falling through water, which could be unsafe to splice return false; // so don't From 245b2483ab1fac0ad86dfb870762d5ef667db678 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 5 Dec 2018 18:01:23 -0800 Subject: [PATCH 057/140] fix crash when path length is exactly 30 --- src/main/java/baritone/utils/pathing/PathBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 129e07358..3fbc95ca2 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -47,7 +47,7 @@ public abstract class PathBase implements IPath { return this; } double factor = BaritoneAPI.getSettings().pathCutoffFactor.get(); - int newLength = (int) ((length() - 1 - min) * factor) + min; + int newLength = (int) ((length() - min) * factor) + min - 1; return new CutoffPath(this, newLength); } } From a61b82748cd2e2a371438320fb09368898994409 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Dec 2018 21:52:24 -0800 Subject: [PATCH 058/140] remove extraneous prints --- src/main/java/baritone/cache/ContainerMemory.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index b2b6d5967..ae54e157c 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -51,14 +51,12 @@ public class ContainerMemory implements IContainerMemory { } private void read(byte[] bytes) throws IOException { - System.out.println("READ BYTES " + bytes.length); PacketBuffer in = new PacketBuffer(Unpooled.wrappedBuffer(bytes)); int chests = in.readInt(); for (int i = 0; i < chests; i++) { int x = in.readInt(); int y = in.readInt(); int z = in.readInt(); - System.out.println("Read x y z " + x + " " + y + " " + z); RememberedInventory rem = new RememberedInventory(); rem.items.addAll(readItemStacks(in)); rem.size = rem.items.size(); @@ -80,7 +78,6 @@ public class ContainerMemory implements IContainerMemory { out = new PacketBuffer(out.writeInt(entry.getKey().getZ())); out = writeItemStacks(entry.getValue().getContents(), out); } - System.out.println("CONTAINER BYTES " + out.array().length); Files.write(saveTo, out.array()); } @@ -112,7 +109,6 @@ public class ContainerMemory implements IContainerMemory { public static List readItemStacks(PacketBuffer in) throws IOException { int count = in.readInt(); - System.out.println("Read count " + count); List result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(in.readItemStack()); @@ -128,10 +124,8 @@ public class ContainerMemory implements IContainerMemory { } public static PacketBuffer writeItemStacks(List write, PacketBuffer out) { - System.out.println("WRITING ITEM STACKS " + write.size() + " " + write); out = new PacketBuffer(out.writeInt(write.size())); for (ItemStack stack : write) { - System.out.println(out.writableBytes()); out = out.writeItemStack(stack); } return out; From bf68afdda3345cbe708ffc220288e9c437bfb6a0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Dec 2018 15:40:32 -0800 Subject: [PATCH 059/140] GetToBlock should only highlight the block itself --- src/main/java/baritone/utils/PathRenderer.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index f740cdf60..deca0951d 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -21,10 +21,7 @@ import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.event.events.RenderEvent; import baritone.api.pathing.calc.IPath; -import baritone.api.pathing.goals.Goal; -import baritone.api.pathing.goals.GoalComposite; -import baritone.api.pathing.goals.GoalTwoBlocks; -import baritone.api.pathing.goals.GoalXZ; +import baritone.api.pathing.goals.*; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.interfaces.IGoalRenderPos; import baritone.behavior.PathingBehavior; @@ -283,14 +280,14 @@ public final class PathRenderer implements Helper { minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); - if (goal instanceof GoalTwoBlocks) { + if (goal instanceof GoalGetToBlock || goal instanceof GoalTwoBlocks) { y /= 2; } y1 = 1 + y + goalPos.getY() - renderPosY; y2 = 1 - y + goalPos.getY() - renderPosY; minY = goalPos.getY() - renderPosY; maxY = minY + 2; - if (goal instanceof GoalTwoBlocks) { + if (goal instanceof GoalGetToBlock || goal instanceof GoalTwoBlocks) { y1 -= 0.5; y2 -= 0.5; maxY--; From d5e155d77f6ac3cc05bd569cb9733bca57f43406 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Dec 2018 15:53:41 -0800 Subject: [PATCH 060/140] walk into, and right click on arrival --- .../baritone/process/GetToBlockProcess.java | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 920e57433..669e6aff9 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -21,19 +21,27 @@ import baritone.Baritone; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalComposite; import baritone.api.pathing.goals.GoalGetToBlock; +import baritone.api.pathing.goals.GoalTwoBlocks; import baritone.api.process.IGetToBlockProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.utils.Rotation; +import baritone.api.utils.RotationUtils; +import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.utils.BaritoneProcessHelper; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.ContainerPlayer; import net.minecraft.util.math.BlockPos; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess { + private Block gettingTo; private List knownLocations; @@ -45,8 +53,8 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl @Override public void getToBlock(Block block) { + onLostControl(); gettingTo = block; - knownLocations = null; rescan(new ArrayList<>(), new CalculationContext(baritone)); } @@ -80,9 +88,16 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(current, context)); } - Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); - if (goal.isInGoal(ctx.playerFeet())) { - onLostControl(); + Goal goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new)); + if (goal.isInGoal(ctx.playerFeet()) && isSafeToCancel) { + // we're there + if (rightClickOnArrival(gettingTo)) { + if (rightClick()) { + onLostControl(); + } + } else { + onLostControl(); + } } return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH); } @@ -91,6 +106,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl public void onLostControl() { gettingTo = null; knownLocations = null; + baritone.getInputOverrideHandler().clearAllKeys(); } @Override @@ -101,4 +117,35 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl private void rescan(List known, CalculationContext context) { knownLocations = MineProcess.searchWorld(context, Collections.singletonList(gettingTo), 64, known); } + + private Goal createGoal(BlockPos pos) { + return walkIntoInsteadOfAdjacent(gettingTo) ? new GoalTwoBlocks(pos) : new GoalGetToBlock(pos); + } + + private boolean rightClick() { + for (BlockPos pos : knownLocations) { + Optional reachable = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); + if (reachable.isPresent()) { + baritone.getLookBehavior().updateTarget(reachable.get(), true); + if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); // TODO find some way to right click even if we're in an ESC menu + System.out.println(ctx.player().openContainer); + if (!(ctx.player().openContainer instanceof ContainerPlayer)) { + return true; + } + } + return false; // trying to right click, will do it next tick or so + } + } + logDirect("Arrived but failed to right click open"); + return true; + } + + private boolean walkIntoInsteadOfAdjacent(Block block) { + return block == Blocks.PORTAL; + } + + private boolean rightClickOnArrival(Block block) { + return block == Blocks.CRAFTING_TABLE || block == Blocks.FURNACE || block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST; + } } \ No newline at end of file From efe06264bde2da357e758372ada793ccf6bedc56 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Dec 2018 16:54:12 -0800 Subject: [PATCH 061/140] settings for right click and enter portal --- src/api/java/baritone/api/Settings.java | 11 +++++++++++ src/main/java/baritone/process/GetToBlockProcess.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index e909c1353..e65ce88e2 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -184,6 +184,17 @@ public class Settings { public Setting mobAvoidanceRadius = new Setting<>(8); + /** + * When running a goto towards a container block (chest, ender chest, furnace, etc), + * right click and open it once you arrive. + */ + public Setting rightClickContainerOnArrival = new Setting<>(true); + + /** + * When running a goto towards a nether portal block, walk all the way into the portal + * instead of stopping one block before. + */ + public Setting enterPortal = new Setting<>(true); /** * Don't repropagate cost improvements below 0.01 ticks. They're all just floating point inaccuracies, diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 669e6aff9..48883e13b 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -142,10 +142,16 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } private boolean walkIntoInsteadOfAdjacent(Block block) { + if (!Baritone.settings().enterPortal.get()) { + return false; + } return block == Blocks.PORTAL; } private boolean rightClickOnArrival(Block block) { + if (!Baritone.settings().rightClickContainerOnArrival.get()) { + return false; + } return block == Blocks.CRAFTING_TABLE || block == Blocks.FURNACE || block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST; } } \ No newline at end of file From c15dac3582f988da85fb57063aaeb8a1992e62ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 7 Dec 2018 16:57:12 -0800 Subject: [PATCH 062/140] simple inventory management --- src/api/java/baritone/api/Settings.java | 5 + src/main/java/baritone/Baritone.java | 6 +- .../baritone/behavior/InventoryBehavior.java | 98 +++++++++++++++++++ src/main/java/baritone/utils/ToolSet.java | 2 +- 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 src/main/java/baritone/behavior/InventoryBehavior.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index e65ce88e2..fe28da51d 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -50,6 +50,11 @@ public class Settings { */ public Setting allowPlace = new Setting<>(true); + /** + * Allow Baritone to move items in your inventory to your hotbar + */ + public Setting allowInventory = new Setting<>(false); + /** * It doesn't actually take twenty ticks to place a block, this cost is so high * because we want to generally conserve blocks which might be limited diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 1353dcc68..41fa36c50 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -22,10 +22,7 @@ import baritone.api.IBaritone; import baritone.api.Settings; import baritone.api.event.listener.IEventBus; import baritone.api.utils.IPlayerContext; -import baritone.behavior.Behavior; -import baritone.behavior.LookBehavior; -import baritone.behavior.MemoryBehavior; -import baritone.behavior.PathingBehavior; +import baritone.behavior.*; import baritone.cache.WorldProvider; import baritone.event.GameEventHandler; import baritone.process.CustomGoalProcess; @@ -110,6 +107,7 @@ public class Baritone implements IBaritone { pathingBehavior = new PathingBehavior(this); lookBehavior = new LookBehavior(this); memoryBehavior = new MemoryBehavior(this); + new InventoryBehavior(this); inputOverrideHandler = new InputOverrideHandler(this); new ExampleBaritoneControl(this); } diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java new file mode 100644 index 000000000..9b191204b --- /dev/null +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -0,0 +1,98 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.behavior; + +import baritone.Baritone; +import baritone.api.event.events.TickEvent; +import baritone.utils.ToolSet; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.ClickType; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemTool; +import net.minecraft.util.NonNullList; + +public class InventoryBehavior extends Behavior { + public InventoryBehavior(Baritone baritone) { + super(baritone); + } + + @Override + public void onTick(TickEvent event) { + if (!Baritone.settings().allowInventory.get()) { + return; + } + if (event.getType() == TickEvent.Type.OUT) { + return; + } + if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiInventory)) { + // we have chat or a chest or something open + return; + } + if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory + swapWithHotBar(firstValidThrowaway(), 8); + } + int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class); + if (pick >= 9) { + swapWithHotBar(pick, 0); + } + } + + private void swapWithHotBar(int inInventory, int inHotbar) { + int windowId = ctx.player().inventoryContainer.windowId; + // aaaaaaaaaaaaaaaaaaaaaaaaaaaa + // aaaaaaaaAAAAAAaaaaaAAaaaAAAAaaAAA + if (inInventory < 9) { + inInventory += 36; + } + ctx.playerController().windowClick(windowId, inInventory, inHotbar, ClickType.SWAP, ctx.player()); + } + + private int firstValidThrowaway() { // TODO offhand idk + NonNullList invy = ctx.player().inventory.mainInventory; + for (int i = 0; i < invy.size(); i++) { + if (Baritone.settings().acceptableThrowawayItems.get().contains(invy.get(i).getItem())) { + return i; + } + } + return -1; + } + + private int bestToolAgainst(Block against, Class klass) { + NonNullList invy = ctx.player().inventory.mainInventory; + int bestInd = -1; + double bestSpeed = -1; + for (int i = 0; i < invy.size(); i++) { + ItemStack stack = invy.get(i); + if (stack.isEmpty()) { + continue; + } + if (klass.isInstance(stack.getItem())) { + double speed = ToolSet.calculateStrVsBlock(stack, against.getDefaultState()); // takes into account enchants + if (speed > bestSpeed) { + bestSpeed = speed; + bestInd = i; + } + } + } + return bestInd; + } +} diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 026ec1996..880517a06 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -138,7 +138,7 @@ public class ToolSet { * @param state the blockstate to be mined * @return how long it would take in ticks */ - private double calculateStrVsBlock(ItemStack item, IBlockState state) { + public static double calculateStrVsBlock(ItemStack item, IBlockState state) { float hardness = state.getBlockHardness(null, null); if (hardness < 0) { return -1; From 72d8863862e3982382c34af2bae9698965bac2c5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 8 Dec 2018 17:49:23 -0800 Subject: [PATCH 063/140] fix openness check to work for mulitple bots --- src/main/java/baritone/behavior/InventoryBehavior.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 9b191204b..ad5eae10d 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -21,8 +21,6 @@ import baritone.Baritone; import baritone.api.event.events.TickEvent; import baritone.utils.ToolSet; import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.init.Blocks; import net.minecraft.inventory.ClickType; import net.minecraft.item.ItemPickaxe; @@ -43,8 +41,8 @@ public class InventoryBehavior extends Behavior { if (event.getType() == TickEvent.Type.OUT) { return; } - if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiInventory)) { - // we have chat or a chest or something open + if (ctx.player().openContainer == ctx.player().inventoryContainer) { + // we have a crafting table or a chest or something open return; } if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory From 1d0413f159173e967d7e9e0ce18dfd9b9cedafca Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 8 Dec 2018 18:28:04 -0800 Subject: [PATCH 064/140] im idiot --- src/main/java/baritone/behavior/InventoryBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index ad5eae10d..25a97965c 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -41,7 +41,7 @@ public class InventoryBehavior extends Behavior { if (event.getType() == TickEvent.Type.OUT) { return; } - if (ctx.player().openContainer == ctx.player().inventoryContainer) { + if (ctx.player().openContainer != ctx.player().inventoryContainer) { // we have a crafting table or a chest or something open return; } From bca6a580e310b26460bd418eeed9f220bda596b5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 9 Dec 2018 19:25:00 -0800 Subject: [PATCH 065/140] combine --- src/main/java/baritone/behavior/InventoryBehavior.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 25a97965c..3e0ff70b0 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -55,13 +55,12 @@ public class InventoryBehavior extends Behavior { } private void swapWithHotBar(int inInventory, int inHotbar) { - int windowId = ctx.player().inventoryContainer.windowId; // aaaaaaaaaaaaaaaaaaaaaaaaaaaa // aaaaaaaaAAAAAAaaaaaAAaaaAAAAaaAAA if (inInventory < 9) { inInventory += 36; } - ctx.playerController().windowClick(windowId, inInventory, inHotbar, ClickType.SWAP, ctx.player()); + ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory, inHotbar, ClickType.SWAP, ctx.player()); } private int firstValidThrowaway() { // TODO offhand idk From 24c0ec905e6813abb6348a2426e67ae0217f65dc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 10 Dec 2018 18:05:31 -0800 Subject: [PATCH 066/140] removed dumb comment --- src/main/java/baritone/behavior/InventoryBehavior.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 3e0ff70b0..b6d7e1bd6 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -55,8 +55,6 @@ public class InventoryBehavior extends Behavior { } private void swapWithHotBar(int inInventory, int inHotbar) { - // aaaaaaaaaaaaaaaaaaaaaaaaaaaa - // aaaaaaaaAAAAAAaaaaaAAaaaAAAAaaAAA if (inInventory < 9) { inInventory += 36; } From fb2a808f5c1927028ef54cd45c42499fd22ed700 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 12:16:36 -0800 Subject: [PATCH 067/140] more badges is good --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 904f3d61c..e3cd6f74f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) [![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://minecraft.gamepedia.com/1.12.2) +[![Impact integration](https://img.shields.io/badge/Impact%20integration-1.0.0--hotfix--4-green.svg)](https://impactdevelopment.github.io/) +[![KAMI integration](https://img.shields.io/badge/KAMI%20integration-1.0.0-orange.svg)](https://github.com/zeroeightysix/KAMI/) +[![Asuna integration](https://img.shields.io/badge/Asuna%20integration-1.0.0-orange.svg)](https://github.com/EmotionalLove/Asuna/) +[![Future integration](https://img.shields.io/badge/Future%20integration-%3F%3F%3F-red.svg)](https://futureclient.net/) A Minecraft pathfinder bot. From 9480f0d2bc8a8ffbb87598f01710f445739f9eec Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 12:19:45 -0800 Subject: [PATCH 068/140] hell yeah bright green --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3cd6f74f..f8202d893 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) [![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://minecraft.gamepedia.com/1.12.2) -[![Impact integration](https://img.shields.io/badge/Impact%20integration-1.0.0--hotfix--4-green.svg)](https://impactdevelopment.github.io/) +[![Impact integration](https://img.shields.io/badge/Impact%20integration-1.0.0--hotfix--4-brightgreen.svg)](https://impactdevelopment.github.io/) [![KAMI integration](https://img.shields.io/badge/KAMI%20integration-1.0.0-orange.svg)](https://github.com/zeroeightysix/KAMI/) [![Asuna integration](https://img.shields.io/badge/Asuna%20integration-1.0.0-orange.svg)](https://github.com/EmotionalLove/Asuna/) [![Future integration](https://img.shields.io/badge/Future%20integration-%3F%3F%3F-red.svg)](https://futureclient.net/) From e343756e44d3fda9a9279066bc6e2121c43fb5d6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 12:21:24 -0800 Subject: [PATCH 069/140] i dont like license being orange --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8202d893..054a44665 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Baritone [![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone) [![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases) -[![License](https://img.shields.io/github/license/cabaletta/baritone.svg)](LICENSE) +[![License](https://img.shields.io/badge/license-LGPL--3.0-green.svg)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade) [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) From 4f9268e57105225e27025dfbdba11027f4d2d65a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 12:23:26 -0800 Subject: [PATCH 070/140] forgot Vs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 054a44665..3f2a009b2 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) [![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://minecraft.gamepedia.com/1.12.2) -[![Impact integration](https://img.shields.io/badge/Impact%20integration-1.0.0--hotfix--4-brightgreen.svg)](https://impactdevelopment.github.io/) -[![KAMI integration](https://img.shields.io/badge/KAMI%20integration-1.0.0-orange.svg)](https://github.com/zeroeightysix/KAMI/) -[![Asuna integration](https://img.shields.io/badge/Asuna%20integration-1.0.0-orange.svg)](https://github.com/EmotionalLove/Asuna/) +[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.0.0--hotfix--4-brightgreen.svg)](https://impactdevelopment.github.io/) +[![KAMI integration](https://img.shields.io/badge/KAMI%20integration-v1.0.0-orange.svg)](https://github.com/zeroeightysix/KAMI/) +[![Asuna integration](https://img.shields.io/badge/Asuna%20integration-v1.0.0-orange.svg)](https://github.com/EmotionalLove/Asuna/) [![Future integration](https://img.shields.io/badge/Future%20integration-%3F%3F%3F-red.svg)](https://futureclient.net/) A Minecraft pathfinder bot. From a2534a822748321a851df995e20badc953616b7c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 16:00:48 -0800 Subject: [PATCH 071/140] unused imports --- .../event/listener/IGameEventListener.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index 5cca43a55..9308ab4c5 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -23,13 +23,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiGameOver; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; -import net.minecraft.util.text.ITextComponent; /** * @author Brady @@ -40,18 +36,16 @@ public interface IGameEventListener { /** * Run once per game tick before screen input is handled. * - * @see Minecraft#runTick() - * * @param event The event + * @see Minecraft#runTick() */ void onTick(TickEvent event); /** * Run once per game tick from before and after the player rotation is sent to the server. * - * @see EntityPlayerSP#onUpdate() - * * @param event The event + * @see EntityPlayerSP#onUpdate() */ void onPlayerUpdate(PlayerUpdateEvent event); @@ -63,18 +57,16 @@ public interface IGameEventListener { /** * Runs whenever the client player sends a message to the server. * - * @see EntityPlayerSP#sendChatMessage(String) - * * @param event The event + * @see EntityPlayerSP#sendChatMessage(String) */ void onSendChatMessage(ChatEvent event); /** * Runs before and after whenever a chunk is either loaded, unloaded, or populated. * - * @see WorldClient#doPreChunk(int, int, boolean) - * * @param event The event + * @see WorldClient#doPreChunk(int, int, boolean) */ void onChunkEvent(ChunkEvent event); @@ -90,29 +82,26 @@ public interface IGameEventListener { /** * Runs before and after whenever a new world is loaded * - * @see Minecraft#loadWorld(WorldClient, String) - * * @param event The event + * @see Minecraft#loadWorld(WorldClient, String) */ void onWorldEvent(WorldEvent event); /** * Runs before a outbound packet is sent * + * @param event The event * @see Packet * @see GenericFutureListener - * - * @param event The event */ void onSendPacket(PacketEvent event); /** * Runs before an inbound packet is processed * + * @param event The event * @see Packet * @see GenericFutureListener - * - * @param event The event */ void onReceivePacket(PacketEvent event); @@ -120,9 +109,8 @@ public interface IGameEventListener { * Run once per game tick from before and after the player's moveRelative method is called * and before and after the player jumps. * - * @see Entity#moveRelative(float, float, float, float) - * * @param event The event + * @see Entity#moveRelative(float, float, float, float) */ void onPlayerRotationMove(RotationMoveEvent event); From 44963fa4c793bd726035fb2076c18b6c67554bca Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Dec 2018 22:26:55 -0800 Subject: [PATCH 072/140] diagonal descend --- .../java/baritone/pathing/movement/Moves.java | 40 ++++++----- .../movement/movements/MovementDiagonal.java | 66 ++++++++++++------- 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Moves.java b/src/main/java/baritone/pathing/movement/Moves.java index c5a6ceb6d..c626327e1 100644 --- a/src/main/java/baritone/pathing/movement/Moves.java +++ b/src/main/java/baritone/pathing/movement/Moves.java @@ -220,51 +220,59 @@ public enum Moves { } }, - DIAGONAL_NORTHEAST(+1, 0, -1) { + DIAGONAL_NORTHEAST(+1, 0, -1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST, res.y - src.y); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementDiagonal.cost(context, x, y, z, x + 1, z - 1); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDiagonal.cost(context, x, y, z, x + 1, z - 1, result); } }, - DIAGONAL_NORTHWEST(-1, 0, -1) { + DIAGONAL_NORTHWEST(-1, 0, -1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST, res.y - src.y); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementDiagonal.cost(context, x, y, z, x - 1, z - 1); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDiagonal.cost(context, x, y, z, x - 1, z - 1, result); } }, - DIAGONAL_SOUTHEAST(+1, 0, +1) { + DIAGONAL_SOUTHEAST(+1, 0, +1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST, res.y - src.y); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementDiagonal.cost(context, x, y, z, x + 1, z + 1); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDiagonal.cost(context, x, y, z, x + 1, z + 1, result); } }, - DIAGONAL_SOUTHWEST(-1, 0, +1) { + DIAGONAL_SOUTHWEST(-1, 0, +1, false, true) { @Override public Movement apply0(CalculationContext context, BetterBlockPos src) { - return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST); + MutableMoveResult res = new MutableMoveResult(); + apply(context, src.x, src.y, src.z, res); + return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST, res.y - src.y); } @Override - public double cost(CalculationContext context, int x, int y, int z) { - return MovementDiagonal.cost(context, x, y, z, x - 1, z + 1); + public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) { + MovementDiagonal.cost(context, x, y, z, x - 1, z + 1, result); } }, diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 1426b73bc..f53c58328 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -26,6 +26,7 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; +import baritone.utils.pathing.MutableMoveResult; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -39,13 +40,13 @@ public class MovementDiagonal extends Movement { private static final double SQRT_2 = Math.sqrt(2); - public MovementDiagonal(IBaritone baritone, BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) { - this(baritone, start, start.offset(dir1), start.offset(dir2), dir2); + public MovementDiagonal(IBaritone baritone, BetterBlockPos start, EnumFacing dir1, EnumFacing dir2, int dy) { + this(baritone, start, start.offset(dir1), start.offset(dir2), dir2, dy); // super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()}); } - private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) { - this(baritone, start, dir1.offset(drr2), dir1, dir2); + private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2, int dy) { + this(baritone, start, dir1.offset(drr2).up(dy), dir1, dir2); } private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) { @@ -54,17 +55,26 @@ public class MovementDiagonal extends Movement { @Override protected double calculateCost(CalculationContext context) { - return cost(context, src.x, src.y, src.z, dest.x, dest.z); + MutableMoveResult result = new MutableMoveResult(); + cost(context, src.x, src.y, src.z, dest.x, dest.z, result); + if (result.y != dest.y) { + return COST_INF; // doesn't apply to us, this position is incorrect + } + return result.cost; } - public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { + public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { IBlockState destInto = context.get(destX, y, destZ); if (!MovementHelper.canWalkThrough(context.bsi(), destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi(), destX, y + 1, destZ)) { - return COST_INF; + return; } IBlockState destWalkOn = context.get(destX, y - 1, destZ); + boolean descend = false; if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destWalkOn)) { - return COST_INF; + descend = true; + if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi(), destX, y - 1, destZ, destWalkOn)) { + return; + } } double multiplier = WALK_ONE_BLOCK_COST; // For either possible soul sand, that affects half of our walking @@ -73,18 +83,18 @@ public class MovementDiagonal extends Movement { } Block fromDown = context.get(x, y - 1, z).getBlock(); if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { - return COST_INF; + return; } if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } Block cuttingOver1 = context.get(x, y - 1, destZ).getBlock(); if (cuttingOver1 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver1)) { - return COST_INF; + return; } Block cuttingOver2 = context.get(destX, y - 1, z).getBlock(); if (cuttingOver2 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver2)) { - return COST_INF; + return; } IBlockState pb0 = context.get(x, y, destZ); IBlockState pb2 = context.get(destX, y, z); @@ -93,27 +103,27 @@ public class MovementDiagonal extends Movement { if (optionA != 0 && optionB != 0) { // check these one at a time -- if pb0 and pb2 were nonzero, we already know that (optionA != 0 && optionB != 0) // so no need to check pb1 as well, might as well return early here - return COST_INF; + return; } IBlockState pb1 = context.get(x, y + 1, destZ); optionA += MovementHelper.getMiningDurationTicks(context, x, y + 1, destZ, pb1, true); if (optionA != 0 && optionB != 0) { // same deal, if pb1 makes optionA nonzero and option B already was nonzero, pb3 can't affect the result - return COST_INF; + return; } IBlockState pb3 = context.get(destX, y + 1, z); if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER))) { // at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction - return COST_INF; + return; } optionB += MovementHelper.getMiningDurationTicks(context, destX, y + 1, z, pb3, true); if (optionA != 0 && optionB != 0) { // and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible - return COST_INF; + return; } if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb1.getBlock()) && pb1.getBlock() != Blocks.WATER))) { // and now that option B is fully calculated, see if we can edge around that way - return COST_INF; + return; } boolean water = false; Block startIn = context.getBlock(x, y, z); @@ -128,16 +138,26 @@ public class MovementDiagonal extends Movement { multiplier *= SQRT_2 - 0.001; // TODO tune if (startIn == Blocks.LADDER || startIn == Blocks.VINE) { // edging around doesn't work if doing so would climb a ladder or vine instead of moving sideways - return COST_INF; + return; + } + } else { + // only can sprint if not edging around + if (context.canSprint() && !water) { + // If we aren't edging around anything, and we aren't in water + // We can sprint =D + // Don't check for soul sand, since we can sprint on that too + multiplier *= SPRINT_MULTIPLIER; } } - if (context.canSprint() && !water) { - // If we aren't edging around anything, and we aren't in water - // We can sprint =D - // Don't check for soul sand, since we can sprint on that too - multiplier *= SPRINT_MULTIPLIER; + res.cost = multiplier * SQRT_2; + if (descend) { + res.cost += Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST); + res.y = y - 1; + } else { + res.y = y; } - return multiplier * SQRT_2; + res.x = destX; + res.z = destZ; } @Override From 801727dca6e5e2e0fe271e238c4370ea85eb1317 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 12 Dec 2018 18:14:56 -0800 Subject: [PATCH 073/140] fix parkour failures at height limit on NCP --- src/api/java/baritone/api/Settings.java | 7 +++++++ .../java/baritone/pathing/movement/CalculationContext.java | 6 ++++++ .../pathing/movement/movements/MovementParkour.java | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index fe28da51d..c2d1e3c0b 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -94,6 +94,13 @@ public class Settings { */ public Setting assumeSafeWalk = new Setting<>(false); + /** + * If true, parkour is allowed to make jumps when standing on blocks at the maximum height, so player feet is y=256 + *

+ * Defaults to false because this fails on NCP + */ + public Setting allowJumpAt256 = 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/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index f3b9a2284..5db455c0e 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -55,6 +55,7 @@ public class CalculationContext { private final boolean allowBreak; private final boolean allowParkour; private final boolean allowParkourPlace; + private final boolean allowJumpAt256; private final boolean assumeWalkOnWater; private final int maxFallHeightNoWater; private final int maxFallHeightBucket; @@ -81,6 +82,7 @@ public class CalculationContext { this.allowBreak = Baritone.settings().allowBreak.get(); this.allowParkour = Baritone.settings().allowParkour.get(); this.allowParkourPlace = Baritone.settings().allowParkourPlace.get(); + this.allowJumpAt256 = Baritone.settings().allowJumpAt256.get(); this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.get(); this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); @@ -187,6 +189,10 @@ public class CalculationContext { return allowParkourPlace; } + public boolean allowJumpAt256() { + return allowJumpAt256; + } + public boolean assumeWalkOnWater() { return assumeWalkOnWater; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 2d6e0b2f6..ae87aa06b 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -63,6 +63,9 @@ public class MovementParkour extends Movement { if (!context.allowParkour()) { return; } + if (y == 256 && !context.allowJumpAt256()) { + return; + } int xDiff = dir.getXOffset(); int zDiff = dir.getZOffset(); From d89aa887fb7de50c7336c3a27132cba98f22910b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 13 Dec 2018 14:43:32 -0800 Subject: [PATCH 074/140] add vulnerabilities badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3f2a009b2..66357bfae 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![License](https://img.shields.io/badge/license-LGPL--3.0-green.svg)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade) [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) +[![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) [![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://minecraft.gamepedia.com/1.12.2) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.0.0--hotfix--4-brightgreen.svg)](https://impactdevelopment.github.io/) From 35efd9293b76e9615faa7ca9ed1aae5dabc33597 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 13 Dec 2018 18:22:33 -0600 Subject: [PATCH 075/140] BlockInteractEvent Type clarification --- .../java/baritone/api/event/events/BlockInteractEvent.java | 6 +++--- src/launch/java/baritone/launch/mixins/MixinMinecraft.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/event/events/BlockInteractEvent.java b/src/api/java/baritone/api/event/events/BlockInteractEvent.java index fbdadba19..6508d7397 100644 --- a/src/api/java/baritone/api/event/events/BlockInteractEvent.java +++ b/src/api/java/baritone/api/event/events/BlockInteractEvent.java @@ -20,7 +20,7 @@ package baritone.api.event.events; import net.minecraft.util.math.BlockPos; /** - * Called when the local player interacts with a block, can be either {@link Type#BREAK} or {@link Type#USE}. + * Called when the local player interacts with a block, can be either {@link Type#START_BREAK} or {@link Type#USE}. * * @author Brady * @since 8/22/2018 @@ -59,9 +59,9 @@ public final class BlockInteractEvent { public enum Type { /** - * We're breaking the target block. + * We're starting to break the target block. */ - BREAK, + START_BREAK, /** * We're right clicking on the target block. Either placing or interacting with. diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 12e915745..7e30d9a03 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -164,7 +164,7 @@ public class MixinMinecraft { ) private void onBlockBreak(CallbackInfo ci, BlockPos pos) { // clickMouse is only for the main player - BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK)); + BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.START_BREAK)); } @Inject( From d4947c3c471ec5ab1938b9d2be28f7b7328307b3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 14 Dec 2018 08:30:25 -0800 Subject: [PATCH 076/140] tweak custom goal process logic --- src/main/java/baritone/process/CustomGoalProcess.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index a07e4aa44..1c4e03118 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -52,7 +52,9 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG @Override public void setGoal(Goal goal) { this.goal = goal; - this.state = State.GOAL_SET; + if (this.state == State.NONE) { + this.state = State.GOAL_SET; + } } @Override From 2afdaa1ac94c8acaa749637baaf019223d16bde2 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 14 Dec 2018 18:50:39 -0600 Subject: [PATCH 077/140] Add individual chunk scanning to IWorldScanner --- .../baritone/api/cache/IWorldScanner.java | 15 +++++++ .../java/baritone/cache/WorldScanner.java | 43 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/api/java/baritone/api/cache/IWorldScanner.java b/src/api/java/baritone/api/cache/IWorldScanner.java index 6d6f49efb..caa44cbc6 100644 --- a/src/api/java/baritone/api/cache/IWorldScanner.java +++ b/src/api/java/baritone/api/cache/IWorldScanner.java @@ -20,6 +20,7 @@ package baritone.api.cache; import baritone.api.utils.IPlayerContext; import net.minecraft.block.Block; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import java.util.List; @@ -42,4 +43,18 @@ public interface IWorldScanner { * @return The matching block positions */ List scanChunkRadius(IPlayerContext ctx, List blocks, int max, int yLevelThreshold, int maxSearchRadius); + + /** + * Scans a single chunk for the specified blocks. + * + * @param ctx The {@link IPlayerContext} containing player and world info that the + * scan is based upon + * @param blocks The blocks to scan for + * @param pos The position of the target chunk + * @param max The maximum number of blocks to scan before cutoff + * @param yLevelThreshold If a block is found within this Y level, the current result will be + * returned, if the value is negative, then this condition doesn't apply. + * @return The matching block positions + */ + List scanChunk(IPlayerContext ctx, List blocks, ChunkPos pos, int max, int yLevelThreshold); } diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 1d220188d..30b67ded5 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -23,10 +23,12 @@ 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.util.math.ChunkPos; import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -107,4 +109,45 @@ public enum WorldScanner implements IWorldScanner { searchRadiusSq++; } } + + @Override + public List scanChunk(IPlayerContext ctx, List blocks, ChunkPos pos, int max, int yLevelThreshold) { + if (blocks.isEmpty()) { + return Collections.emptyList(); + } + + ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider(); + Chunk chunk = chunkProvider.getLoadedChunk(pos.x, pos.z); + int playerY = ctx.playerFeet().getY(); + + if (chunk == null || chunk.isEmpty()) { + return Collections.emptyList(); + } + + LinkedList res = new LinkedList<>(); + ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); + 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 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 (blocks.contains(state.getBlock())) { + int yy = yReal | y; + res.add(new BlockPos((pos.x << 4) | x, yy, (pos.z << 4) | z)); + if (res.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { + return res; + } + } + } + } + } + } + return res; + } } From 66da826eab56381c2de9cb3b80b7a30af34dd778 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 15 Dec 2018 22:25:50 -0800 Subject: [PATCH 078/140] fix toxic cloud --- .../java/baritone/cache/WorldScanner.java | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 30b67ded5..3487a0c1a 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -28,6 +28,7 @@ import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -71,33 +72,7 @@ public enum WorldScanner implements IWorldScanner { continue; } 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(); - // 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 (blocks.contains(state.getBlock())) { - int yy = yReal | y; - res.add(new BlockPos(chunkX | x, yy, chunkZ | z)); - if (Math.abs(yy - playerY) < yLevelThreshold) { - foundWithinY = true; - } - } - } - } - } - } + scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY); } } if ((allUnloaded && foundChunks) @@ -125,6 +100,11 @@ public enum WorldScanner implements IWorldScanner { } LinkedList res = new LinkedList<>(); + scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY); + return res; + } + + public void scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List search, Collection result, int max, int yLevelThreshold, int playerY) { ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); for (int y0 = 0; y0 < 16; y0++) { ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; @@ -133,21 +113,22 @@ public enum WorldScanner implements IWorldScanner { } int yReal = y0 << 4; BlockStateContainer bsc = extendedblockstorage.getData(); + // 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 (blocks.contains(state.getBlock())) { + if (search.contains(state.getBlock())) { int yy = yReal | y; - res.add(new BlockPos((pos.x << 4) | x, yy, (pos.z << 4) | z)); - if (res.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { - return res; + result.add(new BlockPos(chunkX | x, yy, chunkZ | z)); + if (result.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { + return; } } } } } } - return res; } } From cc04342358b70c5c5e6aab63b31363387073b920 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 16 Dec 2018 16:26:48 -0800 Subject: [PATCH 079/140] epic performance --- src/main/java/baritone/cache/WorldScanner.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 3487a0c1a..efed8af0f 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -28,9 +28,9 @@ import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; public enum WorldScanner implements IWorldScanner { @@ -42,7 +42,7 @@ public enum WorldScanner implements IWorldScanner { if (blocks.contains(null)) { throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString()); } - LinkedList res = new LinkedList<>(); + ArrayList res = new ArrayList<>(); if (blocks.isEmpty()) { return res; } @@ -99,7 +99,7 @@ public enum WorldScanner implements IWorldScanner { return Collections.emptyList(); } - LinkedList res = new LinkedList<>(); + ArrayList res = new ArrayList<>(); scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY); return res; } From fe4290b2183a9ed87270b112495d6dc64489ecbf Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 16 Dec 2018 20:14:07 -0800 Subject: [PATCH 080/140] little fix --- src/main/java/baritone/process/MineProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 9347dba24..2d5d18bed 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -39,7 +39,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.chunk.EmptyChunk; import java.util.*; import java.util.stream.Collectors; @@ -255,7 +254,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro .distinct() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) + + .filter(pos -> !ctx.bsi().isLoaded(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi(), pos)) From 90d0fb7efbaa9172f9096f6a5a935f025b006801 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 17 Dec 2018 18:27:31 -0800 Subject: [PATCH 081/140] simplify check --- src/main/java/baritone/process/FollowProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 84ab0748d..4c9c12636 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -79,7 +79,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo if (entity.equals(ctx.player())) { return false; } - return ctx.world().loadedEntityList.contains(entity) || ctx.world().playerEntities.contains(entity); + return ctx.world().loadedEntityList.contains(entity); } private void scanWorld() { From a0ab2a8ba7559cc3648a8135c25b18d6de91dfde Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 18 Dec 2018 16:16:32 -0800 Subject: [PATCH 082/140] timing meme --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index bbc0738a8..52837dd83 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -77,12 +77,15 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel int numMovementsConsidered = 0; int numEmptyChunk = 0; boolean favoring = !favored.isEmpty(); + int timeCheckInterval = 1 << 6; int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) { - long now = System.nanoTime() / 1000000L; - if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) { - break; + if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond) + long now = System.nanoTime() / 1000000L; // since nanoTime is slow on windows (takes many microseconds) + if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) { + break; + } } if (slowPath) { try { From 807d6a0cf4fc5207fdde512730c9e02e3e85edab Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 18 Dec 2018 16:22:54 -0800 Subject: [PATCH 083/140] crucial performance optimization --- .../java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java index 6758a30af..33f077b9d 100644 --- a/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java +++ b/src/main/java/baritone/pathing/calc/openset/BinaryHeapOpenSet.java @@ -59,7 +59,7 @@ public final class BinaryHeapOpenSet implements IOpenSet { @Override public final void insert(PathNode value) { if (size >= array.length - 1) { - array = Arrays.copyOf(array, array.length * 2); + array = Arrays.copyOf(array, array.length << 1); } size++; value.heapPosition = size; From 18f5c129a48e873a4ef2d7ed26f19365aa9fd3fc Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 14 Dec 2018 17:24:07 -0600 Subject: [PATCH 084/140] Remove dependency for PlayerControllerMP implementation --- .../baritone/api/utils/IPlayerContext.java | 3 +- .../baritone/api/utils/IPlayerController.java | 43 ++++++++++++++ .../utils/player/PrimaryPlayerContext.java | 5 +- .../utils/player/PrimaryPlayerController.java | 58 +++++++++++++++++++ 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/api/java/baritone/api/utils/IPlayerController.java create mode 100644 src/main/java/baritone/utils/player/PrimaryPlayerController.java diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index cd80a7d99..83040ab52 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -20,7 +20,6 @@ package baritone.api.utils; import baritone.api.cache.IWorldData; import net.minecraft.block.BlockSlab; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -37,7 +36,7 @@ public interface IPlayerContext { EntityPlayerSP player(); - PlayerControllerMP playerController(); + IPlayerController playerController(); World world(); diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java new file mode 100644 index 000000000..bf987a068 --- /dev/null +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -0,0 +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 Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.utils; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameType; + +/** + * @author Brady + * @since 12/14/2018 + */ +public interface IPlayerController { + + boolean clickBlock(BlockPos pos, EnumFacing side); + + boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side); + + void resetBlockRemoving(); + + void setGameType(GameType type); + + GameType getGameType(); + + default double getBlockReachDistance() { + return this.getGameType().isCreative() ? 5.0F : 4.5F; + } +} diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 4247e92bd..05b1f80ae 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -20,6 +20,7 @@ package baritone.utils.player; import baritone.api.BaritoneAPI; import baritone.api.cache.IWorldData; import baritone.api.utils.IPlayerContext; +import baritone.api.utils.IPlayerController; import baritone.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.PlayerControllerMP; @@ -42,8 +43,8 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper { } @Override - public PlayerControllerMP playerController() { - return mc.playerController; + public IPlayerController playerController() { + return PrimaryPlayerController.INSTANCE; } @Override diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java new file mode 100644 index 000000000..750d578cf --- /dev/null +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -0,0 +1,58 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.player; + +import baritone.api.utils.IPlayerController; +import baritone.utils.Helper; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameType; + +/** + * @author Brady + * @since 12/14/2018 + */ +public enum PrimaryPlayerController implements IPlayerController, Helper { + + INSTANCE; + + @Override + public boolean clickBlock(BlockPos pos, EnumFacing side) { + return mc.playerController.clickBlock(pos, side); + } + + @Override + public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) { + return mc.playerController.onPlayerDamageBlock(pos, side); + } + + @Override + public void resetBlockRemoving() { + mc.playerController.resetBlockRemoving(); + } + + @Override + public void setGameType(GameType type) { + mc.playerController.setGameType(type); + } + + @Override + public GameType getGameType() { + return mc.playerController.getCurrentGameType(); + } +} From 764e8d7daa7780e0c02a5f201250c0793203b0dc Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 18 Dec 2018 19:27:45 -0600 Subject: [PATCH 085/140] Add windowClick to IPlayerController --- src/api/java/baritone/api/utils/IPlayerController.java | 5 +++++ .../baritone/utils/player/PrimaryPlayerController.java | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index bf987a068..8ecc7e115 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -17,6 +17,9 @@ package baritone.api.utils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameType; @@ -33,6 +36,8 @@ public interface IPlayerController { void resetBlockRemoving(); + ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player); + void setGameType(GameType type); GameType getGameType(); diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index 750d578cf..fa4ced9df 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -19,6 +19,9 @@ package baritone.utils.player; import baritone.api.utils.IPlayerController; import baritone.utils.Helper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameType; @@ -46,6 +49,11 @@ public enum PrimaryPlayerController implements IPlayerController, Helper { mc.playerController.resetBlockRemoving(); } + @Override + public ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player) { + return mc.playerController.windowClick(windowId, slotId, mouseButton, type, player); + } + @Override public void setGameType(GameType type) { mc.playerController.setGameType(type); From 9703de86d31cdda7a9ef2de083426ab3205798dd Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 15 Dec 2018 12:27:19 -0600 Subject: [PATCH 086/140] Fix NullPointerException --- src/main/java/baritone/utils/BlockBreakHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index d4d03f676..9f5b970df 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -55,7 +55,8 @@ public final class BlockBreakHelper implements Helper { } public void stopBreakingBlock() { - if (playerContext.playerController() != null) { + // The player controller will never be null, but the player can be + if (playerContext.player() != null) { playerContext.playerController().resetBlockRemoving(); } lastBlock = null; From 0ef3386ebf8cfb4a317597a23922115cefbd52b1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 12:47:22 -0800 Subject: [PATCH 087/140] appease codacy --- src/main/java/baritone/behavior/InventoryBehavior.java | 5 +---- src/main/java/baritone/behavior/MemoryBehavior.java | 8 +++----- src/main/java/baritone/cache/ContainerMemory.java | 3 ++- src/main/java/baritone/utils/pathing/Favoring.java | 6 +----- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index b6d7e1bd6..a49cbb7de 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -55,10 +55,7 @@ public class InventoryBehavior extends Behavior { } private void swapWithHotBar(int inInventory, int inHotbar) { - if (inInventory < 9) { - inInventory += 36; - } - ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory, inHotbar, ClickType.SWAP, ctx.player()); + ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player()); } private int firstValidThrowaway() { // TODO offhand idk diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 06627d7e1..34b266b32 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -116,12 +116,10 @@ public final class MemoryBehavior extends Behavior { System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId()); System.out.println(packet.getWindowTitle()); - if (packet.getWindowTitle() instanceof TextComponentTranslation) { + if (packet.getWindowTitle() instanceof TextComponentTranslation && ((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) { // title is not customized (i.e. this isn't just a renamed shulker) - if (((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) { - enderChestWindowId = packet.getWindowId(); - return; - } + enderChestWindowId = packet.getWindowId(); + return; } futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index ae54e157c..f2b69e5c6 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -123,7 +123,8 @@ public class ContainerMemory implements IContainerMemory { return out.array(); } - public static PacketBuffer writeItemStacks(List write, PacketBuffer out) { + public static PacketBuffer writeItemStacks(List write, PacketBuffer out2) { + PacketBuffer out = out2; // avoid reassigning an argument LOL out = new PacketBuffer(out.writeInt(write.size())); for (ItemStack stack : write) { out = out.writeItemStack(stack); diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java index de80f442d..7ffe49ffd 100644 --- a/src/main/java/baritone/utils/pathing/Favoring.java +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -23,16 +23,12 @@ import baritone.api.utils.BetterBlockPos; import baritone.api.utils.IPlayerContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; -import java.util.List; - public final class Favoring { - private List avoidances; private final Long2DoubleOpenHashMap favorings; public Favoring(IPlayerContext ctx, IPath previous) { this(previous); - avoidances = Avoidance.create(ctx); - for (Avoidance avoid : avoidances) { + for (Avoidance avoid : Avoidance.create(ctx)) { avoid.applySpherical(favorings); } System.out.println("Favoring size: " + favorings.size()); From d41aa5f9ae0ab662dc740e11e80f509a8cf12d1e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 12:59:07 -0800 Subject: [PATCH 088/140] epicly fast --- .../java/baritone/pathing/calc/AStarPathFinder.java | 5 +---- src/main/java/baritone/pathing/calc/PathNode.java | 12 +++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 52837dd83..59e52129e 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -55,7 +55,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel startNode.combinedCost = startNode.estimatedCostToGoal; 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]) double[] bestHeuristicSoFar = new double[COEFFICIENTS.length]; for (int i = 0; i < bestHeuristicSoFar.length; i++) { @@ -94,7 +93,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel } } PathNode currentNode = openSet.removeLowest(); - currentNode.isOpen = false; mostRecentConsidered = currentNode; numNodes++; if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { @@ -156,10 +154,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel neighbor.previous = currentNode; neighbor.cost = tentativeCost; neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal; - if (neighbor.isOpen) { + if (neighbor.isOpen()) { openSet.update(neighbor); } else { - neighbor.isOpen = true; openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there } for (int i = 0; i < bestSoFar.length; i++) { diff --git a/src/main/java/baritone/pathing/calc/PathNode.java b/src/main/java/baritone/pathing/calc/PathNode.java index dc2dbf906..2b693338a 100644 --- a/src/main/java/baritone/pathing/calc/PathNode.java +++ b/src/main/java/baritone/pathing/calc/PathNode.java @@ -58,12 +58,6 @@ public final class PathNode { */ public PathNode previous; - /** - * Is this a member of the open set in A*? (only used during pathfinding) - * Instead of doing a costly member check in the open set, cache membership in each node individually too. - */ - public boolean isOpen; - /** * Where is this node in the array flattenization of the binary heap? Needed for decrease-key operations. */ @@ -76,12 +70,16 @@ public final class PathNode { if (Double.isNaN(estimatedCostToGoal)) { throw new IllegalStateException(goal + " calculated implausible heuristic"); } - this.isOpen = false; + this.heapPosition = -1; this.x = x; this.y = y; this.z = z; } + public boolean isOpen() { + return heapPosition != -1; + } + /** * TODO: Possibly reimplement hashCode and equals. They are necessary for this class to function but they could be done better * From 77938a77e8dbbc4266a92fbec7d27399c4a1254c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 14:37:11 -0800 Subject: [PATCH 089/140] add jump penalty --- src/api/java/baritone/api/Settings.java | 5 +++++ .../java/baritone/pathing/movement/CalculationContext.java | 6 ++++++ .../baritone/pathing/movement/movements/MovementAscend.java | 5 ++++- .../pathing/movement/movements/MovementParkour.java | 4 ++-- .../baritone/pathing/movement/movements/MovementPillar.java | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index c2d1e3c0b..8528c9217 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -68,6 +68,11 @@ public class Settings { */ public Setting blockBreakAdditionalPenalty = new Setting<>(2D); + /** + * Additional penalty for hitting the space bar (ascend, pillar, or parkour) beacuse it uses hunger + */ + public Setting jumpPenalty = new Setting<>(2D); + /** * Allow Baritone to fall arbitrary distances and place a water bucket beneath it. * Reliability: questionable. diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 5db455c0e..e81ed6c8e 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -61,6 +61,7 @@ public class CalculationContext { private final int maxFallHeightBucket; private final double waterWalkSpeed; private final double breakBlockAdditionalCost; + private final double jumpPenalty; private final BetterWorldBorder worldBorder; public CalculationContext(IBaritone baritone) { @@ -93,6 +94,7 @@ public class CalculationContext { float mult = depth / 3.0F; this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult; this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.get(); + this.jumpPenalty = Baritone.settings().jumpPenalty.get(); // why cache these things here, why not let the movements just get directly from settings? // because if some movements are calculated one way and others are calculated another way, // then you get a wildly inconsistent path that isn't optimal for either scenario. @@ -212,4 +214,8 @@ public class CalculationContext { public double breakBlockAdditionalCost() { return breakBlockAdditionalCost; } + + public double jumpPenalty() { + return jumpPenalty; + } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 735c94b87..609fb1020 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -115,15 +115,18 @@ public class MovementAscend extends Movement { if (jumpingToBottomSlab) { if (jumpingFromBottomSlab) { walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); // we hit space immediately on entering this action + walk += context.jumpPenalty(); } else { walk = WALK_ONE_BLOCK_COST; // we don't hit space we just walk into the slab } } else { + // jumpingFromBottomSlab must be false if (toPlace.getBlock() == Blocks.SOUL_SAND) { walk = WALK_ONE_OVER_SOUL_SAND_COST; } else { - walk = WALK_ONE_BLOCK_COST; + walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); } + walk += context.jumpPenalty(); } // cracks knuckles diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index ae87aa06b..795693db5 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -115,7 +115,7 @@ public class MovementParkour extends Movement { res.x = x + xDiff * i; res.y = y; res.z = z + zDiff * i; - res.cost = costFromJumpDistance(i); + res.cost = costFromJumpDistance(i) + context.jumpPenalty(); return; } } @@ -145,7 +145,7 @@ public class MovementParkour extends Movement { res.x = destX; res.y = y; res.z = destZ; - res.cost = costFromJumpDistance(4) + context.placeBlockCost(); + res.cost = costFromJumpDistance(4) + context.placeBlockCost() + context.jumpPenalty(); return; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 0e6b023e3..3ca414644 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -112,7 +112,7 @@ public class MovementPillar extends Movement { if (ladder) { return LADDER_UP_ONE_COST + hardness * 5; } else { - return JUMP_ONE_BLOCK_COST + context.placeBlockCost() + hardness; + return JUMP_ONE_BLOCK_COST + context.placeBlockCost() + context.jumpPenalty() + hardness; } } From 57f238de7d6abd5b3e3ab4a39f1b6d1c02dcbfad Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 17:02:09 -0800 Subject: [PATCH 090/140] that was a big screwup --- src/main/java/baritone/process/MineProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 2d5d18bed..1a22b9c05 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -255,7 +255,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> !ctx.bsi().isLoaded(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) + .filter(pos -> !ctx.bsi().worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi(), pos)) From 02478ee8878fbb2e7d81baf905d94ec6233127a8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 21:30:58 -0800 Subject: [PATCH 091/140] wtF --- src/main/java/baritone/cache/WorldScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index efed8af0f..463dd22f7 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -122,7 +122,7 @@ public enum WorldScanner implements IWorldScanner { if (search.contains(state.getBlock())) { int yy = yReal | y; result.add(new BlockPos(chunkX | x, yy, chunkZ | z)); - if (result.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { + if (result.size() >= max && Math.abs(yy - playerY) < yLevelThreshold) { return; } } From ae9ab03e512649f93c55c0ecce934a2b36239ddd Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 19 Dec 2018 22:01:47 -0800 Subject: [PATCH 092/140] walk on water hunger penalty --- src/api/java/baritone/api/Settings.java | 5 +++++ .../java/baritone/pathing/movement/CalculationContext.java | 6 ++++++ .../pathing/movement/movements/MovementDiagonal.java | 2 ++ .../pathing/movement/movements/MovementTraverse.java | 2 ++ 4 files changed, 15 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 8528c9217..59d6c2179 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -73,6 +73,11 @@ public class Settings { */ public Setting jumpPenalty = new Setting<>(2D); + /** + * Walking on water uses up hunger really quick, so penalize it + */ + public Setting walkOnWaterOnePenalty = new Setting<>(5D); + /** * Allow Baritone to fall arbitrary distances and place a water bucket beneath it. * Reliability: questionable. diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index e81ed6c8e..5d6fe81b8 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -62,6 +62,7 @@ public class CalculationContext { private final double waterWalkSpeed; private final double breakBlockAdditionalCost; private final double jumpPenalty; + private final double walkOnWaterOnePenalty; private final BetterWorldBorder worldBorder; public CalculationContext(IBaritone baritone) { @@ -95,6 +96,7 @@ public class CalculationContext { this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult; this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.get(); this.jumpPenalty = Baritone.settings().jumpPenalty.get(); + this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.get(); // why cache these things here, why not let the movements just get directly from settings? // because if some movements are calculated one way and others are calculated another way, // then you get a wildly inconsistent path that isn't optimal for either scenario. @@ -218,4 +220,8 @@ public class CalculationContext { public double jumpPenalty() { return jumpPenalty; } + + public double walkOnWaterOnePenalty() { + return walkOnWaterOnePenalty; + } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index f53c58328..2b1e77af2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -80,6 +80,8 @@ public class MovementDiagonal extends Movement { // For either possible soul sand, that affects half of our walking if (destWalkOn.getBlock() == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; + } else if (destWalkOn.getBlock() == Blocks.WATER) { + multiplier += context.walkOnWaterOnePenalty() * SQRT_2; } Block fromDown = context.get(x, y - 1, z).getBlock(); if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 59720b91c..2edfe78dc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -75,6 +75,8 @@ public class MovementTraverse extends Movement { } else { if (destOn.getBlock() == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; + } else if (destOn.getBlock() == Blocks.WATER) { + WC += context.walkOnWaterOnePenalty(); } if (srcDown == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; From 8a4f48f08d8059190122a9549ab1430e6cfa3ae1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 20 Dec 2018 21:06:56 -0800 Subject: [PATCH 093/140] diagonal descend option --- src/api/java/baritone/api/Settings.java | 13 ++++++++++--- .../pathing/movement/CalculationContext.java | 6 ++++++ .../movement/movements/MovementDiagonal.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 59d6c2179..9df80d2f0 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -111,6 +111,15 @@ public class Settings { */ public Setting allowJumpAt256 = new Setting<>(false); + /** + * Allow descending diagonally + *

+ * Safer than allowParkour yet still slightly unsafe, can make contact with unchecked adjacent blocks, so it's unsafe in the nether. + *

+ * For a generic "take some risks" mode I'd turn on this one, parkour, and parkour place. + */ + public Setting allowDiagonalDescend = new Setting<>(false); + /** * Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.) */ @@ -163,10 +172,8 @@ public class Settings { * metric gets better and better with each block, instead of slightly worse. *

* Finding the optimal path is worth it, so it's the default. - *

- * This value is an expression instead of a literal so that it's exactly equal to SPRINT_ONE_BLOCK_COST defined in ActionCosts.java */ - public Setting costHeuristic = new Setting<>(20 / 5.612); + public Setting costHeuristic = new Setting<>(3.563); // a bunch of obscure internal A* settings that you probably don't want to change /** diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 5d6fe81b8..e2485be77 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -57,6 +57,7 @@ public class CalculationContext { private final boolean allowParkourPlace; private final boolean allowJumpAt256; private final boolean assumeWalkOnWater; + private final boolean allowDiagonalDescend; private final int maxFallHeightNoWater; private final int maxFallHeightBucket; private final double waterWalkSpeed; @@ -86,6 +87,7 @@ public class CalculationContext { this.allowParkourPlace = Baritone.settings().allowParkourPlace.get(); this.allowJumpAt256 = Baritone.settings().allowJumpAt256.get(); this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.get(); + this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.get(); this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get(); this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get(); int depth = EnchantmentHelper.getDepthStriderModifier(player); @@ -201,6 +203,10 @@ public class CalculationContext { return assumeWalkOnWater; } + public boolean allowDiagonalDescend() { + return allowDiagonalDescend; + } + public int maxFallHeightNoWater() { return maxFallHeightNoWater; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 2b1e77af2..3145f2536 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -72,7 +72,7 @@ public class MovementDiagonal extends Movement { boolean descend = false; if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destWalkOn)) { descend = true; - if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi(), destX, y - 1, destZ, destWalkOn)) { + if (!context.allowDiagonalDescend() || !MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi(), destX, y - 1, destZ, destWalkOn)) { return; } } From b9b25e7e6b6be61da1e76bb0df8f5df0c3de88c4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 20 Dec 2018 21:22:18 -0800 Subject: [PATCH 094/140] no more stupid wrapper getters --- .../baritone/gradle/util/MappingType.java | 2 +- .../baritone/gradle/util/ReobfWrapper.java | 2 +- .../baritone/behavior/MemoryBehavior.java | 2 +- .../baritone/behavior/PathingBehavior.java | 4 +- .../pathing/calc/AStarPathFinder.java | 2 +- .../pathing/movement/CalculationContext.java | 134 ++++-------------- .../baritone/pathing/movement/Movement.java | 3 +- .../pathing/movement/MovementHelper.java | 8 +- .../movement/movements/MovementAscend.java | 14 +- .../movement/movements/MovementDescend.java | 18 +-- .../movement/movements/MovementDiagonal.java | 12 +- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementParkour.java | 20 +-- .../movement/movements/MovementPillar.java | 10 +- .../movement/movements/MovementTraverse.java | 27 ++-- .../baritone/pathing/path/PathExecutor.java | 2 +- .../baritone/process/GetToBlockProcess.java | 2 +- .../java/baritone/process/MineProcess.java | 8 +- .../java/baritone/cache/CachedRegionTest.java | 2 +- .../pathing/calc/openset/OpenSetsTest.java | 2 +- .../pathing/goals/GoalGetToBlockTest.java | 2 +- .../pathing/movement/ActionCostsTest.java | 2 +- .../utils/pathing/BetterBlockPosTest.java | 2 +- .../utils/pathing/PathingBlockTypeTest.java | 2 +- 24 files changed, 101 insertions(+), 183 deletions(-) diff --git a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java index 4a6c10ffb..a3be9b49f 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java +++ b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java @@ -26,4 +26,4 @@ public enum MappingType { SEARGE, NOTCH, CUSTOM // forgegradle -} \ No newline at end of file +} diff --git a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java index 92f38a9f9..f752cd946 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java +++ b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java @@ -60,4 +60,4 @@ public class ReobfWrapper { throw new IllegalStateException(ex); } } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 34b266b32..499860185 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -175,7 +175,7 @@ public final class MemoryBehavior extends Behavior { } private BlockPos neighboringConnectedBlock(BlockPos in) { - BlockStateInterface bsi = new CalculationContext(baritone).bsi(); + BlockStateInterface bsi = new CalculationContext(baritone).bsi; Block block = bsi.get0(in).getBlock(); if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) { return null; // other things that have contents, but can be placed adjacent without combining diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 066a47d41..6f0cf32b0 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -433,7 +433,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, Optional path = calcResult.getPath(); if (Baritone.settings().cutoffAtLoadBoundary.get()) { path = path.map(p -> { - IPath result = p.cutoffAtLoadedChunks(context.bsi()); + IPath result = p.cutoffAtLoadedChunks(context.bsi); if (result instanceof CutoffPath) { logDebug("Cutting off path at edge of loaded chunks"); @@ -499,7 +499,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, Goal transformed = goal; if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); - if (context.world().getChunk(pos) instanceof EmptyChunk) { + if (context.world.getChunk(pos) instanceof EmptyChunk) { transformed = new GoalXZ(pos.getX(), pos.getZ()); } } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 59e52129e..6c62925e4 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -63,7 +63,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel } MutableMoveResult res = new MutableMoveResult(); Favoring favored = favoring; - BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); + BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder()); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index e2485be77..725ab569c 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -42,29 +42,29 @@ public class CalculationContext { private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET); - private final IBaritone baritone; - private final EntityPlayerSP player; - private final World world; - private final WorldData worldData; - private final BlockStateInterface bsi; - private final ToolSet toolSet; - private final boolean hasWaterBucket; - private final boolean hasThrowaway; - private final boolean canSprint; - private final double placeBlockCost; - private final boolean allowBreak; - private final boolean allowParkour; - private final boolean allowParkourPlace; - private final boolean allowJumpAt256; - private final boolean assumeWalkOnWater; - private final boolean allowDiagonalDescend; - private final int maxFallHeightNoWater; - private final int maxFallHeightBucket; - private final double waterWalkSpeed; - private final double breakBlockAdditionalCost; - private final double jumpPenalty; - private final double walkOnWaterOnePenalty; - private final BetterWorldBorder worldBorder; + public final IBaritone baritone; + public final EntityPlayerSP player; + public final World world; + public final WorldData worldData; + public final BlockStateInterface bsi; + public final ToolSet toolSet; + public final boolean hasWaterBucket; + public final boolean hasThrowaway; + public final boolean canSprint; + public final double placeBlockCost; + public final boolean allowBreak; + public final boolean allowParkour; + public final boolean allowParkourPlace; + public final boolean allowJumpAt256; + public final boolean assumeWalkOnWater; + public final boolean allowDiagonalDescend; + public final int maxFallHeightNoWater; + public final int maxFallHeightBucket; + public final double waterWalkSpeed; + public final double breakBlockAdditionalCost; + public final double jumpPenalty; + public final double walkOnWaterOnePenalty; + public final BetterWorldBorder worldBorder; public CalculationContext(IBaritone baritone) { this(baritone, false); @@ -126,7 +126,7 @@ public class CalculationContext { } public boolean canPlaceThrowawayAt(int x, int y, int z) { - if (!hasThrowaway()) { // only true if allowPlace is true, see constructor + if (!hasThrowaway) { // only true if allowPlace is true, see constructor return false; } if (isPossiblyProtected(x, y, z)) { @@ -136,7 +136,7 @@ public class CalculationContext { } public boolean canBreakAt(int x, int y, int z) { - if (!allowBreak()) { + if (!allowBreak) { return false; } return !isPossiblyProtected(x, y, z); @@ -146,88 +146,4 @@ public class CalculationContext { // TODO more protection logic here; see #220 return false; } - - public World world() { - return world; - } - - public EntityPlayerSP player() { - return player; - } - - public BlockStateInterface bsi() { - return bsi; - } - - public WorldData worldData() { - return worldData; - } - - public ToolSet getToolSet() { - return toolSet; - } - - public boolean hasWaterBucket() { - return hasWaterBucket; - } - - public boolean hasThrowaway() { - return hasThrowaway; - } - - public boolean canSprint() { - return canSprint; - } - - public double placeBlockCost() { - return placeBlockCost; - } - - public boolean allowBreak() { - return allowBreak; - } - - public boolean allowParkour() { - return allowParkour; - } - - public boolean allowParkourPlace() { - return allowParkourPlace; - } - - public boolean allowJumpAt256() { - return allowJumpAt256; - } - - public boolean assumeWalkOnWater() { - return assumeWalkOnWater; - } - - public boolean allowDiagonalDescend() { - return allowDiagonalDescend; - } - - public int maxFallHeightNoWater() { - return maxFallHeightNoWater; - } - - public int maxFallHeightBucket() { - return maxFallHeightBucket; - } - - public double waterWalkSpeed() { - return waterWalkSpeed; - } - - public double breakBlockAdditionalCost() { - return breakBlockAdditionalCost; - } - - public double jumpPenalty() { - return jumpPenalty; - } - - public double walkOnWaterOnePenalty() { - return walkOnWaterOnePenalty; - } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 38cc329bb..3754d831c 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -26,7 +26,6 @@ import baritone.utils.BlockStateInterface; import net.minecraft.block.BlockLiquid; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; import java.util.ArrayList; import java.util.List; @@ -231,7 +230,7 @@ public abstract class Movement implements IMovement, MovementHelper { } public void checkLoadedChunk(CalculationContext context) { - calculatedWhileLoaded = !(context.world().getChunk(getDest()) instanceof EmptyChunk); + calculatedWhileLoaded = context.bsi.worldContainsLoadedChunk(dest.x, dest.z); } @Override diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 5f9549b83..d07f05e78 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -340,24 +340,24 @@ public interface MovementHelper extends ActionCosts, Helper { static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) { Block block = state.getBlock(); - if (!canWalkThrough(context.bsi(), x, y, z, state)) { + if (!canWalkThrough(context.bsi, x, y, z, state)) { if (!context.canBreakAt(x, y, z)) { return COST_INF; } - if (avoidBreaking(context.bsi(), x, y, z, state)) { + if (avoidBreaking(context.bsi, x, y, z, state)) { return COST_INF; } if (block instanceof BlockLiquid) { 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 strVsBlock = context.getToolSet().getStrVsBlock(state); + double strVsBlock = context.toolSet.getStrVsBlock(state); if (strVsBlock <= 0) { return COST_INF; } double result = m / strVsBlock; - result += context.breakBlockAdditionalCost(); + result += context.breakBlockAdditionalCost; if (includeFalling) { IBlockState above = context.get(x, y + 1, z); if (above.getBlock() instanceof BlockFalling) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 609fb1020..083780ad4 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -59,11 +59,11 @@ public class MovementAscend extends Movement { public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { IBlockState toPlace = context.get(destX, y, destZ); boolean hasToPlace = false; - if (!MovementHelper.canWalkOn(context.bsi(), destX, y, destZ, toPlace)) { + if (!MovementHelper.canWalkOn(context.bsi, destX, y, destZ, toPlace)) { if (!context.canPlaceThrowawayAt(destX, y, destZ)) { return COST_INF; } - if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi())) { + if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi)) { return COST_INF; } for (int i = 0; i < 5; i++) { @@ -73,7 +73,7 @@ public class MovementAscend extends Movement { if (againstX == x && againstZ == z) { // we might be able to backplace now, but it doesn't matter because it will have been broken by the time we'd need to use it continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) { hasToPlace = true; break; } @@ -83,7 +83,7 @@ public class MovementAscend extends Movement { } } IBlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway - if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi(), x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts @@ -115,7 +115,7 @@ public class MovementAscend extends Movement { if (jumpingToBottomSlab) { if (jumpingFromBottomSlab) { walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); // we hit space immediately on entering this action - walk += context.jumpPenalty(); + walk += context.jumpPenalty; } else { walk = WALK_ONE_BLOCK_COST; // we don't hit space we just walk into the slab } @@ -126,7 +126,7 @@ public class MovementAscend extends Movement { } else { walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); } - walk += context.jumpPenalty(); + walk += context.jumpPenalty; } // cracks knuckles @@ -134,7 +134,7 @@ public class MovementAscend extends Movement { double totalCost = 0; totalCost += walk; if (hasToPlace) { - totalCost += context.placeBlockCost(); + totalCost += context.placeBlockCost; } // start with srcUp2 since we already have its state // includeFalling isn't needed because of the falling check above -- if srcUp3 is falling we will have already exited with COST_INF if we'd actually have to break it diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index fc61a1eb5..ba915ac6d 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -93,7 +93,7 @@ public class MovementDescend extends Movement { //C, D, etc determine the length of the fall IBlockState below = context.get(destX, y - 2, destZ); - if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ, below)) { + if (!MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ, below)) { dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res); return; } @@ -122,7 +122,7 @@ public class MovementDescend extends Movement { // and potentially replace the water we're going to fall into return false; } - if (!MovementHelper.canWalkThrough(context.bsi(), destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { + if (!MovementHelper.canWalkThrough(context.bsi, destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { return false; } double costSoFar = 0; @@ -140,13 +140,13 @@ public class MovementDescend extends Movement { if (ontoBlock.getBlock() == Blocks.WATER && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad // however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works) - if (context.assumeWalkOnWater()) { + if (context.assumeWalkOnWater) { return false; // TODO fix } if (MovementHelper.isFlowing(ontoBlock)) { return false; // TODO flowing check required here? } - if (!MovementHelper.canWalkOn(context.bsi(), destX, newY - 1, destZ)) { + if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) { // we could punch right through the water into something else return false; } @@ -168,23 +168,23 @@ public class MovementDescend extends Movement { effectiveStartHeight = newY; continue; } - if (MovementHelper.canWalkThrough(context.bsi(), destX, newY, destZ, ontoBlock)) { + if (MovementHelper.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { continue; } - if (!MovementHelper.canWalkOn(context.bsi(), destX, newY, destZ, ontoBlock)) { + if (!MovementHelper.canWalkOn(context.bsi, destX, newY, destZ, ontoBlock)) { return false; } if (MovementHelper.isBottomSlab(ontoBlock)) { return false; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect } - if (context.hasWaterBucket() && unprotectedFallHeight <= context.maxFallHeightBucket() + 1) { + if (context.hasWaterBucket && unprotectedFallHeight <= context.maxFallHeightBucket + 1) { res.x = destX; res.y = newY + 1;// this is the block we're falling onto, so dest is +1 res.z = destZ; - res.cost = tentativeCost + context.placeBlockCost(); + res.cost = tentativeCost + context.placeBlockCost; return true; } - if (unprotectedFallHeight <= context.maxFallHeightNoWater() + 1) { + if (unprotectedFallHeight <= context.maxFallHeightNoWater + 1) { // fallHeight = 4 means onto.up() is 3 blocks down, which is the max res.x = destX; res.y = newY + 1; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 3145f2536..f2aeebbb4 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -65,14 +65,14 @@ public class MovementDiagonal extends Movement { public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { IBlockState destInto = context.get(destX, y, destZ); - if (!MovementHelper.canWalkThrough(context.bsi(), destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi(), destX, y + 1, destZ)) { + if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) { return; } IBlockState destWalkOn = context.get(destX, y - 1, destZ); boolean descend = false; - if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destWalkOn)) { + if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)) { descend = true; - if (!context.allowDiagonalDescend() || !MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi(), destX, y - 1, destZ, destWalkOn)) { + if (!context.allowDiagonalDescend || !MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi, destX, y - 1, destZ, destWalkOn)) { return; } } @@ -81,7 +81,7 @@ public class MovementDiagonal extends Movement { if (destWalkOn.getBlock() == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } else if (destWalkOn.getBlock() == Blocks.WATER) { - multiplier += context.walkOnWaterOnePenalty() * SQRT_2; + multiplier += context.walkOnWaterOnePenalty * SQRT_2; } Block fromDown = context.get(x, y - 1, z).getBlock(); if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { @@ -133,7 +133,7 @@ public class MovementDiagonal extends Movement { // Ignore previous multiplier // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Not even touching the blocks below - multiplier = context.waterWalkSpeed(); + multiplier = context.waterWalkSpeed; water = true; } if (optionA != 0 || optionB != 0) { @@ -144,7 +144,7 @@ public class MovementDiagonal extends Movement { } } else { // only can sprint if not edging around - if (context.canSprint() && !water) { + if (context.canSprint && !water) { // If we aren't edging around anything, and we aren't in water // We can sprint =D // Don't check for soul sand, since we can sprint on that too diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 2855bcebf..81b257e73 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -48,7 +48,7 @@ public class MovementDownward extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - if (!MovementHelper.canWalkOn(context.bsi(), x, y - 2, z)) { + if (!MovementHelper.canWalkOn(context.bsi, x, y - 2, z)) { return COST_INF; } IBlockState down = context.get(x, y - 1, z); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 795693db5..5bc5b1db5 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -60,10 +60,10 @@ public class MovementParkour extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, EnumFacing dir, MutableMoveResult res) { - if (!context.allowParkour()) { + if (!context.allowParkour) { return; } - if (y == 256 && !context.allowJumpAt256()) { + if (y == 256 && !context.allowJumpAt256) { return; } @@ -74,7 +74,7 @@ public class MovementParkour extends Movement { return; } IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); - if (MovementHelper.canWalkOn(context.bsi(), x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (MovementHelper.canWalkOn(context.bsi, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) // second most common case -- we could just traverse not parkour return; } @@ -98,7 +98,7 @@ public class MovementParkour extends Movement { if (standingOn.getBlock() == Blocks.SOUL_SAND) { maxJump = 2; // 1 block gap } else { - if (context.canSprint()) { + if (context.canSprint) { maxJump = 4; } else { maxJump = 3; @@ -111,18 +111,18 @@ public class MovementParkour extends Movement { return; } } - if (MovementHelper.canWalkOn(context.bsi(), x + xDiff * i, y - 1, z + zDiff * i)) { + if (MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i)) { res.x = x + xDiff * i; res.y = y; res.z = z + zDiff * i; - res.cost = costFromJumpDistance(i) + context.jumpPenalty(); + res.cost = costFromJumpDistance(i) + context.jumpPenalty; return; } } if (maxJump != 4) { return; } - if (!context.allowParkourPlace()) { + if (!context.allowParkourPlace) { return; } int destX = x + 4 * xDiff; @@ -131,7 +131,7 @@ public class MovementParkour extends Movement { return; } IBlockState toReplace = context.get(destX, y - 1, destZ); - if (!MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.bsi())) { + if (!MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.bsi)) { return; } for (int i = 0; i < 5; i++) { @@ -141,11 +141,11 @@ public class MovementParkour extends Movement { if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) { res.x = destX; res.y = y; res.z = destZ; - res.cost = costFromJumpDistance(4) + context.placeBlockCost() + context.jumpPenalty(); + res.cost = costFromJumpDistance(4) + context.placeBlockCost + context.jumpPenalty; return; } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 3ca414644..fafba24a2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -58,7 +58,7 @@ public class MovementPillar extends Movement { return COST_INF; // can't pillar up from a bottom slab onto a non ladder } } - if (from instanceof BlockVine && !hasAgainst(context, x, y, z)) { // TODO this vine can't be climbed, but we could place a pillar still since vines are replacable, no? perhaps the pillar jump would be impossible because of the slowdown actually. + if (from == Blocks.VINE && !hasAgainst(context, x, y, z)) { // TODO this vine can't be climbed, but we could place a pillar still since vines are replacable, no? perhaps the pillar jump would be impossible because of the slowdown actually. return COST_INF; } IBlockState toBreak = context.get(x, y + 2, z); @@ -76,7 +76,7 @@ public class MovementPillar extends Movement { if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) { // we need to place a block where we started to jump on it return COST_INF; } - if (from instanceof BlockLiquid || (fromDown.getBlock() instanceof BlockLiquid && context.assumeWalkOnWater())) { + if (from instanceof BlockLiquid || (fromDown.getBlock() instanceof BlockLiquid && context.assumeWalkOnWater)) { // otherwise, if we're standing in water, we cannot pillar // if we're standing on water and assumeWalkOnWater is true, we cannot pillar // if we're standing on water and assumeWalkOnWater is false, we must have ascended to here, or sneak backplaced, so it is possible to pillar again @@ -112,7 +112,7 @@ public class MovementPillar extends Movement { if (ladder) { return LADDER_UP_ONE_COST + hardness * 5; } else { - return JUMP_ONE_BLOCK_COST + context.placeBlockCost() + context.jumpPenalty() + hardness; + return JUMP_ONE_BLOCK_COST + context.placeBlockCost + context.jumpPenalty + hardness; } } @@ -159,8 +159,8 @@ public class MovementPillar extends Movement { } return state; } - boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; - boolean vine = fromDown.getBlock() instanceof BlockVine; + boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE; + boolean vine = fromDown.getBlock() == Blocks.VINE; Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch)); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 2edfe78dc..84e423589 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -30,7 +30,10 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockDoor; +import net.minecraft.block.BlockFenceGate; +import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; @@ -66,17 +69,17 @@ public class MovementTraverse extends Movement { IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); Block srcDown = context.getBlock(x, y - 1, z); - if (MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { - WC = context.waterWalkSpeed(); + WC = context.waterWalkSpeed; water = true; } else { if (destOn.getBlock() == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } else if (destOn.getBlock() == Blocks.WATER) { - WC += context.walkOnWaterOnePenalty(); + WC += context.walkOnWaterOnePenalty; } if (srcDown == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; @@ -88,7 +91,7 @@ public class MovementTraverse extends Movement { } double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break if (hardness1 == 0 && hardness2 == 0) { - if (!water && context.canSprint()) { + if (!water && context.canSprint) { // If there's nothing in the way, and this isn't water, and we aren't sneak placing // We can sprint =D // Don't check for soul sand, since we can sprint on that too @@ -105,7 +108,7 @@ public class MovementTraverse extends Movement { if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { return COST_INF; } - if (MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.bsi())) { + if (MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.bsi)) { boolean throughWater = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock()); if (MovementHelper.isWater(destOn.getBlock()) && throughWater) { // this happens when assume walk on water is true and this is a traverse in water, which isn't allowed @@ -119,7 +122,7 @@ public class MovementTraverse extends Movement { return COST_INF; } double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break - double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST; + double WC = throughWater ? context.waterWalkSpeed : WALK_ONE_BLOCK_COST; for (int i = 0; i < 5; i++) { int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset(); int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset(); @@ -127,8 +130,8 @@ public class MovementTraverse extends Movement { if (againstX == x && againstZ == z) { // this would be a backplace continue; } - if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, againstY, againstZ)) { // found a side place option - return WC + context.placeBlockCost() + hardness1 + hardness2; + if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) { // found a side place option + return WC + context.placeBlockCost + hardness1 + hardness2; } } // now that we've checked all possible directions to side place, we actually need to backplace @@ -139,7 +142,7 @@ public class MovementTraverse extends Movement { return COST_INF; // this is obviously impossible } WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are sneak backplacing, we are sneaking lol - return WC + context.placeBlockCost() + hardness1 + hardness2; + return WC + context.placeBlockCost + hardness1 + hardness2; } return COST_INF; } @@ -183,7 +186,7 @@ public class MovementTraverse extends Movement { state.setInput(Input.SNEAK, false); Block fd = BlockStateInterface.get(ctx, src.down()).getBlock(); - boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; + boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE; IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]); IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]); @@ -236,7 +239,7 @@ public class MovementTraverse extends Movement { state.setInput(Input.SPRINT, true); } Block destDown = BlockStateInterface.get(ctx, dest.down()).getBlock(); - if (whereAmI.getY() != dest.getY() && ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { + if (whereAmI.getY() != dest.getY() && ladder && (destDown == Blocks.VINE || destDown == Blocks.LADDER)) { new MovementPillar(baritone, dest.down(), dest).updateState(state); // i'm sorry return state; } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0e3e9bea5..ec71ef48e 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -374,7 +374,7 @@ public class PathExecutor implements IPathExecutor, Helper { private void sprintIfRequested() { // first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint - if (!new CalculationContext(behavior.baritone).canSprint()) { + if (!new CalculationContext(behavior.baritone).canSprint) { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); ctx.player().setSprinting(false); return; diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 48883e13b..f3e245da3 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -154,4 +154,4 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } return block == Blocks.CRAFTING_TABLE || block == Blocks.FURNACE || block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST; } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 1a22b9c05..d3883bbbe 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -209,7 +209,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro //long b = System.currentTimeMillis(); for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { - locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2)); + locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2)); } else { uninteresting.add(m); } @@ -248,17 +248,17 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } public static List prune(CalculationContext ctx, List locs2, List mining, int max) { - List dropped = droppedItemsScan(mining, ctx.world()); + List dropped = droppedItemsScan(mining, ctx.world); List locs = locs2 .stream() .distinct() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> !ctx.bsi().worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) + .filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) - .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi(), pos)) + .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi, pos)) .sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().playerFeet()::distanceSq)) .collect(Collectors.toList()); diff --git a/src/test/java/baritone/cache/CachedRegionTest.java b/src/test/java/baritone/cache/CachedRegionTest.java index 19874990c..f33ea1d82 100644 --- a/src/test/java/baritone/cache/CachedRegionTest.java +++ b/src/test/java/baritone/cache/CachedRegionTest.java @@ -44,4 +44,4 @@ public class CachedRegionTest { } } } -} \ No newline at end of file +} diff --git a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java index 8cc0bec73..a12e0b7ae 100644 --- a/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java +++ b/src/test/java/baritone/pathing/calc/openset/OpenSetsTest.java @@ -167,4 +167,4 @@ public class OpenSetsTest { assertTrue(set.isEmpty()); } } -} \ No newline at end of file +} diff --git a/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java index 6234e0505..fdcef8789 100644 --- a/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java +++ b/src/test/java/baritone/pathing/goals/GoalGetToBlockTest.java @@ -47,4 +47,4 @@ public class GoalGetToBlockTest { } assertTrue(acceptableOffsets.toString(), acceptableOffsets.isEmpty()); } -} \ No newline at end of file +} diff --git a/src/test/java/baritone/pathing/movement/ActionCostsTest.java b/src/test/java/baritone/pathing/movement/ActionCostsTest.java index a3108c591..cce61e4b3 100644 --- a/src/test/java/baritone/pathing/movement/ActionCostsTest.java +++ b/src/test/java/baritone/pathing/movement/ActionCostsTest.java @@ -48,4 +48,4 @@ public class ActionCostsTest { return fallDistance; } -} \ No newline at end of file +} diff --git a/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java b/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java index a21f0cd48..1cd4cf913 100644 --- a/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java +++ b/src/test/java/baritone/utils/pathing/BetterBlockPosTest.java @@ -136,4 +136,4 @@ public class BetterBlockPosTest { long after2 = System.nanoTime() / 1000000L; System.out.println((after1 - before1) + " " + (after2 - before2)); } -} \ No newline at end of file +} diff --git a/src/test/java/baritone/utils/pathing/PathingBlockTypeTest.java b/src/test/java/baritone/utils/pathing/PathingBlockTypeTest.java index 1582b66f6..c30b45d11 100644 --- a/src/test/java/baritone/utils/pathing/PathingBlockTypeTest.java +++ b/src/test/java/baritone/utils/pathing/PathingBlockTypeTest.java @@ -29,4 +29,4 @@ public class PathingBlockTypeTest { assertTrue(type == PathingBlockType.fromBits(bits[0], bits[1])); } } -} \ No newline at end of file +} From 4d7e74365b5bfe3f5865f958cc2893d812b2fad0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 21 Dec 2018 17:54:16 -0800 Subject: [PATCH 095/140] reformat --- src/api/java/baritone/api/pathing/calc/IPathFinder.java | 1 - src/api/java/baritone/api/pathing/goals/Goal.java | 2 -- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 7 +++---- .../java/baritone/utils/player/PrimaryPlayerContext.java | 1 - 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/pathing/calc/IPathFinder.java b/src/api/java/baritone/api/pathing/calc/IPathFinder.java index 7f73693fa..ab04b3f2e 100644 --- a/src/api/java/baritone/api/pathing/calc/IPathFinder.java +++ b/src/api/java/baritone/api/pathing/calc/IPathFinder.java @@ -36,7 +36,6 @@ public interface IPathFinder { * * @param primaryTimeout If a path is found, the path finder will stop after this amount of time * @param failureTimeout If a path isn't found, the path finder will continue for this amount of time - * * @return The final path */ PathCalculationResult calculate(long primaryTimeout, long failureTimeout); diff --git a/src/api/java/baritone/api/pathing/goals/Goal.java b/src/api/java/baritone/api/pathing/goals/Goal.java index 1ecf2dfb9..acee68db8 100644 --- a/src/api/java/baritone/api/pathing/goals/Goal.java +++ b/src/api/java/baritone/api/pathing/goals/Goal.java @@ -33,7 +33,6 @@ public interface Goal { * @param x The goal X position * @param y The goal Y position * @param z The goal Z position - * * @return Whether or not it satisfies this goal */ boolean isInGoal(int x, int y, int z); @@ -44,7 +43,6 @@ public interface Goal { * @param x The goal X position * @param y The goal Y position * @param z The goal Z position - * * @return The estimate number of ticks to satisfy the goal */ double heuristic(int x, int y, int z); diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 490ab7a6d..78710204f 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -136,11 +136,10 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * for the node mapped to the specified pos. If no node is found, * a new node is created. * - * @param x The x position of the node - * @param y The y position of the node - * @param z The z position of the node + * @param x The x position of the node + * @param y The y position of the node + * @param z The z position of the node * @param hashCode The hash code of the node, provided by {@link BetterBlockPos#longHash(int, int, int)} - * * @return The associated node * @see Issue #107 */ diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 05b1f80ae..f0d7ee016 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -23,7 +23,6 @@ import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerController; import baritone.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; From 64200030d2689c1a732aed3c8a8c7fed16ce803b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 22 Dec 2018 20:38:44 -0800 Subject: [PATCH 096/140] brady was too optimistic --- src/api/java/baritone/api/utils/Logger.java | 27 --------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/api/java/baritone/api/utils/Logger.java diff --git a/src/api/java/baritone/api/utils/Logger.java b/src/api/java/baritone/api/utils/Logger.java deleted file mode 100644 index c2f6c99ac..000000000 --- a/src/api/java/baritone/api/utils/Logger.java +++ /dev/null @@ -1,27 +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 Lesser 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.utils; - -/** - * @author Brady - * @since 9/23/2018 - */ -public class Logger { - - -} From c4eb6be0fe76ce7c1dbc51432191cb01143c2e22 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 23 Dec 2018 23:09:02 -0800 Subject: [PATCH 097/140] dumb --- .../baritone/pathing/movement/movements/MovementAscend.java | 2 -- 1 file changed, 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 083780ad4..74a2aae4c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -129,8 +129,6 @@ public class MovementAscend extends Movement { walk += context.jumpPenalty; } - // cracks knuckles - double totalCost = 0; totalCost += walk; if (hasToPlace) { From c324f11a96f55c5bd511fdbbfd6c50016cb46bf7 Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 24 Dec 2018 12:15:11 -0600 Subject: [PATCH 098/140] Fix bad block breaking that NCP doesn't agree with --- src/api/java/baritone/api/Settings.java | 4 ---- src/api/java/baritone/api/utils/IPlayerController.java | 2 -- src/main/java/baritone/utils/BlockBreakHelper.java | 10 ---------- .../baritone/utils/player/PrimaryPlayerController.java | 5 ----- 4 files changed, 21 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 9df80d2f0..1b4f62e01 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -452,10 +452,6 @@ public class Settings { /** * {@code true}: can mine blocks when in inventory, chat, or tabbed away in ESC menu - *

- * {@code false}: works on cosmic prisons - *

- * LOL */ public Setting leftClickWorkaround = new Setting<>(true); diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index 8ecc7e115..dd63a41b2 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -30,8 +30,6 @@ import net.minecraft.world.GameType; */ public interface IPlayerController { - boolean clickBlock(BlockPos pos, EnumFacing side); - boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side); void resetBlockRemoving(); diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 9f5b970df..36f31c6de 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -31,11 +31,6 @@ import net.minecraft.util.math.RayTraceResult; */ public final class BlockBreakHelper implements Helper { - /** - * The last block that we tried to break, if this value changes - * between attempts, then we re-initialize the breaking process. - */ - private BlockPos lastBlock; private boolean didBreakLastTick; private IPlayerContext playerContext; @@ -45,13 +40,9 @@ public final class BlockBreakHelper implements Helper { } public void tryBreakBlock(BlockPos pos, EnumFacing side) { - if (!pos.equals(lastBlock)) { - playerContext.playerController().clickBlock(pos, side); - } if (playerContext.playerController().onPlayerDamageBlock(pos, side)) { playerContext.player().swingArm(EnumHand.MAIN_HAND); } - lastBlock = pos; } public void stopBreakingBlock() { @@ -59,7 +50,6 @@ public final class BlockBreakHelper implements Helper { if (playerContext.player() != null) { playerContext.playerController().resetBlockRemoving(); } - lastBlock = null; } private boolean fakeBreak() { diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index fa4ced9df..7b998bb59 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -34,11 +34,6 @@ public enum PrimaryPlayerController implements IPlayerController, Helper { INSTANCE; - @Override - public boolean clickBlock(BlockPos pos, EnumFacing side) { - return mc.playerController.clickBlock(pos, side); - } - @Override public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) { return mc.playerController.onPlayerDamageBlock(pos, side); From bbb73008ac10f02f3b6b59bd6aef3d079cbe71fa Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 24 Dec 2018 18:41:16 -0800 Subject: [PATCH 099/140] stupid --- .../baritone/pathing/movement/movements/MovementAscend.java | 3 +-- 1 file changed, 1 insertion(+), 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 74a2aae4c..9973e94b3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -129,8 +129,7 @@ public class MovementAscend extends Movement { walk += context.jumpPenalty; } - double totalCost = 0; - totalCost += walk; + double totalCost = walk; if (hasToPlace) { totalCost += context.placeBlockCost; } From 50d37bb311224455af8994f7ef7c7b3f3fe23bd8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 25 Dec 2018 20:07:26 -0800 Subject: [PATCH 100/140] lol --- src/main/java/baritone/pathing/movement/Movement.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 3754d831c..b8f7b25e1 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -34,7 +34,6 @@ import java.util.Optional; public abstract class Movement implements IMovement, MovementHelper { - protected static final EnumFacing[] HORIZONTALS = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST}; protected static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; protected final IBaritone baritone; From bebdede33bcf7be3557063247b2e2aa12774b639 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 26 Dec 2018 18:07:14 -1000 Subject: [PATCH 101/140] unneeded --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 66357bfae..6bffdc242 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,6 @@ Here are some links to help to get started: - [Installation](INSTALL.md) -There's also some useful information down below - # Setup ## Command Line From dffbb8e4c8fa97b0e33bad233e7f1f776d2f990f Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 27 Dec 2018 17:15:13 -0600 Subject: [PATCH 102/140] Overload reachable with IPlayerContext parameter --- src/api/java/baritone/api/utils/RotationUtils.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index 0649ff107..9352b7fe9 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -127,6 +127,16 @@ public final class RotationUtils { return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2)); } + /** + * @param ctx Context for the viewing entity + * @param pos The target block position + * @return The optional rotation + * @see #reachable(EntityPlayerSP, BlockPos, double) + */ + public static Optional reachable(IPlayerContext ctx, BlockPos pos) { + return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); + } + /** * Determines if the specified entity is able to reach the center of any of the sides * of the specified block. It first checks if the block center is reachable, and if so, From c2c69f243eb9ac1ce48c1de513ccb7ad50e838ff Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 27 Dec 2018 16:16:12 -1000 Subject: [PATCH 103/140] nothing is trashy in baritone --- src/main/java/baritone/process/FollowProcess.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 4c9c12636..3d25c0765 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -57,7 +57,6 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo } private Goal towards(Entity following) { - // lol this is trashy but it works BlockPos pos; if (Baritone.settings().followOffsetDistance.get() == 0) { pos = new BlockPos(following); From 1da72ba473b8d32b2d478e15de4cd1550b2e6eb3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 28 Dec 2018 17:17:43 -1000 Subject: [PATCH 104/140] unneeded --- src/main/java/baritone/pathing/path/PathExecutor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index ec71ef48e..8d841e465 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -110,7 +110,6 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } - //System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI); if (!Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks if (whereAmI.equals(path.positions().get(i))) { From 258700ee7bca524b2f8f2975bca5415ba9857961 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 29 Dec 2018 14:50:21 -1000 Subject: [PATCH 105/140] bitshift --- src/main/java/baritone/cache/CachedWorld.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index e9caddfe7..fc1e177b0 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -215,7 +215,7 @@ public final class CachedWorld implements ICachedWorld, Helper { if (mostRecentlyModified == null) { return new BlockPos(0, 0, 0); } - return new BlockPos(mostRecentlyModified.x * 16 + 8, 0, mostRecentlyModified.z * 16 + 8); + return new BlockPos(mostRecentlyModified.x << 4 + 8, 0, mostRecentlyModified.z << 4 + 8); } private synchronized List allRegions() { From 539b0e64c868fe5dad08c89f2b3ae47a9e4cda9a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 30 Dec 2018 07:36:10 -1000 Subject: [PATCH 106/140] bitshift 2: electric boogaloo --- src/main/java/baritone/cache/CachedWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index fc1e177b0..b604ce485 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -179,8 +179,8 @@ public final class CachedWorld implements ICachedWorld, Helper { if (region == null) { continue; } - int distX = (region.getX() * 512 + 256) - pruneCenter.getX(); - int distZ = (region.getZ() * 512 + 256) - pruneCenter.getZ(); + int distX = (region.getX() << 9 + 256) - pruneCenter.getX(); + int distZ = (region.getZ() << 9 + 256) - pruneCenter.getZ(); double dist = Math.sqrt(distX * distX + distZ * distZ); if (dist > 1024) { logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); From 0e012adb6c6d95cbd3e89790780a2f99ed4ad932 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 31 Dec 2018 08:00:43 -1000 Subject: [PATCH 107/140] unneeded --- src/main/java/baritone/pathing/movement/Movement.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index b8f7b25e1..40e523c5f 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -125,8 +125,7 @@ public abstract class Movement implements IMovement, MovementHelper { currentState.getTarget().hasToForceRotations())); // TODO: calculate movement inputs from latestState.getGoal().position - // latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE - + currentState.getInputStates().forEach((input, forced) -> { baritone.getInputOverrideHandler().setInputForceState(input, forced); }); From 816727d65b6a45ec35c2f7fa2b32e94c4a91c3e7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 1 Jan 2019 22:32:43 -0800 Subject: [PATCH 108/140] not happening --- src/main/java/baritone/pathing/movement/Movement.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 40e523c5f..dcdcdec7e 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -124,8 +124,6 @@ public abstract class Movement implements IMovement, MovementHelper { rotation, currentState.getTarget().hasToForceRotations())); - // TODO: calculate movement inputs from latestState.getGoal().position - currentState.getInputStates().forEach((input, forced) -> { baritone.getInputOverrideHandler().setInputForceState(input, forced); }); From 83e6b2fdfe19c066dca39c1b9761af99bd553f71 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 2 Jan 2019 21:08:31 -0800 Subject: [PATCH 109/140] cursed --- buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 235b0d31d..351ded3a9 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -208,7 +208,7 @@ public class ProguardTask extends BaritoneGradleTask { Objects.requireNonNull(extension); // for some reason cant use Class.forName - Class class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); + Class class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); // <-- cursed Field f_replacer = class_baseExtension.getDeclaredField("replacer"); f_replacer.setAccessible(true); Object replacer = f_replacer.get(extension); From 39648c5dc6052e94360812fd6052a4a3675c57ba Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 3 Jan 2019 23:40:43 -0800 Subject: [PATCH 110/140] comment --- src/main/java/baritone/utils/PathingControlManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index f5fff5460..1dfdbb579 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -64,8 +64,7 @@ public class PathingControlManager implements IPathingControlManager { command = null; for (IBaritoneProcess proc : processes) { proc.onLostControl(); - if (proc.isActive() && !proc.isTemporary()) { // it's okay for a temporary thing (like combat pause) to maintain control even if you say to cancel - // but not for a non temporary thing + if (proc.isActive() && !proc.isTemporary()) { // it's okay only for a temporary thing (like combat pause) to maintain control even if you say to cancel throw new IllegalStateException(proc.displayName()); } } From 7898b24baced3daf7627c5cb32bf8970ff321016 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 4 Jan 2019 23:37:00 -0800 Subject: [PATCH 111/140] mc is weird --- src/main/java/baritone/utils/ToolSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 880517a06..0aa02afd0 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -180,7 +180,7 @@ public class ToolSet { speed *= 0.09; break; case 2: - speed *= 0.0027; + speed *= 0.0027; // you might think that 0.09*0.3 = 0.027 so that should be next, that would make too much sense. it's 0.0027. break; default: speed *= 0.00081; From 8b6d621d20318b3c69202fc5b4fbcde43f410806 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 5 Jan 2019 23:38:24 -0800 Subject: [PATCH 112/140] crucial performance optimization --- src/main/java/baritone/utils/PathingControlManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 1dfdbb579..79a36695e 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -174,7 +174,7 @@ public class PathingControlManager implements IPathingControlManager { boolean found = false; boolean cancelOthers = false; PathingCommand exec = null; - for (int i = inContention.size() - 1; i >= 0; i--) { // truly a gamer moment + for (int i = inContention.size() - 1; i >= 0; --i) { // truly a gamer moment IBaritoneProcess proc = inContention.get(i); if (found) { if (cancelOthers) { From 76427b8ecb94769da3c5a6261745b5cc7f952732 Mon Sep 17 00:00:00 2001 From: EvilSourcerer <32974335+EvilSourcerer@users.noreply.github.com> Date: Sun, 6 Jan 2019 19:49:58 -0500 Subject: [PATCH 113/140] real gamers use bufferedreader --- src/api/java/baritone/api/utils/SettingsUtil.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 4d13d0274..fc7c3efde 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -23,9 +23,14 @@ import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import java.awt.*; +import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; -import java.util.*; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,9 +42,9 @@ public class SettingsUtil { private static final Map, SettingsIO> map; public static void readAndApply(Settings settings) { - try (Scanner scan = new Scanner(settingsFile)) { - while (scan.hasNextLine()) { - String line = scan.nextLine(); + try (BufferedReader scan = new BufferedReader(new FileReader(settingsFile))) { + String line; + while ((line = scan.readLine()) != null) { if (line.isEmpty()) { continue; } From 712a0a39052ae9a088bfb09e8a04104ef0a8fcbe Mon Sep 17 00:00:00 2001 From: babbaj Date: Mon, 7 Jan 2019 01:08:46 -0500 Subject: [PATCH 114/140] refactor SettingsUtil to be more epic --- .../java/baritone/api/utils/SettingsUtil.java | 66 ++++++++++++------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index fc7c3efde..a9e81383c 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -18,15 +18,18 @@ package baritone.api.utils; import baritone.api.Settings; -import net.minecraft.client.Minecraft; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.function.Consumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import java.awt.*; import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -35,44 +38,57 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import static net.minecraft.client.Minecraft.getMinecraft; + public class SettingsUtil { - private static final File settingsFile = new File(new File(Minecraft.getMinecraft().gameDir, "baritone"), "settings.txt"); + private static final Path settingsFile = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt"); + private static final Pattern SETTING_PATTERN = Pattern.compile("^(?[^ ]+) +(?[^ ]+)");// 2 words separated by spaces private static final Map, SettingsIO> map; - public static void readAndApply(Settings settings) { - try (BufferedReader scan = new BufferedReader(new FileReader(settingsFile))) { + + private static boolean isComment(String line) { + return line.startsWith("#") || line.startsWith("//"); + } + + private static void forEachLine(Path file, Consumer consumer) throws IOException { + try (BufferedReader scan = Files.newBufferedReader(file)) { String line; while ((line = scan.readLine()) != null) { - if (line.isEmpty()) { - continue; + if (line.isEmpty() || isComment(line)) continue; + + consumer.accept(line); + } + } + } + + public void readAndApply(Settings settings) { + try { + forEachLine(settingsFile, line -> { + Matcher matcher = SETTING_PATTERN.matcher(line); + if (!matcher.matches()) { + System.out.println("Invalid syntax in setting file: " + line); + return; } - if (line.startsWith("#") || line.startsWith("//")) { - continue; - } - int space = line.indexOf(" "); - if (space == -1) { - System.out.println("Skipping invalid line with no space: " + line); - continue; - } - String settingName = line.substring(0, space).trim().toLowerCase(); - String settingValue = line.substring(space).trim(); + + String settingName = matcher.group("setting").toLowerCase(); + String settingValue = matcher.group("value").toLowerCase(); try { parseAndApply(settings, settingName, settingValue); } catch (Exception ex) { - ex.printStackTrace(); System.out.println("Unable to parse line " + line); + ex.printStackTrace(); } - } + }); } catch (Exception ex) { - ex.printStackTrace(); System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!"); + ex.printStackTrace(); } } public static synchronized void save(Settings settings) { - try (FileOutputStream out = new FileOutputStream(settingsFile)) { + try (BufferedWriter out = Files.newBufferedWriter(settingsFile)) { for (Settings.Setting setting : settings.allSettings) { if (setting.get() == null) { System.out.println("NULL SETTING?" + setting.getName()); @@ -88,11 +104,11 @@ public class SettingsUtil { if (io == null) { throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting + " " + setting.getName()); } - out.write((setting.getName() + " " + io.toString.apply(setting.get()) + "\n").getBytes()); + out.write(setting.getName() + " " + io.toString.apply(setting.get()) + "\n"); } } catch (Exception ex) { + System.out.println("Exception thrown while saving Baritone settings!"); ex.printStackTrace(); - System.out.println("Exception while saving Baritone settings!"); } } From 227b30366907c8c7ea055f5717606aa0a91b9b3f Mon Sep 17 00:00:00 2001 From: babbaj Date: Mon, 7 Jan 2019 01:16:52 -0500 Subject: [PATCH 115/140] value doesnt have to be lowercase --- src/api/java/baritone/api/utils/SettingsUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index a9e81383c..f71f76146 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -73,7 +73,7 @@ public class SettingsUtil { } String settingName = matcher.group("setting").toLowerCase(); - String settingValue = matcher.group("value").toLowerCase(); + String settingValue = matcher.group("value"); try { parseAndApply(settings, settingName, settingValue); } catch (Exception ex) { From 84b580b00161cc11d63df3c6f26179e2c444ffcc Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 6 Jan 2019 21:04:50 -0800 Subject: [PATCH 116/140] cursed --- src/main/java/baritone/utils/pathing/PathBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/PathBase.java b/src/main/java/baritone/utils/pathing/PathBase.java index 3fbc95ca2..04fe9872c 100644 --- a/src/main/java/baritone/utils/pathing/PathBase.java +++ b/src/main/java/baritone/utils/pathing/PathBase.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.BlockPos; public abstract class PathBase implements IPath { @Override - public PathBase cutoffAtLoadedChunks(Object bsi0) { + public PathBase cutoffAtLoadedChunks(Object bsi0) { // <-- cursed cursed cursed BlockStateInterface bsi = (BlockStateInterface) bsi0; for (int i = 0; i < positions().size(); i++) { BlockPos pos = positions().get(i); From 23dc97ad5e96bcb577228efc89ac98eec2a3dd39 Mon Sep 17 00:00:00 2001 From: babbaj Date: Mon, 7 Jan 2019 01:25:39 -0500 Subject: [PATCH 117/140] oops that should have been static --- src/api/java/baritone/api/utils/SettingsUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index f71f76146..b6623b988 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -63,7 +63,7 @@ public class SettingsUtil { } } - public void readAndApply(Settings settings) { + public static void readAndApply(Settings settings) { try { forEachLine(settingsFile, line -> { Matcher matcher = SETTING_PATTERN.matcher(line); From ee9519d8911464b35203104e96ab74444c3b0907 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 7 Jan 2019 08:53:39 -0800 Subject: [PATCH 118/140] tweaks --- .../java/baritone/api/utils/SettingsUtil.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index b6623b988..07b4cd98d 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -18,23 +18,23 @@ package baritone.api.utils; import baritone.api.Settings; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import java.awt.*; import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -42,12 +42,11 @@ import static net.minecraft.client.Minecraft.getMinecraft; public class SettingsUtil { - private static final Path settingsFile = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt"); - private static final Pattern SETTING_PATTERN = Pattern.compile("^(?[^ ]+) +(?[^ ]+)");// 2 words separated by spaces + private static final Path SETTINGS_PATH = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt"); + private static final Pattern SETTING_PATTERN = Pattern.compile("^(?[^ ]+) +(?[^ ]+)"); // 2 words separated by spaces private static final Map, SettingsIO> map; - private static boolean isComment(String line) { return line.startsWith("#") || line.startsWith("//"); } @@ -56,8 +55,9 @@ public class SettingsUtil { try (BufferedReader scan = Files.newBufferedReader(file)) { String line; while ((line = scan.readLine()) != null) { - if (line.isEmpty() || isComment(line)) continue; - + if (line.isEmpty() || isComment(line)) { + continue; + } consumer.accept(line); } } @@ -65,7 +65,7 @@ public class SettingsUtil { public static void readAndApply(Settings settings) { try { - forEachLine(settingsFile, line -> { + forEachLine(SETTINGS_PATH, line -> { Matcher matcher = SETTING_PATTERN.matcher(line); if (!matcher.matches()) { System.out.println("Invalid syntax in setting file: " + line); @@ -88,7 +88,7 @@ public class SettingsUtil { } public static synchronized void save(Settings settings) { - try (BufferedWriter out = Files.newBufferedWriter(settingsFile)) { + try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) { for (Settings.Setting setting : settings.allSettings) { if (setting.get() == null) { System.out.println("NULL SETTING?" + setting.getName()); From e971d5d43fb14947e4872faaee52aa05ae24692a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Jan 2019 14:56:21 -0800 Subject: [PATCH 119/140] prevent favoring from affecting movement cost thresholds --- src/main/java/baritone/pathing/calc/Path.java | 4 +++- src/main/java/baritone/pathing/movement/Movement.java | 2 +- .../baritone/pathing/movement/movements/MovementAscend.java | 2 +- .../baritone/pathing/movement/movements/MovementDescend.java | 2 +- .../baritone/pathing/movement/movements/MovementDiagonal.java | 2 +- .../baritone/pathing/movement/movements/MovementDownward.java | 2 +- .../baritone/pathing/movement/movements/MovementFall.java | 2 +- .../baritone/pathing/movement/movements/MovementParkour.java | 2 +- .../baritone/pathing/movement/movements/MovementPillar.java | 2 +- .../baritone/pathing/movement/movements/MovementTraverse.java | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 0b5b2cc71..374417438 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -132,7 +132,9 @@ class Path extends PathBase { Movement move = moves.apply0(context, src); if (move.getDest().equals(dest)) { // have to calculate the cost at calculation time so we can accurately judge whether a cost increase happened between cached calculation and real execution - move.override(cost); + // however, taking into account possible favoring that could skew the node cost, we really want the stricter limit of the two + // so we take the minimum of the path node cost difference, and the calculated cost + move.override(Math.min(move.calculateCost(context), cost)); return move; } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index dcdcdec7e..2db8bf8d1 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -84,7 +84,7 @@ public abstract class Movement implements IMovement, MovementHelper { return cost; } - protected abstract double calculateCost(CalculationContext context); + public abstract double calculateCost(CalculationContext context); @Override public double recalculateCost() { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 9973e94b3..2e20dd6e1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -52,7 +52,7 @@ public class MovementAscend extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { return cost(context, src.x, src.y, src.z, dest.x, dest.z); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index ba915ac6d..d2d2c2820 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -52,7 +52,7 @@ public class MovementDescend extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { MutableMoveResult result = new MutableMoveResult(); cost(context, src.x, src.y, src.z, dest.x, dest.z, result); if (result.y != dest.y) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index f2aeebbb4..a47fc2634 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -54,7 +54,7 @@ public class MovementDiagonal extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { MutableMoveResult result = new MutableMoveResult(); cost(context, src.x, src.y, src.z, dest.x, dest.z, result); if (result.y != dest.y) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 81b257e73..2bec8fcf3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -43,7 +43,7 @@ public class MovementDownward extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { return cost(context, src.x, src.y, src.z); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 90b44c14c..6442d7d96 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -54,7 +54,7 @@ public class MovementFall extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { MutableMoveResult result = new MutableMoveResult(); MovementDescend.cost(context, src.x, src.y, src.z, dest.x, dest.z, result); if (result.y != dest.y) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 5bc5b1db5..ab98d3d08 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -166,7 +166,7 @@ public class MovementParkour extends Movement { @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { MutableMoveResult res = new MutableMoveResult(); cost(context, src.x, src.y, src.z, direction, res); if (res.x != dest.x || res.z != dest.z) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index fafba24a2..b236f7e2b 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -42,7 +42,7 @@ public class MovementPillar extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { return cost(context, src.x, src.y, src.z); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 84e423589..0788ff8c8 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -60,7 +60,7 @@ public class MovementTraverse extends Movement { } @Override - protected double calculateCost(CalculationContext context) { + public double calculateCost(CalculationContext context) { return cost(context, src.x, src.y, src.z, dest.x, dest.z); } From bc5982b994eea763495c57e6397a17cc5c55f377 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Jan 2019 20:45:35 -0800 Subject: [PATCH 120/140] fine lol --- src/main/java/baritone/utils/PathingControlManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 79a36695e..f28655e66 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -170,12 +170,11 @@ public class PathingControlManager implements IPathingControlManager { public PathingCommand doTheStuff() { - List inContention = processes.stream().filter(IBaritoneProcess::isActive).sorted(Comparator.comparingDouble(IBaritoneProcess::priority)).collect(Collectors.toList()); + List inContention = processes.stream().filter(IBaritoneProcess::isActive).sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()).collect(Collectors.toList()); boolean found = false; boolean cancelOthers = false; PathingCommand exec = null; - for (int i = inContention.size() - 1; i >= 0; --i) { // truly a gamer moment - IBaritoneProcess proc = inContention.get(i); + for (IBaritoneProcess proc : inContention) { if (found) { if (cancelOthers) { proc.onLostControl(); From ae1e229619704b76f29931615621bcd86089a86b Mon Sep 17 00:00:00 2001 From: babbaj Date: Wed, 9 Jan 2019 05:39:37 -0500 Subject: [PATCH 121/140] fix garbage code --- .../baritone/utils/PathingControlManager.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index f28655e66..327884337 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -26,10 +26,10 @@ import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; +import java.util.stream.Stream; import net.minecraft.util.math.BlockPos; import java.util.*; -import java.util.stream.Collectors; public class PathingControlManager implements IPathingControlManager { private final Baritone baritone; @@ -170,30 +170,30 @@ public class PathingControlManager implements IPathingControlManager { public PathingCommand doTheStuff() { - List inContention = processes.stream().filter(IBaritoneProcess::isActive).sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()).collect(Collectors.toList()); - boolean found = false; - boolean cancelOthers = false; - PathingCommand exec = null; - for (IBaritoneProcess proc : inContention) { - if (found) { - if (cancelOthers) { - proc.onLostControl(); + Stream inContention = processes.stream() + .filter(IBaritoneProcess::isActive) + .sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()); + + + Iterator iterator = inContention.iterator(); + while(iterator.hasNext()) { + IBaritoneProcess proc = iterator.next(); + + PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); + if (exec == null) { + if (proc.isActive()) { + throw new IllegalStateException(proc.displayName() + " returned null PathingCommand"); } + proc.onLostControl(); } else { - exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); - if (exec == null) { - if (proc.isActive()) { - throw new IllegalStateException(proc.displayName()); - } - proc.onLostControl(); - continue; - } - //System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); inControlThisTick = proc; - found = true; - cancelOthers = !proc.isTemporary(); + if (!proc.isTemporary()) { + iterator.forEachRemaining(IBaritoneProcess::onLostControl); + } + + return exec; } } - return exec; + return null; } } From a4495ce80abc80951087a7466cb375f49f8ddb5f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Jan 2019 22:00:33 -0800 Subject: [PATCH 122/140] tweaks --- .../java/baritone/utils/PathingControlManager.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 327884337..d1cb4f614 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -26,10 +26,10 @@ import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; -import java.util.stream.Stream; import net.minecraft.util.math.BlockPos; import java.util.*; +import java.util.stream.Stream; public class PathingControlManager implements IPathingControlManager { private final Baritone baritone; @@ -82,7 +82,7 @@ public class PathingControlManager implements IPathingControlManager { public void preTick() { inControlLastTick = inControlThisTick; - command = doTheStuff(); + command = executeProcesses(); if (command == null) { return; } @@ -169,14 +169,14 @@ public class PathingControlManager implements IPathingControlManager { } - public PathingCommand doTheStuff() { + public PathingCommand executeProcesses() { Stream inContention = processes.stream() - .filter(IBaritoneProcess::isActive) - .sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()); + .filter(IBaritoneProcess::isActive) + .sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()); Iterator iterator = inContention.iterator(); - while(iterator.hasNext()) { + while (iterator.hasNext()) { IBaritoneProcess proc = iterator.next(); PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); @@ -190,7 +190,6 @@ public class PathingControlManager implements IPathingControlManager { if (!proc.isTemporary()) { iterator.forEachRemaining(IBaritoneProcess::onLostControl); } - return exec; } } From fbcae10f961bf289bb826512172cae4fb84bc9db Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 15:13:09 -0800 Subject: [PATCH 123/140] cherry picked fix from builder --- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 6f0cf32b0..8c5fb8a4e 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -499,7 +499,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, Goal transformed = goal; if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); - if (context.world.getChunk(pos) instanceof EmptyChunk) { + if (!context.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ())) { transformed = new GoalXZ(pos.getX(), pos.getZ()); } } From 7d572d748b56362e7702b25206030bfc86f49bae Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 15:13:48 -0800 Subject: [PATCH 124/140] shouldnt be needed actually --- .../java/baritone/pathing/movement/CalculationContext.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 725ab569c..559330389 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -43,7 +43,6 @@ public class CalculationContext { private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET); public final IBaritone baritone; - public final EntityPlayerSP player; public final World world; public final WorldData worldData; public final BlockStateInterface bsi; @@ -72,7 +71,7 @@ public class CalculationContext { public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) { this.baritone = baritone; - this.player = baritone.getPlayerContext().player(); + EntityPlayerSP player = baritone.getPlayerContext().player(); this.world = baritone.getPlayerContext().world(); this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld(); this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO From 85ea21e83b24ac4d290728a5097114bf97e59878 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 18:22:34 -0800 Subject: [PATCH 125/140] epic movement input --- .../baritone/pathing/path/PathExecutor.java | 3 +- .../baritone/utils/InputOverrideHandler.java | 16 +++++- .../baritone/utils/PlayerMovementInput.java | 57 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/main/java/baritone/utils/PlayerMovementInput.java diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 8d841e465..cad144aa0 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -380,7 +380,8 @@ public class PathExecutor implements IPathExecutor, Helper { } // if the movement requested sprinting, then we're done - if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(mc.gameSettings.keyBindSprint)) { + if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) { + behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); if (!ctx.player().isSprinting()) { ctx.player().setSprinting(true); } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index c6e19c157..654ab10e8 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -18,11 +18,14 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.BaritoneAPI; import baritone.api.event.events.TickEvent; import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.input.Input; import baritone.behavior.Behavior; +import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.MovementInputFromOptions; import org.lwjgl.input.Keyboard; import java.util.HashMap; @@ -58,7 +61,13 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri */ @Override public final boolean isInputForcedDown(KeyBinding key) { - return isInputForcedDown(Input.getInputForBind(key)); + Input input = Input.getInputForBind(key); + if (input == null || (input != Input.CLICK_LEFT && input != Input.CLICK_RIGHT)) { + // TODO handle left and right better + // ideally we wouldn't force any keybinds and would do everything directly for real + return false; + } + return isInputForcedDown(input); } /** @@ -114,6 +123,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri } boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); setInputForceState(Input.CLICK_LEFT, stillClick); + if (baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) { + ctx.player().movementInput = new PlayerMovementInput(this); + } else { + ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + } } public BlockBreakHelper getBlockBreakHelper() { diff --git a/src/main/java/baritone/utils/PlayerMovementInput.java b/src/main/java/baritone/utils/PlayerMovementInput.java new file mode 100644 index 000000000..4ffbef2bd --- /dev/null +++ b/src/main/java/baritone/utils/PlayerMovementInput.java @@ -0,0 +1,57 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import baritone.api.utils.input.Input; +import net.minecraft.util.MovementInput; + +public class PlayerMovementInput extends MovementInput { + private final InputOverrideHandler handler; + + public PlayerMovementInput(InputOverrideHandler handler) { + this.handler = handler; + } + + public void updatePlayerMoveState() { + this.moveStrafe = 0.0F; + this.moveForward = 0.0F; + + jump = handler.isInputForcedDown(Input.JUMP); // oppa + + if (this.forwardKeyDown = handler.isInputForcedDown(Input.MOVE_FORWARD)) { + this.moveForward++; + } + + if (this.backKeyDown = handler.isInputForcedDown(Input.MOVE_BACK)) { + this.moveForward--; + } + + if (this.leftKeyDown = handler.isInputForcedDown(Input.MOVE_LEFT)) { + this.moveStrafe++; + } + + if (this.rightKeyDown = handler.isInputForcedDown(Input.MOVE_RIGHT)) { + this.moveStrafe--; + } + + if (this.sneak = handler.isInputForcedDown(Input.SNEAK)) { + this.moveStrafe *= 0.3D; + this.moveForward *= 0.3D; + } + } +} From 5ca214534dba85e8c87c44be851810cfd34794a9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 9 Jan 2019 19:11:53 -0800 Subject: [PATCH 126/140] mouse stuff --- .../listener/AbstractGameEventListener.java | 3 -- .../event/listener/IGameEventListener.java | 5 -- .../api/utils/IInputOverrideHandler.java | 4 +- .../launch/mixins/MixinKeyBinding.java | 27 +++++++++- .../launch/mixins/MixinMinecraft.java | 9 ---- .../java/baritone/event/GameEventHandler.java | 5 -- .../java/baritone/utils/BlockBreakHelper.java | 23 +-------- .../baritone/utils/InputOverrideHandler.java | 51 +++++++++---------- 8 files changed, 50 insertions(+), 77 deletions(-) diff --git a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java index c11f926d8..135c29a75 100644 --- a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -36,9 +36,6 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onPlayerUpdate(PlayerUpdateEvent event) {} - @Override - default void onProcessKeyBinds() {} - @Override default void onSendChatMessage(ChatEvent event) {} diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index 9308ab4c5..0572cbe9e 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -49,11 +49,6 @@ public interface IGameEventListener { */ void onPlayerUpdate(PlayerUpdateEvent event); - /** - * Run once per game tick from before keybinds are processed. - */ - void onProcessKeyBinds(); - /** * Runs whenever the client player sends a message to the server. * diff --git a/src/api/java/baritone/api/utils/IInputOverrideHandler.java b/src/api/java/baritone/api/utils/IInputOverrideHandler.java index 69dbbbebd..03f6e4ddf 100644 --- a/src/api/java/baritone/api/utils/IInputOverrideHandler.java +++ b/src/api/java/baritone/api/utils/IInputOverrideHandler.java @@ -27,9 +27,7 @@ import net.minecraft.client.settings.KeyBinding; */ public interface IInputOverrideHandler extends IBehavior { - default boolean isInputForcedDown(KeyBinding key) { - return isInputForcedDown(Input.getInputForBind(key)); - } + Boolean isInputForcedDown(KeyBinding key); boolean isInputForcedDown(Input input); diff --git a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java index 5859d3c5c..cf8325335 100644 --- a/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java +++ b/src/launch/java/baritone/launch/mixins/MixinKeyBinding.java @@ -18,8 +18,10 @@ package baritone.launch.mixins; import baritone.api.BaritoneAPI; +import baritone.utils.Helper; import net.minecraft.client.settings.KeyBinding; 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.callback.CallbackInfoReturnable; @@ -31,6 +33,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(KeyBinding.class) public class MixinKeyBinding { + @Shadow + public int pressTime; + @Inject( method = "isKeyDown", at = @At("HEAD"), @@ -38,8 +43,26 @@ public class MixinKeyBinding { ) private void isKeyDown(CallbackInfoReturnable cir) { // only the primary baritone forces keys - if (BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) { - cir.setReturnValue(true); + Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this); + if (force != null) { + cir.setReturnValue(force); // :sunglasses: + } + } + + @Inject( + method = "isPressed", + at = @At("HEAD"), + cancellable = true + ) + private void isPressed(CallbackInfoReturnable cir) { + // only the primary baritone forces keys + Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this); + if (force != null && force == false) { // <-- cursed + if (pressTime > 0) { + Helper.HELPER.logDirect("You're trying to press this mouse button but I won't let you"); + pressTime--; + } + cir.setReturnValue(force); // :sunglasses: } } } diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 7e30d9a03..6ee1a79be 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -96,15 +96,6 @@ public class MixinMinecraft { } - @Inject( - method = "processKeyBinds", - at = @At("HEAD") - ) - private void runTickKeyboard(CallbackInfo ci) { - // keyboard input is only the primary baritone - BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onProcessKeyBinds(); - } - @Inject( method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", at = @At("HEAD") diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 9f16283e9..e85c46de1 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -54,11 +54,6 @@ public final class GameEventHandler implements IEventBus, Helper { listeners.forEach(l -> l.onPlayerUpdate(event)); } - @Override - public final void onProcessKeyBinds() { - listeners.forEach(IGameEventListener::onProcessKeyBinds); - } - @Override public final void onSendChatMessage(ChatEvent event) { listeners.forEach(l -> l.onSendChatMessage(event)); diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 36f31c6de..b410e6b37 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -17,8 +17,6 @@ package baritone.utils; -import baritone.Baritone; -import baritone.api.BaritoneAPI; import baritone.api.utils.IPlayerContext; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -52,26 +50,8 @@ public final class BlockBreakHelper implements Helper { } } - private boolean fakeBreak() { - if (playerContext != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()) { - // for a non primary player, we need to fake break always, CLICK_LEFT has no effect - return true; - } - if (!Baritone.settings().leftClickWorkaround.get()) { - // if this setting is false, we CLICK_LEFT regardless of gui status - return false; - } - return mc.currentScreen != null; - } - - public boolean tick(boolean isLeftClick) { - if (!fakeBreak()) { - if (didBreakLastTick) { - stopBreakingBlock(); - } - return isLeftClick; - } + public void tick(boolean isLeftClick) { RayTraceResult trace = playerContext.objectMouseOver(); boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK; @@ -82,6 +62,5 @@ public final class BlockBreakHelper implements Helper { stopBreakingBlock(); didBreakLastTick = false; } - return false; // fakeBreak is true so no matter what we aren't forcing CLICK_LEFT } } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 654ab10e8..93fbe8759 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -25,8 +25,8 @@ import baritone.api.utils.input.Input; import baritone.behavior.Behavior; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.MovementInput; import net.minecraft.util.MovementInputFromOptions; -import org.lwjgl.input.Keyboard; import java.util.HashMap; import java.util.Map; @@ -60,14 +60,18 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri * @return Whether or not it is being forced down */ @Override - public final boolean isInputForcedDown(KeyBinding key) { + public final Boolean isInputForcedDown(KeyBinding key) { Input input = Input.getInputForBind(key); - if (input == null || (input != Input.CLICK_LEFT && input != Input.CLICK_RIGHT)) { - // TODO handle left and right better - // ideally we wouldn't force any keybinds and would do everything directly for real + if (input == null || !inControl()) { + return null; + } + if (input == Input.CLICK_LEFT) { return false; } - return isInputForcedDown(input); + if (input == Input.CLICK_RIGHT) { + return isInputForcedDown(Input.CLICK_RIGHT); + } + return null; } /** @@ -100,36 +104,27 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri this.inputForceStateMap.clear(); } - @Override - public final void onProcessKeyBinds() { - // Simulate the key being held down this tick - for (Input input : Input.values()) { - KeyBinding keyBinding = input.getKeyBinding(); - - if (isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) { - int keyCode = keyBinding.getKeyCode(); - - if (keyCode < Keyboard.KEYBOARD_SIZE) { - KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode); - } - } - } - } - @Override public final void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); - setInputForceState(Input.CLICK_LEFT, stillClick); - if (baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) { - ctx.player().movementInput = new PlayerMovementInput(this); - } else { - ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT)); + + MovementInput desired = inControl() + ? new PlayerMovementInput(this) + : new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings); + + if (ctx.player().movementInput.getClass() != desired.getClass()) { + ctx.player().movementInput = desired; // only set it if it was previously incorrect + // gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol } } + private boolean inControl() { + return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); + } + public BlockBreakHelper getBlockBreakHelper() { return blockBreakHelper; } From 200211c186189a894af299c2627f5ab395c626ce Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 10 Jan 2019 13:52:52 -0800 Subject: [PATCH 127/140] dont continue walking if there is no process in charge --- src/main/java/baritone/utils/PathingControlManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index d1cb4f614..e748042e4 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -82,11 +82,12 @@ public class PathingControlManager implements IPathingControlManager { public void preTick() { inControlLastTick = inControlThisTick; + PathingBehavior p = baritone.getPathingBehavior(); command = executeProcesses(); if (command == null) { + p.cancelSegmentIfSafe(); return; } - PathingBehavior p = baritone.getPathingBehavior(); switch (command.commandType) { case REQUEST_PAUSE: p.requestPause(); From f727e71eaf538f2727ff4d6b2d9fdeab67b37a16 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 10 Jan 2019 19:57:09 -0600 Subject: [PATCH 128/140] Expose IPathingControlManager in IBaritone --- src/api/java/baritone/api/IBaritone.java | 3 +++ src/main/java/baritone/Baritone.java | 1 + 2 files changed, 4 insertions(+) diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index bbff9f9bf..6bdb7d108 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -21,6 +21,7 @@ import baritone.api.behavior.ILookBehavior; import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.event.listener.IEventBus; +import baritone.api.pathing.calc.IPathingControlManager; import baritone.api.process.ICustomGoalProcess; import baritone.api.process.IFollowProcess; import baritone.api.process.IGetToBlockProcess; @@ -64,6 +65,8 @@ public interface IBaritone { */ IWorldProvider getWorldProvider(); + IPathingControlManager getPathingControlManager(); + IInputOverrideHandler getInputOverrideHandler(); ICustomGoalProcess getCustomGoalProcess(); diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 41fa36c50..c3a8e272d 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -129,6 +129,7 @@ public class Baritone implements IBaritone { this.initialized = true; } + @Override public PathingControlManager getPathingControlManager() { return this.pathingControlManager; } From 1ad6a0d5b58ff1f27ab978d684e02728022bf909 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 10 Jan 2019 18:21:02 -0800 Subject: [PATCH 129/140] remove all that crap lol --- .../baritone/pathing/movement/Movement.java | 2 +- .../pathing/movement/MovementState.java | 37 +------------------ 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 2db8bf8d1..ce78c231f 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -127,7 +127,7 @@ public abstract class Movement implements IMovement, MovementHelper { currentState.getInputStates().forEach((input, forced) -> { baritone.getInputOverrideHandler().setInputForceState(input, forced); }); - currentState.getInputStates().replaceAll((input, forced) -> false); + currentState.getInputStates().clear(); // If the current status indicates a completed movement if (currentState.getStatus().isComplete()) { diff --git a/src/main/java/baritone/pathing/movement/MovementState.java b/src/main/java/baritone/pathing/movement/MovementState.java index 4432c5037..73539698a 100644 --- a/src/main/java/baritone/pathing/movement/MovementState.java +++ b/src/main/java/baritone/pathing/movement/MovementState.java @@ -20,7 +20,6 @@ package baritone.pathing.movement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.Rotation; import baritone.api.utils.input.Input; -import net.minecraft.util.math.Vec3d; import java.util.HashMap; import java.util.Map; @@ -29,7 +28,6 @@ import java.util.Optional; public class MovementState { private MovementStatus status; - private MovementTarget goal = new MovementTarget(); private MovementTarget target = new MovementTarget(); private final Map inputState = new HashMap<>(); @@ -42,15 +40,6 @@ public class MovementState { return status; } - public MovementTarget getGoal() { - return this.goal; - } - - public MovementState setGoal(MovementTarget goal) { - this.goal = goal; - return this; - } - public MovementTarget getTarget() { return this.target; } @@ -65,23 +54,12 @@ public class MovementState { return this; } - public boolean getInput(Input input) { - return this.inputState.getOrDefault(input, false); - } - public Map getInputStates() { return this.inputState; } public static class MovementTarget { - /** - * Necessary movement to achieve - *

- * TODO: Decide desiredMovement type - */ - public Vec3d position; - /** * Yaw and pitch angles that must be matched */ @@ -95,27 +73,14 @@ public class MovementState { private boolean forceRotations; public MovementTarget() { - this(null, null, false); - } - - public MovementTarget(Vec3d position) { - this(position, null, false); + this(null, false); } public MovementTarget(Rotation rotation, boolean forceRotations) { - this(null, rotation, forceRotations); - } - - public MovementTarget(Vec3d position, Rotation rotation, boolean forceRotations) { - this.position = position; this.rotation = rotation; this.forceRotations = forceRotations; } - public final Optional getPosition() { - return Optional.ofNullable(this.position); - } - public final Optional getRotation() { return Optional.ofNullable(this.rotation); } From 5f29bb3e7f4a98d8bdbd2b82e317083d8da4c01d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 10 Jan 2019 18:55:55 -0800 Subject: [PATCH 130/140] gotta go fast --- src/main/java/baritone/utils/BlockStateInterface.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index be49c97c9..5f8cac6ad 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -46,6 +46,8 @@ public class BlockStateInterface { private Chunk prev = null; private CachedRegion prevCached = null; + private final boolean useTheRealWorld; + private static final IBlockState AIR = Blocks.AIR.getDefaultState(); public BlockStateInterface(IPlayerContext ctx) { @@ -64,6 +66,7 @@ public class BlockStateInterface { } else { this.loadedChunks = worldLoaded; // this will only be used on the main thread } + this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.get(); if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } @@ -94,7 +97,7 @@ public class BlockStateInterface { return AIR; } - if (!Baritone.settings().pathThroughCachedOnly.get()) { + if (useTheRealWorld) { Chunk cached = prev; // there's great cache locality in block state lookups // generally it's within each movement From 09e94eaa8e55f635bae4fcae0b82d69b224e95b2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 11 Jan 2019 13:02:03 -0800 Subject: [PATCH 131/140] not anymore --- src/main/java/baritone/pathing/movement/CalculationContext.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 559330389..4c3b299d2 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -75,7 +75,6 @@ public class CalculationContext { this.world = baritone.getPlayerContext().world(); this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld(); this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO - // new CalculationContext() needs to happen, can't add an argument (i'll beat you), can we get the world provider from currentlyTicking? this.toolSet = new ToolSet(player); this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false); this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether(); From bec7f9be966196e5498fb1b5d1937cb9aa8a18f2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 11 Jan 2019 13:18:31 -0800 Subject: [PATCH 132/140] this lets proguard optimize out one more double division --- .../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 0788ff8c8..4a87a8a64 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -141,7 +141,7 @@ public class MovementTraverse extends Movement { if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) { return COST_INF; // this is obviously impossible } - WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are sneak backplacing, we are sneaking lol + WC = WC * (SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST);//since we are sneak backplacing, we are sneaking lol return WC + context.placeBlockCost + hardness1 + hardness2; } return COST_INF; From f23630064e3310f9674b25cdced8f9239e2f414d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 12 Jan 2019 22:33:46 -0800 Subject: [PATCH 133/140] reorder --- 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 6c62925e4..70c2419e8 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -125,10 +125,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel if (actionCost <= 0 || Double.isNaN(actionCost)) { throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); } + // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (moves.dynamicXZ && !worldBorder.entirelyContains(res.x, res.z)) { // see issue #218 continue; } - // check destination after verifying it's not COST_INF -- some movements return a static IMPOSSIBLE object with COST_INF and destination being 0,0,0 to avoid allocating a new result for every failed calculation if (!moves.dynamicXZ && (res.x != newX || res.z != newZ)) { throw new IllegalStateException(moves + " " + res.x + " " + newX + " " + res.z + " " + newZ); } From f8681d179d82001dd98b42c1f21a525d6b57b577 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 13 Jan 2019 00:00:52 -0800 Subject: [PATCH 134/140] TODO use nanotime when calc starts on dec 31 --- .../java/baritone/pathing/calc/AStarPathFinder.java | 10 +++++----- 1 file 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 70c2419e8..b32fc99ff 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -64,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel MutableMoveResult res = new MutableMoveResult(); Favoring favored = favoring; BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder()); - long startTime = System.nanoTime() / 1000000L; + long startTime = System.currentTimeMillis(); boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + primaryTimeout + "ms"); @@ -81,7 +81,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) { if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond) - long now = System.nanoTime() / 1000000L; // since nanoTime is slow on windows (takes many microseconds) + long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds) if (now - failureTimeoutTime >= 0 || (!failing && now - primaryTimeoutTime >= 0)) { break; } @@ -96,7 +96,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel mostRecentConsidered = currentNode; numNodes++; if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) { - logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext)); } for (Moves moves : Moves.values()) { @@ -181,7 +181,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel System.out.println(numMovementsConsidered + " movements considered"); System.out.println("Open set size: " + openSet.size()); System.out.println("PathNode map size: " + mapSize()); - System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second"); + 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) { @@ -192,7 +192,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); + logDebug("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 ae3fc14b52a1972febed67ac424e6040ef05e6f6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 14 Jan 2019 19:52:31 -0800 Subject: [PATCH 135/140] refactor name --- src/main/java/baritone/behavior/InventoryBehavior.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index a49cbb7de..8a1ea943c 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -78,7 +78,7 @@ public class InventoryBehavior extends Behavior { continue; } if (klass.isInstance(stack.getItem())) { - double speed = ToolSet.calculateStrVsBlock(stack, against.getDefaultState()); // takes into account enchants + double speed = ToolSet.calculateSpeedVsBlock(stack, against.getDefaultState()); // takes into account enchants if (speed > bestSpeed) { bestSpeed = speed; bestInd = i; diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 0aa02afd0..ab8d2e403 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { IBlockState blockState = b.getDefaultState(); for (byte i = 0; i < 9; i++) { ItemStack itemStack = player.inventory.getStackInSlot(i); - double v = calculateStrVsBlock(itemStack, blockState); + double v = calculateSpeedVsBlock(itemStack, blockState); if (v > value) { value = v; best = i; @@ -128,7 +128,7 @@ public class ToolSet { */ private double getBestDestructionTime(Block b) { ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b)); - return calculateStrVsBlock(stack, b.getDefaultState()); + return calculateSpeedVsBlock(stack, b.getDefaultState()); } /** @@ -138,7 +138,7 @@ public class ToolSet { * @param state the blockstate to be mined * @return how long it would take in ticks */ - public static double calculateStrVsBlock(ItemStack item, IBlockState state) { + public static double calculateSpeedVsBlock(ItemStack item, IBlockState state) { float hardness = state.getBlockHardness(null, null); if (hardness < 0) { return -1; From 9dfcef6356e421c510463989f35d7fad30757584 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 15 Jan 2019 17:21:50 -0800 Subject: [PATCH 136/140] crucial performance optimization --- src/main/java/baritone/utils/ToolSet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index ab8d2e403..fa71a6b0f 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -154,11 +154,10 @@ public class ToolSet { speed /= hardness; if (state.getMaterial().isToolNotRequired() || (!item.isEmpty() && item.canHarvestBlock(state))) { - speed /= 30; + return speed / 30; } else { - speed /= 100; + return speed / 100; } - return speed; } /** From 59320d9b85672f079d3b14ea8a1ed00e67d90fcd Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:37:39 -0600 Subject: [PATCH 137/140] Auto test class javadoc --- src/main/java/baritone/utils/BaritoneAutoTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index 2e4a5706a..b7ae5fbb3 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -32,6 +32,15 @@ import net.minecraft.world.GameType; import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldType; +/** + * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific + * seed, setting a specified goal, and only allowing a certain amount of ticks to pass before the pathing test is + * considered a failure. In order to test locally, docker may be used, or through an IDE: Create a run config which runs + * in a separate directory from the primary one (./run), and set the enrivonmental variable {@code BARITONE_AUTO_TEST} + * to {@code true}. + * + * @author leijurv, Brady + */ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { public static final BaritoneAutoTest INSTANCE = new BaritoneAutoTest(); From db24822d2f908f839a4e1fc2a1808451d19f1045 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:50:15 -0600 Subject: [PATCH 138/140] Fix cursed exception --- src/api/java/baritone/api/utils/PathCalculationResult.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/utils/PathCalculationResult.java b/src/api/java/baritone/api/utils/PathCalculationResult.java index 20aef9de7..a71c31a6b 100644 --- a/src/api/java/baritone/api/utils/PathCalculationResult.java +++ b/src/api/java/baritone/api/utils/PathCalculationResult.java @@ -19,6 +19,7 @@ package baritone.api.utils; import baritone.api.pathing.calc.IPath; +import java.util.Objects; import java.util.Optional; public class PathCalculationResult { @@ -31,11 +32,9 @@ public class PathCalculationResult { } public PathCalculationResult(Type type, IPath path) { + Objects.requireNonNull(type); this.path = path; this.type = type; - if (type == null) { - throw new IllegalArgumentException("come on"); - } } public final Optional getPath() { From 2daedecf9233c07d3dcf415b9ecbe2a8559ac3c4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 16 Jan 2019 17:42:43 -0800 Subject: [PATCH 139/140] maybe fix --- src/main/java/baritone/behavior/MemoryBehavior.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 499860185..696e107d5 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; import baritone.cache.Waypoint; @@ -60,6 +61,14 @@ public final class MemoryBehavior extends Behavior { super(baritone); } + @Override + public synchronized void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + enderChestWindowId = null; + futureInventories.clear(); + } + } + @Override public synchronized void onPlayerUpdate(PlayerUpdateEvent event) { if (event.getState() == EventState.PRE) { From a5b98857673a2753a396ae80e2a55511c1e8bc30 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 17 Jan 2019 12:22:36 -0800 Subject: [PATCH 140/140] not even used --- src/main/java/baritone/utils/BaritoneProcessHelper.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java index 4f3870c5a..c5e13619f 100644 --- a/src/main/java/baritone/utils/BaritoneProcessHelper.java +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -23,16 +23,10 @@ import baritone.api.utils.IPlayerContext; public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper { - public static final double DEFAULT_PRIORITY = 0; - protected final Baritone baritone; protected final IPlayerContext ctx; private final double priority; - public BaritoneProcessHelper(Baritone baritone) { - this(baritone, DEFAULT_PRIORITY); - } - public BaritoneProcessHelper(Baritone baritone, double priority) { this.baritone = baritone; this.ctx = baritone.getPlayerContext();