Skip to content

Commit

Permalink
Merge pull request #4385 from ZacSharp/pr/1.19.4/farm/unhardcodeScanL…
Browse files Browse the repository at this point in the history
…imit

Unhardcode farm scan limit
  • Loading branch information
leijurv committed Jun 20, 2024
2 parents b184141 + b25a630 commit 64639b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,11 @@ public final class Settings {
*/
public final Setting<Boolean> replantNetherWart = new Setting<>(false);

/**
* Farming will scan for at most this many blocks.
*/
public final Setting<Integer> farmMaxScanSize = new Setting<>(256);

/**
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
* <p>
Expand Down
54 changes: 38 additions & 16 deletions src/main/java/baritone/process/FarmProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ private boolean isCocoa(ItemStack stack) {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
ArrayList<Block> scan = new ArrayList<>();
for (Harvest harvest : Harvest.values()) {
scan.add(harvest.block);
}
if (Baritone.settings().replantCrops.value) {
scan.add(Blocks.FARMLAND);
scan.add(Blocks.JUNGLE_LOG);
if (Baritone.settings().replantNetherWart.value) {
scan.add(Blocks.SOUL_SAND);
if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
ArrayList<Block> scan = new ArrayList<>();
for (Harvest harvest : Harvest.values()) {
scan.add(harvest.block);
}
if (Baritone.settings().replantCrops.value) {
scan.add(Blocks.FARMLAND);
scan.add(Blocks.JUNGLE_LOG);
if (Baritone.settings().replantNetherWart.value) {
scan.add(Blocks.SOUL_SAND);
}
}
}

if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10));
Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, Baritone.settings().farmMaxScanSize.value, 10, 10));
}
if (locations == null) {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
Expand Down Expand Up @@ -256,7 +256,12 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}

baritone.getInputOverrideHandler().clearAllKeys();
BetterBlockPos playerPos = ctx.playerFeet();
double blockReachDistance = ctx.playerController().getBlockReachDistance();
for (BlockPos pos : toBreak) {
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
continue;
}
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
if (rot.isPresent() && isSafeToCancel) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
Expand All @@ -270,10 +275,13 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
both.addAll(openSoulsand);
for (BlockPos pos : both) {
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
continue;
}
boolean soulsand = openSoulsand.contains(pos);
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), blockReachDistance, false);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == Direction.UP) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
Expand All @@ -284,14 +292,17 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
}
for (BlockPos pos : openLog) {
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
continue;
}
for (Direction dir : Direction.Plane.HORIZONTAL) {
if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) {
continue;
}
Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5));
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false);
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, blockReachDistance, false);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance);
if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == dir) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
Expand All @@ -303,6 +314,9 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
}
for (BlockPos pos : bonemealable) {
if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) {
continue;
}
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
Expand Down Expand Up @@ -359,6 +373,14 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
}
}
if (goalz.isEmpty()) {
logDirect("Farm failed");
if (Baritone.settings().notificationOnFarmFail.value) {
logNotification("Farm failed", true);
}
onLostControl();
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH);
}

Expand Down

0 comments on commit 64639b3

Please sign in to comment.