mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
.
This commit is contained in:
@ -27,13 +27,14 @@ import com.sk89q.worldedit.regions.iterator.RegionIterator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractRegion implements Region {
|
||||
public abstract class AbstractRegion extends AbstractSet<BlockVector3> implements Region {
|
||||
|
||||
protected World world;
|
||||
|
||||
@ -41,6 +42,11 @@ public abstract class AbstractRegion implements Region {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getCenter() {
|
||||
return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2);
|
||||
@ -100,21 +106,6 @@ public abstract class AbstractRegion implements Region {
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
@Override
|
||||
public int getArea() {
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
|
@ -19,12 +19,20 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.boydti.fawe.beta.ChunkFilterBlock;
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.IChunk;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
import com.boydti.fawe.beta.IChunkSet;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
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;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -54,14 +62,23 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
|
||||
*
|
||||
* @return center point
|
||||
*/
|
||||
Vector3 getCenter();
|
||||
default Vector3 getCenter() {
|
||||
return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
int getArea();
|
||||
default int getArea() {
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
@ -128,7 +145,9 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
|
||||
* @param position the position
|
||||
* @return true if contained
|
||||
*/
|
||||
boolean contains(BlockVector3 position);
|
||||
default boolean contains(BlockVector3 position) {
|
||||
return contains(position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of chunks.
|
||||
@ -172,4 +191,63 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
|
||||
* @return the points.
|
||||
*/
|
||||
List<BlockVector2> polygonize(int maxPoints);
|
||||
|
||||
default int getMinY() {
|
||||
return getMinimumPoint().getY();
|
||||
}
|
||||
|
||||
default int getMaxY() {
|
||||
return getMaximumPoint().getY();
|
||||
}
|
||||
|
||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set) {
|
||||
int minSection = Math.max(0, getMinY() >> 4);
|
||||
int maxSection = Math.min(15, getMaxY() >> 4);
|
||||
for (int layer = minSection; layer <= maxSection; layer++) {
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
|
||||
block = block.init(get, set, layer);
|
||||
block.filter(filter, this);
|
||||
}
|
||||
}
|
||||
|
||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, final int minY, final int maxY) {
|
||||
int minSection = minY >> 4;
|
||||
int maxSection = maxY >> 4;
|
||||
int yStart = (minY & 15);
|
||||
int yEnd = (maxY & 15);
|
||||
if (minSection == maxSection) {
|
||||
filter(chunk, filter, block, get, set, minSection, yStart, yEnd);
|
||||
return;
|
||||
}
|
||||
if (yStart != 0) {
|
||||
filter(chunk, filter, block, get, set, minSection, yStart, 15);
|
||||
minSection++;
|
||||
}
|
||||
if (yEnd != 15) {
|
||||
filter(chunk, filter, block, get, set, minSection, 0, yEnd);
|
||||
maxSection--;
|
||||
}
|
||||
for (int layer = minSection; layer < maxSection; layer++) {
|
||||
filter(chunk, filter, block, get, set, layer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer) {
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
|
||||
block = block.init(get, set, layer);
|
||||
block.filter(filter);
|
||||
}
|
||||
|
||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
|
||||
block = block.init(get, set, layer);
|
||||
block.filter(filter, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
default void filter(final IChunk chunk, final Filter filter, ChunkFilterBlock block, final IChunkGet get, final IChunkSet set, int layer, int yStart, int yEnd) {
|
||||
if (!get.hasSection(layer) || !filter.appliesLayer(chunk, layer)) return;
|
||||
block = block.init(get, set, layer);
|
||||
block.filter(filter, yStart, yEnd);
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -31,6 +28,9 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An intersection of several other regions. Any location that is contained in one
|
||||
* of the child regions is considered as contained by this region.
|
||||
|
@ -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