Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a list of placements instead of one. (faster builder) #4471

Open
wants to merge 1 commit into
base: 1.19.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use a list of placements instead of one. Which means we place blocks …
…faster.

Use a list of placements instead of one. Which means we place blocks faster.
Redhawk18 committed Sep 19, 2024
commit b0c2fcbe7c604ccbc515990a308267d504601b7c
5 changes: 5 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
@@ -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
*/
31 changes: 20 additions & 11 deletions src/main/java/baritone/process/BuilderProcess.java
Original file line number Diff line number Diff line change
@@ -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++) {
@@ -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();
}

@@ -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);
}