Search in sources :

Example 1 with RandomNoise

use of com.sk89q.worldedit.math.noise.RandomNoise in project FastAsyncWorldEdit by IntellectualSites.

the class NoiseMaskParser method parseFromInput.

@Override
public Mask parseFromInput(String input, ParserContext context) {
    if (!input.startsWith("%")) {
        return null;
    }
    // FAWE start - richer parsing
    if (input.charAt(1) == '[') {
        int end = input.lastIndexOf(']');
        if (end == -1) {
            return null;
        }
        input = input.substring(2, end);
    } else {
        input = input.substring(1);
    }
    int i = Integer.parseInt(input);
    return new NoiseFilter(new RandomNoise(), ((double) i) / 100);
}
Also used : NoiseFilter(com.sk89q.worldedit.function.mask.NoiseFilter) RandomNoise(com.sk89q.worldedit.math.noise.RandomNoise)

Example 2 with RandomNoise

use of com.sk89q.worldedit.math.noise.RandomNoise in project FastAsyncWorldEdit by IntellectualSites.

the class Paint method createFromContext.

@Override
public Operation createFromContext(EditContext context) {
    Extent destination = firstNonNull(context.getDestination(), this.destination);
    Region region = firstNonNull(context.getRegion(), this.region);
    GroundFunction ground = new GroundFunction(new ExistingBlockMask(destination), function.createFromContext(context));
    // FAWE start - provide extent for preloading
    LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground, destination);
    // FAWE end
    visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
    return visitor;
}
Also used : RandomNoise(com.sk89q.worldedit.math.noise.RandomNoise) GroundFunction(com.sk89q.worldedit.function.GroundFunction) NullExtent(com.sk89q.worldedit.extent.NullExtent) Extent(com.sk89q.worldedit.extent.Extent) LayerVisitor(com.sk89q.worldedit.function.visitor.LayerVisitor) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) NoiseFilter2D(com.sk89q.worldedit.function.mask.NoiseFilter2D)

Example 3 with RandomNoise

use of com.sk89q.worldedit.math.noise.RandomNoise in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method flora.

@Command(name = "/flora", desc = "Make flora within the region")
@CommandPermissions("worldedit.region.flora")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int flora(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The density of the forest", def = "5") double density) throws WorldEditException {
    checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
    density = density / 100;
    FloraGenerator generator = new FloraGenerator(editSession);
    GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
    // FAWE start - provide extent for preloading
    LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
    // FAWE end
    visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
    Operations.completeLegacy(visitor);
    int affected = ground.getAffected();
    actor.print(Caption.of("worldedit.flora.created", TextComponent.of(affected)));
    return affected;
}
Also used : FloraGenerator(com.sk89q.worldedit.function.generator.FloraGenerator) RandomNoise(com.sk89q.worldedit.math.noise.RandomNoise) GroundFunction(com.sk89q.worldedit.function.GroundFunction) LayerVisitor(com.sk89q.worldedit.function.visitor.LayerVisitor) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) NoiseFilter2D(com.sk89q.worldedit.function.mask.NoiseFilter2D) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with RandomNoise

use of com.sk89q.worldedit.math.noise.RandomNoise in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method makeForest.

/**
 * Makes a forest.
 *
 * @param region   the region to generate trees in
 * @param density  between 0 and 1, inclusive
 * @param treeType the tree type
 * @return number of trees created
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int makeForest(Region region, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException {
    ForestGenerator generator = new ForestGenerator(this, treeType);
    GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
    // FAWE start - provide extent for preloading
    LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground, this);
    // FAWE end
    visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
    Operations.completeLegacy(visitor);
    return ground.getAffected();
}
Also used : RandomNoise(com.sk89q.worldedit.math.noise.RandomNoise) GroundFunction(com.sk89q.worldedit.function.GroundFunction) LayerVisitor(com.sk89q.worldedit.function.visitor.LayerVisitor) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) ForestGenerator(com.sk89q.worldedit.function.generator.ForestGenerator) NoiseFilter2D(com.sk89q.worldedit.function.mask.NoiseFilter2D)

Example 5 with RandomNoise

use of com.sk89q.worldedit.math.noise.RandomNoise 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

RandomNoise (com.sk89q.worldedit.math.noise.RandomNoise)5 GroundFunction (com.sk89q.worldedit.function.GroundFunction)4 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)4 NoiseFilter2D (com.sk89q.worldedit.function.mask.NoiseFilter2D)4 LayerVisitor (com.sk89q.worldedit.function.visitor.LayerVisitor)4 Regions.asFlatRegion (com.sk89q.worldedit.regions.Regions.asFlatRegion)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 Logging (com.sk89q.worldedit.command.util.Logging)1 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)1 Preload (com.sk89q.worldedit.command.util.annotation.Preload)1 Extent (com.sk89q.worldedit.extent.Extent)1 NullExtent (com.sk89q.worldedit.extent.NullExtent)1 FloraGenerator (com.sk89q.worldedit.function.generator.FloraGenerator)1 ForestGenerator (com.sk89q.worldedit.function.generator.ForestGenerator)1 GardenPatchGenerator (com.sk89q.worldedit.function.generator.GardenPatchGenerator)1 NoiseFilter (com.sk89q.worldedit.function.mask.NoiseFilter)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 FlatRegion (com.sk89q.worldedit.regions.FlatRegion)1 NullRegion (com.sk89q.worldedit.regions.NullRegion)1 Region (com.sk89q.worldedit.regions.Region)1