replant nether wart setting

This commit is contained in:
Leijurv 2019-04-20 11:03:59 -07:00
parent 850c414e8f
commit 498e4e2d6c
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 43 additions and 40 deletions

View File

@ -590,6 +590,11 @@ public final class Settings {
*/
public final Setting<Integer> exploreChunkSetMinimumSize = new Setting<>(10);
/**
* Replant nether wart
*/
public final Setting<Boolean> replantNetherWart = new Setting<>(false);
/**
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
* <p>

View File

@ -123,7 +123,7 @@ public class InventoryBehavior extends Behavior {
public boolean hasGenericThrowaway() {
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
if (throwaway(false, item::equals)) {
if (throwaway(false, stack -> item.equals(stack.getItem()))) {
return true;
}
}
@ -132,18 +132,18 @@ public class InventoryBehavior extends Behavior {
public boolean selectThrowawayForLocation(int x, int y, int z) {
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
if (maybe != null && throwaway(true, item -> item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(maybe.getBlock()))) {
if (maybe != null && throwaway(true, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
return true; // gotem
}
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
if (throwaway(true, item::equals)) {
if (throwaway(true, stack -> item.equals(stack.getItem()))) {
return true;
}
}
return false;
}
private boolean throwaway(boolean select, Predicate<? super Item> desired) {
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
EntityPlayerSP p = ctx.player();
NonNullList<ItemStack> inv = p.inventory.mainInventory;
for (byte i = 0; i < 9; i++) {
@ -153,14 +153,14 @@ public class InventoryBehavior extends Behavior {
// and then it's called during execution
// since this function is never called during cost calculation, we don't need to migrate
// acceptableThrowawayItems to the CalculationContext
if (desired.test(item.getItem())) {
if (desired.test(item)) {
if (select) {
p.inventory.currentItem = i;
}
return true;
}
}
if (desired.test(p.inventory.offHandInventory.get(0).getItem())) {
if (desired.test(p.inventory.offHandInventory.get(0))) {
// 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
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem

View File

@ -40,7 +40,6 @@ import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@ -143,39 +142,18 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
return false;
}
private boolean selectFarmlandPlantable(boolean doSelect) {//EnumDyeColor.WHITE == EnumDyeColor.byDyeDamage(stack.getMetadata())
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
for (int i = 0; i < 9; i++) {
if (FARMLAND_PLANTABLE.contains(invy.get(i).getItem())) {
if (doSelect) {
ctx.player().inventory.currentItem = i;
}
return true;
}
}
return false;
}
private boolean selectBoneMeal(boolean doSelect) {
if (isBoneMeal(ctx.player().inventory.offHandInventory.get(0))) {
return true;
}
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
for (int i = 0; i < 9; i++) {
if (isBoneMeal(invy.get(i))) {
if (doSelect) {
ctx.player().inventory.currentItem = i;
}
return true;
}
}
return false;
private boolean isPlantable(ItemStack stack) {
return FARMLAND_PLANTABLE.contains(stack.getItem());
}
private boolean isBoneMeal(ItemStack stack) {
return !stack.isEmpty() && stack.getItem() instanceof ItemDye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.WHITE;
}
private boolean isNetherWart(ItemStack stack) {
return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART);
}
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
ArrayList<Block> scan = new ArrayList<>();
@ -183,20 +161,31 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
scan.add(harvest.block);
}
scan.add(Blocks.FARMLAND);
if (Baritone.settings().replantNetherWart.value) {
scan.add(Blocks.SOUL_SAND);
}
List<BlockPos> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4);
List<BlockPos> toBreak = new ArrayList<>();
List<BlockPos> openFarmland = new ArrayList<>();
List<BlockPos> bonemealable = new ArrayList<>();
List<BlockPos> openSoulsand = new ArrayList<>();
for (BlockPos pos : locations) {
IBlockState state = ctx.world().getBlockState(pos);
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
if (state.getBlock() == Blocks.FARMLAND) {
if (ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir) {
if (airAbove) {
openFarmland.add(pos);
}
continue;
}
if (state.getBlock() == Blocks.SOUL_SAND) {
if (airAbove) {
openSoulsand.add(pos);
}
continue;
}
if (readyForHarvest(ctx.world(), pos, state)) {
toBreak.add(pos);
continue;
@ -221,9 +210,12 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
}
for (BlockPos pos : openFarmland) {
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
both.addAll(openSoulsand);
for (BlockPos pos : both) {
boolean soulsand = openSoulsand.contains(pos);
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance());
if (rot.isPresent() && isSafeToCancel && selectFarmlandPlantable(true)) {
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
@ -233,7 +225,7 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
}
for (BlockPos pos : bonemealable) {
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
if (rot.isPresent() && isSafeToCancel && selectBoneMeal(true)) {
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
@ -252,12 +244,17 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
for (BlockPos pos : toBreak) {
goalz.add(new BuilderProcess.GoalBreak(pos));
}
if (selectFarmlandPlantable(false)) {
if (baritone.getInventoryBehavior().throwaway(false, this::isPlantable)) {
for (BlockPos pos : openFarmland) {
goalz.add(new GoalBlock(pos.up()));
}
}
if (selectBoneMeal(false)) {
if (baritone.getInventoryBehavior().throwaway(false, this::isNetherWart)) {
for (BlockPos pos : openSoulsand) {
goalz.add(new GoalBlock(pos.up()));
}
}
if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
for (BlockPos pos : bonemealable) {
goalz.add(new GoalBlock(pos));
}
@ -266,6 +263,7 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
if (entity instanceof EntityItem && entity.onGround) {
EntityItem ei = (EntityItem) entity;
if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
// +0.1 because of farmland's 0.9375 dummy height lol
goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));
}
}