2014-07-17 07:21:13 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.world.biome;
|
|
|
|
|
|
|
|
import com.google.common.base.Functions;
|
|
|
|
import com.sk89q.worldedit.util.WeightedChoice;
|
|
|
|
import com.sk89q.worldedit.util.WeightedChoice.Choice;
|
|
|
|
import com.sk89q.worldedit.util.function.LevenshteinDistance;
|
|
|
|
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
2018-06-16 06:36:55 +00:00
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import javax.annotation.Nullable;
|
2014-07-17 07:21:13 +00:00
|
|
|
|
2020-07-14 02:50:59 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
/**
|
|
|
|
* Utility methods related to biomes.
|
2020-03-24 00:47:30 +00:00
|
|
|
*
|
|
|
|
* @deprecated Only method is being deprecated for removal.
|
2014-07-17 07:21:13 +00:00
|
|
|
*/
|
2020-03-24 00:47:30 +00:00
|
|
|
@Deprecated
|
2014-07-17 07:21:13 +00:00
|
|
|
public final class Biomes {
|
|
|
|
|
|
|
|
private Biomes() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a biome that matches the given input name.
|
|
|
|
*
|
|
|
|
* @param biomes a list of biomes
|
|
|
|
* @param name the name to test
|
|
|
|
* @param registry a biome registry
|
|
|
|
* @return a biome or null
|
2020-03-24 00:47:30 +00:00
|
|
|
* @deprecated This uses the outdated name system. Find names by comparing with their ID instead.
|
2014-07-17 07:21:13 +00:00
|
|
|
*/
|
2020-03-24 00:47:30 +00:00
|
|
|
@Deprecated
|
2014-07-17 07:21:13 +00:00
|
|
|
@Nullable
|
2019-02-16 07:27:00 +00:00
|
|
|
public static BiomeType findBiomeByName(Collection<BiomeType> biomes, String name, BiomeRegistry registry) {
|
2014-07-17 07:21:13 +00:00
|
|
|
checkNotNull(biomes);
|
|
|
|
checkNotNull(name);
|
|
|
|
checkNotNull(registry);
|
|
|
|
|
|
|
|
Function<String, ? extends Number> compare = new LevenshteinDistance(name, false, LevenshteinDistance.STANDARD_CHARS);
|
2019-02-16 07:27:00 +00:00
|
|
|
WeightedChoice<BiomeType> chooser = new WeightedChoice<>(Functions.compose(compare::apply, new BiomeName(registry)), 0);
|
|
|
|
for (BiomeType biome : biomes) {
|
2014-07-17 07:21:13 +00:00
|
|
|
chooser.consider(biome);
|
|
|
|
}
|
2019-02-16 07:27:00 +00:00
|
|
|
Optional<Choice<BiomeType>> choice = chooser.getChoice();
|
2014-07-17 07:21:13 +00:00
|
|
|
if (choice.isPresent() && choice.get().getScore() <= 1) {
|
|
|
|
return choice.get().getValue();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|