Reduced some code duplication in the regions.

This commit is contained in:
TomyLobo
2013-07-31 10:35:47 +02:00
committed by wizjany
parent c838ef7b25
commit 22798f49c8
5 changed files with 120 additions and 173 deletions

View File

@ -20,17 +20,13 @@
package com.sk89q.worldedit.regions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.data.ChunkStore;
/**
* Represents a cylindrical region.
@ -314,49 +310,6 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
return pt.toVector2D().subtract(center).divide(radius).lengthSq() <= 1;
}
/**
* Get a list of chunks.
*
* @return
*/
public Set<Vector2D> getChunks() {
Set<Vector2D> chunks = new HashSet<Vector2D>();
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))) {
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) {
if (contains(new BlockVector(x, y, z))) {
chunks.add(new BlockVector(x >> ChunkStore.CHUNK_SHIFTS,
y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
}
}
}
}
return chunks;
}
/**
* Sets the height of the cylinder to fit the specified Y.