Condition
The base class for all conditions.
Conditions are an expressive way to simplify complex execute commands. They allow you to apply boolean logic to generate multiple execute commands from a single condition.
For example, the following code:
if_(
(con("A") and (con("B") or !con("C")))
or con("D")
or !(con("E") or !con("F"))
) {
cmd("say hi")
}
Generates the following commands:
execute if A if B run say hi
execute if A unless C run say hi
execute if D run say hi
execute unless E if F run say hi
This allows you to write conditions in an understandable way.
The TermCondition is generally created with the shorthand con("...")
and represents a terminal condition, just a basic boolean such as "if ..." or "unless ...". The TermCondition generates an "if ..." by default, and generates an "unless ..." when negated.
There are also other classes and functions that create TermConditions such as com.zacklukem.mcdsl.blocks.Lever.isOff.
The AndCondition and OrCondition are created with the and
and or
infix functions respectively. These classes represent the boolean logic of "and" and "or" respectively. These classes can be nested to create complex boolean logic.
It is highly discouraged to mix the and
and or
infix functions. This is because the precedence of the infix function is not the same as the precedence of the boolean logic. Instead, always use parentheses to group your conditions.
Basically, don't do this: A and B or C
instead do this: (A and B) or C
AndCondition and OrCondition can both be negated with the not
function. This just applies De Morgan's law to the condition.