throws BlockBagException, InvalidDirectionException,
UnacceptableTypeException, InvalidConstructionException {
Direction direction = getDirection();
Vector change = null;
Vector leftSide = null;
Vector rightSide = null;
int centerShift = 1;
if (direction == Direction.NORTH) {
change = new Vector(-1, 0, 0);
leftSide = pt.add(0, 1, -1);
rightSide = pt.add(0, 1, 1);
} else if (direction == Direction.SOUTH) {
change = new Vector(1, 0, 0);
leftSide = pt.add(0, 1, -1);
rightSide = pt.add(0, 1, 1);
} else if (direction == Direction.WEST) {
change = new Vector(0, 0, 1);
leftSide = pt.add(1, 1, 0);
rightSide = pt.add(-1, 1, 0);
} else if (direction == Direction.EAST) {
change = new Vector(0, 0, -1);
leftSide = pt.add(1, 1, 0);
rightSide = pt.add(-1, 1, 0);
}
// Block above the sign
int type = world.getId(x, y + 1, z);
// Attempt to detect whether the bridge is above or below the sign,
// first assuming that the bridge is above
if (type == 0
|| !canUseBlock(type)
|| world.getId(leftSide) != type
|| world.getId(rightSide) != type) {
// The bridge is not above, so let's try below
leftSide = leftSide.add(0, -2, 0);
rightSide = rightSide.add(0, -2, 0);
centerShift = -1;
// Block below the sign
type = world.getId(x, y - 1, z);
if (!canUseBlock(type)) {
throw new UnacceptableTypeException();
}
// Guess not
if (world.getId(leftSide) != type
|| world.getId(leftSide) != type) {
throw new InvalidConstructionException(
"Blocks adjacent to the bridge block must be of the same type.");
}
}
Vector current = pt;
boolean found = false;
int dist = 0;
// Find the other side
for (int i = 0; i < maxLength + 2; i++) {
int id = world.getId(current);
if (id == BlockType.SIGN_POST) {
SignInterface otherSignText =
(SignInterface) world.getBlockEntity(current);
if (otherSignText != null) {
String line2 = otherSignText.getLine2();
if (line2.equalsIgnoreCase("[Bridge]")
|| line2.equalsIgnoreCase("[Bridge End]")) {
found = true;
dist = i;
break;
}
}
}
current = current.add(change);
}
// Failed to find the other side!
if (!found) {
throw new InvalidConstructionException(
"[Bridge] sign required on other side (or it was too far away).");
}
Vector shift = change.multiply(dist + 1);
// Check the other side to see if it's built correctly
if (world.getId(pt.add(shift).add(0, centerShift, 0)) != type
|| world.getId(leftSide.add(shift)) != type
|| world.getId(rightSide.add(shift)) != type) {