Added pasting at origin and saving origin to the .schematic.

This commit is contained in:
sk89q 2010-11-06 22:23:43 -07:00
parent 162fd11d40
commit 7585cccccb
2 changed files with 50 additions and 8 deletions

View File

@ -155,7 +155,7 @@ public void copy(EditSession editSession) {
for (int y = 0; y < size.getBlockY(); y++) { for (int y = 0; y < size.getBlockY(); y++) {
for (int z = 0; z < size.getBlockZ(); z++) { for (int z = 0; z < size.getBlockZ(); z++) {
data[x][y][z] = data[x][y][z] =
editSession.getBlock(new Vector(x, y, z).add(origin)); editSession.getBlock(new Vector(x, y, z).add(getOrigin()));
} }
} }
} }
@ -224,6 +224,9 @@ public void saveSchematic(String path) throws IOException, DataException {
schematic.put("Length", new ShortTag("Length", (short)length)); schematic.put("Length", new ShortTag("Length", (short)length));
schematic.put("Height", new ShortTag("Height", (short)height)); schematic.put("Height", new ShortTag("Height", (short)height));
schematic.put("Materials", new StringTag("Materials", "Alpha")); schematic.put("Materials", new StringTag("Materials", "Alpha"));
schematic.put("WEOriginX", new IntTag("WEOriginX", getOrigin().getBlockX()));
schematic.put("WEOriginY", new IntTag("WEOriginY", getOrigin().getBlockY()));
schematic.put("WEOriginZ", new IntTag("WEOriginZ", getOrigin().getBlockZ()));
// Copy // Copy
byte[] blocks = new byte[width * height * length]; byte[] blocks = new byte[width * height * length];
@ -285,6 +288,8 @@ public static CuboidClipboard loadSchematic(String path)
FileInputStream stream = new FileInputStream(path); FileInputStream stream = new FileInputStream(path);
NBTInputStream nbtStream = new NBTInputStream(stream); NBTInputStream nbtStream = new NBTInputStream(stream);
Vector origin = new Vector();
// Schematic tag // Schematic tag
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag(); CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
if (!schematicTag.getName().equals("Schematic")) { if (!schematicTag.getName().equals("Schematic")) {
@ -302,6 +307,15 @@ public static CuboidClipboard loadSchematic(String path)
short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue(); short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue();
short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue(); short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue();
try {
int originX = (Integer)getChildTag(schematic, "WEOriginX", IntTag.class).getValue();
int originY = (Integer)getChildTag(schematic, "WEOriginY", IntTag.class).getValue();
int originZ = (Integer)getChildTag(schematic, "WEOriginZ", IntTag.class).getValue();
origin = new Vector(originX, originY, originZ);
} catch (DataException e) {
// No origin data
}
// Check type of Schematic // Check type of Schematic
String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue(); String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue();
if (!materials.equals("Alpha")) { if (!materials.equals("Alpha")) {
@ -352,6 +366,7 @@ public static CuboidClipboard loadSchematic(String path)
Vector size = new Vector(width, height, length); Vector size = new Vector(width, height, length);
CuboidClipboard clipboard = new CuboidClipboard(size); CuboidClipboard clipboard = new CuboidClipboard(size);
clipboard.setOrigin(origin);
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
@ -405,4 +420,18 @@ private static Tag getChildTag(Map<String,Tag> items, String key, Class expected
} }
return tag; return tag;
} }
/**
* @return the origin
*/
public Vector getOrigin() {
return origin;
}
/**
* @param origin the origin to set
*/
public void setOrigin(Vector origin) {
this.origin = origin;
}
} }

View File

@ -140,8 +140,8 @@ public WorldEditListener() {
commands.put("/removenear", "<ID> <Size> - Remove blocks near you"); commands.put("/removenear", "<ID> <Size> - Remove blocks near you");
commands.put("//copy", "Copies the currently selected region"); commands.put("//copy", "Copies the currently selected region");
commands.put("//cut", "Cuts the currently selected region"); commands.put("//cut", "Cuts the currently selected region");
commands.put("//paste", "Pastes the clipboard"); commands.put("//paste", "<AtOrigin?> - Pastes the clipboard");
commands.put("//pasteair", "Pastes the clipboard (with air)"); commands.put("//pasteair", "<AtOrigin?> - Pastes the clipboard (with air)");
commands.put("//move", "<Count> <Dir> <LeaveID> - Move the selection"); commands.put("//move", "<Count> <Dir> <LeaveID> - Move the selection");
commands.put("//moveair", "<Count> <Dir> <LeaveID> - Move the selection (with air)"); commands.put("//moveair", "<Count> <Dir> <LeaveID> - Move the selection (with air)");
commands.put("//stack", "<Count> <Dir> - Stacks the selection"); commands.put("//stack", "<Count> <Dir> - Stacks the selection");
@ -599,11 +599,24 @@ public boolean performCommand(WorldEditPlayer player,
// Paste // Paste
} else if (split[0].equalsIgnoreCase("//pasteair") || } else if (split[0].equalsIgnoreCase("//pasteair") ||
split[0].equalsIgnoreCase("//paste")) { split[0].equalsIgnoreCase("//paste")) {
checkArgs(split, 0, 1, split[0]);
boolean atOrigin = split.length > 1
? (split[1].equalsIgnoreCase("true")
|| split[1].equalsIgnoreCase("yes"))
: false;
if (atOrigin) {
Vector pos = session.getClipboard().getOrigin();
session.getClipboard().place(editSession, pos,
split[0].equalsIgnoreCase("//paste"));
player.findFreePosition();
player.print("Pasted to copy origin. Undo with //undo");
} else {
Vector pos = session.getPlacementPosition(player); Vector pos = session.getPlacementPosition(player);
session.getClipboard().paste(editSession, pos, session.getClipboard().paste(editSession, pos,
split[0].equalsIgnoreCase("//paste")); split[0].equalsIgnoreCase("//paste"));
player.findFreePosition(); player.findFreePosition();
player.print("Pasted. Undo with //undo"); player.print("Pasted relative to you. Undo with //undo");
}
return true; return true;