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;
}
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();
}
Aggregations