Package net.minecraftforge.common.data
Class JsonCodecProvider<T>
java.lang.Object
net.minecraftforge.common.data.JsonCodecProvider<T>
- Type Parameters:
T
- the type of thing being generated.
- All Implemented Interfaces:
DataProvider
Dataprovider for using a Codec to generate jsons. Path names for jsons are derived from the given registry folder and each entry's namespaced id, in the format:
<assets/data>/entryid/registryfolder/entrypath.json
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.mojang.serialization.Codec<T>
protected Map<ResourceLocation,
ICondition[]> protected final DataGenerator
protected final String
protected final com.mojang.serialization.DynamicOps<com.google.gson.JsonElement>
protected final Map<ResourceLocation,
T> protected final ExistingFileHelper
private static final org.slf4j.Logger
protected final String
protected final PackType
Fields inherited from interface net.minecraft.data.DataProvider
FIXED_ORDER_FIELDS, KEY_COMPARATOR
-
Constructor Summary
ConstructorDescriptionJsonCodecProvider
(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper, String modid, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps, PackType packType, String directory, com.mojang.serialization.Codec<T> codec, Map<ResourceLocation, T> entries) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> JsonCodecProvider<T>
forDatapackRegistry
(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper, String modid, RegistryOps<com.google.gson.JsonElement> registryOps, ResourceKey<Registry<T>> registryKey, Map<ResourceLocation, T> entries) Returns DatapackRegistryProvider that encodes using the registered loading codec for the provided registry key.protected void
gather
(BiConsumer<ResourceLocation, T> consumer) getName()
void
run
(CachedOutput cache) setConditions
(Map<ResourceLocation, ICondition[]> conditions) Applies a condition map to this provider.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
dataGenerator
-
existingFileHelper
-
modid
-
dynamicOps
protected final com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps -
packType
-
directory
-
codec
-
entries
-
conditions
-
-
Constructor Details
-
JsonCodecProvider
public JsonCodecProvider(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper, String modid, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps, PackType packType, String directory, com.mojang.serialization.Codec<T> codec, Map<ResourceLocation, T> entries) - Parameters:
dataGenerator
- DataGenerator provided byGatherDataEvent
.dynamicOps
- DynamicOps to encode values to jsons with using the provided Codec, e.g.JsonOps.INSTANCE
.packType
- PackType specifying whether to generate entries in assets or data.directory
- String representing the directory to generate jsons in, e.g. "dimension" or "cheesemod/cheese".codec
- Codec to encode values to jsons with using the provided DynamicOps.entries
- Map of named entries to serialize to jsons. Paths for values are derived from the ResourceLocation's entryid:entrypath as specified above.
-
-
Method Details
-
forDatapackRegistry
public static <T> JsonCodecProvider<T> forDatapackRegistry(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper, String modid, RegistryOps<com.google.gson.JsonElement> registryOps, ResourceKey<Registry<T>> registryKey, Map<ResourceLocation, T> entries) Returns DatapackRegistryProvider that encodes using the registered loading codec for the provided registry key. Ensures the correct directory and codec are used. Only vanilla datapack registries enumerated inRegistryAccess
and custom forge datapack registries can be generated this way.- Type Parameters:
T
- Registry element type, e.g. Biome- Parameters:
dataGenerator
- DataGenerator provided byGatherDataEvent
.modid
- namespace of the mod adding this DataProvider, for logging purposes.registryOps
- RegistryOps to encode values to json with.registryKey
- ResourceKey identifying the registry and its directory.entries
- Map of entries to encode and their ResourceLocations. Paths for values are derived from the ResourceLocation's entryid:entrypath.- Returns:
- DatapackRegistryProvider that encodes using the registered loading codec for the provided registry key
-
run
- Specified by:
run
in interfaceDataProvider
- Throws:
IOException
-
gather
-
getName
- Specified by:
getName
in interfaceDataProvider
-
setConditions
Applies a condition map to this provider. These conditions will be applied to the created JsonElements with the matching names. Null or empty arrays will not be written, and if the top-level json type is not JsonObject, attempting to add conditions will error.- Parameters:
conditions
- The name->condition map to apply.
-