Whitespace + general cleanup
This commit is contained in:
@@ -21,7 +21,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
private final World world;
|
||||
private final int maxDistance;
|
||||
|
||||
private static final int gridSize = 1<<24;
|
||||
private static final int gridSize = 1 << 24;
|
||||
|
||||
private boolean end = false;
|
||||
|
||||
@@ -56,74 +56,74 @@ public class BlockIterator implements Iterator<Block> {
|
||||
this.maxDistance = maxDistance;
|
||||
|
||||
Vector startClone = start.clone();
|
||||
startClone.setY(startClone.getY( )+ yOffset);
|
||||
|
||||
startClone.setY(startClone.getY() + yOffset);
|
||||
|
||||
currentDistance = 0;
|
||||
|
||||
double mainDirection = 0;
|
||||
double mainDirection = 0;
|
||||
double secondDirection = 0;
|
||||
double thirdDirection = 0;
|
||||
double thirdDirection = 0;
|
||||
|
||||
double mainPosition = 0;
|
||||
double secondPosition = 0;
|
||||
double thirdPosition = 0;
|
||||
double mainPosition = 0;
|
||||
double secondPosition = 0;
|
||||
double thirdPosition = 0;
|
||||
|
||||
Block startBlock = world.getBlockAt((int)Math.floor(startClone.getX()), (int)Math.floor(startClone.getY()), (int)Math.floor(startClone.getZ()));
|
||||
Block startBlock = world.getBlockAt((int) Math.floor(startClone.getX()), (int) Math.floor(startClone.getY()), (int) Math.floor(startClone.getZ()));
|
||||
|
||||
if (getXLength(direction) > mainDirection) {
|
||||
mainFace = getXFace(direction);
|
||||
mainDirection = getXLength(direction);
|
||||
mainPosition = getXPosition(direction, startClone, startBlock);
|
||||
mainFace = getXFace(direction);
|
||||
mainDirection = getXLength(direction);
|
||||
mainPosition = getXPosition(direction, startClone, startBlock);
|
||||
|
||||
secondFace = getYFace(direction);
|
||||
secondFace = getYFace(direction);
|
||||
secondDirection = getYLength(direction);
|
||||
secondPosition = getYPosition(direction, startClone, startBlock);
|
||||
secondPosition = getYPosition(direction, startClone, startBlock);
|
||||
|
||||
thirdFace = getZFace(direction);
|
||||
thirdDirection = getZLength(direction);
|
||||
thirdPosition = getZPosition(direction, startClone, startBlock);
|
||||
thirdFace = getZFace(direction);
|
||||
thirdDirection = getZLength(direction);
|
||||
thirdPosition = getZPosition(direction, startClone, startBlock);
|
||||
}
|
||||
if (getYLength(direction) > mainDirection) {
|
||||
mainFace = getYFace(direction);
|
||||
mainDirection = getYLength(direction);
|
||||
mainPosition = getYPosition(direction, startClone, startBlock);
|
||||
mainFace = getYFace(direction);
|
||||
mainDirection = getYLength(direction);
|
||||
mainPosition = getYPosition(direction, startClone, startBlock);
|
||||
|
||||
secondFace = getZFace(direction);
|
||||
secondFace = getZFace(direction);
|
||||
secondDirection = getZLength(direction);
|
||||
secondPosition = getZPosition(direction, startClone, startBlock);
|
||||
secondPosition = getZPosition(direction, startClone, startBlock);
|
||||
|
||||
thirdFace = getXFace(direction);
|
||||
thirdDirection = getXLength(direction);
|
||||
thirdPosition = getXPosition(direction, startClone, startBlock);
|
||||
thirdFace = getXFace(direction);
|
||||
thirdDirection = getXLength(direction);
|
||||
thirdPosition = getXPosition(direction, startClone, startBlock);
|
||||
}
|
||||
if (getZLength(direction) > mainDirection) {
|
||||
mainFace = getZFace(direction);
|
||||
mainDirection = getZLength(direction);
|
||||
mainPosition = getZPosition(direction, startClone, startBlock);
|
||||
mainFace = getZFace(direction);
|
||||
mainDirection = getZLength(direction);
|
||||
mainPosition = getZPosition(direction, startClone, startBlock);
|
||||
|
||||
secondFace = getXFace(direction);
|
||||
secondFace = getXFace(direction);
|
||||
secondDirection = getXLength(direction);
|
||||
secondPosition = getXPosition(direction, startClone, startBlock);
|
||||
secondPosition = getXPosition(direction, startClone, startBlock);
|
||||
|
||||
thirdFace = getYFace(direction);
|
||||
thirdDirection = getYLength(direction);
|
||||
thirdPosition = getYPosition(direction, startClone, startBlock);
|
||||
thirdFace = getYFace(direction);
|
||||
thirdDirection = getYLength(direction);
|
||||
thirdPosition = getYPosition(direction, startClone, startBlock);
|
||||
}
|
||||
|
||||
// trace line backwards to find intercept with plane perpendicular to the main axis
|
||||
|
||||
double d = mainPosition/mainDirection; // how far to hit face behind
|
||||
double secondd = secondPosition - secondDirection*d;
|
||||
double thirdd = thirdPosition - thirdDirection*d;
|
||||
|
||||
secondError = (int)(Math.floor(secondd*gridSize));
|
||||
secondStep = (int)(Math.round(secondDirection/mainDirection*gridSize));
|
||||
thirdError = (int)(Math.floor(thirdd*gridSize));
|
||||
thirdStep = (int)(Math.round(thirdDirection/mainDirection*gridSize));
|
||||
double d = mainPosition / mainDirection; // how far to hit face behind
|
||||
double secondd = secondPosition - secondDirection * d;
|
||||
double thirdd = thirdPosition - thirdDirection * d;
|
||||
|
||||
// Guarantee that the ray will pass though the start block.
|
||||
// It is possible that it would miss due to rounding
|
||||
// This should only move the ray by 1 grid position
|
||||
secondError = (int) (Math.floor(secondd * gridSize));
|
||||
secondStep = (int) (Math.round(secondDirection / mainDirection * gridSize));
|
||||
thirdError = (int) (Math.floor(thirdd * gridSize));
|
||||
thirdStep = (int) (Math.round(thirdDirection / mainDirection * gridSize));
|
||||
|
||||
if (secondError + secondStep <= 0) {
|
||||
secondError = -secondStep + 1;
|
||||
@@ -134,6 +134,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
}
|
||||
|
||||
Block lastBlock;
|
||||
|
||||
lastBlock = startBlock.getFace(reverseFace(mainFace));
|
||||
|
||||
if (secondError < 0) {
|
||||
@@ -157,7 +158,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
|
||||
boolean startBlockFound = false;
|
||||
|
||||
for (int cnt=currentBlock; cnt>=0; cnt--) {
|
||||
for (int cnt = currentBlock; cnt >= 0; cnt--) {
|
||||
if (blockEquals(blockQueue[cnt], startBlock)) {
|
||||
currentBlock = cnt;
|
||||
startBlockFound = true;
|
||||
@@ -170,7 +171,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
}
|
||||
|
||||
// Calculate the number of planes passed to give max distance
|
||||
maxDistanceInt = (int)Math.round(maxDistance/(Math.sqrt(mainDirection*mainDirection + secondDirection*secondDirection + thirdDirection*thirdDirection)/mainDirection));
|
||||
maxDistanceInt = (int) Math.round(maxDistance / (Math.sqrt(mainDirection * mainDirection + secondDirection * secondDirection + thirdDirection * thirdDirection) / mainDirection));
|
||||
|
||||
}
|
||||
|
||||
@@ -179,14 +180,27 @@ public class BlockIterator implements Iterator<Block> {
|
||||
}
|
||||
|
||||
private BlockFace reverseFace(BlockFace face) {
|
||||
switch(face) {
|
||||
case UP: return BlockFace.DOWN;
|
||||
case DOWN: return BlockFace.UP;
|
||||
case NORTH: return BlockFace.SOUTH;
|
||||
case SOUTH: return BlockFace.NORTH;
|
||||
case EAST: return BlockFace.WEST;
|
||||
case WEST: return BlockFace.EAST;
|
||||
default: return null;
|
||||
switch (face) {
|
||||
case UP:
|
||||
return BlockFace.DOWN;
|
||||
|
||||
case DOWN:
|
||||
return BlockFace.UP;
|
||||
|
||||
case NORTH:
|
||||
return BlockFace.SOUTH;
|
||||
|
||||
case SOUTH:
|
||||
return BlockFace.NORTH;
|
||||
|
||||
case EAST:
|
||||
return BlockFace.WEST;
|
||||
|
||||
case WEST:
|
||||
return BlockFace.EAST;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +229,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
}
|
||||
|
||||
private double getPosition(double direction, double position, int blockPosition) {
|
||||
return direction > 0 ? (position-blockPosition) : (blockPosition + 1 - position);
|
||||
return direction > 0 ? (position - blockPosition) : (blockPosition + 1 - position);
|
||||
}
|
||||
|
||||
private double getXPosition(Vector direction, Vector position, Block block) {
|
||||
@@ -278,7 +292,6 @@ public class BlockIterator implements Iterator<Block> {
|
||||
this(entity.getLocation(), entity.getEyeHeight(), maxDistance);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the BlockIterator.
|
||||
*
|
||||
@@ -300,7 +313,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
return currentBlock != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the next Block in the trace
|
||||
*
|
||||
* @return the next Block in the trace
|
||||
@@ -311,7 +324,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
if (currentBlock <= -1) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return blockQueue[currentBlock--];
|
||||
return blockQueue[currentBlock--];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +351,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
|
||||
if (secondError > 0 && thirdError > 0) {
|
||||
blockQueue[2] = blockQueue[0].getFace(mainFace);
|
||||
if (((long)secondStep) * ((long)thirdError) < ((long)thirdStep) * ((long)secondError)) {
|
||||
if (((long) secondStep) * ((long) thirdError) < ((long) thirdStep) * ((long) secondError)) {
|
||||
blockQueue[1] = blockQueue[2].getFace(secondFace);
|
||||
blockQueue[0] = blockQueue[1].getFace(thirdFace);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user