mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-01-30 12:51:17 +08:00
Fix selecting at 0,0,0 or radius 0 cyl/ellipse (#1734)
This commit is contained in:
parent
876108fdb3
commit
5a7cbfd6ef
@ -55,6 +55,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
protected static final transient NumberFormat NUMBER_FORMAT;
|
||||
protected transient CylinderRegion region;
|
||||
protected transient boolean selectedCenter;
|
||||
protected transient boolean selectedRadius;
|
||||
|
||||
static {
|
||||
NUMBER_FORMAT = (NumberFormat) NumberFormat.getInstance().clone();
|
||||
@ -89,6 +91,8 @@ public CylinderRegionSelector(RegionSelector oldSelector) {
|
||||
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
|
||||
|
||||
region = new CylinderRegion(cylSelector.region);
|
||||
selectedCenter = cylSelector.selectedCenter;
|
||||
selectedRadius = cylSelector.selectedRadius;
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
@ -106,6 +110,9 @@ public CylinderRegionSelector(RegionSelector oldSelector) {
|
||||
|
||||
region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
|
||||
region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
|
||||
|
||||
selectedCenter = true;
|
||||
selectedRadius = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +133,9 @@ public CylinderRegionSelector(@Nullable World world, BlockVector2 center, Vector
|
||||
|
||||
region.setMinimumY(Math.min(minY, maxY));
|
||||
region.setMaximumY(Math.max(minY, maxY));
|
||||
|
||||
selectedCenter = true;
|
||||
selectedRadius = true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -141,7 +151,7 @@ public void setWorld(@Nullable World world) {
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) {
|
||||
if (!region.getCenter().equals(Vector3.ZERO) && position.equals(region.getCenter().toBlockPoint())) {
|
||||
if (selectedCenter && position.equals(region.getCenter().toBlockPoint()) && !selectedRadius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -149,22 +159,26 @@ public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) {
|
||||
region.setCenter(position.toBlockVector2());
|
||||
region.setY(position.getBlockY());
|
||||
|
||||
selectedCenter = true;
|
||||
selectedRadius = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) {
|
||||
Vector3 center = region.getCenter();
|
||||
if (center.equals(Vector3.ZERO)) {
|
||||
if (!selectedCenter) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Vector2 diff = position.toVector3().subtract(center).toVector2();
|
||||
final Vector2 diff = position.toVector3().subtract(region.getCenter()).toVector2();
|
||||
final Vector2 minRadius = diff.getMaximum(diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
|
||||
region.setY(position.getBlockY());
|
||||
|
||||
selectedRadius = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -177,9 +191,7 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) {
|
||||
Vector3 center = region.getCenter();
|
||||
|
||||
if (!center.equals(Vector3.ZERO)) {
|
||||
if (selectedCenter) {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.cylinder.explain.secondary",
|
||||
TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getX())),
|
||||
@ -224,7 +236,8 @@ public CylinderRegion getIncompleteRegion() {
|
||||
|
||||
@Override
|
||||
public boolean isDefined() {
|
||||
return !region.getRadius().equals(Vector2.ZERO);
|
||||
// selectedCenter is implied by selectedRadius
|
||||
return selectedRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
protected transient EllipsoidRegion region;
|
||||
protected transient boolean started = false;
|
||||
protected transient boolean selectedRadius = false;
|
||||
|
||||
/**
|
||||
* Create a new selector with a {@code null} world.
|
||||
@ -80,6 +81,7 @@ public EllipsoidRegionSelector(RegionSelector oldSelector) {
|
||||
|
||||
region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
|
||||
started = ellipsoidRegionSelector.started;
|
||||
selectedRadius = ellipsoidRegionSelector.selectedRadius;
|
||||
} else {
|
||||
Region oldRegion;
|
||||
try {
|
||||
@ -95,6 +97,7 @@ public EllipsoidRegionSelector(RegionSelector oldSelector) {
|
||||
region.setCenter(center);
|
||||
region.setRadius(pos2.subtract(center).toVector3());
|
||||
started = true;
|
||||
selectedRadius = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +113,9 @@ public EllipsoidRegionSelector(@Nullable World world, BlockVector3 center, Vecto
|
||||
|
||||
region.setCenter(center);
|
||||
region.setRadius(radius);
|
||||
|
||||
started = true;
|
||||
selectedRadius = true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -125,13 +131,14 @@ public void setWorld(@Nullable World world) {
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) {
|
||||
if (position.equals(region.getCenter().toBlockPoint()) && region.getRadius().lengthSq() == 0) {
|
||||
if (started && position.equals(region.getCenter().toBlockPoint()) && !selectedRadius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region.setCenter(position);
|
||||
region.setRadius(Vector3.ZERO);
|
||||
started = true;
|
||||
selectedRadius = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -145,6 +152,9 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) {
|
||||
final Vector3 diff = position.toVector3().subtract(region.getCenter());
|
||||
final Vector3 minRadius = diff.getMaximum(diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
|
||||
selectedRadius = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -191,7 +201,8 @@ public void explainRegionAdjust(Actor player, LocalSession session) {
|
||||
|
||||
@Override
|
||||
public boolean isDefined() {
|
||||
return started && region.getRadius().lengthSq() > 0;
|
||||
// started implied by selectedRadius
|
||||
return selectedRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,9 +59,11 @@ public SphereRegionSelector(@Nullable World world) {
|
||||
*/
|
||||
public SphereRegionSelector(RegionSelector oldSelector) {
|
||||
super(oldSelector);
|
||||
final Vector3 radius = region.getRadius();
|
||||
final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
|
||||
region.setRadius(Vector3.at(radiusScalar, radiusScalar, radiusScalar));
|
||||
if (selectedRadius) {
|
||||
final Vector3 radius = region.getRadius();
|
||||
final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
|
||||
region.setRadius(Vector3.at(radiusScalar, radiusScalar, radiusScalar));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,6 +86,8 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) {
|
||||
final double radiusScalar = Math.ceil(position.toVector3().distance(region.getCenter()));
|
||||
region.setRadius(Vector3.at(radiusScalar, radiusScalar, radiusScalar));
|
||||
|
||||
selectedRadius = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user