Skip to content

DataLoaders

Real Ant Engineer edited this page Oct 29, 2025 · 8 revisions

๐Ÿ—‚๏ธ Data Loaders

Data Loaders in the Formic API allow mods to dynamically load numeric or tabulated data from datapacks at runtime.
They are the foundation for defining physical or simulation parameters such as temperature, conduction, or material properties.


๐Ÿ“ Available Loaders

๐Ÿ”น FloatMapDataLoader<T>

A generic data loader that associates float values with entries from any Minecraft registry โ€” blocks, fluids, biomes, etc.

It supports both direct entries and tag-based definitions (using #).

Too use an instance of said loader you need to make a json file in data/<floatmap_namespace>/float_map/<registry_namespace>/<registry_path>/<floatmap_path>.json

๐Ÿงฉ Example Implementation

// Example: Registering a FloatMapDataLoader for block hardness values
public static final FloatMapDataLoader<Block> BLOCK_HARDNESS =
    new FloatMapDataLoader<>("modid", "blocks/hardness", Registries.BLOCK);

// Register your loader during the data reload event
forgeEventBus.addListener(FormicDataLoaders::onAddReloadListeners);

public static void onAddReloadListeners(AddReloadListenerEvent event) {
    event.addListener(BLOCK_HARDNESS);
}

// Example usage: get the hardness of a block, with a fallback value
public static float getBlockHardness(BlockState state) {
    // Default hardness = 1.0f
    return BLOCK_HARDNESS.getValue(state.getBlock(), 1.0f);
}

โœ… Example JSON (data/modid/float_map/blocks/hardness.json)

{
  "replace": false,
  "values": {
    "#minecraft:stone_ore_replaceables": 3.0,
    "minecraft:stone": 5.0,
    "minecraft:dirt": 0.5,
    "minecraft:obsidian": 50.0,
    "minecraft:air": 0.0
  }
}

๐Ÿ”น TwoDTabulatedFunctionLoader

Loads 2D tabulated functions from datapacks, allowing interpolation of numerical models such as thermodynamic surfaces or simulation data.

Each dataset defines a function f(x, y) as a grid of precomputed samples. At runtime, the loader performs bilinear interpolation to provide smooth results.


๐Ÿ”น TwoDTabulatedFunctionProvider

Used during data generation (datagen) to export and structure function tables for use with TwoDTabulatedFunctionLoader.

This enables creating reusable simulation tables without manual JSON authoring.


๐Ÿ”— Related Pages: