add resuming to builder, fixes #371

This commit is contained in:
Leijurv 2019-03-27 17:32:02 -07:00
parent d2de8828e7
commit 926e2d5620
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 19 additions and 4 deletions

View File

@ -65,6 +65,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
private ISchematic schematic; private ISchematic schematic;
private Vec3i origin; private Vec3i origin;
private int ticks; private int ticks;
private boolean paused;
public boolean build(String schematicFile, BlockPos origin) { public boolean build(String schematicFile, BlockPos origin) {
File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile); File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile);
@ -77,6 +78,11 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
this.name = name; this.name = name;
this.schematic = schematic; this.schematic = schematic;
this.origin = origin; this.origin = origin;
this.paused = false;
}
public void resume() {
paused = false;
} }
@Override @Override
@ -276,6 +282,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
@Override @Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
baritone.getInputOverrideHandler().clearAllKeys(); baritone.getInputOverrideHandler().clearAllKeys();
if (paused) {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
BuilderCalculationContext bcc = new BuilderCalculationContext(); BuilderCalculationContext bcc = new BuilderCalculationContext();
if (!recalc(bcc)) { if (!recalc(bcc)) {
logDirect("Done building"); logDirect("Done building");
@ -352,9 +361,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
if (goal == null) { if (goal == null) {
goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly
if (goal == null) { if (goal == null) {
logDirect("Unable to do it =("); logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
onLostControl(); paused = true;
return null; return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
} }
} }
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc); return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
@ -533,11 +542,12 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
incorrectPositions = null; incorrectPositions = null;
name = null; name = null;
schematic = null; schematic = null;
paused = false;
} }
@Override @Override
public String displayName0() { public String displayName0() {
return "Building " + name; return paused ? "Builder Paused" : "Building " + name;
} }
public List<IBlockState> placable(int size) { public List<IBlockState> placable(int size) {

View File

@ -353,6 +353,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
baritone.getBuilderProcess().clearArea(corner1, corner2); baritone.getBuilderProcess().clearArea(corner1, corner2);
return true; return true;
} }
if (msg.equals("resume")) {
baritone.getBuilderProcess().resume();
logDirect("resumed");
return true;
}
if (msg.equals("reset")) { if (msg.equals("reset")) {
for (Settings.Setting setting : Baritone.settings().allSettings) { for (Settings.Setting setting : Baritone.settings().allSettings) {
setting.reset(); setting.reset();