Add -f flag to //count to allow fuzzy inputs.

Also re-implement //distr -c. And remove outdated help text on //copy.
Dieser Commit ist enthalten in:
wizjany 2019-03-25 22:38:51 -04:00
Ursprung 692ba6fda3
Commit 8eccdc7444
2 geänderte Dateien mit 15 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -75,8 +75,7 @@ public class ClipboardCommands {
help = "Copy the selection to the clipboard\n" + help = "Copy the selection to the clipboard\n" +
"Flags:\n" + "Flags:\n" +
" -e will also copy entities\n" + " -e will also copy entities\n" +
" -m sets a source mask so that excluded blocks become air\n" + " -m sets a source mask so that excluded blocks become air",
"WARNING: Pasting entities cannot yet be undone!",
min = 0, min = 0,
max = 0 max = 0
) )

Datei anzeigen

@ -36,6 +36,9 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -625,6 +628,7 @@ public class SelectionCommands {
@Command( @Command(
aliases = { "/count" }, aliases = { "/count" },
usage = "<block>", usage = "<block>",
flags = "f",
desc = "Counts the number of a certain type of block", desc = "Counts the number of a certain type of block",
min = 1, min = 1,
max = 1 max = 1
@ -638,6 +642,7 @@ public class SelectionCommands {
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
context.setSession(session); context.setSession(session);
context.setRestricted(false); context.setRestricted(false);
context.setPreferringWildcard(args.hasFlag('f'));
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context); Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context);
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks); int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
@ -659,16 +664,17 @@ public class SelectionCommands {
@CommandPermissions("worldedit.analysis.distr") @CommandPermissions("worldedit.analysis.distr")
public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException { public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException {
int size;
boolean separateStates = args.hasFlag('d'); boolean separateStates = args.hasFlag('d');
List<Countable<BlockState>> distribution; List<Countable<BlockState>> distribution;
if (args.hasFlag('c')) { if (args.hasFlag('c')) {
// TODO: Update for new clipboard Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing
throw new CommandException("Needs to be re-written again"); BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count);
Operations.completeBlindly(visitor);
distribution = count.getDistribution();
} else { } else {
distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()), separateStates); distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()), separateStates);
size = session.getSelection(player.getWorld()).getArea();
} }
if (distribution.isEmpty()) { // *Should* always be false if (distribution.isEmpty()) { // *Should* always be false
@ -676,19 +682,21 @@ public class SelectionCommands {
return; return;
} }
// note: doing things like region.getArea is inaccurate for non-cuboids.
int size = distribution.stream().mapToInt(Countable::getAmount).sum();
player.print("# total blocks: " + size); player.print("# total blocks: " + size);
for (Countable<BlockState> c : distribution) { for (Countable<BlockState> c : distribution) {
String name = c.getID().getBlockType().getName(); String name = c.getID().getBlockType().getName();
String str; String str;
if (separateStates) { if (separateStates) {
str = String.format("%-7s (%.3f%%) %s #%s", str = String.format("%-7s (%.3f%%) %s (%s)",
String.valueOf(c.getAmount()), String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100, c.getAmount() / (double) size * 100,
name, name,
c.getID().getAsString()); c.getID().getAsString());
} else { } else {
str = String.format("%-7s (%.3f%%) %s #%s", str = String.format("%-7s (%.3f%%) %s (%s)",
String.valueOf(c.getAmount()), String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100, c.getAmount() / (double) size * 100,
name, name,