Skip to content

Commit b25a630

Browse files
committed
Don't bother testing reachability for far away blocks
This is a massive performance improvement for big farms.
1 parent 98e90e7 commit b25a630

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main/java/baritone/process/FarmProcess.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
256256
}
257257

258258
baritone.getInputOverrideHandler().clearAllKeys();
259+
BetterBlockPos playerPos = ctx.playerFeet();
260+
double blockReachDistance = ctx.playerController().getBlockReachDistance();
259261
for (BlockPos pos : toBreak) {
262+
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
263+
continue;
264+
}
260265
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
261266
if (rot.isPresent() && isSafeToCancel) {
262267
baritone.getLookBehavior().updateTarget(rot.get(), true);
@@ -270,10 +275,13 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
270275
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
271276
both.addAll(openSoulsand);
272277
for (BlockPos pos : both) {
278+
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
279+
continue;
280+
}
273281
boolean soulsand = openSoulsand.contains(pos);
274-
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
282+
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), blockReachDistance, false);
275283
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
276-
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
284+
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
277285
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == Direction.UP) {
278286
baritone.getLookBehavior().updateTarget(rot.get(), true);
279287
if (ctx.isLookingAt(pos)) {
@@ -284,14 +292,17 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
284292
}
285293
}
286294
for (BlockPos pos : openLog) {
295+
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
296+
continue;
297+
}
287298
for (Direction dir : Direction.Plane.HORIZONTAL) {
288299
if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) {
289300
continue;
290301
}
291302
Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5));
292-
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false);
303+
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, blockReachDistance, false);
293304
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
294-
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
305+
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
295306
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == dir) {
296307
baritone.getLookBehavior().updateTarget(rot.get(), true);
297308
if (ctx.isLookingAt(pos)) {
@@ -303,6 +314,9 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
303314
}
304315
}
305316
for (BlockPos pos : bonemealable) {
317+
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
318+
continue;
319+
}
306320
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
307321
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
308322
baritone.getLookBehavior().updateTarget(rot.get(), true);

0 commit comments

Comments
 (0)