Skip to content

Commit

Permalink
Only move tools and throwaways when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSharp committed Jul 6, 2023
1 parent 6654476 commit 42f5dea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
40 changes: 0 additions & 40 deletions src/main/java/baritone/behavior/InventoryBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ public void onTick(TickEvent event) {
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 (lastTickRequestedMove != null) {
logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick");
requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]);
Expand Down Expand Up @@ -117,39 +110,6 @@ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) {
return true;
}

private int firstValidThrowaway() { // TODO offhand idk
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
for (int i = 0; i < invy.size(); i++) {
if (Baritone.settings().acceptableThrowawayItems.value.contains(invy.get(i).getItem())) {
return i;
}
}
return -1;
}

private int bestToolAgainst(Block against, Class<? extends ItemTool> cla$$) {
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
int bestInd = -1;
double bestSpeed = -1;
for (int i = 0; i < invy.size(); i++) {
ItemStack stack = invy.get(i);
if (stack.isEmpty()) {
continue;
}
if (Baritone.settings().itemSaver.value && (stack.getItemDamage() + Baritone.settings().itemSaverThreshold.value) >= stack.getMaxDamage() && stack.getMaxDamage() > 1) {
continue;
}
if (cla$$.isInstance(stack.getItem())) {
double speed = ToolSet.calculateSpeedVsBlock(stack, against.getDefaultState()); // takes into account enchants
if (speed > bestSpeed) {
bestSpeed = speed;
bestInd = i;
}
}
}
return bestInd;
}

public boolean hasGenericThrowaway() {
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
if (throwaway(false, stack -> item.equals(stack.getItem()))) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/baritone/pathing/movement/MovementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,12 @@ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) {
*/
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) {
if (Baritone.settings().autoTool.value && !Baritone.settings().assumeExternalAutoTool.value) {
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch);
int slot = ts.getBestSlot(b.getBlock(), preferSilkTouch);
if (slot < 9) {
ctx.player().inventory.currentItem = slot;
} else {
((Baritone) BaritoneAPI.getProvider().getBaritoneForPlayer(ctx.player())).getInventoryBehavior().attemptToPutOnHotbar(slot, s -> false);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/baritone/utils/ToolSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ possible, this lets us make pathing depend on the actual tool to be used (if aut
int lowestCost = Integer.MIN_VALUE;
boolean bestSilkTouch = false;
IBlockState blockState = b.getDefaultState();
for (int i = 0; i < 9; i++) {
int maxSlot = Baritone.settings().allowInventory.value ? 36 : 9;
for (int i = 0; i < maxSlot; i++) {
ItemStack itemStack = player.inventory.getStackInSlot(i);
if (!Baritone.settings().useSwordToMine.value && itemStack.getItem() instanceof ItemSword) {
continue;
Expand Down

0 comments on commit 42f5dea

Please sign in to comment.