Search in sources :

Example 11 with RandomPattern

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

the class NoisePatternParser method parseFromInput.

@Override
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) {
    if (arguments.length != 2) {
        throw new InputParseException(Caption.of("fawe.error.command.syntax", TextComponent.of(getPrefix() + "[scale][pattern] (e.g. " + getPrefix() + "[5][dirt,stone])")));
    }
    double scale = parseScale(arguments[0]);
    Pattern inner = worldEdit.getPatternFactory().parseFromInput(arguments[1], context);
    if (inner instanceof RandomPattern) {
        return new RandomPattern(new NoiseRandom(this.generatorSupplier.get(), scale), (RandomPattern) inner);
    } else if (inner instanceof BlockStateHolder) {
        // single blocks won't have any impact on how a noise behaves
        return inner;
    } else {
        throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName() + " cannot be used with #" + this.name));
    }
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) NoiseRandom(com.fastasyncworldedit.core.math.random.NoiseRandom) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 12 with RandomPattern

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

the class FloraGenerator method getDesertPattern.

/**
 * Get a pattern for plants to place inside a desert environment.
 *
 * @return a pattern that places flora
 */
public static Pattern getDesertPattern() {
    RandomPattern pattern = new RandomPattern();
    pattern.add(BlockTypes.DEAD_BUSH.getDefaultState(), 30);
    pattern.add(BlockTypes.CACTUS.getDefaultState(), 20);
    pattern.add(BlockTypes.AIR.getDefaultState(), 300);
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 13 with RandomPattern

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

the class FloraGenerator method getTemperatePattern.

/**
 * Get a pattern for plants to place inside a temperate environment.
 *
 * @return a pattern that places flora
 */
public static Pattern getTemperatePattern() {
    RandomPattern pattern = new RandomPattern();
    pattern.add(BlockTypes.GRASS.getDefaultState(), 300);
    pattern.add(BlockTypes.POPPY.getDefaultState(), 5);
    pattern.add(BlockTypes.DANDELION.getDefaultState(), 5);
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 14 with RandomPattern

use of com.sk89q.worldedit.function.pattern.RandomPattern in project PrivateMines by UntouchedOdin0.

the class Mine method expand.

public void expand() {
    final World world = privateMines.getMineWorldManager().getMinesWorld();
    boolean canExpand = canExpand(1);
    if (!canExpand) {
        privateMines.getLogger().info("Failed to expand the mine due to the mine being too large");
    } else {
        final var fillType = BlockTypes.DIAMOND_BLOCK;
        final var wallType = BlockTypes.BEDROCK;
        final var min = getMineData().getMinimumMining();
        final var max = getMineData().getMaximumMining();
        final Region mine = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        final Region fillAir = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        final Region walls = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        if (fillType == null || wallType == null)
            return;
        mine.expand(ExpansionUtils.expansionVectors(1));
        walls.expand(ExpansionUtils.expansionVectors(1));
        walls.expand(BlockVector3.UNIT_X, BlockVector3.UNIT_Y, BlockVector3.UNIT_Z, BlockVector3.UNIT_MINUS_X, BlockVector3.UNIT_MINUS_Y, BlockVector3.UNIT_MINUS_Z);
        fillAir.expand(BlockVector3.UNIT_X, BlockVector3.UNIT_Y, BlockVector3.UNIT_Z, BlockVector3.UNIT_MINUS_X, BlockVector3.UNIT_MINUS_Z);
        Map<Material, Double> materials = mineData.getMineType().getMaterials();
        final RandomPattern randomPattern = new RandomPattern();
        if (materials != null) {
            materials.forEach((material, chance) -> {
                Pattern pattern = BukkitAdapter.adapt(material.createBlockData());
                randomPattern.add(pattern, chance);
            });
        }
        try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(world)).fastMode(true).build()) {
            editSession.setBlocks(walls, BukkitAdapter.adapt(Material.BEDROCK.createBlockData()));
            editSession.setBlocks(fillAir, BukkitAdapter.adapt(Material.AIR.createBlockData()));
        }
        mineData.setMinimumMining(BukkitAdapter.adapt(world, mine.getMinimumPoint()));
        mineData.setMaximumMining(BukkitAdapter.adapt(world, mine.getMaximumPoint()));
        mineData.setMinimumFullRegion(mineData.getMinimumFullRegion().subtract(1, 1, 1));
        mineData.setMaximumFullRegion(mineData.getMaximumFullRegion().add(1, 1, 1));
        setMineData(mineData);
        privateMines.getMineStorage().replaceMine(mineData.getMineOwner(), this);
        reset();
    }
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) EditSession(com.sk89q.worldedit.EditSession)

Example 15 with RandomPattern

use of com.sk89q.worldedit.function.pattern.RandomPattern in project Nexus by ProjectEdenGG.

the class WorldEditUtils method toRandomPattern.

public RandomPattern toRandomPattern(Set<BlockType> baseBlocks) {
    RandomPattern pattern = new RandomPattern();
    baseBlocks.forEach(baseBlock -> pattern.add(baseBlock, (float) 100 / baseBlocks.size()));
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Aggregations

RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)17 Pattern (com.sk89q.worldedit.function.pattern.Pattern)9 EditSession (com.sk89q.worldedit.EditSession)5 Region (com.sk89q.worldedit.regions.Region)5 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 MineData (me.untouchedodin0.privatemines.mine.data.MineData)3 Caption (com.fastasyncworldedit.core.configuration.Caption)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)2 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 World (com.sk89q.worldedit.world.World)2 Collections (java.util.Collections)2 List (java.util.List)2 Locale (java.util.Locale)2 Stream (java.util.stream.Stream)2 MineType (me.untouchedodin0.kotlin.mine.type.MineType)2 CuboidRegion (redempt.redlib.region.CuboidRegion)2