Copy paste/merge FAWE classes to this WorldEdit fork

- so certain people can look at the diff and complain about my sloppy code :(

Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
Jesse Boyd
2018-08-13 00:03:07 +10:00
parent a920c77cb8
commit a629d15c74
994 changed files with 117583 additions and 10745 deletions

View File

@ -21,11 +21,11 @@ package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.util.HashSet;
import java.util.Set;
@ -37,12 +37,15 @@ public class EllipsoidRegion extends AbstractRegion {
/**
* Stores the center.
*/
private Vector center;
private MutableBlockVector center;
/**
* Stores the radii plus 0.5 on each axis.
*/
private Vector radius;
private MutableBlockVector radius;
private MutableBlockVector radiusSqr;
private int radiusLengthSqr;
private boolean sphere;
/**
* Construct a new instance of this ellipsoid region.
@ -54,16 +57,17 @@ public class EllipsoidRegion extends AbstractRegion {
this(null, pos1, pos2);
}
/**
* Construct a new instance of this ellipsoid region.
*
* @param world the world
* @param world the world
* @param center the center
* @param radius the radius
*/
public EllipsoidRegion(World world, Vector center, Vector radius) {
super(world);
this.center = center;
this.center = new MutableBlockVector(center);
setRadius(radius);
}
@ -73,16 +77,17 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public Vector getMinimumPoint() {
return center.subtract(getRadius());
return center.subtract(getRadius()).clampY(0, 255);
}
@Override
public Vector getMaximumPoint() {
return center.add(getRadius());
return center.add(getRadius()).clampY(0, 255);
}
@Override
public int getArea() {
if (radius == null) return 0;
return (int) Math.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
}
@ -93,7 +98,7 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public int getHeight() {
return (int) (2 * radius.getY());
return Math.max((int) (2 * radius.getY()), 256);
}
@Override
@ -123,20 +128,20 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public void expand(Vector... changes) throws RegionOperationException {
center = center.add(calculateDiff(changes));
radius = radius.add(calculateChanges(changes));
center = new MutableBlockVector(center.add(calculateDiff(changes)));
setRadius(radius.add(calculateChanges(changes)));
}
@Override
public void contract(Vector... changes) throws RegionOperationException {
center = center.subtract(calculateDiff(changes));
center = new MutableBlockVector(center.subtract(calculateDiff(changes)));
Vector newRadius = radius.subtract(calculateChanges(changes));
radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius);
setRadius(Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius));
}
@Override
public void shift(Vector change) throws RegionOperationException {
center = center.add(change);
center = new MutableBlockVector(center.add(change));
}
/**
@ -155,7 +160,7 @@ public class EllipsoidRegion extends AbstractRegion {
* @param center the center
*/
public void setCenter(Vector center) {
this.center = center;
this.center = new MutableBlockVector(center);
}
/**
@ -164,6 +169,7 @@ public class EllipsoidRegion extends AbstractRegion {
* @return radii
*/
public Vector getRadius() {
if (radius == null) return null;
return radius.subtract(0.5, 0.5, 0.5);
}
@ -173,12 +179,19 @@ public class EllipsoidRegion extends AbstractRegion {
* @param radius the radius
*/
public void setRadius(Vector radius) {
this.radius = radius.add(0.5, 0.5, 0.5);
this.radius = new MutableBlockVector(radius.add(0.5, 0.5, 0.5));
radiusSqr = new MutableBlockVector(radius.multiply(radius));
radiusLengthSqr = radiusSqr.getBlockX();
if (radius.getBlockY() == radius.getBlockX() && radius.getBlockX() == radius.getBlockZ()) {
this.sphere = true;
} else {
this.sphere = false;
}
}
@Override
public Set<Vector2D> getChunks() {
final Set<Vector2D> chunks = new HashSet<>();
final Set<Vector2D> chunks = new HashSet<Vector2D>();
final Vector min = getMinimumPoint();
final Vector max = getMaximumPoint();
@ -191,8 +204,8 @@ public class EllipsoidRegion extends AbstractRegion {
}
chunks.add(new BlockVector2D(
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS
));
}
}
@ -202,7 +215,28 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public boolean contains(Vector position) {
return position.subtract(center).divide(radius).lengthSq() <= 1;
int cx = position.getBlockX() - center.getBlockX();
int cx2 = cx * cx;
if (cx2 > radiusSqr.getBlockX()) {
return false;
}
int cz = position.getBlockZ() - center.getBlockZ();
int cz2 = cz * cz;
if (cz2 > radiusSqr.getBlockZ()) {
return false;
}
int cy = position.getBlockY() - center.getBlockY();
int cy2 = cy * cy;
if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) {
return false;
}
if (sphere) {
return cx2 + cy2 + cz2 <= radiusLengthSqr;
}
double cxd = (double) cx / radius.getBlockX();
double cyd = (double) cy / radius.getBlockY();
double czd = (double) cz / radius.getBlockZ();
return cxd * cxd + cyd * cyd + czd * czd <= 1;
}
/**
@ -225,4 +259,7 @@ public class EllipsoidRegion extends AbstractRegion {
return (EllipsoidRegion) super.clone();
}
public static Class<EllipsoidRegion> inject() {
return EllipsoidRegion.class;
}
}