commoble.looot.data

## Class MergeableCodecDataManager<RAW,FINE>

- java.lang.Object
- - net.minecraft.client.resources.ReloadListener<java.util.Map<net.minecraft.util.ResourceLocation,FINE>>
  - - commoble.looot.data.MergeableCodecDataManager<RAW,FINE>

Type Parameters:
  `RAW` - The type of the objects that the codec is parsing jsons as
  `FINE` - The type of the object we get after merging the parsed objects. Can be the same as RAW

All Implemented Interfaces:
  net.minecraft.resources.IFutureReloadListener

Direct Known Subclasses:
  EnchantmentNameLimitManager, NameListManager

    public class MergeableCodecDataManager<RAW,FINE>
    extends net.minecraft.client.resources.ReloadListener<java.util.Map<net.minecraft.util.ResourceLocation,FINE>>

Generic data loader for Codec-parsable data. This works best if initialized during your mod's construction. After creating the manager, subscribeAsSyncable can optionally be called on it to subscribe the manager to the forge events necessary for syncing datapack data to clients.

### Nested Class Summary

### Nested classes/interfaces inherited from interface net.minecraft.resources.IFutureReloadListener

`net.minecraft.resources.IFutureReloadListener.IStage`

### Field Summary

Fields
`java.util.Map<net.minecraft.util.ResourceLocation,FINE>` `data`
`java.lang.String` `folderName`
`protected static java.lang.String` `JSON_EXTENSION`
`protected static int` `JSON_EXTENSION_LENGTH`
`protected static com.google.gson.Gson` `STANDARD_GSON`

### Constructor Summary

Constructors
Constructor and Description
`MergeableCodecDataManager(java.lang.String folderName, org.apache.logging.log4j.Logger logger, com.mojang.serialization.Codec<RAW> codec, java.util.function.Function<java.util.List<RAW>,FINE> merger)` Initialize a data manager with the given folder name, codec, and merger
`MergeableCodecDataManager(java.lang.String folderName, org.apache.logging.log4j.Logger logger, com.mojang.serialization.Codec<RAW> codec, java.util.function.Function<java.util.List<RAW>,FINE> merger, com.google.gson.Gson gson)` Initialize a data manager with the given folder name, codec, and merger, as well as a user-defined GSON instance.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `apply(java.util.Map<net.minecraft.util.ResourceLocation,FINE> processedData, net.minecraft.resources.IResourceManager resourceManager, net.minecraft.profiler.IProfiler profiler)` Main-thread processing, runs after prepare concludes
`protected java.util.Map<net.minecraft.util.ResourceLocation,FINE>` `prepare(net.minecraft.resources.IResourceManager resourceManager, net.minecraft.profiler.IProfiler profiler)` Off-thread processing (can include reading files from hard drive)

`<PACKET> MergeableCodecDataManager<RAW,FINE>`

`subscribeAsSyncable(net.minecraftforge.fml.network.simple.SimpleChannel channel, java.util.function.Function<java.util.Map<net.minecraft.util.ResourceLocation,FINE>,PACKET> packetFactory)`
This should be called at most once, in a mod constructor (FMLCommonSetupEvent *may* work as well) Calling this method in static init may cause it to be called later than it should be.

### Methods inherited from class net.minecraft.client.resources.ReloadListener

`reload`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.minecraft.resources.IFutureReloadListener

`getSimpleName`

### Field Detail

#### JSON_EXTENSION

    protected static final java.lang.String JSON_EXTENSION

See Also:
  Constant Field Values

#### JSON_EXTENSION_LENGTH

    protected static final int JSON_EXTENSION_LENGTH

#### STANDARD_GSON

    protected static final com.google.gson.Gson STANDARD_GSON

#### data

    @Nonnull
    public java.util.Map<net.minecraft.util.ResourceLocation,FINE> data

#### folderName

    public final java.lang.String folderName

### Constructor Detail

#### MergeableCodecDataManager

    public MergeableCodecDataManager(java.lang.String folderName,
                                     org.apache.logging.log4j.Logger logger,
                                     com.mojang.serialization.Codec<RAW> codec,
                                     java.util.function.Function<java.util.List<RAW>,FINE> merger)

