ForwardExtentCopy can now apply a function to source blocks after copy.

This commit is contained in:
sk89q 2014-03-30 10:27:25 -07:00
parent 36c5ceaf90
commit 5c3db177a4

View File

@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.operation;
import com.sk89q.worldedit.Extent; import com.sk89q.worldedit.Extent;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter; import com.sk89q.worldedit.function.RegionMaskingFilter;
import com.sk89q.worldedit.function.block.ExtentBlockCopy; import com.sk89q.worldedit.function.block.ExtentBlockCopy;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
@ -49,6 +51,7 @@ public class ForwardExtentCopy implements Operation {
private final Vector to; private final Vector to;
private int repetitions = 1; private int repetitions = 1;
private Mask sourceMask = Masks.alwaysTrue(); private Mask sourceMask = Masks.alwaysTrue();
private RegionFunction sourceFunction = null;
private Transform transform = new Identity(); private Transform transform = new Identity();
private Transform currentTransform = null; private Transform currentTransform = null;
private RegionVisitor lastVisitor; private RegionVisitor lastVisitor;
@ -117,6 +120,26 @@ public class ForwardExtentCopy implements Operation {
this.sourceMask = sourceMask; this.sourceMask = sourceMask;
} }
/**
* Get the function that gets applied to all source blocks <em>after</em>
* the copy has been made.
*
* @return a source function, or null if none is to be applied
*/
public RegionFunction getSourceFunction() {
return sourceFunction;
}
/**
* Set the function that gets applied to all source blocks <em>after</em>
* the copy has been made.
*
* @param function a source function, or null if none is to be applied
*/
public void setSourceFunction(RegionFunction function) {
this.sourceFunction = function;
}
/** /**
* Get the number of repetitions left. * Get the number of repetitions left.
* *
@ -161,7 +184,8 @@ public class ForwardExtentCopy implements Operation {
ExtentBlockCopy copy = new ExtentBlockCopy(source, region.getMinimumPoint(), destination, to, currentTransform); ExtentBlockCopy copy = new ExtentBlockCopy(source, region.getMinimumPoint(), destination, to, currentTransform);
RegionMaskingFilter filter = new RegionMaskingFilter(sourceMask, copy); RegionMaskingFilter filter = new RegionMaskingFilter(sourceMask, copy);
RegionVisitor visitor = new RegionVisitor(region, filter); RegionFunction function = sourceFunction != null ? new CombinedRegionFunction(filter, sourceFunction) : filter;
RegionVisitor visitor = new RegionVisitor(region, function);
lastVisitor = visitor; lastVisitor = visitor;
currentTransform = currentTransform.combine(transform); currentTransform = currentTransform.combine(transform);
return new DelegateOperation(this, visitor); return new DelegateOperation(this, visitor);