mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 04:46:40 +00:00
Region filter
This commit is contained in:
@ -41,6 +41,7 @@ import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.*;
|
||||
|
||||
/**
|
||||
* An axis-aligned cuboid. It can be defined using two corners of the cuboid.
|
||||
@ -627,5 +628,36 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
return new CuboidRegion(origin.subtract(size), origin.add(size));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
|
||||
int minChunkX = minX >> 4;
|
||||
if (minChunkX <= X) {
|
||||
int maxChunkX = maxX >> 4;
|
||||
if (maxChunkX >= X) {
|
||||
int minChunkZ = minZ >> 4;
|
||||
if (minChunkZ <= X) {
|
||||
int maxChunkZ = maxZ >> 4;
|
||||
if (maxChunkZ >= Z) {
|
||||
int cx1 = X << 4;
|
||||
int cx2 = cx1 + 15;
|
||||
int cz1 = Z << 4;
|
||||
int cz2 = cz1 + 15;
|
||||
|
||||
int bx = Math.max(cx1, minX);
|
||||
int bz = Math.max(cz1, minZ);
|
||||
int tx = Math.min(cx2, maxX);
|
||||
int tz = Math.min(cz2, maxZ);
|
||||
|
||||
min.setComponents(bx & 15, minY, bz & 15);
|
||||
max.setComponents(tx & 15, maxY, tz & 15);
|
||||
if (min.getX() == 0 && min.getZ() == 0 && max.getX() == 15 && max.getZ() == 15) {
|
||||
return FULL;
|
||||
}
|
||||
return PARTIAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
@ -28,6 +29,9 @@ import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
|
||||
|
||||
/**
|
||||
* Represents a physical shape.
|
||||
*/
|
||||
@ -178,4 +182,33 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
|
||||
* @return the points.
|
||||
*/
|
||||
List<BlockVector2> polygonize(int maxPoints);
|
||||
|
||||
default Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
|
||||
BlockVector3 pos1 = getMinimumPoint();
|
||||
BlockVector3 pos2 = getMaximumPoint();
|
||||
int cx1 = X << 4;
|
||||
int cx2 = cx1 + 15;
|
||||
int cz1 = Z << 4;
|
||||
int cz2 = cz1 + 15;
|
||||
|
||||
int bx = Math.max(cx1, pos1.getX());
|
||||
int bz = Math.max(cz1, pos1.getZ());
|
||||
int tx = Math.min(cx2, pos2.getX());
|
||||
int tz = Math.min(cz2, pos2.getZ());
|
||||
|
||||
min.setComponents(bx & 15, pos1.getY(), bz & 15);
|
||||
max.setComponents(tx & 15, pos2.getY(), tz & 15);
|
||||
|
||||
if (bx > cx2 || bz > cz2 || tx < cx1 || tz < cz1) {
|
||||
return NONE;
|
||||
}
|
||||
return CHECKED;
|
||||
}
|
||||
|
||||
enum Contains {
|
||||
FULL,
|
||||
PARTIAL,
|
||||
CHECKED,
|
||||
NONE;
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,14 @@ package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.FULL;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
|
||||
import static com.sk89q.worldedit.regions.Region.Contains.PARTIAL;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.transform.Identity;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Transforms another region according to a provided vector {@code Transform}.
|
||||
*
|
||||
* @see Transform
|
||||
*/
|
||||
public class TransformRegion extends AbstractRegion {
|
||||
|
||||
private final Region region;
|
||||
private Transform transform = new Identity();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param region the region
|
||||
* @param transform the transform
|
||||
*/
|
||||
public TransformRegion(Region region, Transform transform) {
|
||||
this(null, region, transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param world the world, which may be null
|
||||
* @param region the region
|
||||
* @param transform the transform
|
||||
*/
|
||||
public TransformRegion(@Nullable World world, Region region, Transform transform) {
|
||||
super(world);
|
||||
checkNotNull(region);
|
||||
checkNotNull(transform);
|
||||
this.region = region;
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the untransformed, base region.
|
||||
*
|
||||
* @return the base region
|
||||
*/
|
||||
public Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transform that is applied.
|
||||
*
|
||||
* @return the transform
|
||||
*/
|
||||
public Transform getTransform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the transform that is applied.
|
||||
*
|
||||
* @param transform the transform
|
||||
*/
|
||||
public void setTransform(Transform transform) {
|
||||
checkNotNull(transform);
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector3 getMinimumPoint() {
|
||||
return transform.apply(region.getMinimumPoint().toVector3()).toBlockPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector3 getMaximumPoint() {
|
||||
return transform.apply(region.getMaximumPoint().toVector3()).toBlockPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getCenter() {
|
||||
return transform.apply(region.getCenter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea(); // Cannot transform this
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockX() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockY() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockZ() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expand(BlockVector3... changes) throws RegionOperationException {
|
||||
throw new RegionOperationException("Can't expand a TransformedRegion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contract(BlockVector3... changes) throws RegionOperationException {
|
||||
throw new RegionOperationException("Can't contract a TransformedRegion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shift(BlockVector3 change) throws RegionOperationException {
|
||||
throw new RegionOperationException("Can't change a TransformedRegion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BlockVector3 position) {
|
||||
return region.contains(transform.inverse().apply(position.toVector3()).toBlockPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector2> polygonize(int maxPoints) {
|
||||
List<BlockVector2> origPoints = region.polygonize(maxPoints);
|
||||
List<BlockVector2> transformedPoints = new ArrayList<>();
|
||||
for (BlockVector2 vector : origPoints) {
|
||||
transformedPoints.add(transform.apply(vector.toVector3(0)).toVector2().toBlockPoint());
|
||||
}
|
||||
return transformedPoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
final Iterator<BlockVector3> it = region.iterator();
|
||||
|
||||
return new Iterator<BlockVector3>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector3 next() {
|
||||
BlockVector3 next = it.next();
|
||||
if (next != null) {
|
||||
return transform.apply(next.toVector3()).toBlockPoint();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
it.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user