Search in sources :

Example 1 with RandomPattern

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

the class BlockCategoryPatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    if (!input.startsWith("##")) {
        return null;
    }
    String tag = input.substring(2).toLowerCase(Locale.ROOT);
    boolean anyState = false;
    if (tag.startsWith("*")) {
        tag = tag.substring(1);
        anyState = true;
    }
    BlockCategory category = BlockCategory.REGISTRY.get(tag);
    if (category == null) {
        throw new InputParseException(Caption.of("worldedit.error.unknown-tag", TextComponent.of(tag)));
    }
    RandomPattern randomPattern = new RandomPattern();
    Set<BlockType> blocks = category.getAll();
    if (blocks.isEmpty()) {
        throw new InputParseException(Caption.of("worldedit.error.empty-tag", TextComponent.of(category.getId())));
    }
    if (anyState) {
        blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> randomPattern.add(state, 1.0));
    } else {
        for (BlockType blockType : blocks) {
            randomPattern.add(blockType.getDefaultState(), 1.0);
        }
    }
    return randomPattern;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Set(java.util.Set) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Caption(com.fastasyncworldedit.core.configuration.Caption) BlockCategory(com.sk89q.worldedit.world.block.BlockCategory) ParserContext(com.sk89q.worldedit.extension.input.ParserContext) AliasedParser(com.fastasyncworldedit.core.extension.factory.parser.AliasedParser) List(java.util.List) Stream(java.util.stream.Stream) InputParser(com.sk89q.worldedit.internal.registry.InputParser) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) Locale(java.util.Locale) WorldEdit(com.sk89q.worldedit.WorldEdit) SuggestionHelper(com.sk89q.worldedit.command.util.SuggestionHelper) Pattern(com.sk89q.worldedit.function.pattern.Pattern) Collections(java.util.Collections) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockType(com.sk89q.worldedit.world.block.BlockType) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) BlockCategory(com.sk89q.worldedit.world.block.BlockCategory)

Example 2 with RandomPattern

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

the class RandomPatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    RandomPattern randomPattern = new RandomPattern();
    // FAWE start
    List<String> patterns = StringUtil.split(input, ',', '[', ']');
    // FAWE end
    if (patterns.size() == 1) {
        // let a 'single'-pattern parser handle it
        return null;
    }
    for (String token : patterns) {
        double chance;
        Pattern innerPattern;
        // Parse special percentage syntax
        if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
            // FAWE start
            String[] p = token.split("%", 2);
            if (p.length < 2) {
                throw new InputParseException(Caption.of("worldedit.error.parser.missing-random-type", TextComponent.of(input)));
            } else {
                chance = Double.parseDouble(p[0]);
                innerPattern = worldEdit.getPatternFactory().parseFromInput(p[1], context);
            }
        } else {
            chance = 1;
            innerPattern = worldEdit.getPatternFactory().parseFromInput(token, context);
        }
        randomPattern.add(innerPattern, chance);
    }
    return randomPattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 3 with RandomPattern

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

the class FloraGenerator method mushroomPattern.

// FAWE start
/**
 * Get a pattern for plants to place inside a mushroom environment.
 *
 * @return a pattern that places flora
 */
public static Pattern mushroomPattern() {
    RandomPattern pattern = new RandomPattern();
    pattern.add(BlockTypes.RED_MUSHROOM.getDefaultState(), 10);
    pattern.add(BlockTypes.BROWN_MUSHROOM.getDefaultState(), 10);
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 4 with RandomPattern

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

the class FloraGenerator method netherPattern.

/**
 * Get a pattern for plants to place inside a nether environment.
 *
 * @return a pattern that places flora
 */
public static Pattern netherPattern() {
    RandomPattern pattern = new RandomPattern();
    pattern.add(BlockTypes.CRIMSON_ROOTS.getDefaultState(), 10);
    pattern.add(BlockTypes.CRIMSON_FUNGUS.getDefaultState(), 20);
    pattern.add(BlockTypes.WARPED_FUNGUS.getDefaultState(), 5);
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 5 with RandomPattern

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

the class FloraGenerator method warpedNyliumPattern.

/**
 * Get a pattern for plants to place inside a nether environment.
 *
 * @return a pattern that places flora
 */
public static Pattern warpedNyliumPattern() {
    RandomPattern pattern = new RandomPattern();
    pattern.add(BlockTypes.WARPED_ROOTS.getDefaultState(), 15);
    pattern.add(BlockTypes.NETHER_SPROUTS.getDefaultState(), 20);
    pattern.add(BlockTypes.WARPED_FUNGUS.getDefaultState(), 7);
    pattern.add(BlockTypes.CRIMSON_ROOTS.getDefaultState(), 10);
    return pattern;
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Aggregations

RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)11 Pattern (com.sk89q.worldedit.function.pattern.Pattern)5 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)4 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 CuboidRegion (redempt.redlib.region.CuboidRegion)2 SuggestInputParseException (com.fastasyncworldedit.core.command.SuggestInputParseException)1 AliasedParser (com.fastasyncworldedit.core.extension.factory.parser.AliasedParser)1 FaweParser (com.fastasyncworldedit.core.extension.factory.parser.FaweParser)1 NoiseRandom (com.fastasyncworldedit.core.math.random.NoiseRandom)1 TrueRandom (com.fastasyncworldedit.core.math.random.TrueRandom)1 StringMan (com.fastasyncworldedit.core.util.StringMan)1