Skip to content

Conditions

Meredith Espinosa edited this page Jan 19, 2020 · 1 revision

Client use

For conditional resources, add a file <target resource with extension>.mcmeta. This will be parsed as JSON to check whether the resource should be loaded. All conditions go in an array with the key when:, and are each given as an object with a single key-value pair. Each pair will specify a condition that must be met for the recipe to be loaded. There are four conditions pre-included, and other mods may add their own:

  • libcd:mod_loaded (passed a String or an array): Will return true if all mods with the given IDs are loaded.
  • libcd:item_exists (passed a String or an array): Will return true if all items with the given item IDs are registered.
  • libcd:item_tag_exists (passed a String or an array): Will return true if all item tags with the given IDs are registered.
  • libcd:block_exists (passed a String or an array): Will return true if all blocks with the given block IDs are registered.
  • libcd:block_tag_exists (passed a String or an array): Will return true if all block tags with the given IDs are registered.
  • libcd:not (passed a single-element object): Will return true if the condition listed in the given object is not true.
  • libcd:none (passed an array): Will return true if all conditions listed in the given array are not true.
  • libcd:or (passed an array, aliased to "or"): Will return true if any condition listed in the given array is true.
  • libcd:xor (passed an array): Will return true if only one condition listed in the given array is true.
  • libcd:dev_mode (passed a boolean): Will return true if the given boolean matches whether dev mode is on. (see the config)

Developer use

LibCD allows any mod to register their own conditions, to prevent recipe loading based on config or more advanced logic. LibCD is available on the CurseForge maven.

To add a new condition, add a LibCDInitializer entrypoint and construct new conditions via lambdas in the initConditions block.

The Object passed to the predicate will be a boxed primitive (Integer, Float, Boolean, etc.), a String, a List, a JsonObject, or null. Use an instanceof check to be sure what you're being passed. Throw a CDSyntaxError if passed the wrong

Clone this wiki locally