mirror of
https://codeberg.org/vlw/mcfstd.git
synced 2026-05-28 12:17:50 +02:00
A standard library that adds variables, arithmetic, and relational operators to mcfunction
- mcfunction 100%
This PR moves all the functions related to variables into the `var` namespace. This is to allow for other standard functions to be added in the future (block and entity functions for example). Reviewed-on: https://codeberg.org/vlw/mcfstd/pulls/5 |
||
|---|---|---|
| data | ||
| .gitignore | ||
| LICENSE | ||
| pack.mcmeta | ||
| README.md | ||
Standard library for mcfunction
Make development of Minecraft datapacks in mcfunction easier with variables, arithmetic, and relational (comparison) operators.
# Set variable 'my_variable' to 10
function var:set { k: my_variable, v: 10 }
# Set variable 'my_other_variable' to 15
function var:set { k: my_other_variable, v: 15 }
# Add the value of 'my_other_variable' to 'my_variable'
function var:math/add { k: my_variable, v: my_other_variable }
# Subtract the integer value of 5 from 'my_variable'
function var:math/sub { k: my_variable, v: 5 }
# Test if 'my_variable' == 20
function var:comp/eq { k: my_variable, v: 20 }
# Run 'my_function' if 'my_variable' == 20
execute if function stdout:true run function my_function
# Run 'my_other_function' if 'my_variable' != 20
execute if function stdout:false run function my_other_function
See the function reference for a full list of available functions
Installation
Download the datapack as a zip from the releases page for the version that you require. Place the zip file directly into the datapacks/ directory of your Minecraft world save directory.
Enable this library in Minecraft by typing the following two commands
reload
datapack enable "file/mcfstd-X-X-X.zip" # Where X-X-X would be the version of the datapack
Functions
Note
All functions under the
z_std:namespace are used internally by this datapack and are not meant to be called directly unless you know what you are doing.
| Function | Arguments | Returns | Description |
|---|---|---|---|
| Variables | |||
var:set |
k Variable name [string] |
[void] |
Create a new variable with a name and value. Or set the value of an existing variable by name |
v Variable integer value [int] |
|||
var:unset |
k Variable name [string] |
[void] |
Remove a variable |
var:isset |
k Variable name [string] |
[bool] |
Check if a variable with the target name is set |
var:cp |
k Source variable name [string] |
[void] |
Copy the value of one variable to another variable. |
v Destination variable name (a new variable with this name will be created if it doesn't exist) [string] |
|||
var:mv |
k Variable name [string] |
[void] |
Rename a variable |
v New variable name [string] |
|||
var:inc |
k Variable name [string] |
[void] |
Increment the value of a variable |
var:dec |
k Variable name [string] |
[void] |
Decrement the value of a variable |
| Arithmetic | |||
var:math/add |
k Variable name [string] |
[void] |
Add an integer or the value of another variable to the target variable |
v Integer or variable name [int|string] |
|||
var:math/sub |
k Variable name [string] |
[void] |
Subtract an integer or the value of another variable to the target variable |
v Integer or variable name [int|string] |
|||
var:math/mul |
k Variable name [string] |
[void] |
Multiply an integer or the value of another variable to the target variable |
v Integer or variable name [int|string] |
|||
var:math/div |
k Variable name [string] |
[void] |
Divide the target variable with an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
var:math/mod |
k Variable name [string] |
[void] |
Modulo the target variable with an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
| Relation / Compare | |||
var:comp/eq |
k Variable name [string] |
[bool] |
Check if this variable value is equal to an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
var:comp/gt |
k Variable name [string] |
[bool] |
Check if this variable value is greater than an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
var:comp/gteq |
k Variable name [string] |
[bool] |
Check if this variable value is greater than or equal to an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
var:comp/lt |
k Variable name [string] |
[bool] |
Check if this variable value is less than an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
var:comp/lteq |
k Variable name [string] |
[bool] |
Check if this variable value is less than or equal to an integer or the value of another variable |
v Integer or variable name [int|string] |
|||
| Standard output | |||
stdout:true |
[void] |
[bool] |
Returns true if the previous comparison was successful. a == b |
stdout:false |
[void] |
[bool] |
Returns true if the previous comparison was unsuccessful. a != b |