Cleaned up some code, changed WorldEdit to be world-aware (finally).
This commit is contained in:
@@ -48,9 +48,11 @@ public abstract class WorldEditPlayer {
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
protected WorldEditPlayer() {
|
||||
server = ServerInterface.getInstance();
|
||||
protected WorldEditPlayer(ServerInterface server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +74,7 @@ public abstract class WorldEditPlayer {
|
||||
*
|
||||
* @param searchPos search position
|
||||
*/
|
||||
public void findFreePosition(Vector searchPos) {
|
||||
public void findFreePosition(LocalWorld world, Vector searchPos) {
|
||||
int x = searchPos.getBlockX();
|
||||
int y = Math.max(0, searchPos.getBlockY());
|
||||
int origY = y;
|
||||
@@ -81,7 +83,8 @@ public abstract class WorldEditPlayer {
|
||||
byte free = 0;
|
||||
|
||||
while (y <= 129) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(world,
|
||||
new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@@ -106,7 +109,7 @@ public abstract class WorldEditPlayer {
|
||||
* that free position.
|
||||
*/
|
||||
public void findFreePosition() {
|
||||
findFreePosition(getBlockIn());
|
||||
findFreePosition(getPosition().getWorld(), getBlockIn());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,12 +122,13 @@ public abstract class WorldEditPlayer {
|
||||
int x = pos.getBlockX();
|
||||
int y = Math.max(0, pos.getBlockY());
|
||||
int z = pos.getBlockZ();
|
||||
LocalWorld world = getPosition().getWorld();
|
||||
|
||||
byte free = 0;
|
||||
byte spots = 0;
|
||||
|
||||
while (y <= 129) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@@ -133,7 +137,7 @@ public abstract class WorldEditPlayer {
|
||||
if (free == 2) {
|
||||
spots++;
|
||||
if (spots == 2) {
|
||||
int type = server.getBlockType(new Vector(x, y - 2, z));
|
||||
int type = server.getBlockType(world, new Vector(x, y - 2, z));
|
||||
|
||||
// Don't get put in lava!
|
||||
if (type == 10 || type == 11) {
|
||||
@@ -161,11 +165,12 @@ public abstract class WorldEditPlayer {
|
||||
int x = pos.getBlockX();
|
||||
int y = Math.max(0, pos.getBlockY() - 1);
|
||||
int z = pos.getBlockZ();
|
||||
LocalWorld world = getPosition().getWorld();
|
||||
|
||||
byte free = 0;
|
||||
|
||||
while (y >= 1) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@@ -176,7 +181,7 @@ public abstract class WorldEditPlayer {
|
||||
// lightly and also check to see if there's something to
|
||||
// stand upon
|
||||
while (y >= 0) {
|
||||
int type = server.getBlockType(new Vector(x, y, z));
|
||||
int type = server.getBlockType(world, new Vector(x, y, z));
|
||||
|
||||
// Don't want to end up in lava
|
||||
if (type != 0 && type != 10 && type != 11) {
|
||||
@@ -209,17 +214,18 @@ public abstract class WorldEditPlayer {
|
||||
int initialY = Math.max(0, pos.getBlockY());
|
||||
int y = Math.max(0, pos.getBlockY() + 2);
|
||||
int z = pos.getBlockZ();
|
||||
LocalWorld world = getPosition().getWorld();
|
||||
|
||||
// No free space above
|
||||
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
if (server.getBlockType(world, new Vector(x, y, z)) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (y <= 127) {
|
||||
// Found a ceiling!
|
||||
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
|
||||
int platformY = Math.max(initialY, y - 3 - clearance);
|
||||
server.setBlockType(new Vector(x, platformY, z),
|
||||
server.setBlockType(world, new Vector(x, platformY, z),
|
||||
BlockType.GLASS.getID());
|
||||
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
|
||||
return true;
|
||||
@@ -244,14 +250,15 @@ public abstract class WorldEditPlayer {
|
||||
int y = Math.max(0, pos.getBlockY() + 1);
|
||||
int z = pos.getBlockZ();
|
||||
int maxY = Math.min(128, initialY + distance);
|
||||
LocalWorld world = getPosition().getWorld();
|
||||
|
||||
while (y <= 129) {
|
||||
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
|
||||
break; // Hit something
|
||||
} else if (y > maxY + 1) {
|
||||
break;
|
||||
} else if (y == maxY + 1) {
|
||||
server.setBlockType(new Vector(x, y - 2, z),
|
||||
server.setBlockType(world, new Vector(x, y - 2, z),
|
||||
BlockType.GLASS.getID());
|
||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||
return true;
|
||||
@@ -268,8 +275,8 @@ public abstract class WorldEditPlayer {
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getBlockIn() {
|
||||
return getPosition().toBlockVector();
|
||||
public WorldVector getBlockIn() {
|
||||
return getPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,8 +284,9 @@ public abstract class WorldEditPlayer {
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getBlockOn() {
|
||||
return getPosition().subtract(0, 1, 0).toBlockVector();
|
||||
public WorldVector getBlockOn() {
|
||||
WorldVector pos = getPosition();
|
||||
return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,7 +295,7 @@ public abstract class WorldEditPlayer {
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getBlockTrace(int range);
|
||||
public abstract WorldVector getBlockTrace(int range);
|
||||
|
||||
/**
|
||||
* Get the point of the block being looked at. May return null.
|
||||
@@ -295,7 +303,7 @@ public abstract class WorldEditPlayer {
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getSolidBlockTrace(int range);
|
||||
public abstract WorldVector getSolidBlockTrace(int range);
|
||||
|
||||
/**
|
||||
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
|
||||
@@ -360,7 +368,14 @@ public abstract class WorldEditPlayer {
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getPosition();
|
||||
public abstract WorldVector getPosition();
|
||||
|
||||
/**
|
||||
* Get the player's world.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract LocalWorld getWorld();
|
||||
|
||||
/**
|
||||
* Get the player's view pitch.
|
||||
|
||||
Reference in New Issue
Block a user