Search in sources :

Example 1 with FlatRegion

use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.

the class ForwardExtentCopy method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    // FAWE start
    if (currentTransform == null) {
        currentTransform = transform;
    }
    // FAWE end
    if (lastBiomeVisitor != null) {
        affectedBiomeCols += lastBiomeVisitor.getAffected();
        lastBiomeVisitor = null;
    }
    if (lastEntityVisitor != null) {
        affectedEntities += lastEntityVisitor.getAffected();
        lastEntityVisitor = null;
    }
    // FAWE start
    Extent finalDest = destination;
    BlockVector3 translation = to.subtract(from);
    if (!translation.equals(BlockVector3.ZERO)) {
        finalDest = new BlockTranslateExtent(finalDest, translation.getBlockX(), translation.getBlockY(), translation.getBlockZ());
    }
    // FAWE end
    // FAWE start - RegionVisitor > ExtentBlockCopy
    RegionFunction copy;
    RegionVisitor blockCopy = null;
    PositionTransformExtent transExt = null;
    if (!currentTransform.isIdentity()) {
        if (!(currentTransform instanceof AffineTransform) || ((AffineTransform) currentTransform).isOffAxis()) {
            transExt = new PositionTransformExtent(source, currentTransform.inverse());
            transExt.setOrigin(from);
            copy = new SimpleBlockCopy(transExt, finalDest);
            if (this.filterFunction != null) {
                copy = new IntersectRegionFunction(filterFunction, copy);
            }
            if (sourceFunction != null) {
                copy = CombinedRegionFunction.combine(copy, sourceFunction);
            }
            if (sourceMask != Masks.alwaysTrue()) {
                new MaskTraverser(sourceMask).reset(transExt);
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
            if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
                copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
            }
            blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy);
        } else {
            transExt = new PositionTransformExtent(finalDest, currentTransform);
            transExt.setOrigin(from);
            finalDest = transExt;
        }
    }
    if (blockCopy == null) {
        RegionFunction maskFunc = null;
        if (sourceFunction != null) {
            BlockVector3 disAbs = translation.abs();
            BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            boolean overlap = (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ());
            RegionFunction copySrcFunc = sourceFunction;
            if (overlap && translation.length() != 0) {
                int x = translation.getBlockX();
                int y = translation.getBlockY();
                int z = translation.getBlockZ();
                maskFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
                    if (region.contains(bv)) {
                        return sourceFunction.apply(bv);
                    }
                    return false;
                };
                copySrcFunc = position -> {
                    BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
                    if (!region.contains(bv)) {
                        return sourceFunction.apply(position);
                    }
                    return false;
                };
            }
            copy = new CombinedBlockCopy(source, finalDest, copySrcFunc);
        } else {
            copy = new SimpleBlockCopy(source, finalDest);
        }
        if (this.filterFunction != null) {
            copy = new IntersectRegionFunction(filterFunction, copy);
        }
        if (sourceMask != Masks.alwaysTrue()) {
            if (maskFunc != null) {
                copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc);
            } else {
                copy = new RegionMaskingFilter(source, sourceMask, copy);
            }
        }
        if (copyingBiomes && (source.isWorld() || region instanceof FlatRegion)) {
            copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
        }
        ExtentTraverser<ParallelQueueExtent> queueTraverser = new ExtentTraverser<>(finalDest).find(ParallelQueueExtent.class);
        Extent preloader = queueTraverser != null ? queueTraverser.get() : source;
        blockCopy = new RegionVisitor(region, copy, preloader);
    }
    List<? extends Entity> entities;
    if (copyingEntities) {
        // filter players since they can't be copied
        entities = source.getEntities(region);
        entities.removeIf(entity -> {
            EntityProperties properties = entity.getFacet(EntityProperties.class);
            return properties != null && !properties.isPasteable();
        });
    } else {
        entities = Collections.emptyList();
    }
    for (int i = 0; i < repetitions; i++) {
        Operations.completeBlindly(blockCopy);
        if (!entities.isEmpty()) {
            ExtentEntityCopy entityCopy = new ExtentEntityCopy(source, from.toVector3(), destination, to.toVector3(), currentTransform);
            entityCopy.setRemoving(removingEntities);
            List<? extends Entity> entities2 = Lists.newArrayList(source.getEntities(region));
            entities2.removeIf(entity -> {
                EntityProperties properties = entity.getFacet(EntityProperties.class);
                return properties != null && !properties.isPasteable();
            });
            EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy);
            Operations.completeBlindly(entityVisitor);
            affectedEntities += entityVisitor.getAffected();
        }
        if (transExt != null) {
            currentTransform = currentTransform.combine(transform);
            transExt.setTransform(currentTransform);
        }
    }
    affectedBlocks += blockCopy.getAffected();
    // FAWE end
    return null;
}
Also used : PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent) Extent(com.sk89q.worldedit.extent.Extent) RegionMaskTestFunction(com.fastasyncworldedit.core.function.RegionMaskTestFunction) EntityVisitor(com.sk89q.worldedit.function.visitor.EntityVisitor) SimpleBlockCopy(com.fastasyncworldedit.core.function.block.SimpleBlockCopy) CombinedBlockCopy(com.fastasyncworldedit.core.function.block.CombinedBlockCopy) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) ExtentEntityCopy(com.sk89q.worldedit.function.entity.ExtentEntityCopy) BiomeCopy(com.fastasyncworldedit.core.function.block.BiomeCopy) PositionTransformExtent(com.fastasyncworldedit.core.extent.PositionTransformExtent) EntityProperties(com.sk89q.worldedit.entity.metadata.EntityProperties) ParallelQueueExtent(com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) RegionFunction(com.sk89q.worldedit.function.RegionFunction) CombinedRegionFunction(com.sk89q.worldedit.function.CombinedRegionFunction) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) IntersectRegionFunction(com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction) BlockTranslateExtent(com.fastasyncworldedit.core.extent.BlockTranslateExtent)

