Overview#
DataPack Anvil is a foundational library mod developed by Sirttas, primarily used to support complex data-driven mechanics in mods such as The Graveyard and Elemental Craft. Unlike standard content mods, DataPack Anvil does not add new mobs, items, or biomes directly to the game. Instead, it provides a technical framework that allows other mods to store, load, and synchronize custom data via Minecraft's datapack system.
By leveraging this library, developers can create highly configurable mods where gameplay values, structure generation rules, and block behaviors are defined in JSON files within a datapack rather than being hardcoded. This allows players and server owners to easily customize mod behavior without needing to modify the mod's source code.
Core Mechanics#
The mod introduces several core systems that handle the lifecycle of custom data. These systems ensure that data is loaded correctly when a world starts or when the /reload command is executed.
Data Manager
The Data Manager is the heart of the mod. It automates the process of reading JSON files from specific directories within a datapack. Key features include:
- Automatic Reloading: Automatically refreshes data when the game reloads datapacks.
- Server-to-Client Syncing: Ensures that custom data values (like mob stats or structure frequencies) are consistent between the server and all connected clients.
- Namespace Support: Organizes data into standard Minecraft namespaces (e.g.,
data/modid/custom_folder/).
@DataHolder Annotation
This technical feature allows developers to mark specific Java classes or fields as containers for datapack data. When the Data Manager loads a JSON file, it automatically injects the values into these annotated fields, reducing the amount of boilerplate code required to handle custom configurations.
Serializable Block Predicates#
One of the most powerful features for gameplay customization is the Serializable Block Predicate. This system allows mods to define complex block-matching logic within JSON files. For example, a mod might use a predicate to determine which blocks a custom mob can spawn on or which blocks a specific tool can harvest.
Predicate JSON Structure
A typical block predicate file includes the following fields:
| Field | Type | Description |
|---|---|---|
blocks |
Array | A list of specific block IDs (e.g., ["minecraft:stone", "minecraft:dirt"]). |
tag |
String | A reference to a block tag (e.g., "minecraft:base_stone_overworld"). |
properties |
Object | Specific block state properties to match (e.g., "snowy": "true"). |
When a mod checks a predicate, it returns true if the block at a specific location matches any of the defined criteria (blocks, tags, or properties).
Custom Tags and Events#
DataPack Anvil extends Minecraft's native tag system to support custom object types beyond just blocks, items, and fluids. This allows developers to group custom data objects together, making it easier to apply logic to multiple data entries at once.
Event System
The mod provides custom hooks (Events) that trigger during the data loading process. These are essential for mods that need to perform calculations or register secondary values once all datapack data has been successfully parsed. Common events include:
- Data Loading Start: Triggered before the Data Manager begins parsing files.
- Data Loading Complete: Triggered after all JSON files are loaded and synced.
- Reload Event: Specifically handles the transition when a player uses the
/reloadcommand in-game.
Integration and Usage#
DataPack Anvil is a required dependency for several prominent mods. Its presence is vital for the following functionalities in integrated mods:
- The Graveyard: Uses DataPack Anvil to define the generation rules for various graveyard structures and the spawning conditions for its unique undead mobs.
- Elemental Craft: Utilizes the library to manage elemental recipes and the properties of various magical nodes.
Because it is a library, players only need to ensure the correct version of DataPack Anvil is installed alongside the mods that require it. It does not require separate configuration by the end-user unless they are creating their own custom datapacks to override mod defaults.