Merge pull request #1332 from aUniqueUser/master

#740 (Custom tunneling) Updated for new command system
This commit is contained in:
Leijurv 2020-02-27 14:29:18 -08:00 committed by GitHub
commit 448dd979a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 11 deletions

View File

@ -18,11 +18,13 @@
package baritone.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalStrictDirection;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.argument.IArgConsumer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import java.util.List;
@ -36,13 +38,56 @@ public class TunnelCommand extends Command {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
Goal goal = new GoalStrictDirection(
ctx.playerFeet(),
ctx.player().getHorizontalFacing()
);
baritone.getCustomGoalProcess().setGoalAndPath(goal);
logDirect(String.format("Goal: %s", goal.toString()));
args.requireMax(3);
if (args.hasExactly(3)) {
boolean cont = true;
int height = Integer.parseInt(args.getArgs().get(0).getValue());
int width = Integer.parseInt(args.getArgs().get(1).getValue());
int depth = Integer.parseInt(args.getArgs().get(2).getValue());
if (width < 1 || height < 2 || depth < 1 || height > 255) {
logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks, and cannot be greater than the build limit.");
cont = false;
}
if (cont) {
height--;
width--;
BlockPos corner1;
BlockPos corner2;
EnumFacing enumFacing = ctx.player().getHorizontalFacing();
int addition = ((width % 2 == 0) ? 0 : 1);
switch (enumFacing) {
case EAST:
corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z - width / 2);
corner2 = new BlockPos(ctx.playerFeet().x + depth, ctx.playerFeet().y + height, ctx.playerFeet().z + width / 2 + addition);
break;
case WEST:
corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z + width / 2 + addition);
corner2 = new BlockPos(ctx.playerFeet().x - depth, ctx.playerFeet().y + height, ctx.playerFeet().z - width / 2);
break;
case NORTH:
corner1 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y, ctx.playerFeet().z);
corner2 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y + height, ctx.playerFeet().z - depth);
break;
case SOUTH:
corner1 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y, ctx.playerFeet().z);
corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth);
break;
default:
throw new IllegalStateException("Unexpected value: " + enumFacing);
}
logDirect(String.format("Creating a tunnel %s block(s) high, %s block(s) wide, and %s block(s) deep", height+1, width+1, depth));
baritone.getBuilderProcess().clearArea(corner1, corner2);
}
} else {
Goal goal = new GoalStrictDirection(
ctx.playerFeet(),
ctx.player().getHorizontalFacing()
);
baritone.getCustomGoalProcess().setGoalAndPath(goal);
logDirect(String.format("Goal: %s", goal.toString()));
}
}
@Override
@ -61,7 +106,8 @@ public class TunnelCommand extends Command {
"The tunnel command sets a goal that tells Baritone to mine completely straight in the direction that you're facing.",
"",
"Usage:",
"> tunnel"
"> tunnel - No arguments, mines in a 1x2 radius.",
"> tunnel height/width/depth - Tunnels in a user defined height, width and depth."
);
}
}