Package commoble.databuddy.data

# Class CodecJsonDataManager<T>

java.lang.Object
net.minecraft.server.packs.resources.SimplePreparableReloadListener<Map<net.minecraft.resources.ResourceLocation,com.google.gson.JsonElement>>
net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener
commoble.databuddy.data.KeyedCodecJsonDataManager<net.minecraft.resources.ResourceLocation,T>
commoble.databuddy.data.CodecJsonDataManager<T>

Type Parameters:
  `T` - The type of the objects that the codec is parsing jsons as

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

public class CodecJsonDataManager<T> extends KeyedCodecJsonDataManager<net.minecraft.resources.ResourceLocation,T>
Codec-based data manager for loading 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 inherited from class commoble.databuddy.data.KeyedCodecJsonDataManager

`data`

## Constructor Summary

Constructors
Constructor
Description
`CodecJsonDataManager(String folderName, com.mojang.serialization.Codec<T> codec)`
Creates a data manager with a standard gson parser
`CodecJsonDataManager(String folderName, com.mojang.serialization.Codec<T> codec, com.google.gson.Gson gson)`
As above but with a custom GSON

## Method Summary

Modifier and Type
Method
Description
`Map<net.minecraft.resources.ResourceLocation,T>`
`getData()`
`<PACKET> CodecJsonDataManager<T>`
`subscribeAsSyncable(net.minecraftforge.network.simple.SimpleChannel channel, Function<Map<net.minecraft.resources.ResourceLocation,T>,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 commoble.databuddy.data.KeyedCodecJsonDataManager

`apply, subscribeMeAsSyncable`

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

## Constructor Details

### CodecJsonDataManager

public CodecJsonDataManager(String folderName, com.mojang.serialization.Codec<T> codec)
Creates a data manager with a standard gson parser

Parameters:
  `folderName` - The name of the data folder that we will load from, vanilla folderNames are "recipes", "loot_tables", etc
  Jsons will be read from data/all_modids/folderName/all_jsons
  folderName can include subfolders, e.g. "some_mod_that_adds_lots_of_data_loaders/cheeses"
  `codec` - A codec to deserialize the json into your T, see javadocs above class

### CodecJsonDataManager

public CodecJsonDataManager(String folderName, com.mojang.serialization.Codec<T> codec, com.google.gson.Gson gson)
As above but with a custom GSON

Parameters:
  `folderName` - The name of the data folder that we will load from, vanilla folderNames are "recipes", "loot_tables", etc
  Jsons will be read from data/all_modids/folderName/all_jsons
  folderName can include subfolders, e.g. "some_mod_that_adds_lots_of_data_loaders/cheeses"
  `codec` - A codec to deserialize the json into your T, see javadocs above class
  `gson` - A gson for parsing the raw json data into JsonElements. JsonElement-to-T conversion will be done by the codec, so gson type adapters shouldn't be necessary here

## Method Details

### getData

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

Overrides:
  `getData` in class `KeyedCodecJsonDataManager<net.minecraft.resources.ResourceLocation,T>`
Returns:
  The data entries

### subscribeAsSyncable

public <PACKET> CodecJsonDataManager<T> subscribeAsSyncable(net.minecraftforge.network.simple.SimpleChannel channel, Function<Map<net.minecraft.resources.ResourceLocation,T>,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:
  `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