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;
|
|
|
|
|
2019-04-26 06:16:18 +00:00
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
import com.google.common.collect.Lists;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-04-24 01:46:46 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
2019-04-17 06:02:23 +00:00
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
import com.sk89q.worldedit.function.GroundFunction;
|
2019-04-26 06:16:18 +00:00
|
|
|
import com.sk89q.worldedit.function.RegionFunction;
|
|
|
|
import com.sk89q.worldedit.function.block.BlockReplace;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.generator.FloraGenerator;
|
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.visitor.LayerVisitor;
|
2019-04-26 06:16:18 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Direction;
|
|
|
|
import com.sk89q.worldedit.internal.annotation.Selection;
|
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
2018-10-14 10:40:53 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
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;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
2019-04-24 01:46:46 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-04-24 01:46:46 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
2019-05-15 00:57:05 +00:00
|
|
|
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
|
2019-04-24 01:46:46 +00:00
|
|
|
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
|
|
|
|
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
|
|
|
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands that operate on regions.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
2019-04-24 01:46:46 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class RegionCommands {
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*/
|
2019-04-24 01:46:46 +00:00
|
|
|
public RegionCommands() {
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 06:16:18 +00:00
|
|
|
@Command(
|
|
|
|
name = "/set",
|
|
|
|
desc = "Sets all the blocks in the region"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.set")
|
|
|
|
@Logging(REGION)
|
|
|
|
public int set(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "The patter of blocks to set")
|
|
|
|
Pattern pattern) {
|
|
|
|
RegionFunction set = new BlockReplace(editSession, pattern);
|
|
|
|
RegionVisitor visitor = new RegionVisitor(region, set);
|
|
|
|
|
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
List<String> messages = Lists.newArrayList();
|
|
|
|
visitor.addStatusMessages(messages);
|
|
|
|
if (messages.isEmpty()) {
|
|
|
|
player.print("Operation completed.");
|
|
|
|
} else {
|
|
|
|
player.print("Operation completed (" + Joiner.on(", ").join(messages) + ").");
|
|
|
|
}
|
|
|
|
|
|
|
|
return visitor.getAffected();
|
|
|
|
}
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/line",
|
|
|
|
desc = "Draws a line segment between cuboid selection corners",
|
|
|
|
descFooter = "Can only be used with a cuboid selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.line")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int line(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to place")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The thickness of the line", def = "0")
|
|
|
|
int thickness,
|
|
|
|
@Switch(name = 'h', desc = "Generate only a shell")
|
|
|
|
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");
|
2019-04-24 01:46:46 +00:00
|
|
|
return 0;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
CuboidRegion cuboidregion = (CuboidRegion) region;
|
2018-10-14 10:40:53 +00:00
|
|
|
BlockVector3 pos1 = cuboidregion.getPos1();
|
|
|
|
BlockVector3 pos2 = cuboidregion.getPos2();
|
2018-06-15 05:41:37 +00:00
|
|
|
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
player.print(blocksChanged + " block(s) have been changed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return blocksChanged;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/curve",
|
|
|
|
desc = "Draws a spline through selected points",
|
|
|
|
descFooter = "Can only be used with a convex polyhedral selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.curve")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int curve(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to place")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The thickness of the curve", def = "0")
|
|
|
|
int thickness,
|
|
|
|
@Switch(name = 'h', desc = "Generate only a shell")
|
|
|
|
boolean shell) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
if (!(region instanceof ConvexPolyhedralRegion)) {
|
2016-08-27 20:53:51 +00:00
|
|
|
player.printError("//curve only works with convex polyhedral selections");
|
2019-04-24 01:46:46 +00:00
|
|
|
return 0;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
|
2018-10-14 10:40:53 +00:00
|
|
|
List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices());
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-06-15 05:41:37 +00:00
|
|
|
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
player.print(blocksChanged + " block(s) have been changed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return blocksChanged;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/replace",
|
|
|
|
aliases = { "/re", "/rep" },
|
|
|
|
desc = "Replace all blocks in the selection with another"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.replace")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int replace(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The mask representing blocks to replace", def = "")
|
|
|
|
Mask from,
|
|
|
|
@Arg(desc = "The pattern of blocks to replace with")
|
2019-04-29 04:42:45 +00:00
|
|
|
Pattern to) throws WorldEditException {
|
2014-06-28 08:01:49 +00:00
|
|
|
if (from == null) {
|
|
|
|
from = new ExistingBlockMask(editSession);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected = editSession.replaceBlocks(region, from, to);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been replaced.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/overlay",
|
|
|
|
desc = "Set a block on top of blocks in the region"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.overlay")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int overlay(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to overlay")
|
|
|
|
Pattern pattern) throws WorldEditException {
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected = editSession.overlayCuboidBlocks(region, pattern);
|
2014-06-28 08:01:49 +00:00
|
|
|
player.print(affected + " block(s) have been overlaid.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/center",
|
|
|
|
aliases = { "/middle" },
|
|
|
|
desc = "Set the center block(s)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@Logging(REGION)
|
|
|
|
@CommandPermissions("worldedit.region.center")
|
2019-04-24 01:46:46 +00:00
|
|
|
public int center(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern) throws WorldEditException {
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected = editSession.center(region, pattern);
|
2019-04-24 01:46:46 +00:00
|
|
|
player.print("Center set (" + affected + " block(s) changed)");
|
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/naturalize",
|
|
|
|
desc = "3 layers of dirt on top then rock below"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.naturalize")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int 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.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/walls",
|
|
|
|
desc = "Build the four sides of the selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.walls")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int walls(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern) throws WorldEditException {
|
2018-08-30 06:42:50 +00:00
|
|
|
int affected = editSession.makeWalls(region, pattern);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/faces",
|
|
|
|
aliases = { "/outline" },
|
|
|
|
desc = "Build the walls, ceiling, and floor of a selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.faces")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int faces(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern) throws WorldEditException {
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected = editSession.makeCuboidFaces(region, pattern);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/smooth",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Smooth the elevation in the selection",
|
2019-04-24 01:46:46 +00:00
|
|
|
descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.smooth")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int smooth(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "# of iterations to perform", def = "1")
|
|
|
|
int iterations,
|
|
|
|
@Arg(desc = "The mask of blocks to use as the height map", def = "")
|
|
|
|
Mask mask) throws WorldEditException {
|
2019-02-26 23:15:35 +00:00
|
|
|
HeightMap heightMap = new HeightMap(editSession, region, mask);
|
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.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/move",
|
|
|
|
desc = "Move the contents of the selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.move")
|
|
|
|
@Logging(ORIENTATION_REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int move(Player player, EditSession editSession, LocalSession session,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "# of blocks to move", def = "1")
|
|
|
|
int count,
|
|
|
|
@Arg(desc = "The direction to move", def = Direction.AIM)
|
|
|
|
@Direction(includeDiagonals = true)
|
|
|
|
BlockVector3 direction,
|
|
|
|
@Arg(desc = "The pattern of blocks to leave", def = "air")
|
|
|
|
Pattern replace,
|
|
|
|
@Switch(name = 's', desc = "Shift the selection to the target location")
|
|
|
|
boolean moveSelection,
|
|
|
|
@Switch(name = 'a', desc = "Ignore air blocks")
|
|
|
|
boolean ignoreAirBlocks) throws WorldEditException {
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(count >= 1, "Count must be >= 1");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-03-02 02:15:21 +00:00
|
|
|
int affected = editSession.moveRegion(region, direction, count, !ignoreAirBlocks, 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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 01:46:46 +00:00
|
|
|
player.print(affected + " block(s) moved.");
|
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/stack",
|
|
|
|
desc = "Repeat the contents of the selection"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.stack")
|
|
|
|
@Logging(ORIENTATION_REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int stack(Player player, EditSession editSession, LocalSession session,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "# of copies to stack", def = "1")
|
|
|
|
int count,
|
|
|
|
@Arg(desc = "The direction to stack", def = Direction.AIM)
|
|
|
|
@Direction(includeDiagonals = true)
|
|
|
|
BlockVector3 direction,
|
|
|
|
@Switch(name = 's', desc = "Shift the selection to the last stacked copy")
|
|
|
|
boolean moveSelection,
|
|
|
|
@Switch(name = 'a', desc = "Ignore air blocks")
|
|
|
|
boolean ignoreAirBlocks) throws WorldEditException {
|
2014-06-28 08:01:49 +00:00
|
|
|
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 {
|
2018-10-14 10:40:53 +00:00
|
|
|
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint());
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint();
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 01:46:46 +00:00
|
|
|
player.print(affected + " block(s) changed. Undo with //undo");
|
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/regen",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Regenerates the contents of the selection",
|
2019-04-24 01:46:46 +00:00
|
|
|
descFooter = "This command might affect things outside the selection,\n" +
|
|
|
|
"if they are within the same chunk."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@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 {
|
2019-04-24 01:46:46 +00:00
|
|
|
session.setMask(null);
|
2014-06-28 08:01:49 +00:00
|
|
|
player.getWorld().regenerate(region, editSession);
|
|
|
|
} finally {
|
|
|
|
session.setMask(mask);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("Region regenerated.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/deform",
|
|
|
|
desc = "Deforms a selected region with an expression",
|
|
|
|
descFooter = "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."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.deform")
|
|
|
|
@Logging(ALL)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int deform(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Selection Region region,
|
2019-04-29 05:03:54 +00:00
|
|
|
@Arg(desc = "The expression to use", variable = true)
|
|
|
|
List<String> expression,
|
2019-04-24 01:46:46 +00:00
|
|
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
|
|
|
boolean useRawCoords,
|
|
|
|
@Switch(name = 'o', desc = "Use the selection's center as origin")
|
|
|
|
boolean offset) throws WorldEditException {
|
2018-10-14 10:40:53 +00:00
|
|
|
final Vector3 zero;
|
|
|
|
Vector3 unit;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
if (useRawCoords) {
|
2018-10-14 10:40:53 +00:00
|
|
|
zero = Vector3.ZERO;
|
|
|
|
unit = Vector3.ONE;
|
2014-06-28 08:01:49 +00:00
|
|
|
} else if (offset) {
|
2018-10-14 10:40:53 +00:00
|
|
|
zero = session.getPlacementPosition(player).toVector3();
|
|
|
|
unit = Vector3.ONE;
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-10-14 10:40:53 +00:00
|
|
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
|
|
|
final Vector3 max = region.getMaximumPoint().toVector3();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
zero = max.add(min).divide(2);
|
2014-04-03 02:08:50 +00:00
|
|
|
unit = max.subtract(zero);
|
|
|
|
|
2018-10-14 10:40:53 +00:00
|
|
|
if (unit.getX() == 0) unit = unit.withX(1.0);
|
|
|
|
if (unit.getY() == 0) unit = unit.withY(1.0);
|
|
|
|
if (unit.getZ() == 0) unit = unit.withZ(1.0);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-04-29 05:03:54 +00:00
|
|
|
final int affected = editSession.deformRegion(region, zero, unit, String.join(" ", expression), session.getTimeout());
|
2014-04-03 02:08:50 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been deformed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
} catch (ExpressionException e) {
|
|
|
|
player.printError(e.getMessage());
|
2019-04-24 01:46:46 +00:00
|
|
|
return 0;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/hollow",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Hollows out the object contained in this selection",
|
2019-04-24 01:46:46 +00:00
|
|
|
descFooter = "Thickness is measured in manhattan distance."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.hollow")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int hollow(Player player, EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "Thickness of the shell to leave", def = "0")
|
|
|
|
int thickness,
|
|
|
|
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
|
|
|
|
Pattern pattern) throws WorldEditException {
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected = editSession.hollowOutRegion(region, thickness, pattern);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/forest",
|
|
|
|
desc = "Make a forest within the region"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.forest")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int forest(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The type of tree to place", def = "tree")
|
|
|
|
TreeType type,
|
|
|
|
@Arg(desc = "The density of the forest", def = "5")
|
|
|
|
double density) throws WorldEditException {
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
|
2019-03-21 01:05:11 +00:00
|
|
|
int affected = editSession.makeForest(region, density / 100, type);
|
|
|
|
player.print(affected + " trees created.");
|
2019-04-24 01:46:46 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-24 01:46:46 +00:00
|
|
|
name = "/flora",
|
|
|
|
desc = "Make flora within the region"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.region.flora")
|
|
|
|
@Logging(REGION)
|
2019-04-24 01:46:46 +00:00
|
|
|
public int flora(Player player, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(desc = "The density of the forest", def = "5")
|
|
|
|
double density) throws WorldEditException {
|
2019-05-15 00:57:05 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
|
2014-06-28 08:01:49 +00:00
|
|
|
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);
|
|
|
|
|
2019-04-24 01:46:46 +00:00
|
|
|
int affected = ground.getAffected();
|
|
|
|
player.print(affected + " flora created.");
|
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|