2012-01-05 21:38:23 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2012-01-05 21:38:23 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2012-01-05 21:38:23 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2012-01-05 21:38:23 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2012-01-05 21:38:23 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2012-01-05 21:38:23 +00:00
|
|
|
|
2012-01-03 14:57:29 +00:00
|
|
|
package com.sk89q.worldedit.regions;
|
|
|
|
|
2014-04-04 01:32:51 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2012-01-03 15:13:50 +00:00
|
|
|
import com.sk89q.worldedit.Vector;
|
2014-04-04 01:32:51 +00:00
|
|
|
import com.sk89q.worldedit.regions.iterator.RegionIterator;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.world.storage.ChunkStore;
|
2012-01-03 14:57:29 +00:00
|
|
|
|
2014-04-04 01:32:51 +00:00
|
|
|
import java.util.*;
|
|
|
|
|
2012-01-03 14:57:29 +00:00
|
|
|
public abstract class AbstractRegion implements Region {
|
|
|
|
/**
|
|
|
|
* Stores the world.
|
|
|
|
*/
|
|
|
|
protected LocalWorld world;
|
|
|
|
|
|
|
|
public AbstractRegion(LocalWorld world) {
|
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
2012-08-29 08:00:26 +00:00
|
|
|
@Override
|
|
|
|
public Vector getCenter() {
|
|
|
|
return getMinimumPoint().add(getMaximumPoint()).divide(2);
|
|
|
|
}
|
|
|
|
|
2012-01-03 14:57:29 +00:00
|
|
|
/**
|
|
|
|
* Get the iterator.
|
|
|
|
*
|
|
|
|
* @return iterator of points inside the region
|
|
|
|
*/
|
|
|
|
public Iterator<BlockVector> iterator() {
|
|
|
|
return new RegionIterator(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocalWorld getWorld() {
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWorld(LocalWorld world) {
|
|
|
|
this.world = world;
|
|
|
|
}
|
2012-01-03 15:13:50 +00:00
|
|
|
|
|
|
|
public void shift(Vector change) throws RegionOperationException {
|
|
|
|
expand(change);
|
|
|
|
contract(change);
|
|
|
|
}
|
2012-03-20 14:14:41 +00:00
|
|
|
|
|
|
|
public AbstractRegion clone() {
|
|
|
|
try {
|
|
|
|
return (AbstractRegion) super.clone();
|
|
|
|
} catch (CloneNotSupportedException exc) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2013-07-27 09:12:29 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<BlockVector2D> polygonize(int maxPoints) {
|
|
|
|
if (maxPoints >= 0 && maxPoints < 4) {
|
|
|
|
throw new IllegalArgumentException("Cannot polygonize an AbstractRegion with no overridden polygonize method into less than 4 points.");
|
|
|
|
}
|
|
|
|
|
|
|
|
final BlockVector min = getMinimumPoint().toBlockVector();
|
|
|
|
final BlockVector max = getMaximumPoint().toBlockVector();
|
|
|
|
|
|
|
|
final List<BlockVector2D> points = new ArrayList<BlockVector2D>(4);
|
|
|
|
|
|
|
|
points.add(new BlockVector2D(min.getX(), min.getZ()));
|
|
|
|
points.add(new BlockVector2D(min.getX(), max.getZ()));
|
|
|
|
points.add(new BlockVector2D(max.getX(), max.getZ()));
|
|
|
|
points.add(new BlockVector2D(max.getX(), min.getZ()));
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
2013-07-31 08:35:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of blocks in the region.
|
|
|
|
*
|
|
|
|
* @return number of blocks
|
|
|
|
*/
|
|
|
|
public int getArea() {
|
|
|
|
Vector min = getMinimumPoint();
|
|
|
|
Vector max = getMaximumPoint();
|
|
|
|
|
|
|
|
return (int)((max.getX() - min.getX() + 1) *
|
|
|
|
(max.getY() - min.getY() + 1) *
|
|
|
|
(max.getZ() - min.getZ() + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get X-size.
|
|
|
|
*
|
|
|
|
* @return width
|
|
|
|
*/
|
|
|
|
public int getWidth() {
|
|
|
|
Vector min = getMinimumPoint();
|
|
|
|
Vector max = getMaximumPoint();
|
|
|
|
|
|
|
|
return (int) (max.getX() - min.getX() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Y-size.
|
|
|
|
*
|
|
|
|
* @return height
|
|
|
|
*/
|
|
|
|
public int getHeight() {
|
|
|
|
Vector min = getMinimumPoint();
|
|
|
|
Vector max = getMaximumPoint();
|
|
|
|
|
|
|
|
return (int) (max.getY() - min.getY() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Z-size.
|
|
|
|
*
|
|
|
|
* @return length
|
|
|
|
*/
|
|
|
|
public int getLength() {
|
|
|
|
Vector min = getMinimumPoint();
|
|
|
|
Vector max = getMaximumPoint();
|
|
|
|
|
|
|
|
return (int) (max.getZ() - min.getZ() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of chunks.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Set<Vector2D> getChunks() {
|
|
|
|
final Set<Vector2D> chunks = new HashSet<Vector2D>();
|
|
|
|
|
|
|
|
final Vector min = getMinimumPoint();
|
|
|
|
final Vector max = getMaximumPoint();
|
|
|
|
|
|
|
|
final int minY = min.getBlockY();
|
|
|
|
|
|
|
|
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
|
|
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
|
|
|
if (!contains(new Vector(x, minY, z))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks.add(new BlockVector2D(
|
|
|
|
x >> ChunkStore.CHUNK_SHIFTS,
|
|
|
|
z >> ChunkStore.CHUNK_SHIFTS
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<Vector> getChunkCubes() {
|
|
|
|
final Set<Vector> chunks = new HashSet<Vector>();
|
|
|
|
|
|
|
|
final Vector min = getMinimumPoint();
|
|
|
|
final 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 Vector(x, y, z))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks.add(new BlockVector(
|
|
|
|
x >> ChunkStore.CHUNK_SHIFTS,
|
|
|
|
y >> ChunkStore.CHUNK_SHIFTS,
|
|
|
|
z >> ChunkStore.CHUNK_SHIFTS
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunks;
|
|
|
|
}
|
2012-01-03 14:57:29 +00:00
|
|
|
}
|