diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 0b34fb07..1ac201e1 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -78,12 +78,16 @@ public class BuilderProcess extends BaritoneProcessHelper { if (tag == null) { return false; } - name = schematicFile; - schematic = parse(tag); - origin = ctx.playerFeet(); + build(schematicFile, parse(tag), ctx.playerFeet()); return true; } + public void build(String name, ISchematic schematic, Vec3i origin) { + this.name = name; + this.schematic = schematic; + this.origin = origin; + } + private static ISchematic parse(NBTTagCompound schematic) { return new Schematic(schematic); } diff --git a/src/main/java/baritone/utils/AirSchematic.java b/src/main/java/baritone/utils/AirSchematic.java new file mode 100644 index 00000000..bced26e7 --- /dev/null +++ b/src/main/java/baritone/utils/AirSchematic.java @@ -0,0 +1,53 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; + +public class AirSchematic implements ISchematic { + public final int widthX; + public final int heightY; + public final int lengthZ; + + public AirSchematic(int widthX, int heightY, int lengthZ) { + this.widthX = widthX; + this.heightY = heightY; + this.lengthZ = lengthZ; + } + + @Override + public IBlockState desiredState(int x, int y, int z) { + return Blocks.AIR.getDefaultState(); + } + + @Override + public int widthX() { + return widthX; + } + + @Override + public int heightY() { + return heightY; + } + + @Override + public int lengthZ() { + return lengthZ; + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 55009575..6e65c087 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -284,6 +284,36 @@ public class ExampleBaritoneControl extends Behavior implements Helper { }); return true; } + if (msg.startsWith("cleararea")) { + String suffix = msg.substring("cleararea".length()); + BlockPos corner1; + BlockPos corner2; + if (suffix.isEmpty()) { + // clear the area from the current goal to here + Goal goal = baritone.getPathingBehavior().getGoal(); + if (goal == null || !(goal instanceof GoalBlock)) { + logDirect("Need to specify goal of opposite corner"); + return true; + } + corner1 = ((GoalBlock) goal).getGoalPos(); + corner2 = ctx.playerFeet(); + } else { + try { + String[] spl = suffix.split(" "); + corner1 = ctx.playerFeet(); + corner2 = new BlockPos(Integer.parseInt(spl[0]), Integer.parseInt(spl[1]), Integer.parseInt(spl[2])); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) { + logDirect("unable to parse"); + return true; + } + } + BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); + int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; + int heightY = Math.abs(corner1.getY() - corner2.getY()) + 1; + int lengthZ = Math.abs(corner1.getZ() - corner2.getZ()) + 1; + baritone.getBuilderProcess().build("clear area", new AirSchematic(widthX, heightY, lengthZ), origin); + return true; + } if (msg.equals("reset")) { Baritone.settings().reset(); logDirect("Baritone settings reset"); diff --git a/src/main/java/baritone/utils/ISchematic.java b/src/main/java/baritone/utils/ISchematic.java index b68f1a1c..77ba8634 100644 --- a/src/main/java/baritone/utils/ISchematic.java +++ b/src/main/java/baritone/utils/ISchematic.java @@ -33,7 +33,9 @@ public interface ISchematic { * @param z * @return */ - boolean inSchematic(int x, int y, int z); + default boolean inSchematic(int x, int y, int z) { + return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ(); + } IBlockState desiredState(int x, int y, int z); diff --git a/src/main/java/baritone/utils/Schematic.java b/src/main/java/baritone/utils/Schematic.java index dbc80a73..3fef4b1e 100644 --- a/src/main/java/baritone/utils/Schematic.java +++ b/src/main/java/baritone/utils/Schematic.java @@ -66,11 +66,6 @@ public class Schematic implements ISchematic { } } - @Override - public boolean inSchematic(int x, int y, int z) { - return x >= 0 && x < widthX && y >= 0 && y < heightY && z >= 0 && z < lengthZ; - } - @Override public IBlockState desiredState(int x, int y, int z) { return states[x][z][y];