Added range argument to farm
This commit is contained in:
parent
5a5d11922f
commit
5d3522ca0a
@ -17,7 +17,9 @@
|
||||
|
||||
package baritone.api.process;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IFarmProcess extends IBaritoneProcess {
|
||||
|
||||
void farm();
|
||||
void farm(int range, BlockPos pos);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -34,8 +35,13 @@ public class FarmCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
args.requireMax(0);
|
||||
baritone.getFarmProcess().farm();
|
||||
args.requireMax(1);
|
||||
int range = 0;
|
||||
if (args.hasExactly(1)) {
|
||||
range = args.getAs(Integer.class);
|
||||
}
|
||||
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
|
||||
baritone.getFarmProcess().farm(range, origin);
|
||||
logDirect("Farming");
|
||||
}
|
||||
|
||||
@ -55,7 +61,8 @@ public class FarmCommand extends Command {
|
||||
"The farm command starts farming nearby plants. It harvests mature crops and plants new ones.",
|
||||
"",
|
||||
"Usage:",
|
||||
"> farm"
|
||||
"> farm - farms every crop it can find.",
|
||||
"> farm 100 - farm crops within a 100 block radius from the starting position."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
private List<BlockPos> locations;
|
||||
private int tickCount;
|
||||
|
||||
private int range;
|
||||
private BlockPos center;
|
||||
|
||||
private static final List<Item> FARMLAND_PLANTABLE = Arrays.asList(
|
||||
Items.BEETROOT_SEEDS,
|
||||
Items.MELON_SEEDS,
|
||||
@ -97,7 +100,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
|
||||
@Override
|
||||
public void farm() {
|
||||
public void farm(int range, BlockPos pos) {
|
||||
center = pos;
|
||||
this.range = range;
|
||||
active = true;
|
||||
locations = null;
|
||||
}
|
||||
@ -191,6 +196,11 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
List<BlockPos> bonemealable = new ArrayList<>();
|
||||
List<BlockPos> openSoulsand = new ArrayList<>();
|
||||
for (BlockPos pos : locations) {
|
||||
//check if the target block is out of range.
|
||||
if (range != 0 && pos.getDistance(center.getX(), center.getY(), center.getZ()) > range) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IBlockState state = ctx.world().getBlockState(pos);
|
||||
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
|
||||
if (state.getBlock() == Blocks.FARMLAND) {
|
||||
|
Loading…
Reference in New Issue
Block a user