mine quantity
This commit is contained in:
parent
42e179c4ce
commit
71952410eb
@ -33,13 +33,12 @@ import baritone.utils.BlockStateInterface;
|
|||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,6 +52,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
|
|
||||||
private List<Block> mining;
|
private List<Block> mining;
|
||||||
private List<BlockPos> locationsCache;
|
private List<BlockPos> locationsCache;
|
||||||
|
private int quantity;
|
||||||
|
|
||||||
private MineBehavior() {}
|
private MineBehavior() {}
|
||||||
|
|
||||||
@ -61,6 +61,16 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
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();
|
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
||||||
if (mineGoalUpdateInterval != 0) {
|
if (mineGoalUpdateInterval != 0) {
|
||||||
if (event.getCount() % mineGoalUpdateInterval == 0) {
|
if (event.getCount() % mineGoalUpdateInterval == 0) {
|
||||||
@ -93,6 +103,8 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
locationsCache = locs;
|
locationsCache = locs;
|
||||||
PathingBehavior.INSTANCE.setGoal(coalesce(locs));
|
PathingBehavior.INSTANCE.setGoal(coalesce(locs));
|
||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
|
|
||||||
|
Blocks.DIAMOND_ORE.getItemDropped(Blocks.DIAMOND_ORE.getDefaultState(), new Random(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GoalComposite coalesce(List<BlockPos> locs) {
|
public static GoalComposite coalesce(List<BlockPos> locs) {
|
||||||
@ -157,8 +169,9 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
return locs;
|
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.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
||||||
|
this.quantity = quantity;
|
||||||
this.locationsCache = new ArrayList<>();
|
this.locationsCache = new ArrayList<>();
|
||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
@ -170,7 +183,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
mine((String[]) null);
|
mine(0, (String[]) null);
|
||||||
PathingBehavior.INSTANCE.cancel();
|
PathingBehavior.INSTANCE.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,14 +289,23 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
if (msg.startsWith("mine")) {
|
if (msg.startsWith("mine")) {
|
||||||
String[] blockTypes = msg.substring(4).trim().split(" ");
|
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) {
|
for (String s : blockTypes) {
|
||||||
if (ChunkPacker.stringToBlock(s) == null) {
|
if (ChunkPacker.stringToBlock(s) == null) {
|
||||||
logDirect(s + " isn't a valid block name");
|
logDirect(s + " isn't a valid block name");
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
MineBehavior.INSTANCE.mine(blockTypes);
|
MineBehavior.INSTANCE.mine(0, blockTypes);
|
||||||
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user