Skip to content

Releases: WingedSeal/jmc

v1.0.0-alpha.1

14 Jan 08:25
Compare
Choose a tag to compare
v1.0.0-alpha.1 Pre-release
Pre-release

Changelog:

  • Custom condition features (e.g. $var>=10)
  • Add incrementation/decrementation (i.e. var++, var--)

v1.0.0-alpha

14 Jan 06:51
Compare
Choose a tag to compare
v1.0.0-alpha Pre-release
Pre-release

Import

Literally move context of another jmc file to the top of the main file.
Warning: Importing doesn't add extra namespace
Syntax:

@import '[<directory>/]<file_name>';

Will copy the context inside [<directory>/]<file_name>.jmc to main jmc.
Example:

@import 'lib/math';

Multiline Command

You are allowed to split a single command into multiple line, with a cost of adding semicolons (;) at the end of every command (required).

Example:

execute
    as @a
    at @s
    run playsound
        entity.wither.spawn
        master
        @s
        ~ ~ ~
        1 2;

Comment

Syntax:

  • #
  • //

You are allowed to put comment at the end of the line.
Example:

#comment
function tellraw_message() {
    tellraw @a "Message"; //comment
}

Load/Tick

  • Any commands outside a function will be automatically put into __load__.mcfunction
  • Generate load.json with a value of __load__.mcfunction
  • Generate tick.json with a value of __tick__.mcfunction

Custom Syntax

Variable

  • 1. Variable Declaration
    • Initialize a variable (Set to 0, if doesn't exist)
int $<variable>;

Output:

scoreboard players add $<variable> __variable__ 0
  • 2. Variable Assignment
$<variable> = <integer>;

Output:

scoreboard players set $<variable> __variable__ <integer>
  • 3. Variable Operations
    • operations:
      • "=" Assign: Set target's score to source's score (for variable)
      • "+=" Addition: Add source's score to target's score
      • "-=" Subtraction: Subtract source's score from target's score
      • "*=" Multiplication: Set target's score to the product of the target's and source's scores
      • "/=" (Integer) Division: Divide target's score by source' scores, and the result will be rounded down to an integer.
      • "%=" Modulus: Divide target's score by source's score, and use the positive remainder to set the target score
$<target: variable> <operations> ($<source: variable>|<integer>);

Output:

scoreboard players operations <target> __variable__ <operations> <source> __variable__
scoreboard players operations <target> __variable__ <operations> <integer> __int__

Function

  • 1. Function Definition
    • You can't pass any parameter.
    • Arrow function doesn't work.
    • Any capital letter (which is invalid for minecraft function name) will be automatically be turn into lower case, which means it is not case sensitive. For example, deathMessage will override deathmessage
function [<directory>.]<file_name>() {
    <command>;
    <command>;
    ...
}

Output:

[<directory>/]<file_name>.mcfunction

<command>;
<command>;
...

Example:

function utils.chat.spamChat() {
    tellraw @a "SPAM 1";
    tellraw @a "SPAM 2";
    tellraw @a "SPAM 2";
}

Output:

utils/chat/spamchat.mcfunction

tellraw @a "SPAM 1"
tellraw @a "SPAM 2"
tellraw @a "SPAM 2"
  • 2. Function Calling
    • You can't pass any argument.
    • Any capital letter (which is invalid for minecraft function name) will be automatically be turn into lower case, which means it is not case sensitive. For example, deathMessage() is the same as deathmessage()
[<directory>.]<file_name>();

Output:

function namespace:[<directory>/]<file_name>

Example:

execute as @a run utils.chat.spamChat();

Output:

execute as @a run function namespace:utils/chat/spamchat
  • 3. Function Grouping
    • The syntax uses class but it is not a real "class".
    • Will add extra layers of directory/namespace to any function inside it.
    • Doesn't affect normal commands inside it.
    • Do not stack classes on top of each other (class inside class inside class...)
class [<directory>.]<folder_name> {
    function [<directory>/]<file_name>() {
        <command>;
        <command>;
        ...
    }
    <command>;
    <command>;
    ....
}

Output:

__load__.mcfunction

<command>;
<command>;
...

[<directory>/]<folder_name>/[<directory>/]<file_name>.mcfunction

<command>;
<command>;
....

For now, I don't recommend using "class".

Flow controlling

  • 1. If, Else
    • Automatically generate anonymous function(s) with integer name.
    • Allow JavaScript's if/else syntax
    • Even if the first condition is met, the rest will still need to check a scoreboard
    • If there's only if and no else, compiler will turn it into a vanilla execute if command.
if (<condition>) { 
    <command>;
    <command>;
    ...
} else if (<condition>) {
    <command>;
    <command>;
    ...
} else if (<condition>) {
    <command>;
    <command>;
    ...
} else {
    <command>;
    <command>;
    ...
}

Output:

scoreboard players set __tmp__ __variable__ 0
execute if <condition> run function namespace:__private__/if_else/0
execute if score __tmp__ __variable__ matches 0 if <condition> run function namespace:__private__/if_else/1
execute if score __tmp__ __variable__ matches 0 if <condition> run function namespace:__private__/if_else/2
execute if score __tmp__ __variable__ matches 0 run function namespace:__private__/if_else/3

__private__/if_else/0.mcfunction

scoreboard players set __tmp__ __variable__ 1
<command>;
<command>;
...

__private__/if_else/1.mcfunction

scoreboard players set __tmp__ __variable__ 1
<command>;
<command>;
...

__private__/if_else/2.mcfunction

scoreboard players set __tmp__ __variable__ 1
<command>;
<command>;
...

__private__/if_else/3.mcfunction

<command>;
<command>;
...

Example:

function do_i_have_tag() {
    if (entity @s[tag=my_tag]) { 
        say I have tag!;
    } else {
        say I don't have tag!;
    }
}
execute as @a[team=my_team] run do_i_have_tag();

Output:

__load__.mcfunction

execute as @a[team=my_team] run function namespace:do_i_have_tag

do_i_have_tag.mcfunction

scoreboard players set __tmp__ __variable__ 0
execute if entity @s[tag=my_tag] run function namespace:__private__/if_else/11
execute if score __tmp__ __variable__ matches 0 run function namespace:__private__/if_else/12

__private__/if_else/11.mcfunction

scoreboard players set __tmp__ __variable__ 1
say I have tag!

__private__/if_else/12.mcfunction

say I don't have tag!

Built-in functions

  • 1. toString
    • turns variable into json for display (tellraw, title, etc.)
$<variable>.toString([<key>=(<value>|"<value>")])

Output:

{"score":{"name":"$<variable>","objective":"__variable__"},"key":(<value>|"<value>")}

Example:

$deathCount.toString(color="red", bold=true)

Output:

{"score":{"name":"$deathCount","objective":"__variable__"},"color":"red","bold":true}