Added range command for brushes. Thanks Nichts

This commit is contained in:
Wizjany
2011-06-22 18:28:56 -04:00
parent 45302859ef
commit 021e99c252
6 changed files with 86 additions and 4 deletions

View File

@ -100,6 +100,31 @@ public class TargetBlock {
prevPos = targetPos;
}
/**
* Returns any block at the sight. Returns null if out of range or if no
* viable target was found. Will try to return the last valid air block it finds.
*
* @return Block
*/
public BlockWorldVector getAnyTargetBlock() {
boolean searchForLastBlock = true;
BlockWorldVector lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlockType(getCurrentBlock()) == 0) {
if(searchForLastBlock) {
lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= 127) {
searchForLastBlock = false;
}
}
} else {
break;
}
}
BlockWorldVector currentBlock = getCurrentBlock();
return (currentBlock != null ? currentBlock : lastBlock);
}
/**
* Returns the block at the sight. Returns null if out of range or if no
* viable target was found