area clear

This commit is contained in:
Leijurv 2019-01-14 21:41:40 -08:00
parent e2cdd6a7f9
commit d5b393d6bd
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 93 additions and 9 deletions

View File

@ -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);
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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");

View File

@ -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);

View File

@ -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];