Package com.sk89q.worldedit.function.pattern

Examples of com.sk89q.worldedit.function.pattern.RandomPattern


    }

    @Override
    public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
        BlockFactory blockRegistry = worldEdit.getBlockFactory();
        RandomPattern randomPattern = new RandomPattern();

        for (String token : input.split(",")) {
            BaseBlock block;

            double chance;

            // Parse special percentage syntax
            if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
                String[] p = token.split("%");

                if (p.length < 2) {
                    throw new InputParseException("Missing the type after the % symbol for '" + input + "'");
                } else {
                    chance = Double.parseDouble(p[0]);
                    block = blockRegistry.parseFromInput(p[1], context);
                }
            } else {
                chance = 1;
                block = blockRegistry.parseFromInput(token, context);
            }

            randomPattern.add(new BlockPattern(block), chance);
        }

        return randomPattern;
    }
View Full Code Here


     * 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(new BlockPattern(new BaseBlock(BlockID.DEAD_BUSH)), 30);
        pattern.add(new BlockPattern(new BaseBlock(BlockID.CACTUS)), 20);
        pattern.add(new BlockPattern(new BaseBlock(BlockID.AIR)), 300);
        return pattern;
    }
View Full Code Here

     * 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(new BlockPattern(new BaseBlock(BlockID.LONG_GRASS, 1)), 300);
        pattern.add(new BlockPattern(new BaseBlock(BlockID.RED_FLOWER)), 5);
        pattern.add(new BlockPattern(new BaseBlock(BlockID.YELLOW_FLOWER)), 5);
        return pattern;
    }
View Full Code Here

     * Get a pattern that creates pumpkins with different faces.
     *
     * @return a pumpkin pattern
     */
    public static Pattern getPumpkinPattern() {
        RandomPattern pattern = new RandomPattern();
        for (int i = 0; i < 4; i++) {
            pattern.add(new BlockPattern(new BaseBlock(BlockID.PUMPKIN, i)), 100);
        }
        return pattern;
    }
View Full Code Here

TOP

Related Classes of com.sk89q.worldedit.function.pattern.RandomPattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.