geforkt von Mirrors/FastAsyncWorldEdit
Changed everything to use BaseBlock, which supports block data and soon some tile entity data.
Dieser Commit ist enthalten in:
Ursprung
23b24b3615
Commit
d1eca7c429
@ -30,7 +30,7 @@ import com.sk89q.worldedit.*;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class CuboidClipboard {
|
public class CuboidClipboard {
|
||||||
private int[][][] data;
|
private BaseBlock[][][] data;
|
||||||
private Vector offset;
|
private Vector offset;
|
||||||
private Vector origin;
|
private Vector origin;
|
||||||
private Vector size;
|
private Vector size;
|
||||||
@ -42,7 +42,7 @@ public class CuboidClipboard {
|
|||||||
*/
|
*/
|
||||||
public CuboidClipboard(Vector size) {
|
public CuboidClipboard(Vector size) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
data = new int[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||||
origin = new Vector();
|
origin = new Vector();
|
||||||
offset = new Vector();
|
offset = new Vector();
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public class CuboidClipboard {
|
|||||||
*/
|
*/
|
||||||
public CuboidClipboard(Vector size, Vector origin) {
|
public CuboidClipboard(Vector size, Vector origin) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
data = new int[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
offset = new Vector();
|
offset = new Vector();
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class CuboidClipboard {
|
|||||||
*/
|
*/
|
||||||
public CuboidClipboard(Vector size, Vector origin, Vector offset) {
|
public CuboidClipboard(Vector size, Vector origin, Vector offset) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
data = new int[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ public class CuboidClipboard {
|
|||||||
int shiftX = sizeRotated.getX() < 0 ? newWidth - 1 : 0;
|
int shiftX = sizeRotated.getX() < 0 ? newWidth - 1 : 0;
|
||||||
int shiftZ = sizeRotated.getZ() < 0 ? newLength - 1: 0;
|
int shiftZ = sizeRotated.getZ() < 0 ? newLength - 1: 0;
|
||||||
|
|
||||||
int newData[][][] = new int[newWidth][getHeight()][newLength];
|
BaseBlock newData[][][] = new BaseBlock[newWidth][getHeight()][newLength];
|
||||||
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int z = 0; z < length; z++) {
|
for (int z = 0; z < length; z++) {
|
||||||
@ -182,7 +182,8 @@ public class CuboidClipboard {
|
|||||||
for (int x = 0; x < size.getBlockX(); x++) {
|
for (int x = 0; x < size.getBlockX(); x++) {
|
||||||
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++) {
|
||||||
if (noAir && data[x][y][z] == 0) continue;
|
if (noAir && data[x][y][z].isAir())
|
||||||
|
continue;
|
||||||
|
|
||||||
editSession.setBlock(new Vector(x, y, z).add(pos),
|
editSession.setBlock(new Vector(x, y, z).add(pos),
|
||||||
data[x][y][z]);
|
data[x][y][z]);
|
||||||
@ -221,19 +222,18 @@ public class CuboidClipboard {
|
|||||||
|
|
||||||
// Copy blocks
|
// Copy blocks
|
||||||
byte[] blocks = new byte[width * height * length];
|
byte[] blocks = new byte[width * height * length];
|
||||||
|
byte[] blockData = new byte[width * height * length];
|
||||||
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++) {
|
||||||
for (int z = 0; z < length; z++) {
|
for (int z = 0; z < length; z++) {
|
||||||
int index = y * width * length + z * width + x;
|
int index = y * width * length + z * width + x;
|
||||||
blocks[index] = (byte)data[x][y][z];
|
blocks[index] = (byte)data[x][y][z].getType();
|
||||||
|
blockData[index] = (byte)data[x][y][z].getData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||||
|
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||||
// Current data is not supported
|
|
||||||
byte[] data = new byte[width * height * length];
|
|
||||||
schematic.put("Data", new ByteArrayTag("Data", data));
|
|
||||||
|
|
||||||
// These are not stored either
|
// These are not stored either
|
||||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
||||||
@ -275,6 +275,7 @@ public class CuboidClipboard {
|
|||||||
throw new SchematicException("Schematic file is not an Alpha schematic");
|
throw new SchematicException("Schematic file is not an Alpha schematic");
|
||||||
}
|
}
|
||||||
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
|
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
|
||||||
|
byte[] blockData = (byte[])getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
|
||||||
|
|
||||||
Vector size = new Vector(width, height, length);
|
Vector size = new Vector(width, height, length);
|
||||||
|
|
||||||
@ -284,7 +285,8 @@ public class CuboidClipboard {
|
|||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
for (int z = 0; z < length; z++) {
|
for (int z = 0; z < length; z++) {
|
||||||
int index = y * width * length + z * width + x;
|
int index = y * width * length + z * width + x;
|
||||||
clipboard.data[x][y][z] = blocks[index];
|
clipboard.data[x][y][z] =
|
||||||
|
new BaseBlock(blocks[index], blockData[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,15 @@ public class EditSession {
|
|||||||
/**
|
/**
|
||||||
* Stores the original blocks before modification.
|
* Stores the original blocks before modification.
|
||||||
*/
|
*/
|
||||||
private HashMap<BlockVector,Integer> original = new HashMap<BlockVector,Integer>();
|
private Map<BlockVector,BaseBlock> original = new HashMap<BlockVector,BaseBlock>();
|
||||||
/**
|
/**
|
||||||
* Stores the current blocks.
|
* Stores the current blocks.
|
||||||
*/
|
*/
|
||||||
private HashMap<BlockVector,Integer> current = new HashMap<BlockVector,Integer>();
|
private Map<BlockVector,BaseBlock> current = new HashMap<BlockVector,BaseBlock>();
|
||||||
/**
|
/**
|
||||||
* Queue.
|
* Queue.
|
||||||
*/
|
*/
|
||||||
private HashMap<BlockVector,Integer> queue = new HashMap<BlockVector,Integer>();
|
private Map<BlockVector,BaseBlock> queue = new HashMap<BlockVector,BaseBlock>();
|
||||||
/**
|
/**
|
||||||
* The maximum number of blocks to change at a time. If this number is
|
* The maximum number of blocks to change at a time. If this number is
|
||||||
* exceeded, a MaxChangedBlocksException exception will be
|
* exceeded, a MaxChangedBlocksException exception will be
|
||||||
@ -98,25 +98,12 @@ public class EditSession {
|
|||||||
* @param blockType
|
* @param blockType
|
||||||
* @return Whether the block changed
|
* @return Whether the block changed
|
||||||
*/
|
*/
|
||||||
private boolean rawSetBlock(Vector pt, int blockType) {
|
private boolean rawSetBlock(Vector pt, BaseBlock block) {
|
||||||
return etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(),
|
boolean result = etc.getMCServer().e.d(pt.getBlockX(), pt.getBlockY(),
|
||||||
pt.getBlockZ(), blockType);
|
pt.getBlockZ(), block.getType());
|
||||||
}
|
etc.getMCServer().e.c(pt.getBlockX(), pt.getBlockY(),
|
||||||
|
pt.getBlockZ(), block.getData());
|
||||||
/**
|
return result;
|
||||||
* Sets the block at position x, y, z with a block type. If queue mode is
|
|
||||||
* enabled, blocks may not be actually set in world until flushQueue()
|
|
||||||
* is called.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param blockType
|
|
||||||
* @return Whether the block changed -- not entirely dependable
|
|
||||||
*/
|
|
||||||
public boolean setBlock(int x, int y, int z, int blockType)
|
|
||||||
throws MaxChangedBlocksException {
|
|
||||||
return setBlock(new Vector(x, y, z), blockType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,10 +112,10 @@ public class EditSession {
|
|||||||
* is called.
|
* is called.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return Whether the block changed -- not entirely dependable
|
* @return Whether the block changed -- not entirely dependable
|
||||||
*/
|
*/
|
||||||
public boolean setBlock(Vector pt, int blockType)
|
public boolean setBlock(Vector pt, BaseBlock block)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
BlockVector blockPt = pt.toBlockVector();
|
BlockVector blockPt = pt.toBlockVector();
|
||||||
|
|
||||||
@ -140,25 +127,25 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current.put(pt.toBlockVector(), blockType);
|
current.put(pt.toBlockVector(), block);
|
||||||
|
|
||||||
return smartSetBlock(pt, blockType);
|
return smartSetBlock(pt, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a block only if there's no block already there.
|
* Set a block only if there's no block already there.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return if block was changed
|
* @return if block was changed
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public boolean setBlockIfAir(Vector pt, int blockType)
|
public boolean setBlockIfAir(Vector pt, BaseBlock block)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
if (getBlock(pt) != 0) {
|
if (!getBlock(pt).isAir()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return setBlock(pt, blockType);
|
return setBlock(pt, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,22 +153,22 @@ public class EditSession {
|
|||||||
* Actually set the block. Will use queue.
|
* Actually set the block. Will use queue.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean smartSetBlock(Vector pt, int blockType) {
|
private boolean smartSetBlock(Vector pt, BaseBlock block) {
|
||||||
if (queued) {
|
if (queued) {
|
||||||
if (blockType != 0 && queuedBlocks.contains(blockType)
|
if (!block.isAir() && queuedBlocks.contains(block.getType())
|
||||||
&& rawGetBlock(pt.add(0, -1, 0)) == 0) {
|
&& rawGetBlock(pt.add(0, -1, 0)).isAir()) {
|
||||||
queue.put(pt.toBlockVector(), blockType);
|
queue.put(pt.toBlockVector(), block);
|
||||||
return getBlock(pt) != blockType;
|
return getBlock(pt).getType() != block.getType();
|
||||||
} else if (blockType == 0
|
} else if (block.isAir()
|
||||||
&& queuedBlocks.contains(rawGetBlock(pt.add(0, 1, 0)))) {
|
&& queuedBlocks.contains(rawGetBlock(pt.add(0, 1, 0)).getType())) {
|
||||||
rawSetBlock(pt.add(0, 1, 0), 0); // Prevent items from being dropped
|
rawSetBlock(pt.add(0, 1, 0), new BaseBlock(0)); // Prevent items from being dropped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawSetBlock(pt, blockType);
|
return rawSetBlock(pt, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,7 +177,7 @@ public class EditSession {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return Block type
|
* @return Block type
|
||||||
*/
|
*/
|
||||||
public int getBlock(Vector pt) {
|
public BaseBlock getBlock(Vector pt) {
|
||||||
// In the case of the queue, the block may have not actually been
|
// In the case of the queue, the block may have not actually been
|
||||||
// changed yet
|
// changed yet
|
||||||
if (queued) {
|
if (queued) {
|
||||||
@ -200,38 +187,31 @@ public class EditSession {
|
|||||||
return current.get(blockPt);
|
return current.get(blockPt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
return new BaseBlock(
|
||||||
}
|
(short)etc.getMCServer().e.a(pt.getBlockX(),
|
||||||
|
pt.getBlockY(),
|
||||||
/**
|
pt.getBlockZ()));
|
||||||
* Gets the block type at a position x, y, z.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @return Block type
|
|
||||||
*/
|
|
||||||
public int getBlock(int x, int y, int z) {
|
|
||||||
return getBlock(new Vector(x, y, z));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the block type at a position x, y, z.
|
* Gets the block type at a position x, y, z.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
* @return Block type
|
* @return BaseBlock
|
||||||
*/
|
*/
|
||||||
public int rawGetBlock(Vector pt) {
|
public BaseBlock rawGetBlock(Vector pt) {
|
||||||
return etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
int type = etc.getMCServer().e.a(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
int data = etc.getMCServer().e.b(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
return new BaseBlock(type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores all blocks to their initial state.
|
* Restores all blocks to their initial state.
|
||||||
*/
|
*/
|
||||||
public void undo() {
|
public void undo() {
|
||||||
for (Map.Entry<BlockVector,Integer> entry : original.entrySet()) {
|
for (Map.Entry<BlockVector,BaseBlock> entry : original.entrySet()) {
|
||||||
BlockVector pt = (BlockVector)entry.getKey();
|
BlockVector pt = (BlockVector)entry.getKey();
|
||||||
smartSetBlock(pt, (int)entry.getValue());
|
smartSetBlock(pt, (BaseBlock)entry.getValue());
|
||||||
}
|
}
|
||||||
flushQueue();
|
flushQueue();
|
||||||
}
|
}
|
||||||
@ -240,9 +220,9 @@ public class EditSession {
|
|||||||
* Sets to new state.
|
* Sets to new state.
|
||||||
*/
|
*/
|
||||||
public void redo() {
|
public void redo() {
|
||||||
for (Map.Entry<BlockVector,Integer> entry : current.entrySet()) {
|
for (Map.Entry<BlockVector,BaseBlock> entry : current.entrySet()) {
|
||||||
BlockVector pt = (BlockVector)entry.getKey();
|
BlockVector pt = (BlockVector)entry.getKey();
|
||||||
smartSetBlock(pt, (int)entry.getValue());
|
smartSetBlock(pt, (BaseBlock)entry.getValue());
|
||||||
}
|
}
|
||||||
flushQueue();
|
flushQueue();
|
||||||
}
|
}
|
||||||
@ -309,9 +289,9 @@ public class EditSession {
|
|||||||
public void flushQueue() {
|
public void flushQueue() {
|
||||||
if (!queued) { return; }
|
if (!queued) { return; }
|
||||||
|
|
||||||
for (Map.Entry<BlockVector,Integer> entry : queue.entrySet()) {
|
for (Map.Entry<BlockVector,BaseBlock> entry : queue.entrySet()) {
|
||||||
BlockVector pt = (BlockVector)entry.getKey();
|
BlockVector pt = (BlockVector)entry.getKey();
|
||||||
rawSetBlock(pt, (int)entry.getValue());
|
rawSetBlock(pt, (BaseBlock)entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,12 +301,12 @@ public class EditSession {
|
|||||||
* @param x
|
* @param x
|
||||||
* @param z
|
* @param z
|
||||||
* @param origin
|
* @param origin
|
||||||
* @param blockType
|
* @param block
|
||||||
* @param radius
|
* @param radius
|
||||||
* @param depth
|
* @param depth
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
*/
|
*/
|
||||||
public int fillXZ(int x, int z, Vector origin, int blockType, int radius, int depth)
|
public int fillXZ(int x, int z, Vector origin, BaseBlock block, int radius, int depth)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
double dist = Math.sqrt(Math.pow(origin.getX() - x, 2) + Math.pow(origin.getZ() - z, 2));
|
double dist = Math.sqrt(Math.pow(origin.getX() - x, 2) + Math.pow(origin.getZ() - z, 2));
|
||||||
int minY = origin.getBlockY() - depth + 1;
|
int minY = origin.getBlockY() - depth + 1;
|
||||||
@ -336,16 +316,16 @@ public class EditSession {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getBlock(new Vector(x, origin.getY(), z)) == 0) {
|
if (getBlock(new Vector(x, origin.getY(), z)).isAir()) {
|
||||||
affected = fillY(x, (int)origin.getY(), z, blockType, minY);
|
affected = fillY(x, (int)origin.getY(), z, block, minY);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
affected += fillXZ(x + 1, z, origin, blockType, radius, depth);
|
affected += fillXZ(x + 1, z, origin, block, radius, depth);
|
||||||
affected += fillXZ(x - 1, z, origin, blockType, radius, depth);
|
affected += fillXZ(x - 1, z, origin, block, radius, depth);
|
||||||
affected += fillXZ(x, z + 1, origin, blockType, radius, depth);
|
affected += fillXZ(x, z + 1, origin, block, radius, depth);
|
||||||
affected += fillXZ(x, z - 1, origin, blockType, radius, depth);
|
affected += fillXZ(x, z - 1, origin, block, radius, depth);
|
||||||
|
|
||||||
return affected;
|
return affected;
|
||||||
}
|
}
|
||||||
@ -356,20 +336,20 @@ public class EditSession {
|
|||||||
* @param x
|
* @param x
|
||||||
* @param cy
|
* @param cy
|
||||||
* @param z
|
* @param z
|
||||||
* @param blockType
|
* @param block
|
||||||
* @param minY
|
* @param minY
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private int fillY(int x, int cy, int z, int blockType, int minY)
|
private int fillY(int x, int cy, int z, BaseBlock block, int minY)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
for (int y = cy; y >= minY; y--) {
|
for (int y = cy; y >= minY; y--) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
|
|
||||||
if (getBlock(pt) == 0) {
|
if (getBlock(pt).isAir()) {
|
||||||
setBlock(pt, blockType);
|
setBlock(pt, block);
|
||||||
affected++;
|
affected++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -398,8 +378,8 @@ public class EditSession {
|
|||||||
for (int y = (int)pos.getY(); y <= maxY; y++) {
|
for (int y = (int)pos.getY(); y <= maxY; y++) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
|
|
||||||
if (getBlock(pt) != 0) {
|
if (!getBlock(pt).isAir()) {
|
||||||
setBlock(pt, 0);
|
setBlock(pt, new BaseBlock(0));
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -428,8 +408,8 @@ public class EditSession {
|
|||||||
for (int y = (int)pos.getY(); y >= minY; y--) {
|
for (int y = (int)pos.getY(); y >= minY; y--) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
|
|
||||||
if (getBlock(pt) != 0) {
|
if (!getBlock(pt).isAir()) {
|
||||||
setBlock(pt, 0);
|
setBlock(pt, new BaseBlock(0));
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,11 +423,11 @@ public class EditSession {
|
|||||||
* Sets all the blocks inside a region to a certain block type.
|
* Sets all the blocks inside a region to a certain block type.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int setBlocks(Region region, int blockType)
|
public int setBlocks(Region region, BaseBlock block)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
@ -461,7 +441,7 @@ public class EditSession {
|
|||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
|
|
||||||
if (setBlock(pt, blockType)) {
|
if (setBlock(pt, block)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,7 +449,7 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Vector pt : region) {
|
for (Vector pt : region) {
|
||||||
if (setBlock(pt, blockType)) {
|
if (setBlock(pt, block)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +467,7 @@ public class EditSession {
|
|||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int replaceBlocks(Region region, int fromBlockType, int toBlockType)
|
public int replaceBlocks(Region region, int fromBlockType, BaseBlock toBlock)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
@ -500,11 +480,11 @@ public class EditSession {
|
|||||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
int curBlockType = getBlock(pt);
|
int curBlockType = getBlock(pt).getType();
|
||||||
|
|
||||||
if (fromBlockType == -1 && curBlockType != 0 ||
|
if (fromBlockType == -1 && curBlockType != 0 ||
|
||||||
curBlockType == fromBlockType) {
|
curBlockType == fromBlockType) {
|
||||||
if (setBlock(pt, toBlockType)) {
|
if (setBlock(pt, toBlock)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -513,11 +493,11 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Vector pt : region) {
|
for (Vector pt : region) {
|
||||||
int curBlockType = getBlock(pt);
|
int curBlockType = getBlock(pt).getType();
|
||||||
|
|
||||||
if (fromBlockType == -1 && curBlockType != 0 ||
|
if (fromBlockType == -1 && curBlockType != 0 ||
|
||||||
curBlockType == fromBlockType) {
|
curBlockType == fromBlockType) {
|
||||||
if (setBlock(pt, toBlockType)) {
|
if (setBlock(pt, toBlock)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -531,11 +511,11 @@ public class EditSession {
|
|||||||
* Make faces of the region (as if it was a cuboid if it's not).
|
* Make faces of the region (as if it was a cuboid if it's not).
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int makeCuboidFaces(Region region, int blockType)
|
public int makeCuboidFaces(Region region, BaseBlock block)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
@ -544,23 +524,23 @@ public class EditSession {
|
|||||||
|
|
||||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||||
if (setBlock(x, y, min.getBlockZ(), blockType)) { affected++; }
|
if (setBlock(new Vector(x, y, min.getBlockZ()), block)) { affected++; }
|
||||||
if (setBlock(x, y, max.getBlockZ(), blockType)) { affected++; }
|
if (setBlock(new Vector(x, y, max.getBlockZ()), block)) { affected++; }
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
if (setBlock(min.getBlockX(), y, z, blockType)) { affected++; }
|
if (setBlock(new Vector(min.getBlockX(), y, z), block)) { affected++; }
|
||||||
if (setBlock(max.getBlockX(), y, z, blockType)) { affected++; }
|
if (setBlock(new Vector(max.getBlockX(), y, z), block)) { affected++; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||||
if (setBlock(x, min.getBlockY(), z, blockType)) { affected++; }
|
if (setBlock(new Vector(x, min.getBlockY(), z), block)) { affected++; }
|
||||||
if (setBlock(x, max.getBlockY(), z, blockType)) { affected++; }
|
if (setBlock(new Vector(x, max.getBlockY(), z), block)) { affected++; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,11 +551,11 @@ public class EditSession {
|
|||||||
* Overlays a layer of blocks over a cuboid area.
|
* Overlays a layer of blocks over a cuboid area.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region
|
||||||
* @param blockType
|
* @param block
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int overlayCuboidBlocks(Region region, int blockType)
|
public int overlayCuboidBlocks(Region region, BaseBlock block)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
Vector min = region.getMinimumPoint();
|
Vector min = region.getMinimumPoint();
|
||||||
Vector max = region.getMaximumPoint();
|
Vector max = region.getMaximumPoint();
|
||||||
@ -588,8 +568,11 @@ public class EditSession {
|
|||||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
for (int y = upperY; y >= lowerY; y--) {
|
for (int y = upperY; y >= lowerY; y--) {
|
||||||
if (y + 1 <= 127 && getBlock(x, y, z) != 0 && getBlock(x, y + 1, z) == 0) {
|
Vector above = new Vector(x, y + 1, z);
|
||||||
if (setBlock(x, y + 1, z, blockType)) {
|
|
||||||
|
if (y + 1 <= 127 && !getBlock(new Vector(x, y, z)).isAir()
|
||||||
|
&& getBlock(above).isAir()) {
|
||||||
|
if (setBlock(above, block)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -625,12 +608,16 @@ public class EditSession {
|
|||||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||||
int blockType = getBlock(new Vector(x, y, z));
|
BaseBlock block = getBlock(new Vector(x, y, z));
|
||||||
|
|
||||||
if (blockType != 0 || copyAir) {
|
if (!block.isAir() || copyAir) {
|
||||||
for (int i = 1; i <= count; i++) {
|
for (int i = 1; i <= count; i++) {
|
||||||
if (setBlock(x + xs * dir.getBlockX() * i, y + ys * dir.getBlockY() * i,
|
Vector pos = new Vector(
|
||||||
z + zs * dir.getBlockZ() * i, blockType)) {
|
x + xs * dir.getBlockX() * i,
|
||||||
|
y + ys * dir.getBlockY() * i,
|
||||||
|
z + zs * dir.getBlockZ() * i);
|
||||||
|
|
||||||
|
if (setBlock(pos, block)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -667,7 +654,7 @@ public class EditSession {
|
|||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
BlockVector cur = queue.pop();
|
BlockVector cur = queue.pop();
|
||||||
|
|
||||||
int type = getBlock(cur);
|
int type = getBlock(cur).getType();
|
||||||
|
|
||||||
// Check block type
|
// Check block type
|
||||||
if (type != 8 && type != 9 && type != 10 && type != 11) {
|
if (type != 8 && type != 9 && type != 10 && type != 11) {
|
||||||
@ -698,7 +685,7 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setBlock(cur, 0)) {
|
if (setBlock(cur, new BaseBlock(0))) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,14 +698,14 @@ public class EditSession {
|
|||||||
* Set a block by chance.
|
* Set a block by chance.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param pos
|
||||||
* @param type
|
* @param block
|
||||||
* @param c 0-1 chance
|
* @param c 0-1 chance
|
||||||
* @return whether a block was changed
|
* @return whether a block was changed
|
||||||
*/
|
*/
|
||||||
private boolean setChanceBlockIfAir(Vector pos, int type, double c)
|
private boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
if (Math.random() <= c) {
|
if (Math.random() <= c) {
|
||||||
return setBlockIfAir(pos, type);
|
return setBlockIfAir(pos, block);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -733,9 +720,12 @@ public class EditSession {
|
|||||||
int trunkHeight = (int)Math.floor(Math.random() * 2) + 3;
|
int trunkHeight = (int)Math.floor(Math.random() * 2) + 3;
|
||||||
int height = (int)Math.floor(Math.random() * 5) + 8;
|
int height = (int)Math.floor(Math.random() * 5) + 8;
|
||||||
|
|
||||||
|
BaseBlock logBlock = new BaseBlock(17);
|
||||||
|
BaseBlock leavesBlock = new BaseBlock(18);
|
||||||
|
|
||||||
// Create trunk
|
// Create trunk
|
||||||
for (int i = 0; i < trunkHeight; i++) {
|
for (int i = 0; i < trunkHeight; i++) {
|
||||||
if (!setBlockIfAir(basePos.add(0, i, 0), 17)) {
|
if (!setBlockIfAir(basePos.add(0, i, 0), logBlock)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -747,38 +737,38 @@ public class EditSession {
|
|||||||
|
|
||||||
// Create tree + leaves
|
// Create tree + leaves
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
setBlockIfAir(basePos.add(0, i, 0), 17);
|
setBlockIfAir(basePos.add(0, i, 0), logBlock);
|
||||||
|
|
||||||
// Less leaves at these levels
|
// Less leaves at these levels
|
||||||
double chance = ((i == 0 || i == height - 1) ? 0.6 : 1);
|
double chance = ((i == 0 || i == height - 1) ? 0.6 : 1);
|
||||||
|
|
||||||
// Inner leaves
|
// Inner leaves
|
||||||
setChanceBlockIfAir(basePos.add(-1, i, 0), 18, chance);
|
setChanceBlockIfAir(basePos.add(-1, i, 0), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(1, i, 0), 18, chance);
|
setChanceBlockIfAir(basePos.add(1, i, 0), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(0, i, -1), 18, chance);
|
setChanceBlockIfAir(basePos.add(0, i, -1), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(0, i, 1), 18, chance);
|
setChanceBlockIfAir(basePos.add(0, i, 1), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(1, i, 1), 18, chance);
|
setChanceBlockIfAir(basePos.add(1, i, 1), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(-1, i, 1), 18, chance);
|
setChanceBlockIfAir(basePos.add(-1, i, 1), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(1, i, -1), 18, chance);
|
setChanceBlockIfAir(basePos.add(1, i, -1), leavesBlock, chance);
|
||||||
setChanceBlockIfAir(basePos.add(-1, i, -1), 18, chance);
|
setChanceBlockIfAir(basePos.add(-1, i, -1), leavesBlock, chance);
|
||||||
|
|
||||||
if (!(i == 0 || i == height - 1)) {
|
if (!(i == 0 || i == height - 1)) {
|
||||||
for (int j = -2; j <= 2; j++) {
|
for (int j = -2; j <= 2; j++) {
|
||||||
setChanceBlockIfAir(basePos.add(-2, i, j), 18, 0.6);
|
setChanceBlockIfAir(basePos.add(-2, i, j), leavesBlock, 0.6);
|
||||||
}
|
}
|
||||||
for (int j = -2; j <= 2; j++) {
|
for (int j = -2; j <= 2; j++) {
|
||||||
setChanceBlockIfAir(basePos.add(2, i, j), 18, 0.6);
|
setChanceBlockIfAir(basePos.add(2, i, j), leavesBlock, 0.6);
|
||||||
}
|
}
|
||||||
for (int j = -2; j <= 2; j++) {
|
for (int j = -2; j <= 2; j++) {
|
||||||
setChanceBlockIfAir(basePos.add(j, i, -2), 18, 0.6);
|
setChanceBlockIfAir(basePos.add(j, i, -2), leavesBlock, 0.6);
|
||||||
}
|
}
|
||||||
for (int j = -2; j <= 2; j++) {
|
for (int j = -2; j <= 2; j++) {
|
||||||
setChanceBlockIfAir(basePos.add(j, i, 2), 18, 0.6);
|
setChanceBlockIfAir(basePos.add(j, i, 2), leavesBlock, 0.6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlockIfAir(basePos.add(0, height, 0), 18);
|
setBlockIfAir(basePos.add(0, height, 0), leavesBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -795,13 +785,14 @@ public class EditSession {
|
|||||||
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) {
|
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) {
|
||||||
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) {
|
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) {
|
||||||
// Don't want to be in the ground
|
// Don't want to be in the ground
|
||||||
if (getBlock(new Vector(x, basePos.getBlockY(), z)) != 0) { continue; }
|
if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir())
|
||||||
|
continue;
|
||||||
// The gods don't want a tree here
|
// The gods don't want a tree here
|
||||||
if (Math.random() < 0.95) { continue; }
|
if (Math.random() < 0.95) { continue; }
|
||||||
|
|
||||||
for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) {
|
for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) {
|
||||||
// Check if we hit the ground
|
// Check if we hit the ground
|
||||||
int t = getBlock(new Vector(x, y, z));
|
int t = getBlock(new Vector(x, y, z)).getType();
|
||||||
if (t == 2 || t == 3) {
|
if (t == 2 || t == 3) {
|
||||||
makePineTree(new Vector(x, y + 1, z));
|
makePineTree(new Vector(x, y + 1, z));
|
||||||
affected++;
|
affected++;
|
||||||
|
@ -127,7 +127,7 @@ public class WorldEdit {
|
|||||||
* @throws UnknownItemException
|
* @throws UnknownItemException
|
||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public int getItem(String id, boolean allAllowed)
|
public BaseBlock getBlock(String id, boolean allAllowed)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws UnknownItemException, DisallowedItemException {
|
||||||
int foundID;
|
int foundID;
|
||||||
|
|
||||||
@ -143,23 +143,23 @@ public class WorldEdit {
|
|||||||
|
|
||||||
// Check if the item is allowed
|
// Check if the item is allowed
|
||||||
if (allAllowed || allowedBlocks.isEmpty() || allowedBlocks.contains(foundID)) {
|
if (allAllowed || allowedBlocks.isEmpty() || allowedBlocks.contains(foundID)) {
|
||||||
return foundID;
|
return new BaseBlock(foundID);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new DisallowedItemException();
|
throw new DisallowedItemException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item ID from an item name or an item ID number.
|
* Get a block.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
* @throws UnknownItemException
|
* @throws UnknownItemException
|
||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public int getItem(String id) throws UnknownItemException,
|
public BaseBlock getBlock(String id) throws UnknownItemException,
|
||||||
DisallowedItemException {
|
DisallowedItemException {
|
||||||
return getItem(id, false);
|
return getBlock(id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,13 +326,13 @@ public class WorldEdit {
|
|||||||
// Fill a hole
|
// Fill a hole
|
||||||
} else if (split[0].equalsIgnoreCase("/editfill")) {
|
} else if (split[0].equalsIgnoreCase("/editfill")) {
|
||||||
checkArgs(split, 2, 3, split[0]);
|
checkArgs(split, 2, 3, split[0]);
|
||||||
int blockType = getItem(split[1]);
|
BaseBlock block = getBlock(split[1]);
|
||||||
int radius = Math.max(1, Integer.parseInt(split[2]));
|
int radius = Math.max(1, Integer.parseInt(split[2]));
|
||||||
int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1;
|
int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1;
|
||||||
|
|
||||||
Vector pos = player.getBlockIn();
|
Vector pos = player.getBlockIn();
|
||||||
int affected = editSession.fillXZ((int)pos.getX(), (int)pos.getZ(),
|
int affected = editSession.fillXZ((int)pos.getX(), (int)pos.getZ(),
|
||||||
pos, blockType, radius, depth);
|
pos, block, radius, depth);
|
||||||
player.print(affected + " block(s) have been created.");
|
player.print(affected + " block(s) have been created.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -430,8 +430,8 @@ public class WorldEdit {
|
|||||||
// Replace all blocks in the region
|
// Replace all blocks in the region
|
||||||
} else if(split[0].equalsIgnoreCase("/editset")) {
|
} else if(split[0].equalsIgnoreCase("/editset")) {
|
||||||
checkArgs(split, 1, 1, split[0]);
|
checkArgs(split, 1, 1, split[0]);
|
||||||
int blockType = getItem(split[1]);
|
BaseBlock block = getBlock(split[1]);
|
||||||
int affected = editSession.setBlocks(session.getRegion(), blockType);
|
int affected = editSession.setBlocks(session.getRegion(), block);
|
||||||
player.print(affected + " block(s) have been changed.");
|
player.print(affected + " block(s) have been changed.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -439,8 +439,8 @@ public class WorldEdit {
|
|||||||
// Set the outline of a region
|
// Set the outline of a region
|
||||||
} else if(split[0].equalsIgnoreCase("/editoutline")) {
|
} else if(split[0].equalsIgnoreCase("/editoutline")) {
|
||||||
checkArgs(split, 1, 1, split[0]);
|
checkArgs(split, 1, 1, split[0]);
|
||||||
int blockType = getItem(split[1]);
|
BaseBlock block = getBlock(split[1]);
|
||||||
int affected = editSession.makeCuboidFaces(session.getRegion(), blockType);
|
int affected = editSession.makeCuboidFaces(session.getRegion(), block);
|
||||||
player.print(affected + " block(s) have been changed.");
|
player.print(affected + " block(s) have been changed.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -457,13 +457,14 @@ public class WorldEdit {
|
|||||||
// Replace all blocks in the region
|
// Replace all blocks in the region
|
||||||
} else if(split[0].equalsIgnoreCase("/editreplace")) {
|
} else if(split[0].equalsIgnoreCase("/editreplace")) {
|
||||||
checkArgs(split, 1, 2, split[0]);
|
checkArgs(split, 1, 2, split[0]);
|
||||||
int from, to;
|
int from;
|
||||||
|
BaseBlock to;
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
from = -1;
|
from = -1;
|
||||||
to = getItem(split[1]);
|
to = getBlock(split[1]);
|
||||||
} else {
|
} else {
|
||||||
from = getItem(split[1]);
|
from = getBlock(split[1]).getType();
|
||||||
to = getItem(split[2]);
|
to = getBlock(split[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int affected = editSession.replaceBlocks(session.getRegion(), from, to);
|
int affected = editSession.replaceBlocks(session.getRegion(), from, to);
|
||||||
@ -474,10 +475,10 @@ public class WorldEdit {
|
|||||||
// Lay blocks over an area
|
// Lay blocks over an area
|
||||||
} else if (split[0].equalsIgnoreCase("/editoverlay")) {
|
} else if (split[0].equalsIgnoreCase("/editoverlay")) {
|
||||||
checkArgs(split, 1, 1, split[0]);
|
checkArgs(split, 1, 1, split[0]);
|
||||||
int blockType = getItem(split[1]);
|
BaseBlock block = getBlock(split[1]);
|
||||||
|
|
||||||
Region region = session.getRegion();
|
Region region = session.getRegion();
|
||||||
int affected = editSession.overlayCuboidBlocks(region, blockType);
|
int affected = editSession.overlayCuboidBlocks(region, block);
|
||||||
player.print(affected + " block(s) have been overlayed.");
|
player.print(affected + " block(s) have been overlayed.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
92
src/com/sk89q/worldedit/BaseBlock.java
Normale Datei
92
src/com/sk89q/worldedit/BaseBlock.java
Normale Datei
@ -0,0 +1,92 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a block.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class BaseBlock {
|
||||||
|
/**
|
||||||
|
* BaseBlock type.
|
||||||
|
*/
|
||||||
|
private short type = 0;
|
||||||
|
/**
|
||||||
|
* BaseBlock data.
|
||||||
|
*/
|
||||||
|
private char data = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the block with its type.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public BaseBlock(int type) {
|
||||||
|
this.type = (short)type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the block with its type and data.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public BaseBlock(int type, int data) {
|
||||||
|
this.type = (short)type;
|
||||||
|
this.data = (char)data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type
|
||||||
|
*/
|
||||||
|
public int getType() {
|
||||||
|
return (int)type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type the type to set
|
||||||
|
*/
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = (short)type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the data
|
||||||
|
*/
|
||||||
|
public int getData() {
|
||||||
|
return (int)data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data the data to set
|
||||||
|
*/
|
||||||
|
public void setData(int data) {
|
||||||
|
this.data = (char)data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if it's air.
|
||||||
|
*
|
||||||
|
* @return if air
|
||||||
|
*/
|
||||||
|
public boolean isAir() {
|
||||||
|
return type == 0;
|
||||||
|
}
|
||||||
|
}
|
@ -344,6 +344,36 @@ public class Vector {
|
|||||||
return new Vector(this.x / x, this.y / y, this.z / z);
|
return new Vector(this.x / x, this.y / y, this.z / z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scalar division.
|
||||||
|
*
|
||||||
|
* @param n
|
||||||
|
* @return new point
|
||||||
|
*/
|
||||||
|
public Vector divide(int n) {
|
||||||
|
return new Vector(x / n, y / n, z / n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scalar division.
|
||||||
|
*
|
||||||
|
* @param n
|
||||||
|
* @return new point
|
||||||
|
*/
|
||||||
|
public Vector divide(double n) {
|
||||||
|
return new Vector(x / n, y / n, z / n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scalar division.
|
||||||
|
*
|
||||||
|
* @param n
|
||||||
|
* @return new point
|
||||||
|
*/
|
||||||
|
public Vector divide(float n) {
|
||||||
|
return new Vector(x / n, y / n, z / n);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the distance away from a point.
|
* Get the distance away from a point.
|
||||||
*
|
*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren