Package net.commoble.databuddy.data

# Class MergeableCodecDataManager<RAW,FINE>

java.lang.Object
net.neoforged.neoforge.resource.ContextAwareReloadListener
net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,FINE>>
net.commoble.databuddy.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.server.packs.resources.PreparableReloadListener`

public class MergeableCodecDataManager<RAW,FINE> extends net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.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.server.packs.resources.PreparableReloadListener

`net.minecraft.server.packs.resources.PreparableReloadListener.PreparationBarrier`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Map<net.minecraft.resources.ResourceLocation,FINE>`
`data`
the loaded data
`protected static final String`
`JSON_EXTENSION`
".json"
`protected static final int`
`JSON_EXTENSION_LENGTH`
5

## Constructor Summary

Constructors
Constructor
Description
`MergeableCodecDataManager(String folderName, com.mojang.serialization.Codec<RAW> codec, Function<List<RAW>,FINE> merger)`
Initialize a data manager with the given folder name, codec, and merger

## Method Summary

Modifier and Type
Method
Description
`protected void`
`apply(Map<net.minecraft.resources.ResourceLocation,FINE> processedData, net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)`
Main-thread processing, runs after prepare concludes
`Map<net.minecraft.resources.ResourceLocation,FINE>`
`getData()`
`protected Map<net.minecraft.resources.ResourceLocation,FINE>`
`prepare(net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)`
Off-thread processing (can include reading files from hard drive)
`<PACKET extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
MergeableCodecDataManager<RAW,FINE>`
`subscribeAsSyncable(Function<Map<net.minecraft.resources.ResourceLocation,FINE>,PACKET> packetFactory)`
This should be called at most once, during construction of your mod Calling this method automatically subscribes a packet-sender to `OnDatapackSyncEvent`.

### Methods inherited from class net.minecraft.server.packs.resources.SimplePreparableReloadListener

`reload`

### Methods inherited from class net.neoforged.neoforge.resource.ContextAwareReloadListener

`getContext, getRegistryLookup, injectContext, makeConditionalOps`

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

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

### Methods inherited from interface net.minecraft.server.packs.resources.PreparableReloadListener

`getName`

## Field Details

### JSON_EXTENSION

protected static final String JSON_EXTENSION
".json"

See Also:
  - Constant Field Values

### JSON_EXTENSION_LENGTH

protected static final int JSON_EXTENSION_LENGTH
5

### data

protected Map<net.minecraft.resources.ResourceLocation,FINE> data
the loaded data

## Constructor Details

### MergeableCodecDataManager

public MergeableCodecDataManager(String folderName, com.mojang.serialization.Codec<RAW> codec, Function<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"
  `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

## Method Details

### getData

public Map<net.minecraft.resources.ResourceLocation,FINE> getData()

Returns:
  The immutable map of data entries

### prepare

protected Map<net.minecraft.resources.ResourceLocation,FINE> prepare(net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)
Off-thread processing (can include reading files from hard drive)

Specified by:
  `prepare` in class `net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,FINE>>`

### apply

protected void apply(Map<net.minecraft.resources.ResourceLocation,FINE> processedData, net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)
Main-thread processing, runs after prepare concludes

Specified by:
  `apply` in class `net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,FINE>>`

### subscribeAsSyncable

public <PACKET extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> MergeableCodecDataManager<RAW,FINE> subscribeAsSyncable(Function<Map<net.minecraft.resources.ResourceLocation,FINE>,PACKET> packetFactory)
This should be called at most once, during construction of your mod Calling this method automatically subscribes a packet-sender to `OnDatapackSyncEvent`.

Type Parameters:
  `PACKET` - the packet type that will be sent
Parameters:
  `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