3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-04 18:40:06 +01:00

Added //forest that generates a forest in a selection.

Fixes WORLDEDIT-2958.
Dieser Commit ist enthalten in:
sk89q 2014-02-28 16:15:51 -08:00
Ursprung 9627d830d7
Commit 0e615e5bf7
2 geänderte Dateien mit 120 neuen und 91 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,5 @@
5.6
- Added //forest that generates a forest in a selection.
- Added -s flag to //paste to select the pasted area.
- Added //line command and EditSession method.
- Added /curve.

Datei anzeigen

@ -19,37 +19,27 @@
package com.sk89q.worldedit.commands;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.ORIENTATION_REGION;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.HeightMap;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.expression.ExpressionException;
import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.patterns.SingleBlockPattern;
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.masks.Mask;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.patterns.SingleBlockPattern;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.util.TreeGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
/**
* Region related commands.
@ -88,80 +78,80 @@ public class RegionCommands {
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)
@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)
public void line(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(session.getSelectionWorld());
if (!(region instanceof CuboidRegion)) {
player.printError("Invalid region type");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return;
}
Pattern pattern = we.getBlockPattern(player, args.getString(0));
CuboidRegion cuboidregion = (CuboidRegion) region;
Vector pos1 = cuboidregion.getPos1();
Vector pos2 = cuboidregion.getPos2();
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h'));
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)
public void curve(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(session.getSelectionWorld());
if (!(region instanceof ConvexPolyhedralRegion)) {
player.printError("Invalid region type");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return;
}
Pattern pattern = we.getBlockPattern(player, args.getString(0));
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<Vector> vectors = new ArrayList<Vector>(cpregion.getVertices());
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h'));
player.print(blocksChanged + " block(s) have been changed.");
}
player.printError("Invalid region type");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return;
}
Pattern pattern = we.getBlockPattern(player, args.getString(0));
CuboidRegion cuboidregion = (CuboidRegion) region;
Vector pos1 = cuboidregion.getPos1();
Vector pos2 = cuboidregion.getPos2();
int blocksChanged = editSession.drawLine(pattern, pos1, pos2, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h'));
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)
public void curve(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
Region region = session.getSelection(session.getSelectionWorld());
if (!(region instanceof ConvexPolyhedralRegion)) {
player.printError("Invalid region type");
return;
}
if (args.argsLength() < 2 ? false : args.getDouble(1) < 0) {
player.printError("Invalid thickness. Must not be negative");
return;
}
Pattern pattern = we.getBlockPattern(player, args.getString(0));
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<Vector> vectors = new ArrayList<Vector>(cpregion.getVertices());
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, args.argsLength() < 2 ? 0 : args.getDouble(1), !args.hasFlag('h'));
player.print(blocksChanged + " block(s) have been changed.");
}
@Command(
aliases = { "/replace", "/re", "/rep" },
@ -526,4 +516,42 @@ public class RegionCommands {
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)
public void forest(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
TreeGenerator.TreeType type = args.argsLength() > 1 ? 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;
}
Region region = session.getSelection(player.getWorld());
FlatRegion flatRegion;
if (region instanceof FlatRegion) {
flatRegion = (FlatRegion) region;
} else {
player.print("(The given region is not a 'flat region', so a cuboid region will be used instead.)");
flatRegion = CuboidRegion.makeCuboid(region);
}
int upperY = flatRegion.getMaximumY() + 1; // Increase by 1 to have trees generate above the selection 1 block
int lowerY = flatRegion.getMinimumY();
int affected = editSession.makeForest(flatRegion.asFlatRegion(), upperY, lowerY, density, new TreeGenerator(type));
player.print(affected + " trees created.");
}
}