Add -e/-b/-m flags to //stack and //move, to match copy and paste.

Fixes WORLDEDIT-3935.
This commit is contained in:
wizjany
2019-08-03 12:59:24 -04:00
parent a1465c02ed
commit e25a6d21cd
7 changed files with 253 additions and 19 deletions

View File

@ -25,12 +25,17 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.pattern.BiomePattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldedit.regions.AbstractFlatRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -46,12 +51,16 @@ import java.util.Map;
* <p>This buffer will not attempt to return results from the buffer when
* accessor methods (such as {@link #getBlock(BlockVector3)}) are called.</p>
*/
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern {
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern, BiomePattern {
private final Map<BlockVector3, BaseBlock> buffer = new LinkedHashMap<>();
private final Map<BlockVector2, BiomeType> biomeBuffer = new LinkedHashMap<>();
private final Mask mask;
private final Mask2D biomeMask;
private BlockVector3 min = null;
private BlockVector2 min2d = null;
private BlockVector3 max = null;
private BlockVector2 max2d = null;
/**
* Create a new extent buffer that will buffer every change.
@ -71,9 +80,10 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
*/
public ForgetfulExtentBuffer(Extent delegate, Mask mask) {
super(delegate);
checkNotNull(delegate);
checkNotNull(mask);
this.mask = mask;
Mask2D bmask = mask.toMask2D();
this.biomeMask = bmask == null ? Masks.alwaysTrue2D() : bmask;
}
@Override
@ -100,6 +110,30 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
}
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
// Update minimum
if (min2d == null) {
min2d = position;
} else {
min2d = min2d.getMinimum(position);
}
// Update maximum
if (max2d == null) {
max2d = position;
} else {
max2d = max2d.getMaximum(position);
}
if (biomeMask.test(position)) {
biomeBuffer.put(position, biome);
return true;
} else {
return getExtent().setBiome(position, biome);
}
}
@Override
public BaseBlock apply(BlockVector3 pos) {
BaseBlock block = buffer.get(pos);
@ -110,13 +144,23 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
}
}
@Override
public BiomeType apply(BlockVector2 pos) {
BiomeType biome = biomeBuffer.get(pos);
if (biome != null) {
return biome;
} else {
return BiomeTypes.OCEAN;
}
}
/**
* Return a region representation of this buffer.
*
* @return a region
*/
public Region asRegion() {
return new AbstractRegion(null) {
return new AbstractFlatRegion(null) {
@Override
public BlockVector3 getMinimumPoint() {
return min != null ? min : BlockVector3.ZERO;
@ -146,6 +190,11 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
public Iterator<BlockVector3> iterator() {
return buffer.keySet().iterator();
}
@Override
public Iterable<BlockVector2> asFlatRegion() {
return biomeBuffer.keySet();
}
};
}
}