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