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