2010-10-02 23:11:44 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2010-10-02 23:11:44 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2010-10-02 23:11:44 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2010-10-02 23:11:44 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2010-10-02 23:11:44 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2010-10-02 23:11:44 +00:00
|
|
|
|
2011-01-02 05:50:31 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2012-03-28 18:05:52 +00:00
|
|
|
|
2011-12-25 23:36:23 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2012-03-30 04:16:59 +00:00
|
|
|
import java.util.ArrayList;
|
2012-11-07 20:36:35 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2012-03-30 04:16:59 +00:00
|
|
|
import java.util.List;
|
2012-11-07 20:36:35 +00:00
|
|
|
import java.util.Map;
|
2012-03-30 04:16:59 +00:00
|
|
|
|
2013-01-19 14:31:00 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2013-08-24 08:44:17 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.world.DataException;
|
2013-08-24 08:44:17 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2013-01-19 14:31:00 +00:00
|
|
|
import com.sk89q.worldedit.schematic.SchematicFormat;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.util.Countable;
|
2013-01-19 14:31:00 +00:00
|
|
|
|
2010-10-02 23:11:44 +00:00
|
|
|
/**
|
2010-10-13 17:08:53 +00:00
|
|
|
* The clipboard remembers the state of a cuboid region.
|
2010-10-02 23:11:44 +00:00
|
|
|
*
|
2010-10-13 17:08:53 +00:00
|
|
|
* @author sk89q
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2010-10-11 08:22:47 +00:00
|
|
|
public class CuboidClipboard {
|
2010-11-27 06:15:21 +00:00
|
|
|
/**
|
|
|
|
* Flip direction.
|
|
|
|
*/
|
|
|
|
public enum FlipDirection {
|
|
|
|
NORTH_SOUTH,
|
|
|
|
WEST_EAST,
|
|
|
|
UP_DOWN
|
|
|
|
}
|
|
|
|
|
2010-10-13 23:49:35 +00:00
|
|
|
private BaseBlock[][][] data;
|
2010-10-13 17:08:53 +00:00
|
|
|
private Vector offset;
|
2010-10-13 01:03:56 +00:00
|
|
|
private Vector origin;
|
2010-10-13 17:08:53 +00:00
|
|
|
private Vector size;
|
2012-03-30 04:16:59 +00:00
|
|
|
private List<CopiedEntity> entities = new ArrayList<CopiedEntity>();
|
2010-10-02 23:11:44 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-13 17:08:53 +00:00
|
|
|
* Constructs the clipboard.
|
|
|
|
*
|
|
|
|
* @param size
|
|
|
|
*/
|
|
|
|
public CuboidClipboard(Vector size) {
|
|
|
|
this.size = size;
|
2010-10-13 23:49:35 +00:00
|
|
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2010-10-13 17:08:53 +00:00
|
|
|
origin = new Vector();
|
|
|
|
offset = new Vector();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the clipboard.
|
|
|
|
*
|
|
|
|
* @param size
|
|
|
|
* @param origin
|
|
|
|
*/
|
|
|
|
public CuboidClipboard(Vector size, Vector origin) {
|
|
|
|
this.size = size;
|
2010-10-13 23:49:35 +00:00
|
|
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2010-10-13 17:08:53 +00:00
|
|
|
this.origin = origin;
|
|
|
|
offset = new Vector();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the clipboard.
|
|
|
|
*
|
|
|
|
* @param size
|
2010-10-02 23:11:44 +00:00
|
|
|
* @param origin
|
2011-09-24 19:32:03 +00:00
|
|
|
* @param offset
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2010-10-13 17:08:53 +00:00
|
|
|
public CuboidClipboard(Vector size, Vector origin, Vector offset) {
|
|
|
|
this.size = size;
|
2010-10-13 23:49:35 +00:00
|
|
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2010-10-02 23:11:44 +00:00
|
|
|
this.origin = origin;
|
2010-10-13 17:08:53 +00:00
|
|
|
this.offset = offset;
|
2010-10-02 23:11:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-03 17:44:52 +00:00
|
|
|
/**
|
|
|
|
* Get the width (X-direction) of the clipboard.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return width
|
2010-10-03 17:44:52 +00:00
|
|
|
*/
|
|
|
|
public int getWidth() {
|
2010-10-13 17:08:53 +00:00
|
|
|
return size.getBlockX();
|
2010-10-03 17:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the length (Z-direction) of the clipboard.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return length
|
2010-10-03 17:44:52 +00:00
|
|
|
*/
|
|
|
|
public int getLength() {
|
2010-10-13 17:08:53 +00:00
|
|
|
return size.getBlockZ();
|
2010-10-03 17:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the height (Y-direction) of the clipboard.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return height
|
2010-10-03 17:44:52 +00:00
|
|
|
*/
|
|
|
|
public int getHeight() {
|
2010-10-13 17:08:53 +00:00
|
|
|
return size.getBlockY();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
|
2010-11-27 06:15:21 +00:00
|
|
|
*
|
2010-10-13 17:08:53 +00:00
|
|
|
* @param angle in degrees
|
|
|
|
*/
|
|
|
|
public void rotate2D(int angle) {
|
|
|
|
angle = angle % 360;
|
|
|
|
if (angle % 90 != 0) { // Can only rotate 90 degrees at the moment
|
|
|
|
return;
|
|
|
|
}
|
2013-08-24 08:44:17 +00:00
|
|
|
final boolean reverse = angle < 0;
|
|
|
|
final int numRotations = Math.abs((int) Math.floor(angle / 90.0));
|
2010-10-13 17:08:53 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
final int width = getWidth();
|
|
|
|
final int length = getLength();
|
|
|
|
final int height = getHeight();
|
|
|
|
final Vector sizeRotated = size.transform2D(angle, 0, 0, 0, 0);
|
|
|
|
final int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
|
|
|
|
final int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;
|
2010-10-13 17:08:53 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock newData[][][] = new BaseBlock
|
2010-10-17 22:17:24 +00:00
|
|
|
[Math.abs(sizeRotated.getBlockX())]
|
|
|
|
[Math.abs(sizeRotated.getBlockY())]
|
|
|
|
[Math.abs(sizeRotated.getBlockZ())];
|
2010-10-13 17:08:53 +00:00
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
for (int z = 0; z < length; ++z) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final Vector2D v = new Vector2D(x, z).transform2D(angle, 0, 0, shiftX, shiftZ);
|
|
|
|
final int newX = v.getBlockX();
|
|
|
|
final int newZ = v.getBlockZ();
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int y = 0; y < height; ++y) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block = data[x][y][z];
|
|
|
|
newData[newX][y][newZ] = block;
|
|
|
|
|
|
|
|
if (block == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
if (reverse) {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int i = 0; i < numRotations; ++i) {
|
2011-01-30 07:10:12 +00:00
|
|
|
block.rotate90Reverse();
|
|
|
|
}
|
|
|
|
} else {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int i = 0; i < numRotations; ++i) {
|
2011-01-30 07:10:12 +00:00
|
|
|
block.rotate90();
|
|
|
|
}
|
|
|
|
}
|
2010-10-13 17:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data = newData;
|
2010-10-17 22:17:24 +00:00
|
|
|
size = new Vector(Math.abs(sizeRotated.getBlockX()),
|
|
|
|
Math.abs(sizeRotated.getBlockY()),
|
|
|
|
Math.abs(sizeRotated.getBlockZ()));
|
2010-10-13 17:08:53 +00:00
|
|
|
offset = offset.transform2D(angle, 0, 0, 0, 0)
|
2011-08-26 02:57:05 +00:00
|
|
|
.subtract(shiftX, 0, shiftZ);
|
2010-10-03 17:44:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
/**
|
|
|
|
* Flip the clipboard.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-09-03 16:54:20 +00:00
|
|
|
* @param dir direction to flip
|
|
|
|
*/
|
|
|
|
public void flip(FlipDirection dir) {
|
|
|
|
flip(dir, false);
|
|
|
|
}
|
|
|
|
|
2010-11-27 06:15:21 +00:00
|
|
|
/**
|
|
|
|
* Flip the clipboard.
|
|
|
|
*
|
2011-09-03 16:54:20 +00:00
|
|
|
* @param dir direction to flip
|
|
|
|
* @param aroundPlayer flip the offset around the player
|
2010-11-27 06:15:21 +00:00
|
|
|
*/
|
2011-08-26 02:57:05 +00:00
|
|
|
public void flip(FlipDirection dir, boolean aroundPlayer) {
|
2011-08-28 10:28:31 +00:00
|
|
|
final int width = getWidth();
|
|
|
|
final int length = getLength();
|
|
|
|
final int height = getHeight();
|
2010-11-27 06:15:21 +00:00
|
|
|
|
2011-08-26 02:57:05 +00:00
|
|
|
switch (dir) {
|
2013-01-14 05:53:38 +00:00
|
|
|
case WEST_EAST:
|
2011-08-28 10:28:31 +00:00
|
|
|
final int wid = (int) Math.ceil(width / 2.0f);
|
2011-08-26 02:57:05 +00:00
|
|
|
for (int xs = 0; xs < wid; ++xs) {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int z = 0; z < length; ++z) {
|
|
|
|
for (int y = 0; y < height; ++y) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block1 = data[xs][y][z];
|
|
|
|
if (block1 != null) {
|
|
|
|
block1.flip(dir);
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:58:01 +00:00
|
|
|
// Skip the center plane
|
|
|
|
if (xs == width - xs - 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block2 = data[width - xs - 1][y][z];
|
|
|
|
if (block2 != null) {
|
|
|
|
block2.flip(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
data[xs][y][z] = block2;
|
|
|
|
data[width - xs - 1][y][z] = block1;
|
2010-11-27 06:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
if (aroundPlayer) {
|
2011-08-26 02:57:05 +00:00
|
|
|
offset = offset.setX(1 - offset.getX() - width);
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2013-01-14 05:53:38 +00:00
|
|
|
case NORTH_SOUTH:
|
2011-08-28 10:28:31 +00:00
|
|
|
final int len = (int) Math.ceil(length / 2.0f);
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int zs = 0; zs < len; ++zs) {
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
for (int y = 0; y < height; ++y) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block1 = data[x][y][zs];
|
|
|
|
if (block1 != null) {
|
|
|
|
block1.flip(dir);
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:58:01 +00:00
|
|
|
// Skip the center plane
|
|
|
|
if (zs == length - zs - 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block2 = data[x][y][length - zs - 1];
|
|
|
|
if (block2 != null) {
|
|
|
|
block2.flip(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
data[x][y][zs] = block2;
|
|
|
|
data[x][y][length - zs - 1] = block1;
|
2010-11-27 06:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
if (aroundPlayer) {
|
2011-08-26 02:57:05 +00:00
|
|
|
offset = offset.setZ(1 - offset.getZ() - length);
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UP_DOWN:
|
2011-08-28 10:28:31 +00:00
|
|
|
final int hei = (int) Math.ceil(height / 2.0f);
|
2011-08-26 02:57:05 +00:00
|
|
|
for (int ys = 0; ys < hei; ++ys) {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
for (int z = 0; z < length; ++z) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block1 = data[x][ys][z];
|
|
|
|
if (block1 != null) {
|
|
|
|
block1.flip(dir);
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:58:01 +00:00
|
|
|
// Skip the center plane
|
|
|
|
if (ys == height - ys - 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block2 = data[x][height - ys - 1][z];
|
|
|
|
if (block2 != null) {
|
|
|
|
block2.flip(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
data[x][ys][z] = block2;
|
|
|
|
data[x][height - ys - 1][z] = block1;
|
2010-11-27 06:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
if (aroundPlayer) {
|
2011-08-26 02:57:05 +00:00
|
|
|
offset = offset.setY(1 - offset.getY() - height);
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-08-26 02:57:05 +00:00
|
|
|
|
|
|
|
break;
|
2010-11-27 06:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-02 23:11:44 +00:00
|
|
|
/**
|
2013-08-24 08:44:17 +00:00
|
|
|
* Copies blocks to the clipboard.
|
2010-10-02 23:11:44 +00:00
|
|
|
*
|
2013-08-24 08:44:17 +00:00
|
|
|
* @param editSession The EditSession from which to take the blocks
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
|
|
|
public void copy(EditSession editSession) {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int x = 0; x < size.getBlockX(); ++x) {
|
|
|
|
for (int y = 0; y < size.getBlockY(); ++y) {
|
|
|
|
for (int z = 0; z < size.getBlockZ(); ++z) {
|
2010-10-13 17:08:53 +00:00
|
|
|
data[x][y][z] =
|
2011-11-23 01:29:48 +00:00
|
|
|
editSession.getBlock(new Vector(x, y, z).add(getOrigin()));
|
2010-10-02 23:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
/**
|
|
|
|
* Copies blocks to the clipboard.
|
|
|
|
*
|
|
|
|
* @param editSession The EditSession from which to take the blocks
|
|
|
|
* @param region A region that further constrains which blocks to take.
|
|
|
|
*/
|
|
|
|
public void copy(EditSession editSession, Region region) {
|
|
|
|
for (int x = 0; x < size.getBlockX(); ++x) {
|
|
|
|
for (int y = 0; y < size.getBlockY(); ++y) {
|
|
|
|
for (int z = 0; z < size.getBlockZ(); ++z) {
|
|
|
|
final Vector pt = new Vector(x, y, z).add(getOrigin());
|
|
|
|
if (region.contains(pt)) {
|
|
|
|
data[x][y][z] = editSession.getBlock(pt);
|
|
|
|
} else {
|
|
|
|
data[x][y][z] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 04:16:59 +00:00
|
|
|
public void paste(EditSession editSession, Vector newOrigin, boolean noAir)
|
|
|
|
throws MaxChangedBlocksException {
|
|
|
|
paste(editSession, newOrigin, noAir, false);
|
|
|
|
}
|
|
|
|
|
2010-10-02 23:11:44 +00:00
|
|
|
/**
|
|
|
|
* Paste from the clipboard.
|
|
|
|
*
|
|
|
|
* @param editSession
|
2010-10-11 15:56:19 +00:00
|
|
|
* @param newOrigin Position to paste it from
|
2010-10-02 23:11:44 +00:00
|
|
|
* @param noAir True to not paste air
|
2010-10-04 23:39:35 +00:00
|
|
|
* @throws MaxChangedBlocksException
|
2010-10-02 23:11:44 +00:00
|
|
|
*/
|
2012-03-30 04:16:59 +00:00
|
|
|
public void paste(EditSession editSession, Vector newOrigin, boolean noAir, boolean entities)
|
2010-10-05 20:46:31 +00:00
|
|
|
throws MaxChangedBlocksException {
|
2010-10-13 17:08:53 +00:00
|
|
|
place(editSession, newOrigin.add(offset), noAir);
|
2012-03-30 04:16:59 +00:00
|
|
|
if (entities) {
|
|
|
|
pasteEntities(newOrigin.add(offset));
|
|
|
|
}
|
2010-10-05 20:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Places the blocks in a position from the minimum corner.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-05 20:46:31 +00:00
|
|
|
* @param editSession
|
2010-10-13 17:08:53 +00:00
|
|
|
* @param pos
|
2010-10-05 20:46:31 +00:00
|
|
|
* @param noAir
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-11-23 01:29:48 +00:00
|
|
|
public void place(EditSession editSession, Vector pos, boolean noAir) throws MaxChangedBlocksException {
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int x = 0; x < size.getBlockX(); ++x) {
|
|
|
|
for (int y = 0; y < size.getBlockY(); ++y) {
|
|
|
|
for (int z = 0; z < size.getBlockZ(); ++z) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block = data[x][y][z];
|
|
|
|
if (block == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noAir && block.isAir()) {
|
2010-10-13 23:49:35 +00:00
|
|
|
continue;
|
2011-11-23 01:29:48 +00:00
|
|
|
}
|
2010-10-17 22:17:24 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
editSession.setBlock(new Vector(x, y, z).add(pos), block);
|
2010-10-02 23:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2012-03-30 04:16:59 +00:00
|
|
|
public LocalEntity[] pasteEntities(Vector pos) {
|
|
|
|
LocalEntity[] entities = new LocalEntity[this.entities.size()];
|
|
|
|
for (int i = 0; i < this.entities.size(); ++i) {
|
|
|
|
CopiedEntity copied = this.entities.get(i);
|
|
|
|
if (copied.entity.spawn(copied.entity.getPosition().setPosition(copied.relativePosition.add(pos)))) {
|
|
|
|
entities[i] = copied.entity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entities;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void storeEntity(LocalEntity entity) {
|
|
|
|
this.entities.add(new CopiedEntity(entity));
|
|
|
|
}
|
|
|
|
|
2011-01-30 09:01:11 +00:00
|
|
|
/**
|
2013-08-24 08:44:17 +00:00
|
|
|
* Get one point in the copy.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-08-24 08:44:17 +00:00
|
|
|
* @param The point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin.
|
|
|
|
* @return air, if this block was outside the (non-cuboid) selection while copying
|
|
|
|
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
|
|
|
* @deprecated Use {@link #getBlock(Vector)} instead
|
2011-01-30 09:01:11 +00:00
|
|
|
*/
|
|
|
|
public BaseBlock getPoint(Vector pos) throws ArrayIndexOutOfBoundsException {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block = getBlock(pos);
|
|
|
|
if (block == null) {
|
|
|
|
return new BaseBlock(BlockID.AIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get one point in the copy.
|
|
|
|
*
|
|
|
|
* @param The point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin.
|
|
|
|
* @return null, if this block was outside the (non-cuboid) selection while copying
|
|
|
|
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
|
|
|
*/
|
|
|
|
public BaseBlock getBlock(Vector pos) throws ArrayIndexOutOfBoundsException {
|
2011-01-30 09:01:11 +00:00
|
|
|
return data[pos.getBlockX()][pos.getBlockY()][pos.getBlockZ()];
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2012-03-28 18:05:52 +00:00
|
|
|
/**
|
2013-08-24 08:44:17 +00:00
|
|
|
* Set one point in the copy. Pass null to remove the block.
|
2012-03-28 18:05:52 +00:00
|
|
|
*
|
2013-08-24 08:44:17 +00:00
|
|
|
* @param The point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin.
|
|
|
|
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
2012-03-28 18:05:52 +00:00
|
|
|
*/
|
|
|
|
public void setBlock(Vector pt, BaseBlock block) {
|
|
|
|
data[pt.getBlockX()][pt.getBlockY()][pt.getBlockZ()] = block;
|
|
|
|
}
|
|
|
|
|
2011-01-30 08:34:13 +00:00
|
|
|
/**
|
|
|
|
* Get the size of the copy.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-30 08:34:13 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Vector getSize() {
|
|
|
|
return size;
|
|
|
|
}
|
2010-10-03 17:44:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the clipboard data to a .schematic-format file.
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
* @throws IOException
|
2010-10-20 09:12:16 +00:00
|
|
|
* @throws DataException
|
2010-10-03 17:44:52 +00:00
|
|
|
*/
|
2012-03-28 18:05:52 +00:00
|
|
|
@Deprecated
|
2011-01-27 09:51:34 +00:00
|
|
|
public void saveSchematic(File path) throws IOException, DataException {
|
2012-03-28 18:05:52 +00:00
|
|
|
SchematicFormat.MCEDIT.save(this, path);
|
2010-10-03 17:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a .schematic file into a clipboard.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-03 17:44:52 +00:00
|
|
|
* @param path
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return clipboard
|
2010-10-20 09:12:16 +00:00
|
|
|
* @throws DataException
|
2010-10-03 17:44:52 +00:00
|
|
|
* @throws IOException
|
|
|
|
*/
|
2012-03-28 18:05:52 +00:00
|
|
|
@Deprecated
|
2011-01-27 09:51:34 +00:00
|
|
|
public static CuboidClipboard loadSchematic(File path)
|
2010-10-20 09:12:16 +00:00
|
|
|
throws DataException, IOException {
|
2012-03-28 18:05:52 +00:00
|
|
|
return SchematicFormat.MCEDIT.load(path);
|
2010-10-03 17:44:52 +00:00
|
|
|
}
|
2010-11-07 05:23:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the origin
|
|
|
|
*/
|
|
|
|
public Vector getOrigin() {
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param origin the origin to set
|
|
|
|
*/
|
|
|
|
public void setOrigin(Vector origin) {
|
|
|
|
this.origin = origin;
|
|
|
|
}
|
2010-11-17 06:34:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the offset
|
|
|
|
*/
|
|
|
|
public Vector getOffset() {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-24 19:32:03 +00:00
|
|
|
* @param offset
|
2010-11-17 06:34:18 +00:00
|
|
|
*/
|
|
|
|
public void setOffset(Vector offset) {
|
|
|
|
this.offset = offset;
|
|
|
|
}
|
2012-03-30 04:16:59 +00:00
|
|
|
|
|
|
|
private class CopiedEntity {
|
|
|
|
private final LocalEntity entity;
|
|
|
|
private final Vector relativePosition;
|
|
|
|
|
|
|
|
public CopiedEntity(LocalEntity entity) {
|
|
|
|
this.entity = entity;
|
|
|
|
this.relativePosition = entity.getPosition().getPosition().subtract(getOrigin());
|
|
|
|
}
|
|
|
|
}
|
2012-11-07 20:36:35 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block = data[x][y][z];
|
|
|
|
if (block == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-07 20:36:35 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
int id = block.getId();
|
2012-11-07 20:36:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-01-19 14:31:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the block distribution inside a clipboard with data values.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// TODO reduce code duplication
|
|
|
|
public List<Countable<BaseBlock>> getBlockDistributionWithData() {
|
|
|
|
List<Countable<BaseBlock>> distribution = new ArrayList<Countable<BaseBlock>>();
|
|
|
|
Map<BaseBlock, Countable<BaseBlock>> map = new HashMap<BaseBlock, Countable<BaseBlock>>();
|
|
|
|
|
|
|
|
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) {
|
2013-08-24 08:44:17 +00:00
|
|
|
final BaseBlock block = data[x][y][z];
|
|
|
|
if (block == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-19 14:31:00 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
// Strip the block from metadata that is not part of our key
|
|
|
|
final BaseBlock bareBlock = new BaseBlock(block.getId(), block.getData());
|
2013-01-19 14:31:00 +00:00
|
|
|
|
2013-08-24 08:44:17 +00:00
|
|
|
if (map.containsKey(bareBlock)) {
|
|
|
|
map.get(bareBlock).increment();
|
2013-01-19 14:31:00 +00:00
|
|
|
} else {
|
2013-08-24 08:44:17 +00:00
|
|
|
Countable<BaseBlock> c = new Countable<BaseBlock>(bareBlock, 1);
|
|
|
|
map.put(bareBlock, c);
|
2013-01-19 14:31:00 +00:00
|
|
|
distribution.add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(distribution);
|
|
|
|
// Collections.reverse(distribution);
|
|
|
|
|
|
|
|
return distribution;
|
|
|
|
}
|
2010-10-02 23:11:44 +00:00
|
|
|
}
|