Class DataLoader

java.lang.Object
org.moddingx.libx.datapack.DataLoader

public class DataLoader extends Object
Utilities to load data from a ResourceManager
  • Constructor Details

    • DataLoader

      public DataLoader()
  • Method Details

    • loadJson

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> loadJson(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, com.mojang.serialization.Codec<T> codec) throws IOException
      Loads json data from a base path. For example if the base path is a/b and there are the json files a/b/c.json and a/b/d/e.json, the resulting ids will be modid:c and modid:d/e.
      Parameters:
      codec - A Codec to create the resulting objects.
      Throws:
      IOException
    • loadJson

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> loadJson(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, DataLoader.ResourceFactory<JsonElement,T> factory) throws IOException
      Loads json data from a base path. For example if the base path is a/b and there are the json files a/b/c.json and a/b/d/e.json, the resulting ids will be modid:c and modid:d/e.
      Parameters:
      factory - A factory to create the resulting objects.
      Throws:
      IOException
    • collect

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> collect(List<ResourceEntry> resources, DataLoader.ResourceFactory<net.minecraft.server.packs.resources.Resource,T> factory) throws IOException
      Collects data from the given resources by a given factory.
      Throws:
      IOException
    • collectText

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> collectText(List<ResourceEntry> resources, DataLoader.ResourceFactory<String,T> factory) throws IOException
      Collects data from the given resources by a given factory. The contents of the resource are mapped to a String first.
      Throws:
      IOException
    • collectJson

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> collectJson(List<ResourceEntry> resources, com.mojang.serialization.Codec<T> codec) throws IOException
      Collects data from the given resources by a given Codec. The contents of the resource are mapped to a JsonElement first.
      Throws:
      IOException
    • collectJson

      public static <T> Map<net.minecraft.resources.ResourceLocation,T> collectJson(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement,T> factory) throws IOException
      Collects data from the given resources by a given factory. The contents of the resource are mapped to a JsonElement first.
      Throws:
      IOException
    • join

      public static <T> Stream<T> join(List<ResourceEntry> resources, DataLoader.ResourceFactory<net.minecraft.server.packs.resources.Resource,T> factory) throws IOException
      Joins data from the given resources by a given factory into a stream.
      Throws:
      IOException
    • joinText

      public static <T> Stream<T> joinText(List<ResourceEntry> resources, DataLoader.ResourceFactory<String,T> factory) throws IOException
      Joins data from the given resources by a given factory into a stream. The contents of the resource are mapped to a String first.
      Throws:
      IOException
    • joinJson

      public static <T> Stream<T> joinJson(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement,T> factory) throws IOException
      Joins data from the given resources by a given factory into a stream. The contents of the resource are mapped to a JsonElement first.
      Throws:
      IOException
    • locate

      public static List<ResourceEntry> locate(net.minecraft.server.packs.resources.ResourceManager rm, String fullPath, String idPath)
      Locates resources in different namespaces.
      Parameters:
      rm - The resource manager to use.
      fullPath - The full path of the resource
      idPath - The string that will be used as path name for the id in the resulting resource.
    • locate

      public static List<ResourceEntry> locate(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, @Nullable String suffix, boolean recursive)
      Locates resources in a specific folder.
      Parameters:
      rm - The resource manager to use.
      basePath - The base path to scan.
      suffix - The suffix of the files to load. A file must wnd in a point followed by this if suffix is non-null.
      recursive - Whether to scan sub-directories as well.
      Returns:
      A list of resources. Their ids will have basePath and suffix stripped.