Compare commits

...

3 commits

Author SHA1 Message Date
4e797fc0db fix: add missing math:lteq function (#3)
This PR adds the missing `math:lteq` function which I forgot to create for the initial release.

Reviewed-on: https://codeberg.org/vlw/mcfstd/pulls/3
2026-03-13 20:20:30 +01:00
vlw
0385912729 docs: fix mistakes in the README (#2)
This PR fixes some mistakes in the README. It also removes the "example" colum from the function reference since I believe the description for each function should suffice and make the table more readable.

Reviewed-on: https://codeberg.org/vlw/mcfstd/pulls/2
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2026-03-13 20:20:16 +01:00
vlw
c4195baf85 refactor: bundle mcfstd as a datapack (#1)
So it turns out it will be much harder to create namespaced instances of this datapack like we initially thought. It might be worth considering in the future, but we would not be able to use any functions that we add with this library by the library itself, since the namespace change will make all internal function calls point to an undefined target. So we will bundle this as a datapack for now.

Reviewed-on: https://codeberg.org/vlw/mcfstd/pulls/1
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2026-03-13 20:02:31 +01:00
30 changed files with 40 additions and 51 deletions

View file

@ -24,26 +24,14 @@ execute unless std:out run return fail
**See the [function reference](#functions) for a full list of available functions**
# Installation
This is not a stand-alone datapack but is instead intended to be placed inside the `data/` directory of your own datapack. Clone this repository into the `data/` directory of your datapack.
Download the datapack as a zip from [the releases page](/vlw/mcfstd/releases) for the version that you require. Place the zip file directly into the `datapacks/` directory of your Minecraft world save directory.
```
git clonne http://codeberg.org/vlw/mcfstd
```
Enable this library in Minecraft by typing the following two commands
```mcfunction
reload
It is highly recommended that you rename the directory that contains this library after you clone it. This will prevent other datapacks that use this library from interfering with yours, and it also prevents your datapacks from interfering with theirs. This is important since other datapacks might use a version of this library that is not compatible with yours.
For example
datapack enable "file/mcfstd-X-X-X.zip" # Where X-X-X would be the version of the datapack
```
data/
mcfstd/
```
would become:
```
data/
std_my_datapack/
```
One that is done, reload your plugins with `/reload` and you should have access to mcfstd functions
# The standard output
This library contains a standard output that is used as an intermediary for arithmetic and comparison operations.
@ -78,12 +66,14 @@ execute if std:out run return run function my_function
```
# Functions
> [!Note]
> The functions under the `z_:` namespace are used internally by mcfstd and are not meant to be called directly unless you know what you are doing.
<table>
<tr>
<th>Function</th>
<th>Arguments</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<th colspan="4">Variables</th>
@ -93,7 +83,6 @@ execute if std:out run return run function my_function
<td rowspan="2"><code>var:set</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Set the value of a variable</td>
<td rowspan="2"><code>function var:set { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Value of the variable (int)</td>
@ -103,14 +92,12 @@ execute if std:out run return run function my_function
<td><code>var:unset</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td>Remove a varialbe</td>
<td><code>function var:unset { k: my_variable }</code></td>
</tr>
<!-- var:mv -->
<tr>
<td rowspan="2"><code>var:mv</code></td>
<td><code>k</code> Old variable name (string)</td>
<td rowspan="2">Rename a variable</td>
<td rowspan="2"><code>function var:mv { k: my_variable, v: my_renamed_variable }</code></td>
</tr>
<tr>
<td><code>v</code> New variable name (string)</td>
@ -120,21 +107,18 @@ execute if std:out run return run function my_function
<td><code>var:inc</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td>Increment the value of a variable</td>
<td><code>function var:inc { k: my_variable }</code></td>
</tr>
<!-- var:dec -->
<tr>
<td><code>var:dec</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td>Decrement the value of a variable</td>
<td><code>function var:dec { k: my_variable }</code></td>
</tr>
<!-- var:put -->
<tr>
<td><code>var:put</code></td>
<td>-</td>
<td>Put the current value of A into this variable</td>
<td><code>function var:put { k: my_variable }</code></td>
</tr>
<tr>
<th colspan="4">Arithmetic</th>
@ -144,50 +128,45 @@ execute if std:out run return run function my_function
<td rowspan="2"><code>math:add</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Add a number to the current value of a variable and store the result in A</td>
<td rowspan="2"><code>function math:add { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Number to add (string)</td>
<td><code>v</code> Number to add (int)</td>
</tr>
<!-- math:sub -->
<tr>
<td rowspan="2"><code>math:sub</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Subtract a number to the current value of a variable and store the result in A</td>
<td rowspan="2"><code>function math:sub { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Number to subtract (string)</td>
<td><code>v</code> Number to subtract (int)</td>
</tr>
<!-- math:mul -->
<tr>
<td rowspan="2"><code>math:mul</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Multiply a number with the current value of a variable and store the result in A</td>
<td rowspan="2"><code>function math:mul { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Number to multiply (string)</td>
<td><code>v</code> Number to multiply (int)</td>
</tr>
<!-- math:div -->
<tr>
<td rowspan="2"><code>math:div</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Divide a number with the current value of a variable and store the result in A</td>
<td rowspan="2"><code>function math:div { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Number to divide (string)</td>
<td><code>v</code> Number to divide (int)</td>
</tr>
<!-- math:mod -->
<tr>
<td rowspan="2"><code>math:mod</code></td>
<td><code>k</code> Name of the variable (string)</td>
<td rowspan="2">Modulo a number with the current value of a variable and store the result in A</td>
<td rowspan="2"><code>function math:mod { k: my_variable, v: 10 }</code></td>
</tr>
<tr>
<td><code>v</code> Number to modulo (string)</td>
<td><code>v</code> Number to modulo (int)</td>
</tr>
<tr>
<th colspan="4">Relation / Compare</th>
@ -196,51 +175,46 @@ execute if std:out run return run function my_function
<tr>
<td rowspan="2"><code>comp:eq</code></td>
<td><code>a</code> Name of the first variable (string)</td>
<td rowspan="2">Check if <code>a = b</code> and store the result in <code>stdout</code></td>
<td rowspan="2"><code>function comp:eq { a: my_variable, b: my_other_variable }</code></td>
<td rowspan="2">Check if <code>a = b</code> and store the result in <a href="#the-standard-output">the standard output</a></td>
</tr>
<tr>
<td><code>v</code> Name of the second variable (string)</td>
<td><code>b</code> Name of the second variable (string)</td>
</tr>
<!-- comp:gt -->
<tr>
<td rowspan="2"><code>comp:gt</code></td>
<td><code>a</code> Name of the first variable (string)</td>
<td rowspan="2">Check if <code>a > b</code> and store the result in <code>stdout</code></td>
<td rowspan="2"><code>function comp:gt { a: my_variable, b: my_other_variable }</code></td>
<td rowspan="2">Check if <code>a > b</code> and store the result in <a href="#the-standard-output">the standard output</a></td>
</tr>
<tr>
<td><code>v</code> Name of the second variable (string)</td>
<td><code>b</code> Name of the second variable (string)</td>
</tr>
<!-- comp:gteq -->
<tr>
<td rowspan="2"><code>comp:gteq</code></td>
<td><code>a</code> Name of the first variable (string)</td>
<td rowspan="2">Check if <code>a >= b</code> and store the result in <code>stdout</code></td>
<td rowspan="2"><code>function comp:gteq { a: my_variable, b: my_other_variable }</code></td>
<td rowspan="2">Check if <code>a >= b</code> and store the result in <a href="#the-standard-output">the standard output</a></td>
</tr>
<tr>
<td><code>v</code> Name of the second variable (string)</td>
<td><code>b</code> Name of the second variable (string)</td>
</tr>
<!-- comp:lt -->
<tr>
<td rowspan="2"><code>comp:lt</code></td>
<td><code>a</code> Name of the first variable (string)</td>
<td rowspan="2">Check if <code>a < b</code> and store the result in <code>stdout</code></td>
<td rowspan="2"><code>function comp:lt { a: my_variable, b: my_other_variable }</code></td>
<td rowspan="2">Check if <code>a < b</code> and store the result in <a href="#the-standard-output">the standard output</a></td>
</tr>
<tr>
<td><code>v</code> Name of the second variable (string)</td>
<td><code>b</code> Name of the second variable (string)</td>
</tr>
<!-- comp:lteq -->
<tr>
<td rowspan="2"><code>comp:lteq</code></td>
<td><code>a</code> Name of the first variable (string)</td>
<td rowspan="2">Check if <code>a <= b</code> and store the resulteq in <code>stdout</code></td>
<td rowspan="2"><code>function comp:lteq { a: my_variable, b: my_other_variable }</code></td>
<td rowspan="2">Check if <code>a <= b</code> and store the resulteq in <a href="#the-standard-output">the standard output</a></td>
</tr>
<tr>
<td><code>v</code> Name of the second variable (string)</td>
<td><code>b</code> Name of the second variable (string)</td>
</tr>
<tr>
<th colspan="4">Built-in operations</th>
@ -249,7 +223,6 @@ execute if std:out run return run function my_function
<tr>
<td><code>std:out</code></td>
<td>-</td>
<td>Will return true if the value of stdout is 0 (success)</td>
<td><code>execute if function std:out run function my_function</code></td>
<td>Will return nothing if the value of <a href="#the-standard-output">the standard output</a> is not <code>fail</code>. Else this function will also <code>fail</code></td>
</tr>
</table>

View file

@ -0,0 +1,7 @@
function z_:construct
$function comp:eq { a: $(a), b: $(b) }
execute unless function std:out run return fail
$function comp:lt { a: $(a), b: $(b) }
execute unless function std:out run return fail

9
pack.mcmeta Normal file
View file

@ -0,0 +1,9 @@
{
"pack": {
"description": {
"translate": "A standard library that adds variables, arithmetic, and relational operators to mcfunction"
},
"min_format": [88, 0],
"max_format": [88, 0]
}
}