From 652f27c853335d57b38bc54f98bfe87b15086804 Mon Sep 17 00:00:00 2001 From: Mgazul Date: Tue, 9 Apr 2019 11:29:43 +0800 Subject: [PATCH] Fix fixLiquid --- .../java/com/sk89q/worldedit/EditSession.java | 20 ++++++++++++------- .../worldedit/command/UtilityCommands.java | 10 ++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index ee865680e..9581bf5ba 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2196,18 +2196,24 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fixLiquid(final BlockVector3 origin, final double radius, Mask liquidMask, Pattern pattern) { + public int fixLiquid(final BlockVector3 origin, final double radius, BlockType fluid) { checkNotNull(origin); checkArgument(radius >= 0, "radius >= 0 required"); + // Our origins can only be liquids + Mask liquidMask = new BlockTypeMask(this, fluid); + + // But we will also visit air blocks + MaskIntersection blockMask = new MaskUnion(liquidMask, Masks.negate(new ExistingBlockMask(this))); + // There are boundaries that the routine needs to stay in MaskIntersection mask = new MaskIntersection( - new BoundedHeightMask(0, Math.min(origin.getBlockY(), getMaximumPoint().getBlockY())), + new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), - liquidMask); + blockMask); - BlockReplace replace = new BlockReplace(this, pattern); - NonRisingVisitor visitor = new NonRisingVisitor(mask, replace, (int) (radius * 2 + 1), this); + BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState())); + NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { @@ -2216,8 +2222,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } - Operations.completeBlindly(visitor); - return getBlockChangeCount(); + Operations.completeLegacy(visitor); + return visitor.getAffected(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 2f0ae81df..23319dc91 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -317,10 +317,11 @@ public class UtilityCommands extends MethodCommands { ) @CommandPermissions("worldedit.fixlava") @Logging(PLACEMENT) - public void fixLava(Player player, LocalSession session, EditSession editSession, double radius) throws WorldEditException { + public void fixLava(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + double radius = Math.max(0, args.getDouble(0)); worldEdit.checkMaxRadius(radius); int affected = editSession.fixLiquid( - session.getPlacementPosition(player), radius, BlockTypes.LAVA.toMask(editSession), BlockTypes.LAVA.getDefaultState()); + session.getPlacementPosition(player), radius, BlockTypes.LAVA); player.print(BBC.getPrefix() + affected + " block(s) have been changed."); } @@ -333,10 +334,11 @@ public class UtilityCommands extends MethodCommands { ) @CommandPermissions("worldedit.fixwater") @Logging(PLACEMENT) - public void fixWater(Player player, LocalSession session, EditSession editSession, double radius) throws WorldEditException { + public void fixWater(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + double radius = Math.max(0, args.getDouble(0)); worldEdit.checkMaxRadius(radius); int affected = editSession.fixLiquid( - session.getPlacementPosition(player), radius, BlockTypes.WATER.toMask(editSession), BlockTypes.WATER.getDefaultState()); + session.getPlacementPosition(player), radius, BlockTypes.WATER); BBC.VISITOR_BLOCK.send(player, affected); }