3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-27 19:30:07 +01:00

Converted //move to visitors.

Dieser Commit ist enthalten in:
sk89q 2014-03-30 10:29:00 -07:00
Ursprung 5c3db177a4
Commit c8ee9ce931

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.expression.Expression; import com.sk89q.worldedit.expression.Expression;
import com.sk89q.worldedit.expression.ExpressionException; import com.sk89q.worldedit.expression.ExpressionException;
import com.sk89q.worldedit.expression.runtime.RValue; import com.sk89q.worldedit.expression.runtime.RValue;
import com.sk89q.worldedit.extent.ExtentBuffer;
import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter; import com.sk89q.worldedit.function.RegionMaskingFilter;
import com.sk89q.worldedit.function.block.BlockCount; import com.sk89q.worldedit.function.block.BlockCount;
@ -36,6 +37,7 @@ import com.sk89q.worldedit.function.generator.GardenPatchGenerator;
import com.sk89q.worldedit.function.mask.*; import com.sk89q.worldedit.function.mask.*;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.OperationHelper; import com.sk89q.worldedit.function.operation.OperationHelper;
import com.sk89q.worldedit.function.operation.OperationQueue;
import com.sk89q.worldedit.function.util.RegionOffset; import com.sk89q.worldedit.function.util.RegionOffset;
import com.sk89q.worldedit.function.visitor.DownwardVisitor; import com.sk89q.worldedit.function.visitor.DownwardVisitor;
import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.function.visitor.LayerVisitor;
@ -1217,51 +1219,46 @@ public class EditSession implements Extent {
} }
/** /**
* Move a region. * Move the blocks in a region a certain direction.
* *
* @param region * @param region the region to move
* @param dir * @param dir the direction
* @param distance * @param distance the distance to move
* @param copyAir * @param copyAir true to copy air blocks
* @param replace * @param replacement the replacement block to fill in after moving, or null to use air
* @return number of blocks moved * @return number of blocks moved
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException thrown if too many blocks are changed
* @throws RegionOperationException
*/ */
public int moveRegion(Region region, Vector dir, int distance, public int moveRegion(Region region, Vector dir, int distance, boolean copyAir, BaseBlock replacement) throws MaxChangedBlocksException {
boolean copyAir, BaseBlock replace) checkNotNull(region);
throws MaxChangedBlocksException, RegionOperationException { checkNotNull(dir);
int affected = 0; checkArgument(distance >= 1, "distance >= 1 required");
final Vector shift = dir.multiply(distance); Vector to = region.getMinimumPoint();
final Region newRegion = region.clone(); // Remove the original blocks
newRegion.shift(shift); Pattern pattern = replacement != null ?
new SingleBlockPattern(replacement) :
new SingleBlockPattern(new BaseBlock(BlockID.AIR));
BlockReplace remove = new BlockReplace(this, pattern);
final Map<Vector, BaseBlock> delayed = new LinkedHashMap<Vector, BaseBlock>(); // Copy to a buffer so we don't destroy our original before we can copy all the blocks from it
ExtentBuffer buffer = new ExtentBuffer(this, new RegionMask(region));
for (Vector pos : region) { ForwardExtentCopy copy = new ForwardExtentCopy(this, region, buffer, to);
final BaseBlock block = getBlock(pos); copy.setTransform(new AffineTransform().translate(dir.multiply(distance)));
copy.setSourceFunction(remove); // Remove
if (!block.isAir() || copyAir) { if (!copyAir) {
final Vector newPos = pos.add(shift); copy.setSourceMask(new ExistingBlockMask(this));
delayed.put(newPos, getBlock(pos));
// Don't want to replace the old block if it's in
// the new area
if (!newRegion.contains(pos)) {
setBlock(pos, replace);
}
}
} }
for (Map.Entry<Vector, BaseBlock> entry : delayed.entrySet()) { // Then we need to copy the buffer to the world
setBlock(entry.getKey(), entry.getValue()); BlockReplace replace = new BlockReplace(this, buffer);
++affected; RegionVisitor visitor = new RegionVisitor(buffer.asRegion(), replace);
}
return affected; OperationQueue operation = new OperationQueue(copy, visitor);
OperationHelper.completeLegacy(operation);
return copy.getAffected();
} }
/** /**