2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-08-08 12:40:02 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2011-10-02 10:35:05 +00:00
|
|
|
import com.sk89q.worldedit.expression.Expression;
|
|
|
|
import com.sk89q.worldedit.expression.ExpressionException;
|
2011-02-18 23:14:43 +00:00
|
|
|
import com.sk89q.worldedit.patterns.Pattern;
|
2011-10-02 10:35:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2011-01-30 22:54:42 +00:00
|
|
|
import com.sk89q.worldedit.util.TreeGenerator;
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generation commands.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class GenerationCommands {
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/hcyl" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius> [height]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Generate a hollow cylinder",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.cylinder")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void hcyl(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
Pattern block = we.getBlockPattern(player, args.getString(0));
|
2011-08-07 03:20:50 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
2011-01-29 10:05:22 +00:00
|
|
|
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
int affected = editSession.makeHollowCylinder(pos, block, radius, height);
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/cyl" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius> [height]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Generate a cylinder",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.cylinder")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void cyl(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
Pattern block = we.getBlockPattern(player, args.getString(0));
|
2011-08-07 03:20:50 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
2011-01-29 10:05:22 +00:00
|
|
|
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
int affected = editSession.makeCylinder(pos, block, radius, height);
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/hsphere" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius>[,<radius>,<radius>] [raised?]",
|
2011-09-03 16:54:20 +00:00
|
|
|
desc = "Generate a hollow sphere.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void hsphere(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-09-02 19:38:38 +00:00
|
|
|
final Pattern block = we.getBlockPattern(player, args.getString(0));
|
|
|
|
String[] radiuses = args.getString(1).split(",");
|
|
|
|
final double radiusX, radiusY, radiusZ;
|
|
|
|
switch (radiuses.length) {
|
|
|
|
case 1:
|
|
|
|
radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radiuses[0]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
radiusX = Math.max(1, Double.parseDouble(radiuses[0]));
|
|
|
|
radiusY = Math.max(1, Double.parseDouble(radiuses[1]));
|
|
|
|
radiusZ = Math.max(1, Double.parseDouble(radiuses[2]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
player.printError("You must either specify 1 or 3 radius values.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final boolean raised;
|
2011-09-03 16:54:20 +00:00
|
|
|
if (args.argsLength() > 2) {
|
2011-09-02 19:38:38 +00:00
|
|
|
raised = args.getString(2).equalsIgnoreCase("true") || args.getString(2).equalsIgnoreCase("yes");
|
2011-09-03 16:54:20 +00:00
|
|
|
} else {
|
2011-09-02 19:38:38 +00:00
|
|
|
raised = false;
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
if (raised) {
|
2011-09-02 19:38:38 +00:00
|
|
|
pos = pos.add(0, radiusY, 0);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 19:38:38 +00:00
|
|
|
int affected = editSession.makeSphere(pos, block, radiusX, radiusY, radiusZ, false);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/sphere" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius>[,<radius>,<radius>] [raised?]",
|
2011-09-03 16:54:20 +00:00
|
|
|
desc = "Generate a filled sphere.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void sphere(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
Pattern block = we.getBlockPattern(player, args.getString(0));
|
2011-09-02 19:38:38 +00:00
|
|
|
String[] radiuses = args.getString(1).split(",");
|
|
|
|
final double radiusX, radiusY, radiusZ;
|
|
|
|
switch (radiuses.length) {
|
|
|
|
case 1:
|
|
|
|
radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radiuses[0]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
radiusX = Math.max(1, Double.parseDouble(radiuses[0]));
|
|
|
|
radiusY = Math.max(1, Double.parseDouble(radiuses[1]));
|
|
|
|
radiusZ = Math.max(1, Double.parseDouble(radiuses[2]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
player.printError("You must either specify 1 or 3 radius values.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final boolean raised;
|
2011-09-03 16:54:20 +00:00
|
|
|
if (args.argsLength() > 2) {
|
2011-09-02 19:38:38 +00:00
|
|
|
raised = args.getString(2).equalsIgnoreCase("true") || args.getString(2).equalsIgnoreCase("yes");
|
2011-09-03 16:54:20 +00:00
|
|
|
} else {
|
2011-09-02 19:38:38 +00:00
|
|
|
raised = false;
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
if (raised) {
|
2011-09-02 19:38:38 +00:00
|
|
|
pos = pos.add(0, radiusY, 0);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 19:38:38 +00:00
|
|
|
int affected = editSession.makeSphere(pos, block, radiusX, radiusY, radiusZ, true);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "forestgen" },
|
2011-01-30 22:54:42 +00:00
|
|
|
usage = "[size] [type] [density]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Generate a forest",
|
|
|
|
min = 0,
|
2011-01-31 06:09:24 +00:00
|
|
|
max = 3
|
2011-01-29 10:05:22 +00:00
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.forest")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(POSITION)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void forestGen(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
2011-01-30 22:54:42 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
2011-01-30 22:54:42 +00:00
|
|
|
TreeGenerator.TreeType type = args.argsLength() > 1 ?
|
|
|
|
type = TreeGenerator.lookup(args.getString(1))
|
|
|
|
: TreeGenerator.TreeType.TREE;
|
|
|
|
double density = args.argsLength() > 2 ? args.getDouble(2) / 100 : 0.05;
|
|
|
|
|
|
|
|
if (type == null) {
|
|
|
|
player.printError("Tree type '" + args.getString(1) + "' is unknown.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
int affected = editSession.makeForest(player.getPosition(),
|
2011-01-30 22:54:42 +00:00
|
|
|
size, density, new TreeGenerator(type));
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " trees created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "pumpkins" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[size]",
|
|
|
|
desc = "Generate pumpkin patches",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.pumpkins")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(POSITION)
|
2011-01-29 10:05:22 +00:00
|
|
|
public static void pumpkins(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
|
|
|
|
|
|
|
int affected = editSession.makePumpkinPatches(player.getPosition(), size);
|
|
|
|
player.print(affected + " pumpkin patches created.");
|
|
|
|
}
|
2011-08-07 00:40:48 +00:00
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/pyramid" },
|
2011-09-26 05:43:39 +00:00
|
|
|
usage = "<block> <size>",
|
2011-08-07 00:40:48 +00:00
|
|
|
desc = "Generate a filled pyramid",
|
|
|
|
min = 2,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-08-07 00:40:48 +00:00
|
|
|
public static void pyramid(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Pattern block = we.getBlockPattern(player, args.getString(0));
|
|
|
|
int size = Math.max(1, args.getInteger(1));
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
|
|
|
|
int affected = editSession.makePyramid(pos, block, size, true);
|
|
|
|
|
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/hpyramid" },
|
2011-09-26 05:43:39 +00:00
|
|
|
usage = "<block> <size>",
|
2011-08-07 00:40:48 +00:00
|
|
|
desc = "Generate a hollow pyramid",
|
|
|
|
min = 2,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-08-07 00:40:48 +00:00
|
|
|
public static void hpyramid(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
Pattern block = we.getBlockPattern(player, args.getString(0));
|
|
|
|
int size = Math.max(1, args.getInteger(1));
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
|
|
|
|
int affected = editSession.makePyramid(pos, block, size, false);
|
|
|
|
|
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
2011-10-02 10:35:05 +00:00
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/generate", "/gen", "/g" },
|
|
|
|
usage = "<block> <equation>",
|
2011-10-26 21:23:26 +00:00
|
|
|
desc = "Generates a shape according to a formula. -h for hollow, -r for raw coordinates, -o for unscaled, but offset from placement",
|
2011-10-02 10:35:05 +00:00
|
|
|
flags = "hro",
|
|
|
|
min = 1,
|
|
|
|
max = -1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.shape")
|
|
|
|
@Logging(ALL)
|
|
|
|
public static void generate(CommandContext args, WorldEdit we,
|
|
|
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
|
|
|
throws WorldEditException {
|
|
|
|
|
|
|
|
final Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
|
|
|
final Region region = session.getSelection(player.getWorld());
|
|
|
|
|
|
|
|
final Expression expression;
|
|
|
|
try {
|
|
|
|
expression = Expression.compile(args.getJoinedStrings(1), "x", "y", "z");
|
|
|
|
expression.optimize();
|
2011-10-27 17:25:54 +00:00
|
|
|
}
|
|
|
|
catch (ExpressionException e) {
|
2011-10-02 10:35:05 +00:00
|
|
|
player.printError(e.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ArbitraryShape shape;
|
|
|
|
|
|
|
|
if (args.hasFlag('r')) {
|
|
|
|
shape = new ArbitraryShape(region) {
|
|
|
|
@Override
|
|
|
|
protected boolean isInside(double x, double y, double z) {
|
|
|
|
try {
|
|
|
|
return expression.evaluate(x, y, z) > 0;
|
2011-10-27 17:25:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2011-10-02 10:35:05 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (args.hasFlag('o')) {
|
|
|
|
final Vector placement = session.getPlacementPosition(player);
|
|
|
|
|
|
|
|
final double placementX = placement.getX();
|
|
|
|
final double placementY = placement.getY();
|
|
|
|
final double placementZ = placement.getZ();
|
|
|
|
|
|
|
|
shape = new ArbitraryShape(region) {
|
|
|
|
@Override
|
|
|
|
protected boolean isInside(double x, double y, double z) {
|
|
|
|
try {
|
2011-10-27 17:25:54 +00:00
|
|
|
return expression.evaluate(x - placementX, y - placementY, z - placementZ) > 0;
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2011-10-02 10:35:05 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
final Vector min = region.getMinimumPoint();
|
|
|
|
final Vector max = region.getMaximumPoint();
|
|
|
|
final Vector center = max.add(min).multiply(0.5);
|
|
|
|
final Vector stretch = max.subtract(center);
|
|
|
|
shape = new ArbitraryShape(region) {
|
|
|
|
@Override
|
|
|
|
protected boolean isInside(double x, double y, double z) {
|
2011-10-27 17:25:54 +00:00
|
|
|
final Vector scaled = new Vector(x, y, z).subtract(center).divide(stretch);
|
2011-10-02 10:35:05 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
return expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ()) > 0;
|
2011-10-27 17:25:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2011-10-02 10:35:05 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean hollow = args.hasFlag('h');
|
|
|
|
int affected = shape.generate(editSession, pattern, hollow);
|
|
|
|
|
|
|
|
player.findFreePosition();
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|