Package org.moddingx.libx.datapack
Class DataLoader
java.lang.Object
org.moddingx.libx.datapack.DataLoader
Utilities to load data from a
ResourceManager
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A factory to map a resource to something else. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Map<net.minecraft.resources.ResourceLocation,
T> collect
(List<ResourceEntry> resources, DataLoader.ResourceFactory<net.minecraft.server.packs.resources.Resource, T> factory) Collects data from the givenresources
by a given factory.static <T> Map<net.minecraft.resources.ResourceLocation,
T> collectJson
(List<ResourceEntry> resources, com.mojang.serialization.Codec<T> codec) Collects data from the givenresources
by a givenCodec
.static <T> Map<net.minecraft.resources.ResourceLocation,
T> collectJson
(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement, T> factory) Collects data from the givenresources
by a given factory.static <T> Map<net.minecraft.resources.ResourceLocation,
T> collectText
(List<ResourceEntry> resources, DataLoader.ResourceFactory<String, T> factory) Collects data from the givenresources
by a given factory.static <T> Stream<T>
join
(List<ResourceEntry> resources, DataLoader.ResourceFactory<net.minecraft.server.packs.resources.Resource, T> factory) Joins data from the givenresources
by a given factory into a stream.static <T> Stream<T>
joinJson
(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement, T> factory) Joins data from the givenresources
by a given factory into a stream.static <T> Stream<T>
joinText
(List<ResourceEntry> resources, DataLoader.ResourceFactory<String, T> factory) Joins data from the givenresources
by a given factory into a stream.static <T> Map<net.minecraft.resources.ResourceLocation,
T> loadJson
(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, com.mojang.serialization.Codec<T> codec) Loads json data from a base path.static <T> Map<net.minecraft.resources.ResourceLocation,
T> loadJson
(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, DataLoader.ResourceFactory<JsonElement, T> factory) Loads json data from a base path.static List<ResourceEntry>
Locates resources in different namespaces.static List<ResourceEntry>
locate
(net.minecraft.server.packs.resources.ResourceManager rm, String basePath, String suffix, boolean recursive) Locates resources in a specific folder.
-
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 isa/b
and there are the json filesa/b/c.json
anda/b/d/e.json
, the resulting ids will bemodid:c
andmodid:d/e
.- Parameters:
codec
- ACodec
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 IOExceptionLoads json data from a base path. For example if the base path isa/b
and there are the json filesa/b/c.json
anda/b/d/e.json
, the resulting ids will bemodid:c
andmodid: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 IOExceptionCollects data from the givenresources
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 IOExceptionCollects data from the givenresources
by a given factory. The contents of the resource are mapped to aString
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 givenresources
by a givenCodec
. The contents of the resource are mapped to aJsonElement
first.- Throws:
IOException
-
collectJson
public static <T> Map<net.minecraft.resources.ResourceLocation,T> collectJson(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement, T> factory) throws IOExceptionCollects data from the givenresources
by a given factory. The contents of the resource are mapped to aJsonElement
first.- Throws:
IOException
-
join
public static <T> Stream<T> join(List<ResourceEntry> resources, DataLoader.ResourceFactory<net.minecraft.server.packs.resources.Resource, T> factory) throws IOExceptionJoins data from the givenresources
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 IOExceptionJoins data from the givenresources
by a given factory into a stream. The contents of the resource are mapped to aString
first.- Throws:
IOException
-
joinJson
public static <T> Stream<T> joinJson(List<ResourceEntry> resources, DataLoader.ResourceFactory<JsonElement, T> factory) throws IOExceptionJoins data from the givenresources
by a given factory into a stream. The contents of the resource are mapped to aJsonElement
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 resourceidPath
- 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 ifsuffix
is non-null.recursive
- Whether to scan sub-directories as well.- Returns:
- A list of resources. Their ids will have
basePath
andsuffix
stripped.
-