Skip to main content

resources

  • Replaces PreparableReloadListener for specifically json data

Usage‚Äč

  • ResourcesWrapper<Example> DATA = ResourcesWrapper.data(Example.class, "directory")
    • load from data packs on the logical server
  • ResourcesWrapper<Example> ASSETS = ResourcesWrapper.assets(Example.class, "directory")
    • load from resource packs on the logical client

Any .json files in that directory of (data or resource) packs will be parsed into an object of your specified class. You can call withGson(Gson) to specify a Gson instance to use for deserialization with your custom type adapters.

These methods will automatically register a listener with the appropriate mod loader API.

onLoad(Runnable)‚Äč

The runnable will be called immediately after loading your resources.

  • data: when the server starts or /reload command is used
    • on the logical server only
  • assets: when the clint starts or the player presses F3 + T
    • on the logical client only

synced()‚Äč

  • Causes the values to be synced to all clients.
  • This may only be called for data packs.
  • Syncing happens when a player connects or after the onLoad action fires.

mergeWith(MergeRule)‚Äč

A MergeRule defines how your objects will be combined into one when multiple packs include a file for the same resource location. It's just a function that converts a list of your objects to a single one (Function<List<T>, T>).

For example, you could implement behaviour like tags where a replace field is used to decide whether values should replace or be combined with values from previously loaded packs.

Reading Resource Values‚Äč

  • Call entrySet() to get all values.
  • Call get(ResourceLocation) to get a specific value.

Make sure to only call these on the logical side where they will be loaded (or either if synced data).