Class MolangExpr

java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.armature.molang.MolangExpr

public final class MolangExpr extends Object
A compiled Molang expression or script, the language Bedrock and Blockbench write animation values in. Keyframes, anim_time_update, blend_weight and timeline instructions are all read as these, and mods can compile their own.
MolangExpr bob = MolangExpr.parse("math.sin(q.anim_time * 360) * 2");
double value = bob.eval(context);
MolangExpr.parse("v.charge = math.min(v.charge + q.delta_time, 1); return v.charge;");
What is understood: numbers, + - * /, comparisons, && || !, ?: and ??, parentheses, math.* (trigonometry in degrees, as in Bedrock), query./q. values from ArmatureQueries, variable./v. and temp./t. variables, assignments, return, and several statements split by ;. Names are not case sensitive. Anything else fails to parse.
  • Field Details

  • Method Details

    • constant

      public static MolangExpr constant(double value)
      An expression that is always this number.
    • parse

      public static MolangExpr parse(String source)
      Compiles Molang source. A plain number gives a constant.
      Throws:
      IllegalArgumentException - if the source can't be read; the message says where
    • of

      public static MolangExpr of(MolangExpr.Node node, String source)
      Wraps a node the parser built.
    • eval

      public double eval(ArmatureContext context)
      The value in this context. Never throws: a broken query or division by zero gives 0 or infinity, not an error.
    • evalFloat

      public float evalFloat(ArmatureContext context)
    • isConstant

      public boolean isConstant()
      Whether the value never changes, so it can be read once without a context.
    • constantValue

      public double constantValue()
      The value of a constant expression; 0 for any other.
    • source

      public String source()
    • toString

      public String toString()
      Overrides:
      toString in class Object