mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
@ -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 number of blocks affected
|
||||
* @return the 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.completeBlindly(visitor);
|
||||
Operations.completeLegacy(visitor);
|
||||
|
||||
return this.changes = visitor.getAffected();
|
||||
}
|
||||
@ -2185,12 +2185,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
*
|
||||
* @param position a position
|
||||
* @param radius a radius
|
||||
* @param onlyNormalDirt only affect normal dirt (data value 0)
|
||||
* @param onlyNormalDirt only affect normal dirt (all default properties)
|
||||
* @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();
|
||||
@ -2257,7 +2258,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.completeBlindly(visitor);
|
||||
Operations.completeLegacy(visitor);
|
||||
return this.changes = ground.getAffected();
|
||||
}
|
||||
|
||||
@ -2403,11 +2404,42 @@ 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");
|
||||
@ -2425,7 +2457,6 @@ 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 {
|
||||
|
@ -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.getArea()));
|
||||
actor.print(Caption.of("fawe.worldedit.copy.command.copy" , region.getVolume()));
|
||||
}
|
||||
|
||||
// @Command(
|
||||
|
@ -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 {
|
||||
int oldSize = region.getArea();
|
||||
long oldSize = region.getVolume();
|
||||
region.expand(
|
||||
BlockVector3.at(0, (world.getMaxY() + 1), 0),
|
||||
BlockVector3.at(0, -(world.getMaxY() + 1), 0));
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
int newSize = region.getArea();
|
||||
long newSize = region.getVolume();
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
int changeSize = newSize - oldSize;
|
||||
long 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);
|
||||
int oldSize = region.getArea();
|
||||
long oldSize = region.getVolume();
|
||||
|
||||
if (reverseAmount == 0) {
|
||||
for (BlockVector3 dir : direction) {
|
||||
@ -147,11 +147,11 @@ public class ExpandCommands {
|
||||
}
|
||||
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
int newSize = region.getArea();
|
||||
long newSize = region.getVolume();
|
||||
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
|
||||
int changeSize = newSize - oldSize;
|
||||
long changeSize = newSize - oldSize;
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.expand.expanded", TextComponent.of(changeSize)));
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,7 @@
|
||||
//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;
|
||||
@ -171,22 +168,6 @@
|
||||
// }
|
||||
//
|
||||
// @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"
|
||||
// )
|
||||
|
@ -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, @Range(from = 0, to = 15) int value) {
|
||||
public void setlighting(Player player, EditSession editSession, @Selection Region region) {
|
||||
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, @Range(from = 0, to= 15) int value) {
|
||||
public void setskylighting(Player player, @Selection Region region) {
|
||||
player.printInfo(TextComponent.of("Temporarily not working"));
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ public class SelectionCommands {
|
||||
List<BlockVector3> direction) throws WorldEditException {
|
||||
try {
|
||||
Region region = session.getSelection(world);
|
||||
int oldSize = region.getArea();
|
||||
long oldSize = region.getVolume();
|
||||
if (reverseAmount == 0) {
|
||||
for (BlockVector3 dir : direction) {
|
||||
region.contract(dir.multiply(amount));
|
||||
@ -350,7 +350,7 @@ public class SelectionCommands {
|
||||
}
|
||||
}
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
int newSize = region.getArea();
|
||||
long newSize = region.getVolume();
|
||||
|
||||
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.getArea())));
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getVolume())));
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -20,22 +20,7 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
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.factory.parser.mask.*;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -81,6 +66,9 @@ 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));
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,3 @@
|
||||
/*
|
||||
* 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;
|
||||
|
@ -1,22 +1,3 @@
|
||||
/*
|
||||
* 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;
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.boydti.fawe.config.Caption;
|
||||
import com.boydti.fawe.object.task.AsyncNotifyQueue;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
|
||||
@ -701,10 +700,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
* @return
|
||||
*/
|
||||
public Region getLargestRegion() {
|
||||
int area = 0;
|
||||
long area = 0;
|
||||
Region max = null;
|
||||
for (Region region : this.getCurrentRegions()) {
|
||||
final int tmp = region.getArea();
|
||||
final long tmp = region.getVolume();
|
||||
if (tmp > area) {
|
||||
area = tmp;
|
||||
max = region;
|
||||
|
@ -59,7 +59,8 @@ public class AbstractDelegateExtent implements Extent {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractDelegateExtent.class);
|
||||
|
||||
private final Extent extent;
|
||||
//Not safe for public usage
|
||||
public Extent extent;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
|
@ -27,8 +27,9 @@ public class SelectionPoint2DEvent implements CUIEvent {
|
||||
protected final int id;
|
||||
protected final int blockX;
|
||||
protected final int blockZ;
|
||||
protected final int area;
|
||||
protected final long area;
|
||||
|
||||
@Deprecated
|
||||
public SelectionPoint2DEvent(int id, BlockVector2 pos, int area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
@ -36,6 +37,7 @@ public class SelectionPoint2DEvent implements CUIEvent {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SelectionPoint2DEvent(int id, BlockVector3 pos, int area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
@ -43,6 +45,20 @@ 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";
|
||||
|
@ -25,14 +25,21 @@ public class SelectionPointEvent implements CUIEvent {
|
||||
|
||||
protected final int id;
|
||||
protected final BlockVector3 pos;
|
||||
protected final int area;
|
||||
protected final long 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";
|
||||
|
@ -20,6 +20,7 @@
|
||||
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;
|
||||
@ -44,7 +45,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getArea();
|
||||
return com.google.common.primitives.Ints.saturatedCast(getVolume());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -106,19 +107,14 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
@Override
|
||||
public int getArea() {
|
||||
public long getVolume() {
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1);
|
||||
return (max.getX() - min.getX() + 1L) *
|
||||
(max.getY() - min.getY() + 1L) *
|
||||
(max.getZ() - min.getZ() + 1L);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +214,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 = 31 * result + this.getArea();
|
||||
result = (int) (31 * result + this.getVolume());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -239,7 +235,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.getArea() == region.getArea()){
|
||||
&& this.getVolume() == region.getVolume()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -35,6 +35,9 @@ 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;
|
||||
|
||||
@ -196,9 +199,16 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
return minY;
|
||||
}
|
||||
|
||||
private static final BigDecimal PI = BigDecimal.valueOf(Math.PI);
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return (int) Math.floor(radius.getX() * radius.getZ() * Math.PI * getHeight());
|
||||
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
|
||||
|
@ -32,6 +32,8 @@ 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;
|
||||
|
||||
@ -68,7 +70,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
|
||||
*/
|
||||
@ -92,10 +94,16 @@ 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 int getArea() {
|
||||
return (int) Math
|
||||
.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,7 +126,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();
|
||||
|
@ -53,7 +53,7 @@ public class NullRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
public long getVolume() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ 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;
|
||||
@ -197,18 +199,22 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
double area = 0;
|
||||
public long getVolume() {
|
||||
long area = 0;
|
||||
int i, j = points.size() - 1;
|
||||
|
||||
for (i = 0; i < points.size(); ++i) {
|
||||
area += (points.get(j).getBlockX() + points.get(i).getBlockX())
|
||||
* (points.get(j).getBlockZ() - points.get(i).getBlockZ());
|
||||
long x = points.get(j).getBlockX() + points.get(i).getBlockX();
|
||||
long z = points.get(j).getBlockZ() - points.get(i).getBlockZ();
|
||||
area += x * z;
|
||||
j = i;
|
||||
}
|
||||
|
||||
return (int) Math.floor(Math.abs(area * 0.5)
|
||||
* (maxY - minY + 1));
|
||||
return BigDecimal.valueOf(area)
|
||||
.multiply(BigDecimal.valueOf(0.5))
|
||||
.abs()
|
||||
.setScale(0, RoundingMode.FLOOR)
|
||||
.longValue() * (maxY - minY + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,8 +32,10 @@ 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;
|
||||
|
||||
/**
|
||||
@ -74,14 +76,40 @@ 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.
|
||||
*
|
||||
|
@ -135,8 +135,31 @@ public interface RegionSelector {
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks, or -1 if undefined
|
||||
* @deprecated use {@link RegionSelector#getVolume()}
|
||||
*/
|
||||
int getArea();
|
||||
@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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
|
@ -113,8 +113,8 @@ public class TransformRegion extends AbstractRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea(); // Cannot transform this
|
||||
public long getVolume() {
|
||||
return region.getVolume(); // Cannot transform this
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,8 +170,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
}
|
||||
|
||||
@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, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getVolume()));
|
||||
}
|
||||
|
||||
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(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} else if (position1 != null) {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.primary", TextComponent.of(position1.toString())));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getVolume()));
|
||||
}
|
||||
|
||||
@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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} else if (position2 != null) {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.secondary", TextComponent.of(position2.toString())));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getVolume()));
|
||||
}
|
||||
|
||||
@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, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
|
||||
}
|
||||
|
||||
if (position2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
public long getVolume() {
|
||||
if (position1 == null) {
|
||||
return -1;
|
||||
}
|
||||
@ -277,17 +277,17 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return region.getArea();
|
||||
return region.getVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeCUI(LocalSession session, Actor player) {
|
||||
if (position1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
|
||||
}
|
||||
|
||||
if (position2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} else {
|
||||
player.printError(TranslatableComponent.of("worldedit.selection.cylinder.explain.secondary-missing"));
|
||||
@ -260,8 +260,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
}
|
||||
|
||||
@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(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} 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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} else {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
@ -238,8 +238,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
}
|
||||
|
||||
@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(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
|
||||
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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
|
@ -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, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getVolume()));
|
||||
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, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
@ -247,8 +247,8 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getVolume()));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
|
@ -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.getArea())
|
||||
TextComponent.of(region.getVolume())
|
||||
));
|
||||
} else {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.sphere.explain.secondary", TextComponent.of(region.getRadius().getX())));
|
||||
|
@ -78,8 +78,8 @@ public class RequestSelection implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return getRegion().getArea();
|
||||
public long getVolume() {
|
||||
return getRegion().getVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
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;
|
||||
@ -36,6 +35,7 @@ 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,6 +43,7 @@ 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;
|
||||
|
||||
@ -51,12 +52,6 @@ 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));
|
||||
}
|
||||
@ -245,26 +240,65 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
entrySet = es = new AbstractSet<Entry<BlockVector3, V>>() {
|
||||
@Override
|
||||
public Iterator<Entry<BlockVector3, V>> iterator() {
|
||||
return new AbstractIterator<Entry<BlockVector3, V>>() {
|
||||
return new Iterator<Entry<BlockVector3,V>>() {
|
||||
|
||||
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
|
||||
= Long2ObjectMaps.fastIterator(maps);
|
||||
private long currentGroupKey;
|
||||
private Long2ObjectMap.Entry<Int2ObjectMap<V>> currentPrimaryEntry;
|
||||
private ObjectIterator<Int2ObjectMap.Entry<V>> secondaryIterator;
|
||||
private boolean finished;
|
||||
private LazyEntry next;
|
||||
|
||||
@Override
|
||||
protected Entry<BlockVector3, V> computeNext() {
|
||||
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() {
|
||||
if (secondaryIterator == null || !secondaryIterator.hasNext()) {
|
||||
if (!primaryIterator.hasNext()) {
|
||||
return endOfData();
|
||||
return null;
|
||||
}
|
||||
|
||||
Long2ObjectMap.Entry<Int2ObjectMap<V>> next = primaryIterator.next();
|
||||
currentGroupKey = next.getLongKey();
|
||||
secondaryIterator = Int2ObjectMaps.fastIterator(next.getValue());
|
||||
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!");
|
||||
}
|
||||
Int2ObjectMap.Entry<V> next = secondaryIterator.next();
|
||||
return new LazyEntry(currentGroupKey, next.getIntKey(), next.getValue());
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -364,13 +398,14 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
BlockVector3 vec = (BlockVector3) key;
|
||||
Int2ObjectMap<V> activeMap = maps.get(toGroupKey(vec));
|
||||
long groupKey = toGroupKey(vec);
|
||||
Int2ObjectMap<V> activeMap = maps.get(groupKey);
|
||||
if (activeMap == null) {
|
||||
return null;
|
||||
}
|
||||
V removed = activeMap.remove(toInnerKey(vec));
|
||||
if (activeMap.isEmpty()) {
|
||||
maps.remove(toGroupKey(vec));
|
||||
maps.remove(groupKey);
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
@ -429,7 +464,9 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
}
|
||||
if (o instanceof BlockMap) {
|
||||
// optimize by skipping entry translations:
|
||||
return maps.equals(((BlockMap) o).maps);
|
||||
@SuppressWarnings("unchecked")
|
||||
BlockMap<V> other = (BlockMap<V>) o;
|
||||
return maps.equals(other.maps);
|
||||
}
|
||||
return super.equals(o);
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ 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() {
|
||||
@ -101,15 +102,26 @@ 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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -30,49 +30,54 @@ import java.util.Iterator;
|
||||
|
||||
class VectorPositionList implements PositionList {
|
||||
|
||||
private final IntList delegate = new IntArrayList();
|
||||
private final IntList delegateX = new IntArrayList();
|
||||
private final IntList delegateY = new IntArrayList();
|
||||
private final IntList delegateZ = new IntArrayList();
|
||||
|
||||
@Override
|
||||
public BlockVector3 get(int index) {
|
||||
int ri = index * 3;
|
||||
return BlockVector3.at(
|
||||
delegate.getInt(ri),
|
||||
delegate.getInt(ri + 1),
|
||||
delegate.getInt(ri + 2));
|
||||
delegateX.getInt(index),
|
||||
delegateY.getInt(index),
|
||||
delegateZ.getInt(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BlockVector3 vector) {
|
||||
delegate.add(vector.getX());
|
||||
delegate.add(vector.getY());
|
||||
delegate.add(vector.getZ());
|
||||
delegateX.add(vector.getX());
|
||||
delegateY.add(vector.getY());
|
||||
delegateZ.add(vector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return delegate.size();
|
||||
return delegateX.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
delegate.clear();
|
||||
delegateX.clear();
|
||||
delegateY.clear();
|
||||
delegateZ.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private final IntIterator iterator = delegate.iterator();
|
||||
private final IntIterator iteratorX = delegateX.iterator();
|
||||
private final IntIterator iteratorY = delegateY.iterator();
|
||||
private final IntIterator iteratorZ = delegateZ.iterator();
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (!iterator.hasNext()) {
|
||||
if (!iteratorX.hasNext()) {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iterator.nextInt(),
|
||||
iterator.nextInt(),
|
||||
iterator.nextInt());
|
||||
iteratorX.nextInt(),
|
||||
iteratorY.nextInt(),
|
||||
iteratorZ.nextInt());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -81,17 +86,19 @@ class VectorPositionList implements PositionList {
|
||||
public Iterator<BlockVector3> reverseIterator() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private final IntListIterator iterator = delegate.listIterator(delegate.size());
|
||||
private final IntListIterator iteratorX = delegateX.listIterator(delegateX.size());
|
||||
private final IntListIterator iteratorY = delegateY.listIterator(delegateY.size());
|
||||
private final IntListIterator iteratorZ = delegateZ.listIterator(delegateZ.size());
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (!iterator.hasPrevious()) {
|
||||
if (!iteratorX.hasPrevious()) {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iterator.previousInt(),
|
||||
iterator.previousInt(),
|
||||
iterator.previousInt());
|
||||
iteratorX.previousInt(),
|
||||
iteratorY.previousInt(),
|
||||
iteratorZ.previousInt());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -31,13 +31,7 @@ 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();
|
||||
if (ordinal1 < ordinal2) {
|
||||
return -1;
|
||||
} else if (ordinal1 > ordinal2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Integer.compare(ordinal1, ordinal2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user