From cec44e3668d87d1e9ed2c0eb688de43813eb0e13 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 13 Jun 2021 00:21:52 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20a=20clipboard=20to=20#sel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baritone/command/defaults/SelCommand.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 0eab8a9a..659a3183 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -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 - Replaces blocks with another block.", + "> sel copy/cp - Copy the selected area relative to the specified or your position.", + "> sel paste/p - Build the copied area relative to the specified or your position.", "", "> sel expand - Expand the targets.", "> sel contract - 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;