All Downloads are FREE. Search and download functionalities are using the official Maven repository.

personthecat.catlib.util.FeatureSupport Maven / Gradle / Ivy

Go to download

Utilities for serialization, commands, noise generation, IO, and some new data types.

The newest version!
package personthecat.catlib.util;

import lombok.experimental.UtilityClass;
import net.minecraft.class_2960;
import net.minecraft.class_3031;
import net.minecraft.class_5321;
import net.minecraft.class_6796;
import personthecat.catlib.registry.DynamicRegistries;

import java.util.Map.Entry;
import java.util.stream.Stream;

@UtilityClass
public class FeatureSupport {

    /**
     * Determines whether the given {@link class_6796} contains any features of the
     * given type.
     *
     * @param pf The placed feature being compared against.
     * @param f  The raw feature type which this feature may contain.
     * @return true, if the features match.
     */
    public static boolean matches(final class_6796 pf, final class_3031 f) {
        return pf.method_39643().anyMatch(c -> f.equals(c.comp_332()));
    }

    /**
     * Streams every matching configured feature to its resource key.
     *
     * @param f The raw feature type being queried against.
     * @return A stream of all matching features and their resource keys.
     */
    public static Stream, class_6796>> getMatching(final class_3031 f) {
        return DynamicRegistries.PLACED_FEATURES.streamEntries()
            .filter(c -> matches(c.getValue(), f));
    }

    /**
     * Streams the {@link class_2960} of every {@link class_6796} containing
     * the given feature.
     *
     * @param f The raw feature type being queried against.
     * @return A stream of all matching feature IDs.
     */
    public static Stream getIds(final class_3031 f) {
        return getMatching(f).map(e -> e.getKey().method_29177());
    }

    /**
     * Streams every {@link class_6796} containing the given feature type.
     *
     * @param f The raw feature type being queried against.
     * @return A stream of all matching features.
     */
    public static Stream getFeatures(final class_3031 f) {
        return getMatching(f).map(Entry::getValue);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy