Skip to content

Commit

Permalink
Fix negative height cones.
Browse files Browse the repository at this point in the history
Despite the description/doc stating that negative heights would generate inverted cones, this wasn't actually implemented.
  • Loading branch information
wizjany committed Mar 3, 2025
1 parent cd2ddef commit a9819ca
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1832,9 +1832,10 @@ public int makeCone(BlockVector3 pos, Pattern block, double radiusX, double radi
final double radiusXPow = Math.pow(radiusX, 2);
final double radiusZPow = Math.pow(radiusZ, 2);
final double heightPow = Math.pow(height, 2);
final int layers = Math.abs(height);

for (int y = 0; y < height; ++y) {
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - height, 2) / heightPow;
for (int y = 0; y < layers; ++y) {
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - layers, 2) / heightPow;

forX:
for (int x = 0; x <= ceilRadiusX; ++x) {
Expand All @@ -1856,25 +1857,26 @@ public int makeCone(BlockVector3 pos, Pattern block, double radiusX, double radi
double xNext = Math.pow(x + thickness, 2) / radiusXPow
+ zSquaredOverRadiusZ - ySquaredMinusHeightOverHeightSquared;
double yNext = xSquaredOverRadiusX + zSquaredOverRadiusZ
- Math.pow(y + thickness - height, 2) / heightPow;
- Math.pow(y + thickness - layers, 2) / heightPow;
double zNext = xSquaredOverRadiusX + Math.pow(z + thickness, 2)
/ radiusZPow - ySquaredMinusHeightOverHeightSquared;
if (xNext <= 0 && zNext <= 0 && (yNext <= 0 && y + thickness != height)) {
if (xNext <= 0 && zNext <= 0 && (yNext <= 0 && y + thickness != layers)) {
continue;
}
}

if (distanceFromOriginMinusHeightSquared <= 0) {
if (setBlock(pos.add(x, y, z), block)) {
int yOffset = height < 0 ? -y : y;
if (setBlock(pos.add(x, yOffset, z), block)) {
++affected;
}
if (setBlock(pos.add(-x, y, z), block)) {
if (setBlock(pos.add(-x, yOffset, z), block)) {
++affected;
}
if (setBlock(pos.add(x, y, -z), block)) {
if (setBlock(pos.add(x, yOffset, -z), block)) {
++affected;
}
if (setBlock(pos.add(-x, y, -z), block)) {
if (setBlock(pos.add(-x, yOffset, -z), block)) {
++affected;
}
}
Expand Down

0 comments on commit a9819ca

Please sign in to comment.