Added /ascend and /descend.

Dieser Commit ist enthalten in:
sk89q 2010-10-12 22:06:46 -07:00
Ursprung 87daf8e7ed
Commit 514a78272e
2 geänderte Dateien mit 105 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -94,6 +94,8 @@ public class WorldEdit {
commands.put("/editexpand", "<Dir> [Num] - Expands the selection");
commands.put("/editcontract", "<Dir> [Num] - Contracts the selection");
commands.put("/unstuck", "Go up to the first free spot");
commands.put("/ascend", "Go up one level");
commands.put("/descend", "Go dowm one level");
}
/**
@ -202,6 +204,26 @@ public class WorldEdit {
player.findFreePosition();
return true;
// Ascend a level
} else if(split[0].equalsIgnoreCase("/ascend")) {
checkArgs(split, 0, 0, split[0]);
if (player.ascendLevel()) {
player.print("Ascended a level.");
} else {
player.printError("No free spot above you found.");
}
return true;
// Descend a level
} else if(split[0].equalsIgnoreCase("/descend")) {
checkArgs(split, 0, 0, split[0]);
if (player.descendLevel()) {
player.print("Descended a level.");
} else {
player.printError("No free spot below you found.");
}
return true;
// Set edit position #1
} else if (split[0].equalsIgnoreCase("/editpos1")) {
checkArgs(split, 0, 0, split[0]);

Datei anzeigen

@ -133,7 +133,7 @@ public class WorldEditPlayer {
/**
* Move the player.
*
*
* @param pos
* @param pitch
* @param yaw
@ -148,6 +148,21 @@ public class WorldEditPlayer {
player.teleportTo(loc);
}
/**
* Move the player.
*
* @param pos
*/
public void setPosition(Vector pos) {
Location loc = new Location();
loc.x = pos.getX();
loc.y = pos.getY();
loc.z = pos.getZ();
loc.rotX = (float)getYaw();
loc.rotY = (float)getPitch();
player.teleportTo(loc);
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
@ -186,6 +201,73 @@ public class WorldEditPlayer {
}
}
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
public boolean ascendLevel() {
int x = (int)Math.floor(player.getX());
int y = (int)Math.floor(player.getY());
int z = (int)Math.floor(player.getZ());
byte free = 0;
byte spots = 0;
boolean inFree = false;
while (y <= 129) {
if (etc.getServer().getBlockIdAt(x, y, z) == 0) {
free++;
} else {
free = 0;
inFree = false;
}
if (free == 2 && inFree == false) {
inFree = true;
spots++;
if (y >= 129 || spots == 2) {
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
return true;
}
}
y++;
}
return false;
}
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
public boolean descendLevel() {
int x = (int)Math.floor(player.getX());
int y = (int)Math.floor(player.getY()) - 1;
int z = (int)Math.floor(player.getZ());
byte free = 0;
while (y >= 0) {
if (etc.getServer().getBlockIdAt(x, y, z) == 0) {
free++;
} else {
free = 0;
}
if (free == 2) {
setPosition(new Vector(x + 0.5, y, z + 0.5));
return true;
}
y--;
}
return false;
}
/**
* Gives the player an item.
*