Converted //stack to visitors.

Dieser Commit ist enthalten in:
sk89q 2014-03-30 03:08:56 -07:00
Ursprung e3a42db309
Commit 37c388baef

Datei anzeigen

@ -34,6 +34,7 @@ import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.function.block.Naturalizer; import com.sk89q.worldedit.function.block.Naturalizer;
import com.sk89q.worldedit.function.generator.GardenPatchGenerator; 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.OperationHelper; import com.sk89q.worldedit.function.operation.OperationHelper;
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;
@ -45,6 +46,7 @@ import com.sk89q.worldedit.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.interpolation.Node; import com.sk89q.worldedit.interpolation.Node;
import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.math.noise.RandomNoise; import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.patterns.SingleBlockPattern; import com.sk89q.worldedit.patterns.SingleBlockPattern;
import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.regions.*;
@ -249,8 +251,8 @@ public class EditSession implements Extent {
} }
@Override @Override
public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) { public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws MaxChangedBlocksException {
return setBlock(location, block, true); return setBlock(location, block);
} }
/** /**
@ -1190,52 +1192,28 @@ public class EditSession implements Extent {
/** /**
* Stack a cuboid region. * Stack a cuboid region.
* *
* @param region * @param region the region to stack
* @param dir * @param dir the direction to stack
* @param count * @param count the number of times to stack
* @param copyAir * @param copyAir true to also copy air blocks
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int stackCuboidRegion(Region region, Vector dir, int count, public int stackCuboidRegion(Region region, Vector dir, int count, boolean copyAir) throws MaxChangedBlocksException {
boolean copyAir) throws MaxChangedBlocksException { checkNotNull(region);
int affected = 0; checkNotNull(dir);
checkArgument(count >= 1, "count >= 1 required");
Vector min = region.getMinimumPoint(); Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
Vector max = region.getMaximumPoint(); Vector to = region.getMinimumPoint();
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
int minX = min.getBlockX(); copy.setRepetitions(count);
int minY = min.getBlockY(); copy.setTransform(new AffineTransform().translate(dir.multiply(size)));
int minZ = min.getBlockZ(); if (!copyAir) {
int maxX = max.getBlockX(); copy.setSourceMask(new ExistingBlockMask(this));
int maxY = max.getBlockY();
int maxZ = max.getBlockZ();
int xs = region.getWidth();
int ys = region.getHeight();
int zs = region.getLength();
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
for (int y = minY; y <= maxY; ++y) {
BaseBlock block = getBlock(new Vector(x, y, z));
if (!block.isAir() || copyAir) {
for (int i = 1; i <= count; ++i) {
Vector pos = new Vector(x + xs * dir.getBlockX()
* i, y + ys * dir.getBlockY() * i, z + zs
* dir.getBlockZ() * i);
if (setBlock(pos, block)) {
++affected;
} }
} OperationHelper.completeLegacy(copy);
} return copy.getAffected();
}
}
}
return affected;
} }
/** /**