2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
import com.sk89q.worldedit.function.GroundFunction;
|
|
|
|
import com.sk89q.worldedit.function.generator.FloraGenerator;
|
|
|
|
import com.sk89q.worldedit.function.generator.ForestGenerator;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
|
|
|
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
|
|
|
import com.sk89q.worldedit.function.pattern.Patterns;
|
|
|
|
import com.sk89q.worldedit.function.visitor.LayerVisitor;
|
|
|
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
|
|
|
import com.sk89q.worldedit.internal.annotation.Selection;
|
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.math.convolution.GaussianKernel;
|
|
|
|
import com.sk89q.worldedit.math.convolution.HeightMap;
|
|
|
|
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.math.noise.RandomNoise;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
|
|
|
import com.sk89q.worldedit.util.TreeGenerator;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
|
|
|
import com.sk89q.worldedit.util.command.binding.Range;
|
|
|
|
import com.sk89q.worldedit.util.command.binding.Switch;
|
|
|
|
import com.sk89q.worldedit.util.command.binding.Text;
|
|
|
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-04-03 02:08:50 +00:00
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
|
|
|
import static com.sk89q.worldedit.regions.Regions.*;
|
|
|
|
|
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands that operate on regions.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
|
|
|
public class RegionCommands {
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public RegionCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/set" },
|
|
|
|
usage = "<block>",
|
|
|
|
desc = "Set all the blocks inside the selection to a block",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.set")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void set(Player player, LocalSession session, EditSession editSession, Pattern pattern) throws WorldEditException {
|
|
|
|
int affected = editSession.setBlocks(session.getSelection(player.getWorld()), Patterns.wrap(pattern));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/line" },
|
|
|
|
usage = "<block> [thickness]",
|
|
|
|
desc = "Draws a line segment between cuboid selection corners",
|
|
|
|
help =
|
|
|
|
"Draws a line segment between cuboid selection corners.\n" +
|
|
|
|
"Can only be used with cuboid selections.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -h generates only a shell",
|
|
|
|
flags = "h",
|
|
|
|
min = 1,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.line")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void line(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
Pattern pattern,
|
|
|
|
@Optional("0") @Range(min = 0) int thickness,
|
|
|
|
@Switch('h') boolean shell) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
if (!(region instanceof CuboidRegion)) {
|
2014-06-28 08:01:49 +00:00
|
|
|
player.printError("//line only works with cuboid selections");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CuboidRegion cuboidregion = (CuboidRegion) region;
|
|
|
|
Vector pos1 = cuboidregion.getPos1();
|
|
|
|
Vector pos2 = cuboidregion.getPos2();
|
2014-06-28 08:01:49 +00:00
|
|
|
int blocksChanged = editSession.drawLine(Patterns.wrap(pattern), pos1, pos2, thickness, !shell);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
player.print(blocksChanged + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/curve" },
|
|
|
|
usage = "<block> [thickness]",
|
|
|
|
desc = "Draws a spline through selected points",
|
|
|
|
help =
|
|
|
|
"Draws a spline through selected points.\n" +
|
|
|
|
"Can only be uesd with convex polyhedral selections.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -h generates only a shell",
|
|
|
|
flags = "h",
|
|
|
|
min = 1,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.curve")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void curve(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
Pattern pattern,
|
|
|
|
@Optional("0") @Range(min = 0) int thickness,
|
|
|
|
@Switch('h') boolean shell) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
if (!(region instanceof ConvexPolyhedralRegion)) {
|
2014-06-28 08:01:49 +00:00
|
|
|
player.printError("//line only works with convex polyhedral selections");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
|
|
|
|
List<Vector> vectors = new ArrayList<Vector>(cpregion.getVertices());
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
int blocksChanged = editSession.drawSpline(Patterns.wrap(pattern), vectors, 0, 0, 0, 10, thickness, !shell);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
player.print(blocksChanged + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/replace", "/re", "/rep" },
|
|
|
|
usage = "[from-block] <to-block>",
|
|
|
|
desc = "Replace all blocks in the selection with another",
|
|
|
|
flags = "f",
|
|
|
|
min = 1,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.replace")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void replace(Player player, EditSession editSession, @Selection Region region, @Optional Mask from, Pattern to) throws WorldEditException {
|
|
|
|
if (from == null) {
|
|
|
|
from = new ExistingBlockMask(editSession);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2014-06-28 08:01:49 +00:00
|
|
|
int affected = editSession.replaceBlocks(region, from, Patterns.wrap(to));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been replaced.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/overlay" },
|
|
|
|
usage = "<block>",
|
|
|
|
desc = "Set a block on top of blocks in the region",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.overlay")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void overlay(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
|
|
|
|
int affected = editSession.overlayCuboidBlocks(region, Patterns.wrap(pattern));
|
|
|
|
player.print(affected + " block(s) have been overlaid.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/center", "/middle" },
|
|
|
|
usage = "<block>",
|
|
|
|
desc = "Set the center block(s)",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.region.center")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void center(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
|
|
|
|
int affected = editSession.center(region, Patterns.wrap(pattern));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Center set ("+ affected + " blocks changed)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/naturalize" },
|
|
|
|
usage = "",
|
|
|
|
desc = "3 layers of dirt on top then rock below",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.naturalize")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void naturalize(Player player, EditSession editSession, @Selection Region region) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
int affected = editSession.naturalizeCuboidBlocks(region);
|
2014-06-28 08:01:49 +00:00
|
|
|
player.print(affected + " block(s) have been made to look more natural.");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/walls" },
|
|
|
|
usage = "<block>",
|
|
|
|
desc = "Build the four sides of the selection",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.walls")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void walls(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
|
|
|
|
int affected = editSession.makeCuboidWalls(region, Patterns.wrap(pattern));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/faces", "/outline" },
|
|
|
|
usage = "<block>",
|
|
|
|
desc = "Build the walls, ceiling, and floor of a selection",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.faces")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void faces(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException {
|
|
|
|
int affected = editSession.makeCuboidFaces(region, Patterns.wrap(pattern));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/smooth" },
|
|
|
|
usage = "[iterations]",
|
|
|
|
flags = "n",
|
|
|
|
desc = "Smooth the elevation in the selection",
|
|
|
|
help =
|
|
|
|
"Smooths the elevation in the selection.\n" +
|
|
|
|
"The -n flag makes it only consider naturally occuring blocks.",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.smooth")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void smooth(Player player, EditSession editSession, @Selection Region region, @Optional("1") int iterations, @Switch('n') boolean affectNatural) throws WorldEditException {
|
|
|
|
HeightMap heightMap = new HeightMap(editSession, region, affectNatural);
|
2014-04-03 02:08:50 +00:00
|
|
|
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
|
|
|
int affected = heightMap.applyFilter(filter, iterations);
|
|
|
|
player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/move" },
|
|
|
|
usage = "[count] [direction] [leave-id]",
|
|
|
|
flags = "s",
|
|
|
|
desc = "Move the contents of the selection",
|
|
|
|
help =
|
|
|
|
"Moves the contents of the selection.\n" +
|
|
|
|
"The -s flag shifts the selection to the target location.\n" +
|
|
|
|
"Optionally fills the old location with <leave-id>.",
|
|
|
|
min = 0,
|
|
|
|
max = 3
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.move")
|
|
|
|
@Logging(ORIENTATION_REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void move(Player player, EditSession editSession, LocalSession session,
|
|
|
|
@Selection Region region,
|
|
|
|
@Optional("1") @Range(min = 1) int count,
|
|
|
|
@Optional(Direction.AIM) @Direction Vector direction,
|
|
|
|
@Optional("air") BaseBlock replace,
|
|
|
|
@Switch('s') boolean moveSelection) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
int affected = editSession.moveRegion(region, direction, count, true, replace);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
if (moveSelection) {
|
2014-04-03 02:08:50 +00:00
|
|
|
try {
|
2014-06-28 08:01:49 +00:00
|
|
|
region.shift(direction.multiply(count));
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.print(affected + " blocks moved.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/stack" },
|
|
|
|
usage = "[count] [direction]",
|
|
|
|
flags = "sa",
|
|
|
|
desc = "Repeat the contents of the selection",
|
|
|
|
help =
|
|
|
|
"Repeats the contents of the selection.\n" +
|
|
|
|
"Flags:\n" +
|
|
|
|
" -s shifts the selection to the last stacked copy\n" +
|
|
|
|
" -a skips air blocks",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.stack")
|
|
|
|
@Logging(ORIENTATION_REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void stack(Player player, EditSession editSession, LocalSession session,
|
|
|
|
@Selection Region region,
|
|
|
|
@Optional("1") @Range(min = 1) int count,
|
|
|
|
@Optional(Direction.AIM) @Direction Vector direction,
|
|
|
|
@Switch('s') boolean moveSelection,
|
|
|
|
@Switch('a') boolean ignoreAirBlocks) throws WorldEditException {
|
|
|
|
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks);
|
|
|
|
|
2014-06-28 23:30:22 +00:00
|
|
|
if (moveSelection) {
|
2014-04-03 02:08:50 +00:00
|
|
|
try {
|
|
|
|
final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
final Vector shiftVector = direction.multiply(count * (Math.abs(direction.dot(size)) + 1));
|
2014-04-03 02:08:50 +00:00
|
|
|
region.shift(shiftVector);
|
|
|
|
|
|
|
|
session.getRegionSelector(player.getWorld()).learnChanges();
|
|
|
|
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
|
|
|
} catch (RegionOperationException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.print(affected + " blocks changed. Undo with //undo");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/regen" },
|
|
|
|
usage = "",
|
|
|
|
desc = "Regenerates the contents of the selection",
|
|
|
|
help =
|
|
|
|
"Regenerates the contents of the current selection.\n" +
|
|
|
|
"This command might affect things outside the selection,\n" +
|
|
|
|
"if they are within the same chunk.",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.regen")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
Mask mask = session.getMask();
|
2014-06-28 08:01:49 +00:00
|
|
|
try {
|
|
|
|
session.setMask((Mask) null);
|
|
|
|
player.getWorld().regenerate(region, editSession);
|
|
|
|
} finally {
|
|
|
|
session.setMask(mask);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Region regenerated.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/deform" },
|
|
|
|
usage = "<expression>",
|
|
|
|
desc = "Deforms a selected region with an expression",
|
|
|
|
help =
|
|
|
|
"Deforms a selected region with an expression\n" +
|
|
|
|
"The expression is executed for each block and is expected\n" +
|
|
|
|
"to modify the variables x, y and z to point to a new block\n" +
|
|
|
|
"to fetch. See also tinyurl.com/wesyntax.",
|
|
|
|
flags = "ro",
|
|
|
|
min = 1,
|
|
|
|
max = -1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.deform")
|
|
|
|
@Logging(ALL)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void deform(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Text String expression,
|
|
|
|
@Switch('r') boolean useRawCoords,
|
|
|
|
@Switch('o') boolean offset) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
final Vector zero;
|
|
|
|
Vector unit;
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
if (useRawCoords) {
|
2014-04-03 02:08:50 +00:00
|
|
|
zero = Vector.ZERO;
|
|
|
|
unit = Vector.ONE;
|
2014-06-28 08:01:49 +00:00
|
|
|
} else if (offset) {
|
2014-04-03 02:08:50 +00:00
|
|
|
zero = session.getPlacementPosition(player);
|
|
|
|
unit = Vector.ONE;
|
|
|
|
} else {
|
|
|
|
final Vector min = region.getMinimumPoint();
|
|
|
|
final Vector max = region.getMaximumPoint();
|
|
|
|
|
|
|
|
zero = max.add(min).multiply(0.5);
|
|
|
|
unit = max.subtract(zero);
|
|
|
|
|
|
|
|
if (unit.getX() == 0) unit = unit.setX(1.0);
|
|
|
|
if (unit.getY() == 0) unit = unit.setY(1.0);
|
|
|
|
if (unit.getZ() == 0) unit = unit.setZ(1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
final int affected = editSession.deformRegion(region, zero, unit, expression);
|
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been deformed.");
|
|
|
|
} catch (ExpressionException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/hollow" },
|
|
|
|
usage = "[<thickness>[ <block>]]",
|
|
|
|
desc = "Hollows out the object contained in this selection",
|
|
|
|
help =
|
|
|
|
"Hollows out the object contained in this selection.\n" +
|
|
|
|
"Optionally fills the hollowed out part with the given block.\n" +
|
|
|
|
"Thickness is measured in manhattan distance.",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.hollow")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void hollow(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Optional("0") @Range(min = 0) int thickness,
|
|
|
|
@Optional("air") Pattern pattern) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
int affected = editSession.hollowOutRegion(region, thickness, Patterns.wrap(pattern));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/forest" },
|
|
|
|
usage = "[type] [density]",
|
|
|
|
desc = "Make a forest within the region",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.forest")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void forest(Player player, EditSession editSession, @Selection Region region, @Optional("tree") TreeType type, @Optional("5") double density) throws WorldEditException {
|
|
|
|
density = density / 100;
|
2014-04-03 02:08:50 +00:00
|
|
|
ForestGenerator generator = new ForestGenerator(editSession, new TreeGenerator(type));
|
|
|
|
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
|
|
|
|
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
|
|
|
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
|
|
|
|
player.print(ground.getAffected() + " trees created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/flora" },
|
|
|
|
usage = "[density]",
|
|
|
|
desc = "Make flora within the region",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.flora")
|
|
|
|
@Logging(REGION)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void flora(Player player, EditSession editSession, @Selection Region region, @Optional("10") double density) throws WorldEditException {
|
|
|
|
density = density / 100;
|
2014-04-03 02:08:50 +00:00
|
|
|
FloraGenerator generator = new FloraGenerator(editSession);
|
|
|
|
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
|
|
|
|
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
|
|
|
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
|
|
|
|
player.print(ground.getAffected() + " flora created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|