Skip to content

Commit

Permalink
Use a list of placements instead of one. Which means we place blocks …
Browse files Browse the repository at this point in the history
…faster.

Use a list of placements instead of one. Which means we place blocks faster.
  • Loading branch information
Redhawk18 committed Sep 19, 2024
1 parent f6045b7 commit b0c2fcb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 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 @@ -1503,6 +1503,11 @@ public final class Settings {
*/
public final Setting<Boolean> elytraChatSpam = new Setting<>(false);

/**
* The max amount of blocks baritone can place at once in a burst speed, not a constant speed.
*/
public final Setting<Integer> placementLimit = new Setting<>(3);

/**
* A map of lowercase setting field names to their respective setting
*/
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/baritone/process/BuilderProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ public Placement(int hotbarSelection, BlockPos placeAgainst, Direction side, Rot
}
}

private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<BlockState> desirableOnHotbar) {
private Optional<List<Placement>> searchForPlacables(BuilderCalculationContext bcc, List<BlockState> desirableOnHotbar) {
ArrayList<Placement> list = new ArrayList<>();

BetterBlockPos center = ctx.playerFeet();
for (int dx = -5; dx <= 5; dx++) {
for (int dy = -5; dy <= 1; dy++) {
Expand All @@ -344,13 +346,14 @@ private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, Li
}
desirableOnHotbar.add(desired);
Optional<Placement> opt = possibleToPlace(desired, x, y, z, bcc.bsi);
if (opt.isPresent()) {
return opt;
}
opt.ifPresent(list::add);
}

if (list.size() == Baritone.settings().placementLimit.value) return Optional.of(list);
}
}
}
if (!list.isEmpty()) return Optional.of(list);
return Optional.empty();
}

Expand Down Expand Up @@ -561,14 +564,20 @@ public int lengthZ() {
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<BlockState> desirableOnHotbar = new ArrayList<>();
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
Optional<List<Placement>> toPlace = searchForPlacables(bcc, desirableOnHotbar);
if (toPlace.isPresent() && isSafeToCancel && ctx.player().isOnGround() && ticks <= 0) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().getInventory().selected = toPlace.get().hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ((BlockHitResult) ctx.objectMouseOver()).getDirection().equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
logDebug("We have " + toPlace.get().size() + " placement options right now");
for (Placement placement : toPlace.get()) {
Rotation rot = placement.rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().getInventory().selected = placement.hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(placement.placeAgainst) &&
((BlockHitResult) ctx.objectMouseOver()).getDirection().equals(placement.side))
|| ctx.playerRotations().isReallyCloseTo(rot)
) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
Expand Down

0 comments on commit b0c2fcb

Please sign in to comment.