Search in sources :

Example 1 with BlockPattern

use of com.sk89q.worldedit.function.pattern.BlockPattern in project FastAsyncWorldEdit by IntellectualSites.

the class Extent method setBlocks.

/**
 * Sets all the blocks inside a region to a given pattern.
 *
 * @param region  the region
 * @param pattern the pattern that provides the replacement block
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
default int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(pattern);
    if (pattern instanceof BlockPattern) {
        return setBlocks(region, ((BlockPattern) pattern).getBlock());
    }
    if (pattern instanceof BlockStateHolder) {
        return setBlocks(region, (BlockStateHolder) pattern);
    }
    int count = 0;
    for (BlockVector3 pos : region) {
        if (pattern.apply(this, pos, pos)) {
            count++;
        }
    }
    return count;
}
Also used : BlockPattern(com.sk89q.worldedit.function.pattern.BlockPattern) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 2 with BlockPattern

use of com.sk89q.worldedit.function.pattern.BlockPattern in project PrivateMinesOOP by UntouchedOdin0.

the class WE6Adapter method fillRegion.

@Override
public void fillRegion(CuboidRegion region, Map<Material, Double> materials) {
    World world = new BukkitWorld(region.getWorld());
    final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
    editSession.enableQueue();
    final RandomPattern randomPattern = new RandomPattern();
    materials.forEach((material, chance) -> {
        // noinspection deprecation SHUT UP
        final BlockPattern pattern = new BlockPattern(new BaseBlock(material.getId()));
        randomPattern.add(pattern, chance);
    });
    final Region worldEditRegion = new com.sk89q.worldedit.regions.CuboidRegion(BukkitUtil.toVector(region.getStart()), BukkitUtil.toVector(region.getEnd()));
    try {
        editSession.setBlocks(worldEditRegion, Patterns.wrap(randomPattern));
    } catch (MaxChangedBlocksException e) {
        e.printStackTrace();
    // this shouldn't happen
    }
    editSession.flushQueue();
}
Also used : BlockPattern(com.sk89q.worldedit.function.pattern.BlockPattern) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) com.sk89q.worldedit(com.sk89q.worldedit) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(redempt.redlib.region.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(redempt.redlib.region.CuboidRegion) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BaseBlock(com.sk89q.worldedit.blocks.BaseBlock)

Aggregations

BlockPattern (com.sk89q.worldedit.function.pattern.BlockPattern)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 com.sk89q.worldedit (com.sk89q.worldedit)1 BaseBlock (com.sk89q.worldedit.blocks.BaseBlock)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Region (com.sk89q.worldedit.regions.Region)1 World (com.sk89q.worldedit.world.World)1 BlockStateHolder (com.sk89q.worldedit.world.block.BlockStateHolder)1 CuboidRegion (redempt.redlib.region.CuboidRegion)1