Origins: Powerful Powers
» Language referencePage 10 of 17

Language reference

Variable code is Java's expression syntax, with Java's precedence, associativity, number promotion and overflow.

Where code goes

FieldContainsCan change things?
fields of variablesfield declarationsonly its own initial values
code of executestatementsyes
code of for_eachstatementsyes, including value
expression of expressionone boolean expressionno
value of modify_variableone expressionno
${…} in with_variables and /opp withone expressionno

Names

NameMeans
manathis entity's variable (the actor, in bi-entity code)
self.manathe same, written out
other.manathe target's variable. Only in bi-entity code.
Scoreboard, Item, Death, Stat, Globalbuilt-in names, reserved
value, index, sizethe current element of the innermost loop (page 11)
history.size(), …a list's methods (page 11)

Literals

42, 0xFF, 1_000_000, 10L, 1.5, 1.5f, 2e3, 1d, true, false, and "text" with the escapes \n \t \" \\ \uXXXX.

Comments: // and /* */.

Operators

Highest precedence first:

OperatorsNotes
x++ x--variables only
++x --x +x -x !x ~x (type) x
* / %whole-number division rounds toward zero. Dividing an int or long by zero is an error
+ -+ joins text when either side is a String
<< >> >>>int/long
< <= > >=numbers
== !=numbers, booleans, Strings
& ^ |bitwise on int/long, logical on booleans
&& ||short-circuit
?:
= += -= *= /= %= &= |= ^= <<= >>= >>>=actions only

Types and conversions

As in Java:

  • Mixed arithmetic promotes: int, then long, then float, then double. 5 / 2 is 2, and 5 / 2.0 is 2.5.
  • int and long overflow wraps around.
  • = only widens. int x = someDouble; is an error. Write x = (int) someDouble;.
  • Compound assignment casts, so x += 1.5 on an int is allowed.
  • Casts between number types behave like Java's. To convert between numbers and booleans or Strings, use String.valueOf(x), "" + x or Integer.parseInt(s).

Built-ins

GroupMembers
Math.abs max min clamp round floor ceil rint signum sqrt cbrt pow exp log log10 sin cos tan asin acos atan atan2 hypot toRadians toDegrees floorDiv floorMod random, PI, E
Integer., Long., Float., Double.MAX_VALUE, MIN_VALUE, parseInt(s) / parseLong / parseFloat / parseDouble
Double.POSITIVE_INFINITY, NEGATIVE_INFINITY, NaN, isNaN(x), isInfinite(x)
Boolean. / String.Boolean.parseBoolean(s), String.valueOf(x)
Scoreboard.get(objective), get(holder, objective), has(objective), has(holder, objective): see page 9
Item.id(slot), id(power, slot), count(slot), count(power, slot): what's in a vanilla slot or a slot of an origins:inventory power. cooldown(item or slot): vanilla cooldown ticks left. Each takes an optional first argument self or other. See page 14
Death.has(), x(), y(), z(), dimension(), distance(): where the player last died. See Death below
Stat.get(stat), get(self or other, stat): a vanilla statistic. See Stat below
Global.has(key), get(key), set(key, value), delete(key), bind(key, self or other), lock(key, owner), unlock(key), list(key), list(key, type): the global store. See page 12
String methodslength() isEmpty() isBlank() equals(x) equalsIgnoreCase(s) contains(s) startsWith(s) endsWith(s) indexOf(s) lastIndexOf(s) compareTo(s) concat(s) toUpperCase() toLowerCase() trim() strip() substring(i) substring(i, j) replace(a, b) repeat(n)
List methodssize() isEmpty() get(i) contains(v) indexOf(v) set(i, v) add(v) add(i, v) remove(x) clear(): see page 11

Overloads resolve as in javac:

  • Math.abs(int) stays int
  • Math.max(int, long) is long
  • Math.round(double) is long
  • Math.round(float) is int

Death

The player's last death location, the one vanilla keeps for the recovery compass. Each method takes an optional self or other (bi-entity code only), like Death.distance(other).

MethodTypeValue
Death.has()booleanwhether there's a death location. Always false for non-players.
Death.x(), Death.y(), Death.z()intthe block where they died. An error without a death location, so check Death.has() first.
Death.dimension()Stringthe dimension they died in, like minecraft:the_nether. Same error rule.
Death.distance()doubleblocks from the entity to the centre of that block. -1 when there's no death location or it's in another dimension. Never an error.
  • Vanilla saves the location, so it survives relogging and restarts. Only a death changes it.
  • The same distance is the last_death_distance attribute.

Example: execute code that stores a hint in a String variable: grave_hint = Death.has() ? "grave at " + Death.x() + " " + Death.z() : "no grave";

Stat

Stat.get(stat) is the player's value for a vanilla statistic, an int. Stat.get(other, stat) reads the other entity in bi-entity code.

The name is written as scoreboard criteria write it: stat type and id with their : swapped for ., joined by a :. For example:

  • "minecraft.custom:minecraft.jump"
  • "minecraft.mined:minecraft.stone"
  • "minecraft.killed:minecraft.zombie"
  • An unknown statistic is an error when the code runs.
  • Non-players and the client read 0. Stats only exist on the server.
  • Units are vanilla's: centimetres for distances, ticks for time. See the stat condition for the list of types.

Example: blocks walked per hour played, as a double:

java
Stat.get("minecraft.custom:minecraft.walk_one_cm") / 100.0 / (Stat.get("minecraft.custom:minecraft.play_time") / 72000.0)

Differences from Java

  • == on Strings compares the text, like .equals().
  • No null. An empty String is "".
  • No char, byte or short.
  • No control flow (if, for, while, return), local variables, new, or methods of your own. Use ?: for choices and the loop actions on page 11 for lists.
  • Types are checked when code runs. Syntax errors, unknown methods, assigning in a condition, and field initializers fail when the pack loads. A type error like mana = "full"; is reported when that code runs.
  • The two branches of ?: keep their own types, so c ? 1 : 2.0 can be an int.
  • toUpperCase() and toLowerCase() ignore the system language.
  • No octal numbers. 010 is an error.

Errors

  • Load errors fail the power when the pack loads, with the line, column and nearby text: expected ';' but found 'casting' (at column 16, near "casting = true").
  • Errors while running are logged once per distinct message, prefixed [variables], with the code that caused them. An action stops at the failing statement, and earlier changes stay. A condition counts as false.