Example 2 with FlatRegion

use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method naturalizeCuboidBlocks.

/**
 * Turns the first 3 layers into dirt/grass and the bottom layers
 * into rock, like a natural Minecraft mountain.
 *
 * @param region the region to affect
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int naturalizeCuboidBlocks(Region region) throws MaxChangedBlocksException {
    checkNotNull(region);
    Naturalizer naturalizer = new Naturalizer(this);
    FlatRegion flatRegion = Regions.asFlatRegion(region);
    // FAWE start - provide extent for preloading
    LayerVisitor visitor = new LayerVisitor(flatRegion, minimumBlockY(region), maximumBlockY(region), naturalizer, this);
    // FAWE end
    Operations.completeBlindly(visitor);
    return this.changes = naturalizer.getAffected();
}
Also used : LayerVisitor(com.sk89q.worldedit.function.visitor.LayerVisitor) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) Naturalizer(com.sk89q.worldedit.function.block.Naturalizer)

Example 3 with FlatRegion

use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method moveRegion.

/**
 * Move the blocks in a region a certain direction.
 *
 * @param region       the region to move
 * @param offset       the offset. Is directional.
 * @param multiplier   the number to multiply the offset by
 * @param moveEntities true to move entities
 * @param copyBiomes   true to copy biomes (source biome is unchanged)
 * @param mask         source mask for the operation (only matching blocks are moved)
 * @param replacement  the replacement pattern to fill in after moving, or null to use air
 * @return number of blocks moved
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 * @throws IllegalArgumentException  thrown if the region is not a flat region, but copyBiomes is true
 */
public int moveRegion(Region region, BlockVector3 offset, int multiplier, boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(offset);
    checkArgument(multiplier >= 1, "distance >= 1 required");
    checkArgument(!copyBiomes || region instanceof FlatRegion, "can't copy biomes from non-flat region");
    // FAWE start - add up distance
    BlockVector3 to = region.getMinimumPoint().add(offset.multiply(multiplier));
    final BlockVector3 displace = offset.multiply(multiplier);
    final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
    BlockVector3 disAbs = displace.abs();
    if (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ()) {
        // Buffer if overlapping
        enableQueue();
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
    if (replacement == null) {
        replacement = BlockTypes.AIR.getDefaultState();
    }
    BlockReplace remove = replacement instanceof ExistingPattern ? null : new BlockReplace(this, replacement);
    // Remove
    copy.setSourceFunction(remove);
    copy.setCopyingEntities(moveEntities);
    copy.setRemovingEntities(moveEntities);
    copy.setCopyingBiomes(copyBiomes);
    copy.setRepetitions(1);
    final Region allowedRegion;
    if (allowedRegions == null || allowedRegions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(allowedRegions);
    }
    Mask sourceMask = this.getSourceMask();
    mask = MaskIntersection.of(sourceMask, mask, new RegionMask(allowedRegion)).optimize();
    if (mask != Masks.alwaysTrue()) {
        copy.setSourceMask(mask);
        if (sourceMask != null && sourceMask.equals(mask)) {
            setSourceMask(null);
        }
    }
    Operations.completeBlindly(copy);
    return this.changes = copy.getAffected();
// FAWE end
}
Also used : ExistingPattern(com.fastasyncworldedit.core.function.pattern.ExistingPattern) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) WallMakeMask(com.fastasyncworldedit.core.function.mask.WallMakeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) Mask(com.sk89q.worldedit.function.mask.Mask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) CylinderRegion(com.sk89q.worldedit.regions.CylinderRegion) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion)

