mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-09-06 15:58:20 +00:00
Added EditSession.moveRegion.
This commit is contained in:
parent
cd5f832adf
commit
c1396a2468
@ -44,6 +44,7 @@ import com.sk89q.worldedit.masks.Mask;
|
|||||||
import com.sk89q.worldedit.patterns.Pattern;
|
import com.sk89q.worldedit.patterns.Pattern;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||||
import com.sk89q.worldedit.util.TreeGenerator;
|
import com.sk89q.worldedit.util.TreeGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1835,6 +1836,54 @@ public class EditSession {
|
|||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move a region.
|
||||||
|
*
|
||||||
|
* @param region
|
||||||
|
* @param dir
|
||||||
|
* @param distance
|
||||||
|
* @param copyAir
|
||||||
|
* @param replace
|
||||||
|
* @return number of blocks moved
|
||||||
|
* @throws MaxChangedBlocksException
|
||||||
|
* @throws RegionOperationException
|
||||||
|
*/
|
||||||
|
public int moveRegion(Region region, Vector dir, int distance,
|
||||||
|
boolean copyAir, BaseBlock replace)
|
||||||
|
throws MaxChangedBlocksException, RegionOperationException {
|
||||||
|
int affected = 0;
|
||||||
|
|
||||||
|
final Vector shift = dir.multiply(distance);
|
||||||
|
|
||||||
|
final Region newRegion = region.clone();
|
||||||
|
newRegion.shift(shift);
|
||||||
|
|
||||||
|
final Map<Vector, BaseBlock> delayed = new LinkedHashMap<Vector, BaseBlock>();
|
||||||
|
|
||||||
|
for (Vector pos : region) {
|
||||||
|
final BaseBlock block = getBlock(pos);
|
||||||
|
|
||||||
|
if (!block.isAir() || copyAir) {
|
||||||
|
final Vector newPos = pos.add(shift);
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
setBlock(entry.getKey(), entry.getValue());
|
||||||
|
++affected;
|
||||||
|
}
|
||||||
|
|
||||||
|
return affected;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a cuboid region.
|
* Move a cuboid region.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user