Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 10:30:04 +01:00
Added //size -c and //distr -c command options. Describes clipboard.
Dieser Commit ist enthalten in:
Ursprung
14aa9a524d
Commit
b352f7321f
@ -22,12 +22,17 @@ package com.sk89q.worldedit;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.blocks.*;
|
import com.sk89q.worldedit.blocks.*;
|
||||||
import com.sk89q.worldedit.data.*;
|
import com.sk89q.worldedit.data.*;
|
||||||
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.schematic.SchematicFormat;
|
import com.sk89q.worldedit.schematic.SchematicFormat;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The clipboard remembers the state of a cuboid region.
|
* The clipboard remembers the state of a cuboid region.
|
||||||
@ -421,4 +426,39 @@ public class CuboidClipboard {
|
|||||||
this.relativePosition = entity.getPosition().getPosition().subtract(getOrigin());
|
this.relativePosition = entity.getPosition().getPosition().subtract(getOrigin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the block distribution inside a clipboard.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Countable<Integer>> getBlockDistribution() {
|
||||||
|
List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
|
||||||
|
Map<Integer, Countable<Integer>> map = new HashMap<Integer, Countable<Integer>>();
|
||||||
|
|
||||||
|
int maxX = getWidth();
|
||||||
|
int maxY = getHeight();
|
||||||
|
int maxZ = getLength();
|
||||||
|
|
||||||
|
for (int x = 0; x < maxX; ++x) {
|
||||||
|
for (int y = 0; y < maxY; ++y) {
|
||||||
|
for (int z = 0; z < maxZ; ++z) {
|
||||||
|
|
||||||
|
int id = data[x][y][z].getId();
|
||||||
|
|
||||||
|
if (map.containsKey(id)) {
|
||||||
|
map.get(id).increment();
|
||||||
|
} else {
|
||||||
|
Countable<Integer> c = new Countable<Integer>(id, 1);
|
||||||
|
map.put(id, c);
|
||||||
|
distribution.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(distribution);
|
||||||
|
// Collections.reverse(distribution);
|
||||||
|
|
||||||
|
return distribution;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package com.sk89q.worldedit.commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
import com.sk89q.minecraft.util.commands.CommandAlias;
|
import com.sk89q.minecraft.util.commands.CommandAlias;
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
@ -496,31 +495,49 @@ public class SelectionCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/size" },
|
aliases = { "/size" },
|
||||||
|
flags = "c",
|
||||||
usage = "",
|
usage = "",
|
||||||
desc = "Get information about the selection",
|
desc = "Get information about the selection",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 0
|
max = 0
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.selection.size")
|
@CommandPermissions("worldedit.selection.size")
|
||||||
public void size(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession)
|
public void size(CommandContext args, LocalSession session, LocalPlayer player,
|
||||||
throws WorldEditException {
|
EditSession editSession) throws WorldEditException {
|
||||||
|
|
||||||
|
if (args.hasFlag('c')) {
|
||||||
|
CuboidClipboard clipboard = session.getClipboard();
|
||||||
|
Vector size = clipboard.getSize();
|
||||||
|
Vector offset = clipboard.getOffset();
|
||||||
|
|
||||||
|
player.print("Size: " + size);
|
||||||
|
player.print("Offset: " + offset);
|
||||||
|
player.print("Cuboid distance: " + size.distance( new Vector(1, 1, 1)));
|
||||||
|
player.print("# of blocks: "
|
||||||
|
+ (int) (size.getX() * size.getY() * size.getZ()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Region region = session.getSelection(player.getWorld());
|
Region region = session.getSelection(player.getWorld());
|
||||||
Vector size = region.getMaximumPoint()
|
Vector size = region.getMaximumPoint()
|
||||||
.subtract(region.getMinimumPoint())
|
.subtract(region.getMinimumPoint())
|
||||||
.add(1, 1, 1);
|
.add(1, 1, 1);
|
||||||
|
|
||||||
player.print("Type: " + session.getRegionSelector(player.getWorld()).getTypeName());
|
|
||||||
|
|
||||||
for (String line : session.getRegionSelector(player.getWorld()).getInformationLines()) {
|
player.print("Type: " + session.getRegionSelector(player.getWorld())
|
||||||
|
.getTypeName());
|
||||||
|
|
||||||
|
for (String line : session.getRegionSelector(player.getWorld())
|
||||||
|
.getInformationLines()) {
|
||||||
player.print(line);
|
player.print(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.print("Size: " + size);
|
player.print("Size: " + size);
|
||||||
player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint()));
|
player.print("Cuboid distance: " + region.getMaximumPoint()
|
||||||
player.print("# of blocks: " + region.getArea());
|
.distance(region.getMinimumPoint()));
|
||||||
|
player.print("# of blocks: " + region.getArea());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "/count" },
|
aliases = { "/count" },
|
||||||
usage = "<block>",
|
usage = "<block>",
|
||||||
@ -544,7 +561,7 @@ public class SelectionCommands {
|
|||||||
desc = "Get the distribution of blocks in the selection",
|
desc = "Get the distribution of blocks in the selection",
|
||||||
help =
|
help =
|
||||||
"Gets the distribution of blocks in the selection.\n" +
|
"Gets the distribution of blocks in the selection.\n" +
|
||||||
"The -c flag makes it print to the console as well.",
|
"The -c flag gets the distribution of your clipboard.",
|
||||||
flags = "c",
|
flags = "c",
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 0
|
max = 0
|
||||||
@ -553,35 +570,33 @@ public class SelectionCommands {
|
|||||||
public void distr(CommandContext args, LocalSession session, LocalPlayer player,
|
public void distr(CommandContext args, LocalSession session, LocalPlayer player,
|
||||||
EditSession editSession) throws WorldEditException {
|
EditSession editSession) throws WorldEditException {
|
||||||
|
|
||||||
List<Countable<Integer>> distribution =
|
List<Countable<Integer>> distribution;
|
||||||
editSession.getBlockDistribution(session.getSelection(player.getWorld()));
|
int size;
|
||||||
|
|
||||||
Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
if (args.hasFlag('c')) {
|
||||||
|
CuboidClipboard clip = session.getClipboard();
|
||||||
if (distribution.size() > 0) { // *Should* always be true
|
distribution = clip.getBlockDistribution();
|
||||||
int size = session.getSelection(player.getWorld()).getArea();
|
size = clip.getHeight() * clip.getLength() * clip.getWidth();
|
||||||
|
|
||||||
player.print("# total blocks: " + size);
|
|
||||||
|
|
||||||
if (args.hasFlag('c')) {
|
|
||||||
logger.info("Block distribution (req. by " + player.getName() + "):");
|
|
||||||
logger.info("# total blocks: " + size);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Countable<Integer> c : distribution) {
|
|
||||||
BlockType block = BlockType.fromID(c.getID());
|
|
||||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
|
||||||
String.valueOf(c.getAmount()),
|
|
||||||
c.getAmount() / (double) size * 100,
|
|
||||||
block == null ? "Unknown" : block.getName(), c.getID());
|
|
||||||
player.print(str);
|
|
||||||
|
|
||||||
if (args.hasFlag('c')) {
|
|
||||||
logger.info(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
distribution = editSession
|
||||||
|
.getBlockDistribution(session.getSelection(player.getWorld()));
|
||||||
|
size = session.getSelection(player.getWorld()).getArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distribution.size() <= 0) { // *Should* always be true
|
||||||
player.printError("No blocks counted.");
|
player.printError("No blocks counted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.print("# total blocks: " + size);
|
||||||
|
|
||||||
|
for (Countable<Integer> c : distribution) {
|
||||||
|
BlockType block = BlockType.fromID(c.getID());
|
||||||
|
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||||
|
String.valueOf(c.getAmount()),
|
||||||
|
c.getAmount() / (double) size * 100,
|
||||||
|
block == null ? "Unknown" : block.getName(), c.getID());
|
||||||
|
player.print(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren