mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-09-19 13:58:22 +00:00
50ab8ad5c7
* Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit275ba9bd84
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit9fd8984804
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit861fb45e5c
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit420c45a29a
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit4d4db7dcd0
Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commitc98f6e4f37
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit2485f5eccc
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commitd9418ec8ae
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of41073bb1a0
Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
426 lines
12 KiB
Java
426 lines
12 KiB
Java
/*
|
|
* 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 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.sk89q.worldedit.regions;
|
|
|
|
import com.fastasyncworldedit.core.queue.Filter;
|
|
import com.fastasyncworldedit.core.queue.IChunk;
|
|
import com.fastasyncworldedit.core.queue.IChunkGet;
|
|
import com.fastasyncworldedit.core.queue.IChunkSet;
|
|
import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock;
|
|
import com.fastasyncworldedit.core.configuration.Caption;
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
import com.sk89q.worldedit.math.Vector2;
|
|
import com.sk89q.worldedit.math.Vector3;
|
|
import com.sk89q.worldedit.math.geom.Polygons;
|
|
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
|
|
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
|
|
import com.sk89q.worldedit.world.World;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
/**
|
|
* Represents a cylindrical region.
|
|
*/
|
|
public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
|
|
|
private BlockVector2 center;
|
|
private Vector2 radius;
|
|
private Vector2 radiusInverse;
|
|
private int minY;
|
|
private int maxY;
|
|
private boolean hasY = false;
|
|
|
|
/**
|
|
* Construct the region.
|
|
*/
|
|
public CylinderRegion() {
|
|
this((World) null);
|
|
}
|
|
|
|
/**
|
|
* Construct the region.
|
|
*
|
|
* @param world the world
|
|
*/
|
|
public CylinderRegion(World world) {
|
|
this(world, BlockVector3.ZERO, Vector2.ZERO, 0, 0);
|
|
hasY = false;
|
|
}
|
|
|
|
/**
|
|
* Construct the region.
|
|
*
|
|
* @param world the world
|
|
* @param center the center position
|
|
* @param radius the radius along the X and Z axes
|
|
* @param minY the minimum Y, inclusive
|
|
* @param maxY the maximum Y, inclusive
|
|
*/
|
|
public CylinderRegion(World world, BlockVector3 center, Vector2 radius, int minY, int maxY) {
|
|
super(world);
|
|
setCenter(center.toBlockVector2());
|
|
setRadius(radius);
|
|
this.minY = minY;
|
|
this.maxY = maxY;
|
|
hasY = true;
|
|
}
|
|
|
|
/**
|
|
* Construct the region.
|
|
*
|
|
* @param center the center position
|
|
* @param radius the radius along the X and Z axes
|
|
* @param minY the minimum Y, inclusive
|
|
* @param maxY the maximum Y, inclusive
|
|
*/
|
|
public CylinderRegion(BlockVector3 center, Vector2 radius, int minY, int maxY) {
|
|
super(null);
|
|
setCenter(center.toBlockVector2());
|
|
setRadius(radius);
|
|
this.minY = minY;
|
|
this.maxY = maxY;
|
|
hasY = true;
|
|
}
|
|
|
|
public CylinderRegion(CylinderRegion region) {
|
|
this(region.world, region.getCenter().toBlockPoint(), region.getRadius(), region.minY, region.maxY);
|
|
hasY = region.hasY;
|
|
}
|
|
|
|
@Override
|
|
public Vector3 getCenter() {
|
|
return center.toVector3((maxY + minY) / 2);
|
|
}
|
|
|
|
/**
|
|
* Sets the main center point of the region.
|
|
*
|
|
* @param center the center point
|
|
*/
|
|
public void setCenter(BlockVector2 center) {
|
|
this.center = center;
|
|
}
|
|
|
|
/**
|
|
* Returns the radius of the cylinder.
|
|
*
|
|
* @return the radius along the X and Z axes
|
|
*/
|
|
public Vector2 getRadius() {
|
|
return radius.subtract(0.5, 0.5);
|
|
}
|
|
|
|
/**
|
|
* Sets the radius of the cylinder.
|
|
*
|
|
* @param radius the radius along the X and Z axes
|
|
*/
|
|
public void setRadius(Vector2 radius) {
|
|
this.radius = radius.add(0.5, 0.5);
|
|
this.radiusInverse = Vector2.ONE.divide(radius);
|
|
}
|
|
|
|
/**
|
|
* Extends the radius to be at least the given radius.
|
|
*
|
|
* @param minRadius the minimum radius
|
|
*/
|
|
public void extendRadius(Vector2 minRadius) {
|
|
setRadius(minRadius.getMaximum(getRadius()));
|
|
}
|
|
|
|
/**
|
|
* Set the minimum Y.
|
|
*
|
|
* @param y the y
|
|
*/
|
|
public void setMinimumY(int y) {
|
|
hasY = true;
|
|
minY = y;
|
|
}
|
|
|
|
/**
|
|
* Se the maximum Y.
|
|
*
|
|
* @param y the y
|
|
*/
|
|
public void setMaximumY(int y) {
|
|
hasY = true;
|
|
maxY = y;
|
|
}
|
|
|
|
@Override
|
|
public BlockVector3 getMinimumPoint() {
|
|
return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint();
|
|
}
|
|
|
|
@Override
|
|
public BlockVector3 getMaximumPoint() {
|
|
return center.toVector2().add(getRadius()).toVector3(maxY).toBlockPoint();
|
|
}
|
|
|
|
@Override
|
|
public int getMaximumY() {
|
|
return maxY;
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumY() {
|
|
return minY;
|
|
}
|
|
|
|
private static final BigDecimal PI = BigDecimal.valueOf(Math.PI);
|
|
|
|
@Override
|
|
public long getVolume() {
|
|
return BigDecimal.valueOf(radius.getX())
|
|
.multiply(BigDecimal.valueOf(radius.getZ()))
|
|
.multiply(PI)
|
|
.multiply(BigDecimal.valueOf(getHeight()))
|
|
.setScale(0, RoundingMode.FLOOR)
|
|
.longValue();
|
|
}
|
|
|
|
@Override
|
|
public int getWidth() {
|
|
return (int) (2 * radius.getX());
|
|
}
|
|
|
|
@Override
|
|
public int getHeight() {
|
|
return maxY - minY + 1;
|
|
}
|
|
|
|
@Override
|
|
public int getLength() {
|
|
return (int) (2 * radius.getZ());
|
|
}
|
|
|
|
private BlockVector2 calculateDiff2D(BlockVector3... changes) throws RegionOperationException {
|
|
BlockVector2 diff = BlockVector2.ZERO;
|
|
for (BlockVector3 change : changes) {
|
|
diff = diff.add(change.toBlockVector2());
|
|
}
|
|
|
|
if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) {
|
|
throw new RegionOperationException(Caption.of("worldedit.selection.cylinder.error.even-horizontal"));
|
|
}
|
|
|
|
return diff.divide(2).floor();
|
|
}
|
|
|
|
private BlockVector2 calculateChanges2D(BlockVector3... changes) {
|
|
BlockVector2 total = BlockVector2.ZERO;
|
|
for (BlockVector3 change : changes) {
|
|
total = total.add(change.toBlockVector2().abs());
|
|
}
|
|
|
|
return total.divide(2).floor();
|
|
}
|
|
|
|
/**
|
|
* Expand the region.
|
|
* Expand the region.
|
|
*
|
|
* @param changes array/arguments with multiple related changes
|
|
*/
|
|
@Override
|
|
public void expand(BlockVector3... changes) throws RegionOperationException {
|
|
center = center.add(calculateDiff2D(changes));
|
|
radius = radius.add(calculateChanges2D(changes).toVector2());
|
|
this.radiusInverse = Vector2.ONE.divide(radius);
|
|
for (BlockVector3 change : changes) {
|
|
int changeY = change.getBlockY();
|
|
if (changeY > 0) {
|
|
maxY += changeY;
|
|
} else {
|
|
minY += changeY;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Contract the region.
|
|
*
|
|
* @param changes array/arguments with multiple related changes
|
|
*/
|
|
@Override
|
|
public void contract(BlockVector3... changes) throws RegionOperationException {
|
|
center = center.subtract(calculateDiff2D(changes));
|
|
Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2());
|
|
radius = Vector2.at(1.5, 1.5).getMaximum(newRadius);
|
|
this.radiusInverse = Vector2.ONE.divide(radius);
|
|
for (BlockVector3 change : changes) {
|
|
int height = maxY - minY;
|
|
int changeY = change.getBlockY();
|
|
if (changeY > 0) {
|
|
minY += Math.min(height, changeY);
|
|
} else {
|
|
maxY += Math.max(-height, changeY);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void shift(BlockVector3 change) throws RegionOperationException {
|
|
center = center.add(change.toBlockVector2());
|
|
|
|
int changeY = change.getBlockY();
|
|
maxY += changeY;
|
|
minY += changeY;
|
|
}
|
|
|
|
/**
|
|
* Checks to see if a point is inside this region.
|
|
*/
|
|
/* FAWE start - Slow and unnecessary
|
|
@Override
|
|
public boolean contains(BlockVector3 position) {
|
|
final int blockY = position.getBlockY();
|
|
if (blockY < minY || blockY > maxY) {
|
|
return false;
|
|
}
|
|
|
|
return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1;
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* Checks to see if a point is inside this region.
|
|
*/
|
|
@Override
|
|
public boolean contains(int x, int y, int z) {
|
|
if (y < minY || y > maxY) {
|
|
return false;
|
|
}
|
|
return contains(x, z);
|
|
}
|
|
|
|
@Override
|
|
public boolean contains(int x, int z) {
|
|
double dx = Math.abs(x - center.getBlockX()) * radiusInverse.getX();
|
|
double dz = Math.abs(z - center.getBlockZ()) * radiusInverse.getZ();
|
|
|
|
return dx * dx + dz * dz <= 1;
|
|
}
|
|
|
|
@Override
|
|
public boolean contains(BlockVector3 position) {
|
|
return contains(position.getX(), position.getY(), position.getZ());
|
|
}
|
|
//FAWE end
|
|
|
|
/**
|
|
* Sets the height of the cylinder to fit the specified Y.
|
|
*
|
|
* @param y the y value
|
|
* @return true if the area was expanded
|
|
*/
|
|
public boolean setY(int y) {
|
|
if (!hasY) {
|
|
minY = y;
|
|
maxY = y;
|
|
hasY = true;
|
|
return true;
|
|
} else if (y < minY) {
|
|
minY = y;
|
|
return true;
|
|
} else if (y > maxY) {
|
|
maxY = y;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Iterator<BlockVector3> iterator() {
|
|
return new FlatRegion3DIterator(this);
|
|
}
|
|
|
|
@Override
|
|
public Iterable<BlockVector2> asFlatRegion() {
|
|
return () -> new FlatRegionIterator(CylinderRegion.this);
|
|
}
|
|
|
|
/**
|
|
* Returns string representation in the format.
|
|
* "(centerX, centerZ) - (radiusX, radiusZ) - (minY, maxY)"
|
|
*
|
|
* @return string
|
|
*/
|
|
@Override
|
|
public String toString() {
|
|
return center + " - " + radius + "(" + minY + ", " + maxY + ")";
|
|
}
|
|
|
|
@Override
|
|
public CylinderRegion clone() {
|
|
return (CylinderRegion) super.clone();
|
|
}
|
|
|
|
@Override
|
|
public List<BlockVector2> polygonize(int maxPoints) {
|
|
return Polygons.polygonizeCylinder(center, radius, maxPoints);
|
|
}
|
|
|
|
/**
|
|
* Return a new instance with the given center and radius in the X and Z
|
|
* axes with a Y that extends from the bottom of the extent to the top
|
|
* of the extent.
|
|
*
|
|
* @param extent the extent
|
|
* @param center the center position
|
|
* @param radius the radius in the X and Z axes
|
|
* @return a region
|
|
*/
|
|
public static CylinderRegion createRadius(Extent extent, BlockVector3 center, double radius) {
|
|
checkNotNull(extent);
|
|
checkNotNull(center);
|
|
Vector2 radiusVec = Vector2.at(radius, radius);
|
|
int minY = extent.getMinimumPoint().getBlockY();
|
|
int maxY = extent.getMaximumPoint().getBlockY();
|
|
return new CylinderRegion(center, radiusVec, minY, maxY);
|
|
}
|
|
|
|
//FAWE start
|
|
@Override
|
|
public void filter(final IChunk chunk, final Filter filter, final ChunkFilterBlock block,
|
|
final IChunkGet get, final IChunkSet set, boolean full) {
|
|
int bcx = chunk.getX() >> 4;
|
|
int bcz = chunk.getZ() >> 4;
|
|
int tcx = bcx + 15;
|
|
int tcz = bcz + 15;
|
|
if (contains(bcx, bcz) && contains(tcx, tcz)) {
|
|
filter(chunk, filter, block, get, set, minY, maxY, full);
|
|
return;
|
|
}
|
|
super.filter(chunk, filter, block, get, set, full);
|
|
}
|
|
//FAWE end
|
|
}
|