From 2e3c3404d4cc2e361fc38d575a817b588d8c4152 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 26 Nov 2010 23:24:55 -0800 Subject: [PATCH] Blocks should now be fully removed correctly so that they don't drop items. --- src/EditSession.java | 43 ++++++++++++++------ src/com/sk89q/worldedit/DoubleArrayList.java | 8 ++++ 2 files changed, 39 insertions(+), 12 deletions(-) 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. *