|
| 1 | +/* |
| 2 | + * WorldEdit, a Minecraft world manipulation toolkit |
| 3 | + * Copyright (C) sk89q <http://www.sk89q.com> |
| 4 | + * Copyright (C) WorldEdit team and contributors |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.sk89q.worldedit.function; |
| 21 | + |
| 22 | +import com.sk89q.worldedit.MaxChangedBlocksException; |
| 23 | +import com.sk89q.worldedit.extent.Extent; |
| 24 | +import com.sk89q.worldedit.extent.clipboard.Clipboard; |
| 25 | +import com.sk89q.worldedit.function.mask.Mask; |
| 26 | +import com.sk89q.worldedit.function.operation.ForwardExtentCopy; |
| 27 | +import com.sk89q.worldedit.function.operation.Operations; |
| 28 | +import com.sk89q.worldedit.math.BlockVector3; |
| 29 | +import com.sk89q.worldedit.regions.Region; |
| 30 | +import com.sk89q.worldedit.session.ClipboardHolder; |
| 31 | + |
| 32 | +public final class ClipboardPaste implements RegionFunction { |
| 33 | + |
| 34 | + private final Extent destination; |
| 35 | + private final ClipboardHolder holder; |
| 36 | + private final boolean ignoreAirBlocks; |
| 37 | + private final boolean ignoreStructureVoidBlocks; |
| 38 | + private final boolean usingOrigin; |
| 39 | + private final boolean pasteEntities; |
| 40 | + private final boolean pasteBiomes; |
| 41 | + private final Mask sourceMask; |
| 42 | + |
| 43 | + public ClipboardPaste(Extent destination, ClipboardHolder holder, boolean ignoreAirBlocks, |
| 44 | + boolean ignoreStructureVoidBlocks, boolean usingOrigin, boolean pasteEntities, |
| 45 | + boolean pasteBiomes, Mask sourceMask) { |
| 46 | + this.destination = destination; |
| 47 | + this.holder = holder; |
| 48 | + this.ignoreAirBlocks = ignoreAirBlocks; |
| 49 | + this.ignoreStructureVoidBlocks = ignoreStructureVoidBlocks; |
| 50 | + this.usingOrigin = usingOrigin; |
| 51 | + this.pasteEntities = pasteEntities; |
| 52 | + this.pasteBiomes = pasteBiomes; |
| 53 | + this.sourceMask = sourceMask; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public boolean apply(BlockVector3 position) throws MaxChangedBlocksException { |
| 58 | + Clipboard clipboard = holder.getClipboard(); |
| 59 | + Region region = clipboard.getRegion(); |
| 60 | + BlockVector3 centerOffset = region.getCenter().toBlockPoint().subtract(clipboard.getOrigin()); |
| 61 | + BlockVector3 transformedCenterOffset = holder.getTransform().apply(centerOffset.toVector3()).toBlockPoint(); |
| 62 | + |
| 63 | + ForwardExtentCopy operation = (ForwardExtentCopy) holder |
| 64 | + .createPaste(destination) |
| 65 | + .to(usingOrigin ? position : position.subtract(transformedCenterOffset)) |
| 66 | + .ignoreAirBlocks(ignoreAirBlocks) |
| 67 | + .ignoreStructureVoidBlocks(ignoreStructureVoidBlocks) |
| 68 | + .copyEntities(pasteEntities) |
| 69 | + .copyBiomes(pasteBiomes) |
| 70 | + .maskSource(sourceMask) |
| 71 | + .build(); |
| 72 | + |
| 73 | + Operations.completeLegacy(operation); |
| 74 | + return operation.getAffected() > 0; |
| 75 | + } |
| 76 | +} |
0 commit comments