commoble.databuddy.data

## Class MergeableJsonDataManager<RAW,FINE>

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

All Implemented Interfaces:
  net.minecraft.resources.IFutureReloadListener

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

### 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`
`protected static java.lang.String` `JSON_EXTENSION`
`protected static int` `JSON_EXTENSION_LENGTH`

### Constructor Summary

Constructors
Constructor and Description
`MergeableJsonDataManager(java.lang.String folderName, java.lang.reflect.Type type, com.google.gson.Gson gson, org.apache.logging.log4j.Logger logger, java.util.function.Function<java.util.stream.Stream<RAW>,FINE> merger)` Initialize a data manager with the given data folder name and gson codec

### Method Summary

All Methods Static 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 -- the processedData argument is the data generated and returned by prepare off-thread
`protected RAW` `getJsonAsData(com.google.gson.JsonObject json)` Use a json object to generate a raw data object
`static boolean` `isStringJsonFile(java.lang.String filename)`
`static <Key,In,Out> java.util.Map<Key,Out>` `mapValues(java.util.Map<Key,In> inputs, java.util.function.Function<In,Out> mapper)`
`protected java.util.Map<net.minecraft.util.ResourceLocation,FINE>` `prepare(net.minecraft.resources.IResourceManager resourceManager, net.minecraft.profiler.IProfiler profiler)` Off-thread calculations (can include reading files)
`protected FINE` `processData(java.util.List<com.google.gson.JsonObject> data)`
`<PACKET> void` `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.

### 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

`getName`

### 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

#### data

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

### Constructor Detail

#### MergeableJsonDataManager

    public MergeableJsonDataManager(java.lang.String folderName,
                                    java.lang.reflect.Type type,
                                    com.google.gson.Gson gson,
                                    org.apache.logging.log4j.Logger logger,
                                    java.util.function.Function<java.util.stream.Stream<RAW>,FINE> merger)

Initialize a data manager with the given data folder name and gson codec

Parameters:
  `folderName` - The name of the data folders we are reading from, can include subfolders, e.g. "folder/subfolder" a json at src/main/resources/data/modid/foldername/jsonid.json has the id "modid:jsonid"
  `type` - The type of java object we are converting jsons into; This is for the RAW data type use TypeToken.get(YourThing.class).getType() or e.g. new TypeToken<Map<Thing>>(){}.getType() for collections
  `gson` - The gson instance used to deserialize jsons to our java objects The standard gson is pretty good at doing this, a specialized instance may be faster or overcome limitations, see here for gson usage details/examples https://github.com/google/gson/blob/master/UserGuide.md
  `logger` - A logger to notify users when resource errors occur
  `merger` - A function that converts a list of objects from multiple datapacks into a single object

### Method Detail

#### subscribeAsSyncable

    public <PACKET> void 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. 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

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

#### prepare

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

Off-thread calculations (can include reading files)

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

#### processData

    protected FINE processData(java.util.List<com.google.gson.JsonObject> data)

#### getJsonAsData

    protected RAW getJsonAsData(com.google.gson.JsonObject json)

Use a json object to generate a raw data object

Parameters:
  `json` - The json object we are converting to the raw instance
Returns:
  The raw instance we converted the json object to

#### 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 -- the processedData argument is the data generated and returned by prepare off-thread

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

#### isStringJsonFile

    public static boolean isStringJsonFile(java.lang.String filename)

#### mapValues

    public static <Key,In,Out> java.util.Map<Key,Out> mapValues(java.util.Map<Key,In> inputs,
                                                                java.util.function.Function<In,Out> mapper)