simple inventory management
This commit is contained in:
parent
efe06264bd
commit
c15dac3582
@ -50,6 +50,11 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public Setting<Boolean> allowPlace = new Setting<>(true);
|
public Setting<Boolean> allowPlace = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow Baritone to move items in your inventory to your hotbar
|
||||||
|
*/
|
||||||
|
public Setting<Boolean> allowInventory = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It doesn't actually take twenty ticks to place a block, this cost is so high
|
* It doesn't actually take twenty ticks to place a block, this cost is so high
|
||||||
* because we want to generally conserve blocks which might be limited
|
* because we want to generally conserve blocks which might be limited
|
||||||
|
@ -22,10 +22,7 @@ import baritone.api.IBaritone;
|
|||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.*;
|
||||||
import baritone.behavior.LookBehavior;
|
|
||||||
import baritone.behavior.MemoryBehavior;
|
|
||||||
import baritone.behavior.PathingBehavior;
|
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.event.GameEventHandler;
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.process.CustomGoalProcess;
|
import baritone.process.CustomGoalProcess;
|
||||||
@ -110,6 +107,7 @@ public class Baritone implements IBaritone {
|
|||||||
pathingBehavior = new PathingBehavior(this);
|
pathingBehavior = new PathingBehavior(this);
|
||||||
lookBehavior = new LookBehavior(this);
|
lookBehavior = new LookBehavior(this);
|
||||||
memoryBehavior = new MemoryBehavior(this);
|
memoryBehavior = new MemoryBehavior(this);
|
||||||
|
new InventoryBehavior(this);
|
||||||
inputOverrideHandler = new InputOverrideHandler(this);
|
inputOverrideHandler = new InputOverrideHandler(this);
|
||||||
new ExampleBaritoneControl(this);
|
new ExampleBaritoneControl(this);
|
||||||
}
|
}
|
||||||
|
98
src/main/java/baritone/behavior/InventoryBehavior.java
Normal file
98
src/main/java/baritone/behavior/InventoryBehavior.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.behavior;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.event.events.TickEvent;
|
||||||
|
import baritone.utils.ToolSet;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.inventory.ClickType;
|
||||||
|
import net.minecraft.item.ItemPickaxe;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.ItemTool;
|
||||||
|
import net.minecraft.util.NonNullList;
|
||||||
|
|
||||||
|
public class InventoryBehavior extends Behavior {
|
||||||
|
public InventoryBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick(TickEvent event) {
|
||||||
|
if (!Baritone.settings().allowInventory.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiInventory)) {
|
||||||
|
// we have chat or a chest or something open
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
|
||||||
|
swapWithHotBar(firstValidThrowaway(), 8);
|
||||||
|
}
|
||||||
|
int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class);
|
||||||
|
if (pick >= 9) {
|
||||||
|
swapWithHotBar(pick, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void swapWithHotBar(int inInventory, int inHotbar) {
|
||||||
|
int windowId = ctx.player().inventoryContainer.windowId;
|
||||||
|
// aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
// aaaaaaaaAAAAAAaaaaaAAaaaAAAAaaAAA
|
||||||
|
if (inInventory < 9) {
|
||||||
|
inInventory += 36;
|
||||||
|
}
|
||||||
|
ctx.playerController().windowClick(windowId, inInventory, inHotbar, ClickType.SWAP, ctx.player());
|
||||||
|
}
|
||||||
|
|
||||||
|
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.get().contains(invy.get(i).getItem())) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int bestToolAgainst(Block against, Class<? extends ItemTool> klass) {
|
||||||
|
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 (klass.isInstance(stack.getItem())) {
|
||||||
|
double speed = ToolSet.calculateStrVsBlock(stack, against.getDefaultState()); // takes into account enchants
|
||||||
|
if (speed > bestSpeed) {
|
||||||
|
bestSpeed = speed;
|
||||||
|
bestInd = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestInd;
|
||||||
|
}
|
||||||
|
}
|
@ -138,7 +138,7 @@ public class ToolSet {
|
|||||||
* @param state the blockstate to be mined
|
* @param state the blockstate to be mined
|
||||||
* @return how long it would take in ticks
|
* @return how long it would take in ticks
|
||||||
*/
|
*/
|
||||||
private double calculateStrVsBlock(ItemStack item, IBlockState state) {
|
public static double calculateStrVsBlock(ItemStack item, IBlockState state) {
|
||||||
float hardness = state.getBlockHardness(null, null);
|
float hardness = state.getBlockHardness(null, null);
|
||||||
if (hardness < 0) {
|
if (hardness < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user