Cleanup, make copy/paste flags consistent, add status messages.

Dieser Commit ist enthalten in:
wizjany 2019-04-05 19:40:25 -04:00 committet von Matthew Miller
Ursprung 17fba54305
Commit f0587354be
3 geänderte Dateien mit 72 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import com.google.common.collect.Lists;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
@ -52,6 +53,8 @@ import com.sk89q.worldedit.session.PasteBuilder;
import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.command.parametric.Optional;
import java.util.List;
/** /**
* Clipboard commands. * Clipboard commands.
*/ */
@ -76,8 +79,8 @@ 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" + " -b will also copy biomes\n" +
" -b will also copy biomes", " -m sets a source mask so that excluded blocks become air",
min = 0, min = 0,
max = 0 max = 0
) )
@ -97,17 +100,21 @@ public class ClipboardCommands {
Operations.completeLegacy(copy); Operations.completeLegacy(copy);
session.setClipboard(new ClipboardHolder(clipboard)); session.setClipboard(new ClipboardHolder(clipboard));
player.print(region.getArea() + " block(s) were copied."); List<String> messages = Lists.newArrayList();
copy.addStatusMessages(messages);
messages.forEach(player::print);
} }
@Command( @Command(
aliases = { "/cut" }, aliases = { "/cut" },
flags = "em", flags = "em",
usage = "[leave-id]", usage = "[leave-pattern]",
desc = "Cut the selection to the clipboard", desc = "Cut the selection to the clipboard",
help = "Copy the selection to the clipboard\n" + help = "Copy the selection to the clipboard\n" +
"The space will be filled with the leave pattern if specified, otherwise air." +
"Flags:\n" + "Flags:\n" +
" -e will also cut entities\n" + " -e will also cut entities\n" +
" -b will also copy biomes (source biomes unaffected)\n" +
" -m sets a source mask so that excluded blocks become air\n" + " -m sets a source mask so that excluded blocks become air\n" +
"WARNING: Cutting and pasting entities cannot yet be undone!", "WARNING: Cutting and pasting entities cannot yet be undone!",
max = 1 max = 1
@ -116,7 +123,7 @@ public class ClipboardCommands {
@Logging(REGION) @Logging(REGION)
public void cut(Player player, LocalSession session, EditSession editSession, public void cut(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities, @Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities,
@Switch('m') Mask mask) throws WorldEditException { @Switch('m') Mask mask, @Switch('b') boolean copyBiomes) throws WorldEditException {
BlockArrayClipboard clipboard = new BlockArrayClipboard(region); BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(session.getPlacementPosition(player)); clipboard.setOrigin(session.getPlacementPosition(player));
@ -124,20 +131,20 @@ public class ClipboardCommands {
copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setCopyingEntities(copyEntities); copy.setCopyingEntities(copyEntities);
copy.setRemovingEntities(true); copy.setRemovingEntities(true);
// doesn't really make sense to "cut" biomes? so copy anyway and let them choose when pasting copy.setCopyingBiomes(copyBiomes);
copy.setCopyingBiomes(true);
if (mask != null) { if (mask != null) {
copy.setSourceMask(mask); copy.setSourceMask(mask);
} }
Operations.completeLegacy(copy); Operations.completeLegacy(copy);
session.setClipboard(new ClipboardHolder(clipboard)); session.setClipboard(new ClipboardHolder(clipboard));
player.print(region.getArea() + " block(s) were cut."); List<String> messages = Lists.newArrayList();
copy.addStatusMessages(messages);
messages.forEach(player::print);
} }
@Command( @Command(
aliases = { "/paste" }, aliases = { "/paste" },
usage = "",
flags = "saobem:", flags = "saobem:",
desc = "Paste the clipboard's contents", desc = "Paste the clipboard's contents",
help = help =
@ -145,18 +152,17 @@ public class ClipboardCommands {
"Flags:\n" + "Flags:\n" +
" -a skips air blocks\n" + " -a skips air blocks\n" +
" -b pastes biomes if available\n" + " -b pastes biomes if available\n" +
" -e skips entities (default is don't skip!)\n" + " -e pastes entities if available\n" +
" -m [<mask>] skips matching blocks in the clipboard\n" + " -m [<mask>] skips matching blocks in the clipboard\n" +
" -o pastes at the original position\n" + " -o pastes at the original position\n" +
" -s selects the region after pasting\n", " -s selects the region after pasting\n",
min = 0,
max = 0 max = 0
) )
@CommandPermissions("worldedit.clipboard.paste") @CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void paste(Player player, LocalSession session, EditSession editSession, public void paste(Player player, LocalSession session, EditSession editSession,
@Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin, @Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin,
@Switch('s') boolean selectPasted, @Switch('e') boolean skipEntities, @Switch('s') boolean selectPasted, @Switch('e') boolean pasteEntities,
@Switch('b') boolean pasteBiomes, @Switch('m') Mask sourceMask) throws WorldEditException { @Switch('b') boolean pasteBiomes, @Switch('m') Mask sourceMask) throws WorldEditException {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
@ -169,7 +175,7 @@ public class ClipboardCommands {
.to(to) .to(to)
.ignoreAirBlocks(ignoreAirBlocks) .ignoreAirBlocks(ignoreAirBlocks)
.copyBiomes(pasteBiomes) .copyBiomes(pasteBiomes)
.copyEntities(!skipEntities); .copyEntities(pasteEntities);
if (sourceMask != null) { if (sourceMask != null) {
builder.maskSource(sourceMask); builder.maskSource(sourceMask);
} }
@ -187,6 +193,9 @@ public class ClipboardCommands {
} }
player.print("The clipboard has been pasted at " + to); player.print("The clipboard has been pasted at " + to);
List<String> messages = Lists.newArrayList();
operation.addStatusMessages(messages);
messages.forEach(player::print);
} }
@Command( @Command(

Datei anzeigen

@ -39,6 +39,7 @@ import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler; import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -57,6 +58,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -141,7 +143,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
} }
// Note: these aren't actually required by the spec, but we require them I guess?
int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue(); int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue();
Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
if (paletteObject.size() != paletteMax) { if (paletteObject.size() != paletteMax) {
@ -161,7 +162,8 @@ public class SpongeSchematicReader extends NBTSchematicReader {
try { try {
state = WorldEdit.getInstance().getBlockFactory().parseFromInput(palettePart, parserContext).toImmutableState(); state = WorldEdit.getInstance().getBlockFactory().parseFromInput(palettePart, parserContext).toImmutableState();
} catch (InputParseException e) { } catch (InputParseException e) {
throw new IOException("Invalid BlockState in schematic: " + palettePart + ". Are you missing a mod or using a schematic made in a newer version of Minecraft?"); throw new IOException("Invalid BlockState in palette: " + palettePart +
". Are you missing a mod or using a schematic made in a newer version of Minecraft?");
} }
palette.put(id, state); palette.put(id, state);
} }
@ -251,8 +253,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException { private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class); ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
// TODO for now, we just assume if biomedata is present, palette will be as well.
// atm the spec doesn't actually require palettes
IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class); IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class); CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
@ -262,10 +262,11 @@ public class SpongeSchematicReader extends NBTSchematicReader {
} }
Map<String, Tag> paletteEntries = paletteTag.getValue(); Map<String, Tag> paletteEntries = paletteTag.getValue();
for (Map.Entry<String, Tag> palettePart : paletteEntries.entrySet()) { for (Entry<String, Tag> palettePart : paletteEntries.entrySet()) {
BiomeType biome = BiomeTypes.get(palettePart.getKey()); BiomeType biome = BiomeTypes.get(palettePart.getKey());
if (biome == null) { if (biome == null) {
log.warn("Unknown biome type '" + palettePart.getKey() + "' in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?"); log.warn("Unknown biome type :" + palettePart.getKey() +
" in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?");
} }
Tag idTag = palettePart.getValue(); Tag idTag = palettePart.getValue();
if (!(idTag instanceof IntTag)) { if (!(idTag instanceof IntTag)) {
@ -281,6 +282,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int biomeJ = 0; int biomeJ = 0;
int bVal; int bVal;
int varIntLength; int varIntLength;
BlockVector2 min = clipboard.getMinimumPoint().toBlockVector2();
while (biomeJ < biomes.length) { while (biomeJ < biomes.length) {
bVal = 0; bVal = 0;
varIntLength = 0; varIntLength = 0;
@ -299,7 +301,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int z = biomeIndex / width; int z = biomeIndex / width;
int x = biomeIndex % width; int x = biomeIndex % width;
BiomeType type = palette.get(bVal); BiomeType type = palette.get(bVal);
clipboard.setBiome(clipboard.getMinimumPoint().toBlockVector2().add(x, z), type); clipboard.setBiome(min.add(x, z), type);
biomeIndex++; biomeIndex++;
} }
} }

Datei anzeigen

@ -41,7 +41,6 @@ import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.visitor.EntityVisitor; import com.sk89q.worldedit.function.visitor.EntityVisitor;
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor; import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.math.transform.Transform;
@ -72,8 +71,14 @@ public class ForwardExtentCopy implements Operation {
private RegionFunction sourceFunction = null; private RegionFunction sourceFunction = null;
private Transform transform = new Identity(); private Transform transform = new Identity();
private Transform currentTransform = null; private Transform currentTransform = null;
private RegionVisitor lastVisitor; private RegionVisitor lastVisitor;
private int affected; private FlatRegionVisitor lastBiomeVisitor;
private EntityVisitor lastEntityVisitor;
private int affectedBlocks;
private int affectedBiomeCols;
private int affectedEntities;
/** /**
* Create a new copy using the region's lowest minimum point as the * Create a new copy using the region's lowest minimum point as the
@ -257,15 +262,23 @@ public class ForwardExtentCopy implements Operation {
* @return the number of affected * @return the number of affected
*/ */
public int getAffected() { public int getAffected() {
return affected; return affectedBlocks + affectedBiomeCols + affectedEntities;
} }
@Override @Override
public Operation resume(RunContext run) throws WorldEditException { public Operation resume(RunContext run) throws WorldEditException {
if (lastVisitor != null) { if (lastVisitor != null) {
affected += lastVisitor.getAffected(); affectedBlocks += lastVisitor.getAffected();
lastVisitor = null; lastVisitor = null;
} }
if (lastBiomeVisitor != null) {
affectedBiomeCols += lastBiomeVisitor.getAffected();
lastBiomeVisitor = null;
}
if (lastEntityVisitor != null) {
affectedEntities += lastEntityVisitor.getAffected();
lastEntityVisitor = null;
}
if (repetitions > 0) { if (repetitions > 0) {
repetitions--; repetitions--;
@ -293,13 +306,11 @@ public class ForwardExtentCopy implements Operation {
ExtentBiomeCopy biomeCopy = new ExtentBiomeCopy(source, from.toBlockVector2(), ExtentBiomeCopy biomeCopy = new ExtentBiomeCopy(source, from.toBlockVector2(),
destination, to.toBlockVector2(), currentTransform); destination, to.toBlockVector2(), currentTransform);
Mask2D biomeMask = sourceMask.toMask2D(); Mask2D biomeMask = sourceMask.toMask2D();
if (biomeMask != null) { FlatRegionFunction biomeFunction = biomeMask == null ? biomeCopy
FlatRegionMaskingFilter filteredBiomeCopy = new FlatRegionMaskingFilter(biomeMask, biomeCopy); : new FlatRegionMaskingFilter(biomeMask, biomeCopy);
FlatRegionVisitor biomeVisitor = new FlatRegionVisitor(((FlatRegion) region), filteredBiomeCopy); FlatRegionVisitor biomeVisitor = new FlatRegionVisitor(((FlatRegion) region), biomeFunction);
ops.add(biomeVisitor); ops.add(biomeVisitor);
} else { lastBiomeVisitor = biomeVisitor;
ops.add(new FlatRegionVisitor(((FlatRegion) region), biomeCopy));
}
} }
if (copyingEntities) { if (copyingEntities) {
@ -312,6 +323,7 @@ public class ForwardExtentCopy implements Operation {
}); });
EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
ops.add(entityVisitor); ops.add(entityVisitor);
lastEntityVisitor = entityVisitor;
} }
return new DelegateOperation(this, new OperationQueue(ops)); return new DelegateOperation(this, new OperationQueue(ops));
@ -326,6 +338,24 @@ public class ForwardExtentCopy implements Operation {
@Override @Override
public void addStatusMessages(List<String> messages) { public void addStatusMessages(List<String> messages) {
StringBuilder msg = new StringBuilder();
msg.append(affectedBlocks).append(" block(s)");
if (affectedBiomeCols > 0) {
if (affectedEntities > 0) {
msg.append(", ");
} else {
msg.append(" and ");
}
msg.append(affectedBiomeCols).append(" biome(s)");
}
if (affectedEntities > 0) {
if (affectedBiomeCols > 0) {
msg.append(",");
}
msg.append(" and ").append(affectedEntities).append(" entities(s)");
}
msg.append(" affected.");
messages.add(msg.toString());
} }
} }