Skip to content

Load Conditions

This documentation is for the Bookshelf mod! You can download the mod here.

Load conditions allow JSON files in data packs and resource packs to be loaded conditionally. For example if you are creating a recipe that references items from another mod the recipe should only be loaded if that mod is installed. This can be done using a simple load condition.

Condition Format

Load conditions can be used with most JSON resources loaded from data packs or resource packs. This is done by creating a bookshelf:load_conditions property in the JSON file. You can define as many conditions as you want by using a JSON array. If more than one condition is present all conditions must be met.

The following example is of a shapeless crafting recipe that is only loaded if the examplemod has been loaded, allowing the recipe to safely reference an item from the mod in the recipe.

data/example/recipes/dirt_to_diamonds.json
{
"bookshelf:load_conditions": [
{
"type": "bookshelf:mod_loaded",
"values": ["examplemod"]
}
],
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "examplemod:diamond_dirt"
}
],
"result": {
"item": "minecraft:diamond",
"count": 1
}
}

Condition Types

The previous example used the bookshelf:mod_loaded condition type. While this condition is very useful there are many condition types that you can use. This section will go into all of the built-in conditions and explain how they can be beneficial.

Mod Loader Platform

The bookshelf:on_platform condition will check if the data is being loaded on a specific mod loader. For example you can have a recipe that is only loaded on Fabric. This condition can be useful when you have a data file that is using features specific to one mod loader that would otherwise be invalid on a different loader. The accepted platform names are fabric, forge, and neoforge. The casing of the platform name is not important.

{
"type": "bookshelf:on_platform",
"platform": "fabric"
}

Mod Loaded

The bookshelf:mod_loaded condition will check if all of the specified mods are loaded. For example you can have a recipe that is only loaded if a specific mod or group of mods are installed. This is especially useful when creating files to add compatibility with other mods. For example adding a recipe that incorporates modded ingredients, or adding items to an item tag from another mod. Mods are specified using their mod ID which is case sensitive!

{
"type": "bookshelf:mod_loaded",
"values": ["mod_a", "mod_b"]
}

Registry Entry Exists

There are several conditions that check if registry entries exist. For example you can have a recipe that is only loaded when a certain block or item exists. This is similar to the mod_loaded condition but allows you to be much more precise. For example an older/newer version of a mod may not have the item you want to reference, so checking for the item would be more accurate. The values must be valid namespaced ids and can not contain upper case characters. If more than one entry is defined all entries must be registered for the condition to pass.

Here are a list of the supported registry conditions.

  • bookshelf:block_exists
  • bookshelf:item_exists
  • bookshelf:enchantment_exists
  • bookshelf:painting_exists
  • bookshelf:mob_effect_exists
  • bookshelf:potion_exists
  • bookshelf:attribute_exists
  • bookshelf:entity_exists
  • bookshelf:block_entity_exists
{
"type": "bookshelf:item_exists",
"values": ["minecraft:stick", "minecraft:apple"]
}

And

The bookshelf:and condition checks if all sub-conditions are met. For example you can check the mod loader and if a specific mod is loaded. The and condition allows you to create complex condition logic.

{
"type": "bookshelf:and",
"conditions": [
{
"type": "bookshelf:on_platform",
"platform": "fabric"
},
{
"type": "bookshelf:mod_loaded",
"values": ["example_a"]
}
]
}

Or

The bookshelf:or condition checks if at least one of the sub-conditions are met. The or condition allows you to create complex condition logic.

{
"type": "bookshelf:or",
"conditions": [
{
"type": "bookshelf:on_platform",
"platform": "neoforge"
},
{
"type": "bookshelf:on_platform",
"platform": "forge"
}
]
}

Not

The bookshelf:not condition checks if none of the sub-conditions are met. This allows you to invert conditions and create complex condition logic. If more than one condition is specified none of them can be met.

{
"type": "bookshelf:not",
"conditions": [
{
"type": "bookshelf:on_platform",
"platform": "forge"
}
]
}