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

โœ… Example JSON

{
  "replace": false,
  "values": {
    "#minecraft:stone_ore_replaceables": 295.15,
    "minecraft:lava": 4000.0,
    "minecraft:water": 293.15
  }
}

๐Ÿงฉ Example Implementation

// Registering a FloatMapDataLoader for block mass
public static final FloatMapDataLoader<Block> BLOCK_MASS =
    new FloatMapDataLoader<>(MODID, "blocks/mass", Registries.BLOCK);

Then, register your loaders during the data reload event:

forgeEventBus.addListener(onAddReloadListeners);

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

Once registered, values can be retrieved anywhere:

float blockMass = BLOCK_MASS.getValue(blockState.getBlock(), 1000f);

This returns the mass defined in datapacks, or falls back to the default (1000f) if not found.


๐Ÿ”น 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.


๐Ÿง  Summary

Loader Purpose Example Registry Use Case
FloatMapDataLoader<T> Maps floats to registry entries Blocks, Fluids, Biomes Temperature, conductivity, resilience
TwoDTabulatedFunctionLoader Loads tabulated 2D data โ€“ Thermodynamic or simulation surfaces
TwoDTabulatedFunctionProvider Generates tabulated 2D data (datagen) โ€“ Automatic dataset generation

๐Ÿ”— Related Pages:

Clone this wiki locally