use of com.google.common.collect.AbstractIterator in project Wurst-MC-1.12 by Wurst-Imperium.
the class BlockUtils method getValidBlocks.
public static Iterable<BlockPos> getValidBlocks(int blockRange, BlockValidator validator) {
BlockPos playerPos = new BlockPos(RotationUtils.getEyesPos());
BlockPos min = playerPos.add(-blockRange, -blockRange, -blockRange);
BlockPos max = playerPos.add(blockRange, blockRange, blockRange);
return () -> new AbstractIterator<BlockPos>() {
private BlockPos last;
private BlockPos computeNextUnchecked() {
if (last == null) {
last = min;
return last;
}
int x = last.getX();
int y = last.getY();
int z = last.getZ();
if (z < max.getZ())
z++;
else if (x < max.getX()) {
z = min.getZ();
x++;
} else if (y < max.getY()) {
z = min.getZ();
x = min.getX();
y++;
} else
return null;
last = new BlockPos(x, y, z);
return last;
}
@Override
protected BlockPos computeNext() {
BlockPos pos;
while ((pos = computeNextUnchecked()) != null) {
// skip air blocks
if (WBlock.getMaterial(pos) == Material.AIR)
continue;
// check if block is valid
if (!validator.isValid(pos))
continue;
return pos;
}
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project DynamicSurroundings by OreCruncher.
the class BlockPosHelper method getAllInBoxMutable.
/**
* Like getAllInBox but reuses a single MutableBlockPos instead. If this method
* is used, the resulting BlockPos instances can only be used inside the
* iteration loop.
*
* NOTE: This is similar to the logic in Forge. Difference is that it favors
* iterating along the Y axis first before X/Z. Goal is to maximize chunk
* caching for area scanning.
*/
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(BlockPos from, BlockPos to) {
final BlockPos blockpos = createMinPoint(from, to);
final BlockPos blockpos1 = createMaxPoint(from, to);
return () -> new AbstractIterator<BlockPos.MutableBlockPos>() {
private BlockPos.MutableBlockPos theBlockPos;
@Override
protected BlockPos.MutableBlockPos computeNext() {
if (this.theBlockPos == null) {
this.theBlockPos = new BlockPos.MutableBlockPos(blockpos.getX(), blockpos.getY(), blockpos.getZ());
return this.theBlockPos;
} else if (this.theBlockPos.equals(blockpos1)) {
return endOfData();
} else {
int i = this.theBlockPos.getX();
int j = this.theBlockPos.getY();
int k = this.theBlockPos.getZ();
if (j < blockpos1.getY()) {
++j;
} else if (i < blockpos1.getX()) {
j = blockpos.getY();
++i;
} else if (k < blockpos1.getZ()) {
i = blockpos.getX();
j = blockpos.getY();
++k;
}
this.theBlockPos.setPos(i, j, k);
return this.theBlockPos;
}
}
};
}
use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class TestSelectiveOrcReader method skipEvery.
private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
return () -> new AbstractIterator<T>() {
private final Iterator<T> delegate = iterable.iterator();
private int position;
@Override
protected T computeNext() {
while (true) {
if (!delegate.hasNext()) {
return endOfData();
}
T next = delegate.next();
position++;
if (position <= n) {
return next;
}
position = 0;
}
}
};
}
use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class AbstractTestParquetReader method skipEvery.
private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
return () -> new AbstractIterator<T>() {
private final Iterator<T> delegate = iterable.iterator();
private int position;
@Override
protected T computeNext() {
while (true) {
if (!delegate.hasNext()) {
return endOfData();
}
T next = delegate.next();
position++;
if (position <= n) {
return next;
}
position = 0;
}
}
};
}
use of com.google.common.collect.AbstractIterator in project presto by prestodb.
the class AbstractTestOrcReader method skipEvery.
private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
return () -> new AbstractIterator<T>() {
private final Iterator<T> delegate = iterable.iterator();
private int position;
@Override
protected T computeNext() {
while (true) {
if (!delegate.hasNext()) {
return endOfData();
}
T next = delegate.next();
position++;
if (position <= n) {
return next;
}
position = 0;
}
}
};
}
Aggregations