Example 4 with FlatRegion

use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method fall.

public <B extends BlockStateHolder<B>> int fall(final Region region, boolean fullHeight, final B replace) {
    FlatRegion flat = asFlatRegion(region);
    final int startPerformY = region.getMinimumPoint().getBlockY();
    final int startCheckY = fullHeight ? getMinY() : startPerformY;
    final int endY = region.getMaximumPoint().getBlockY();
    RegionVisitor visitor = new RegionVisitor(flat, pos -> {
        int x = pos.getX();
        int z = pos.getZ();
        int freeSpot = startCheckY;
        for (int y = startCheckY; y <= endY; y++) {
            if (y < startPerformY) {
                if (!getBlockType(x, y, z).getMaterial().isAir()) {
                    freeSpot = y + 1;
                }
                continue;
            }
            BlockType block = getBlockType(x, y, z);
            if (!block.getMaterial().isAir()) {
                if (freeSpot != y) {
                    setBlock(x, freeSpot, z, block);
                    setBlock(x, y, z, replace);
                }
                freeSpot++;
            }
        }
        return true;
    }, this);
    Operations.completeBlindly(visitor);
    return this.changes;
}
Also used : RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) FlatRegionVisitor(com.sk89q.worldedit.function.visitor.FlatRegionVisitor) BlockType(com.sk89q.worldedit.world.block.BlockType) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion)

Example 5 with FlatRegion

use of com.sk89q.worldedit.regions.FlatRegion in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method makePumpkinPatches.

// FAWE start - support density
public int makePumpkinPatches(BlockVector3 position, int apothem, double density) throws MaxChangedBlocksException {
    // We want to generate pumpkins
    GardenPatchGenerator generator = new GardenPatchGenerator(this);
    generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
    // In a region of the given radius
    FlatRegion region = new CuboidRegion(// Causes clamping of Y range
    getWorld(), position.add(-apothem, -5, -apothem), position.add(apothem, 10, apothem));
    GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
    LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground, this);
    visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
    Operations.completeLegacy(visitor);
    return this.changes = ground.getAffected();
}
Also used : RandomNoise(com.sk89q.worldedit.math.noise.RandomNoise) GroundFunction(com.sk89q.worldedit.function.GroundFunction) LayerVisitor(com.sk89q.worldedit.function.visitor.LayerVisitor) FlatRegion(com.sk89q.worldedit.regions.FlatRegion) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) GardenPatchGenerator(com.sk89q.worldedit.function.generator.GardenPatchGenerator) NoiseFilter2D(com.sk89q.worldedit.function.mask.NoiseFilter2D)

Aggregations

FlatRegion (com.sk89q.worldedit.regions.FlatRegion)5 Regions.asFlatRegion (com.sk89q.worldedit.regions.Regions.asFlatRegion)4 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)2 LayerVisitor (com.sk89q.worldedit.function.visitor.LayerVisitor)2 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 BlockTranslateExtent (com.fastasyncworldedit.core.extent.BlockTranslateExtent)1 PositionTransformExtent (com.fastasyncworldedit.core.extent.PositionTransformExtent)1 RegionMaskTestFunction (com.fastasyncworldedit.core.function.RegionMaskTestFunction)1 BiomeCopy (com.fastasyncworldedit.core.function.block.BiomeCopy)1 CombinedBlockCopy (com.fastasyncworldedit.core.function.block.CombinedBlockCopy)1 SimpleBlockCopy (com.fastasyncworldedit.core.function.block.SimpleBlockCopy)1 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)1 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)1 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)1 ExistingPattern (com.fastasyncworldedit.core.function.pattern.ExistingPattern)1 IntersectRegionFunction (com.fastasyncworldedit.core.function.visitor.IntersectRegionFunction)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 ParallelQueueExtent (com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent)1