geforkt von Mirrors/FastAsyncWorldEdit
Add support for expand with reverse dir for Cylinder & Ellipsoid
Dieser Commit ist enthalten in:
Ursprung
760f77e681
Commit
857f721bb5
@ -271,8 +271,6 @@ public class SelectionCommands {
|
||||
public void expand(CommandContext args, LocalSession session, LocalPlayer player,
|
||||
EditSession editSession) throws WorldEditException {
|
||||
|
||||
Vector dir;
|
||||
|
||||
// Special syntax (//expand vert) to expand the selection between
|
||||
// sky and bedrock.
|
||||
if (args.getString(0).equalsIgnoreCase("vert")
|
||||
@ -295,6 +293,7 @@ public class SelectionCommands {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector dir;
|
||||
int change = args.getInteger(0);
|
||||
int reverseChange = 0;
|
||||
|
||||
@ -302,7 +301,7 @@ public class SelectionCommands {
|
||||
case 2:
|
||||
// Either a reverse amount or a direction
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
reverseChange = args.getInteger(1);
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player,
|
||||
@ -312,7 +311,7 @@ public class SelectionCommands {
|
||||
|
||||
case 3:
|
||||
// Both reverse amount and direction
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
reverseChange = args.getInteger(1);
|
||||
dir = we.getDirection(player,
|
||||
args.getString(2).toLowerCase());
|
||||
break;
|
||||
@ -322,10 +321,11 @@ public class SelectionCommands {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.expand(dir.multiply(change));
|
||||
|
||||
if (reverseChange != 0) {
|
||||
region.expand(dir.multiply(reverseChange));
|
||||
if (reverseChange == 0) {
|
||||
region.expand(dir.multiply(change));
|
||||
} else {
|
||||
region.expand(dir.multiply(change), dir.multiply(-reverseChange));
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||
@ -356,7 +356,7 @@ public class SelectionCommands {
|
||||
case 2:
|
||||
// Either a reverse amount or a direction
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
reverseChange = args.getInteger(1);
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player, args.getString(1).toLowerCase());
|
||||
@ -365,7 +365,7 @@ public class SelectionCommands {
|
||||
|
||||
case 3:
|
||||
// Both reverse amount and direction
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
reverseChange = args.getInteger(1);
|
||||
dir = we.getDirection(player, args.getString(2).toLowerCase());
|
||||
break;
|
||||
default:
|
||||
@ -375,9 +375,10 @@ public class SelectionCommands {
|
||||
try {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.contract(dir.multiply(change));
|
||||
if (reverseChange != 0) {
|
||||
region.contract(dir.multiply(reverseChange));
|
||||
if (reverseChange == 0) {
|
||||
region.contract(dir.multiply(change));
|
||||
} else {
|
||||
region.contract(dir.multiply(change), dir.multiply(-reverseChange));
|
||||
}
|
||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||
int newSize = region.getArea();
|
||||
|
@ -213,39 +213,28 @@ public class CylinderRegion extends AbstractRegion {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
|
||||
private Vector2D getTotalXZChanges(Vector... changes) throws RegionOperationException {
|
||||
private Vector2D calculateDiff2D(Vector... changes) throws RegionOperationException {
|
||||
Vector2D diff = new Vector2D();
|
||||
Vector2D total = new Vector2D();
|
||||
for (Vector change : changes) {
|
||||
diff = diff.add(change.toVector2D());
|
||||
}
|
||||
|
||||
if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
|
||||
throw new RegionOperationException("Cylinders changes must be even for each horizontal dimensions.");
|
||||
}
|
||||
|
||||
return diff.divide(2).floor();
|
||||
}
|
||||
|
||||
private Vector2D calculateChanges2D(Vector... changes) {
|
||||
Vector2D total = new Vector2D();
|
||||
for (Vector change : changes) {
|
||||
total = total.add(change.toVector2D().positive());
|
||||
}
|
||||
|
||||
if (diff.getBlockX() != 0 || diff.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders changes must be equal for both directions of each horizontal dimensions.");
|
||||
}
|
||||
|
||||
return total.divide(2).floor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void expand(Vector change) throws RegionOperationException {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders can only be expanded vertically.");
|
||||
}
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
maxY += changeY;
|
||||
} else {
|
||||
minY += changeY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
* Expand the region.
|
||||
@ -254,27 +243,15 @@ public class CylinderRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
radius = radius.add(getTotalXZChanges(changes));
|
||||
setCenter(getCenter().add(calculateDiff2D(changes).toVector()));
|
||||
radius = radius.add(calculateChanges2D(changes));
|
||||
for (Vector change : changes) {
|
||||
expand(new Vector(0, change.getBlockY(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract the region.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void contract(Vector change) throws RegionOperationException {
|
||||
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
|
||||
throw new RegionOperationException("Cylinders can only be expanded vertically.");
|
||||
}
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
minY += changeY;
|
||||
} else {
|
||||
maxY += changeY;
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
maxY += changeY;
|
||||
} else {
|
||||
minY += changeY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,10 +262,16 @@ public class CylinderRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
Vector2D newRadius = radius.subtract(getTotalXZChanges(changes));
|
||||
setCenter(getCenter().subtract(calculateDiff2D(changes).toVector()));
|
||||
Vector2D newRadius = radius.subtract(calculateChanges2D(changes));
|
||||
radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius);
|
||||
for (Vector change : changes) {
|
||||
contract(new Vector(0, change.getBlockY(), 0));
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
minY += changeY;
|
||||
} else {
|
||||
maxY += changeY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,30 +120,26 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return (int) (2 * radius.getZ());
|
||||
}
|
||||
|
||||
private Vector getTotalChanges(Vector... changes) throws RegionOperationException {
|
||||
Vector diff = new Vector();
|
||||
private Vector calculateDiff(Vector... changes) throws RegionOperationException {
|
||||
Vector diff = new Vector().add(changes);
|
||||
|
||||
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
|
||||
throw new RegionOperationException(
|
||||
"Ellipsoid changes must be even for each dimensions.");
|
||||
}
|
||||
|
||||
return diff.divide(2).floor();
|
||||
}
|
||||
|
||||
private Vector calculateChanges(Vector... changes) {
|
||||
Vector total = new Vector();
|
||||
for (Vector change : changes) {
|
||||
diff = diff.add(change);
|
||||
total = total.add(change.positive());
|
||||
}
|
||||
|
||||
if (diff.getBlockX() != 0 || diff.getBlockY() != 0 || diff.getBlockZ() != 0) {
|
||||
throw new RegionOperationException(
|
||||
"Ellipsoid changes must be equal for both directions of each dimensions.");
|
||||
}
|
||||
|
||||
return total.divide(2).floor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the ellipsoid in a direction.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void expand(Vector change) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
*
|
||||
@ -151,15 +147,8 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
radius = radius.add(getTotalChanges(changes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Contracts the ellipsoid in a direction.
|
||||
*
|
||||
* @param change
|
||||
*/
|
||||
public void contract(Vector change) {
|
||||
center = center.add(calculateDiff(changes));
|
||||
radius = radius.add(calculateChanges(changes));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +158,8 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
Vector newRadius = radius.subtract(getTotalChanges(changes));
|
||||
center = center.subtract(calculateDiff(changes));
|
||||
Vector newRadius = radius.subtract(calculateChanges(changes));
|
||||
radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius);
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren