-
Notifications
You must be signed in to change notification settings - Fork 0
8. JSON In Line Math Expressions
Still under construction
There are terms that might be confusing. So here are some synonyms and explanations:
- "returns" / "yields" / "results in": The result of an operation or function.
- "parameter" / "argument": The values you pass to an operation or function.
- Names may not start with digits (
0-9
) - Names may only contain letters (
A-Z
anda-z
), digits (0-9
) and underscores (_
)
-
int
: Integers, eg.0
,7
,-87
. -
double
: Floating point numbers, eg.0.0
,1.7
,-43.467
,2
. -
vec3
: 3-dimensional vector made of 3double
elements representing any position or motion in a world. -
boolean
: Boolean (logical) values, eg. eithertrue
orfalse
. -
tag
: NBT compound tags (see Minecraft wiki). -
string
: A sequence of characters, eg.'hello'
,'ABCdef123_'
,'Let us also do some Spaces!!'
.
These are the possible type conversions (eg. whenever a double
is required you can also put in a value of type int
, but not the other way around):
-
int
->double
-
int
->string
-
double
->string
-
boolean
->string
E.g. how to make type values with text:
-
int
: Just type the integer, eg.0
,7
,-87
. -
double
: Type the floating point number using a.
, eg.0.0
,1.7
,-43.467
,2
. -
vec3
: Use thevec3
function mentioned below, eg.vec3(2, 4, 6)
. -
boolean
: Type the logical values, eg. eithertrue
orfalse
. -
tag
: To make a new compound tag use thenew_tag
supplier function mentioned below and populate that using theput_nbt_*
functions, eg.put_nbt_int(new_tag(), 'my_key', 7)
makes a new tag and attaches the integer7
with the keymy_key
resulting in{"my_key": 7}
. -
string
: Write the sequence of characters wrapped by'
characters, eg.'hello'
,'ABCdef123_'
,'Let us also do some Spaces!!'
.
These tables represent all binary operations defined by types. If two operants have different types the resulting type is looked up and the non-matching operant is converted according to the type conversions definition. Eg. Adding a double
and a int
together will convert the later into a double
first and then sum these two up.
Any operation between 2 types not being defined here means that it is also not defined in the system. Attempting such an operation will yield no result.
+ / -
|
int |
double |
---|---|---|
int |
int |
double |
double |
double |
double |
+ / -
|
vec3 |
---|---|
vec3 |
vec3 |
The +
operation also works with strings. Whenever a string is added together with another string, these are concatenated, eg. 'abc' + 'def'
results in the string 'abcdef'
.
* / /
|
int |
double |
vec3 |
---|---|---|---|
int |
int |
double |
vec3 |
double |
double |
double |
vec3 |
vec3 |
vec3 |
vec3 |
Dividing by 0
yields no result.
Works only with the int
type. Remainder by 0
yields no result.
All of these comparison operators allow you to compare 2 values. They always yield a boolean
as result depending on whether the comparison is true
or false
(eg. 0 <= 1
is obviously true
, 'AB' == 'CD' is
false because they are not equal
). The comparison operators are available for the following types:
-
==
(equality):int
,double
,vec3
,boolean
,string
-
!=
(inequality):int
,double
,vec3
,boolean
,string
-
>
(greater than):int
,double
-
>=
(greater than or equal):int
,double
-
<
(less than):int
,double
-
<=
(less than or equal):int
,double
&& |
false |
true |
---|---|---|
false |
false |
false |
true |
false |
true |
&& |
false |
true |
---|---|---|
false |
false |
true |
true |
true |
true |
This is a unary operation where you write the !
symbol in front of the operant.
!true -> false
!false -> true
This is a ternary operation (3 operants) which yields the 2nd or 3rd operant depending on if the 1st operant is true or not:
condition ? value_if_true : value_if_false
Examples:
-
a > b ? a : b
will always return the bigger value ofa
orb
(this is the same as themax
function). -
flag ? var : 12
will returnvar
ifflag
istrue
, otherwise returns12
.
You can also stack these:
a ? b : (c ? d : e)
All functions are explained here. This is to be read as function_name(argument_types) -> result_type
:
-
function_name
: Name of the function -
argument_types
: The amount of arguments and their types -
result_type
: Every function yields a single result with a defined type
-
pi() -> double
: The value of PI.pi() -> 3.14159265359...
-
tag() -> tag
: Create a new empty nbt compound tag. -
sqrt2() -> double
: The value of the square root of 2.sqrt2() -> 1.41421356237...
-
random_int() -> int
: Any possible integerx
with-2147483648 <= x <= 2147483647
(2 to the power of 32 different values).random_int() -> -67
-
random_double() -> int
: Any possible doublex
with0 <= x < 1
.random_double() -> 0.78125
-
random_uuid() -> string
: A random UUID.random_uuid() -> '139AA4B1-D4EC-4A01-9BA0-18E5C32BFCF2'
-
new_tag() -> tag
: A new and empty NBT compound tag.
-
round(double) -> int
: Rounds thedouble
number towards the closestint
number with.5
being rounded up.round(1.2) -> 1
round(2.5) -> 2
round(3.7) -> 4
round(-5.5) -> -5
round(-1.9) -> -2
round(6.0) -> 6
-
floor(double) -> int
: Rounds down thedouble
number to anint
number.floor(1.2) -> 1
floor(2.5) -> 2
floor(3.7) -> 3
floor(-5.5) -> -6
floor(-1.9) -> -2
floor(6.0) -> 6
-
ceil(double) -> int
: Rounds up thedouble
number to anint
number.ceil(1.2) -> 2
ceil(2.5) -> 3
ceil(3.7) -> 4
ceil(-5.5) -> -5
ceil(-1.9) -> -1
ceil(6.0) -> 6
-
sqrt(double) -> double
: Calculates the square root of adouble
number. This number must be positive.sqrt(9.0) -> 3.0
sqrt(2) -> 1.41421356237...
-
get_x(vec3) -> double
: The x-coordinate of thevec3
vector. -
get_y(vec3) -> double
: The y-coordinate of thevec3
vector. -
get_z(vec3) -> double
: The z-coordinate of thevec3
vector. -
length(vec3) -> double
: Calculates the length of thevec3
vector. -
normalize(vec3) -> vec3
: Normalizes thevec3
vector (yields the argumentvector
divided by its length). -
sin(double) -> double
: Calculates the sinus of thedouble
angle, in radians. -
cos(double) -> double
: Calculates the cosinus of thedouble
angle, in radians. -
asin(double) -> double
: Calculates the asinus (inverse sinus, or sin-1) of thedouble
angle, in radians. -
acos(double) -> double
: Calculates the acosinus (inverse cosinus, or cos-1) of thedouble
angle, in radians. -
to_radians(double) -> double
: Converts thedouble
angle from radians to degrees. -
to_degrees(double) -> double
: Converts thedouble
angle from degrees to radians. .uuid_from_string(string) -> string
: Takes any string as seed for the random generator to generate a new UUID from. Calling this method any amount of times with the same parameter always yields the same UUID as result. -
next_int(int) -> int
: Generates a random positive integer up to but excluding the value of the parameter, eg. ifx
is the parameter andy
is the result then0 <= y < x
.next_int(10) -> 3
-
min(int, int) -> int
/min(double, double) -> double
: Gives you the lower value of the 2 arguments.min(1, 2) -> 1
min(2, 1) -> 1
min(-5, -2) -> -5
min(-7, -7) -> -7
-
max(int, int) -> int
/max(double, double) -> double
: Gives you the higher value of the 2 arguments.max(1, 2) -> 2
max(2, 1) -> 2
max(-5, -2) -> -2
max(-7, -7) -> -7
-
nbt_contains(tag, string) -> boolean
: Returnstrue
if the given tag contains a value of the givenstring
name, otherwise returnsfalse
. -
get_nbt_int(tag, string) -> int
: Returns theint
that is on the given tag with the givenstring
name. -
get_nbt_double(tag, string) -> int
: Returns thedouble
that is on the given tag with the givenstring
name. -
get_nbt_boolean(tag, string) -> boolean
: Returns theboolean
that is on the given tag with the givenstring
name. -
get_nbt_compound_tag(tag, string) -> tag
: Returns thetag
that is on the given tag with the givenstring
name. -
get_nbt_string(tag, string) -> string
: Returns thestring
that is on the given tag with the givenstring
name. -
get_nbt_uuid(tag, string) -> string
: Returns thestring
that is on the given tag with the givenstring
name in form of a UUID. -
get_nbt_vec3(tag, string) -> vec3
: Returns thevec3
that is on the given tag with the givenstring
name in form of a list of typedouble
.
-
vec3(double, double, double) -> vec3
: Constructs avec3
made of the 3double
arguments, with the firstdouble
becoming the x-coordinate, the seconddouble
becoming the y-coordinate, and the thirddouble
becoming the z-coordinate. -
put_nbt_int(tag, string, int) -> tag
: Makes a copy of the giventag
and puts the givenint
on it under the givenstring
name then returns this new tag. -
put_nbt_double(tag, string, double) -> tag
: Makes a copy of the giventag
and puts the givendouble
on it under the givenstring
name then returns this new tag. -
put_nbt_boolean(tag, string, boolean) -> tag
: Makes a copy of the giventag
and puts the givenboolean
on it under the givenstring
name then returns this new tag. -
put_nbt_compound_tag(tag, string, boolean) -> tag
: Makes a copy of the giventag
(1st parameter) and puts the giventag
(2nd parameter) on it under the givenstring
name then returns this new tag. -
put_nbt_string(tag, string, string) -> tag
: Makes a copy of the giventag
and puts the givenstring
(2nd parameter) on it under the givenstring
name (3rd parameter) then returns this new tag. -
put_nbt_uuid(tag, string, string) -> tag
: Makes a copy of the giventag
and puts the givenstring
(2nd parameter) on it under the givenstring
name (3rd parameter) in form of a UUID then returns this new tag. -
put_nbt_vec3(tag, string, vec3) -> tag
: Makes a copy of the giventag
and puts the givenvec3
on it under the givenstring
name in form of a list of typedouble
then returns this new tag.
More specifics about this compiler.
- Binds strongest
()
-
-
/!
-
*
//
/%
-
+
/-
-
>
/>=
/<
/<=
-
==
/!=
&&
||
?:
- Binds weakest
This is the exact definition of the compiler, for those interested in it.
-> expression
variable := ( letter | "_" ) { letter | digit | "_" } .
value := digit { digit } [ "." { digit } ] .
function_call := letter { letter | digit | "_" } "(" [ expression { "," expression } ] ")" .
expression := conditional .
conditional := disjunction [ "?" disjunction ":" disjunction ] .
disjunction := conjunction { "||" conjunction } .
conjunction := comparison { "&&" comparison } .
comparison := relation { ( "==" | "!=" ) relation } .
relation := sum { ( ">" | ">=" | "<" | "<=" ) sum } .
sum := product { ( "+" | "-" ) product } .
product := factor { ( "*" | "/" | "%" ) factor } .
factor := [ "-" | "!" ] ( variable | value | "(" expression ")" | function_call ) | "'" string "'" .