Add a clipboard to #sel

This commit is contained in:
ZacSharp 2021-06-13 00:21:52 +02:00
parent e85c1bbc0d
commit cec44e3668
No known key found for this signature in database
GPG Key ID: 9453647B005083A3

View File

@ -37,6 +37,9 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.utils.IRenderer;
import baritone.utils.BlockStateInterface;
import baritone.utils.schematic.StaticSchematic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
@ -53,6 +56,8 @@ public class SelCommand extends Command {
private ISelectionManager manager = baritone.getSelectionManager();
private BetterBlockPos pos1 = null;
private ISchematic clipboard = null;
private Vec3i clipboardOffset = null;
public SelCommand(IBaritone baritone) {
super(baritone, "sel", "selection", "s");
@ -158,6 +163,56 @@ public class SelCommand extends Command {
}
baritone.getBuilderProcess().build("Fill", composite, origin);
logDirect("Filling now");
} else if (action == Action.COPY) {
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
args.requireMax(0);
ISelection[] selections = manager.getSelections();
if (selections.length < 1) {
throw new CommandInvalidStateException("No selections");
}
BlockStateInterface bsi = new BlockStateInterface(ctx);
BetterBlockPos origin = selections[0].min();
CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
for (ISelection selection : selections) {
BetterBlockPos min = selection.min();
origin = new BetterBlockPos(
Math.min(origin.x, min.x),
Math.min(origin.y, min.y),
Math.min(origin.z, min.z)
);
}
for (ISelection selection : selections) {
Vec3i size = selection.size();
BetterBlockPos min = selection.min();
IBlockState[][][] blockstates = new IBlockState[size.getX()][size.getZ()][size.getY()];
for (int x = 0; x < size.getX(); x++) {
for (int y = 0; y < size.getY(); y++) {
for (int z = 0; z < size.getZ(); z++) {
blockstates[x][z][y] = bsi.get0(min.x + x, min.y + y, min.z + z);
}
}
}
ISchematic schematic = new StaticSchematic(){{
states = blockstates;
x = size.getX();
y = size.getY();
z = size.getZ();
}};
composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
}
clipboard = composite;
clipboardOffset = origin.subtract(pos);
logDirect("Selection copied");
} else if (action == Action.PASTE) {
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
args.requireMax(0);
if (clipboard == null) {
throw new CommandInvalidStateException("You need to copy a selection first");
}
baritone.getBuilderProcess().build("Fill", clipboard, pos.add(clipboardOffset));
logDirect("Building now");
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
args.requireExactly(3);
TransformTarget transformTarget = TransformTarget.getByName(args.getString());
@ -252,6 +307,8 @@ public class SelCommand extends Command {
"> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.",
"> sel cleararea/ca - Basically 'set air'.",
"> sel replace/r <blocks...> <with> - Replaces blocks with another block.",
"> sel copy/cp <x> <y> <z> - Copy the selected area relative to the specified or your position.",
"> sel paste/p <x> <y> <z> - Build the copied area relative to the specified or your position.",
"",
"> sel expand <target> <direction> <blocks> - Expand the targets.",
"> sel contract <target> <direction> <blocks> - Contract the targets.",
@ -270,6 +327,8 @@ public class SelCommand extends Command {
CLEARAREA("cleararea", "ca"),
REPLACE("replace", "r"),
EXPAND("expand", "ex"),
COPY("copy", "cp"),
PASTE("paste", "p"),
CONTRACT("contract", "ct"),
SHIFT("shift", "sh");
private final String[] names;