diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 5562eedea..82ebf74ef 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -367,24 +367,19 @@ public class EditSession implements Extent { * @param level the level * @return whether the block changed */ - public boolean setBlock(Vector position, BaseBlock block, boolean notifyAdjacent, Level level) throws WorldEditException { + public boolean setBlock(Vector position, BaseBlock block, Level level) throws WorldEditException { switch (level) { case NORMAL: - return bypassNone.setBlock(position, block, notifyAdjacent); + return bypassNone.setBlock(position, block); case NO_HISTORY_REORDER: - return bypassHistory.setBlock(position, block, notifyAdjacent); + return bypassHistory.setBlock(position, block); case NO_HISTORY: - return bypassReorderHistory.setBlock(position, block, notifyAdjacent); + return bypassReorderHistory.setBlock(position, block); } throw new RuntimeException("New enum entry added that is unhandled here"); } - @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { - return setBlock(location, block, notifyAdjacent, Level.NORMAL); - } - /** * Set a block, bypassing both history and block re-ordering. * @@ -396,7 +391,7 @@ public class EditSession implements Extent { @Deprecated public boolean rawSetBlock(Vector position, BaseBlock block) { try { - return setBlock(position, block, true, Level.NO_HISTORY_REORDER); + return setBlock(position, block, Level.NO_HISTORY_REORDER); } catch (WorldEditException e) { throw new RuntimeException("Unexpected exception", e); } @@ -413,23 +408,16 @@ public class EditSession implements Extent { @Deprecated public boolean smartSetBlock(Vector position, BaseBlock block) { try { - return setBlock(position, block, true, Level.NO_HISTORY); + return setBlock(position, block, Level.NO_HISTORY); } catch (WorldEditException e) { throw new RuntimeException("Unexpected exception", e); } } - /** - * Sets the block at a position, subject to both history and block re-ordering. - * - * @param position the position - * @param block the block - * @return Whether the block changed -- not entirely dependable - * @throws MaxChangedBlocksException thrown if too many blocks are changed - */ + @Override public boolean setBlock(Vector position, BaseBlock block) throws MaxChangedBlocksException { try { - return setBlock(position, block, true, Level.NORMAL); + return setBlock(position, block, Level.NORMAL); } catch (MaxChangedBlocksException e) { throw e; } catch (WorldEditException e) { diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index e5ed7edfb..433ec7fd0 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -526,8 +526,8 @@ public abstract class LocalWorld implements World, Extent { } @Override - public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) { - return setBlock(pt, (Block) block, notifyAdjacent); + public boolean setBlock(Vector pt, BaseBlock block) { + return setBlock(pt, block, true); } @Override diff --git a/src/main/java/com/sk89q/worldedit/extent/BlockBagExtent.java b/src/main/java/com/sk89q/worldedit/extent/BlockBagExtent.java index 734e6883c..3e6122957 100644 --- a/src/main/java/com/sk89q/worldedit/extent/BlockBagExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/BlockBagExtent.java @@ -87,7 +87,7 @@ public class BlockBagExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { if (blockBag != null) { final int type = block.getType(); final int existing = world.getBlockType(location); @@ -115,6 +115,6 @@ public class BlockBagExtent extends ExtentDelegate { } } - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/BlockChangeLimiter.java b/src/main/java/com/sk89q/worldedit/extent/BlockChangeLimiter.java index 618ec535b..9c7ecf331 100644 --- a/src/main/java/com/sk89q/worldedit/extent/BlockChangeLimiter.java +++ b/src/main/java/com/sk89q/worldedit/extent/BlockChangeLimiter.java @@ -75,13 +75,13 @@ public class BlockChangeLimiter extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { if (limit >= 0) { if (count >= limit) { throw new MaxChangedBlocksException(limit); } count++; } - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/BlockQuirkExtent.java b/src/main/java/com/sk89q/worldedit/extent/BlockQuirkExtent.java index 961e976f6..5f9bd6465 100644 --- a/src/main/java/com/sk89q/worldedit/extent/BlockQuirkExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/BlockQuirkExtent.java @@ -49,7 +49,7 @@ public class BlockQuirkExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { final int existing = world.getBlockType(location); if (BlockType.isContainerBlock(existing)) { @@ -58,7 +58,7 @@ public class BlockQuirkExtent extends ExtentDelegate { world.setBlockType(location, BlockID.AIR); // Ice turns until water so this has to be done first } - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java b/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java index 5f5a9534c..189c93207 100644 --- a/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java @@ -47,10 +47,10 @@ public class ChangeSetExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { BaseBlock previous = getBlock(location); changeSet.add(new BlockChange(location.toBlockVector(), previous, block)); - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/ChunkLoadingExtent.java b/src/main/java/com/sk89q/worldedit/extent/ChunkLoadingExtent.java index b1b41e44c..36e0c0eb1 100644 --- a/src/main/java/com/sk89q/worldedit/extent/ChunkLoadingExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/ChunkLoadingExtent.java @@ -59,8 +59,8 @@ public class ChunkLoadingExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { world.checkLoadedChunk(location); - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/DataValidatorExtent.java b/src/main/java/com/sk89q/worldedit/extent/DataValidatorExtent.java index 8a4ba1217..1402ed712 100644 --- a/src/main/java/com/sk89q/worldedit/extent/DataValidatorExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/DataValidatorExtent.java @@ -46,7 +46,7 @@ public class DataValidatorExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { final int y = location.getBlockY(); final int type = block.getType(); if (y < 0 || y > world.getMaxY()) { @@ -58,6 +58,6 @@ public class DataValidatorExtent extends ExtentDelegate { return false; } - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/Extent.java b/src/main/java/com/sk89q/worldedit/extent/Extent.java index 066a62ada..999ca6b20 100644 --- a/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.function.pattern.Pattern; import javax.annotation.Nullable; @@ -33,51 +34,58 @@ import javax.annotation.Nullable; public interface Extent { /** - * Get a copy of the block at the given location. May return null if the location - * given is out of bounds. The returned block must not be tied to any real block - * in the world, so changes to the returned {@link BaseBlock} have no effect until - * {@link #setBlock(Vector, BaseBlock, boolean)} is called. + * Get a snapshot of the block at the given location. + *

+ * If the given position is out of the bounds of the extent, then the behavior + * is undefined (an air block could be returned). However, null + * should not be returned. + *

+ * The returned block is mutable and is a snapshot of the block at the time + * of call. It has no position attached to it, so it could be reused in + * {@link Pattern}s and so on. + *

+ * Calls to this method can actually be quite expensive, so cache results + * whenever it is possible, while being aware of the mutability aspect. + * The cost, however, depends on the implementation and particular extent. * - * @param location location of the block + * @param position position of the block * @return the block, or null if the block does not exist */ - BaseBlock getBlock(Vector location); + BaseBlock getBlock(Vector position); /** * Get the block ID at the given location. * - * @param location location of the block + * @param position position of the block * @return the block ID */ - int getBlockType(Vector location); + int getBlockType(Vector position); /** * Get the data value of the block at the given location. * - * @param location the location of the block + * @param position position of the block * @return the block data value */ - int getBlockData(Vector location); + int getBlockData(Vector position); /** * Change the block at the given location to the given block. The operation may * not tie the given {@link BaseBlock} to the world, so future changes to the * {@link BaseBlock} do not affect the world until this method is called again. + *

+ * The return value of this method indicates whether the change was probably + * successful. It may not be successful if, for example, the location is out + * of the bounds of the extent. It may be unsuccessful if the block passed + * is the same as the one in the world. However, the return value is only an + * estimation and it may be incorrect, but it could be used to count, for + * example, the approximate number of changes. * - *

The return value of this method indicates whether the change "went through," as - * in the block was changed in the world in any way. If the new block is no different - * than the block already at the position in the world, 'false' would be returned. - * If the position is invalid (out of bounds, for example), then nothing should - * occur and 'false' should be returned. If possible, the return value should be - * accurate as possible, but implementations may choose to not provide an accurate - * value if it is not possible to know.

- * - * @param location location of the block + * @param position position of the block * @param block block to set - * @param notifyAdjacent true to notify adjacent blocks of changes * @return true if the block was successfully set (return value may not be accurate) */ - boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException; + boolean setBlock(Vector position, BaseBlock block) throws WorldEditException; /** * Return an {@link Operation} that should be called to tie up loose ends diff --git a/src/main/java/com/sk89q/worldedit/extent/ExtentDelegate.java b/src/main/java/com/sk89q/worldedit/extent/ExtentDelegate.java index 8a23b1209..17b5801bd 100644 --- a/src/main/java/com/sk89q/worldedit/extent/ExtentDelegate.java +++ b/src/main/java/com/sk89q/worldedit/extent/ExtentDelegate.java @@ -71,8 +71,8 @@ public class ExtentDelegate implements Extent { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { - return extent.setBlock(location, block, notifyAdjacent); + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { + return extent.setBlock(location, block); } protected Operation commitBefore() { diff --git a/src/main/java/com/sk89q/worldedit/extent/FastModeExtent.java b/src/main/java/com/sk89q/worldedit/extent/FastModeExtent.java index 1a2e7cada..750b26b3f 100644 --- a/src/main/java/com/sk89q/worldedit/extent/FastModeExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/FastModeExtent.java @@ -81,9 +81,9 @@ public class FastModeExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { dirtyChunks.add(new BlockVector2D(location.getBlockX() >> 4, location.getBlockZ() >> 4)); - return super.setBlock(location, block, notifyAdjacent || enabled); + return world.setBlock(location, block, !enabled); } @Override diff --git a/src/main/java/com/sk89q/worldedit/extent/ForgetfulExtentBuffer.java b/src/main/java/com/sk89q/worldedit/extent/ForgetfulExtentBuffer.java index fe1322c2e..ce8df1606 100644 --- a/src/main/java/com/sk89q/worldedit/extent/ForgetfulExtentBuffer.java +++ b/src/main/java/com/sk89q/worldedit/extent/ForgetfulExtentBuffer.java @@ -77,7 +77,7 @@ public class ForgetfulExtentBuffer extends ExtentDelegate implements Pattern { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { // Update minimum if (min == null) { min = location; @@ -97,7 +97,7 @@ public class ForgetfulExtentBuffer extends ExtentDelegate implements Pattern { buffer.put(blockVector, block); return true; } else { - return getExtent().setBlock(location, block, notifyAdjacent); + return getExtent().setBlock(location, block); } } diff --git a/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java b/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java index 1571258f2..5eb4e1d08 100644 --- a/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java @@ -62,9 +62,9 @@ public class MaskingExtent extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { if (mask.test(location)) { - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } else { return false; } diff --git a/src/main/java/com/sk89q/worldedit/extent/reorder/SimpleBlockReorder.java b/src/main/java/com/sk89q/worldedit/extent/reorder/SimpleBlockReorder.java index e3d7fd266..18f9a919c 100644 --- a/src/main/java/com/sk89q/worldedit/extent/reorder/SimpleBlockReorder.java +++ b/src/main/java/com/sk89q/worldedit/extent/reorder/SimpleBlockReorder.java @@ -82,9 +82,9 @@ public class SimpleBlockReorder extends ExtentDelegate { } @Override - public boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent) throws WorldEditException { + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { if (!enabled) { - return super.setBlock(location, block, notifyAdjacent); + return super.setBlock(location, block); } if (BlockType.shouldPlaceLast(block.getType())) { @@ -97,8 +97,8 @@ public class SimpleBlockReorder extends ExtentDelegate { return !(getBlockType(location) == block.getType() && getBlockData(location) == block.getData()); } else if (BlockType.shouldPlaceLast(getBlockType(location))) { // Destroy torches, etc. first - super.setBlock(location, new BaseBlock(BlockID.AIR), notifyAdjacent); - return super.setBlock(location, block, notifyAdjacent); + super.setBlock(location, new BaseBlock(BlockID.AIR)); + return super.setBlock(location, block); } else { stage1.put(location.toBlockVector(), block); return !(getBlockType(location) == block.getType() && getBlockData(location) == block.getData()); @@ -191,7 +191,7 @@ public class SimpleBlockReorder extends ExtentDelegate { } for (BlockVector pt : walked) { - extent.setBlock(pt, blockTypes.get(pt), true); + extent.setBlock(pt, blockTypes.get(pt)); blocks.remove(pt); } } diff --git a/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java b/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java index c8a5dbedc..d05a7df7c 100644 --- a/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java +++ b/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java @@ -50,7 +50,7 @@ public class BlockReplace implements RegionFunction { @Override public boolean apply(Vector position) throws WorldEditException { - return extent.setBlock(position, pattern.apply(position), true); + return extent.setBlock(position, pattern.apply(position)); } } \ No newline at end of file diff --git a/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java b/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java index af28924a9..4632b387c 100644 --- a/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java +++ b/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java @@ -64,7 +64,7 @@ public class ExtentBlockCopy implements RegionFunction { @Override public boolean apply(Vector position) throws WorldEditException { BaseBlock block = source.getBlock(position); - return destination.setBlock(transform.apply(position.subtract(from)).add(to), block, true); + return destination.setBlock(transform.apply(position.subtract(from)).add(to), block); } } diff --git a/src/main/java/com/sk89q/worldedit/function/visitor/BlockMapEntryVisitor.java b/src/main/java/com/sk89q/worldedit/function/visitor/BlockMapEntryVisitor.java index 08324b118..dee6106ae 100644 --- a/src/main/java/com/sk89q/worldedit/function/visitor/BlockMapEntryVisitor.java +++ b/src/main/java/com/sk89q/worldedit/function/visitor/BlockMapEntryVisitor.java @@ -46,7 +46,7 @@ public class BlockMapEntryVisitor implements Operation { public Operation resume() throws WorldEditException { while (iterator.hasNext()) { Map.Entry entry = iterator.next(); - extent.setBlock(entry.getKey(), entry.getValue(), true); + extent.setBlock(entry.getKey(), entry.getValue()); } return null; diff --git a/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java b/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java index 91d82acda..415d7d669 100644 --- a/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java +++ b/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java @@ -85,12 +85,12 @@ public class BlockChange implements Change { @Override public void undo(UndoContext context) throws WorldEditException { - checkNotNull(context.getExtent()).setBlock(position, previous, true); + checkNotNull(context.getExtent()).setBlock(position, previous); } @Override public void redo(UndoContext context) throws WorldEditException { - checkNotNull(context.getExtent()).setBlock(position, current, true); + checkNotNull(context.getExtent()).setBlock(position, current); } }