Revert matt's changes

Let's not break Fawe, thanks
This commit is contained in:
N0tMyFaultOG
2020-06-13 18:48:57 +02:00
parent 56f29a3962
commit bfcc6184ad
75 changed files with 687 additions and 980 deletions

View File

@ -1102,7 +1102,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param radius the radius of the spherical area to fill
* @param depth the maximum depth, starting from the origin
* @param direction the direction to fill
* @return the number of blocks affected
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fillDirection(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, BlockVector3 direction) throws MaxChangedBlocksException {
@ -1181,7 +1181,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
visitor.visit(origin);
// Execute
Operations.completeLegacy(visitor);
Operations.completeBlindly(visitor);
return this.changes = visitor.getAffected();
}
@ -2185,13 +2185,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
*
* @param position a position
* @param radius a radius
* @param onlyNormalDirt only affect normal dirt (all default properties)
* @param onlyNormalDirt only affect normal dirt (data value 0)
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@Deprecated
public int green(BlockVector3 position, double radius, boolean onlyNormalDirt)
throws MaxChangedBlocksException {
throws MaxChangedBlocksException {
final double radiusSq = radius * radius;
final int ox = position.getBlockX();
@ -2258,7 +2257,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
Operations.completeLegacy(visitor);
Operations.completeBlindly(visitor);
return this.changes = ground.getAffected();
}
@ -2404,42 +2403,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
return changed;
}
/**
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
* to an expression, and then sets the block to the block given by the resulting values of the variables, if they
* have changed.
*
* @param region the region to deform
* @param zero the origin of the coordinate system
* @param unit the scale of the coordinate system
* @param expressionString the expression to evaluate for each block
*
* @return number of blocks changed
*
* @throws ExpressionException thrown on invalid expression input
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString)
throws ExpressionException, MaxChangedBlocksException {
return deformRegion(region, zero, unit, expressionString, WorldEdit.getInstance().getConfiguration().calculationTimeout);
}
/**
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
* to an expression, and then sets the block to the block given by the resulting values of the variables, if they
* have changed.
*
* @param region the region to deform
* @param zero the origin of the coordinate system
* @param unit the scale of the coordinate system
* @param expressionString the expression to evaluate for each block
* @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
*
* @return number of blocks changed
*
* @throws ExpressionException thrown on invalid expression input
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString,
final int timeout) throws ExpressionException, MaxChangedBlocksException {
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
@ -2457,6 +2425,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
final Vector3 zero2 = zero.add(0.5, 0.5, 0.5);
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
private final MutableBlockVector3 mutable = new MutableBlockVector3();
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {

View File

@ -176,7 +176,7 @@ public class ClipboardCommands {
lazyClipboard.setOrigin(session.getPlacementPosition(actor));
session.setClipboard(new ClipboardHolder(lazyClipboard));
actor.print(Caption.of("fawe.worldedit.copy.command.copy" , region.getVolume()));
actor.print(Caption.of("fawe.worldedit.copy.command.copy" , region.getArea()));
}
// @Command(

View File

@ -104,14 +104,14 @@ public class ExpandCommands {
private static void expandVert(LocalSession session, Actor actor, World world) throws IncompleteRegionException {
Region region = session.getSelection(world);
try {
long oldSize = region.getVolume();
int oldSize = region.getArea();
region.expand(
BlockVector3.at(0, (world.getMaxY() + 1), 0),
BlockVector3.at(0, -(world.getMaxY() + 1), 0));
session.getRegionSelector(world).learnChanges();
long newSize = region.getVolume();
int newSize = region.getArea();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
long changeSize = newSize - oldSize;
int changeSize = newSize - oldSize;
actor.printInfo(
TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize))
);
@ -134,7 +134,7 @@ public class ExpandCommands {
@MultiDirection
List<BlockVector3> direction) throws WorldEditException {
Region region = session.getSelection(world);
long oldSize = region.getVolume();
int oldSize = region.getArea();
if (reverseAmount == 0) {
for (BlockVector3 dir : direction) {
@ -147,11 +147,11 @@ public class ExpandCommands {
}
session.getRegionSelector(world).learnChanges();
long newSize = region.getVolume();
int newSize = region.getArea();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
long changeSize = newSize - oldSize;
int changeSize = newSize - oldSize;
actor.printInfo(TranslatableComponent.of("worldedit.expand.expanded", TextComponent.of(changeSize)));
}

View File

@ -7,7 +7,10 @@
//import com.boydti.fawe.object.mask.BiomeMask;
//import com.boydti.fawe.object.mask.BlockLightMask;
//import com.boydti.fawe.object.mask.BrightnessMask;
//import com.boydti.fawe.object.mask.DataMask;
//import com.boydti.fawe.object.mask.ExtremaMask;
//import com.boydti.fawe.object.mask.IdDataMask;
//import com.boydti.fawe.object.mask.IdMask;
//import com.boydti.fawe.object.mask.LightMask;
//import com.boydti.fawe.object.mask.OpacityMask;
//import com.boydti.fawe.object.mask.ROCAngleMask;
@ -168,6 +171,22 @@
// }
//
// @Command(
// name = "#id",
// desc = "Restrict to initial id"
// )
// public Mask id(Extent extent) {
// return new IdMask(extent);
// }
//
// @Command(
// name = "#data",
// desc = "Restrict to initial data"
// )
// public Mask data(Extent extent) {
// return new DataMask(extent);
// }
//
// @Command(
// name = "#iddata",
// desc = "Restrict to initial block id and data"
// )

View File

@ -205,7 +205,7 @@ public class RegionCommands {
desc = "Set block lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
public void setlighting(Player player, EditSession editSession, @Selection Region region) {
public void setlighting(Player player, EditSession editSession, @Selection Region region, @Range(from = 0, to = 15) int value) {
player.print(TextComponent.of("Temporarily not working"));
}
@ -214,7 +214,7 @@ public class RegionCommands {
desc = "Set sky lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
public void setskylighting(Player player, @Selection Region region) {
public void setskylighting(Player player, @Selection Region region, @Range(from = 0, to= 15) int value) {
player.printInfo(TextComponent.of("Temporarily not working"));
}

View File

@ -339,7 +339,7 @@ public class SelectionCommands {
List<BlockVector3> direction) throws WorldEditException {
try {
Region region = session.getSelection(world);
long oldSize = region.getVolume();
int oldSize = region.getArea();
if (reverseAmount == 0) {
for (BlockVector3 dir : direction) {
region.contract(dir.multiply(amount));
@ -350,7 +350,7 @@ public class SelectionCommands {
}
}
session.getRegionSelector(world).learnChanges();
long newSize = region.getVolume();
int newSize = region.getArea();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
@ -501,7 +501,7 @@ public class SelectionCommands {
actor.printInfo(TranslatableComponent.of("worldedit.size.size", TextComponent.of(size.toString())));
actor.printInfo(TranslatableComponent.of("worldedit.size.distance", TextComponent.of(region.getMaximumPoint().distance(region.getMinimumPoint()))));
actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getVolume())));
actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getArea())));
}
@Command(

View File

@ -20,7 +20,22 @@
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.mask.*;
import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -66,9 +81,6 @@ public final class MaskFactory extends AbstractFactory<Mask> {
register(new TrueMaskParser(worldEdit));
register(new AirMaskParser(worldEdit));
register(new LiquidMaskParser(worldEdit));
register(new XAxisMaskParser(worldEdit));
register(new YAxisMaskParser(worldEdit));
register(new ZAxisMaskParser(worldEdit));
}

View File

@ -1,3 +1,22 @@
/*
* 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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.AirMask;

View File

@ -1,3 +1,22 @@
/*
* 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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.LiquidMask;

View File

@ -1,48 +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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.XAxisMask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class XAxisMaskParser extends SimpleInputParser<Mask> {
private final List<String> aliases = ImmutableList.of("#xaxis");
public XAxisMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return aliases;
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new XAxisMask(context.getExtent());
}
}

View File

@ -1,49 +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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.XAxisMask;
import com.boydti.fawe.function.mask.YAxisMask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class YAxisMaskParser extends SimpleInputParser<Mask> {
private final List<String> aliases = ImmutableList.of("#yaxis");
public YAxisMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return aliases;
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new YAxisMask(context.getExtent());
}
}

View File

@ -1,49 +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.extension.factory.parser.mask;
import com.boydti.fawe.function.mask.XAxisMask;
import com.boydti.fawe.function.mask.ZAxisMask;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class ZAxisMaskParser extends SimpleInputParser<Mask> {
private final List<String> aliases = ImmutableList.of("#zaxis");
public ZAxisMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return aliases;
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new ZAxisMask(context.getExtent());
}
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.platform;
import com.boydti.fawe.config.Caption;
import com.boydti.fawe.object.task.AsyncNotifyQueue;
import com.sk89q.worldedit.EditSession;
@ -700,10 +701,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
* @return
*/
public Region getLargestRegion() {
long area = 0;
int area = 0;
Region max = null;
for (Region region : this.getCurrentRegions()) {
final long tmp = region.getVolume();
final int tmp = region.getArea();
if (tmp > area) {
area = tmp;
max = region;

View File

@ -59,8 +59,7 @@ public class AbstractDelegateExtent implements Extent {
private static final Logger logger = LoggerFactory.getLogger(AbstractDelegateExtent.class);
//Not safe for public usage
public Extent extent;
private final Extent extent;
/**
* Create a new instance.

View File

@ -27,9 +27,8 @@ public class SelectionPoint2DEvent implements CUIEvent {
protected final int id;
protected final int blockX;
protected final int blockZ;
protected final long area;
protected final int area;
@Deprecated
public SelectionPoint2DEvent(int id, BlockVector2 pos, int area) {
this.id = id;
this.blockX = pos.getX();
@ -37,7 +36,6 @@ public class SelectionPoint2DEvent implements CUIEvent {
this.area = area;
}
@Deprecated
public SelectionPoint2DEvent(int id, BlockVector3 pos, int area) {
this.id = id;
this.blockX = pos.getX();
@ -45,20 +43,6 @@ public class SelectionPoint2DEvent implements CUIEvent {
this.area = area;
}
public SelectionPoint2DEvent(int id, BlockVector2 pos, long area) {
this.id = id;
this.blockX = pos.getX();
this.blockZ = pos.getZ();
this.area = area;
}
public SelectionPoint2DEvent(int id, BlockVector3 pos, long area) {
this.id = id;
this.blockX = pos.getX();
this.blockZ = pos.getZ();
this.area = area;
}
@Override
public String getTypeId() {
return "p2";

View File

@ -25,21 +25,14 @@ public class SelectionPointEvent implements CUIEvent {
protected final int id;
protected final BlockVector3 pos;
protected final long area;
protected final int area;
@Deprecated
public SelectionPointEvent(int id, BlockVector3 pos, int area) {
this.id = id;
this.pos = pos;
this.area = area;
}
public SelectionPointEvent(int id, BlockVector3 pos, long area) {
this.id = id;
this.pos = pos;
this.area = area;
}
@Override
public String getTypeId() {
return "p";

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.regions;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.google.common.primitives.Longs;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -45,7 +44,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
@Override
public int size() {
return com.google.common.primitives.Ints.saturatedCast(getVolume());
return getArea();
}
@Override
@ -107,14 +106,19 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
return points;
}
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
@Override
public long getVolume() {
public int getArea() {
BlockVector3 min = getMinimumPoint();
BlockVector3 max = getMaximumPoint();
return (max.getX() - min.getX() + 1L) *
(max.getY() - min.getY() + 1L) *
(max.getZ() - min.getZ() + 1L);
return (max.getX() - min.getX() + 1) *
(max.getY() - min.getY() + 1) *
(max.getZ() - min.getZ() + 1);
}
/**
@ -214,7 +218,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
int result = worldHash ^ (worldHash >>> 32);
result = 31 * result + this.getMinimumPoint().hashCode();
result = 31 * result + this.getMaximumPoint().hashCode();
result = (int) (31 * result + this.getVolume());
result = 31 * result + this.getArea();
return result;
}
@ -235,7 +239,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
if(this.getWorld().equals(region.getWorld())
&& this.getMinimumPoint().equals(region.getMinimumPoint())
&& this.getMaximumPoint().equals(region.getMaximumPoint())
&& this.getVolume() == region.getVolume()){
&& this.getArea() == region.getArea()){
return true;
}
return false;

View File

@ -35,9 +35,6 @@ 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;
@ -199,16 +196,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
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();
public int getArea() {
return (int) Math.floor(radius.getX() * radius.getZ() * Math.PI * getHeight());
}
@Override

View File

@ -32,8 +32,6 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashSet;
import java.util.Set;
@ -70,7 +68,7 @@ public class EllipsoidRegion extends AbstractRegion {
/**
* Construct a new instance of this ellipsoid region.
*
* @param world the world
* @param world the world
* @param center the center
* @param radius the radius
*/
@ -94,16 +92,10 @@ public class EllipsoidRegion extends AbstractRegion {
return center.toVector3().add(getRadius()).toBlockPoint();
}
private static final BigDecimal ELLIPSOID_BASE_MULTIPLIER = BigDecimal.valueOf((4.0 / 3.0) * Math.PI);
@Override
public long getVolume() {
return ELLIPSOID_BASE_MULTIPLIER
.multiply(BigDecimal.valueOf(radius.getX()))
.multiply(BigDecimal.valueOf(radius.getY()))
.multiply(BigDecimal.valueOf(radius.getZ()))
.setScale(0, RoundingMode.FLOOR)
.longValue();
public int getArea() {
return (int) Math
.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
}
@Override
@ -126,7 +118,7 @@ public class EllipsoidRegion extends AbstractRegion {
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
throw new RegionOperationException(
"Ellipsoid changes must be even for each dimensions.");
"Ellipsoid changes must be even for each dimensions.");
}
return diff.divide(2).floor();

View File

@ -53,7 +53,7 @@ public class NullRegion implements Region {
}
@Override
public long getVolume() {
public int getArea() {
return 0;
}

View File

@ -25,8 +25,6 @@ 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.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -199,22 +197,18 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
}
@Override
public long getVolume() {
long area = 0;
public int getArea() {
double area = 0;
int i, j = points.size() - 1;
for (i = 0; i < points.size(); ++i) {
long x = points.get(j).getBlockX() + points.get(i).getBlockX();
long z = points.get(j).getBlockZ() - points.get(i).getBlockZ();
area += x * z;
area += (points.get(j).getBlockX() + points.get(i).getBlockX())
* (points.get(j).getBlockZ() - points.get(i).getBlockZ());
j = i;
}
return BigDecimal.valueOf(area)
.multiply(BigDecimal.valueOf(0.5))
.abs()
.setScale(0, RoundingMode.FLOOR)
.longValue() * (maxY - minY + 1);
return (int) Math.floor(Math.abs(area * 0.5)
* (maxY - minY + 1));
}
@Override

View File

@ -32,10 +32,8 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
/**
@ -76,40 +74,14 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
* Get the number of blocks in the region.
*
* @return number of blocks
* @deprecated use {@link Region#getVolume()} to prevent overflows
*/
@Deprecated
default int getArea() {
return (int) getVolume();
}
/**
* Get the number of blocks in the region.
*
* <p>Note: This method <b>must</b> be overridden.</p>
*
* @return number of blocks
*/
default long getVolume() {
// TODO Remove default status when getArea is removed.
try {
if (getClass().getMethod("getArea").getDeclaringClass().equals(Region.class)) {
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
}
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
return getArea();
}
/* FAWE code for getArea() before merge:
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.
*

View File

@ -135,31 +135,8 @@ public interface RegionSelector {
* Get the number of blocks inside the region.
*
* @return number of blocks, or -1 if undefined
* @deprecated use {@link RegionSelector#getVolume()}
*/
@Deprecated
default int getArea() {
return (int) getVolume();
}
/**
* Get the number of blocks inside the region.
*
* <p>Note: This method <b>must</b> be overridden.</p>
*
* @return number of blocks, or -1 if undefined
*/
default long getVolume() {
// TODO Remove default once getArea is removed
try {
if (getClass().getMethod("getArea").getDeclaringClass().equals(RegionSelector.class)) {
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
}
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
return getArea();
}
int getArea();
/**
* Update the selector with changes to the region.

View File

@ -113,8 +113,8 @@ public class TransformRegion extends AbstractRegion {
}
@Override
public long getVolume() {
return region.getVolume(); // Cannot transform this
public int getArea() {
return region.getArea(); // Cannot transform this
}
@Override

View File

@ -170,8 +170,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
}
@Override
public long getVolume() {
return region.getVolume();
public int getArea() {
return region.getArea();
}
@Override
@ -250,7 +250,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
int lastVertexId = -1;
for (BlockVector3 vertex : vertices) {
vertexIds.put(vertex, ++lastVertexId);
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea()));
}
for (Triangle triangle : triangles) {
@ -273,8 +273,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
checkNotNull(session);
if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
}
}

View File

@ -161,13 +161,13 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.cuboid.explain.primary-area",
TextComponent.of(position1.toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else if (position1 != null) {
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.primary", TextComponent.of(position1.toString())));
}
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
}
@Override
@ -180,13 +180,13 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.cuboid.explain.secondary-area",
TextComponent.of(position2.toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else if (position2 != null) {
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.secondary", TextComponent.of(position2.toString())));
}
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
}
@Override
@ -197,11 +197,11 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
if (position1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
}
if (position2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
}
}
@ -268,7 +268,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
}
@Override
public long getVolume() {
public int getArea() {
if (position1 == null) {
return -1;
}
@ -277,17 +277,17 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return -1;
}
return region.getVolume();
return region.getArea();
}
@Override
public void describeCUI(LocalSession session, Actor player) {
if (position1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
}
if (position2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
}
}

View File

@ -188,7 +188,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
"worldedit.selection.cylinder.explain.secondary",
TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getX())),
TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getZ())),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else {
player.printError(TranslatableComponent.of("worldedit.selection.cylinder.explain.secondary-missing"));
@ -260,8 +260,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
}
@Override
public long getVolume() {
return region.getVolume();
public int getArea() {
return region.getArea();
}
@Override
@ -273,8 +273,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
@Override
public void describeLegacyCUI(LocalSession session, Actor player) {
if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
}
}

View File

@ -151,7 +151,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.ellipsoid.explain.primary-area",
TextComponent.of(region.getCenter().toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else {
player.printInfo(TranslatableComponent.of(
@ -169,7 +169,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.ellipsoid.explain.secondary-area",
TextComponent.of(region.getRadius().toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else {
player.printInfo(TranslatableComponent.of(
@ -238,8 +238,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
}
@Override
public long getVolume() {
return region.getVolume();
public int getArea() {
return region.getArea();
}
@Override
@ -250,8 +250,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
@Override
public void describeLegacyCUI(LocalSession session, Actor player) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
}
@Override

View File

@ -134,7 +134,7 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.extend.explain.primary",
TextComponent.of(pos.toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
explainRegionAdjust(player, session);
@ -145,7 +145,7 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.extend.explain.secondary",
TextComponent.of(pos.toString()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
explainRegionAdjust(player, session);

View File

@ -174,7 +174,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
player.printInfo(TranslatableComponent.of("worldedit.selection.polygon2d.explain.primary", TextComponent.of(pos.toString())));
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getVolume()));
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
}
@ -186,7 +186,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
TextComponent.of(pos.toString())
));
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getVolume()));
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea()));
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
}
@ -247,8 +247,8 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
}
@Override
public long getVolume() {
return region.getVolume();
public int getArea() {
return region.getArea();
}
/**
@ -264,7 +264,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
public void describeCUI(LocalSession session, Actor player) {
final List<BlockVector2> points = region.getPoints();
for (int id = 0; id < points.size(); id++) {
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getVolume()));
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
}
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));

View File

@ -93,7 +93,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
player.printInfo(TranslatableComponent.of(
"worldedit.selection.sphere.explain.secondary-defined",
TextComponent.of(region.getRadius().getX()),
TextComponent.of(region.getVolume())
TextComponent.of(region.getArea())
));
} else {
player.printInfo(TranslatableComponent.of("worldedit.selection.sphere.explain.secondary", TextComponent.of(region.getRadius().getX())));

View File

@ -78,8 +78,8 @@ public class RequestSelection implements Region {
}
@Override
public long getVolume() {
return getRegion().getVolume();
public int getArea() {
return getRegion().getArea();
}
@Override

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util.collection;
import com.google.common.collect.AbstractIterator;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -35,7 +36,6 @@ import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
@ -43,7 +43,6 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkState;
import static com.sk89q.worldedit.math.BitMath.fixSign;
import static com.sk89q.worldedit.math.BitMath.mask;
@ -52,6 +51,12 @@ import static com.sk89q.worldedit.math.BitMath.mask;
*/
public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
/* =========================
IF YOU MAKE CHANGES TO THIS CLASS
Re-run BlockMapTest with the blockmap.fulltesting=true system property.
Or just temporarily remove the annotation disabling the related tests.
========================= */
public static <V> BlockMap<V> create() {
return create(() -> new Int2ObjectOpenHashMap<>(64, 0.9f));
}
@ -240,65 +245,26 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
entrySet = es = new AbstractSet<Entry<BlockVector3, V>>() {
@Override
public Iterator<Entry<BlockVector3, V>> iterator() {
return new Iterator<Entry<BlockVector3,V>>() {
return new AbstractIterator<Entry<BlockVector3, V>>() {
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
= Long2ObjectMaps.fastIterator(maps);
private Long2ObjectMap.Entry<Int2ObjectMap<V>> currentPrimaryEntry;
private long currentGroupKey;
private ObjectIterator<Int2ObjectMap.Entry<V>> secondaryIterator;
private boolean finished;
private LazyEntry next;
@Override
public boolean hasNext() {
if (finished) {
return false;
}
if (next == null) {
LazyEntry proposedNext = computeNext();
if (proposedNext == null) {
finished = true;
return false;
}
next = proposedNext;
}
return true;
}
private LazyEntry computeNext() {
protected Entry<BlockVector3, V> computeNext() {
if (secondaryIterator == null || !secondaryIterator.hasNext()) {
if (!primaryIterator.hasNext()) {
return null;
return endOfData();
}
currentPrimaryEntry = primaryIterator.next();
secondaryIterator = Int2ObjectMaps.fastIterator(currentPrimaryEntry.getValue());
// be paranoid
checkState(secondaryIterator.hasNext(),
"Should not have an empty map entry, it should have been removed!");
Long2ObjectMap.Entry<Int2ObjectMap<V>> next = primaryIterator.next();
currentGroupKey = next.getLongKey();
secondaryIterator = Int2ObjectMaps.fastIterator(next.getValue());
}
Int2ObjectMap.Entry<V> next = secondaryIterator.next();
return new LazyEntry(currentPrimaryEntry.getLongKey(), next.getIntKey(), next.getValue());
}
@Override
public Entry<BlockVector3, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
LazyEntry tmp = next;
next = null;
return tmp;
}
@Override
public void remove() {
secondaryIterator.remove();
// ensure invariants hold
if (currentPrimaryEntry.getValue().isEmpty()) {
// the remove call cleared this map. call remove on the primary iter
primaryIterator.remove();
}
return new LazyEntry(currentGroupKey, next.getIntKey(), next.getValue());
}
};
}
@ -398,14 +364,13 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
@Override
public V remove(Object key) {
BlockVector3 vec = (BlockVector3) key;
long groupKey = toGroupKey(vec);
Int2ObjectMap<V> activeMap = maps.get(groupKey);
Int2ObjectMap<V> activeMap = maps.get(toGroupKey(vec));
if (activeMap == null) {
return null;
}
V removed = activeMap.remove(toInnerKey(vec));
if (activeMap.isEmpty()) {
maps.remove(groupKey);
maps.remove(toGroupKey(vec));
}
return removed;
}
@ -464,9 +429,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
}
if (o instanceof BlockMap) {
// optimize by skipping entry translations:
@SuppressWarnings("unchecked")
BlockMap<V> other = (BlockMap<V>) o;
return maps.equals(other.maps);
return maps.equals(((BlockMap) o).maps);
}
return super.equals(o);
}

View File

@ -91,7 +91,6 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
= Int2IntMaps.fastIterator(commonMap);
private final ObjectIterator<Entry<BaseBlock>> uncommonIter
= Int2ObjectMaps.fastIterator(uncommonMap);
private boolean lastNextFromCommon = false;
@Override
public boolean hasNext() {
@ -102,26 +101,15 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
public Entry<BaseBlock> next() {
if (commonIter.hasNext()) {
Int2IntMap.Entry e = commonIter.next();
lastNextFromCommon = true;
return new BasicEntry<>(
e.getIntKey(), assumeAsBlock(e.getIntValue())
);
}
if (uncommonIter.hasNext()) {
lastNextFromCommon = false;
return uncommonIter.next();
}
throw new NoSuchElementException();
}
@Override
public void remove() {
if (lastNextFromCommon) {
commonIter.remove();
} else {
uncommonIter.remove();
}
}
};
}

View File

@ -30,54 +30,49 @@ import java.util.Iterator;
class VectorPositionList implements PositionList {
private final IntList delegateX = new IntArrayList();
private final IntList delegateY = new IntArrayList();
private final IntList delegateZ = new IntArrayList();
private final IntList delegate = new IntArrayList();
@Override
public BlockVector3 get(int index) {
int ri = index * 3;
return BlockVector3.at(
delegateX.getInt(index),
delegateY.getInt(index),
delegateZ.getInt(index));
delegate.getInt(ri),
delegate.getInt(ri + 1),
delegate.getInt(ri + 2));
}
@Override
public void add(BlockVector3 vector) {
delegateX.add(vector.getX());
delegateY.add(vector.getY());
delegateZ.add(vector.getZ());
delegate.add(vector.getX());
delegate.add(vector.getY());
delegate.add(vector.getZ());
}
@Override
public int size() {
return delegateX.size();
return delegate.size();
}
@Override
public void clear() {
delegateX.clear();
delegateY.clear();
delegateZ.clear();
delegate.clear();
}
@Override
public Iterator<BlockVector3> iterator() {
return new AbstractIterator<BlockVector3>() {
private final IntIterator iteratorX = delegateX.iterator();
private final IntIterator iteratorY = delegateY.iterator();
private final IntIterator iteratorZ = delegateZ.iterator();
private final IntIterator iterator = delegate.iterator();
@Override
protected BlockVector3 computeNext() {
if (!iteratorX.hasNext()) {
if (!iterator.hasNext()) {
return endOfData();
}
return BlockVector3.at(
iteratorX.nextInt(),
iteratorY.nextInt(),
iteratorZ.nextInt());
iterator.nextInt(),
iterator.nextInt(),
iterator.nextInt());
}
};
}
@ -86,19 +81,17 @@ class VectorPositionList implements PositionList {
public Iterator<BlockVector3> reverseIterator() {
return new AbstractIterator<BlockVector3>() {
private final IntListIterator iteratorX = delegateX.listIterator(delegateX.size());
private final IntListIterator iteratorY = delegateY.listIterator(delegateY.size());
private final IntListIterator iteratorZ = delegateZ.listIterator(delegateZ.size());
private final IntListIterator iterator = delegate.listIterator(delegate.size());
@Override
protected BlockVector3 computeNext() {
if (!iteratorX.hasPrevious()) {
if (!iterator.hasPrevious()) {
return endOfData();
}
return BlockVector3.at(
iteratorX.previousInt(),
iteratorY.previousInt(),
iteratorZ.previousInt());
iterator.previousInt(),
iterator.previousInt(),
iterator.previousInt());
}
};
}

View File

@ -31,7 +31,13 @@ public class TaskStateComparator implements Comparator<Task<?>> {
public int compare(com.sk89q.worldedit.util.task.Task<?> o1, Task<?> o2) {
int ordinal1 = o1.getState().ordinal();
int ordinal2 = o2.getState().ordinal();
return Integer.compare(ordinal1, ordinal2);
if (ordinal1 < ordinal2) {
return -1;
} else if (ordinal1 > ordinal2) {
return 1;
} else {
return 0;
}
}
}