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

Improve InventoryBehavior #4037

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public final class Settings {
*/
public final Setting<Boolean> allowInventory = new Setting<>(false);

/**
* Allow Baritone to automatically put useful items (such as tools and throwaway blocks) on the hotbar while
* pathing. Having this setting enabled implies {@link #allowInventory}.
*/
public final Setting<Boolean> allowHotbarManagement = new Setting<>(false);
ZeroMemes marked this conversation as resolved.
Show resolved Hide resolved

/**
* Wait this many ticks between InventoryBehavior moving inventory items
*/
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/baritone/behavior/InventoryBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,40 @@

public final class InventoryBehavior extends Behavior implements Helper {

int ticksSinceLastInventoryMove;
int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt
private int ticksSinceLastInventoryMove;
private int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt

public InventoryBehavior(Baritone baritone) {
super(baritone);
}

@Override
public void onTick(TickEvent event) {
if (!this.canAccessInventory()) {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
if (event.getType() == TickEvent.Type.OUT) {
ticksSinceLastInventoryMove++;

// TODO: Move these checks into "requestSwapWithHotBar" or whatever supersedes it
if (!this.canAccessInventory()) {
return;
}
if (ctx.player().openContainer != ctx.player().inventoryContainer) {
// we have a crafting table or a chest or something open
return;
}
ticksSinceLastInventoryMove++;
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
requestSwapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class);
if (pick >= 9) {
requestSwapWithHotBar(pick, 0);

if (Baritone.settings().allowHotbarManagement.value && baritone.getPathingBehavior().isPathing()) {
// TODO: Some way of indicating which slots are currently reserved by this setting
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
requestSwapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class);
if (pick >= 9) {
requestSwapWithHotBar(pick, 0);
}
}

if (lastTickRequestedMove != null) {
logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick");
requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]);
Expand Down Expand Up @@ -225,7 +232,7 @@ public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
}

public boolean canAccessInventory() {
return Baritone.settings().allowInventory.value;
return Baritone.settings().allowInventory.value || Baritone.settings().allowHotbarManagement.value;
}

public boolean isThrowawayItem(ItemStack stack) {
Expand Down