Class JsonCodecProvider<T>

java.lang.Object
io.github.vampirestudios.vampirelib.api.datagen.JsonCodecProvider<T>
Type Parameters:
T - the type of thing being generated.
All Implemented Interfaces:
net.minecraft.data.DataProvider
Direct Known Subclasses:
SpriteSourceProvider

public class JsonCodecProvider<T> extends Object implements net.minecraft.data.DataProvider

Dataprovider for using a Codec to generate jsons. Path names for jsons are derived from the given registry folder and each entry's namespaced id, in the format:

 <assets/data>/entryid/registryfolder/entrypath.json 
 
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.data.DataProvider

    net.minecraft.data.DataProvider.Factory<T extends net.minecraft.data.DataProvider>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.mojang.serialization.Codec<T>
     
    protected Map<net.minecraft.resources.ResourceLocation,net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider[]>
     
    protected final String
     
    protected final com.mojang.serialization.DynamicOps<com.google.gson.JsonElement>
     
    protected final Map<net.minecraft.resources.ResourceLocation,T>
     
    protected final ExistingFileHelper
     
    protected final String
     
    protected final net.minecraft.data.PackOutput
     
    protected final net.minecraft.server.packs.PackType
     

    Fields inherited from interface net.minecraft.data.DataProvider

    FIXED_ORDER_FIELDS, KEY_COMPARATOR
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonCodecProvider(net.minecraft.data.PackOutput output, ExistingFileHelper existingFileHelper, String modid, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps, net.minecraft.server.packs.PackType packType, String directory, com.mojang.serialization.Codec<T> codec, Map<net.minecraft.resources.ResourceLocation,T> entries)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    gather(BiConsumer<net.minecraft.resources.ResourceLocation,T> consumer)
     
     
    run(net.minecraft.data.CachedOutput cache)
     
    setConditions(Map<net.minecraft.resources.ResourceLocation,net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider[]> conditions)
    Applies a condition map to this provider.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • output

      protected final net.minecraft.data.PackOutput output
    • existingFileHelper

      protected final ExistingFileHelper existingFileHelper
    • modid

      protected final String modid
    • dynamicOps

      protected final com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps
    • packType

      protected final net.minecraft.server.packs.PackType packType
    • directory

      protected final String directory
    • codec

      protected final com.mojang.serialization.Codec<T> codec
    • entries

      protected final Map<net.minecraft.resources.ResourceLocation,T> entries
    • conditions

      protected Map<net.minecraft.resources.ResourceLocation,net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider[]> conditions
  • Constructor Details

    • JsonCodecProvider

      public JsonCodecProvider(net.minecraft.data.PackOutput output, ExistingFileHelper existingFileHelper, String modid, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> dynamicOps, net.minecraft.server.packs.PackType packType, String directory, com.mojang.serialization.Codec<T> codec, Map<net.minecraft.resources.ResourceLocation,T> entries)
      Parameters:
      output - PackOutput provided by the DataGenerator.
      dynamicOps - DynamicOps to encode values to jsons with using the provided Codec, e.g. JsonOps.INSTANCE.
      packType - PackType specifying whether to generate entries in assets or data.
      directory - String representing the directory to generate jsons in, e.g. "dimension" or "cheesemod/cheese".
      codec - Codec to encode values to jsons with using the provided DynamicOps.
      entries - Map of named entries to serialize to jsons. Paths for values are derived from the ResourceLocation's entryid:entrypath as specified above.
  • Method Details

    • run

      public CompletableFuture<?> run(net.minecraft.data.CachedOutput cache)
      Specified by:
      run in interface net.minecraft.data.DataProvider
    • gather

      protected void gather(BiConsumer<net.minecraft.resources.ResourceLocation,T> consumer)
    • getName

      public String getName()
      Specified by:
      getName in interface net.minecraft.data.DataProvider
    • setConditions

      public JsonCodecProvider<T> setConditions(Map<net.minecraft.resources.ResourceLocation,net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider[]> conditions)
      Applies a condition map to this provider. These conditions will be applied to the created JsonElements with the matching names. Null or empty arrays will not be written, and if the top-level json type is not JsonObject, attempting to add conditions will error.
      Parameters:
      conditions - The name->condition map to apply.