diff --git a/src/EditSession.java b/src/EditSession.java index 3261c8115..b14bbba5a 100755 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -48,15 +48,23 @@ public class EditSession { /** * Stores the original blocks before modification. */ - private DoubleArrayList original = new DoubleArrayList(); + private DoubleArrayList original = + new DoubleArrayList(); /** * Stores the current blocks. */ - private DoubleArrayList current = new DoubleArrayList(); + private DoubleArrayList current = + new DoubleArrayList(); /** - * Queue. + * Blocks that should be placed before last. */ - private DoubleArrayList queue = new DoubleArrayList(); + private DoubleArrayList queueAfter = + new DoubleArrayList(); + /** + * Blocks that should be placed last. + */ + private DoubleArrayList queueLast = + new DoubleArrayList(); /** * The maximum number of blocks to change at a time. If this number is * exceeded, a MaxChangedBlocksException exception will be @@ -194,13 +202,16 @@ public class EditSession { */ private boolean smartSetBlock(Vector pt, BaseBlock block) { if (queued) { - if (!block.isAir() && BlockType.shouldPlaceLast(block.getID()) - && rawGetBlock(pt.add(0, -1, 0)).isAir()) { - queue.put(pt.toBlockVector(), block); + // Place torches, etc. last + if (BlockType.shouldPlaceLast(block.getID())) { + queueLast.put(pt.toBlockVector(), block); + return getBlock(pt).getID() != block.getID(); + // Destroy torches, etc. first + } else if (BlockType.shouldPlaceLast(getBlock(pt).getID())) { + rawSetBlock(pt, new BaseBlock(0)); + } else { + queueAfter.put(pt.toBlockVector(), block); return getBlock(pt).getID() != block.getID(); - } else if (block.isAir() - && BlockType.shouldPlaceLast(rawGetBlock(pt.add(0, 1, 0)).getID())) { - rawSetBlock(pt.add(0, 1, 0), new BaseBlock(0)); // Prevent items from being dropped } } @@ -336,11 +347,19 @@ public class EditSession { */ public void flushQueue() { if (!queued) { return; } - - for (Map.Entry entry : queue) { + + for (Map.Entry entry : queueAfter) { BlockVector pt = (BlockVector)entry.getKey(); rawSetBlock(pt, (BaseBlock)entry.getValue()); } + + for (Map.Entry entry : queueLast) { + BlockVector pt = (BlockVector)entry.getKey(); + rawSetBlock(pt, (BaseBlock)entry.getValue()); + } + + queueAfter.clear(); + queueLast.clear(); } /** diff --git a/src/com/sk89q/worldedit/DoubleArrayList.java b/src/com/sk89q/worldedit/DoubleArrayList.java index 972f6baa2..9da3df4e8 100644 --- a/src/com/sk89q/worldedit/DoubleArrayList.java +++ b/src/com/sk89q/worldedit/DoubleArrayList.java @@ -60,6 +60,14 @@ public class DoubleArrayList implements Iterable> { return listA.size(); } + /** + * Clear the list. + */ + public void clear() { + listA.clear(); + listB.clear(); + } + /** * Get an entry set. *