Added //flip to flip clipboards.

Dieser Commit ist enthalten in:
sk89q 2010-11-26 22:15:21 -08:00
Ursprung 76d7a14016
Commit 3e2a1f5c33
2 geänderte Dateien mit 105 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -33,6 +33,15 @@ import java.util.List;
* @author sk89q
*/
public class CuboidClipboard {
/**
* Flip direction.
*/
public enum FlipDirection {
NORTH_SOUTH,
WEST_EAST,
UP_DOWN
}
private BaseBlock[][][] data;
private Vector offset;
private Vector origin;
@ -105,7 +114,7 @@ public class CuboidClipboard {
/**
* Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
*
*
* @param angle in degrees
*/
public void rotate2D(int angle) {
@ -145,6 +154,52 @@ public class CuboidClipboard {
.subtract(shiftX, 0, shiftZ);;
}
/**
* Flip the clipboard.
*
* @param dir
*/
public void flip(FlipDirection dir) {
int width = getWidth();
int length = getLength();
int height = getHeight();
if (dir == FlipDirection.NORTH_SOUTH) {
int len = (int)Math.floor(width / 2);
for (int xs = 0; xs < len; xs++) {
for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) {
BaseBlock old = data[xs][y][z];
data[xs][y][z] = data[width - xs - 1][y][z];
data[width - xs - 1][y][z] = old;
}
}
}
} else if (dir == FlipDirection.WEST_EAST) {
int len = (int)Math.floor(length / 2);
for (int zs = 0; zs < len; zs++) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
BaseBlock old = data[x][y][zs];
data[x][y][zs] = data[x][y][length - zs - 1];
data[x][y][length - zs - 1] = old;
}
}
}
} else if (dir == FlipDirection.UP_DOWN) {
int len = (int)Math.floor(height / 2);
for (int ys = 0; ys < len; ys++) {
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
BaseBlock old = data[x][ys][z];
data[x][ys][z] = data[x][height - ys - 1][z];
data[x][height - ys - 1][z] = old;
}
}
}
}
}
/**
* Copy to the clipboard.
*

Datei anzeigen

@ -143,6 +143,7 @@ public class WorldEditListener extends PluginListener {
commands.put("//expand", "[Num] <Dir> - Expands the selection");
commands.put("//contract", "[Num] <Dir> - Contracts the selection");
commands.put("//rotate", "[Angle] - Rotate the clipboard");
commands.put("//flip", "<Dir> - Flip the clipboard");
commands.put("//hcyl", "[ID] [Radius] <Height> - Create a vertical hollow cylinder");
commands.put("//cyl", "[ID] [Radius] <Height> - Create a vertical cylinder");
commands.put("//sphere", "[ID] [Radius] <Raised?> - Create a sphere");
@ -1260,6 +1261,18 @@ public class WorldEditListener extends PluginListener {
return true;
// Flip
} else if (split[0].equalsIgnoreCase("//flip")) {
checkArgs(split, 0, 1, split[0]);
CuboidClipboard.FlipDirection dir = getFlipDirection(player,
split.length > 1 ? split[1].toLowerCase() : "me");
CuboidClipboard clipboard = session.getClipboard();
clipboard.flip(dir);
player.print("Clipboard flipped.");
return true;
// Kill mobs
} else if (split[0].equalsIgnoreCase("/butcher")) {
checkArgs(split, 0, 1, split[0]);
@ -1573,6 +1586,42 @@ public class WorldEditListener extends PluginListener {
return new Vector(xm, ym, zm);
}
/**
* Get the flip direction for a player's direction. May return
* null if a direction could not be found.
*
* @param player
* @param dir
* @return
*/
public CuboidClipboard.FlipDirection getFlipDirection(
WorldEditPlayer player, String dir)
throws UnknownDirectionException {
int xm = 0;
int ym = 0;
int zm = 0;
if (dir.equals("me")) {
dir = player.getCardinalDirection();
}
if (dir.charAt(0) == 'w') {
return CuboidClipboard.FlipDirection.WEST_EAST;
} else if (dir.charAt(0) == 'e') {
return CuboidClipboard.FlipDirection.WEST_EAST;
} else if (dir.charAt(0) == 's') {
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
} else if (dir.charAt(0) == 'n') {
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
} else if (dir.charAt(0) == 'u') {
return CuboidClipboard.FlipDirection.UP_DOWN;
} else if (dir.charAt(0) == 'd') {
return CuboidClipboard.FlipDirection.UP_DOWN;
} else {
throw new UnknownDirectionException(dir);
}
}
/**
* Remove a session.
*