Initialize a data manager with the given folder name, codec, and merger

Parameters:
  `folderName` - The name of the folder to load data from, e.g. "cheeses" would load data from "data/modid/cheeses" for all modids. Can include subfolders, e.g. "cheeses/sharp"
  `logger` - A logger that will log parsing errors if they occur
  `codec` - A codec that will be used to parse jsons. See drullkus's codec primer for help on creating these: https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910
  `merger` - A merging function that uses a list of java-objects-that-were-parsed-from-json to create a final object. The list contains all successfully-parsed objects with the same ID from all mods and datapacks. (for a json located at "data/modid/folderName/name.json", the object's ID is "modid:name") As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:name id, and then all tag jsons defined with the same ID are merged additively into a single set of items, etc

#### MergeableCodecDataManager

    public MergeableCodecDataManager(java.lang.String folderName,
                                     org.apache.logging.log4j.Logger logger,
                                     com.mojang.serialization.Codec<RAW> codec,
                                     java.util.function.Function<java.util.List<RAW>,FINE> merger,
                                     com.google.gson.Gson gson)

Initialize a data manager with the given folder name, codec, and merger, as well as a user-defined GSON instance.

Parameters:
  `folderName` - The name of the folder to load data from, e.g. "cheeses" would load data from "data/modid/cheeses" for all modids. Can include subfolders, e.g. "cheeses/sharp"
  `logger` - A logger that will log parsing errors if they occur
  `codec` - A codec that will be used to parse jsons. See drullkus's codec primer for help on creating these: https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910
  `merger` - A merging function that uses a list of java-objects-that-were-parsed-from-json to create a final object. The list contains all successfully-parsed objects with the same ID from all mods and datapacks. (for a json located at "data/modid/folderName/name.json", the object's ID is "modid:name") As an example, consider vanilla's Tags: mods or datapacks can define tags with the same modid:name id, and then all tag jsons defined with the same ID are merged additively into a single set of items, etc
  `gson` - A GSON instance, allowing for user-defined deserializers. General not needed as the gson is only used to convert raw json to a JsonElement, which the Codec then parses into a proper java object.

### Method Detail

#### prepare

    protected java.util.Map<net.minecraft.util.ResourceLocation,FINE> prepare(net.minecraft.resources.IResourceManager resourceManager,
                                                                              net.minecraft.profiler.IProfiler profiler)

Off-thread processing (can include reading files from hard drive)

Specified by:
  `prepare` in class `net.minecraft.client.resources.ReloadListener<java.util.Map<net.minecraft.util.ResourceLocation,FINE>>`

#### apply

    protected void apply(java.util.Map<net.minecraft.util.ResourceLocation,FINE> processedData,
                         net.minecraft.resources.IResourceManager resourceManager,
                         net.minecraft.profiler.IProfiler profiler)

Main-thread processing, runs after prepare concludes

Specified by:
  `apply` in class `net.minecraft.client.resources.ReloadListener<java.util.Map<net.minecraft.util.ResourceLocation,FINE>>`

#### subscribeAsSyncable

    public <PACKET> MergeableCodecDataManager<RAW,FINE> subscribeAsSyncable(net.minecraftforge.fml.network.simple.SimpleChannel channel,
                                                                            java.util.function.Function<java.util.Map<net.minecraft.util.ResourceLocation,FINE>,PACKET> packetFactory)

This should be called at most once, in a mod constructor (FMLCommonSetupEvent *may* work as well) Calling this method in static init may cause it to be called later than it should be. Calling this method A) causes the data manager to send a data-syncing packet to all players when a server /reloads data, and B) subscribes the data manager to the PlayerLoggedIn event to allow it to sync itself to players when they log in. Be aware that the invoker must still manually subscribe the relevant packet type to the channel themselves.

Type Parameters:
  `PACKET` - the packet type that will be sent on the given channel
Parameters:
  `channel` - The networking channel of your mod
  `packetFactory` - A packet constructor or factory method that converts the given map to a packet object to send on the given channel
Returns:
  this manager object