001/*
002 * Copyright (c) 2023. JEFF Media GbR / mfnalex et al.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package com.jeff_media.jefflib;
019
020import com.jeff_media.jefflib.data.tuples.Pair;
021import com.jeff_media.jefflib.internal.annotations.NMS;
022import com.jeff_media.jefflib.internal.annotations.Tested;
023import lombok.experimental.UtilityClass;
024import org.bukkit.Location;
025import org.bukkit.NamespacedKey;
026import org.jetbrains.annotations.NotNull;
027
028/**
029 * Biome related methods
030 */
031@UtilityClass
032public class BiomeUtils {
033
034    /**
035     * Returns the proper NamespacedKey for the biome at the given location, e.g. "minecraft:desert" or "terralith:salt_flats"
036     *
037     * @param location Location to check
038     * @return NamespacedKey containing the proper biome name
039     * @nms 1.16.2+
040     */
041    @NMS("1.16.2")
042    @Tested("1.19.4")
043    public NamespacedKey getBiomeNamespacedKey(@NotNull final Location location) {
044        final Pair<String, String> keyPair = JeffLib.getNMSHandler().getBiomeName(location);
045        return NamespacedKey.fromString(keyPair.getFirst() + ":" + keyPair.getSecond());
046    }
047}