Added block damage support to //replace and //replacenear

Dieser Commit ist enthalten in:
zml2008 2011-08-28 23:57:07 -07:00
Ursprung d83fed13fb
Commit 1562f17540
5 geänderte Dateien mit 55 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -999,7 +999,7 @@ public class EditSession {
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes,
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes,
BaseBlock toBlock) throws MaxChangedBlocksException {
int affected = 0;
@ -1019,11 +1019,10 @@ public class EditSession {
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
Vector pt = new Vector(x, y, z);
int curBlockType = getBlockType(pt);
BaseBlock curBlockType = getBlock(pt);
if ((fromBlockTypes == null && curBlockType != 0)
|| (fromBlockTypes != null && fromBlockTypes
.contains(curBlockType))) {
if ((fromBlockTypes == null && !curBlockType.isAir())
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) {
if (setBlock(pt, toBlock)) {
++affected;
}
@ -1033,10 +1032,10 @@ public class EditSession {
}
} else {
for (Vector pt : region) {
int curBlockType = getBlockType(pt);
BaseBlock curBlockType = getBlock(pt);
if (fromBlockTypes == null && curBlockType != 0
|| fromBlockTypes.contains(curBlockType)) {
if (fromBlockTypes == null && !curBlockType.isAir()
|| fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes)) {
if (setBlock(pt, toBlock)) {
++affected;
}
@ -1056,7 +1055,7 @@ public class EditSession {
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes,
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes,
Pattern pattern) throws MaxChangedBlocksException {
int affected = 0;
@ -1076,11 +1075,10 @@ public class EditSession {
for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) {
Vector pt = new Vector(x, y, z);
int curBlockType = getBlockType(pt);
BaseBlock curBlockType = getBlock(pt);
if ((fromBlockTypes == null && curBlockType != 0)
|| (fromBlockTypes != null && fromBlockTypes
.contains(curBlockType))) {
if ((fromBlockTypes == null && !curBlockType.isAir())
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) {
if (setBlock(pt, pattern.next(pt))) {
++affected;
}
@ -1090,10 +1088,10 @@ public class EditSession {
}
} else {
for (Vector pt : region) {
int curBlockType = getBlockType(pt);
BaseBlock curBlockType = getBlock(pt);
if (fromBlockTypes == null && curBlockType != 0
|| fromBlockTypes.contains(curBlockType)) {
if (fromBlockTypes == null && !curBlockType.isAir()
|| curBlockType.inIterable(fromBlockTypes)) {
if (setBlock(pt, pattern.next(pt))) {
++affected;
}

Datei anzeigen

@ -400,6 +400,21 @@ public class WorldEdit {
return getBlock(player, id, false);
}
public Set<BaseBlock> getBlocks (LocalPlayer player, String list, boolean allAllowed)
throws DisallowedItemException, UnknownItemException {
String[] items = list.split(",");
Set<BaseBlock> blocks = new HashSet<BaseBlock>();
for (String id : items) {
blocks.add(getBlock(player, id, allAllowed));
}
return blocks;
}
public Set<BaseBlock> getBlocks(LocalPlayer player, String list)
throws DisallowedItemException, UnknownItemException {
return getBlocks(player, list, false);
}
/**
* Get a list of blocks as a set. This returns a Pattern.
*

Datei anzeigen

@ -115,4 +115,26 @@ public class BaseBlock {
public void flip(FlipDirection direction) {
data = (char)BlockData.flip(type, data, direction);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof BaseBlock)) {
return false;
}
return (type == ((BaseBlock)o).type) && (data == ((BaseBlock)o).data);
}
@Override
public String toString() {
return "BaseBlock id: " + getType() + " with damage: " + getData();
}
public boolean inIterable(Iterable<BaseBlock> iter) {
for (BaseBlock block : iter) {
if (block.equals(this)) {
return true;
}
}
return false;
}
}

Datei anzeigen

@ -81,13 +81,13 @@ public class RegionCommands {
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Set<Integer> from;
Set<BaseBlock> from;
Pattern to;
if (args.argsLength() == 1) {
from = null;
to = we.getBlockPattern(player, args.getString(0));
} else {
from = we.getBlockIDs(player, args.getString(0), true);
from = we.getBlocks(player, args.getString(0), true);
to = we.getBlockPattern(player, args.getString(1));
}

Datei anzeigen

@ -239,13 +239,13 @@ public class UtilityCommands {
int size = Math.max(1, args.getInteger(0));
int affected;
Set<Integer> from;
Set<BaseBlock> from;
Pattern to;
if (args.argsLength() == 2) {
from = null;
to = we.getBlockPattern(player, args.getString(1));
} else {
from = we.getBlockIDs(player, args.getString(1), true);
from = we.getBlocks(player, args.getString(1), true);
to = we.getBlockPattern(player, args.getString(2));
}