Data Load Conditions
Sometimes, it is desirable to disable or enable certain features if another mod is present, or if any mod adds another type of ore, etc. For these use cases, NeoForge adds data load conditions. These were originally called recipe conditions, since recipes were the original use case for this system, but it has since been extended to other systems. This is also why some of the built-in conditions are limited to items.
Most JSON files can optionally declare a neoforge:conditions
block in the root, which will be evaluated before the data file is actually loaded. Loading will continue if and only if all conditions pass, otherwise the data file will be ignored. (The exception to this rule are loot tables, which will be replaced with an empty loot table instead.)
{
"neoforge:conditions": [
{
// Condition 1
},
{
// Condition 2
},
// ...
],
// The rest of the data file
}
For example, if we want to only load our file if a mod with id examplemod
is present, our file would look something like this:
{
"neoforge:conditions": [
{
"type": "neoforge:mod_loaded",
"modid": "examplemod"
}
],
"type": "minecraft:crafting_shaped",
// ...
}
Most vanilla files have been patched to use conditions using the ConditionalCodec
wrapper. However, not all systems, especially those not using a codec, can use conditions. To find out whether a data file can use conditions, check the backing codec definition.