2014-07-09 21:14:17 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.session;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.util.MaskTraverser;
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
2018-12-23 16:19:33 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|
|
|
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.RegionFunction;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operation;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.math.transform.Transform;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
/**
|
|
|
|
* Builds an operation to paste the contents of a clipboard.
|
|
|
|
*/
|
|
|
|
public class PasteBuilder {
|
|
|
|
|
|
|
|
private final Clipboard clipboard;
|
|
|
|
private final Transform transform;
|
|
|
|
private final Extent targetExtent;
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
private BlockVector3 to = BlockVector3.ZERO;
|
2014-07-09 21:14:17 +00:00
|
|
|
private boolean ignoreAirBlocks;
|
2018-08-12 14:03:07 +00:00
|
|
|
private boolean ignoreBiomes;
|
|
|
|
private boolean ignoreEntities;
|
|
|
|
private RegionFunction canApply;
|
2014-07-09 21:14:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
2018-08-12 14:03:07 +00:00
|
|
|
* @param holder the clipboard holder
|
|
|
|
* @param targetExtent an extent
|
2014-07-09 21:14:17 +00:00
|
|
|
*/
|
2018-08-12 14:03:07 +00:00
|
|
|
public PasteBuilder(ClipboardHolder holder, Extent targetExtent) {
|
2014-07-09 21:14:17 +00:00
|
|
|
checkNotNull(holder);
|
|
|
|
checkNotNull(targetExtent);
|
|
|
|
this.clipboard = holder.getClipboard();
|
|
|
|
this.transform = holder.getTransform();
|
|
|
|
this.targetExtent = targetExtent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the target location.
|
|
|
|
*
|
|
|
|
* @param to the target location
|
|
|
|
* @return this builder instance
|
|
|
|
*/
|
2018-12-23 16:19:33 +00:00
|
|
|
public PasteBuilder to(BlockVector3 to) {
|
2014-07-09 21:14:17 +00:00
|
|
|
this.to = to;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether air blocks in the source are skipped over when pasting.
|
|
|
|
*
|
|
|
|
* @return this builder instance
|
|
|
|
*/
|
|
|
|
public PasteBuilder ignoreAirBlocks(boolean ignoreAirBlocks) {
|
|
|
|
this.ignoreAirBlocks = ignoreAirBlocks;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public PasteBuilder ignoreBiomes(boolean ignoreBiomes) {
|
|
|
|
this.ignoreBiomes = ignoreBiomes;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PasteBuilder ignoreEntities(boolean ignoreEntities) {
|
|
|
|
this.ignoreEntities = ignoreEntities;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PasteBuilder filter(RegionFunction function) {
|
|
|
|
this.canApply = function;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
/**
|
|
|
|
* Build the operation.
|
|
|
|
*
|
|
|
|
* @return the operation
|
|
|
|
*/
|
|
|
|
public Operation build() {
|
2018-08-12 14:03:07 +00:00
|
|
|
Extent extent = clipboard;
|
|
|
|
if (!transform.isIdentity()) {
|
|
|
|
extent = new BlockTransformExtent(extent, transform);
|
|
|
|
}
|
2014-07-09 21:14:17 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
|
|
|
|
copy.setTransform(transform);
|
2018-08-17 08:33:37 +00:00
|
|
|
copy.setCopyingEntities(!ignoreEntities);
|
2018-08-12 14:03:07 +00:00
|
|
|
copy.setCopyBiomes((!ignoreBiomes) && (!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes()));
|
|
|
|
if (this.canApply != null) {
|
|
|
|
copy.setFilterFunction(this.canApply);
|
|
|
|
}
|
|
|
|
if (targetExtent instanceof EditSession) {
|
|
|
|
Mask sourceMask = ((EditSession) targetExtent).getSourceMask();
|
|
|
|
if (sourceMask != null) {
|
|
|
|
new MaskTraverser(sourceMask).reset(extent);
|
|
|
|
copy.setSourceMask(sourceMask);
|
|
|
|
((EditSession) targetExtent).setSourceMask(null);
|
|
|
|
}
|
|
|
|
}
|
2014-07-09 21:14:17 +00:00
|
|
|
if (ignoreAirBlocks) {
|
|
|
|
copy.setSourceMask(new ExistingBlockMask(clipboard));
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2018-08-12 16:36:39 +00:00
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
}
|