Plex-FAWE/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java

764 lines
34 KiB
Java
Raw Normal View History

/*
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-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
* (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-04 22:03:18 +00:00
* 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/>.
2014-04-04 22:03:18 +00:00
*/
package com.sk89q.worldedit.command;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
2019-11-02 11:13:42 +00:00
import com.boydti.fawe.beta.implementation.processors.ChunkSendProcessor;
import com.boydti.fawe.beta.implementation.processors.NullProcessor;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweLimit;
import com.sk89q.jnbt.CompoundTag;
2018-12-23 16:19:33 +00:00
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
2019-11-16 00:20:14 +00:00
import com.sk89q.worldedit.function.FlatRegionFunction;
import com.sk89q.worldedit.function.GroundFunction;
2019-11-16 00:20:14 +00:00
import com.sk89q.worldedit.function.biome.BiomeReplace;
import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
2019-07-18 06:56:57 +00:00
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
2019-11-16 00:20:14 +00:00
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Range;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.expression.ExpressionException;
2019-04-03 13:25:16 +00:00
import com.sk89q.worldedit.math.BlockVector2;
2018-12-23 16:19:33 +00:00
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMap;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
import com.sk89q.worldedit.math.noise.RandomNoise;
2019-06-30 18:56:32 +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.regions.Regions;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.World;
2019-04-03 13:25:16 +00:00
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
2019-08-06 15:25:53 +00:00
import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.inject.InjectedValueAccess;
2019-11-16 00:20:14 +00:00
import java.util.ArrayList;
2019-11-17 17:22:21 +00:00
import java.util.Collections;
2019-11-16 00:20:14 +00:00
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
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;
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
/**
* Commands that operate on regions.
*/
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class RegionCommands {
private final WorldEdit worldEdit;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public RegionCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
}
@Command(
name = "/air",
aliases = {"/0"},
desc = "Sets all the blocks in the region to air"
)
@CommandPermissions("worldedit.region.set")
@Logging(REGION)
public void air(Actor actor, EditSession editSession,
@Selection Region region,
InjectedValueAccess context) throws WorldEditException {
set(actor, editSession, region, BlockTypes.AIR, context);
}
@Command(
name = "/set",
aliases = {"/"},
desc = "Sets all the blocks in the region"
)
@CommandPermissions("worldedit.region.set")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void set(Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
int affected = editSession.setBlocks(region, pattern);
if (affected != 0) {
2019-10-23 16:58:36 +00:00
BBC.OPERATION.send(actor, affected);
if (!actor.hasPermission("fawe.tips"))
BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(actor);
}
}, getArguments(context), region, context);
}
@Command(
name = "/test",
desc = "test region"
)
@CommandPermissions("worldedit.region.test")
@Logging(REGION)
2019-11-16 00:20:14 +00:00
public void test(Player player, EditSession editSession, @Selection Region region, @Arg(desc = "hello there") BiomeType biome) throws WorldEditException {
System.out.println("Test start");
2019-11-17 17:22:21 +00:00
editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Collections.singleton(player)));
2019-11-16 00:20:14 +00:00
editSession.addProcessor(NullProcessor.INSTANCE);
FlatRegionFunction replace = new BiomeReplace(editSession, biome);
FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace);
Operations.completeLegacy(visitor);
System.out.println("Test end");
}
@Command(
name = "/fixlighting",
desc = "Get the light at a position"
)
@CommandPermissions("worldedit.light.fix")
public void fixLighting(Player player) throws WorldEditException {
final Location loc = player.getLocation();
Region selection = player.getSelection();
if (selection == null) {
final int cx = loc.getBlockX() >> 4;
final int cz = loc.getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
2019-07-21 11:39:36 +00:00
int count = FaweAPI.fixLighting(player.getWorld(), selection,null);
BBC.LIGHTING_PROPAGATE_SELECTION.send(player, count);
}
@Command(
name = "/getlighting",
desc = "Get the light at a position"
)
@CommandPermissions("worldedit.light.fix")
public void getLighting(Player player, EditSession editSession) throws WorldEditException {
final Location loc = player.getLocation();
2019-07-21 11:39:36 +00:00
int block = editSession.getBlockLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
int sky = editSession.getSkyLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
player.print("Light: " + block + " | " + sky);
}
@Command(
name = "/removelighting",
desc = "Removing lighting in a selection"
)
@CommandPermissions("worldedit.light.remove")
public void removeLighting(Player player) {
Region selection = player.getSelection();
if (selection == null) {
final int cx = player.getLocation().getBlockX() >> 4;
final int cz = player.getLocation().getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
2019-07-21 11:39:36 +00:00
int count = FaweAPI.fixLighting(player.getWorld(), selection, null);
BBC.UPDATED_LIGHTING_SELECTION.send(player, count);
}
@Command(
name = "/nbtinfo",
2019-10-23 04:23:52 +00:00
aliases = "/nbt",
desc = "View nbt info for a block"
)
@CommandPermissions("worldedit.nbtinfo")
public void nbtinfo(Player player, EditSession editSession) {
Location pos = player.getBlockTrace(128);
if (pos == null) {
2019-11-02 19:53:25 +00:00
player.printError(BBC.NO_BLOCK.s());
return;
}
2019-03-31 16:09:20 +00:00
CompoundTag nbt = editSession.getFullBlock(pos.toBlockPoint()).getNbtData();
if (nbt != null) {
player.print(nbt.getValue().toString());
} else {
2019-11-02 19:53:25 +00:00
player.printError(BBC.NO_BLOCK.s());
}
}
@Command(
name = "/setblocklight",
desc = "Set block lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
2019-07-21 11:39:36 +00:00
public void setlighting(Player player, EditSession editSession, @Selection Region region, @Range(min = 0, max = 15) int value) {
// TODO NOT IMPLEMENTED
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/setskylight",
desc = "Set sky lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
public void setskylighting(Player player, @Selection Region region, @Range(min = 0, max = 15) int value) {
2019-07-21 11:39:36 +00:00
// TODO NOT IMPLEMENTED
}
@Command(
name = "/line",
desc = "Draws a line segment between cuboid selection corners",
descFooter = "Can only be used with a cuboid selection"
)
@CommandPermissions("worldedit.region.line")
@Logging(REGION)
public int line(Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to place")
2019-10-23 16:58:36 +00:00
Pattern pattern,
2019-07-28 19:26:44 +00:00
@Range(min = 1) @Arg(desc = "The thickness of the line", def = "0")
int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell) throws WorldEditException {
if (!(region instanceof CuboidRegion)) {
actor.printError("//line only works with cuboid selections");
return 0;
}
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
CuboidRegion cuboidregion = (CuboidRegion) region;
2018-12-23 16:19:33 +00:00
BlockVector3 pos1 = cuboidregion.getPos1();
BlockVector3 pos2 = cuboidregion.getPos2();
2019-10-23 16:58:36 +00:00
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell);
BBC.VISITOR_BLOCK.send(actor, blocksChanged);
return blocksChanged;
}
@Command(
name = "/curve",
desc = "Draws a spline through selected points",
descFooter = "Can only be used with a convex polyhedral selection"
)
@CommandPermissions("worldedit.region.curve")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void curve(Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to place")
2019-10-23 16:58:36 +00:00
Pattern pattern,
@Arg(desc = "The thickness of the curve", def = "0")
int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell, InjectedValueAccess context) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) {
2019-10-23 16:58:36 +00:00
actor.printError("//curve only works with convex polyhedral selections");
return;
}
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
2018-12-23 16:19:33 +00:00
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices());
2019-10-23 16:58:36 +00:00
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell);
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, blocksChanged);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/replace",
aliases = { "/repl", "/rep" },
desc = "Replace all blocks in the selection with another"
)
@CommandPermissions("worldedit.region.replace")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void replace(Actor actor, 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")
Pattern to, InjectedValueAccess context) throws WorldEditException {
if (from == null) {
from = new ExistingBlockMask(editSession);
}
2019-08-06 15:25:53 +00:00
Mask finalFrom = from;
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
2019-08-06 15:25:53 +00:00
int affected = editSession.replaceBlocks(region, finalFrom, to);
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, affected);
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_REPLACE_ID
.or(BBC.TIP_REPLACE_LIGHT, BBC.TIP_REPLACE_MARKER, BBC.TIP_TAB_COMPLETE,
BBC.TIP_REPLACE_REGEX, BBC.TIP_REPLACE_REGEX_2, BBC.TIP_REPLACE_REGEX_3,
2019-10-23 16:58:36 +00:00
BBC.TIP_REPLACE_REGEX_4, BBC.TIP_REPLACE_REGEX_5).send(actor);
}
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/overlay",
desc = "Set a block on top of blocks in the region"
)
@CommandPermissions("worldedit.region.overlay")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void overlay(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to overlay")
2019-10-23 16:58:36 +00:00
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.overlayCuboidBlocks(region, pattern);
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/lay",
desc = "Set the top block in the region"
)
@CommandPermissions("worldedit.region.overlay")
@Logging(REGION)
2019-11-02 19:53:25 +00:00
public void lay(Player player, EditSession editSession, @Selection Region region, @Arg(name = "pattern", desc = "The pattern of blocks to lay") Pattern patternArg, InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
BlockVector3 max = region.getMaximumPoint();
2018-09-07 15:09:31 +00:00
int maxY = max.getBlockY();
2019-01-09 07:13:44 +00:00
Iterable<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion();
2019-07-22 09:05:14 +00:00
Iterator<BlockVector2> iter = flat.iterator();
2018-09-07 15:09:31 +00:00
int y = 0;
int affected = 0;
while (iter.hasNext()) {
2019-07-22 20:42:40 +00:00
BlockVector2 pos = iter.next();
2018-09-07 15:09:31 +00:00
int x = pos.getBlockX();
int z = pos.getBlockZ();
y = editSession.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
2019-08-06 15:25:53 +00:00
editSession.setBlock(x, y, z, patternArg);
2018-09-07 15:09:31 +00:00
affected++;
}
2019-11-02 19:53:25 +00:00
BBC.VISITOR_BLOCK.send(player, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/center",
aliases = { "/middle" },
desc = "Set the center block(s)"
)
@Logging(REGION)
@CommandPermissions("worldedit.region.center")
public void center(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
2019-10-23 16:58:36 +00:00
Pattern pattern) throws WorldEditException {
int affected = editSession.center(region, pattern);
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
name = "/naturalize",
desc = "3 layers of dirt on top then rock below"
)
@CommandPermissions("worldedit.region.naturalize")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void naturalize(Actor actor, EditSession editSession, @Selection Region region, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
2018-09-07 15:09:31 +00:00
int affected = editSession.naturalizeCuboidBlocks(region);
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/walls",
desc = "Build the four sides of the selection"
)
@CommandPermissions("worldedit.region.walls")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void walls(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
2019-10-23 16:58:36 +00:00
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.makeWalls(region, pattern);
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/faces",
aliases = { "/outline" },
desc = "Build the walls, ceiling, and floor of a selection"
)
@CommandPermissions("worldedit.region.faces")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void faces(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
2019-10-23 16:58:36 +00:00
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.makeCuboidFaces(region, pattern);
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/smooth",
desc = "Smooth the elevation in the selection",
descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain."
)
@CommandPermissions("worldedit.region.smooth")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void smooth(Actor actor, 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 = "")
2019-10-23 16:58:36 +00:00
Mask mask,
@Switch(name = 's', desc = "TODO") boolean snow, InjectedValueAccess context) throws WorldEditException {
2019-07-22 20:42:40 +00:00
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
2019-10-23 16:58:36 +00:00
FaweLimit limit = actor.getLimit();
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
try {
2019-10-23 16:58:36 +00:00
HeightMap heightMap = new HeightMap(editSession, region, mask, snow);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
2018-09-07 15:09:31 +00:00
int affected = heightMap.applyFilter(filter, iterations);
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, affected);
} catch (Throwable e) {
throw new RuntimeException(e);
}
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/wea",
aliases = {"wea", "worldeditanywhere", "/worldeditanywhere", "/weanywhere"},
desc = "Bypass region restrictions",
2019-07-17 05:43:18 +00:00
descFooter = "Bypass region restrictions"
)
@CommandPermissions("fawe.admin")
2019-10-23 16:58:36 +00:00
public void wea(Actor actor) throws WorldEditException {
if (actor.togglePermission("fawe.bypass")) {
actor.print(BBC.WORLDEDIT_BYPASSED.s());
} else {
2019-10-23 16:58:36 +00:00
actor.print(BBC.WORLDEDIT_RESTRICTED.s());
}
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/wer",
aliases = {"wer", "worldeditregion", "/worldeditregion", "select", "/select"},
desc = "Select your current allowed region",
2019-07-17 05:43:18 +00:00
descFooter = "Select your current allowed region"
)
@CommandPermissions("fawe.worldeditregion")
2019-10-23 16:58:36 +00:00
public void wer(Player player) throws WorldEditException {
final Region region = player.getLargestRegion();
if (region == null) {
2019-10-23 16:58:36 +00:00
player.print(BBC.NO_REGION.s());
} else {
2019-10-23 16:58:36 +00:00
player.setSelection(region);
player.print(BBC.SET_REGION.s());
}
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/move",
aliases = {"/mv"},
desc = "Move the contents of the selection"
)
@CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION)
2019-10-23 16:58:36 +00:00
public void move(Actor actor, World world, 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,
@Switch(name = 'e', desc = "Ignore entities")
boolean skipEntities,
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes,
InjectedValueAccess context) throws WorldEditException {
checkCommandArgument(count >= 1, "Count must be >= 1");
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
int affected = editSession.moveRegion(region, direction, count, !ignoreAirBlocks, !skipEntities, copyBiomes, replace);
2018-09-07 15:09:31 +00:00
if (moveSelection) {
try {
region.shift(direction.multiply(count));
session.getRegionSelector(world).learnChanges();
2019-10-23 16:58:36 +00:00
session.getRegionSelector(world).explainRegionAdjust(actor, session);
2018-09-07 15:09:31 +00:00
} catch (RegionOperationException e) {
2019-10-23 16:58:36 +00:00
actor.printError(e.getMessage());
2018-09-07 15:09:31 +00:00
}
}
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/fall",
desc = "Have the blocks in the selection fall",
2019-07-17 05:43:18 +00:00
descFooter = "Make the blocks in the selection fall\n" +
"The -m flag will only fall within the vertical selection."
)
@CommandPermissions("worldedit.region.fall")
@Logging(ORIENTATION_REGION)
public void fall(Player player, EditSession editSession, LocalSession session,
@Selection Region region,
2019-10-23 16:58:36 +00:00
@Arg(desc = "BlockStateHolder", def = "air") BlockStateHolder replace,
@Switch(name = 'm', desc = "TODO") boolean notFullHeight,
InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
2018-09-07 15:09:31 +00:00
int affected = editSession.fall(region, !notFullHeight, replace);
BBC.VISITOR_BLOCK.send(player, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/stack",
desc = "Repeat the contents of the selection"
)
@CommandPermissions("worldedit.region.stack")
@Logging(ORIENTATION_REGION)
2019-10-23 16:58:36 +00:00
public void stack(Actor actor, World world, 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,
@Switch(name = 'e', desc = "Skip entities")
boolean skipEntities,
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes,
2019-11-14 10:23:02 +00:00
@ArgFlag(name = 'm', desc = "Source mask", def="")
Mask sourceMask,
InjectedValueAccess context) throws WorldEditException {
2019-10-23 16:58:36 +00:00
actor.checkConfirmationStack(() -> {
2018-09-07 15:09:31 +00:00
if (sourceMask != null) {
editSession.addSourceMask(sourceMask);
}
int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks, !skipEntities, copyBiomes);
if (moveSelection) {
try {
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint());
final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint();
2018-09-07 15:09:31 +00:00
region.shift(shiftVector);
2019-10-23 16:58:36 +00:00
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
2018-09-07 15:09:31 +00:00
} catch (RegionOperationException e) {
2019-10-23 16:58:36 +00:00
actor.printError(e.getMessage());
2018-09-07 15:09:31 +00:00
}
}
2019-10-23 16:58:36 +00:00
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, count, context);
}
@Command(
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 https://tinyurl.com/weexpr"
)
@CommandPermissions("worldedit.region.deform")
@Logging(ALL)
2019-10-23 16:58:36 +00:00
public void deform(Actor actor, LocalSession session, EditSession editSession, InjectedValueAccess context,
@Selection Region region,
@Arg(desc = "The expression to use", variable = true)
List<String> expression,
@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-12-23 16:19:33 +00:00
final Vector3 zero;
Vector3 unit;
if (useRawCoords) {
2018-12-23 16:19:33 +00:00
zero = Vector3.ZERO;
unit = Vector3.ONE;
} else if (offset) {
2019-10-23 16:58:36 +00:00
zero = session.getPlacementPosition(actor).toVector3();
2018-12-23 16:19:33 +00:00
unit = Vector3.ONE;
} else {
2018-12-23 16:19:33 +00:00
final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
2018-12-23 16:19:33 +00:00
zero = max.add(min).divide(2);
unit = max.subtract(zero);
2018-12-23 16:19:33 +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);
}
2019-01-09 07:13:44 +00:00
final Vector3 unit1 = unit;
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
2018-09-07 15:09:31 +00:00
try {
2019-07-21 11:39:36 +00:00
final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout());
2019-10-23 16:58:36 +00:00
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 15:09:31 +00:00
} catch (ExpressionException e) {
2019-10-23 16:58:36 +00:00
actor.printError(e.getMessage());
2018-09-07 15:09:31 +00:00
}
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
2019-07-17 05:43:18 +00:00
name = "/regen",
desc = "Regenerates the contents of the selection",
2019-07-17 05:43:18 +00:00
descFooter =
"Regenerates the contents of the current selection.\n" +
"This command might affect things outside the selection,\n" +
2019-07-17 05:43:18 +00:00
"if they are within the same chunk."
)
@CommandPermissions("worldedit.regen")
@Logging(REGION)
2019-11-02 19:53:25 +00:00
public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region,
2019-07-21 11:39:36 +00:00
@Arg(def = "", desc = "Regenerate with biome") BiomeType biome,
@Arg(def = "", desc = "Regenerate with seed") Long seed,
InjectedValueAccess context) throws WorldEditException {
2019-11-02 19:53:25 +00:00
player.checkConfirmationRegion(() -> {
2018-09-07 15:09:31 +00:00
Mask mask = session.getMask();
session.setMask((Mask) null);
session.setSourceMask((Mask) null);
editSession.regenerate(region, biome, seed);
session.setMask(mask);
session.setSourceMask(mask);
2019-11-02 19:53:25 +00:00
if (!player.hasPermission("fawe.tips")) {
player.print(BBC.COMMAND_REGEN_2.s());
2018-09-07 15:09:31 +00:00
} else if (biome == null) {
2019-11-02 19:53:25 +00:00
BBC.COMMAND_REGEN_0.send(player);
if (!player.hasPermission("fawe.tips")) player.print(BBC.TIP_REGEN_0.s());
2018-09-07 15:09:31 +00:00
} else if (seed == null) {
2019-11-02 19:53:25 +00:00
player.print(BBC.COMMAND_REGEN_1.s());
if (!player.hasPermission("fawe.tips")) BBC.TIP_REGEN_1.send(player);
2018-09-07 15:09:31 +00:00
} else {
2019-11-02 19:53:25 +00:00
player.print(BBC.COMMAND_REGEN_2.s());
2018-09-07 15:09:31 +00:00
}
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
2018-09-07 15:09:31 +00:00
}
@Command(
name = "/hollow",
desc = "Hollows out the object contained in this selection",
2019-07-17 05:43:18 +00:00
descFooter = "Hollows out the object contained in this selection.\n" +
"Optionally fills the hollowed out part with the given block.\n" +
2019-07-17 05:43:18 +00:00
"Thickness is measured in manhattan distance."
2019-07-18 06:56:57 +00:00
)
@CommandPermissions("worldedit.region.hollow")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void hollow(Actor actor, EditSession editSession,
@Selection Region region,
2019-07-28 19:26:44 +00:00
@Range(min = 0) @Arg(desc = "Thickness of the shell to leave", def = "0")
int thickness,
2019-10-23 16:58:36 +00:00
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
Pattern pattern,
2019-08-06 15:25:53 +00:00
@ArgFlag(name = 'm', desc = "Mask to hollow with") Mask mask,
InjectedValueAccess context) throws WorldEditException {
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
2019-07-18 06:56:57 +00:00
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask);
BBC.VISITOR_BLOCK.send(actor, affected);
2018-09-07 23:10:36 +00:00
}, getArguments(context), region, context);
}
@Command(
name = "/forest",
desc = "Make a forest within the region"
)
@CommandPermissions("worldedit.region.forest")
@Logging(REGION)
public int forest(Actor actor, 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 {
checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
int affected = editSession.makeForest(region, density / 100, type);
BBC.COMMAND_TREE.send(actor, affected);
return affected;
}
@Command(
name = "/flora",
desc = "Make flora within the region"
)
@CommandPermissions("worldedit.region.flora")
@Logging(REGION)
2019-10-23 16:58:36 +00:00
public void flora(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The density of the forest", def = "5")
double density, InjectedValueAccess context) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
2019-10-23 16:58:36 +00:00
actor.checkConfirmationRegion(() -> {
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 / 100));
Operations.completeLegacy(visitor);
2018-09-07 15:09:31 +00:00
2019-10-23 16:58:36 +00:00
BBC.COMMAND_FLORA.send(actor, ground.getAffected());
2019-08-06 15:25:53 +00:00
}, "/flora", region, context);
}
2019-04-02 20:26:51 +00:00
}