Removed Point/BlockPoint to Vector/BlockVector.

This commit is contained in:
sk89q 2010-10-12 18:03:56 -07:00
parent c039e8e77d
commit 68dcce31f8
10 changed files with 158 additions and 158 deletions

View File

@ -30,9 +30,9 @@ import com.sk89q.worldedit.*;
*/ */
public class CuboidClipboard { public class CuboidClipboard {
private int[][][] data; private int[][][] data;
private Point min; private Vector min;
private Point max; private Vector max;
private Point origin; private Vector origin;
/** /**
* Constructs the region instance. The minimum and maximum points must be * Constructs the region instance. The minimum and maximum points must be
@ -42,7 +42,7 @@ public class CuboidClipboard {
* @param max * @param max
* @param origin * @param origin
*/ */
public CuboidClipboard(Point min, Point max, Point origin) { public CuboidClipboard(Vector min, Vector max, Vector origin) {
this.min = min; this.min = min;
this.max = max; this.max = max;
this.origin = origin; this.origin = origin;
@ -102,7 +102,7 @@ public class CuboidClipboard {
* @param noAir True to not paste air * @param noAir True to not paste air
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public void paste(EditSession editSession, Point newOrigin, boolean noAir) public void paste(EditSession editSession, Vector newOrigin, boolean noAir)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int offsetX = (int)(min.getX() - origin.getX() + newOrigin.getX()); int offsetX = (int)(min.getX() - origin.getX() + newOrigin.getX());
int offsetY = (int)(min.getY() - origin.getY() + newOrigin.getY()); int offsetY = (int)(min.getY() - origin.getY() + newOrigin.getY());
@ -168,7 +168,7 @@ public class CuboidClipboard {
} }
if (moveOrigin) { if (moveOrigin) {
min = new Point((int)offsetX + xm * count, min = new Vector((int)offsetX + xm * count,
(int)offsetY + ym * count, (int)offsetY + ym * count,
(int)offsetZ + zm * count); (int)offsetZ + zm * count);
} }
@ -238,7 +238,7 @@ public class CuboidClipboard {
* @throws SchematicException * @throws SchematicException
* @throws IOException * @throws IOException
*/ */
public static CuboidClipboard loadSchematic(String path, Point origin) public static CuboidClipboard loadSchematic(String path, Vector origin)
throws SchematicException, IOException { throws SchematicException, IOException {
FileInputStream stream = new FileInputStream(path); FileInputStream stream = new FileInputStream(path);
NBTInputStream nbtStream = new NBTInputStream(stream); NBTInputStream nbtStream = new NBTInputStream(stream);
@ -259,8 +259,8 @@ public class CuboidClipboard {
} }
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
Point min = origin; Vector min = origin;
Point max = new Point( Vector max = new Vector(
origin.getX() + xs - 1, origin.getX() + xs - 1,
origin.getY() + ys - 1, origin.getY() + ys - 1,
origin.getZ() + zs - 1 origin.getZ() + zs - 1

View File

@ -37,15 +37,15 @@ public class EditSession {
/** /**
* Stores the original blocks before modification. * Stores the original blocks before modification.
*/ */
private HashMap<BlockPoint,Integer> original = new HashMap<BlockPoint,Integer>(); private HashMap<BlockVector,Integer> original = new HashMap<BlockVector,Integer>();
/** /**
* Stores the current blocks. * Stores the current blocks.
*/ */
private HashMap<BlockPoint,Integer> current = new HashMap<BlockPoint,Integer>(); private HashMap<BlockVector,Integer> current = new HashMap<BlockVector,Integer>();
/** /**
* Queue. * Queue.
*/ */
private HashMap<BlockPoint,Integer> queue = new HashMap<BlockPoint,Integer>(); private HashMap<BlockVector,Integer> queue = new HashMap<BlockVector,Integer>();
/** /**
* The maximum number of blocks to change at a time. If this number is * The maximum number of blocks to change at a time. If this number is
* exceeded, a MaxChangedBlocksException exception will be * exceeded, a MaxChangedBlocksException exception will be
@ -98,7 +98,7 @@ public class EditSession {
* @param blockType * @param blockType
* @return Whether the block changed * @return Whether the block changed
*/ */
private boolean rawSetBlock(Point pt, int blockType) { private boolean rawSetBlock(Vector pt, int blockType) {
return etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(), return etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), blockType); pt.getBlockZ(), blockType);
} }
@ -116,7 +116,7 @@ public class EditSession {
*/ */
public boolean setBlock(int x, int y, int z, int blockType) public boolean setBlock(int x, int y, int z, int blockType)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
return setBlock(new Point(x, y, z), blockType); return setBlock(new Vector(x, y, z), blockType);
} }
/** /**
@ -128,7 +128,7 @@ public class EditSession {
* @param blockType * @param blockType
* @return Whether the block changed -- not entirely dependable * @return Whether the block changed -- not entirely dependable
*/ */
public boolean setBlock(Point pt, int blockType) public boolean setBlock(Vector pt, int blockType)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
if (!original.containsKey(pt)) { if (!original.containsKey(pt)) {
original.put(pt.toBlockPoint(), getBlock(pt)); original.put(pt.toBlockPoint(), getBlock(pt));
@ -150,7 +150,7 @@ public class EditSession {
* @param blockType * @param blockType
* @return * @return
*/ */
private boolean smartSetBlock(Point pt, int blockType) { private boolean smartSetBlock(Vector pt, int blockType) {
if (queued) { if (queued) {
if (blockType != 0 && queuedBlocks.contains(blockType) if (blockType != 0 && queuedBlocks.contains(blockType)
&& rawGetBlock(pt.add(0, -1, 0)) == 0) { && rawGetBlock(pt.add(0, -1, 0)) == 0) {
@ -171,7 +171,7 @@ public class EditSession {
* @param pt * @param pt
* @return Block type * @return Block type
*/ */
public int getBlock(Point pt) { public int getBlock(Vector pt) {
// In the case of the queue, the block may have not actually been // In the case of the queue, the block may have not actually been
// changed yet // changed yet
if (queued) { if (queued) {
@ -191,7 +191,7 @@ public class EditSession {
* @return Block type * @return Block type
*/ */
public int getBlock(int x, int y, int z) { public int getBlock(int x, int y, int z) {
return getBlock(new Point(x, y, z)); return getBlock(new Vector(x, y, z));
} }
/** /**
@ -200,7 +200,7 @@ public class EditSession {
* @param pt * @param pt
* @return Block type * @return Block type
*/ */
public int rawGetBlock(Point pt) { public int rawGetBlock(Vector pt) {
return etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); return etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
} }
@ -208,8 +208,8 @@ public class EditSession {
* Restores all blocks to their initial state. * Restores all blocks to their initial state.
*/ */
public void undo() { public void undo() {
for (Map.Entry<BlockPoint,Integer> entry : original.entrySet()) { for (Map.Entry<BlockVector,Integer> entry : original.entrySet()) {
BlockPoint pt = (BlockPoint)entry.getKey(); BlockVector pt = (BlockVector)entry.getKey();
smartSetBlock(pt, (int)entry.getValue()); smartSetBlock(pt, (int)entry.getValue());
} }
flushQueue(); flushQueue();
@ -219,8 +219,8 @@ public class EditSession {
* Sets to new state. * Sets to new state.
*/ */
public void redo() { public void redo() {
for (Map.Entry<BlockPoint,Integer> entry : current.entrySet()) { for (Map.Entry<BlockVector,Integer> entry : current.entrySet()) {
BlockPoint pt = (BlockPoint)entry.getKey(); BlockVector pt = (BlockVector)entry.getKey();
smartSetBlock(pt, (int)entry.getValue()); smartSetBlock(pt, (int)entry.getValue());
} }
flushQueue(); flushQueue();
@ -288,8 +288,8 @@ public class EditSession {
public void flushQueue() { public void flushQueue() {
if (!queued) { return; } if (!queued) { return; }
for (Map.Entry<BlockPoint,Integer> entry : queue.entrySet()) { for (Map.Entry<BlockVector,Integer> entry : queue.entrySet()) {
BlockPoint pt = (BlockPoint)entry.getKey(); BlockVector pt = (BlockVector)entry.getKey();
rawSetBlock(pt, (int)entry.getValue()); rawSetBlock(pt, (int)entry.getValue());
} }
} }
@ -305,7 +305,7 @@ public class EditSession {
* @param depth * @param depth
* @return number of blocks affected * @return number of blocks affected
*/ */
public int fillXZ(int x, int z, Point origin, int blockType, int radius, int depth) public int fillXZ(int x, int z, Vector origin, int blockType, int radius, int depth)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
double dist = Math.sqrt(Math.pow(origin.getX() - x, 2) + Math.pow(origin.getZ() - z, 2)); double dist = Math.sqrt(Math.pow(origin.getX() - x, 2) + Math.pow(origin.getZ() - z, 2));
int minY = origin.getBlockY() - depth + 1; int minY = origin.getBlockY() - depth + 1;
@ -315,7 +315,7 @@ public class EditSession {
return 0; return 0;
} }
if (getBlock(new Point(x, origin.getY(), z)) == 0) { if (getBlock(new Vector(x, origin.getY(), z)) == 0) {
affected = fillY(x, (int)origin.getY(), z, blockType, minY); affected = fillY(x, (int)origin.getY(), z, blockType, minY);
} else { } else {
return 0; return 0;
@ -345,7 +345,7 @@ public class EditSession {
int affected = 0; int affected = 0;
for (int y = cy; y >= minY; y--) { for (int y = cy; y >= minY; y--) {
Point pt = new Point(x, y, z); Vector pt = new Vector(x, y, z);
if (getBlock(pt) == 0) { if (getBlock(pt) == 0) {
setBlock(pt, blockType); setBlock(pt, blockType);
@ -366,7 +366,7 @@ public class EditSession {
* @param height * @param height
* @return number of blocks affected * @return number of blocks affected
*/ */
public int removeAbove(Point pos, int size, int height) throws public int removeAbove(Vector pos, int size, int height) throws
MaxChangedBlocksException { MaxChangedBlocksException {
int maxY = Math.min(127, pos.getBlockY() + height - 1); int maxY = Math.min(127, pos.getBlockY() + height - 1);
size--; size--;
@ -375,7 +375,7 @@ public class EditSession {
for (int x = (int)pos.getX() - size; x <= (int)pos.getX() + size; x++) { for (int x = (int)pos.getX() - size; x <= (int)pos.getX() + size; x++) {
for (int z = (int)pos.getZ() - size; z <= (int)pos.getZ() + size; z++) { for (int z = (int)pos.getZ() - size; z <= (int)pos.getZ() + size; z++) {
for (int y = (int)pos.getY(); y <= maxY; y++) { for (int y = (int)pos.getY(); y <= maxY; y++) {
Point pt = new Point(x, y, z); Vector pt = new Vector(x, y, z);
if (getBlock(pt) != 0) { if (getBlock(pt) != 0) {
setBlock(pt, 0); setBlock(pt, 0);
@ -396,7 +396,7 @@ public class EditSession {
* @param height * @param height
* @return number of blocks affected * @return number of blocks affected
*/ */
public int removeBelow(Point pos, int size, int height) throws public int removeBelow(Vector pos, int size, int height) throws
MaxChangedBlocksException { MaxChangedBlocksException {
int minY = Math.max(0, pos.getBlockY() - height); int minY = Math.max(0, pos.getBlockY() - height);
size--; size--;
@ -405,7 +405,7 @@ public class EditSession {
for (int x = (int)pos.getX() - size; x <= (int)pos.getX() + size; x++) { for (int x = (int)pos.getX() - size; x <= (int)pos.getX() + size; x++) {
for (int z = (int)pos.getZ() - size; z <= (int)pos.getZ() + size; z++) { for (int z = (int)pos.getZ() - size; z <= (int)pos.getZ() + size; z++) {
for (int y = (int)pos.getY(); y >= minY; y--) { for (int y = (int)pos.getY(); y >= minY; y--) {
Point pt = new Point(x, y, z); Vector pt = new Vector(x, y, z);
if (getBlock(pt) != 0) { if (getBlock(pt) != 0) {
setBlock(pt, 0); setBlock(pt, 0);
@ -432,13 +432,13 @@ public class EditSession {
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
// Doing this for speed // Doing this for speed
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
Point pt = new Point(x, y, z); Vector pt = new Vector(x, y, z);
if (setBlock(pt, blockType)) { if (setBlock(pt, blockType)) {
affected++; affected++;
@ -447,7 +447,7 @@ public class EditSession {
} }
} }
} else { } else {
for (Point pt : region) { for (Vector pt : region) {
if (setBlock(pt, blockType)) { if (setBlock(pt, blockType)) {
affected++; affected++;
} }
@ -472,13 +472,13 @@ public class EditSession {
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
// Doing this for speed // Doing this for speed
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
Point pt = new Point(x, y, z); Vector pt = new Vector(x, y, z);
int curBlockType = getBlock(pt); int curBlockType = getBlock(pt);
if (fromBlockType == -1 && curBlockType != 0 || if (fromBlockType == -1 && curBlockType != 0 ||
@ -491,7 +491,7 @@ public class EditSession {
} }
} }
} else { } else {
for (Point pt : region) { for (Vector pt : region) {
int curBlockType = getBlock(pt); int curBlockType = getBlock(pt);
if (fromBlockType == -1 && curBlockType != 0 || if (fromBlockType == -1 && curBlockType != 0 ||
@ -518,8 +518,8 @@ public class EditSession {
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
@ -556,8 +556,8 @@ public class EditSession {
*/ */
public int overlayCuboidBlocks(Region region, int blockType) public int overlayCuboidBlocks(Region region, int blockType)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
int upperY = Math.min(127, max.getBlockY() + 1); int upperY = Math.min(127, max.getBlockY() + 1);
int lowerY = Math.max(0, min.getBlockY()- 1); int lowerY = Math.max(0, min.getBlockY()- 1);
@ -597,8 +597,8 @@ public class EditSession {
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
int xs = region.getWidth(); int xs = region.getWidth();
int ys = region.getHeight(); int ys = region.getHeight();
int zs = region.getLength(); int zs = region.getLength();
@ -606,7 +606,7 @@ public class EditSession {
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
int blockType = getBlock(new Point(x, y, z)); int blockType = getBlock(new Vector(x, y, z));
if (blockType != 0 || copyAir) { if (blockType != 0 || copyAir) {
for (int i = 1; i <= count; i++) { for (int i = 1; i <= count; i++) {
@ -631,22 +631,22 @@ public class EditSession {
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int drainArea(Point pos, int radius) throws MaxChangedBlocksException { public int drainArea(Vector pos, int radius) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
HashSet<BlockPoint> visited = new HashSet<BlockPoint>(); HashSet<BlockVector> visited = new HashSet<BlockVector>();
Stack<BlockPoint> queue = new Stack<BlockPoint>(); Stack<BlockVector> queue = new Stack<BlockVector>();
for (int x = pos.getBlockX() - 1; x <= pos.getBlockX() + 1; x++) { for (int x = pos.getBlockX() - 1; x <= pos.getBlockX() + 1; x++) {
for (int z = pos.getBlockZ() - 1; z <= pos.getBlockZ() + 1; z++) { for (int z = pos.getBlockZ() - 1; z <= pos.getBlockZ() + 1; z++) {
for (int y = pos.getBlockY() - 1; y <= pos.getBlockY() + 1; y++) { for (int y = pos.getBlockY() - 1; y <= pos.getBlockY() + 1; y++) {
queue.push(new BlockPoint(x, y, z)); queue.push(new BlockVector(x, y, z));
} }
} }
} }
while (!queue.empty()) { while (!queue.empty()) {
BlockPoint cur = queue.pop(); BlockVector cur = queue.pop();
int type = getBlock(cur); int type = getBlock(cur);
@ -670,7 +670,7 @@ public class EditSession {
for (int x = cur.getBlockX() - 1; x <= cur.getBlockX() + 1; x++) { for (int x = cur.getBlockX() - 1; x <= cur.getBlockX() + 1; x++) {
for (int z = cur.getBlockZ() - 1; z <= cur.getBlockZ() + 1; z++) { for (int z = cur.getBlockZ() - 1; z <= cur.getBlockZ() + 1; z++) {
for (int y = cur.getBlockY() - 1; y <= cur.getBlockY() + 1; y++) { for (int y = cur.getBlockY() - 1; y <= cur.getBlockY() + 1; y++) {
BlockPoint newPos = new BlockPoint(x, y, z); BlockVector newPos = new BlockVector(x, y, z);
if (!cur.equals(newPos)) { if (!cur.equals(newPos)) {
queue.push(newPos); queue.push(newPos);

View File

@ -269,7 +269,7 @@ public class WorldEdit {
if (session.getClipboard() == null) { if (session.getClipboard() == null) {
player.printError("Nothing is in your clipboard."); player.printError("Nothing is in your clipboard.");
} else { } else {
Point pos = player.getBlockIn(); Vector pos = player.getBlockIn();
session.getClipboard().paste(editSession, pos, session.getClipboard().paste(editSession, pos,
split[0].equalsIgnoreCase("/editpaste")); split[0].equalsIgnoreCase("/editpaste"));
player.findFreePosition(); player.findFreePosition();
@ -285,7 +285,7 @@ public class WorldEdit {
int radius = Math.max(1, Integer.parseInt(split[2])); int radius = Math.max(1, Integer.parseInt(split[2]));
int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1; int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1;
Point pos = player.getBlockIn(); Vector pos = player.getBlockIn();
int affected = editSession.fillXZ((int)pos.getX(), (int)pos.getZ(), int affected = editSession.fillXZ((int)pos.getX(), (int)pos.getZ(),
pos, blockType, radius, depth); pos, blockType, radius, depth);
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
@ -326,7 +326,7 @@ public class WorldEdit {
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) { if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
player.printError("Schematic could not read or it does not exist."); player.printError("Schematic could not read or it does not exist.");
} else { } else {
Point origin = player.getBlockIn(); Vector origin = player.getBlockIn();
session.setClipboard(CuboidClipboard.loadSchematic(filePath, origin)); session.setClipboard(CuboidClipboard.loadSchematic(filePath, origin));
logger.log(Level.INFO, player.getName() + " loaded " + filePath); logger.log(Level.INFO, player.getName() + " loaded " + filePath);
player.print(filename + " loaded."); player.print(filename + " loaded.");
@ -447,9 +447,9 @@ public class WorldEdit {
} else if (split[0].equalsIgnoreCase("/editcopy")) { } else if (split[0].equalsIgnoreCase("/editcopy")) {
checkArgs(split, 0, 0, split[0]); checkArgs(split, 0, 0, split[0]);
Region region = session.getRegion(); Region region = session.getRegion();
Point min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
Point max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
Point pos = player.getBlockIn(); Vector pos = player.getBlockIn();
CuboidClipboard clipboard = new CuboidClipboard(min, max, pos); CuboidClipboard clipboard = new CuboidClipboard(min, max, pos);
clipboard.copy(editSession); clipboard.copy(editSession);

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.Point; import com.sk89q.worldedit.Vector;
/** /**
* *
@ -49,8 +49,8 @@ public class WorldEditPlayer {
* *
* @return point * @return point
*/ */
public Point getBlockOn() { public Vector getBlockOn() {
return Point.toBlockPoint(player.getX(), player.getY() - 1, player.getZ()); return Vector.toBlockPoint(player.getX(), player.getY() - 1, player.getZ());
} }
/** /**
@ -58,8 +58,8 @@ public class WorldEditPlayer {
* *
* @return point * @return point
*/ */
public Point getBlockIn() { public Vector getBlockIn() {
return Point.toBlockPoint(player.getX(), player.getY(), player.getZ()); return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
} }
/** /**
@ -67,8 +67,8 @@ public class WorldEditPlayer {
* *
* @return point * @return point
*/ */
public Point getPosition() { public Vector getPosition() {
return new Point(player.getX(), player.getY(), player.getZ()); return new Vector(player.getX(), player.getY(), player.getZ());
} }
/** /**
@ -123,7 +123,7 @@ public class WorldEditPlayer {
* @param pitch * @param pitch
* @param yaw * @param yaw
*/ */
public void setPosition(Point pos, float pitch, float yaw) { public void setPosition(Vector pos, float pitch, float yaw) {
Location loc = new Location(); Location loc = new Location();
loc.x = pos.getX(); loc.x = pos.getX();
loc.y = pos.getY(); loc.y = pos.getY();

View File

@ -68,7 +68,7 @@ public class WorldEditSMListener extends PluginListener {
WorldEditSession session = worldEdit.getSession(player); WorldEditSession session = worldEdit.getSession(player);
if (session.isToolControlEnabled()) { if (session.isToolControlEnabled()) {
Point cur = Point.toBlockPoint(blockClicked.getX(), Vector cur = Vector.toBlockPoint(blockClicked.getX(),
blockClicked.getY(), blockClicked.getY(),
blockClicked.getZ()); blockClicked.getZ());
@ -99,7 +99,7 @@ public class WorldEditSMListener extends PluginListener {
WorldEditSession session = worldEdit.getSession(player); WorldEditSession session = worldEdit.getSession(player);
if (session.isToolControlEnabled()) { if (session.isToolControlEnabled()) {
Point cur = Point.toBlockPoint(blockClicked.getX(), Vector cur = Vector.toBlockPoint(blockClicked.getX(),
blockClicked.getY(), blockClicked.getY(),
blockClicked.getZ()); blockClicked.getZ());

View File

@ -26,12 +26,12 @@ import java.util.LinkedList;
*/ */
public class WorldEditSession { public class WorldEditSession {
public static final int MAX_HISTORY_SIZE = 15; public static final int MAX_HISTORY_SIZE = 15;
private Point pos1, pos2; private Vector pos1, pos2;
private LinkedList<EditSession> history = new LinkedList<EditSession>(); private LinkedList<EditSession> history = new LinkedList<EditSession>();
private int historyPointer = 0; private int historyPointer = 0;
private CuboidClipboard clipboard; private CuboidClipboard clipboard;
private boolean toolControl = true; private boolean toolControl = true;
private Point lastToolPos1; private Vector lastToolPos1;
private long lastToolClick = 0; private long lastToolClick = 0;
private int maxBlocksChanged = -1; private int maxBlocksChanged = -1;
@ -120,7 +120,7 @@ public class WorldEditSession {
* @return position 1 * @return position 1
* @throws IncompleteRegionException * @throws IncompleteRegionException
*/ */
public Point getPos1() throws IncompleteRegionException { public Vector getPos1() throws IncompleteRegionException {
checkPos1(); checkPos1();
return pos1; return pos1;
} }
@ -130,7 +130,7 @@ public class WorldEditSession {
* *
* @param pt * @param pt
*/ */
public void setPos1(Point pt) { public void setPos1(Vector pt) {
pos1 = pt; pos1 = pt;
} }
@ -140,7 +140,7 @@ public class WorldEditSession {
* @return position 2 * @return position 2
* @throws IncompleteRegionException * @throws IncompleteRegionException
*/ */
public Point getPos2() throws IncompleteRegionException { public Vector getPos2() throws IncompleteRegionException {
checkPos2(); checkPos2();
return pos2; return pos2;
} }
@ -150,7 +150,7 @@ public class WorldEditSession {
* *
* @param pt * @param pt
*/ */
public void setPos2(Point pt) { public void setPos2(Vector pt) {
pos2 = pt; pos2 = pt;
} }
@ -206,14 +206,14 @@ public class WorldEditSession {
/** /**
* @return the lastToolPos1 * @return the lastToolPos1
*/ */
public Point getLastToolPos1() { public Vector getLastToolPos1() {
return lastToolPos1; return lastToolPos1;
} }
/** /**
* @param lastToolPos1 the lastToolPos1 to set * @param lastToolPos1 the lastToolPos1 to set
*/ */
public void setLastToolPos1(Point lastToolPos1) { public void setLastToolPos1(Vector lastToolPos1) {
this.lastToolPos1 = lastToolPos1; this.lastToolPos1 = lastToolPos1;
} }

View File

@ -20,44 +20,44 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
/** /**
* Extension of Point that supports being compared as ints (for accuracy). * Extension of Vector that supports being compared as ints (for accuracy).
* *
* @author sk89q * @author sk89q
*/ */
public class BlockPoint extends Point { public class BlockVector extends Vector {
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param pt * @param pt
*/ */
public BlockPoint(Point pt) { public BlockVector(Vector pt) {
super(pt); super(pt);
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param pt * @param pt
*/ */
public BlockPoint(int x, int y, int z) { public BlockVector(int x, int y, int z) {
super(x, y, z); super(x, y, z);
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param pt * @param pt
*/ */
public BlockPoint(float x, float y, float z) { public BlockVector(float x, float y, float z) {
super(x, y, z); super(x, y, z);
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param pt * @param pt
*/ */
public BlockPoint(double x, double y, double z) { public BlockVector(double x, double y, double z) {
super(x, y, z); super(x, y, z);
} }
@ -69,10 +69,10 @@ public class BlockPoint extends Point {
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Point)) { if (!(obj instanceof Vector)) {
return false; return false;
} }
Point other = (Point)obj; Vector other = (Vector)obj;
return (int)other.x == (int)this.x && (int)other.y == (int)this.y return (int)other.x == (int)this.x && (int)other.y == (int)this.y
&& (int)other.z == (int)this.z; && (int)other.z == (int)this.z;

View File

@ -29,11 +29,11 @@ public class CuboidRegion implements Region {
/** /**
* Store the first point. * Store the first point.
*/ */
private Point pos1; private Vector pos1;
/** /**
* Store the second point. * Store the second point.
*/ */
private Point pos2; private Vector pos2;
/** /**
* Construct a new instance of this cuboid region. * Construct a new instance of this cuboid region.
@ -41,7 +41,7 @@ public class CuboidRegion implements Region {
* @param pos1 * @param pos1
* @param pos2 * @param pos2
*/ */
public CuboidRegion(Point pos1, Point pos2) { public CuboidRegion(Vector pos1, Vector pos2) {
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
} }
@ -52,8 +52,8 @@ public class CuboidRegion implements Region {
* @return min point * @return min point
*/ */
@Override @Override
public Point getMinimumPoint() { public Vector getMinimumPoint() {
return new Point(Math.min(pos1.getX(), pos2.getX()), return new Vector(Math.min(pos1.getX(), pos2.getX()),
Math.min(pos1.getY(), pos2.getY()), Math.min(pos1.getY(), pos2.getY()),
Math.min(pos1.getZ(), pos2.getZ())); Math.min(pos1.getZ(), pos2.getZ()));
} }
@ -64,8 +64,8 @@ public class CuboidRegion implements Region {
* @return max point * @return max point
*/ */
@Override @Override
public Point getMaximumPoint() { public Vector getMaximumPoint() {
return new Point(Math.max(pos1.getX(), pos2.getX()), return new Vector(Math.max(pos1.getX(), pos2.getX()),
Math.max(pos1.getY(), pos2.getY()), Math.max(pos1.getY(), pos2.getY()),
Math.max(pos1.getZ(), pos2.getZ())); Math.max(pos1.getZ(), pos2.getZ()));
} }
@ -76,8 +76,8 @@ public class CuboidRegion implements Region {
* @return number of blocks * @return number of blocks
*/ */
public int getSize() { public int getSize() {
Point min = getMinimumPoint(); Vector min = getMinimumPoint();
Point max = getMaximumPoint(); Vector max = getMaximumPoint();
return (int)((max.getX() - min.getX() + 1) * return (int)((max.getX() - min.getX() + 1) *
(max.getY() - min.getY() + 1) * (max.getY() - min.getY() + 1) *
@ -90,8 +90,8 @@ public class CuboidRegion implements Region {
* @return width * @return width
*/ */
public int getWidth() { public int getWidth() {
Point min = getMinimumPoint(); Vector min = getMinimumPoint();
Point max = getMaximumPoint(); Vector max = getMaximumPoint();
return (int)(max.getX() - min.getX() + 1); return (int)(max.getX() - min.getX() + 1);
} }
@ -102,8 +102,8 @@ public class CuboidRegion implements Region {
* @return height * @return height
*/ */
public int getHeight() { public int getHeight() {
Point min = getMinimumPoint(); Vector min = getMinimumPoint();
Point max = getMaximumPoint(); Vector max = getMaximumPoint();
return (int)(max.getY() - min.getY() + 1); return (int)(max.getY() - min.getY() + 1);
} }
@ -114,8 +114,8 @@ public class CuboidRegion implements Region {
* @return length * @return length
*/ */
public int getLength() { public int getLength() {
Point min = getMinimumPoint(); Vector min = getMinimumPoint();
Point max = getMaximumPoint(); Vector max = getMaximumPoint();
return (int)(max.getZ() - min.getZ() + 1); return (int)(max.getZ() - min.getZ() + 1);
} }
@ -125,7 +125,7 @@ public class CuboidRegion implements Region {
* *
* @return iterator of Points * @return iterator of Points
*/ */
public Iterator<Point> iterator() { public Iterator<Vector> iterator() {
throw new UnsupportedOperationException("Not implemented"); throw new UnsupportedOperationException("Not implemented");
} }
} }

View File

@ -23,19 +23,19 @@ package com.sk89q.worldedit;
* *
* @author Albert * @author Albert
*/ */
public interface Region extends Iterable<Point> { public interface Region extends Iterable<Vector> {
/** /**
* Get the lower point of a region. * Get the lower point of a region.
* *
* @return min. point * @return min. point
*/ */
public Point getMinimumPoint(); public Vector getMinimumPoint();
/** /**
* Get the upper point of a region. * Get the upper point of a region.
* *
* @return max. point * @return max. point
*/ */
public Point getMaximumPoint(); public Vector getMaximumPoint();
/** /**
* Get the number of blocks in the region. * Get the number of blocks in the region.
* *

View File

@ -23,63 +23,63 @@ package com.sk89q.worldedit;
* *
* @author Albert * @author Albert
*/ */
public class Point { public class Vector {
protected final double x, y, z; protected final double x, y, z;
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param x * @param x
* @param y * @param y
* @param z * @param z
*/ */
public Point(double x, double y, double z) { public Vector(double x, double y, double z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param x * @param x
* @param y * @param y
* @param z * @param z
*/ */
public Point(int x, int y, int z) { public Vector(int x, int y, int z) {
this.x = (double)x; this.x = (double)x;
this.y = (double)y; this.y = (double)y;
this.z = (double)z; this.z = (double)z;
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param x * @param x
* @param y * @param y
* @param z * @param z
*/ */
public Point(float x, float y, float z) { public Vector(float x, float y, float z) {
this.x = (double)x; this.x = (double)x;
this.y = (double)y; this.y = (double)y;
this.z = (double)z; this.z = (double)z;
} }
/** /**
* Construct the Point object. * Construct the Vector object.
* *
* @param pt * @param pt
*/ */
public Point(Point pt) { public Vector(Vector pt) {
this.x = pt.x; this.x = pt.x;
this.y = pt.y; this.y = pt.y;
this.z = pt.z; this.z = pt.z;
} }
/** /**
* Construct the Point object. * Construct the Vector object.
*/ */
public Point() { public Vector() {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;
this.z = 0; this.z = 0;
@ -133,8 +133,8 @@ public class Point {
* @param other * @param other
* @return New point * @return New point
*/ */
public Point add(Point other) { public Vector add(Vector other) {
return new Point(x + other.x, y + other.y, z + other.z); return new Vector(x + other.x, y + other.y, z + other.z);
} }
/** /**
@ -145,8 +145,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point add(double x, double y, double z) { public Vector add(double x, double y, double z) {
return new Point(this.x + x, this.y + y, this.z + z); return new Vector(this.x + x, this.y + y, this.z + z);
} }
/** /**
@ -157,8 +157,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point add(int x, int y, int z) { public Vector add(int x, int y, int z) {
return new Point(this.x + x, this.y + y, this.z + z); return new Vector(this.x + x, this.y + y, this.z + z);
} }
/** /**
@ -167,7 +167,7 @@ public class Point {
* @param others * @param others
* @return New point * @return New point
*/ */
public Point add(Point ... others) { public Vector add(Vector ... others) {
double newX = x, newY = y, newZ = z; double newX = x, newY = y, newZ = z;
for (int i = 0; i < others.length; i++) { for (int i = 0; i < others.length; i++) {
@ -175,7 +175,7 @@ public class Point {
newY += others[i].y; newY += others[i].y;
newZ += others[i].z; newZ += others[i].z;
} }
return new Point(newX, newY, newZ); return new Vector(newX, newY, newZ);
} }
/** /**
@ -184,8 +184,8 @@ public class Point {
* @param other * @param other
* @return New point * @return New point
*/ */
public Point subtract(Point other) { public Vector subtract(Vector other) {
return new Point(x - other.x, y - other.y, z - other.z); return new Vector(x - other.x, y - other.y, z - other.z);
} }
/** /**
@ -196,8 +196,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point subtract(double x, double y, double z) { public Vector subtract(double x, double y, double z) {
return new Point(this.x - x, this.y - y, this.z - z); return new Vector(this.x - x, this.y - y, this.z - z);
} }
/** /**
@ -208,8 +208,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point subtract(int x, int y, int z) { public Vector subtract(int x, int y, int z) {
return new Point(this.x - x, this.y - y, this.z - z); return new Vector(this.x - x, this.y - y, this.z - z);
} }
/** /**
@ -218,7 +218,7 @@ public class Point {
* @param others * @param others
* @return New point * @return New point
*/ */
public Point subtract(Point ... others) { public Vector subtract(Vector ... others) {
double newX = x, newY = y, newZ = z; double newX = x, newY = y, newZ = z;
for (int i = 0; i < others.length; i++) { for (int i = 0; i < others.length; i++) {
@ -226,7 +226,7 @@ public class Point {
newY -= others[i].y; newY -= others[i].y;
newZ -= others[i].z; newZ -= others[i].z;
} }
return new Point(newX, newY, newZ); return new Vector(newX, newY, newZ);
} }
/** /**
@ -235,8 +235,8 @@ public class Point {
* @param other * @param other
* @return New point * @return New point
*/ */
public Point multiply(Point other) { public Vector multiply(Vector other) {
return new Point(x * other.x, y * other.y, z * other.z); return new Vector(x * other.x, y * other.y, z * other.z);
} }
/** /**
@ -247,8 +247,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point multiply(double x, double y, double z) { public Vector multiply(double x, double y, double z) {
return new Point(this.x * x, this.y * y, this.z * z); return new Vector(this.x * x, this.y * y, this.z * z);
} }
/** /**
@ -259,8 +259,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point multiply(int x, int y, int z) { public Vector multiply(int x, int y, int z) {
return new Point(this.x * x, this.y * y, this.z * z); return new Vector(this.x * x, this.y * y, this.z * z);
} }
/** /**
@ -269,7 +269,7 @@ public class Point {
* @param others * @param others
* @return New point * @return New point
*/ */
public Point multiply(Point ... others) { public Vector multiply(Vector ... others) {
double newX = x, newY = y, newZ = z; double newX = x, newY = y, newZ = z;
for (int i = 0; i < others.length; i++) { for (int i = 0; i < others.length; i++) {
@ -277,7 +277,7 @@ public class Point {
newY *= others[i].y; newY *= others[i].y;
newZ *= others[i].z; newZ *= others[i].z;
} }
return new Point(newX, newY, newZ); return new Vector(newX, newY, newZ);
} }
/** /**
@ -286,8 +286,8 @@ public class Point {
* @param other * @param other
* @return New point * @return New point
*/ */
public Point divide(Point other) { public Vector divide(Vector other) {
return new Point(x / other.x, y / other.y, z / other.z); return new Vector(x / other.x, y / other.y, z / other.z);
} }
/** /**
@ -298,8 +298,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point divide(double x, double y, double z) { public Vector divide(double x, double y, double z) {
return new Point(this.x / x, this.y / y, this.z / z); return new Vector(this.x / x, this.y / y, this.z / z);
} }
/** /**
@ -310,8 +310,8 @@ public class Point {
* @param z * @param z
* @return New point * @return New point
*/ */
public Point divide(int x, int y, int z) { public Vector divide(int x, int y, int z) {
return new Point(this.x / x, this.y / y, this.z / z); return new Vector(this.x / x, this.y / y, this.z / z);
} }
/** /**
@ -320,7 +320,7 @@ public class Point {
* @param pt * @param pt
* @return distance * @return distance
*/ */
public double distance(Point pt) { public double distance(Vector pt) {
return Math.sqrt(Math.pow(pt.x - x, 2) + return Math.sqrt(Math.pow(pt.x - x, 2) +
Math.pow(pt.y - y, 2) + Math.pow(pt.y - y, 2) +
Math.pow(pt.z - z, 2)); Math.pow(pt.z - z, 2));
@ -334,8 +334,8 @@ public class Point {
* @param z * @param z
* @return point * @return point
*/ */
public static Point toBlockPoint(double x, double y, double z) { public static Vector toBlockPoint(double x, double y, double z) {
return new Point((int)Math.floor(x), return new Vector((int)Math.floor(x),
(int)Math.floor(y), (int)Math.floor(y),
(int)Math.floor(z)); (int)Math.floor(z));
} }
@ -348,10 +348,10 @@ public class Point {
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Point)) { if (!(obj instanceof Vector)) {
return false; return false;
} }
Point other = (Point)obj; Vector other = (Vector)obj;
return other.x == this.x && other.y == this.y && other.z == this.z; return other.x == this.x && other.y == this.y && other.z == this.z;
} }
@ -379,11 +379,11 @@ public class Point {
} }
/** /**
* Gets a BlockPoint version. * Gets a BlockVector version.
* *
* @return BlockPoint * @return BlockVector
*/ */
public BlockPoint toBlockPoint() { public BlockVector toBlockPoint() {
return new BlockPoint(this); return new BlockVector(this);
} }
} }