From 71952410eb072a8dea888b7391de832d472e8b52 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 17 Sep 2018 14:22:45 -0700 Subject: [PATCH] mine quantity --- .../java/baritone/behavior/MineBehavior.java | 25 ++++++++++++++----- .../utils/ExampleBaritoneControl.java | 11 +++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/behavior/MineBehavior.java b/src/main/java/baritone/behavior/MineBehavior.java index 8b6fa2a1..115232b6 100644 --- a/src/main/java/baritone/behavior/MineBehavior.java +++ b/src/main/java/baritone/behavior/MineBehavior.java @@ -33,13 +33,12 @@ import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -53,6 +52,7 @@ public final class MineBehavior extends Behavior implements Helper { private List mining; private List locationsCache; + private int quantity; private MineBehavior() {} @@ -61,6 +61,16 @@ public final class MineBehavior extends Behavior implements Helper { if (mining == null) { return; } + if (quantity > 0) { + Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0); + int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum(); + System.out.println("Currently have " + curr + " " + item); + if (curr >= quantity) { + logDirect("Have " + curr + " " + item.getItemStackDisplayName(new ItemStack(item, 1))); + cancel(); + return; + } + } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0) { if (event.getCount() % mineGoalUpdateInterval == 0) { @@ -93,6 +103,8 @@ public final class MineBehavior extends Behavior implements Helper { locationsCache = locs; PathingBehavior.INSTANCE.setGoal(coalesce(locs)); PathingBehavior.INSTANCE.path(); + + Blocks.DIAMOND_ORE.getItemDropped(Blocks.DIAMOND_ORE.getDefaultState(), new Random(), 0); } public static GoalComposite coalesce(List locs) { @@ -157,8 +169,9 @@ public final class MineBehavior extends Behavior implements Helper { return locs; } - public void mine(String... blocks) { + public void mine(int quantity, String... blocks) { this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList()); + this.quantity = quantity; this.locationsCache = new ArrayList<>(); updateGoal(); } @@ -170,7 +183,7 @@ public final class MineBehavior extends Behavior implements Helper { } public void cancel() { - mine((String[]) null); + mine(0, (String[]) null); PathingBehavior.INSTANCE.cancel(); } } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 7bbd8c82..47660631 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -289,14 +289,23 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } if (msg.startsWith("mine")) { String[] blockTypes = msg.substring(4).trim().split(" "); + try { + int quantity = Integer.parseInt(blockTypes[1]); + ChunkPacker.stringToBlock(blockTypes[0]).hashCode(); + MineBehavior.INSTANCE.mine(quantity, blockTypes[0]); + logDirect("Will mine " + quantity + " " + blockTypes[0]); + event.cancel(); + return; + } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {} for (String s : blockTypes) { if (ChunkPacker.stringToBlock(s) == null) { logDirect(s + " isn't a valid block name"); event.cancel(); return; } + } - MineBehavior.INSTANCE.mine(blockTypes); + MineBehavior.INSTANCE.mine(0, blockTypes); logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); event.cancel(); return;