Package net.commoble.databuddy.data

# Class CodecJsonDataManager<K,V>

java.lang.Object
net.neoforged.neoforge.resource.ContextAwareReloadListener
net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,com.google.gson.JsonElement>>
net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener
net.commoble.databuddy.data.CodecJsonDataManager<K,V>

Type Parameters:
  `K` - The type of key for the map of objects we parsed from json
  `V` - The type of the objects that the codec is parsing jsons as

All Implemented Interfaces:
  `net.minecraft.server.packs.resources.PreparableReloadListener`

public class CodecJsonDataManager<K,V> extends net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener
Codec-based data manager for loading data. Use `AddReloadListenerEvent` or `RegisterClientReloadListenersEvent` to register instances of this as a data loader or asset loader, respectively. Use `subscribeAsSyncable(Function)` to sync loaded data from server to client, or use the `OnDatapackSyncEvent` to implement syncing yourself.

## 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<K,V>`
`data`
The raw data that we parsed from json last time resources were reloaded

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

`conditionContext, registryAccess`

## Constructor Summary

Constructors
Constructor
Description
`CodecJsonDataManager(String folderName, Function<net.minecraft.resources.ResourceLocation,com.mojang.serialization.DataResult<K>> keyReader, com.mojang.serialization.Codec<V> valueCodec)`
Creates a CodecJsonDataManager using the standard gson instance
`CodecJsonDataManager(String folderName, Function<net.minecraft.resources.ResourceLocation,com.mojang.serialization.DataResult<K>> keyReader, com.mojang.serialization.Codec<V> valueCodec, com.google.gson.Gson gson)`
Creates a CodecJsonDataManager using a custom gson instance

## Method Summary

Modifier and Type
Method
Description
`protected void`
`apply(Map<net.minecraft.resources.ResourceLocation,com.google.gson.JsonElement> jsons, net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)`
`Map<K,V>`
`getData()`
`static <T> CodecJsonDataManager<net.minecraft.resources.ResourceLocation,T>`
`simple(String folderName, com.mojang.serialization.Codec<T> valueCodec)`
Creates a CodecJsonDataManager using ResourceLocations for map keys
`<PACKET extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
CodecJsonDataManager<K,V>`
`subscribeAsSyncable(Function<Map<K,V>,PACKET> packetFactory)`
This should be called at most once, during construction of your mod (static init of your main mod class is fine) Calling this method automatically subscribes a packet-sender to `OnDatapackSyncEvent`.

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

`getPreparedPath, prepare, scanDirectory`

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

`reload`

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

`injectContext`

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

### data

protected Map<K,V> data
The raw data that we parsed from json last time resources were reloaded

## Constructor Details

### CodecJsonDataManager

public CodecJsonDataManager(String folderName, Function<net.minecraft.resources.ResourceLocation,com.mojang.serialization.DataResult<K>> keyReader, com.mojang.serialization.Codec<V> valueCodec)
Creates a CodecJsonDataManager using the standard gson instance

Parameters:
  `folderName` - String path of the loading folder (should probably be "yourmodid/yourstuff")
  `keyReader` - Function to convert resourcelocations to the your map keys
  `valueCodec` - Codec to load data with

### CodecJsonDataManager

public CodecJsonDataManager(String folderName, Function<net.minecraft.resources.ResourceLocation,com.mojang.serialization.DataResult<K>> keyReader, com.mojang.serialization.Codec<V> valueCodec, com.google.gson.Gson gson)
Creates a CodecJsonDataManager using a custom gson instance

Parameters:
  `folderName` - String path of the loading folder (should probably be "yourmodid/yourstuff")
  `keyReader` - Function to convert resourcelocations to the your map keys
  `valueCodec` - Codec to load data with
  `gson` - gson

## Method Details

### simple

public static <T> CodecJsonDataManager<net.minecraft.resources.ResourceLocation,T> simple(String folderName, com.mojang.serialization.Codec<T> valueCodec)
Creates a CodecJsonDataManager using ResourceLocations for map keys

Type Parameters:
  `T` - The type of the objects that the codec is parsing jsons as
Parameters:
  `folderName` - String path of the loading folder (should probably be "yourmodid/yourstuff")
  `valueCodec` - Codec to load data with
Returns:
  CodecJsonDataManager using ResourceLocations for map keys

### getData

public Map<K,V> getData()

Returns:
  The data entries

### apply

protected void apply(Map<net.minecraft.resources.ResourceLocation,com.google.gson.JsonElement> jsons, net.minecraft.server.packs.resources.ResourceManager resourceManager, net.minecraft.util.profiling.ProfilerFiller profiler)

Specified by:
  `apply` in class `net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,com.google.gson.JsonElement>>`

### subscribeAsSyncable

public <PACKET extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> CodecJsonDataManager<K,V> subscribeAsSyncable(Function<Map<K,V>,PACKET> packetFactory)
This should be called at most once, during construction of your mod (static init of your main mod class is fine) Calling this method automatically subscribes a packet-sender to `OnDatapackSyncEvent`.

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