Added getChunkCubes() to Region to get 16^3 chunks a region overlaps with

This commit is contained in:
zml2008
2012-03-29 21:06:43 -07:00
parent 3bfb12c051
commit 03f7d4ecfb
5 changed files with 161 additions and 42 deletions

View File

@ -269,7 +269,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
/**
* Expand the region.
*
* @param change
* @param changes
*/
public void expand(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
@ -292,7 +292,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
/**
* Contract the region.
*
* @param change
* @param changes
*/
public void contract(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
@ -415,12 +415,31 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
Vector min = getMinimumPoint();
Vector max = getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
if (contains(new BlockVector(x, minY, z))) { // Not the best
chunks.add(new BlockVector2D(x >> ChunkStore.CHUNK_SHIFTS,
z >> ChunkStore.CHUNK_SHIFTS));
}
}
}
return chunks;
}
@Override
public Set<Vector> getChunkCubes() {
Set<Vector> chunks = new HashSet<Vector>();
Vector min = getMinimumPoint();
Vector max = getMaximumPoint();
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
Vector pt = new Vector(x, y, z);
if (contains(pt)) { // Not the best
chunks.add(ChunkStore.toChunk(pt));
if (contains(new BlockVector(x, y, z))) { // Not the best
chunks.add(new BlockVector(x >> ChunkStore.CHUNK_SHIFTS,
y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
}
}
}