Skip to content
David Quintana edited this page Feb 14, 2023 · 1 revision

Conditions allow you to display part of the book only if given criteria are met. Conditions are made of two parts - condition declaration and condition attribute.

Condition declarations have to put in the "header" (between opening <book> tag and first <chapter>) and have to by surrounded by <conditions>,<\conditions>. All conditions have a type and a name, and some have additional data. The condition section could look for example like this:

<conditions>
    <all name="valuables">
        <item-exists registry-name="minecraft:gold_ingot"/>
        <item-exists registry-name="minecraft:diamond"/>
    </all>
    <item-exists name="isIronReal" registry-name="minecraft:iron_ingot"/>
    <true name="true"/>
    <not name="alt_true"><false/></not>
</conditions>

Condition attributes are significantly simpler, they are used just like styling attributes (bold, italic), you just have to add condition="name" to an element. Elements with that attribute will only be displayed if condition with given name is true.
For example, if you want text to only display if iron ingots exist, you could use (assuming you also used previous example):

<p condition="isIronReal">Iron ingots are perfectly gray ingots, usefull in many ways.</p>

Index

  1. Simple conditions
  2. Composite conditions

Simple conditions

Simple conditions return true or false based on a single value.
Their structure is as follows: <type name="name"/>.
Most of them require additional information.

True

Always returns true. Can be helpful in debuging. Example:

<true name="true"/>

False

Always returns false. Can be helpful in debuging. Example:

<false name="not_true"/>

Mod loaded

Returns true if mod with given id is loaded. Requires 'modid' to be specified as well. Example:

<mod-loaded name="mod_test" modid="primitivemobs"/>

Item exists

Returns true if item with given id exists. Requires 'registry-name' to be specified as well. Example:

<item-exists name="isIronReal" registry-name="minecraft:iron_ingot"/>

Advancement unlocked

Returns true if player has unlocked advancement with given id. Requires 'advancement' to be specified as well. Example:

<advancement-unlocked name="advancement_test" advancement="minecraft:adventure/adventuring_time"/>

Stage unlocked

Requires Game Stages.
Returns true if player has unlocked stage with given id. Requires 'stage' to be specified as well. Example:

<stage-unlocked name="test1" stage="test1" />

Composite conditions

Composite conditions calculate their value based on conditions inside them. They are basically logical operators.
Because of that their structure is different:

<type name="name">
    <simple condition/>
    <simple condition/>
    <simple condition/>
</type>

Only the outer condition requires 'name' to be specified. You can even put composite conditions inside other composite conditions.

Not

This condition inverts value of condition that is inside. Example:

<not name="isIronNotReal"><item-exists registry-name="minecraft:iron_ingot"/></not>

And/All

Returns true if all conditions inside are true (AND gate). Example:

<all name="valuables">
    <item-exists registry-name="minecraft:gold_ingot"/>
    <item-exists registry-name="minecraft:diamond"/>
</all>

'And' and 'All' are aliases, meaning you can use either of them and they will behave exactly the same.

Or/Any

Returns true if any condition inside is true (OR gate). Example:

<any name="ingotExists">
    <item-exists registry-name="minecraft:gold_ingot"/>
    <item-exists registry-name="minecraft:iron_ingot"/>
</any>

'Or' and 'Any' are aliases, meaning you can use either of them and they will behave exactly the same.