From afe211ae238f3ffaddc92d893a5dc0a1e7fd6bf1 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 00:11:10 -0400 Subject: [PATCH 01/10] Pause if GUI open. --- src/main/java/baritone/utils/InputOverrideHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 38a32f515..5eada5998 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -87,6 +87,10 @@ public final void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } + if (ctx.minecraft().screen != null) { + ctx.player().input = new KeyboardInput(ctx.minecraft().options); + return; + } if (isInputForcedDown(Input.CLICK_LEFT)) { setInputForceState(Input.CLICK_RIGHT, false); } From daf958798de02793d06094808d70eaba3ecf3cb9 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 00:15:05 -0400 Subject: [PATCH 02/10] Link to setting. --- src/main/java/baritone/utils/InputOverrideHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 5eada5998..e19067fec 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -87,7 +87,7 @@ public final void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - if (ctx.minecraft().screen != null) { + if (Baritone.settings().inventoryMoveOnlyIfStationary.value && ctx.minecraft().screen != null) { ctx.player().input = new KeyboardInput(ctx.minecraft().options); return; } From e15444058bfce5aa71c2176421b1426b1e804b54 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 13:51:54 -0400 Subject: [PATCH 03/10] Change setting name. --- src/api/java/baritone/api/Settings.java | 4 ++-- src/main/java/baritone/behavior/InventoryBehavior.java | 2 +- src/main/java/baritone/utils/InputOverrideHandler.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 43ace5e31..0c3b7d202 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -98,9 +98,9 @@ public final class Settings { public final Setting ticksBetweenInventoryMoves = new Setting<>(1); /** - * Come to a halt before doing any inventory moves. Intended for anticheat such as 2b2t + * Come to a halt if inventory opens. Intended for anticheat such as 2b2t */ - public final Setting inventoryMoveOnlyIfStationary = new Setting<>(false); + public final Setting stopWhenInventoryOpen = new Setting<>(false); /** * Disable baritone's auto-tool at runtime, but still assume that another mod will provide auto tool functionality diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 43a553d4d..1de377912 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -115,7 +115,7 @@ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { logDebug("Inventory move requested but delaying " + ticksSinceLastInventoryMove + " " + Baritone.settings().ticksBetweenInventoryMoves.value); return false; } - if (Baritone.settings().inventoryMoveOnlyIfStationary.value && !baritone.getInventoryPauserProcess().stationaryForInventoryMove()) { + if (Baritone.settings().stopWhenInventoryOpen.value && !baritone.getInventoryPauserProcess().stationaryForInventoryMove()) { logDebug("Inventory move requested but delaying until stationary"); return false; } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index e19067fec..ed4c0fdc6 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -87,7 +87,7 @@ public final void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - if (Baritone.settings().inventoryMoveOnlyIfStationary.value && ctx.minecraft().screen != null) { + if (Baritone.settings().stopWhenInventoryOpen.value && ctx.minecraft().screen != null) { ctx.player().input = new KeyboardInput(ctx.minecraft().options); return; } From 62f996b52ef9f41765527e8a6bd3ffcc36e1de6e Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 14:56:57 -0400 Subject: [PATCH 04/10] Only move an item if Baritone is following a path, and you need that item. --- .../baritone/behavior/InventoryBehavior.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 1de377912..bde841a01 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -20,6 +20,7 @@ import baritone.Baritone; import baritone.api.event.events.TickEvent; import baritone.api.utils.Helper; +import baritone.pathing.path.PathExecutor; import baritone.utils.ToolSet; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.Direction; @@ -65,16 +66,20 @@ 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, PickaxeItem.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]); + PathExecutor currentPath = baritone.getPathingBehavior().getCurrent(); + if (currentPath != null) { + int throwaway = firstValidThrowaway(); + if (throwaway >= 9 && !currentPath.toPlace().isEmpty()) { // aka there are none on the hotbar, but there are some in main inventory + requestSwapWithHotBar(throwaway, 8); + } + int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class); + if (pick >= 9 && !currentPath.toBreak().isEmpty()) { + requestSwapWithHotBar(pick, 0); + } + if (lastTickRequestedMove != null) { + logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick"); + requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]); + } } } From 11f744e3c0ed74aca616e726d377a370ac2ed98f Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 18:08:14 -0400 Subject: [PATCH 05/10] Prevent tiny chance of overflow. --- src/main/java/baritone/behavior/InventoryBehavior.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index bde841a01..9990cd1d9 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -46,8 +46,8 @@ 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); @@ -65,7 +65,9 @@ public void onTick(TickEvent event) { // we have a crafting table or a chest or something open return; } - ticksSinceLastInventoryMove++; + if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) { + ticksSinceLastInventoryMove++; + } PathExecutor currentPath = baritone.getPathingBehavior().getCurrent(); if (currentPath != null) { int throwaway = firstValidThrowaway(); From f28d0771de51eb2436bd6047ddce9deeed7fe84d Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 18:32:16 -0400 Subject: [PATCH 06/10] Change placing. --- .../java/baritone/behavior/InventoryBehavior.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 9990cd1d9..80060544f 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -46,7 +46,7 @@ public final class InventoryBehavior extends Behavior implements Helper { - private int ticksSinceLastInventoryMove; + private int ticksSinceLastInventoryMove = 0; private int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt public InventoryBehavior(Baritone baritone) { @@ -65,9 +65,6 @@ public void onTick(TickEvent event) { // we have a crafting table or a chest or something open return; } - if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) { - ticksSinceLastInventoryMove++; - } PathExecutor currentPath = baritone.getPathingBehavior().getCurrent(); if (currentPath != null) { int throwaway = firstValidThrowaway(); @@ -87,12 +84,7 @@ public void onTick(TickEvent event) { public boolean attemptToPutOnHotbar(int inMainInvy, Predicate disallowedHotbar) { OptionalInt destination = getTempHotbarSlot(disallowedHotbar); - if (destination.isPresent()) { - if (!requestSwapWithHotBar(inMainInvy, destination.getAsInt())) { - return false; - } - } - return true; + return destination.isEmpty() || requestSwapWithHotBar(inMainInvy, destination.getAsInt()); } public OptionalInt getTempHotbarSlot(Predicate disallowedHotbar) { @@ -120,6 +112,7 @@ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { lastTickRequestedMove = new int[]{inInventory, inHotbar}; if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) { logDebug("Inventory move requested but delaying " + ticksSinceLastInventoryMove + " " + Baritone.settings().ticksBetweenInventoryMoves.value); + ticksSinceLastInventoryMove++; return false; } if (Baritone.settings().stopWhenInventoryOpen.value && !baritone.getInventoryPauserProcess().stationaryForInventoryMove()) { From fa8d96d8edf69aaac46b74b9bad943926921e797 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 23:05:15 -0400 Subject: [PATCH 07/10] Open have open inventory calls. --- .../baritone/behavior/InventoryBehavior.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 80060544f..cde881b76 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -22,9 +22,11 @@ import baritone.api.utils.Helper; import baritone.pathing.path.PathExecutor; import baritone.utils.ToolSet; +import net.minecraft.client.gui.screens.inventory.InventoryScreen; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; +import net.minecraft.network.protocol.game.ServerboundContainerClosePacket; import net.minecraft.world.InteractionHand; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.BlockItem; @@ -48,6 +50,7 @@ public final class InventoryBehavior extends Behavior implements Helper { private int ticksSinceLastInventoryMove = 0; private int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt + private boolean inventoryOpen = false; public InventoryBehavior(Baritone baritone) { super(baritone); @@ -61,10 +64,6 @@ public void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - if (ctx.player().containerMenu != ctx.player().inventoryMenu) { - // we have a crafting table or a chest or something open - return; - } PathExecutor currentPath = baritone.getPathingBehavior().getCurrent(); if (currentPath != null) { int throwaway = firstValidThrowaway(); @@ -109,6 +108,13 @@ public OptionalInt getTempHotbarSlot(Predicate disallowedHotbar) { } private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { + if (!(ctx.minecraft().screen instanceof InventoryScreen)) { + ctx.player().closeContainer(); + } + if (!inventoryOpen) { + ctx.player().sendOpenInventory(); + inventoryOpen = true; + } lastTickRequestedMove = new int[]{inInventory, inHotbar}; if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) { logDebug("Inventory move requested but delaying " + ticksSinceLastInventoryMove + " " + Baritone.settings().ticksBetweenInventoryMoves.value); @@ -122,6 +128,8 @@ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { ctx.playerController().windowClick(ctx.player().inventoryMenu.containerId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player()); ticksSinceLastInventoryMove = 0; lastTickRequestedMove = null; + ctx.player().connection.send(new ServerboundContainerClosePacket(ctx.player().containerMenu.containerId)); + inventoryOpen = false; return true; } @@ -224,11 +232,11 @@ public boolean throwaway(boolean select, Predicate desired, b if (allowInventory) { for (int i = 9; i < 36; i++) { if (desired.test(inv.get(i))) { + boolean success = true; if (select) { - requestSwapWithHotBar(i, 7); - p.getInventory().selected = 7; + success = requestSwapWithHotBar(i, p.getInventory().selected); } - return true; + return success; } } } From 524e5bb05b18edbc0fd3ee022938a1b7788ad499 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Thu, 24 Jul 2025 23:24:38 -0400 Subject: [PATCH 08/10] Bug fix. --- .../baritone/behavior/InventoryBehavior.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index cde881b76..9934f07a9 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -108,12 +108,13 @@ public OptionalInt getTempHotbarSlot(Predicate disallowedHotbar) { } private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { - if (!(ctx.minecraft().screen instanceof InventoryScreen)) { - ctx.player().closeContainer(); - } - if (!inventoryOpen) { - ctx.player().sendOpenInventory(); - inventoryOpen = true; + if (ctx.minecraft().screen == null) { + if (!inventoryOpen) { + ctx.player().sendOpenInventory(); + inventoryOpen = true; + } + } else if (!(ctx.minecraft().screen instanceof InventoryScreen)) { + return false; } lastTickRequestedMove = new int[]{inInventory, inHotbar}; if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) { @@ -128,8 +129,10 @@ private boolean requestSwapWithHotBar(int inInventory, int inHotbar) { ctx.playerController().windowClick(ctx.player().inventoryMenu.containerId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player()); ticksSinceLastInventoryMove = 0; lastTickRequestedMove = null; - ctx.player().connection.send(new ServerboundContainerClosePacket(ctx.player().containerMenu.containerId)); - inventoryOpen = false; + if (inventoryOpen) { + ctx.player().connection.send(new ServerboundContainerClosePacket(ctx.player().containerMenu.containerId)); + inventoryOpen = false; + } return true; } @@ -232,11 +235,10 @@ public boolean throwaway(boolean select, Predicate desired, b if (allowInventory) { for (int i = 9; i < 36; i++) { if (desired.test(inv.get(i))) { - boolean success = true; if (select) { - success = requestSwapWithHotBar(i, p.getInventory().selected); + requestSwapWithHotBar(i, p.getInventory().selected); } - return success; + return true; } } } From 1d33d59f46ca5f092fde3d4eb231255ac7418d49 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Fri, 25 Jul 2025 00:34:24 -0400 Subject: [PATCH 09/10] Deprecate instead of fully remove `inventoryMoveOnlyIfStationary`. --- src/api/java/baritone/api/Settings.java | 7 +++++++ src/api/java/baritone/api/utils/SettingsUtil.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0c3b7d202..145a129fb 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -102,6 +102,13 @@ public final class Settings { */ public final Setting stopWhenInventoryOpen = new Setting<>(false); + /** + * Just here so mods that use the API don't break. Does nothing. + */ + @Deprecated + @JavaOnly + public final Setting inventoryMoveOnlyIfStationary = new Setting<>(false); + /** * Disable baritone's auto-tool at runtime, but still assume that another mod will provide auto tool functionality *

diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 57ba8af90..b147d39b2 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -87,6 +87,10 @@ public static void readAndApply(Settings settings, String settingsName) { if ("allowjumpat256".equals(settingName)) { settingName = "allowjumpatbuildlimit"; } + // TODO also remove soonish + if ("inventoryMoveOnlyIfStationary".equals(settingName)) { + settingName = "stopWhenInventoryOpen"; + } try { parseAndApply(settings, settingName, settingValue); } catch (Exception ex) { From 5ccb0de1000941799feeaaeb25f27bed7744c454 Mon Sep 17 00:00:00 2001 From: Murat65536 Date: Wed, 13 Aug 2025 07:48:24 -0400 Subject: [PATCH 10/10] Only affect inventories. --- src/main/java/baritone/utils/InputOverrideHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index ed4c0fdc6..05f8ae323 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -23,6 +23,7 @@ import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.input.Input; import baritone.behavior.Behavior; +import net.minecraft.client.gui.screens.inventory.InventoryScreen; import net.minecraft.client.player.KeyboardInput; import java.util.HashMap; @@ -87,7 +88,7 @@ public final void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { return; } - if (Baritone.settings().stopWhenInventoryOpen.value && ctx.minecraft().screen != null) { + if (Baritone.settings().stopWhenInventoryOpen.value && ctx.minecraft().screen instanceof InventoryScreen) { ctx.player().input = new KeyboardInput(ctx.minecraft().options); return; }