Conditions

Page last edited 1,740 days 7 hours ago
From COG Docs
Jump to: navigation, search

Conditional elements are a special feature of the CustomOreGen xml parser. In general, the contents of a conditional element are discarded if the condition is false.

There are three types of condition available. See Types for details.



Using Then and Else

The "contents" (child elements and attributes) of a condition should be placed in a <Then> or (optionally) an <Else> element. If the condition is true all contents of the <Then> are transferred to the conditional's parent. If the condition is false then all contents of the <Else> element are transferred instead.

Source Result if True Result if False
 <Veins>
    <IfChoice name='foo' value='bar'>
        <Then> <OreBlock block='dirt'/> </Then>
        <Else block='sand'/>
    </IfChoice>
 </Veins>
 <Veins>
    <OreBlock block='dirt'/>
 </Veins>
 <Veins block='sand'>
 </Veins>


As a shortcut, the contents (child elements only) can be placed directly in the conditional element, with no <Then>. This cuts down on the amount of code if there is no need for an <Else> block and no child attributes in the content.

Source Result if True Result if False
 <Veins block='sand'>
    <IfChoice name='foo' value='bar'>
        <OreBlock block='dirt'/>
    </IfChoice>
 </Veins>
 <Veins block='sand'>
    <OreBlock block='dirt'/>
 </Veins>
 <Veins block='sand'>
 </Veins>


Condition Types

Presence of another Mod

The <IfModInstalled> and <IfNotModInstalled> elements test whether or not the specified mod is currently installed. This is obviously useful for adding mod-specific distributions to the config file. Both elements have a single attribute:

<IfModInstalled> and <IfNotModInstalled>
Attribute Default Value Description
name [Required] The mod name, as listed by Modloader/FML. This usually includes the prefix "mod_". For example, CustomOreGen has the mod name "mod_CustomOreGen".


Value of a Choice Option

The <IfChoice> and <IfNotChoice> elements test whether or not a choice option has a specific value. This could also be done with <IfCondition> element as well, but <IfChoice> is simpler and offer case insensitive comparison.

<IfChoice> and <IfNotChoice> have the following attributes:

<IfChoice> and <IfNotChoice>
Attribute Default Value Description
name [Required] The option name.
value [Required] The value to compare against.


Arbitrary Expression

The <IfCondition> element accepts an arbitrary boolean expression:

<IfCondition>
Attribute Default Value Description
condition [Required] A boolean value. This could just be true or false, but it could also be a complex expression like := 1 > 0