mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Add /center commmand
This commit is contained in:
parent
c759b9062c
commit
7fd5d1b61c
@ -1352,6 +1352,27 @@ public class EditSession {
|
||||
return affected;
|
||||
}
|
||||
|
||||
public int center(Region region, Pattern pattern)
|
||||
throws MaxChangedBlocksException {
|
||||
Vector center = region.getCenter();
|
||||
int x2 = center.getBlockX();
|
||||
int y2 = center.getBlockY();
|
||||
int z2 = center.getBlockZ();
|
||||
|
||||
int affected = 0;
|
||||
for (int x = (int) center.getX(); x <= x2; x++) {
|
||||
for (int y = (int) center.getY(); y <= y2; y++) {
|
||||
for (int z = (int) center.getZ(); z <= z2; z++) {
|
||||
if (setBlock(new Vector(x, y, z), pattern)) {
|
||||
affected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make faces of the region (as if it was a cuboid if it's not).
|
||||
*
|
||||
|
@ -144,6 +144,22 @@ public class RegionCommands {
|
||||
player.print(affected + " block(s) have been overlayed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "/center", "/middle" },
|
||||
usage = "<block>",
|
||||
desc = "Set the center block(s)",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public void center(CommandContext args, LocalSession session, LocalPlayer player,
|
||||
EditSession editSession) throws WorldEditException {
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
|
||||
int affected = editSession.center(region, pattern);
|
||||
player.print("Center set ("+ affected + " blocks changed)");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "/naturalize" },
|
||||
usage = "",
|
||||
|
@ -35,6 +35,11 @@ public abstract class AbstractRegion implements Region {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return getMinimumPoint().add(getMaximumPoint()).divide(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the iterator.
|
||||
*
|
||||
|
@ -87,6 +87,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return center.toVector((maxY + minY) / 2);
|
||||
}
|
||||
|
@ -175,6 +175,7 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
*
|
||||
* @return center
|
||||
*/
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return center;
|
||||
}
|
||||
|
@ -44,6 +44,15 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
*/
|
||||
public Vector getMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get the center point of a region.
|
||||
* Note: Coordinates will not be integers
|
||||
* if the corresponding lengths are even.
|
||||
*
|
||||
* @return center point
|
||||
*/
|
||||
public Vector getCenter();
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user