This is an old revision of the document!
Table of Contents
Thinking With Resource Conditions (DRAFT)
Introduction
Sometimes you want a recipe to only exist when a certain mod is loaded, or maybe have something happen when an empty tag actually has some items. This is where resource conditions come into play. Resource Conditions allow you to define things like these in a non-breaking way.
Usage in JSON
Resource Conditions are placed in a list, often at the top of the file for simplicity.
Example:
{
"fabric:load_conditions": [
{
"condition": ...
},
{
...
}
],
...
}
Types of Conditions
There are 6 basic types, and 3 'modifier' types.
TrueResourceCondition
The TrueResourceCondition returns true. That's all it does.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:true"
}
],
...
}
AllModsLoadedResourceCondition
This one returns true if all mods(defined by id) listed in it are loaded(running in the current environment).
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:all_mods_loaded"
"values": [
"aether",
"create"
]
}
],
...
}
AnyModsLoadedResourceCondition
Returns true if any mods listed in it are loaded.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:any_mods_loaded"
"values": [
"energizedpower",
"iljatech"
]
}
],
...
}
TagsPopulatedResourceCondition
Returns true if all tags listed in it have members(not empty).
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:tags_populated",
"registry": "minecraft:item",
"values": [
"minecraft:logs",
"minecraft:planks"
]
}
],
...
}
FeaturesEnabledResourceCondition
Returns true if all features listed in it are enabled.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:features_enabled"
"features": [
"minecraft:redstone_experiments"
]
}
],
...
}
RegistryContainsResourceCondition
Returns true if the registry has the identifiers listed in it as entries.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:registry_contains"
"registry": "minecraft:item"
"values": [
"minecraft:coal",
"minecraft:diamond"
]
}
],
...
}
NotResourceCondition
Returns true if the resource condition nested inside is false.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:not"
"value": {
"condition": "fabric:true"
}
}
],
...
}
OrResourceCondition
Returns true if any condition inside it is true.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:or"
"values": [
{
"condition": "fabric:tags_populated",
"registry": "minecraft:item",
"values": [
"minecraft:buttons"
]
},
{
"condition": "fabric:features_enabled",
"features": [
"minecraft:redstone_experiments"
]
},
{
"condition": "fabric:true"
}
]
}
],
...
}
AndResourceCondition
Returns true if all conditions are true.
Example:
{
"fabric:load_conditions": [
{
"condition": "fabric:and"
"values": [
{
"condition": "fabric:tags_populated",
"registry": "minecraft:item",
"values": [
"minecraft:eggs"
]
},
{
"condition": "fabric:features_enabled",
"features": [
"minecraft:minecart_improvements"
]
},
{
"condition": "fabric:true"
}
]
}
],
...
}
Usage in Datagen
This section will assume you have already set up a basic datagen setup. It will use recipes as an example.
We will create a custom shaped recipe that turns a fried egg from farmer's delight refabricated into an egg with a water bucket and only when the mod is loaded.
First, we must use modLocalRuntime and modCompileOnly on any version of Farmer's Delight Refabricated,which can be taken from Modrinth's maven.
Next, we can go into our recipe provider and begin.
public class ModRecipeProvider extends FabricRecipeProvider { ... @Override protected RecipeProvider createRecipeProvider(HolderLookup.Provider provider, RecipeOutput output) { return new RecipeProvider(provider, output) { @Override public void buildRecipes() { shaped(RecipeCategory.FOOD, Items.EGG) .pattern("b") .pattern("w") .define('b', ModItems.FRIED_EGG ) .define('w', Items.WATER_BUCKET) .unlockedBy(getHasName(ModItems.FRIED_EGG ), has(ModItems.FRIED_EGG )) }; } }
The important part of this is when we call the save function. We can wrap our RecipeOutput with the withConditions method provided by FabricRecipeProvider, which allows us to place as many conditions as we want. The result will be this:
{
"fabric:load_conditions": [
{
"condition": "fabric:all_mods_loaded",
"values": [
"farmersdelight"
]
}
],
"type": "minecraft:crafting_shaped",
"category": "food",
"key": {
"b": "farmersdelight:fried_egg",
"w": "minecraft:water_bucket"
},
"pattern": [
"b",
"w"
],
"result": {
"count": 1,
"id": "minecraft:egg"
}
}