From 926e2d56201a03705c8ee5e047580b22d27f5468 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 27 Mar 2019 17:32:02 -0700 Subject: [PATCH] add resuming to builder, fixes #371 --- .../java/baritone/process/BuilderProcess.java | 18 ++++++++++++++---- .../baritone/utils/ExampleBaritoneControl.java | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 320d6030..8b2263ab 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -65,6 +65,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro private ISchematic schematic; private Vec3i origin; private int ticks; + private boolean paused; public boolean build(String schematicFile, BlockPos origin) { 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.schematic = schematic; this.origin = origin; + this.paused = false; + } + + public void resume() { + paused = false; } @Override @@ -276,6 +282,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { baritone.getInputOverrideHandler().clearAllKeys(); + if (paused) { + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } BuilderCalculationContext bcc = new BuilderCalculationContext(); if (!recalc(bcc)) { logDirect("Done building"); @@ -352,9 +361,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro if (goal == null) { goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly if (goal == null) { - logDirect("Unable to do it =("); - onLostControl(); - return null; + logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel"); + paused = true; + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } } return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc); @@ -533,11 +542,12 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro incorrectPositions = null; name = null; schematic = null; + paused = false; } @Override public String displayName0() { - return "Building " + name; + return paused ? "Builder Paused" : "Building " + name; } public List placable(int size) { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 6dbdf388..9b8dd488 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -353,6 +353,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { baritone.getBuilderProcess().clearArea(corner1, corner2); return true; } + if (msg.equals("resume")) { + baritone.getBuilderProcess().resume(); + logDirect("resumed"); + return true; + } if (msg.equals("reset")) { for (Settings.Setting setting : Baritone.settings().allSettings) { setting.reset();