mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-21 04:49:51 +08:00
Added (untested) //hpos1, //hpos2, /jumpto, /thru, /ceil.
This commit is contained in:
parent
171d72319b
commit
9124cdd91f
@ -64,6 +64,54 @@ public Vector getBlockIn() {
|
|||||||
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
|
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the point of the block being looked at. May return null.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public Vector getBlockTrace(int range) {
|
||||||
|
HitBlox hitBlox = new HitBlox(player, range, 0.2);
|
||||||
|
Block block = hitBlox.getTargetBlock();
|
||||||
|
if (block == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Vector(block.getX(), block.getY(), block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass through the wall that you are looking at.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return whether the player was pass through
|
||||||
|
*/
|
||||||
|
public boolean passThroughForwardWall(int range) {
|
||||||
|
int free = 0;
|
||||||
|
int spots = 0;
|
||||||
|
|
||||||
|
HitBlox hitBlox = new HitBlox(player, range, 0.2);
|
||||||
|
Block block;
|
||||||
|
|
||||||
|
free = hitBlox.getLastBlock().getType() == 0 ? 1 : 0;
|
||||||
|
while ((block = hitBlox.getNextBlock()) != null) {
|
||||||
|
if (block.getType() == 0) {
|
||||||
|
free++;
|
||||||
|
if (spots >= 1) {
|
||||||
|
Vector v = new Vector(block.getX(), block.getY() + 1, block.getZ());
|
||||||
|
if (server.getBlockType(v) == 0) {
|
||||||
|
setPosition(v.subtract(0, 1, 0));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
free = 0;
|
||||||
|
spots++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's position.
|
* Get the player's position.
|
||||||
*
|
*
|
||||||
|
@ -114,6 +114,8 @@ private WorldEdit() {
|
|||||||
// for now (see SMWorldEditListener.canUseCommand)
|
// for now (see SMWorldEditListener.canUseCommand)
|
||||||
commands.put("//pos1", "Set editing position #1");
|
commands.put("//pos1", "Set editing position #1");
|
||||||
commands.put("//pos2", "Set editing position #2");
|
commands.put("//pos2", "Set editing position #2");
|
||||||
|
commands.put("//hpos1", "Trace editing position #1");
|
||||||
|
commands.put("//hpos2", "Trace editing position #2");
|
||||||
commands.put("/toggleplace", "Toggle placing at pos #1");
|
commands.put("/toggleplace", "Toggle placing at pos #1");
|
||||||
commands.put("//wand", "Gives you the \"edit wand\"");
|
commands.put("//wand", "Gives you the \"edit wand\"");
|
||||||
commands.put("/toggleeditwand", "Toggles edit wand selection");
|
commands.put("/toggleeditwand", "Toggles edit wand selection");
|
||||||
@ -156,6 +158,9 @@ private WorldEdit() {
|
|||||||
commands.put("/unstuck", "Go up to the first free spot");
|
commands.put("/unstuck", "Go up to the first free spot");
|
||||||
commands.put("/ascend", "Go up one level");
|
commands.put("/ascend", "Go up one level");
|
||||||
commands.put("/descend", "Go down one level");
|
commands.put("/descend", "Go down one level");
|
||||||
|
commands.put("/jumpto", "Jump to the block that you are looking at");
|
||||||
|
commands.put("/thru", "Go through the wall that you are looking at");
|
||||||
|
commands.put("/ceil", "<Clearance> - Get to the ceiling");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,6 +314,41 @@ public boolean performCommand(WorldEditPlayer player,
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Jump to the block in sight
|
||||||
|
} else if (split[0].equalsIgnoreCase("/jumpto")) {
|
||||||
|
checkArgs(split, 0, 0, split[0]);
|
||||||
|
Vector pos = player.getBlockTrace(300);
|
||||||
|
if (pos != null) {
|
||||||
|
player.findFreePosition(pos);
|
||||||
|
player.print("Poof!");
|
||||||
|
} else {
|
||||||
|
player.printError("No block in sight!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Go through a wall
|
||||||
|
} else if (split[0].equalsIgnoreCase("/thru")) {
|
||||||
|
checkArgs(split, 0, 0, split[0]);
|
||||||
|
if (player.passThroughForwardWall(300)) {
|
||||||
|
player.print("Whoosh!");
|
||||||
|
} else {
|
||||||
|
player.printError("No free spot ahead of you found.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Go to the ceiling
|
||||||
|
} else if (split[0].equalsIgnoreCase("/ceil")) {
|
||||||
|
checkArgs(split, 0, 1, split[0]);
|
||||||
|
int clearence = split.length > 1 ?
|
||||||
|
Math.max(0, Integer.parseInt(split[1])) : 0;
|
||||||
|
|
||||||
|
if (player.ascendToCeiling(clearence)) {
|
||||||
|
player.print("Whoosh!");
|
||||||
|
} else {
|
||||||
|
player.printError("No free spot above you found.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
// Set edit position #1
|
// Set edit position #1
|
||||||
} else if (split[0].equalsIgnoreCase("//pos1")) {
|
} else if (split[0].equalsIgnoreCase("//pos1")) {
|
||||||
checkArgs(split, 0, 0, split[0]);
|
checkArgs(split, 0, 0, split[0]);
|
||||||
@ -323,6 +363,30 @@ public boolean performCommand(WorldEditPlayer player,
|
|||||||
player.print("Second edit position set.");
|
player.print("Second edit position set.");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Trace edit position #1
|
||||||
|
} else if (split[0].equalsIgnoreCase("//hpos1")) {
|
||||||
|
checkArgs(split, 0, 0, split[0]);
|
||||||
|
Vector pos = player.getBlockTrace(300);
|
||||||
|
if (pos != null) {
|
||||||
|
session.setPos1(pos);
|
||||||
|
player.print("First edit position set.");
|
||||||
|
} else {
|
||||||
|
player.printError("No block in sight!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Trace edit position #2
|
||||||
|
} else if (split[0].equalsIgnoreCase("//hpos2")) {
|
||||||
|
checkArgs(split, 0, 0, split[0]);
|
||||||
|
Vector pos = player.getBlockTrace(300);
|
||||||
|
if (pos != null) {
|
||||||
|
session.setPos2(pos);
|
||||||
|
player.print("Second edit position set.");
|
||||||
|
} else {
|
||||||
|
player.printError("No block in sight!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
// Edit wand
|
// Edit wand
|
||||||
} else if (split[0].equalsIgnoreCase("//wand")) {
|
} else if (split[0].equalsIgnoreCase("//wand")) {
|
||||||
checkArgs(split, 0, 0, split[0]);
|
checkArgs(split, 0, 0, split[0]);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.ServerInterface;
|
import com.sk89q.worldedit.ServerInterface;
|
||||||
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -55,6 +56,13 @@ public WorldEditPlayer() {
|
|||||||
* @return point
|
* @return point
|
||||||
*/
|
*/
|
||||||
public abstract Vector getBlockIn();
|
public abstract Vector getBlockIn();
|
||||||
|
/**
|
||||||
|
* Get the point of the block being looked at. May return null.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public abstract Vector getBlockTrace(int range);
|
||||||
/**
|
/**
|
||||||
* Get the player's position.
|
* Get the player's position.
|
||||||
*
|
*
|
||||||
@ -135,13 +143,14 @@ public void setPosition(Vector pos) {
|
|||||||
* Blocks above the player will be iteratively tested until there is
|
* Blocks above the player will be iteratively tested until there is
|
||||||
* a series of two free blocks. The player will be teleported to
|
* a series of two free blocks. The player will be teleported to
|
||||||
* that free position.
|
* that free position.
|
||||||
|
*
|
||||||
|
* @param searchPos search position
|
||||||
*/
|
*/
|
||||||
public void findFreePosition() {
|
public void findFreePosition(Vector searchPos) {
|
||||||
Vector pos = getBlockIn();
|
int x = searchPos.getBlockX();
|
||||||
int x = pos.getBlockX();
|
int y = searchPos.getBlockY();
|
||||||
int y = pos.getBlockY();
|
|
||||||
int origY = y;
|
int origY = y;
|
||||||
int z = pos.getBlockZ();
|
int z = searchPos.getBlockZ();
|
||||||
|
|
||||||
byte free = 0;
|
byte free = 0;
|
||||||
|
|
||||||
@ -163,6 +172,24 @@ public void findFreePosition() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* a series of two free blocks. The player will be teleported to
|
||||||
|
* that free position.
|
||||||
|
*/
|
||||||
|
public void findFreePosition() {
|
||||||
|
findFreePosition(getBlockIn());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass through the wall that you are looking at.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return whether a wall was passed through
|
||||||
|
*/
|
||||||
|
public abstract boolean passThroughForwardWall(int range);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go up one level to the next free space above.
|
* Go up one level to the next free space above.
|
||||||
*
|
*
|
||||||
@ -251,6 +278,40 @@ public boolean descendLevel() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ascend to the ceiling above.
|
||||||
|
*
|
||||||
|
* @param clearance
|
||||||
|
* @return whether the player was moved
|
||||||
|
*/
|
||||||
|
public boolean ascendToCeiling(int clearance) {
|
||||||
|
Vector pos = getBlockIn();
|
||||||
|
int x = pos.getBlockX();
|
||||||
|
int y = pos.getBlockY() + 2;
|
||||||
|
int initialY = y;
|
||||||
|
int z = pos.getBlockZ();
|
||||||
|
|
||||||
|
// Nothing above
|
||||||
|
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (y <= 127) {
|
||||||
|
// Found a ceiling!
|
||||||
|
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||||
|
int platformY = Math.max(initialY, y - 3);
|
||||||
|
server.setBlockType(new Vector(x, platformY, z),
|
||||||
|
BlockType.GLASS.getID());
|
||||||
|
setPosition(new Vector(x, platformY + 1, z));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the player an item.
|
* Gives the player an item.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user