builder with multiple materials
This commit is contained in:
parent
261d02e67b
commit
e2cdd6a7f9
@ -21,15 +21,15 @@ import baritone.Baritone;
|
|||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.utils.ToolSet;
|
import baritone.utils.ToolSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.ClickType;
|
import net.minecraft.inventory.ClickType;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.*;
|
||||||
import net.minecraft.item.ItemPickaxe;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.ItemTool;
|
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class InventoryBehavior extends Behavior {
|
public class InventoryBehavior extends Behavior {
|
||||||
public InventoryBehavior(Baritone baritone) {
|
public InventoryBehavior(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone);
|
||||||
@ -92,7 +92,7 @@ public class InventoryBehavior extends Behavior {
|
|||||||
|
|
||||||
public boolean hasGenericThrowaway() {
|
public boolean hasGenericThrowaway() {
|
||||||
for (Item item : Baritone.settings().acceptableThrowawayItems.get()) {
|
for (Item item : Baritone.settings().acceptableThrowawayItems.get()) {
|
||||||
if (throwaway(false, item)) {
|
if (throwaway(false, item::equals)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,19 +100,19 @@ public class InventoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean selectThrowawayForLocation(int x, int y, int z) {
|
public boolean selectThrowawayForLocation(int x, int y, int z) {
|
||||||
Item maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
||||||
if (maybe != null && throwaway(true, maybe)) {
|
if (maybe != null && throwaway(true, item -> item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(maybe.getBlock()))) {
|
||||||
return true; // gotem
|
return true; // gotem
|
||||||
}
|
}
|
||||||
for (Item item : Baritone.settings().acceptableThrowawayItems.get()) {
|
for (Item item : Baritone.settings().acceptableThrowawayItems.get()) {
|
||||||
if (throwaway(true, item)) {
|
if (throwaway(true, item::equals)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean throwaway(boolean select, Item desired) {
|
private boolean throwaway(boolean select, Predicate<? super Item> desired) {
|
||||||
EntityPlayerSP p = ctx.player();
|
EntityPlayerSP p = ctx.player();
|
||||||
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
||||||
for (byte i = 0; i < 9; i++) {
|
for (byte i = 0; i < 9; i++) {
|
||||||
@ -122,14 +122,14 @@ public class InventoryBehavior extends Behavior {
|
|||||||
// and then it's called during execution
|
// and then it's called during execution
|
||||||
// since this function is never called during cost calculation, we don't need to migrate
|
// since this function is never called during cost calculation, we don't need to migrate
|
||||||
// acceptableThrowawayItems to the CalculationContext
|
// acceptableThrowawayItems to the CalculationContext
|
||||||
if (desired.equals(item.getItem())) {
|
if (desired.test(item.getItem())) {
|
||||||
if (select) {
|
if (select) {
|
||||||
p.inventory.currentItem = i;
|
p.inventory.currentItem = i;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desired.equals(p.inventory.offHandInventory.get(0).getItem())) {
|
if (desired.test(p.inventory.offHandInventory.get(0).getItem())) {
|
||||||
// main hand takes precedence over off hand
|
// main hand takes precedence over off hand
|
||||||
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
|
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
|
||||||
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
|
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
|
||||||
|
@ -37,7 +37,6 @@ import baritone.utils.Schematic;
|
|||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
@ -94,7 +93,7 @@ public class BuilderProcess extends BaritoneProcessHelper {
|
|||||||
return schematic != null;
|
return schematic != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item placeAt(int x, int y, int z) {
|
public IBlockState placeAt(int x, int y, int z) {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -105,7 +104,7 @@ public class BuilderProcess extends BaritoneProcessHelper {
|
|||||||
if (state.getBlock() == Blocks.AIR) {
|
if (state.getBlock() == Blocks.AIR) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ItemBlock(state.getBlock());
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user