mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-17 02:04:04 +00:00
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:
@@ -19,19 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.iterator.RegionIterator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractRegion implements Region {
|
||||
|
||||
|
@@ -19,20 +19,22 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An axis-aligned cuboid. It can be defined using two corners of the cuboid.
|
||||
*/
|
||||
@@ -40,6 +42,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
private Vector pos1;
|
||||
private Vector pos2;
|
||||
private boolean useOldIterator;
|
||||
private int minX, minY, minZ, maxX, maxY, maxZ;
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid using two corners of the cuboid.
|
||||
@@ -64,9 +68,20 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
checkNotNull(pos2);
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
if (pos1 instanceof Location) {
|
||||
Extent extent = ((Location) pos1).getExtent();
|
||||
if (extent instanceof World) setWorld((World) extent);
|
||||
} else if (pos2 instanceof Location) {
|
||||
Extent extent = ((Location) pos2).getExtent();
|
||||
if (extent instanceof World) setWorld((World) extent);
|
||||
}
|
||||
recalculate();
|
||||
}
|
||||
|
||||
public void setUseOldIterator(boolean useOldIterator) {
|
||||
this.useOldIterator = useOldIterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first cuboid-defining corner.
|
||||
*
|
||||
@@ -83,6 +98,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
*/
|
||||
public void setPos1(Vector pos1) {
|
||||
this.pos1 = pos1;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,14 +117,26 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
*/
|
||||
public void setPos2(Vector pos2) {
|
||||
this.pos2 = pos2;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamps the cuboid according to boundaries of the world.
|
||||
*/
|
||||
private void recalculate() {
|
||||
pos1 = pos1.clampY(0, world == null ? 255 : world.getMaxY());
|
||||
pos2 = pos2.clampY(0, world == null ? 255 : world.getMaxY());
|
||||
protected void recalculate() {
|
||||
if (pos1 == null || pos2 == null) {
|
||||
return;
|
||||
}
|
||||
pos1 = pos1.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY());
|
||||
pos2 = pos2.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY());
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
minX = min.getBlockX();
|
||||
minY = min.getBlockY();
|
||||
minZ = min.getBlockZ();
|
||||
maxX = max.getBlockX();
|
||||
maxY = max.getBlockY();
|
||||
maxZ = max.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,16 +150,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
return new RegionIntersection(
|
||||
// Project to Z-Y plane
|
||||
new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())),
|
||||
new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())),
|
||||
new CuboidRegion(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())),
|
||||
new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())),
|
||||
|
||||
// Project to X-Y plane
|
||||
new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())),
|
||||
new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ())),
|
||||
new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())),
|
||||
new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), max.getZ())),
|
||||
|
||||
// Project to the X-Z plane
|
||||
new CuboidRegion(pos1.setY(min.getY()), pos2.setY(min.getY())),
|
||||
new CuboidRegion(pos1.setY(max.getY()), pos2.setY(max.getY())));
|
||||
new CuboidRegion(new Vector(pos1.getX(), min.getY(), pos1.getZ()), new Vector(pos2.getX(), min.getY(), pos2.getZ())),
|
||||
new CuboidRegion(new Vector(pos1.getX(), max.getY(), pos1.getZ()), new Vector(pos2.getX(), max.getY(), pos2.getZ())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,12 +174,12 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
return new RegionIntersection(
|
||||
// Project to Z-Y plane
|
||||
new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())),
|
||||
new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())),
|
||||
new CuboidRegion(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())),
|
||||
new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())),
|
||||
|
||||
// Project to X-Y plane
|
||||
new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())),
|
||||
new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ())));
|
||||
new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())),
|
||||
new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), max.getZ())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,6 +308,66 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
recalculate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Vector2D> getChunks() {
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
final int maxX = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
|
||||
final int minX = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
|
||||
final int maxZ = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
|
||||
final int minZ = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
|
||||
final int size = (maxX - minX + 1) * (maxZ - minZ + 1);
|
||||
|
||||
return new AbstractSet<Vector2D>() {
|
||||
@Override
|
||||
public Iterator<Vector2D> iterator() {
|
||||
return new Iterator<Vector2D>() {
|
||||
private MutableBlockVector2D pos = new MutableBlockVector2D().setComponents(maxX + 1, maxZ);
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return pos != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2D next() {
|
||||
Vector2D result = pos;
|
||||
// calc next
|
||||
pos.setComponents(pos.getX() - 1, pos.getZ());
|
||||
if (pos.getX() <= minX) {
|
||||
if (pos.getZ() == minZ) {
|
||||
pos = null;
|
||||
} else if (pos.getX() < minX) {
|
||||
pos.setComponents(maxX, pos.getZ() - 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("This set is immutable.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if (o instanceof Vector2D) {
|
||||
Vector2D cv = (Vector2D) o;
|
||||
return cv.getX() >= minX && cv.getX() <= maxX && cv.getZ() >= minZ && cv.getZ() <= maxZ;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shift(Vector change) throws RegionOperationException {
|
||||
pos1 = pos1.add(change);
|
||||
@@ -288,33 +376,17 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
recalculate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Vector2D> getChunks() {
|
||||
Set<Vector2D> chunks = new HashSet<>();
|
||||
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
|
||||
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
|
||||
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
|
||||
chunks.add(new BlockVector2D(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Vector> getChunkCubes() {
|
||||
Set<Vector> chunks = new HashSet<>();
|
||||
Set chunks = new LocalBlockVectorSet();
|
||||
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
|
||||
for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
|
||||
for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
|
||||
for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) {
|
||||
chunks.add(new BlockVector(x, y, z));
|
||||
for (int x = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x >= min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; --x) {
|
||||
for (int z = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z >= min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; --z) {
|
||||
for (int y = max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y >= min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; --y) {
|
||||
chunks.add(new Vector(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,46 +396,166 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public boolean contains(Vector position) {
|
||||
double x = position.getX();
|
||||
double y = position.getY();
|
||||
double z = position.getZ();
|
||||
return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
|
||||
Vector min = getMinimumPoint();
|
||||
Vector max = getMaximumPoint();
|
||||
// private int ly = Integer.MIN_VALUE;
|
||||
// private int lz = Integer.MIN_VALUE;
|
||||
// private boolean lr, lry, lrz;
|
||||
|
||||
return x >= min.getBlockX() && x <= max.getBlockX()
|
||||
&& y >= min.getBlockY() && y <= max.getBlockY()
|
||||
&& z >= min.getBlockZ() && z <= max.getBlockZ();
|
||||
@Override
|
||||
public boolean contains(int x, int y, int z) {
|
||||
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ && y >= this.minY && y <= this.maxY;
|
||||
// if (z != lz) {
|
||||
// lz = z;
|
||||
// lrz = z >= this.minZ && z <= this.maxZ;
|
||||
// if (y != ly) {
|
||||
// ly = y;
|
||||
// lry = y >= this.minY && y <= this.maxY;
|
||||
// }
|
||||
// lr = lrz && lry;
|
||||
// } else if (y != ly) {
|
||||
// ly = y;
|
||||
// lry = y >= this.minY && y <= this.maxY;
|
||||
// lr = lrz && lry;
|
||||
// }
|
||||
// return lr && (x >= this.minX && x <= this.maxX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int x, int z) {
|
||||
return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector> iterator() {
|
||||
if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) {
|
||||
return iterator_old();
|
||||
}
|
||||
return new Iterator<BlockVector>() {
|
||||
final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
|
||||
private Vector min = getMinimumPoint();
|
||||
private Vector max = getMaximumPoint();
|
||||
|
||||
int bx = min.getBlockX();
|
||||
int by = min.getBlockY();
|
||||
int bz = min.getBlockZ();
|
||||
|
||||
int tx = max.getBlockX();
|
||||
int ty = max.getBlockY();
|
||||
int tz = max.getBlockZ();
|
||||
|
||||
private int x = min.getBlockX();
|
||||
private int y = min.getBlockY();
|
||||
private int z = min.getBlockZ();
|
||||
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
int cbx = Math.max(bx, cx << 4);
|
||||
int cbz = Math.max(bz, cz << 4);
|
||||
int ctx = Math.min(tx, 15 + (cx << 4));
|
||||
int ctz = Math.min(tz, 15 + (cz << 4));
|
||||
|
||||
public boolean hasNext = true;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector next() {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
mutable.mutZ(z);
|
||||
if (++x > ctx) {
|
||||
if (++z > ctz) {
|
||||
if (++y > ty) {
|
||||
y = by;
|
||||
if (x > tx) {
|
||||
x = bx;
|
||||
if (z > tz) {
|
||||
if (!hasNext) {
|
||||
throw new NoSuchElementException("End of iterator") {
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
x = tx;
|
||||
y = ty;
|
||||
hasNext = false;
|
||||
return mutable;
|
||||
}
|
||||
} else {
|
||||
z = cbz;
|
||||
}
|
||||
cx = x >> 4;
|
||||
cz = z >> 4;
|
||||
cbx = Math.max(bx, cx << 4);
|
||||
cbz = Math.max(bz, cz << 4);
|
||||
ctx = Math.min(tx, 15 + (cx << 4));
|
||||
ctz = Math.min(tz, 15 + (cz << 4));
|
||||
} else {
|
||||
x = cbx;
|
||||
z = cbz;
|
||||
}
|
||||
} else {
|
||||
x = cbx;
|
||||
}
|
||||
}
|
||||
return mutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Iterator<BlockVector> iterator_old() {
|
||||
final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
|
||||
return new Iterator<BlockVector>() {
|
||||
private Vector min = getMinimumPoint();
|
||||
private Vector max = getMaximumPoint();
|
||||
private int nextX = min.getBlockX();
|
||||
private int nextY = min.getBlockY();
|
||||
private int nextZ = min.getBlockZ();
|
||||
private boolean hasNext = true;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (nextX != Integer.MIN_VALUE);
|
||||
return hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
BlockVector answer = new BlockVector(nextX, nextY, nextZ);
|
||||
mutable.mutX(nextX);
|
||||
mutable.mutY(nextY);
|
||||
mutable.mutZ(nextZ);
|
||||
if (++nextX > max.getBlockX()) {
|
||||
nextX = min.getBlockX();
|
||||
if (++nextY > max.getBlockY()) {
|
||||
nextY = min.getBlockY();
|
||||
if (++nextZ > max.getBlockZ()) {
|
||||
nextX = Integer.MIN_VALUE;
|
||||
if (++nextZ > max.getBlockZ()) {
|
||||
nextZ = min.getBlockZ();
|
||||
if (++nextY > max.getBlockY()) {
|
||||
if (!hasNext) {
|
||||
throw new NoSuchElementException("End of iterator") {
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
nextX = max.getBlockX();
|
||||
nextZ = max.getBlockZ();
|
||||
nextY = max.getBlockY();
|
||||
hasNext = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
return mutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -375,33 +567,48 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public Iterable<Vector2D> asFlatRegion() {
|
||||
return () -> new Iterator<Vector2D>() {
|
||||
private Vector min = getMinimumPoint();
|
||||
private Vector max = getMaximumPoint();
|
||||
private int nextX = min.getBlockX();
|
||||
private int nextZ = min.getBlockZ();
|
||||
|
||||
return new Iterable<Vector2D>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (nextX != Integer.MIN_VALUE);
|
||||
}
|
||||
public Iterator<Vector2D> iterator() {
|
||||
MutableBlockVector2D mutable = new MutableBlockVector2D();
|
||||
return new Iterator<Vector2D>() {
|
||||
private Vector min = getMinimumPoint();
|
||||
private Vector max = getMaximumPoint();
|
||||
private int nextX = min.getBlockX();
|
||||
private int nextZ = min.getBlockZ();
|
||||
|
||||
@Override
|
||||
public Vector2D next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
Vector2D answer = new Vector2D(nextX, nextZ);
|
||||
if (++nextX > max.getBlockX()) {
|
||||
nextX = min.getBlockX();
|
||||
if (++nextZ > max.getBlockZ()) {
|
||||
nextX = Integer.MIN_VALUE;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (nextZ != Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
@Override
|
||||
public Vector2D next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
Vector2D answer = mutable.setComponents(nextX, nextZ);
|
||||
if (++nextX > max.getBlockX()) {
|
||||
nextX = min.getBlockX();
|
||||
if (++nextZ > max.getBlockZ()) {
|
||||
if (nextZ == Integer.MIN_VALUE) {
|
||||
throw new NoSuchElementException("End of iterator") {
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
nextZ = Integer.MAX_VALUE;
|
||||
nextX = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -428,10 +635,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
return new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint());
|
||||
}
|
||||
|
||||
public static boolean contains(CuboidRegion region) {
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
return region.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ()) && region.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a cuboid from the center.
|
||||
*
|
||||
* @param origin the origin
|
||||
* @param origin the origin
|
||||
* @param apothem the apothem, where 0 is the minimum value to make a 1x1 cuboid
|
||||
* @return a cuboid region
|
||||
*/
|
||||
@@ -441,4 +654,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
Vector size = new Vector(1, 1, 1).multiply(apothem);
|
||||
return new CuboidRegion(origin.subtract(size), origin.add(size));
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return CuboidRegion.class;
|
||||
}
|
||||
}
|
@@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
@@ -34,13 +32,16 @@ import com.sk89q.worldedit.world.World;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents a cylindrical region.
|
||||
*/
|
||||
public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
private Vector2D center;
|
||||
private Vector2D radius;
|
||||
private BlockVector2D center;
|
||||
private BlockVector2D radius;
|
||||
private Vector2D radiusInverse;
|
||||
private int minY;
|
||||
private int maxY;
|
||||
private boolean hasY = false;
|
||||
@@ -104,7 +105,17 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public Vector getCenter() {
|
||||
return center.toVector((maxY + minY) / 2);
|
||||
return center.toVector((getMaximumY() + getMinimumY()) / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main center point of the region
|
||||
*
|
||||
* @deprecated replaced by {@link #setCenter(Vector2D)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCenter(Vector center) {
|
||||
setCenter(center.toVector2D());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +124,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
* @param center the center point
|
||||
*/
|
||||
public void setCenter(Vector2D center) {
|
||||
this.center = center;
|
||||
this.center = new BlockVector2D(center);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +142,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
* @param radius the radius along the X and Z axes
|
||||
*/
|
||||
public void setRadius(Vector2D radius) {
|
||||
this.radius = radius.add(0.5, 0.5);
|
||||
this.radius = radius.add(0.5, 0.5).toBlockVector2D();
|
||||
this.radiusInverse = Vector2D.ONE.divide(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,21 +177,28 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return center.subtract(getRadius()).toVector(minY);
|
||||
return center.subtract(getRadius()).toVector(getMinimumY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMaximumPoint() {
|
||||
return center.add(getRadius()).toVector(maxY);
|
||||
return center.add(getRadius()).toVector(getMaximumY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumY() {
|
||||
int worldMax = world != null ? world.getMaxY() - 1 : 255;
|
||||
if (maxY > worldMax) {
|
||||
return maxY = worldMax;
|
||||
}
|
||||
return maxY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
if (minY < 0) {
|
||||
return minY = 0;
|
||||
}
|
||||
return minY;
|
||||
}
|
||||
|
||||
@@ -195,7 +214,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return maxY - minY + 1;
|
||||
return getMaximumY() - getMinimumY() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,8 +253,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
*/
|
||||
@Override
|
||||
public void expand(Vector... changes) throws RegionOperationException {
|
||||
center = center.add(calculateDiff2D(changes));
|
||||
radius = radius.add(calculateChanges2D(changes));
|
||||
center = center.add(calculateDiff2D(changes)).toBlockVector2D();
|
||||
radius = radius.add(calculateChanges2D(changes)).toBlockVector2D();
|
||||
this.radiusInverse = Vector2D.ONE.divide(radius);
|
||||
for (Vector change : changes) {
|
||||
int changeY = change.getBlockY();
|
||||
if (changeY > 0) {
|
||||
@@ -254,9 +274,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
*/
|
||||
@Override
|
||||
public void contract(Vector... changes) throws RegionOperationException {
|
||||
center = center.subtract(calculateDiff2D(changes));
|
||||
center = center.subtract(calculateDiff2D(changes)).toBlockVector2D();
|
||||
Vector2D newRadius = radius.subtract(calculateChanges2D(changes));
|
||||
radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius);
|
||||
radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius).toBlockVector2D();
|
||||
this.radiusInverse = Vector2D.ONE.divide(radius);
|
||||
for (Vector change : changes) {
|
||||
int height = maxY - minY;
|
||||
int changeY = change.getBlockY();
|
||||
@@ -270,7 +291,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public void shift(Vector change) throws RegionOperationException {
|
||||
center = center.add(change.toVector2D());
|
||||
center = center.add(change.toVector2D()).toBlockVector2D();
|
||||
|
||||
int changeY = change.getBlockY();
|
||||
maxY += changeY;
|
||||
@@ -282,12 +303,17 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Vector position) {
|
||||
final int blockY = position.getBlockY();
|
||||
if (blockY < minY || blockY > maxY) {
|
||||
final int pt = position.getBlockY();
|
||||
if (pt < getMinimumY() || pt > getMaximumY()) {
|
||||
return false;
|
||||
}
|
||||
int px = position.getBlockX();
|
||||
int pz = position.getBlockZ();
|
||||
|
||||
return position.toVector2D().subtract(center).divide(radius).lengthSq() <= 1;
|
||||
double dx = Math.abs(px - center.getBlockX()) * radiusInverse.getX();
|
||||
double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ();
|
||||
|
||||
return dx * dx + dz * dz <= 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +347,12 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
|
||||
@Override
|
||||
public Iterable<Vector2D> asFlatRegion() {
|
||||
return () -> new FlatRegionIterator(CylinderRegion.this);
|
||||
return new Iterable<Vector2D>() {
|
||||
@Override
|
||||
public Iterator<Vector2D> iterator() {
|
||||
return new FlatRegionIterator(CylinderRegion.this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,4 +395,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
return new CylinderRegion(center, radiusVec, minY, maxY);
|
||||
}
|
||||
|
||||
public static Class<CylinderRegion> inject() {
|
||||
return CylinderRegion.class;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,104 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IDelegateRegion extends Region {
|
||||
|
||||
public Region getRegion();
|
||||
|
||||
@Override
|
||||
default Iterator<BlockVector> iterator() {
|
||||
return getRegion().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Vector getMinimumPoint() {
|
||||
return getRegion().getMinimumPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Vector getMaximumPoint() {
|
||||
return getRegion().getMaximumPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Vector getCenter() {
|
||||
return getRegion().getCenter();
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getArea() {
|
||||
return getRegion().getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getWidth() {
|
||||
return getRegion().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getHeight() {
|
||||
return getRegion().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
default int getLength() {
|
||||
return getRegion().getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
default void expand(Vector... changes) throws RegionOperationException {
|
||||
getRegion().expand(changes);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void contract(Vector... changes) throws RegionOperationException {
|
||||
getRegion().contract(changes);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void shift(Vector change) throws RegionOperationException {
|
||||
getRegion().shift(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean contains(Vector position) {
|
||||
return getRegion().contains(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Set<Vector2D> getChunks() {
|
||||
return getRegion().getChunks();
|
||||
}
|
||||
|
||||
@Override
|
||||
default Set<Vector> getChunkCubes() {
|
||||
return getRegion().getChunkCubes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
default World getWorld() {
|
||||
return getRegion().getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
default void setWorld(@Nullable World world) {
|
||||
getRegion().setWorld(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Region clone() {
|
||||
return getRegion().clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
default List<BlockVector2D> polygonize(int maxPoints) {
|
||||
return getRegion().polygonize(maxPoints);
|
||||
}
|
||||
}
|
@@ -19,17 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A region that contains no points.
|
||||
|
@@ -19,17 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a physical shape.
|
||||
*/
|
||||
@@ -40,14 +36,14 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
*
|
||||
* @return min. point
|
||||
*/
|
||||
Vector getMinimumPoint();
|
||||
public Vector getMinimumPoint();
|
||||
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return max. point
|
||||
*/
|
||||
Vector getMaximumPoint();
|
||||
public Vector getMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get the center point of a region.
|
||||
@@ -56,35 +52,35 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
*
|
||||
* @return center point
|
||||
*/
|
||||
Vector getCenter();
|
||||
public Vector getCenter();
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
int getArea();
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
int getWidth();
|
||||
public int getWidth();
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
int getHeight();
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
int getLength();
|
||||
public int getLength();
|
||||
|
||||
/**
|
||||
* Expand the region.
|
||||
@@ -92,7 +88,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
void expand(Vector... changes) throws RegionOperationException;
|
||||
public void expand(Vector... changes) throws RegionOperationException;
|
||||
|
||||
/**
|
||||
* Contract the region.
|
||||
@@ -100,7 +96,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
* @param changes array/arguments with multiple related changes
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
void contract(Vector... changes) throws RegionOperationException;
|
||||
public void contract(Vector... changes) throws RegionOperationException;
|
||||
|
||||
/**
|
||||
* Shift the region.
|
||||
@@ -108,7 +104,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
* @param change the change
|
||||
* @throws RegionOperationException
|
||||
*/
|
||||
void shift(Vector change) throws RegionOperationException;
|
||||
public void shift(Vector change) throws RegionOperationException;
|
||||
|
||||
/**
|
||||
* Returns true based on whether the region contains the point.
|
||||
@@ -116,42 +112,57 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
* @param position the position
|
||||
* @return true if contained
|
||||
*/
|
||||
boolean contains(Vector position);
|
||||
public boolean contains(Vector position);
|
||||
|
||||
default boolean contains(int x, int y, int z) {
|
||||
return contains(MutableBlockVector.get(x, y, z));
|
||||
}
|
||||
|
||||
default boolean contains(int x, int z) {
|
||||
return contains(MutableBlockVector.get(x, 0, z));
|
||||
}
|
||||
|
||||
default boolean isGlobal() {
|
||||
Vector pos1 = getMinimumPoint();
|
||||
Vector pos2 = getMaximumPoint();
|
||||
return pos1.getBlockX() == Integer.MIN_VALUE && pos1.getBlockZ() == Integer.MIN_VALUE && pos2.getBlockX() == Integer.MAX_VALUE && pos2.getBlockZ() == Integer.MAX_VALUE && pos1.getBlockY() <= 0 && pos2.getBlockY() >= 255;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of chunks.
|
||||
*
|
||||
* @return a list of chunk coordinates
|
||||
*/
|
||||
Set<Vector2D> getChunks();
|
||||
public Set<Vector2D> getChunks();
|
||||
|
||||
/**
|
||||
* Return a list of 16*16*16 chunks in a region
|
||||
*
|
||||
* @return the chunk cubes this region overlaps with
|
||||
*/
|
||||
Set<Vector> getChunkCubes();
|
||||
public Set<Vector> getChunkCubes();
|
||||
|
||||
/**
|
||||
* Sets the world that the selection is in.
|
||||
*
|
||||
* @return the world, or null
|
||||
*/
|
||||
@Nullable World getWorld();
|
||||
@Nullable
|
||||
public World getWorld();
|
||||
|
||||
/**
|
||||
* Sets the world that the selection is in.
|
||||
*
|
||||
* @param world the world, which may be null
|
||||
*/
|
||||
void setWorld(@Nullable World world);
|
||||
public void setWorld(@Nullable World world);
|
||||
|
||||
/**
|
||||
* Make a clone of the region.
|
||||
*
|
||||
* @return a cloned version
|
||||
*/
|
||||
Region clone();
|
||||
public Region clone();
|
||||
|
||||
/**
|
||||
* Polygonizes a cross-section or a 2D projection of the region orthogonal to the Y axis.
|
||||
@@ -159,5 +170,5 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
|
||||
* @param maxPoints maximum number of points to generate. -1 for no limit.
|
||||
* @return the points.
|
||||
*/
|
||||
List<BlockVector2D> polygonize(int maxPoints);
|
||||
public List<BlockVector2D> polygonize(int maxPoints);
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Region selectors create {@link Region}s from a series of "selected points."
|
||||
@@ -157,4 +157,13 @@ public interface RegionSelector {
|
||||
*/
|
||||
public List<String> getInformationLines();
|
||||
|
||||
/**
|
||||
* Get the verticies
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
default List<Vector> getVerticies() throws IncompleteRegionException {
|
||||
return Collections.singletonList(getPrimaryPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
@@ -28,11 +26,12 @@ import com.sk89q.worldedit.math.transform.Identity;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Transforms another region according to a provided vector {@code Transform}.
|
||||
|
@@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
@@ -28,6 +26,8 @@ import com.sk89q.worldedit.regions.FlatRegion;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class FlatRegion3DIterator implements Iterator<BlockVector> {
|
||||
|
||||
private Iterator<Vector2D> flatIterator;
|
||||
|
@@ -19,14 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class FlatRegionIterator implements Iterator<Vector2D> {
|
||||
|
||||
private Region region;
|
||||
|
@@ -19,14 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class RegionIterator implements Iterator<BlockVector> {
|
||||
|
||||
private final Region region;
|
||||
|
@@ -19,10 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.polyhedron;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Edge {
|
||||
|
||||
private final Vector start;
|
||||
|
@@ -19,10 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.polyhedron;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Triangle {
|
||||
|
||||
private String tag = "Triangle";
|
||||
|
@@ -19,8 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
@@ -37,15 +36,12 @@ import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import java.util.*;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code ConvexPolyhedralRegion} from a user's selections.
|
||||
*/
|
||||
@@ -70,6 +66,11 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
region = new ConvexPolyhedralRegion(world);
|
||||
}
|
||||
|
||||
public ConvexPolyhedralRegionSelector(ConvexPolyhedralRegion region) {
|
||||
checkNotNull(region);
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new selector.
|
||||
*
|
||||
@@ -97,7 +98,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
|
||||
region = new ConvexPolyhedralRegion(oldRegion.getWorld());
|
||||
|
||||
for (final BlockVector2D pt : new ArrayList<>(oldRegion.polygonize(Integer.MAX_VALUE))) {
|
||||
for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(Integer.MAX_VALUE))) {
|
||||
region.addVertex(pt.toVector(minY));
|
||||
region.addVertex(pt.toVector(maxY));
|
||||
}
|
||||
@@ -106,6 +107,11 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vector> getVerticies() {
|
||||
return new ArrayList<>(region.getVertices());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
@@ -184,7 +190,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
List<String> ret = new ArrayList<>();
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ret.add("Vertices: "+region.getVertices().size());
|
||||
ret.add("Triangles: "+region.getTriangles().size());
|
||||
@@ -201,7 +207,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Started new selection with vertex "+pos+".");
|
||||
BBC.SELECTOR_POS.send(player, 1, pos, region.getArea());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,7 +218,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Added vertex " + pos + " to the selection.");
|
||||
BBC.SELECTOR_POS.send(player, region.getVertices().size(), pos, region.getArea());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,7 +246,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
Collection<Vector> vertices = region.getVertices();
|
||||
Collection<Triangle> triangles = region.getTriangles();
|
||||
|
||||
Map<Vector, Integer> vertexIds = new HashMap<>(vertices.size());
|
||||
Map<Vector, Integer> vertexIds = new HashMap<Vector, Integer>(vertices.size());
|
||||
int lastVertexId = -1;
|
||||
for (Vector vertex : vertices) {
|
||||
vertexIds.put(vertex, ++lastVertexId);
|
||||
@@ -272,4 +278,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return ConvexPolyhedralRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,12 +19,15 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Commands;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.SelectionCommands;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
@@ -33,20 +36,22 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code CuboidRegion} from a user's selections.
|
||||
*/
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
protected transient BlockVector position1;
|
||||
protected transient BlockVector position2;
|
||||
protected transient CuboidRegion region;
|
||||
public transient BlockVector position1;
|
||||
public transient BlockVector position2;
|
||||
public transient CuboidRegion region;
|
||||
|
||||
/**
|
||||
* Create a new region selector with a {@code null} world.
|
||||
@@ -88,7 +93,6 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
position1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||
position2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||
}
|
||||
|
||||
region.setPos1(position1);
|
||||
region.setPos2(position2);
|
||||
}
|
||||
@@ -96,7 +100,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
/**
|
||||
* Create a new region selector with the given two positions.
|
||||
*
|
||||
* @param world the world
|
||||
* @param world the world
|
||||
* @param position1 position 1
|
||||
* @param position2 position 2
|
||||
*/
|
||||
@@ -110,6 +114,11 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
region.setPos2(position2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vector> getVerticies() {
|
||||
return Arrays.asList(position1, position2);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
@@ -153,11 +162,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
checkNotNull(session);
|
||||
checkNotNull(pos);
|
||||
|
||||
Message msg;
|
||||
if (position1 != null && position2 != null) {
|
||||
player.print("First position set to " + position1 + " (" + region.getArea() + ").");
|
||||
msg = BBC.SELECTOR_POS.m(1, position1, region.getArea());
|
||||
} else {
|
||||
player.print("First position set to " + position1 + ".");
|
||||
msg = BBC.SELECTOR_POS.m(1, position1, "");
|
||||
}
|
||||
String prefix = WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/";
|
||||
String cmd = prefix + Commands.getAlias(SelectionCommands.class, "/pos1") + " " + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
|
||||
msg.suggestTip(cmd).send(player);
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
@@ -168,11 +181,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
checkNotNull(session);
|
||||
checkNotNull(pos);
|
||||
|
||||
Message msg;
|
||||
if (position1 != null && position2 != null) {
|
||||
player.print("Second position set to " + position2 + " (" + region.getArea() + ").");
|
||||
msg = BBC.SELECTOR_POS.m(2, position2, region.getArea());
|
||||
} else {
|
||||
player.print("Second position set to " + position2 + ".");
|
||||
msg = BBC.SELECTOR_POS.m(2, position2, "");
|
||||
}
|
||||
String prefix = WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/";
|
||||
String cmd = prefix + Commands.getAlias(SelectionCommands.class, "/pos2") + " " + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
|
||||
msg.suggestTip(cmd).send(player);
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
@@ -238,7 +255,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<>();
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (position1 != null) {
|
||||
lines.add("Position 1: " + position1);
|
||||
@@ -294,5 +311,8 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return CuboidRegionSelector.class;
|
||||
}
|
||||
}
|
@@ -19,8 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -36,13 +35,14 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code CylinderRegionSelector} from a user's selections.
|
||||
*/
|
||||
@@ -63,6 +63,11 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
this((World) null);
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(CylinderRegion region) {
|
||||
checkNotNull(region);
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new region selector.
|
||||
*
|
||||
@@ -165,7 +170,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new cylindrical selection at " + pos + ".");
|
||||
BBC.SELECTOR_CENTER.send(player, pos, 0);
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
@@ -175,9 +180,9 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
Vector center = region.getCenter();
|
||||
|
||||
if (!center.equals(Vector.ZERO)) {
|
||||
player.print("Radius set to " + NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ").");
|
||||
BBC.SELECTOR_RADIUS.send(player, NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()), region.getArea());
|
||||
} else {
|
||||
player.printError("You must select the center point before setting the radius.");
|
||||
BBC.SELECTION_WAND.send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,7 +238,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<>();
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (!region.getCenter().equals(Vector.ZERO)) {
|
||||
lines.add("Center: " + region.getCenter());
|
||||
@@ -279,4 +284,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return CylinderRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -34,12 +33,13 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code EllipsoidRegionSelector} from a user's selections.
|
||||
*/
|
||||
@@ -144,22 +144,14 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Center position set to " + region.getCenter() + ".");
|
||||
}
|
||||
BBC.SELECTOR_CENTER.send(player, region.getCenter(), region.getArea());
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius() + ".");
|
||||
}
|
||||
BBC.SELECTOR_RADIUS.send(player, region.getRadius(), region.getArea());
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
@@ -205,7 +197,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<>();
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
final Vector center = region.getCenter();
|
||||
if (center.lengthSq() > 0) {
|
||||
@@ -257,4 +249,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return region.getCenter().toBlockVector();
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return EllipsoidRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
@@ -26,7 +27,6 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -130,16 +130,19 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
player.print("Started selection at " + pos + " (" + region.getArea() + ").");
|
||||
BBC.SELECTOR_POS.send(player, 1, pos, region.getArea());
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
player.print("Extended selection to encompass " + pos + " (" + region.getArea() + ").");
|
||||
BBC.SELECTOR_EXPANDED.send(player, pos, region.getArea());
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return ExtendingCuboidRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
@@ -36,13 +35,14 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code Polygonal2DRegion} from a user's selections.
|
||||
*/
|
||||
@@ -67,6 +67,11 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
region = new Polygonal2DRegion(world);
|
||||
}
|
||||
|
||||
|
||||
public Polygonal2DRegionSelector(Polygonal2DRegion region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new selector from another one.
|
||||
*
|
||||
@@ -164,7 +169,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new polygon at " + pos + ".");
|
||||
BBC.SELECTOR_POS.send(player, 1, pos, region.getArea());
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
|
||||
@@ -173,7 +178,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
player.print("Added point #" + region.size() + " at " + pos + ".");
|
||||
BBC.SELECTOR_POS.send(player, region.size(), pos, region.getArea());
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
@@ -279,4 +284,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return Polygonal2DRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,13 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -86,11 +86,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius().getX() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius().getX() + ".");
|
||||
}
|
||||
BBC.SELECTOR_RADIUS.send(player, region.getRadius().getX(), region.getArea());
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
@@ -100,4 +96,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
return "sphere";
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return SphereRegionSelector.class;
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,10 @@ package com.sk89q.worldedit.regions.shape;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* Generates solid and hollow shapes according to materials returned by the
|
||||
@@ -92,4 +93,4 @@ public abstract class ArbitraryShape {
|
||||
return affected;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -20,8 +20,9 @@
|
||||
package com.sk89q.worldedit.regions.shape;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Generates solid and hollow shapes according to materials returned by the
|
||||
|
@@ -22,6 +22,7 @@ package com.sk89q.worldedit.regions.shape;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
|
||||
|
||||
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
@@ -29,10 +30,14 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
private final Vector unit;
|
||||
private final Vector zero2;
|
||||
private Vector current = new Vector();
|
||||
private EditSession editSession;
|
||||
private Extent extent;
|
||||
|
||||
public WorldEditExpressionEnvironment(EditSession editSession, Vector unit, Vector zero) {
|
||||
this.editSession = editSession;
|
||||
this((Extent) editSession, unit, zero);
|
||||
}
|
||||
|
||||
public WorldEditExpressionEnvironment(Extent extent, Vector unit, Vector zero) {
|
||||
this.extent = extent;
|
||||
this.unit = unit;
|
||||
this.zero2 = zero.add(0.5, 0.5, 0.5);
|
||||
}
|
||||
@@ -48,36 +53,39 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
|
||||
@Override
|
||||
public int getBlockType(double x, double y, double z) {
|
||||
return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId();
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(double x, double y, double z) {
|
||||
return 0;
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTypeAbs(double x, double y, double z) {
|
||||
return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId();
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockDataAbs(double x, double y, double z) {
|
||||
return 0;
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTypeRel(double x, double y, double z) {
|
||||
return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId();
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockDataRel(double x, double y, double z) {
|
||||
return 0;
|
||||
return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF;
|
||||
}
|
||||
|
||||
public void setCurrentBlock(Vector current) {
|
||||
this.current = current;
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return WorldEditExpressionEnvironment.class;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user