Search in sources :

Example 1 with TagLoader

use of net.minecraft.tags.TagLoader in project MinecraftForge by MinecraftForge.

the class ForgeTagHandler method createCustomTagTypeReaders.

/**
 * Creates a map for custom tag type to tag reader
 *
 * @apiNote Internal: For use by TagManager
 */
public static Map<ResourceLocation, TagLoader<?>> createCustomTagTypeReaders() {
    LOGGER.debug("Gathering custom tag collection reader from types.");
    ImmutableMap.Builder<ResourceLocation, TagLoader<?>> builder = ImmutableMap.builder();
    for (ResourceLocation registryName : customTagTypeNames) {
        ForgeRegistry<?> registry = RegistryManager.ACTIVE.getRegistry(registryName);
        if (registry != null && registry.getTagFolder() != null) {
            builder.put(registryName, new TagLoader<>(rl -> Optional.ofNullable(registry.getValue(rl)), "tags/" + registry.getTagFolder()));
        }
    }
    return builder.build();
}
Also used : Named(net.minecraft.tags.Tag.Named) ResourceLocation(net.minecraft.resources.ResourceLocation) IForgeRegistryEntry(net.minecraftforge.registries.IForgeRegistryEntry) ForgeRegistry(net.minecraftforge.registries.ForgeRegistry) Supplier(java.util.function.Supplier) TagLoader(net.minecraft.tags.TagLoader) Registry(net.minecraft.core.Registry) StaticTagHelper(net.minecraft.tags.StaticTagHelper) GameData(net.minecraftforge.registries.GameData) Map(java.util.Map) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) TagContainer(net.minecraft.tags.TagContainer) ImmutableMap(com.google.common.collect.ImmutableMap) StaticTags(net.minecraft.tags.StaticTags) Set(java.util.Set) Lifecycle(com.mojang.serialization.Lifecycle) ResourceKey(net.minecraft.resources.ResourceKey) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) Logger(org.apache.logging.log4j.Logger) IOptionalNamedTag(net.minecraftforge.common.Tags.IOptionalNamedTag) Optional(java.util.Optional) Collections(java.util.Collections) RegistryManager(net.minecraftforge.registries.RegistryManager) LogManager(org.apache.logging.log4j.LogManager) ResourceLocation(net.minecraft.resources.ResourceLocation) ImmutableMap(com.google.common.collect.ImmutableMap) TagLoader(net.minecraft.tags.TagLoader)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lifecycle (com.mojang.serialization.Lifecycle)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Nullable (javax.annotation.Nullable)1 Registry (net.minecraft.core.Registry)1 ResourceKey (net.minecraft.resources.ResourceKey)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 StaticTagHelper (net.minecraft.tags.StaticTagHelper)1 StaticTags (net.minecraft.tags.StaticTags)1 Named (net.minecraft.tags.Tag.Named)1 TagContainer (net.minecraft.tags.TagContainer)1 TagLoader (net.minecraft.tags.TagLoader)1 IOptionalNamedTag (net.minecraftforge.common.Tags.IOptionalNamedTag)1 ForgeRegistry (net.minecraftforge.registries.ForgeRegistry)1 GameData (net.minecraftforge.registries.GameData)1