Merge branch 'master' into display-title-additions
This commit is contained in:
88 files changed
+3088
-1017
No files matched your search
+320
-99
@@ -296,8 +296,8 @@ For more information, see: [EvalEx GitHub repository](https://github.com/uklimas
|
||||
`scarpet` provides a number of constants that can be used literally in scripts
|
||||
|
||||
* `null`: nothing, zilch, not even false
|
||||
* `true`: pure true, or just 1 (one)
|
||||
* `false`: false truth, or true falsth, 0 (zero) actually
|
||||
* `true`: pure true, can act as `1`
|
||||
* `false`: false truth, or true falsth, equals to `0`
|
||||
* `pi`: for the fans of perimeters, its a perimeter of an apple pi of diameter 1\. About 3.14
|
||||
* `euler`: clever guy. Derivative of its exponent is goto 1\. About 2.72
|
||||
|
||||
@@ -343,7 +343,7 @@ in [User Defined Functions and Program Control Flow](docs/scarpet/language/Funct
|
||||
1357-5 => 1352
|
||||
1357-'5' => 137
|
||||
3*'foo'-'o' => 'fff'
|
||||
l(1,3,5)+7 => l(8,10,12)
|
||||
[1,3,5]+7 => [8,10,12]
|
||||
</pre>
|
||||
|
||||
As you can see, values can behave differently when mixed with other types in the same expression.
|
||||
@@ -403,8 +403,8 @@ In Minecraft API portion `entity ~ feature` is a shortcode for `query(entity,fea
|
||||
any extra arguments.
|
||||
|
||||
<pre>
|
||||
l(1,2,3) ~ 2 => 1
|
||||
l(1,2,3) ~ 4 => null
|
||||
[1,2,3] ~ 2 => 1
|
||||
[1,2,3] ~ 4 => null
|
||||
|
||||
'foobar' ~ 'baz' => null
|
||||
'foobar' ~ '.b' => 'ob'
|
||||
@@ -430,10 +430,10 @@ Or an example to find if a player has specific enchantment on a held axe (either
|
||||
|
||||
<pre>
|
||||
global_get_enchantment(p, ench) -> (
|
||||
$ for(l('main','offhand'),
|
||||
$ for(['main','offhand'],
|
||||
$ holds = query(p, 'holds', _);
|
||||
$ if( holds,
|
||||
$ l(what, count, nbt) = holds;
|
||||
$ [what, count, nbt] = holds;
|
||||
$ if( what ~ '_axe' && nbt ~ ench,
|
||||
$ lvl = max(lvl, number(nbt ~ '(?<=lvl:)\\d') )
|
||||
$ )
|
||||
@@ -470,8 +470,8 @@ Examples:
|
||||
'foo'*3 => 'foofoofoo'
|
||||
'foofoofoo' / 3 => 'foo'
|
||||
'foofoofoo'-'o' => 'fff'
|
||||
l(1,2,3)+1 => l(2,3,4)
|
||||
b = l(100,63,100); b+l(10,0,10) => l(110,63,110)
|
||||
[1,2,3]+1 => [2,3,4]
|
||||
b = [100,63,100]; b+[10,0,10] => [110,63,110]
|
||||
{'a' -> 1} + {'b' -> 2} => {'a' -> 1, 'b' -> 2}
|
||||
</pre>
|
||||
|
||||
@@ -513,11 +513,12 @@ second operand is not necessary, it won't be evaluated, which means one can use
|
||||
case of success returns first positive operand (`||`) or last one (`&&`).
|
||||
|
||||
<pre>
|
||||
true || false => 1
|
||||
null || false => 0
|
||||
null != false || run('kill gnembon') => 1 // gnembon survives
|
||||
null != false && run('kill gnembon') => 0 // when cheats not allowed
|
||||
null != false && run('kill gnembon') => 1 // gnembon dies, cheats allowed
|
||||
true || false => true
|
||||
null || false => false
|
||||
false || null => null
|
||||
null != false || run('kill gnembon') // gnembon survives
|
||||
null != false && run('kill gnembon') // when cheats not allowed
|
||||
null != false && run('kill gnembon') // gnembon dies, cheats allowed
|
||||
</pre>
|
||||
|
||||
### `Assignment Operators = <> +=`
|
||||
@@ -531,11 +532,11 @@ require rewriting of the array anyways.
|
||||
|
||||
<pre>
|
||||
a = 5 => a == 5
|
||||
l(a,b,c) = l(3,4,5) => a==3, b==4, c==5
|
||||
l(minx,maxx) = sort(xi,xj); // minx assumes min(xi, xj) and maxx, max(xi, xj)
|
||||
l(a,b,c,d,e,f) = l(range(6)); l(a,b,c) <> l(d,e,f); l(a,b,c,d,e,f) => [3,4,5,0,1,2]
|
||||
a = l(1,2,3); a += 4 => [1,2,3,4]
|
||||
a = l(1,2,3,4); a = filter(a,_!=2) => [1,3,4]
|
||||
[a,b,c] = [3,4,5] => a==3, b==4, c==5
|
||||
[minx,maxx] = sort(xi,xj); // minx assumes min(xi, xj) and maxx, max(xi, xj)
|
||||
[a,b,c,d,e,f] = [range(6)]; [a,b,c] <> [d,e,f]; [a,b,c,d,e,f] => [3,4,5,0,1,2]
|
||||
a = [1,2,3]; a += 4 => [1,2,3,4]
|
||||
a = [1,2,3,4]; a = filter(a,_!=2) => [1,3,4]
|
||||
</pre>
|
||||
|
||||
### `Unary Operators - +`
|
||||
@@ -553,12 +554,12 @@ Require a number, flips the sign. One way to assert it's a number is by crashing
|
||||
flips boolean condition of the expression. Equivalent of `bool(expr)==false`
|
||||
|
||||
<pre>
|
||||
!true => 0
|
||||
!false => 1
|
||||
!null => 1
|
||||
!5 => 0
|
||||
!l() => 1
|
||||
!l(null) => 0
|
||||
!true => false
|
||||
!false => true
|
||||
!null => true
|
||||
!5 => false
|
||||
!l() => true
|
||||
!l(null) => false
|
||||
</pre>
|
||||
# Arithmetic operations
|
||||
|
||||
@@ -696,30 +697,31 @@ as well as minecraft related concepts like `block`, `entity`, `nbt`, `text`.
|
||||
|
||||
### `bool(expr)`
|
||||
|
||||
Returns a boolean context of the expression. Note that there are no true/false values in scarpet. `true` is
|
||||
alias of 1, and `false` is 0\. Bool is also interpreting string values as boolean, which is different from other
|
||||
Returns a boolean context of the expression.
|
||||
Bool is also interpreting string values as boolean, which is different from other
|
||||
places where boolean context can be used. This can be used in places where API functions return string values to
|
||||
represent binary values
|
||||
represent binary values.
|
||||
|
||||
<pre>
|
||||
bool(pi) => 1
|
||||
bool(false) => 0
|
||||
bool('') => 0
|
||||
bool(l()) => 0
|
||||
bool(l('')) => 1
|
||||
bool('foo') => 1
|
||||
bool('false') => 0
|
||||
bool('nulL') => 0
|
||||
if('false',1,0) => 1
|
||||
bool(pi) => true
|
||||
bool(false) => false
|
||||
bool('') => false
|
||||
bool(l()) => false
|
||||
bool(l('')) => true
|
||||
bool('foo') => true
|
||||
bool('false') => false
|
||||
bool('nulL') => false
|
||||
if('false',1,0) => true
|
||||
</pre>
|
||||
|
||||
### `number(expr)`
|
||||
|
||||
Returns a numeric context of the expression. Can be used to read numbers from strings
|
||||
Returns a numeric context of the expression. Can be used to read numbers from strings, or other types
|
||||
|
||||
<pre>
|
||||
number(null) => null
|
||||
number(null) => 0
|
||||
number(false) => 0
|
||||
number(true) => 1
|
||||
number('') => null
|
||||
number('3.14') => 3.14
|
||||
number(l()) => 0
|
||||
@@ -747,15 +749,15 @@ Supported types (with `"%<?>"` syntax):
|
||||
* `%%`: '%' character
|
||||
|
||||
<pre>
|
||||
str(null) => null
|
||||
str(false) => 0
|
||||
str('') => null
|
||||
str('3.14') => 3.14
|
||||
str(l()) => 0
|
||||
str(l('')) => 1
|
||||
str('foo') => null
|
||||
str('3bar') => null
|
||||
str(2)+str(2) => 22
|
||||
str(null) => 'null'
|
||||
str(false) => 'false'
|
||||
str('') => ''
|
||||
str('3.14') => '3.14'
|
||||
str([]) => '[]'
|
||||
str(['']) => '[]'
|
||||
str('foo') => 'foo'
|
||||
str('3bar') => '3bar'
|
||||
str(2)+str(2) => '22'
|
||||
str('pi: %.2f',pi) => 'pi: 3.14'
|
||||
str('player at: %d %d %d',pos(player())) => 'player at: 567, -2423, 124'
|
||||
</pre>
|
||||
@@ -908,18 +910,24 @@ length('foo') => 3
|
||||
### `rand(expr), rand(expr, seed)`
|
||||
|
||||
returns a random number from `0.0` (inclusive) to `expr` (exclusive). In boolean context (in conditions,
|
||||
boolean functions, or `bool`), returns false if the randomly selected value is less than 1\. This means
|
||||
that `rand(2)` returns true half of the time and `rand(5)` returns true for 80% (4/5) of the time. If seed is not
|
||||
provided, uses a random seed. If seed is provided, each consecutive call to rand() will act like 'next' call to the
|
||||
same random object. Scarpet keeps track of up to 1024 custom random number generators, so if you exceed this number
|
||||
(per app), then your random sequence will revert to the beginning.
|
||||
boolean functions, or `bool`), returns false if the randomly selected value is less than 1. This means
|
||||
that `bool(rand(2))` returns true half of the time and `!rand(5)` returns true for 20% (1/5) of the time. If seed is not
|
||||
provided, uses a random seed that's shared across all scarpet apps.
|
||||
If seed is provided, each consecutive call to rand() will act like 'next' call to the
|
||||
same random object. Scarpet keeps track of up to 65536 custom random number generators (custom seeds, per app),
|
||||
so if you exceed this number, your random sequences will revert to the beginning and start over.
|
||||
|
||||
<pre>
|
||||
map(range(10), floor(rand(10))) => [5, 8, 0, 6, 9, 3, 9, 9, 1, 8]
|
||||
map(range(10), bool(rand(2))) => [1, 1, 1, 0, 0, 1, 1, 0, 0, 0]
|
||||
map(range(10), bool(rand(2))) => [false, false, true, false, false, false, true, false, true, false]
|
||||
map(range(10), str('%.1f',rand(_))) => [0.0, 0.4, 0.6, 1.9, 2.8, 3.8, 5.3, 2.2, 1.6, 5.6]
|
||||
</pre>
|
||||
|
||||
## `reset_seed(seed)`
|
||||
|
||||
Resets the sequence of the randomizer used by `rand` for this seed to its initial state. Returns a boolean value
|
||||
indicating if the given seed has been used or not.
|
||||
|
||||
### `perlin(x), perlin(x, y), perlin(x, y, z), perlin(x, y, z, seed)`
|
||||
|
||||
returns a noise value from `0.0` to `1.0` (roughly) for 1, 2 or 3 dimensional coordinate. The default seed it samples
|
||||
@@ -1217,12 +1225,12 @@ to `all(list,expr) <=> for(list,expr)==length(list)`. `expr` also receives bound
|
||||
and `continue` have no sense and cannot be used inside of `expr` body.
|
||||
|
||||
<pre>
|
||||
all([1,2,3], check_prime(_)) => 1
|
||||
all(neighbours(x,y,z), _=='stone') => 1 // if all neighbours of [x, y, z] are stone
|
||||
map(filter(rect(0,4,0,1000,0,1000), l(x,y,z)=pos(_); all(rect(x,y,z,1,0,1),_=='bedrock') ), pos(_) )
|
||||
all([1,2,3], check_prime(_)) => true
|
||||
all(neighbours(x,y,z), _=='stone') => true // if all neighbours of [x, y, z] are stone
|
||||
map(filter(rect(0,4,0,1000,0,1000), [x,y,z]=pos(_); all(rect(x,y,z,1,0,1),_=='bedrock') ), pos(_) )
|
||||
=> [[-298, 4, -703], [-287, 4, -156], [-269, 4, 104], [242, 4, 250], [-159, 4, 335], [-208, 4, 416], [-510, 4, 546], [376, 4, 806]]
|
||||
// find all 3x3 bedrock structures in the top bedrock layer
|
||||
map( filter( rect(0,4,0,1000,1,1000,1000,0,1000), l(x,y,z)=pos(_);
|
||||
map( filter( rect(0,4,0,1000,1,1000,1000,0,1000), [x,y,z]=pos(_);
|
||||
all(rect(x,y,z,1,0,1),_=='bedrock') && for(rect(x,y-1,z,1,1,1,1,0,1),_=='bedrock')<8),
|
||||
pos(_) ) => [[343, 3, -642], [153, 3, -285], [674, 3, 167], [-710, 3, 398]]
|
||||
// ditto, but requiring at most 7 bedrock block in the 18 blocks below them
|
||||
@@ -1475,15 +1483,73 @@ returns everywhere, but it would often lead to a messy code.
|
||||
|
||||
It terminates entire program passing `expr` as the result of the program execution, or null if omitted.
|
||||
|
||||
### `try(expr, catch_expr(_)?) ... throw(value?)`
|
||||
### `try(expr)` `try(expr, user_catch_expr)` `try(expr, type, catch_expr, type?, catch_expr?, ...)`
|
||||
|
||||
`try` function evaluates expression, and continues further unless `throw` function is called anywhere
|
||||
inside `expr`. In that case the `catch_expr` is evaluates with `_` set to the argument `throw` was called with.
|
||||
This mechanic accepts skipping thrown value - it throws null instead, and catch expression - then try returns
|
||||
null as well This mechanism allows to terminate large portion of a convoluted call stack and continue program
|
||||
execution. There is only one level of exceptions currently in carpet, so if the inner function also defines
|
||||
the `try` catchment area, it will received the exception first, but it can technically rethrow the value its
|
||||
getting for the outer scope. Unhandled throw acts like an exit statement.
|
||||
`try` evaluates expression, allowing capturing exceptions that would be thrown inside `expr` statement. The exceptions can be
|
||||
thrown explicitly using `throw()` or internally by scarpet where code is correct but detects illegal state. The 2-argument form
|
||||
catches only user-thrown exceptions and one argument call `try(expr)` is equivalent to `try(expr, null)`,
|
||||
or `try(expr, 'user_exception', null)`. If multiple `type-catch` pairs are defined, the execution terminates on the first
|
||||
applicable type for the exception thrown. Therefore, even if the caught exception matches multiple filters, only
|
||||
the first matching block will be executed.
|
||||
|
||||
Catch expressions are evaluated with
|
||||
`_` set to the value associated with the exception and `_trace` set to contain details about point of error (token, and line and
|
||||
column positions), call stack and local
|
||||
variables at the time of failure. The `type` will catch any exception of that type and any subtype of this type.
|
||||
|
||||
|
||||
You can use `try` mechanism to exit from large portion of a convoluted call stack and continue program execution, although catching
|
||||
exceptions is typically much more expensive comparing to not throwing them.
|
||||
|
||||
The `try` function allows you to catch some scarpet exceptions for cases covering invalid data, like invalid
|
||||
blocks, biomes, dimensions and other things, that may have been modified by datapacks, resourcepacks or other mods,
|
||||
or when an error is outside of the programmers scope, such as problems when reading or decoding files.
|
||||
|
||||
This is the hierarchy of the exceptions that could be thrown/caught in the with the `try` function:
|
||||
- `exception`: This is the base exception. Catching `'exception'` allows to catch everything that can be caught,
|
||||
but like everywhere else, doing that sounds like a bad idea.
|
||||
- `value_exception`: This is the parent for any exception that occurs due to an
|
||||
incorrect argument value provided to a built-in function
|
||||
- `unknown_item`, `unknown_block`, `unknown_biome`, `unknown_sound`, `unknown_particle`,
|
||||
`unknown_poi_type`, `unknown_dimension`, `unknown_structure`, `unknown_criterion`: Specific
|
||||
errors thrown when a specified internal name does not exist or is invalid.
|
||||
- `io_exception`: This is the parent for any exception that occurs due to an error handling external data.
|
||||
- `nbt_error`: Incorrect input/output NBT file.
|
||||
- `json_error`: Incorrect input/output JSON data.
|
||||
- `user_exception`: Exception thrown by default with `throw` function.
|
||||
|
||||
Synopsis:
|
||||
<pre>
|
||||
inner_call() ->
|
||||
(
|
||||
aaa = 'booyah';
|
||||
try(
|
||||
for (range(10), item_tags('stick'+_*'k'));
|
||||
,
|
||||
print(_trace) // not caught, only catching user_exceptions
|
||||
)
|
||||
);
|
||||
|
||||
outer_call() ->
|
||||
(
|
||||
try(
|
||||
inner_call()
|
||||
, 'exception', // catching everything
|
||||
print(_trace)
|
||||
)
|
||||
);
|
||||
</pre>
|
||||
Producing:
|
||||
```
|
||||
{stack: [[<app>, inner_call, 1, 14]], locals: {_a: 0, aaa: booyah, _: 1, _y: 0, _i: 1, _x: 0, _z: 0}, token: [item_tags, 5, 23]}
|
||||
```
|
||||
|
||||
### `throw(value?)`, `throw(type, value)`, `throw(subtype, type, value)`
|
||||
|
||||
Throws an exception that can be caught in a `try` block (see above). If ran without arguments, it will throw a `user_exception`
|
||||
passing `null` as the value to the `catch_expr`. With two arguments you can mimic any other exception type thrown in scarpet.
|
||||
With 3 arguments, you can specify a custom exception acting as a `subtype` of a provided `type`, allowing to customize `try`
|
||||
statements with custom exceptions.
|
||||
|
||||
### `if(cond, expr, cond?, expr?, ..., default?)`
|
||||
|
||||
@@ -1518,12 +1584,12 @@ In case to simplify the access with nested objects, you can add chain of address
|
||||
than calling it multiple times. `get(get(foo,a),b)` is equivalent to `get(foo, a, b)`, or `foo:a:b`.
|
||||
|
||||
<pre>
|
||||
get(l(range(10)), 5) => 5
|
||||
get(l(range(10)), -1) => 9
|
||||
get(l(range(10)), 10) => 0
|
||||
l(range(10)):93 => 3
|
||||
get([range(10)], 5) => 5
|
||||
get([range(10)], -1) => 9
|
||||
get([range(10)], 10) => 0
|
||||
[range(10)]:93 => 3
|
||||
get(player() ~ 'nbt', 'Health') => 20 // inefficient way to get player health, use player() ~ 'health' instead
|
||||
get(m( l('foo',2), l('bar',3), l('baz',4) ), 'bar') => 3
|
||||
get({ 'foo' -> 2, 'bar' -> 3, 'baz' -> 4 }, 'bar') => 3
|
||||
</pre>
|
||||
|
||||
### `has(container, address, ...), has(lvalue)`
|
||||
@@ -1595,13 +1661,13 @@ of the existing elements. Use `replace` to remove and replace existing element.
|
||||
and merges keys from `value` with the compound tag under the path
|
||||
|
||||
<pre>
|
||||
a = l(1, 2, 3); put(a, 1, 4); a => [1, 4, 3]
|
||||
a = l(1, 2, 3); put(a, null, 4); a => [1, 2, 3, 4]
|
||||
a = l(1, 2, 3); put(a, 1, 4, 'insert'); a => [1, 4, 2, 3]
|
||||
a = l(1, 2, 3); put(a, null, l(4, 5, 6), 'extend'); a => [1, 2, 3, 4, 5, 6]
|
||||
a = l(1, 2, 3); put(a, 1, l(4, 5, 6), 'extend'); a => [1, 4, 5, 6, 2, 3]
|
||||
a = l(l(0,0,0),l(0,0,0),l(0,0,0)); put(a.1, 1, 1); a => [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
|
||||
a = m(1,2,3,4); put(a, 5, null); a => {1: null, 2: null, 3: null, 4: null, 5: null}
|
||||
a = [1, 2, 3]; put(a, 1, 4); a => [1, 4, 3]
|
||||
a = [1, 2, 3]; put(a, null, 4); a => [1, 2, 3, 4]
|
||||
a = [1, 2, 3]; put(a, 1, 4, 'insert'); a => [1, 4, 2, 3]
|
||||
a = [1, 2, 3]; put(a, null, [4, 5, 6], 'extend'); a => [1, 2, 3, 4, 5, 6]
|
||||
a = [1, 2, 3]; put(a, 1, [4, 5, 6], 'extend'); a => [1, 4, 5, 6, 2, 3]
|
||||
a = [[0,0,0],[0,0,0],[0,0,0]]; put(a:1, 1, 1); a => [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
|
||||
a = {1,2,3,4}; put(a, 5, null); a => {1: null, 2: null, 3: null, 4: null, 5: null}
|
||||
tag = nbt('{}'); put(tag, 'BlockData.Properties', '[1,2,3,4]'); tag => {BlockData:{Properties:[1,2,3,4]}}
|
||||
tag = nbt('{a:[{lvl:3},{lvl:5},{lvl:2}]}'); put(tag, 'a[].lvl', 1); tag => {a:[{lvl:1},{lvl:1},{lvl:1}]}
|
||||
tag = nbt('{a:[{lvl:[1,2,3]},{lvl:[3,2,1]},{lvl:[4,5,6]}]}'); put(tag, 'a[].lvl', 1, 2); tag
|
||||
@@ -1682,10 +1748,10 @@ other parts. In that case consecutive calls to `slice` will refer to index `0` t
|
||||
cannot go back nor track where they are in the sequence (see examples).
|
||||
|
||||
<pre>
|
||||
slice([0,1,2,3,4,5], 1, 3) => [1, 2, 3]
|
||||
slice([0,1,2,3,4,5], 1, 3) => [1, 2]
|
||||
slice('foobar', 0, 1) => 'f'
|
||||
slice('foobar', 3) => 'bar'
|
||||
slice(range(10), 3, 5) => [3, 4, 5]
|
||||
slice(range(10), 3, 5) => [3, 4]
|
||||
slice(range(10), 5) => [5, 6, 7, 8, 9]
|
||||
r = range(100); [slice(r, 5, 7), slice(r, 1, 3)] => [[5, 6], [8, 9]]
|
||||
</pre>
|
||||
@@ -1720,7 +1786,7 @@ Primarily to be used in higher order functions
|
||||
|
||||
<pre>
|
||||
range(10) => [...]
|
||||
l(range(10)) => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
[range(10)] => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
map(range(10),_*_) => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
||||
reduce(range(10),_a+_, 0) => 45
|
||||
range(5,10) => [5, 6, 7, 8, 9]
|
||||
@@ -2077,6 +2143,8 @@ when it was used. Block values passed in various places like `scan` functions, e
|
||||
its properties are needed. This means that if the block at the location changes before its queried in the program this
|
||||
might result in getting the later state, which might not be desired. Consider the following example:
|
||||
|
||||
Throws `unknown_block` if provided input is not valid.
|
||||
|
||||
<pre>set(10,10,10,'stone');
|
||||
scan(10,10,10,0,0,0, b = _);
|
||||
set(10,10,10,'air');
|
||||
@@ -2106,6 +2174,8 @@ properties that the original source block may have contained.
|
||||
|
||||
The returned value is either the block state that has been set, or `false` if block setting was skipped, or failed
|
||||
|
||||
Throws `unknown_block` if provided block to set is not valid
|
||||
|
||||
<pre>
|
||||
set(0,5,0,'bedrock') => bedrock
|
||||
set(l(0,5,0), 'bedrock') => bedrock
|
||||
@@ -2184,6 +2254,8 @@ but doesn't open chests / containers, so have no effect on interactive blocks, l
|
||||
Returns true if placement/use was
|
||||
successful, false otherwise.
|
||||
|
||||
Throws `unknown_item` if `item` doesn't exist
|
||||
|
||||
<pre>
|
||||
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
||||
place_item('piston,x,y,z,'down') // places a piston facing down
|
||||
@@ -2202,6 +2274,8 @@ If type is `null`, POI at position is removed. In any case, previous POI is also
|
||||
Interestingly, `unemployed`, and `nitwit` are not used in the game, meaning, they could be used as permanent spatial
|
||||
markers for scarpet apps. `meeting` is the only one with increased max occupancy of 32.
|
||||
|
||||
Throws `unknown_poi` if the provided point of interest doesn't exist
|
||||
|
||||
### `set_biome(pos, biome_name, update=true)`
|
||||
|
||||
Changes the biome at that block position. if update is specified and false, then chunk will not be refreshed
|
||||
@@ -2212,6 +2286,8 @@ is only effective if you set it at y=0, and affects the entire column of. In the
|
||||
specific Y coordinate of the biome you want to change, and it affects roughly 4x4x4 area (give or take some random
|
||||
noise).
|
||||
|
||||
Throws `unknown_biome` if the `biome_name` doesn't exist.
|
||||
|
||||
### `update(pos)`
|
||||
|
||||
Causes a block update at position.
|
||||
@@ -2236,6 +2312,8 @@ In item context, `true` means that breaking item has no nbt to use, `null` indic
|
||||
considered broken in process, and `nbt` type value, for a resulting NBT tag on a hypothetical tool. Its up to the
|
||||
programmer to use that nbt to apply it where it belong
|
||||
|
||||
Throws `unknown_item` if `tool` doesn't exist.
|
||||
|
||||
Here is a sample code that can be used to mine blocks using items in player inventory, without using player context
|
||||
for mining. Obviously, in this case the use of `harvest` would be much more applicable:
|
||||
|
||||
@@ -2327,6 +2405,8 @@ back in state definition in various applications where block properties are requ
|
||||
|
||||
`block_state` can also accept block names as input, returning block's default state.
|
||||
|
||||
Throws `unknown_block` if the provided input is not valid.
|
||||
|
||||
<pre>
|
||||
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z) => {waterlogged: false, half: top, open: false, ...}
|
||||
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z,'half') => top
|
||||
@@ -2347,6 +2427,8 @@ Without arguments, returns list of available tags, with block supplied (either b
|
||||
of tags the block belongs to, and if a tag is specified, returns `null` if tag is invalid, `false` if this block doesn't belong
|
||||
to this tag, and `true` if the block belongs to the tag.
|
||||
|
||||
Throws `unknown_block` if `block` doesn't exist
|
||||
|
||||
### `block_data(pos)`
|
||||
|
||||
Return NBT string associated with specific location, or null if the block does not carry block data. Can be currently
|
||||
@@ -2355,16 +2437,18 @@ used to match specific information from it, or use it to copy to another block
|
||||
<pre> block_data(x,y,z) => '{TransferCooldown:0,x:450,y:68, ... }'
|
||||
</pre>
|
||||
|
||||
### `poi(pos), poi(pos, radius?, type?, status?, column?)`
|
||||
### `poi(pos), poi(pos, radius?, type?, status?, column_search?)`
|
||||
|
||||
Queries a POI (Point of Interest) at a given position, returning `null` if none is found, or tuple of poi type and its
|
||||
occupancy load. With optional `type`, `radius` and `status`, returns a list of POIs around `pos` within a
|
||||
given `radius`. If the `type` is specified, returns only poi types of that types, or everything if omitted or `'any'`.
|
||||
If `status` is specified (either `'any'`, `'available'`, or `'occupied'`) returns only POIs with that status.
|
||||
With `column` set to `true`, it will return all POIs in a cuboid with `radius` blocks away on x and z, in the entire
|
||||
With `column_search` set to `true`, it will return all POIs in a cuboid with `radius` blocks away on x and z, in the entire
|
||||
block column from 0 to 255. Default (`false`) returns POIs within a spherical area centered on `pos` and with `radius`
|
||||
radius.
|
||||
|
||||
All results of `poi` calls are returned in sorted order with respect to the euclidean distance to the requested center of `pos`.
|
||||
|
||||
The return format of the results is a list of poi type, occupancy load, and extra triple of coordinates.
|
||||
|
||||
Querying for POIs using the radius is the intended use of POI mechanics, and the ability of accessing individual POIs
|
||||
@@ -2381,9 +2465,9 @@ poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two
|
||||
|
||||
Without arguments, returns the list of biomes in the world.
|
||||
|
||||
With block, or name, returns the name of the biome in that position, or null, if provided biome is not valid.
|
||||
With block, or name, returns the name of the biome in that position, or throws `'unknown_biome'` if provided biome or block are not valid.
|
||||
|
||||
With an optional feature, it returns value for the specified attribute for that biome. Available and querable features include:
|
||||
With an optional feature, it returns value for the specified attribute for that biome. Available and queryable features include:
|
||||
* `'top_material'`: unlocalized block representing the top surface material
|
||||
* `'under_material'`: unlocalized block representing what sits below topsoil
|
||||
* `'category'`: the parent biome this biome is derived from. Possible values include:
|
||||
@@ -2772,6 +2856,7 @@ If structure is not specified, it will return a set of structure names that are
|
||||
as keys, and same type of map values as with a single structure call. An empty set or an empty map would indicate that nothing
|
||||
should be generated there.
|
||||
|
||||
Throws `unknown_structure` if structure doesn't exist.
|
||||
|
||||
### `structures(pos), structures(pos, structure_name)`
|
||||
|
||||
@@ -2805,6 +2890,8 @@ structure starts.
|
||||
Requires a `Structure Variant` or `Standard Structure` name (see above). If standard name is used, the variant of the
|
||||
structure may depend on the biome, otherwise the default structure for this type will be generated.
|
||||
|
||||
Throws `unknown_structure` if structure doesn't exist.
|
||||
|
||||
### `plop(pos, what)`
|
||||
|
||||
Plops a structure or a feature at a given `pos`, so block, triple position coordinates or a list of coordinates.
|
||||
@@ -2827,7 +2914,9 @@ All generated structures will retain their properties, like mob spawning, howeve
|
||||
itself has certain rules to spawn mobs, like plopping a nether fortress in the overworld will not spawn nether mobs,
|
||||
because nether mobs can spawn only in the nether, but plopped in the nether - will behave like a valid nether fortress.
|
||||
|
||||
### `custom_dimension(name, seed?)`
|
||||
### (deprecated) `custom_dimension(name, seed?)`
|
||||
|
||||
Deprecated by `create_datapack()` which can be used to setup custom dimensions
|
||||
|
||||
Ensures the dimension with the given `'name'` is available and configured with the given seed. It merely sets the world
|
||||
generator settings to the overworld, and the optional custom seed (or using current world seed, if not provided).
|
||||
@@ -3082,7 +3171,7 @@ Returns `true` if en entity is standing on firm ground and falling down due to t
|
||||
|
||||
### `query(e, 'name'), query(e, 'display_name'), query(e, 'custom_name'), query(e, 'type')`
|
||||
|
||||
String of entity name
|
||||
String of entity name or formatted text in the case of `display_name`
|
||||
|
||||
<pre>
|
||||
query(e,'name') => Leatherworker
|
||||
@@ -3627,6 +3716,10 @@ Requires a living entity as an argument.
|
||||
|
||||
Will make the entity jump once.
|
||||
|
||||
### `modify(e, 'swing')` `modify(e, 'swing', 'offhand')`
|
||||
|
||||
Makes the living entity swing their required limb.
|
||||
|
||||
### `modify(e, 'silent', boolean)`
|
||||
|
||||
Silences or unsilences the entity.
|
||||
@@ -3808,14 +3901,16 @@ an inventory, all API functions typically do nothing and return null.
|
||||
|
||||
Most items returned are in the form of a triple of item name, count, and nbt or the extra data associated with an item.
|
||||
|
||||
### item_list(tag?)
|
||||
### `item_list(tag?)`
|
||||
|
||||
With no arguments, returns a list of all items in the game. With an item tag provided, list items matching the tag, or `null` if tag is not valid.
|
||||
|
||||
### item_tags(item, tag?)
|
||||
### `item_tags(item, tag?)`
|
||||
|
||||
Returns list of tags the item belongs to, or, if tag is provided, `true` if an item maches the tag, `false` if it doesn't and `null` if that's not a valid tag
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
### `stack_limit(item)`
|
||||
|
||||
Returns number indicating what is the stack limit for the item. Its typically 1 (non-stackable), 16 (like buckets),
|
||||
@@ -3823,6 +3918,8 @@ or 64 - rest. It is recommended to consult this, as other inventory API function
|
||||
it is up to the programmer to keep it at bay. As of 1.13, game checks for negative numbers and setting an item to
|
||||
negative is the same as empty.
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
<pre>
|
||||
stack_limit('wooden_axe') => 1
|
||||
stack_limit('ender_pearl') => 16
|
||||
@@ -3833,6 +3930,8 @@ stack_limit('stone') => 64
|
||||
|
||||
Returns the string representing the category of a given item, like `building_blocks`, `combat`, or `tools`.
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
<pre>
|
||||
item_category('wooden_axe') => tools
|
||||
item_category('ender_pearl') => misc
|
||||
@@ -3955,6 +4054,8 @@ while( (slot = inventory_find(p, 'diamond', slot)) != null, 41, drop_item(p, slo
|
||||
inventory_drop(x,y,z, 0) => 64 // removed and spawned in the world a full stack of items
|
||||
</pre>
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
### `inventory_remove(inventory, item, amount?)`
|
||||
|
||||
Removes amount (defaults to 1) of item from inventory. If the inventory doesn't have the defined amount, nothing
|
||||
@@ -4349,13 +4450,14 @@ Displays or modifies individual scoreboard values. With no arguments, returns th
|
||||
With specified `objective`, lists all keys (players) associated with current objective, or `null` if objective does not exist.
|
||||
With specified `objective` and
|
||||
`key`, returns current value of the objective for a given player (key). With additional `value` sets a new scoreboard
|
||||
value, returning previous value associated with the `key`.
|
||||
value, returning previous value associated with the `key`. If the `value` is null, resets the scoreboard value.
|
||||
|
||||
### `scoreboard_add(objective, criterion?)`
|
||||
|
||||
Adds a new objective to scoreboard. If `criterion` is not specified, assumes `'dummy'`.
|
||||
If the objective already exists, changes the criterion of that objective and returns `false`. If the criterion was not specified but the objective already exists, returns the current criterion.
|
||||
If the objective was added, returns `true`. If nothing is affected, returns `null`
|
||||
Returns `true` if the objective was created, or `null` if an objective with the specified name already exists.
|
||||
|
||||
Throws `unknown_criterion` if criterion doesn't exist.
|
||||
|
||||
<pre>
|
||||
scoreboard_add('counter')
|
||||
@@ -4374,6 +4476,15 @@ for the objective.
|
||||
Sets display location for a specified `objective`. If `objective` is `null`, then display is cleared. If objective is invalid,
|
||||
returns `null`.
|
||||
|
||||
### `scoreboard_property(objective, property)` `scoreboard_property(objective, property, value)`
|
||||
|
||||
Reads a property of an `objective` or sets it to a `value` if specified. Available properties are:
|
||||
|
||||
* `criterion`
|
||||
* `display_name` (Formatted text supported)
|
||||
* `display_slot`: When reading, returns a list of slots this objective is displayed in, when modifying, displays the objective in the specified slot
|
||||
* `render_type`: Either `'integer'` or `'hearts'`, defaults to `'integer'` if invalid value specified
|
||||
|
||||
# Team
|
||||
|
||||
### `team_list()`, `team_list(team)`
|
||||
@@ -4512,29 +4623,40 @@ Collection of other methods that control smaller, yet still important aspects of
|
||||
|
||||
## Sounds
|
||||
|
||||
### `sound(name, pos, volume?, pitch?, mixer?)`
|
||||
### `sound()`, `sound(name, pos, volume?, pitch?, mixer?)`
|
||||
|
||||
Plays a specific sound `name`, at block or position `pos`, with optional `volume` and modified `pitch`, and under
|
||||
optional `mixer`. Default values for `volume`, `pitch` and `mixer` are `1.0`, `1.0`, and `master`.
|
||||
Valid mixer options are `master`, `music`, `record`, `weather`, `block`, `hostile`,`neutral`, `player`, `ambient`
|
||||
and `voice`. `pos` can be either a block, triple of coords, or a list of thee numbers. Uses the same options as a
|
||||
corresponding `playsound` command.
|
||||
|
||||
Used with no arguments, return the list of available sound names.
|
||||
|
||||
Throws `unknown_sound` if sound doesn't exist.
|
||||
|
||||
## Particles
|
||||
|
||||
### `particle(name, pos, count?. spread?, speed?, player?)`
|
||||
### `particle()`, `particle(name, pos, count?. spread?, speed?, player?)`
|
||||
|
||||
Renders a cloud of particles `name` centered around `pos` position, by default `count` 10 of them, default `speed`
|
||||
of 0, and to all players nearby, but these options can be changed via optional arguments. Follow vanilla `/particle`
|
||||
command on details on those options. Valid particle names are
|
||||
for example `'angry_villager', 'item diamond', 'block stone', 'dust 0.8 0.1 0.1 4'`.
|
||||
|
||||
Used with no arguments, return the list of available particle names. Note that some of the names do not correspond to a valid
|
||||
particle that can be fed to `particle(...)` function due to a fact that some particles need more configuration
|
||||
to be valid, like `dust`, `block` etc. Should be used as a reference only.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
### `particle_line(name, pos, pos2, density?, player?)`
|
||||
|
||||
Renders a line of particles from point `pos` to `pos2` with supplied density (defaults to 1), which indicates how far
|
||||
apart you would want particles to appear, so `0.1` means one every 10cm. If a player (or player name) is supplied, only
|
||||
that player will receive particles.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
### `particle_box(name, pos, pos2, density?, player?)`
|
||||
### `particle_rect` (deprecated)
|
||||
@@ -4542,6 +4664,8 @@ that player will receive particles.
|
||||
Renders a cuboid of particles between points `pos` and `pos2` with supplied density. If a player (or player name) is
|
||||
supplied, only that player will receive particles.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
## Markers
|
||||
|
||||
### `draw_shape(shape, duration, key?, value?, ... )`,
|
||||
@@ -4575,7 +4699,7 @@ Optional shared shape attributes:
|
||||
in the form of `0xRRGGBBAA`, with the default of `-1`, so white opaque, or `0xFFFFFFFF`.
|
||||
* `player` - name or player entity to send the shape to. If specified, the shapes will appear only for the specified
|
||||
player, otherwise it will be send to all players in the dimension.
|
||||
* `line` - line thickness, defaults to 2.0pt
|
||||
* `line` - (Deprecated) line thickness, defaults to 2.0pt. Not supported in 1.17's 3.2 core GL renderer.
|
||||
* `fill` - color for the faces, defaults to no fill. Use `color` attribute format
|
||||
* `follow` - entity, or player name. Shape will follow an entity instead of being static.
|
||||
Follow attribute requires all positional arguments to be relative to the entity and disallow
|
||||
@@ -4609,7 +4733,7 @@ Available shapes:
|
||||
* `align` - text alignment with regards to `pos`. Default is `center` (displayed text is
|
||||
centered with respect to `pos`), `left` (`pos` indicates beginning of text), and `right` (`pos`
|
||||
indicates the end of text).
|
||||
* `tilt` - additional rotation of the text on the canvas
|
||||
* `tilt`, `lean`, `turn` - additional rotations of the text on the canvas along all three axis
|
||||
* `indent`, `height`, `raise` - offsets for text rendering on X (`indent`), Y (`height`), and Z axis (`raise`)
|
||||
with regards to the plane of the text. One unit of these corresponds to 1 line spacing, which
|
||||
can be used to display multiple lines of text bound to the same `pos`
|
||||
@@ -4793,7 +4917,8 @@ Resource is identified by a path to the file.
|
||||
A path can contain letters, numbers, characters `-`, `+`, or `_`, and a folder separator: `'/'`. Any other characters are stripped
|
||||
from the name. Empty descriptors are invalid, except for `list_files` where it means the root folder.
|
||||
Do not add file extensions to the descriptor - extensions are inferred
|
||||
based on the `type` of the file.
|
||||
based on the `type` of the file. A path can have one `'.zip'` component indicating a zip folder allowing to read / write to and from
|
||||
zip files, although you cannot nest zip files in other zip files.
|
||||
|
||||
Resources can be located in the app specific space, or a shared space for all the apps. Accessing of app-specific
|
||||
resources is guaranteed to be isolated from other apps. Shared resources are... well, shared across all apes, meaning
|
||||
@@ -4807,7 +4932,7 @@ specific data directory is under `world/scripts/foo.data/...`, and shared data s
|
||||
|
||||
The default no-name app, via `/script run` command can only save/load/read files from the shared space.
|
||||
|
||||
Functions return `null` if an error is encounter or no file is present (for read, list and delete operations). Returns `true`
|
||||
Functions return `null` if no file is present (for read, list and delete operations). Returns `true`
|
||||
for success writes and deletes, and requested data, based on the file type, for read operations. It returns list of files
|
||||
for folder listing.
|
||||
|
||||
@@ -4828,6 +4953,14 @@ record to the file. Since files are closed after each write, sending multiple li
|
||||
write is beneficial for writing speed. To send multiple packs of data, either provide them flat or as a list in the
|
||||
third argument.
|
||||
|
||||
Throws:
|
||||
- `nbt_read_error`: When failed to read NBT file.
|
||||
- `json_read_error`: When failed to read JSON file. The exception data will contain details about the problem.
|
||||
- `io_exception`: For all other errors when handling data on disk not related to encoding issues
|
||||
|
||||
All other errors resulting of improper use of input arguments should result in `null` returned from the function, rather than exception
|
||||
thrown.
|
||||
|
||||
<pre>
|
||||
write_file('foo', 'shared_text, ['one', 'two']);
|
||||
write_file('foo', 'shared_text', 'three\n', 'four\n');
|
||||
@@ -4879,6 +5012,8 @@ specific data directory is under `world/scripts/foo.data/bar/../baz.nbt`, and sh
|
||||
|
||||
You can use app data to save non-vanilla information separately from the world and other scripts.
|
||||
|
||||
Throws `nbt_read_error` if failed to read app data.
|
||||
|
||||
### `store_app_data(tag)`
|
||||
|
||||
Note: `store_app_data(tag, file)` and `store_app_data(tag, file, shared?)` usages deprecated. Use `write_file` instead.
|
||||
@@ -4893,6 +5028,83 @@ Returns `true` if the file was saved successfully, `false` otherwise.
|
||||
|
||||
Uses the same file structure for exclusive app data, and shared data folder as `load_app_data`.
|
||||
|
||||
### `create_datapack(name, data)`
|
||||
|
||||
Creates and loads custom datapack. The data has to be a map representing the file structure and the content of the
|
||||
json files of the target pack.
|
||||
|
||||
Returns `null` if the pack with this name already exists or is loaded, meaning no change has been made.
|
||||
Returns `false` if adding of the datapack wasn't successful.
|
||||
Returns `true` if creation and loading of the datapack was successful. Loading of a datapack results in
|
||||
reloading of all other datapacks (vanilla restrictions, identical to /datapack enable), however unlike with `/reload`
|
||||
command, scarpet apps will not be reloaded by adding a datapack using `create_datapack`.
|
||||
|
||||
Currently, only json files are supported in the packs. `'pack.mcmeta'` file is added automatically.
|
||||
|
||||
Reloading of datapacks that define new dimensions is not implemented in vanilla. Vanilla game only loads
|
||||
dimension information on server start. `create_datapack` is therefore a direct replacement of manually ploping of the specified
|
||||
file structure in a datapack file and calling `/datapack enable` on the new datapack with all its quirks and sideeffects
|
||||
(like no worldgen changes, reloading all other datapacks, etc.). To enable newly added custom dimensions, call much more
|
||||
experimental `check_hidden_dimensions()` after adding a datapack if needed.
|
||||
|
||||
Synopsis:
|
||||
<pre>
|
||||
script run create_datapack('foo',
|
||||
{
|
||||
'foo' -> {
|
||||
'bar.json' -> {
|
||||
'c' -> true,
|
||||
'd' -> false,
|
||||
'e' -> {'foo' -> [1,2,3]},
|
||||
'a' -> 'foobar',
|
||||
'b' -> 5
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
script run create_datapack('funky_world', {
|
||||
'data' -> {
|
||||
'minecraft' -> {
|
||||
'dimension' -> {
|
||||
'custom_ow.json' -> {
|
||||
'type' -> 'minecraft:the_end',
|
||||
'generator' -> {
|
||||
'biome_source' -> {
|
||||
'seed' -> 0,
|
||||
'large_biomes' -> false,
|
||||
'type' -> 'minecraft:vanilla_layered'
|
||||
},
|
||||
'seed' -> 0,
|
||||
'settings' -> 'minecraft:nether',
|
||||
'type' -> 'minecraft:noise'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
check_hidden_dimensions(); => ['funky_world']
|
||||
|
||||
</pre>
|
||||
|
||||
### `enable_hidden_dimensions()`
|
||||
|
||||
The function reads current datapack settings detecting new dimensions defined by these datapacks that have not yet been added
|
||||
to the list of current dimensions and adds them so that they can be used and accessed right away. It doesn't matter how the
|
||||
datapacks have been added to the game, either with 'create_datapack()' or manually by dropping a datapack file and calling
|
||||
`/datapack enable` on it. Returns the list of valid dimension names / identifiers that has been added in the process.
|
||||
|
||||
Fine print: The function should be
|
||||
considered experimental. There 'should not be' (famous last words) any side-effects if no worlds are added. Already connected
|
||||
clients will not see suggestions for commands that use dimensions `/execute in <dim>` (vanilla client limitation)
|
||||
but all commands should work just fine with
|
||||
the new dimensions. Existing worlds that have gotten modified settings by the datapacks will not be reloaded or replaced.
|
||||
The usability of the dimensions added this way has not been fully tested, but it seems it works just fine. Generator settings
|
||||
for the new dimensions will not be added to `'level.dat'` but it will be added there automatically next time the game restarts by
|
||||
vanilla. One could have said to use this method with caution, and the authors take no responsibility of any losses incurred due to
|
||||
mis-handlilng of the temporary added dimensions, yet the feature itself (custom dimensions) is clearly experimental for Mojang
|
||||
themselves, so that's about it.
|
||||
|
||||
### `tick_time()`
|
||||
|
||||
Returns server tick counter. Can be used to run certain operations every n-th ticks, or to count in-game time.
|
||||
@@ -4956,6 +5168,8 @@ Evaluates the expression `expr` with different dimension execution context. `smt
|
||||
world-localized block, so not `block('stone')`, or a string representing a dimension like:
|
||||
`'nether'`, `'the_nether'`, `'end'` or `'overworld'`, etc.
|
||||
|
||||
Throws `unknown_dimension` if provided dimension can't be found.
|
||||
|
||||
### `view_distance()`
|
||||
Returns the view distance of the server.
|
||||
|
||||
@@ -5010,11 +5224,12 @@ Available options in the scarpet app space:
|
||||
Relevant world related properties
|
||||
* `world_name` - name of the world
|
||||
* `world_seed` - a numeric seed of the world
|
||||
* `world_dimensions` - a list of dimensions in the world
|
||||
* `world_path` - full path to the world saves folder
|
||||
* `world_folder` - name of the direct folder in the saves that holds world files
|
||||
* `world_carpet_rules` - returns all Carpet rules in a map form (`rule`->`value`). Note that the values are always returned as strings, so you can't do boolean comparisons directly. Includes rules from extensions with their namespace (`namespace:rule`->`value`). You can later listen to rule changes with the `on_carpet_rule_changes(rule, newValue)` event.
|
||||
* `world_gamerules` - returns all gamerules in a map form (`rule`->`value`). Like carpet rules, values are returned as strings, so you can use appropriate value conversions using `bool()` or `number()` to convert them to other values. Gamerules are read-only to discourage app programmers to mess up with the settings intentionally applied by server admins. Isn't that just super annoying when a datapack messes up with your gamerule settings? It is still possible to change them though using `run('gamerule ...`.
|
||||
|
||||
* `world_spawn_point` - world spawn point
|
||||
|
||||
Relevant gameplay related properties
|
||||
* `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'`
|
||||
@@ -5025,7 +5240,13 @@ Available options in the scarpet app space:
|
||||
* `game_view_distance` - the view distance
|
||||
* `game_mod_name` - the name of the base mod. Expect `'fabric'`
|
||||
* `game_version` - base version of the game
|
||||
* `game_target` - target release version
|
||||
* `game_major_target` - major release target. For 1.12.2, that would be 12
|
||||
* `game_minor_reease` - minor release target. For 1.12.2, that woudl be 2
|
||||
* `game_protocol` - protocol version number
|
||||
* `game_pack_version` - datapack version number
|
||||
* `game_data_version` - data version of the game. Returns an integer, so it can be compared.
|
||||
* `game_stable` - indicating if its a production release or a snapshot
|
||||
|
||||
Server related properties
|
||||
* `server_motd` - the motd of the server visible when joining
|
||||
|
||||
@@ -4,29 +4,40 @@ Collection of other methods that control smaller, yet still important aspects of
|
||||
|
||||
## Sounds
|
||||
|
||||
### `sound(name, pos, volume?, pitch?, mixer?)`
|
||||
### `sound()`, `sound(name, pos, volume?, pitch?, mixer?)`
|
||||
|
||||
Plays a specific sound `name`, at block or position `pos`, with optional `volume` and modified `pitch`, and under
|
||||
optional `mixer`. Default values for `volume`, `pitch` and `mixer` are `1.0`, `1.0`, and `master`.
|
||||
Valid mixer options are `master`, `music`, `record`, `weather`, `block`, `hostile`,`neutral`, `player`, `ambient`
|
||||
and `voice`. `pos` can be either a block, triple of coords, or a list of thee numbers. Uses the same options as a
|
||||
corresponding `playsound` command.
|
||||
|
||||
Used with no arguments, return the list of available sound names.
|
||||
|
||||
Throws `unknown_sound` if sound doesn't exist.
|
||||
|
||||
## Particles
|
||||
|
||||
### `particle(name, pos, count?. spread?, speed?, player?)`
|
||||
### `particle()`, `particle(name, pos, count?. spread?, speed?, player?)`
|
||||
|
||||
Renders a cloud of particles `name` centered around `pos` position, by default `count` 10 of them, default `speed`
|
||||
of 0, and to all players nearby, but these options can be changed via optional arguments. Follow vanilla `/particle`
|
||||
command on details on those options. Valid particle names are
|
||||
for example `'angry_villager', 'item diamond', 'block stone', 'dust 0.8 0.1 0.1 4'`.
|
||||
|
||||
Used with no arguments, return the list of available particle names. Note that some of the names do not correspond to a valid
|
||||
particle that can be fed to `particle(...)` function due to a fact that some particles need more configuration
|
||||
to be valid, like `dust`, `block` etc. Should be used as a reference only.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
### `particle_line(name, pos, pos2, density?, player?)`
|
||||
|
||||
Renders a line of particles from point `pos` to `pos2` with supplied density (defaults to 1), which indicates how far
|
||||
apart you would want particles to appear, so `0.1` means one every 10cm. If a player (or player name) is supplied, only
|
||||
that player will receive particles.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
### `particle_box(name, pos, pos2, density?, player?)`
|
||||
### `particle_rect` (deprecated)
|
||||
@@ -34,6 +45,8 @@ that player will receive particles.
|
||||
Renders a cuboid of particles between points `pos` and `pos2` with supplied density. If a player (or player name) is
|
||||
supplied, only that player will receive particles.
|
||||
|
||||
Throws `unknown_particle` if particle doesn't exist.
|
||||
|
||||
## Markers
|
||||
|
||||
### `draw_shape(shape, duration, key?, value?, ... )`,
|
||||
@@ -67,7 +80,7 @@ Optional shared shape attributes:
|
||||
in the form of `0xRRGGBBAA`, with the default of `-1`, so white opaque, or `0xFFFFFFFF`.
|
||||
* `player` - name or player entity to send the shape to. If specified, the shapes will appear only for the specified
|
||||
player, otherwise it will be send to all players in the dimension.
|
||||
* `line` - line thickness, defaults to 2.0pt
|
||||
* `line` - (Deprecated) line thickness, defaults to 2.0pt. Not supported in 1.17's 3.2 core GL renderer.
|
||||
* `fill` - color for the faces, defaults to no fill. Use `color` attribute format
|
||||
* `follow` - entity, or player name. Shape will follow an entity instead of being static.
|
||||
Follow attribute requires all positional arguments to be relative to the entity and disallow
|
||||
@@ -101,7 +114,7 @@ Available shapes:
|
||||
* `align` - text alignment with regards to `pos`. Default is `center` (displayed text is
|
||||
centered with respect to `pos`), `left` (`pos` indicates beginning of text), and `right` (`pos`
|
||||
indicates the end of text).
|
||||
* `tilt` - additional rotation of the text on the canvas
|
||||
* `tilt`, `lean`, `turn` - additional rotations of the text on the canvas along all three axis
|
||||
* `indent`, `height`, `raise` - offsets for text rendering on X (`indent`), Y (`height`), and Z axis (`raise`)
|
||||
with regards to the plane of the text. One unit of these corresponds to 1 line spacing, which
|
||||
can be used to display multiple lines of text bound to the same `pos`
|
||||
@@ -296,7 +309,8 @@ Resource is identified by a path to the file.
|
||||
A path can contain letters, numbers, characters `-`, `+`, or `_`, and a folder separator: `'/'`. Any other characters are stripped
|
||||
from the name. Empty descriptors are invalid, except for `list_files` where it means the root folder.
|
||||
Do not add file extensions to the descriptor - extensions are inferred
|
||||
based on the `type` of the file.
|
||||
based on the `type` of the file. A path can have one `'.zip'` component indicating a zip folder allowing to read / write to and from
|
||||
zip files, although you cannot nest zip files in other zip files.
|
||||
|
||||
Resources can be located in the app specific space, or a shared space for all the apps. Accessing of app-specific
|
||||
resources is guaranteed to be isolated from other apps. Shared resources are... well, shared across all apes, meaning
|
||||
@@ -310,7 +324,7 @@ specific data directory is under `world/scripts/foo.data/...`, and shared data s
|
||||
|
||||
The default no-name app, via `/script run` command can only save/load/read files from the shared space.
|
||||
|
||||
Functions return `null` if an error is encounter or no file is present (for read, list and delete operations). Returns `true`
|
||||
Functions return `null` if no file is present (for read, list and delete operations). Returns `true`
|
||||
for success writes and deletes, and requested data, based on the file type, for read operations. It returns list of files
|
||||
for folder listing.
|
||||
|
||||
@@ -331,6 +345,14 @@ record to the file. Since files are closed after each write, sending multiple li
|
||||
write is beneficial for writing speed. To send multiple packs of data, either provide them flat or as a list in the
|
||||
third argument.
|
||||
|
||||
Throws:
|
||||
- `nbt_read_error`: When failed to read NBT file.
|
||||
- `json_read_error`: When failed to read JSON file. The exception data will contain details about the problem.
|
||||
- `io_exception`: For all other errors when handling data on disk not related to encoding issues
|
||||
|
||||
All other errors resulting of improper use of input arguments should result in `null` returned from the function, rather than exception
|
||||
thrown.
|
||||
|
||||
<pre>
|
||||
write_file('foo', 'shared_text, ['one', 'two']);
|
||||
write_file('foo', 'shared_text', 'three\n', 'four\n');
|
||||
@@ -382,6 +404,8 @@ specific data directory is under `world/scripts/foo.data/bar/../baz.nbt`, and sh
|
||||
|
||||
You can use app data to save non-vanilla information separately from the world and other scripts.
|
||||
|
||||
Throws `nbt_read_error` if failed to read app data.
|
||||
|
||||
### `store_app_data(tag)`
|
||||
|
||||
Note: `store_app_data(tag, file)` and `store_app_data(tag, file, shared?)` usages deprecated. Use `write_file` instead.
|
||||
@@ -396,6 +420,83 @@ Returns `true` if the file was saved successfully, `false` otherwise.
|
||||
|
||||
Uses the same file structure for exclusive app data, and shared data folder as `load_app_data`.
|
||||
|
||||
### `create_datapack(name, data)`
|
||||
|
||||
Creates and loads custom datapack. The data has to be a map representing the file structure and the content of the
|
||||
json files of the target pack.
|
||||
|
||||
Returns `null` if the pack with this name already exists or is loaded, meaning no change has been made.
|
||||
Returns `false` if adding of the datapack wasn't successful.
|
||||
Returns `true` if creation and loading of the datapack was successful. Loading of a datapack results in
|
||||
reloading of all other datapacks (vanilla restrictions, identical to /datapack enable), however unlike with `/reload`
|
||||
command, scarpet apps will not be reloaded by adding a datapack using `create_datapack`.
|
||||
|
||||
Currently, only json files are supported in the packs. `'pack.mcmeta'` file is added automatically.
|
||||
|
||||
Reloading of datapacks that define new dimensions is not implemented in vanilla. Vanilla game only loads
|
||||
dimension information on server start. `create_datapack` is therefore a direct replacement of manually ploping of the specified
|
||||
file structure in a datapack file and calling `/datapack enable` on the new datapack with all its quirks and sideeffects
|
||||
(like no worldgen changes, reloading all other datapacks, etc.). To enable newly added custom dimensions, call much more
|
||||
experimental `check_hidden_dimensions()` after adding a datapack if needed.
|
||||
|
||||
Synopsis:
|
||||
<pre>
|
||||
script run create_datapack('foo',
|
||||
{
|
||||
'foo' -> {
|
||||
'bar.json' -> {
|
||||
'c' -> true,
|
||||
'd' -> false,
|
||||
'e' -> {'foo' -> [1,2,3]},
|
||||
'a' -> 'foobar',
|
||||
'b' -> 5
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
script run create_datapack('funky_world', {
|
||||
'data' -> {
|
||||
'minecraft' -> {
|
||||
'dimension' -> {
|
||||
'custom_ow.json' -> {
|
||||
'type' -> 'minecraft:the_end',
|
||||
'generator' -> {
|
||||
'biome_source' -> {
|
||||
'seed' -> 0,
|
||||
'large_biomes' -> false,
|
||||
'type' -> 'minecraft:vanilla_layered'
|
||||
},
|
||||
'seed' -> 0,
|
||||
'settings' -> 'minecraft:nether',
|
||||
'type' -> 'minecraft:noise'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
check_hidden_dimensions(); => ['funky_world']
|
||||
|
||||
</pre>
|
||||
|
||||
### `enable_hidden_dimensions()`
|
||||
|
||||
The function reads current datapack settings detecting new dimensions defined by these datapacks that have not yet been added
|
||||
to the list of current dimensions and adds them so that they can be used and accessed right away. It doesn't matter how the
|
||||
datapacks have been added to the game, either with 'create_datapack()' or manually by dropping a datapack file and calling
|
||||
`/datapack enable` on it. Returns the list of valid dimension names / identifiers that has been added in the process.
|
||||
|
||||
Fine print: The function should be
|
||||
considered experimental. There 'should not be' (famous last words) any side-effects if no worlds are added. Already connected
|
||||
clients will not see suggestions for commands that use dimensions `/execute in <dim>` (vanilla client limitation)
|
||||
but all commands should work just fine with
|
||||
the new dimensions. Existing worlds that have gotten modified settings by the datapacks will not be reloaded or replaced.
|
||||
The usability of the dimensions added this way has not been fully tested, but it seems it works just fine. Generator settings
|
||||
for the new dimensions will not be added to `'level.dat'` but it will be added there automatically next time the game restarts by
|
||||
vanilla. One could have said to use this method with caution, and the authors take no responsibility of any losses incurred due to
|
||||
mis-handlilng of the temporary added dimensions, yet the feature itself (custom dimensions) is clearly experimental for Mojang
|
||||
themselves, so that's about it.
|
||||
|
||||
### `tick_time()`
|
||||
|
||||
Returns server tick counter. Can be used to run certain operations every n-th ticks, or to count in-game time.
|
||||
@@ -459,6 +560,8 @@ Evaluates the expression `expr` with different dimension execution context. `smt
|
||||
world-localized block, so not `block('stone')`, or a string representing a dimension like:
|
||||
`'nether'`, `'the_nether'`, `'end'` or `'overworld'`, etc.
|
||||
|
||||
Throws `unknown_dimension` if provided dimension can't be found.
|
||||
|
||||
### `view_distance()`
|
||||
Returns the view distance of the server.
|
||||
|
||||
@@ -513,11 +616,12 @@ Available options in the scarpet app space:
|
||||
Relevant world related properties
|
||||
* `world_name` - name of the world
|
||||
* `world_seed` - a numeric seed of the world
|
||||
* `world_dimensions` - a list of dimensions in the world
|
||||
* `world_path` - full path to the world saves folder
|
||||
* `world_folder` - name of the direct folder in the saves that holds world files
|
||||
* `world_carpet_rules` - returns all Carpet rules in a map form (`rule`->`value`). Note that the values are always returned as strings, so you can't do boolean comparisons directly. Includes rules from extensions with their namespace (`namespace:rule`->`value`). You can later listen to rule changes with the `on_carpet_rule_changes(rule, newValue)` event.
|
||||
* `world_gamerules` - returns all gamerules in a map form (`rule`->`value`). Like carpet rules, values are returned as strings, so you can use appropriate value conversions using `bool()` or `number()` to convert them to other values. Gamerules are read-only to discourage app programmers to mess up with the settings intentionally applied by server admins. Isn't that just super annoying when a datapack messes up with your gamerule settings? It is still possible to change them though using `run('gamerule ...`.
|
||||
|
||||
* `world_spawn_point` - world spawn point
|
||||
|
||||
Relevant gameplay related properties
|
||||
* `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'`
|
||||
@@ -528,7 +632,13 @@ Available options in the scarpet app space:
|
||||
* `game_view_distance` - the view distance
|
||||
* `game_mod_name` - the name of the base mod. Expect `'fabric'`
|
||||
* `game_version` - base version of the game
|
||||
* `game_target` - target release version
|
||||
* `game_major_target` - major release target. For 1.12.2, that would be 12
|
||||
* `game_minor_reease` - minor release target. For 1.12.2, that woudl be 2
|
||||
* `game_protocol` - protocol version number
|
||||
* `game_pack_version` - datapack version number
|
||||
* `game_data_version` - data version of the game. Returns an integer, so it can be compared.
|
||||
* `game_stable` - indicating if its a production release or a snapshot
|
||||
|
||||
Server related properties
|
||||
* `server_motd` - the motd of the server visible when joining
|
||||
|
||||
@@ -21,6 +21,8 @@ when it was used. Block values passed in various places like `scan` functions, e
|
||||
its properties are needed. This means that if the block at the location changes before its queried in the program this
|
||||
might result in getting the later state, which might not be desired. Consider the following example:
|
||||
|
||||
Throws `unknown_block` if provided input is not valid.
|
||||
|
||||
<pre>set(10,10,10,'stone');
|
||||
scan(10,10,10,0,0,0, b = _);
|
||||
set(10,10,10,'air');
|
||||
@@ -50,6 +52,8 @@ properties that the original source block may have contained.
|
||||
|
||||
The returned value is either the block state that has been set, or `false` if block setting was skipped, or failed
|
||||
|
||||
Throws `unknown_block` if provided block to set is not valid
|
||||
|
||||
<pre>
|
||||
set(0,5,0,'bedrock') => bedrock
|
||||
set(l(0,5,0), 'bedrock') => bedrock
|
||||
@@ -128,6 +132,8 @@ but doesn't open chests / containers, so have no effect on interactive blocks, l
|
||||
Returns true if placement/use was
|
||||
successful, false otherwise.
|
||||
|
||||
Throws `unknown_item` if `item` doesn't exist
|
||||
|
||||
<pre>
|
||||
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
||||
place_item('piston,x,y,z,'down') // places a piston facing down
|
||||
@@ -146,6 +152,8 @@ If type is `null`, POI at position is removed. In any case, previous POI is also
|
||||
Interestingly, `unemployed`, and `nitwit` are not used in the game, meaning, they could be used as permanent spatial
|
||||
markers for scarpet apps. `meeting` is the only one with increased max occupancy of 32.
|
||||
|
||||
Throws `unknown_poi` if the provided point of interest doesn't exist
|
||||
|
||||
### `set_biome(pos, biome_name, update=true)`
|
||||
|
||||
Changes the biome at that block position. if update is specified and false, then chunk will not be refreshed
|
||||
@@ -156,6 +164,8 @@ is only effective if you set it at y=0, and affects the entire column of. In the
|
||||
specific Y coordinate of the biome you want to change, and it affects roughly 4x4x4 area (give or take some random
|
||||
noise).
|
||||
|
||||
Throws `unknown_biome` if the `biome_name` doesn't exist.
|
||||
|
||||
### `update(pos)`
|
||||
|
||||
Causes a block update at position.
|
||||
@@ -180,6 +190,8 @@ In item context, `true` means that breaking item has no nbt to use, `null` indic
|
||||
considered broken in process, and `nbt` type value, for a resulting NBT tag on a hypothetical tool. Its up to the
|
||||
programmer to use that nbt to apply it where it belong
|
||||
|
||||
Throws `unknown_item` if `tool` doesn't exist.
|
||||
|
||||
Here is a sample code that can be used to mine blocks using items in player inventory, without using player context
|
||||
for mining. Obviously, in this case the use of `harvest` would be much more applicable:
|
||||
|
||||
@@ -217,6 +229,13 @@ Causes a block to be harvested by a specified player entity. Honors player item
|
||||
tool if applicable. If the entity is not a valid player, no block gets destroyed. If a player is not allowed to break
|
||||
that block, a block doesn't get destroyed either.
|
||||
|
||||
### `create_explosion(pos, power?, mode?, fire?, source?, attacker?)`
|
||||
|
||||
Creates an explosion at a given position. Default values of optional parameters are: `'power'` - `4` (TNT power),
|
||||
`'mode'` (block breaking effect `none`, `destroy` or `break`: `break`, `fire` (whether extra fire blocks should be created) - `false`,
|
||||
`source` (exploding entity) - `null` and `attacker` (entity responsible for trigerring) - `null`. Explosions created with this
|
||||
endpoint cannot be captured with `__on_explosion` event, however they will be captured by `__on_explosion_outcome`.
|
||||
|
||||
### `weather()`,`weather(type)`,`weather(type, ticks)`
|
||||
|
||||
If called with no args, returns `'clear'`, `'rain` or `'thunder'` based on the current weather. If thundering, will
|
||||
@@ -271,6 +290,8 @@ back in state definition in various applications where block properties are requ
|
||||
|
||||
`block_state` can also accept block names as input, returning block's default state.
|
||||
|
||||
Throws `unknown_block` if the provided input is not valid.
|
||||
|
||||
<pre>
|
||||
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z) => {waterlogged: false, half: top, open: false, ...}
|
||||
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z,'half') => top
|
||||
@@ -291,6 +312,8 @@ Without arguments, returns list of available tags, with block supplied (either b
|
||||
of tags the block belongs to, and if a tag is specified, returns `null` if tag is invalid, `false` if this block doesn't belong
|
||||
to this tag, and `true` if the block belongs to the tag.
|
||||
|
||||
Throws `unknown_block` if `block` doesn't exist
|
||||
|
||||
### `block_data(pos)`
|
||||
|
||||
Return NBT string associated with specific location, or null if the block does not carry block data. Can be currently
|
||||
@@ -299,16 +322,18 @@ used to match specific information from it, or use it to copy to another block
|
||||
<pre> block_data(x,y,z) => '{TransferCooldown:0,x:450,y:68, ... }'
|
||||
</pre>
|
||||
|
||||
### `poi(pos), poi(pos, radius?, type?, status?, column?)`
|
||||
### `poi(pos), poi(pos, radius?, type?, status?, column_search?)`
|
||||
|
||||
Queries a POI (Point of Interest) at a given position, returning `null` if none is found, or tuple of poi type and its
|
||||
occupancy load. With optional `type`, `radius` and `status`, returns a list of POIs around `pos` within a
|
||||
given `radius`. If the `type` is specified, returns only poi types of that types, or everything if omitted or `'any'`.
|
||||
If `status` is specified (either `'any'`, `'available'`, or `'occupied'`) returns only POIs with that status.
|
||||
With `column` set to `true`, it will return all POIs in a cuboid with `radius` blocks away on x and z, in the entire
|
||||
With `column_search` set to `true`, it will return all POIs in a cuboid with `radius` blocks away on x and z, in the entire
|
||||
block column from 0 to 255. Default (`false`) returns POIs within a spherical area centered on `pos` and with `radius`
|
||||
radius.
|
||||
|
||||
All results of `poi` calls are returned in sorted order with respect to the euclidean distance to the requested center of `pos`.
|
||||
|
||||
The return format of the results is a list of poi type, occupancy load, and extra triple of coordinates.
|
||||
|
||||
Querying for POIs using the radius is the intended use of POI mechanics, and the ability of accessing individual POIs
|
||||
@@ -325,9 +350,9 @@ poi(x,y,z,5) => [['nether_portal',0,[7,8,9]],['nether_portal',0,[7,9,9]]] // two
|
||||
|
||||
Without arguments, returns the list of biomes in the world.
|
||||
|
||||
With block, or name, returns the name of the biome in that position, or null, if provided biome is not valid.
|
||||
With block, or name, returns the name of the biome in that position, or throws `'unknown_biome'` if provided biome or block are not valid.
|
||||
|
||||
With an optional feature, it returns value for the specified attribute for that biome. Available and querable features include:
|
||||
With an optional feature, it returns value for the specified attribute for that biome. Available and queryable features include:
|
||||
* `'top_material'`: unlocalized block representing the top surface material
|
||||
* `'under_material'`: unlocalized block representing what sits below topsoil
|
||||
* `'category'`: the parent biome this biome is derived from. Possible values include:
|
||||
@@ -716,6 +741,7 @@ If structure is not specified, it will return a set of structure names that are
|
||||
as keys, and same type of map values as with a single structure call. An empty set or an empty map would indicate that nothing
|
||||
should be generated there.
|
||||
|
||||
Throws `unknown_structure` if structure doesn't exist.
|
||||
|
||||
### `structures(pos), structures(pos, structure_name)`
|
||||
|
||||
@@ -749,6 +775,8 @@ structure starts.
|
||||
Requires a `Structure Variant` or `Standard Structure` name (see above). If standard name is used, the variant of the
|
||||
structure may depend on the biome, otherwise the default structure for this type will be generated.
|
||||
|
||||
Throws `unknown_structure` if structure doesn't exist.
|
||||
|
||||
### `plop(pos, what)`
|
||||
|
||||
Plops a structure or a feature at a given `pos`, so block, triple position coordinates or a list of coordinates.
|
||||
@@ -771,7 +799,9 @@ All generated structures will retain their properties, like mob spawning, howeve
|
||||
itself has certain rules to spawn mobs, like plopping a nether fortress in the overworld will not spawn nether mobs,
|
||||
because nether mobs can spawn only in the nether, but plopped in the nether - will behave like a valid nether fortress.
|
||||
|
||||
### `custom_dimension(name, seed?)`
|
||||
### (deprecated) `custom_dimension(name, seed?)`
|
||||
|
||||
Deprecated by `create_datapack()` which can be used to setup custom dimensions
|
||||
|
||||
Ensures the dimension with the given `'name'` is available and configured with the given seed. It merely sets the world
|
||||
generator settings to the overworld, and the optional custom seed (or using current world seed, if not provided).
|
||||
|
||||
@@ -177,7 +177,7 @@ Returns `true` if en entity is standing on firm ground and falling down due to t
|
||||
|
||||
### `query(e, 'name'), query(e, 'display_name'), query(e, 'custom_name'), query(e, 'type')`
|
||||
|
||||
String of entity name
|
||||
String of entity name or formatted text in the case of `display_name`
|
||||
|
||||
<pre>
|
||||
query(e,'name') => Leatherworker
|
||||
@@ -722,6 +722,10 @@ Requires a living entity as an argument.
|
||||
|
||||
Will make the entity jump once.
|
||||
|
||||
### `modify(e, 'swing')` `modify(e, 'swing', 'offhand')`
|
||||
|
||||
Makes the living entity swing their required limb.
|
||||
|
||||
### `modify(e, 'silent', boolean)`
|
||||
|
||||
Silences or unsilences the entity.
|
||||
|
||||
@@ -79,6 +79,19 @@ at the same time.
|
||||
Triggered right after a lightning strikes. Lightning entity as well as potential horseman trap would
|
||||
already be spawned at that point. `mode` is `true` if the lightning did cause a trap to spawn.
|
||||
|
||||
### `__on_explosion(pos, power, source, causer, mode, fire)`
|
||||
|
||||
Event triggered right before explosion takes place and before has any effect on the world. `source` can be an entity causing
|
||||
the explosion, and `causer` the entity triggering it,
|
||||
`mode` indicates block effects: `'none'`, `'break'` (drop all blocks), or `'destroy'` - drop few blocks. Event
|
||||
is not captured when `create_explosion()` is called.
|
||||
|
||||
### `__on_explosion_outcome(pos, power, source, causer, mode, fire, blocks, entities)`
|
||||
Triggered during the explosion, before any changes to the blocks are done,
|
||||
but the decision to blow up is already made and entities are already affected.
|
||||
The parameter `blocks` contains the list of blocks that will blow up (empty if `explosionNoBlockDamage` is set to `true`).
|
||||
The parameter `entities` contains the list of entities that have been affected by the explosion. Triggered even with `create_explosion()`.
|
||||
|
||||
### `__on_carpet_rule_changes(rule, new_value)`
|
||||
Triggered when a carpet mod rule is changed. It includes extension rules, not using default `/carpet` command,
|
||||
which will then be namespaced as `namespace:rule`.
|
||||
@@ -107,7 +120,7 @@ Example events that may cause it to happen is releasing a bow. The event is trig
|
||||
the request, however the `item_tuple` is provided representing the item that the player started with. You can use that and
|
||||
compare with the currently held item for a delta.
|
||||
|
||||
### `__on_player_finishes_using_item(player, item_tuple, hand))`
|
||||
### `__on_player_finishes_using_item(player, item_tuple, hand)`
|
||||
Player using of an item is done. This is controlled server side and is responsible for such events as finishing
|
||||
eating. The event is triggered after confirming that the action is valid, and sending the feedback back
|
||||
to the client, but before triggering it and its effects in game.
|
||||
|
||||
@@ -28,14 +28,16 @@ an inventory, all API functions typically do nothing and return null.
|
||||
|
||||
Most items returned are in the form of a triple of item name, count, and nbt or the extra data associated with an item.
|
||||
|
||||
### item_list(tag?)
|
||||
### `item_list(tag?)`
|
||||
|
||||
With no arguments, returns a list of all items in the game. With an item tag provided, list items matching the tag, or `null` if tag is not valid.
|
||||
|
||||
### item_tags(item, tag?)
|
||||
### `item_tags(item, tag?)`
|
||||
|
||||
Returns list of tags the item belongs to, or, if tag is provided, `true` if an item maches the tag, `false` if it doesn't and `null` if that's not a valid tag
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
### `stack_limit(item)`
|
||||
|
||||
Returns number indicating what is the stack limit for the item. Its typically 1 (non-stackable), 16 (like buckets),
|
||||
@@ -43,6 +45,8 @@ or 64 - rest. It is recommended to consult this, as other inventory API function
|
||||
it is up to the programmer to keep it at bay. As of 1.13, game checks for negative numbers and setting an item to
|
||||
negative is the same as empty.
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
<pre>
|
||||
stack_limit('wooden_axe') => 1
|
||||
stack_limit('ender_pearl') => 16
|
||||
@@ -53,6 +57,8 @@ stack_limit('stone') => 64
|
||||
|
||||
Returns the string representing the category of a given item, like `building_blocks`, `combat`, or `tools`.
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
<pre>
|
||||
item_category('wooden_axe') => tools
|
||||
item_category('ender_pearl') => misc
|
||||
@@ -175,6 +181,8 @@ while( (slot = inventory_find(p, 'diamond', slot)) != null, 41, drop_item(p, slo
|
||||
inventory_drop(x,y,z, 0) => 64 // removed and spawned in the world a full stack of items
|
||||
</pre>
|
||||
|
||||
Throws `unknown_item` if item doesn't exist.
|
||||
|
||||
### `inventory_remove(inventory, item, amount?)`
|
||||
|
||||
Removes amount (defaults to 1) of item from inventory. If the inventory doesn't have the defined amount, nothing
|
||||
|
||||
@@ -6,13 +6,14 @@ Displays or modifies individual scoreboard values. With no arguments, returns th
|
||||
With specified `objective`, lists all keys (players) associated with current objective, or `null` if objective does not exist.
|
||||
With specified `objective` and
|
||||
`key`, returns current value of the objective for a given player (key). With additional `value` sets a new scoreboard
|
||||
value, returning previous value associated with the `key`.
|
||||
value, returning previous value associated with the `key`. If the `value` is null, resets the scoreboard value.
|
||||
|
||||
### `scoreboard_add(objective, criterion?)`
|
||||
|
||||
Adds a new objective to scoreboard. If `criterion` is not specified, assumes `'dummy'`.
|
||||
If the objective already exists, changes the criterion of that objective and returns `false`. If the criterion was not specified but the objective already exists, returns the current criterion.
|
||||
If the objective was added, returns `true`. If nothing is affected, returns `null`
|
||||
Returns `true` if the objective was created, or `null` if an objective with the specified name already exists.
|
||||
|
||||
Throws `unknown_criterion` if criterion doesn't exist.
|
||||
|
||||
<pre>
|
||||
scoreboard_add('counter')
|
||||
@@ -31,6 +32,15 @@ for the objective.
|
||||
Sets display location for a specified `objective`. If `objective` is `null`, then display is cleared. If objective is invalid,
|
||||
returns `null`.
|
||||
|
||||
### `scoreboard_property(objective, property)` `scoreboard_property(objective, property, value)`
|
||||
|
||||
Reads a property of an `objective` or sets it to a `value` if specified. Available properties are:
|
||||
|
||||
* `criterion`
|
||||
* `display_name` (Formatted text supported)
|
||||
* `display_slot`: When reading, returns a list of slots this objective is displayed in, when modifying, displays the objective in the specified slot
|
||||
* `render_type`: Either `'integer'` or `'hearts'`, defaults to `'integer'` if invalid value specified
|
||||
|
||||
# Team
|
||||
|
||||
### `team_list()`, `team_list(team)`
|
||||
|
||||
@@ -23,12 +23,12 @@ In case to simplify the access with nested objects, you can add chain of address
|
||||
than calling it multiple times. `get(get(foo,a),b)` is equivalent to `get(foo, a, b)`, or `foo:a:b`.
|
||||
|
||||
<pre>
|
||||
get(l(range(10)), 5) => 5
|
||||
get(l(range(10)), -1) => 9
|
||||
get(l(range(10)), 10) => 0
|
||||
l(range(10)):93 => 3
|
||||
get([range(10)], 5) => 5
|
||||
get([range(10)], -1) => 9
|
||||
get([range(10)], 10) => 0
|
||||
[range(10)]:93 => 3
|
||||
get(player() ~ 'nbt', 'Health') => 20 // inefficient way to get player health, use player() ~ 'health' instead
|
||||
get(m( l('foo',2), l('bar',3), l('baz',4) ), 'bar') => 3
|
||||
get({ 'foo' -> 2, 'bar' -> 3, 'baz' -> 4 }, 'bar') => 3
|
||||
</pre>
|
||||
|
||||
### `has(container, address, ...), has(lvalue)`
|
||||
@@ -100,13 +100,13 @@ of the existing elements. Use `replace` to remove and replace existing element.
|
||||
and merges keys from `value` with the compound tag under the path
|
||||
|
||||
<pre>
|
||||
a = l(1, 2, 3); put(a, 1, 4); a => [1, 4, 3]
|
||||
a = l(1, 2, 3); put(a, null, 4); a => [1, 2, 3, 4]
|
||||
a = l(1, 2, 3); put(a, 1, 4, 'insert'); a => [1, 4, 2, 3]
|
||||
a = l(1, 2, 3); put(a, null, l(4, 5, 6), 'extend'); a => [1, 2, 3, 4, 5, 6]
|
||||
a = l(1, 2, 3); put(a, 1, l(4, 5, 6), 'extend'); a => [1, 4, 5, 6, 2, 3]
|
||||
a = l(l(0,0,0),l(0,0,0),l(0,0,0)); put(a.1, 1, 1); a => [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
|
||||
a = m(1,2,3,4); put(a, 5, null); a => {1: null, 2: null, 3: null, 4: null, 5: null}
|
||||
a = [1, 2, 3]; put(a, 1, 4); a => [1, 4, 3]
|
||||
a = [1, 2, 3]; put(a, null, 4); a => [1, 2, 3, 4]
|
||||
a = [1, 2, 3]; put(a, 1, 4, 'insert'); a => [1, 4, 2, 3]
|
||||
a = [1, 2, 3]; put(a, null, [4, 5, 6], 'extend'); a => [1, 2, 3, 4, 5, 6]
|
||||
a = [1, 2, 3]; put(a, 1, [4, 5, 6], 'extend'); a => [1, 4, 5, 6, 2, 3]
|
||||
a = [[0,0,0],[0,0,0],[0,0,0]]; put(a:1, 1, 1); a => [[0, 0, 0], [0, 1, 0], [0, 0, 0]]
|
||||
a = {1,2,3,4}; put(a, 5, null); a => {1: null, 2: null, 3: null, 4: null, 5: null}
|
||||
tag = nbt('{}'); put(tag, 'BlockData.Properties', '[1,2,3,4]'); tag => {BlockData:{Properties:[1,2,3,4]}}
|
||||
tag = nbt('{a:[{lvl:3},{lvl:5},{lvl:2}]}'); put(tag, 'a[].lvl', 1); tag => {a:[{lvl:1},{lvl:1},{lvl:1}]}
|
||||
tag = nbt('{a:[{lvl:[1,2,3]},{lvl:[3,2,1]},{lvl:[4,5,6]}]}'); put(tag, 'a[].lvl', 1, 2); tag
|
||||
@@ -187,10 +187,10 @@ other parts. In that case consecutive calls to `slice` will refer to index `0` t
|
||||
cannot go back nor track where they are in the sequence (see examples).
|
||||
|
||||
<pre>
|
||||
slice([0,1,2,3,4,5], 1, 3) => [1, 2, 3]
|
||||
slice([0,1,2,3,4,5], 1, 3) => [1, 2]
|
||||
slice('foobar', 0, 1) => 'f'
|
||||
slice('foobar', 3) => 'bar'
|
||||
slice(range(10), 3, 5) => [3, 4, 5]
|
||||
slice(range(10), 3, 5) => [3, 4]
|
||||
slice(range(10), 5) => [5, 6, 7, 8, 9]
|
||||
r = range(100); [slice(r, 5, 7), slice(r, 1, 3)] => [[5, 6], [8, 9]]
|
||||
</pre>
|
||||
@@ -225,7 +225,7 @@ Primarily to be used in higher order functions
|
||||
|
||||
<pre>
|
||||
range(10) => [...]
|
||||
l(range(10)) => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
[range(10)] => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
map(range(10),_*_) => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
||||
reduce(range(10),_a+_, 0) => 45
|
||||
range(5,10) => [5, 6, 7, 8, 9]
|
||||
|
||||
@@ -234,15 +234,73 @@ returns everywhere, but it would often lead to a messy code.
|
||||
|
||||
It terminates entire program passing `expr` as the result of the program execution, or null if omitted.
|
||||
|
||||
### `try(expr, catch_expr(_)?) ... throw(value?)`
|
||||
### `try(expr)` `try(expr, user_catch_expr)` `try(expr, type, catch_expr, type?, catch_expr?, ...)`
|
||||
|
||||
`try` function evaluates expression, and continues further unless `throw` function is called anywhere
|
||||
inside `expr`. In that case the `catch_expr` is evaluates with `_` set to the argument `throw` was called with.
|
||||
This mechanic accepts skipping thrown value - it throws null instead, and catch expression - then try returns
|
||||
null as well This mechanism allows to terminate large portion of a convoluted call stack and continue program
|
||||
execution. There is only one level of exceptions currently in carpet, so if the inner function also defines
|
||||
the `try` catchment area, it will received the exception first, but it can technically rethrow the value its
|
||||
getting for the outer scope. Unhandled throw acts like an exit statement.
|
||||
`try` evaluates expression, allowing capturing exceptions that would be thrown inside `expr` statement. The exceptions can be
|
||||
thrown explicitly using `throw()` or internally by scarpet where code is correct but detects illegal state. The 2-argument form
|
||||
catches only user-thrown exceptions and one argument call `try(expr)` is equivalent to `try(expr, null)`,
|
||||
or `try(expr, 'user_exception', null)`. If multiple `type-catch` pairs are defined, the execution terminates on the first
|
||||
applicable type for the exception thrown. Therefore, even if the caught exception matches multiple filters, only
|
||||
the first matching block will be executed.
|
||||
|
||||
Catch expressions are evaluated with
|
||||
`_` set to the value associated with the exception and `_trace` set to contain details about point of error (token, and line and
|
||||
column positions), call stack and local
|
||||
variables at the time of failure. The `type` will catch any exception of that type and any subtype of this type.
|
||||
|
||||
|
||||
You can use `try` mechanism to exit from large portion of a convoluted call stack and continue program execution, although catching
|
||||
exceptions is typically much more expensive comparing to not throwing them.
|
||||
|
||||
The `try` function allows you to catch some scarpet exceptions for cases covering invalid data, like invalid
|
||||
blocks, biomes, dimensions and other things, that may have been modified by datapacks, resourcepacks or other mods,
|
||||
or when an error is outside of the programmers scope, such as problems when reading or decoding files.
|
||||
|
||||
This is the hierarchy of the exceptions that could be thrown/caught in the with the `try` function:
|
||||
- `exception`: This is the base exception. Catching `'exception'` allows to catch everything that can be caught,
|
||||
but like everywhere else, doing that sounds like a bad idea.
|
||||
- `value_exception`: This is the parent for any exception that occurs due to an
|
||||
incorrect argument value provided to a built-in function
|
||||
- `unknown_item`, `unknown_block`, `unknown_biome`, `unknown_sound`, `unknown_particle`,
|
||||
`unknown_poi_type`, `unknown_dimension`, `unknown_structure`, `unknown_criterion`: Specific
|
||||
errors thrown when a specified internal name does not exist or is invalid.
|
||||
- `io_exception`: This is the parent for any exception that occurs due to an error handling external data.
|
||||
- `nbt_error`: Incorrect input/output NBT file.
|
||||
- `json_error`: Incorrect input/output JSON data.
|
||||
- `user_exception`: Exception thrown by default with `throw` function.
|
||||
|
||||
Synopsis:
|
||||
<pre>
|
||||
inner_call() ->
|
||||
(
|
||||
aaa = 'booyah';
|
||||
try(
|
||||
for (range(10), item_tags('stick'+_*'k'));
|
||||
,
|
||||
print(_trace) // not caught, only catching user_exceptions
|
||||
)
|
||||
);
|
||||
|
||||
outer_call() ->
|
||||
(
|
||||
try(
|
||||
inner_call()
|
||||
, 'exception', // catching everything
|
||||
print(_trace)
|
||||
)
|
||||
);
|
||||
</pre>
|
||||
Producing:
|
||||
```
|
||||
{stack: [[<app>, inner_call, 1, 14]], locals: {_a: 0, aaa: booyah, _: 1, _y: 0, _i: 1, _x: 0, _z: 0}, token: [item_tags, 5, 23]}
|
||||
```
|
||||
|
||||
### `throw(value?)`, `throw(type, value)`, `throw(subtype, type, value)`
|
||||
|
||||
Throws an exception that can be caught in a `try` block (see above). If ran without arguments, it will throw a `user_exception`
|
||||
passing `null` as the value to the `catch_expr`. With two arguments you can mimic any other exception type thrown in scarpet.
|
||||
With 3 arguments, you can specify a custom exception acting as a `subtype` of a provided `type`, allowing to customize `try`
|
||||
statements with custom exceptions.
|
||||
|
||||
### `if(cond, expr, cond?, expr?, ..., default?)`
|
||||
|
||||
|
||||
@@ -124,12 +124,12 @@ to `all(list,expr) <=> for(list,expr)==length(list)`. `expr` also receives bound
|
||||
and `continue` have no sense and cannot be used inside of `expr` body.
|
||||
|
||||
<pre>
|
||||
all([1,2,3], check_prime(_)) => 1
|
||||
all(neighbours(x,y,z), _=='stone') => 1 // if all neighbours of [x, y, z] are stone
|
||||
map(filter(rect(0,4,0,1000,0,1000), l(x,y,z)=pos(_); all(rect(x,y,z,1,0,1),_=='bedrock') ), pos(_) )
|
||||
all([1,2,3], check_prime(_)) => true
|
||||
all(neighbours(x,y,z), _=='stone') => true // if all neighbours of [x, y, z] are stone
|
||||
map(filter(rect(0,4,0,1000,0,1000), [x,y,z]=pos(_); all(rect(x,y,z,1,0,1),_=='bedrock') ), pos(_) )
|
||||
=> [[-298, 4, -703], [-287, 4, -156], [-269, 4, 104], [242, 4, 250], [-159, 4, 335], [-208, 4, 416], [-510, 4, 546], [376, 4, 806]]
|
||||
// find all 3x3 bedrock structures in the top bedrock layer
|
||||
map( filter( rect(0,4,0,1000,1,1000,1000,0,1000), l(x,y,z)=pos(_);
|
||||
map( filter( rect(0,4,0,1000,1,1000,1000,0,1000), [x,y,z]=pos(_);
|
||||
all(rect(x,y,z,1,0,1),_=='bedrock') && for(rect(x,y-1,z,1,1,1,1,0,1),_=='bedrock')<8),
|
||||
pos(_) ) => [[343, 3, -642], [153, 3, -285], [674, 3, 167], [-710, 3, 398]]
|
||||
// ditto, but requiring at most 7 bedrock block in the 18 blocks below them
|
||||
|
||||
@@ -16,7 +16,7 @@ in [User Defined Functions and Program Control Flow](docs/scarpet/language/Funct
|
||||
1357-5 => 1352
|
||||
1357-'5' => 137
|
||||
3*'foo'-'o' => 'fff'
|
||||
l(1,3,5)+7 => l(8,10,12)
|
||||
[1,3,5]+7 => [8,10,12]
|
||||
</pre>
|
||||
|
||||
As you can see, values can behave differently when mixed with other types in the same expression.
|
||||
@@ -76,8 +76,8 @@ In Minecraft API portion `entity ~ feature` is a shortcode for `query(entity,fea
|
||||
any extra arguments.
|
||||
|
||||
<pre>
|
||||
l(1,2,3) ~ 2 => 1
|
||||
l(1,2,3) ~ 4 => null
|
||||
[1,2,3] ~ 2 => 1
|
||||
[1,2,3] ~ 4 => null
|
||||
|
||||
'foobar' ~ 'baz' => null
|
||||
'foobar' ~ '.b' => 'ob'
|
||||
@@ -103,10 +103,10 @@ Or an example to find if a player has specific enchantment on a held axe (either
|
||||
|
||||
<pre>
|
||||
global_get_enchantment(p, ench) -> (
|
||||
$ for(l('main','offhand'),
|
||||
$ for(['main','offhand'],
|
||||
$ holds = query(p, 'holds', _);
|
||||
$ if( holds,
|
||||
$ l(what, count, nbt) = holds;
|
||||
$ [what, count, nbt] = holds;
|
||||
$ if( what ~ '_axe' && nbt ~ ench,
|
||||
$ lvl = max(lvl, number(nbt ~ '(?<=lvl:)\\d') )
|
||||
$ )
|
||||
@@ -143,8 +143,8 @@ Examples:
|
||||
'foo'*3 => 'foofoofoo'
|
||||
'foofoofoo' / 3 => 'foo'
|
||||
'foofoofoo'-'o' => 'fff'
|
||||
l(1,2,3)+1 => l(2,3,4)
|
||||
b = l(100,63,100); b+l(10,0,10) => l(110,63,110)
|
||||
[1,2,3]+1 => [2,3,4]
|
||||
b = [100,63,100]; b+[10,0,10] => [110,63,110]
|
||||
{'a' -> 1} + {'b' -> 2} => {'a' -> 1, 'b' -> 2}
|
||||
</pre>
|
||||
|
||||
@@ -186,11 +186,12 @@ second operand is not necessary, it won't be evaluated, which means one can use
|
||||
case of success returns first positive operand (`||`) or last one (`&&`).
|
||||
|
||||
<pre>
|
||||
true || false => 1
|
||||
null || false => 0
|
||||
null != false || run('kill gnembon') => 1 // gnembon survives
|
||||
null != false && run('kill gnembon') => 0 // when cheats not allowed
|
||||
null != false && run('kill gnembon') => 1 // gnembon dies, cheats allowed
|
||||
true || false => true
|
||||
null || false => false
|
||||
false || null => null
|
||||
null != false || run('kill gnembon') // gnembon survives
|
||||
null != false && run('kill gnembon') // when cheats not allowed
|
||||
null != false && run('kill gnembon') // gnembon dies, cheats allowed
|
||||
</pre>
|
||||
|
||||
### `Assignment Operators = <> +=`
|
||||
@@ -204,11 +205,11 @@ require rewriting of the array anyways.
|
||||
|
||||
<pre>
|
||||
a = 5 => a == 5
|
||||
l(a,b,c) = l(3,4,5) => a==3, b==4, c==5
|
||||
l(minx,maxx) = sort(xi,xj); // minx assumes min(xi, xj) and maxx, max(xi, xj)
|
||||
l(a,b,c,d,e,f) = l(range(6)); l(a,b,c) <> l(d,e,f); l(a,b,c,d,e,f) => [3,4,5,0,1,2]
|
||||
a = l(1,2,3); a += 4 => [1,2,3,4]
|
||||
a = l(1,2,3,4); a = filter(a,_!=2) => [1,3,4]
|
||||
[a,b,c] = [3,4,5] => a==3, b==4, c==5
|
||||
[minx,maxx] = sort(xi,xj); // minx assumes min(xi, xj) and maxx, max(xi, xj)
|
||||
[a,b,c,d,e,f] = [range(6)]; [a,b,c] <> [d,e,f]; [a,b,c,d,e,f] => [3,4,5,0,1,2]
|
||||
a = [1,2,3]; a += 4 => [1,2,3,4]
|
||||
a = [1,2,3,4]; a = filter(a,_!=2) => [1,3,4]
|
||||
</pre>
|
||||
|
||||
### `Unary Operators - +`
|
||||
@@ -226,10 +227,10 @@ Require a number, flips the sign. One way to assert it's a number is by crashing
|
||||
flips boolean condition of the expression. Equivalent of `bool(expr)==false`
|
||||
|
||||
<pre>
|
||||
!true => 0
|
||||
!false => 1
|
||||
!null => 1
|
||||
!5 => 0
|
||||
!l() => 1
|
||||
!l(null) => 0
|
||||
!true => false
|
||||
!false => true
|
||||
!null => true
|
||||
!5 => false
|
||||
!l() => true
|
||||
!l(null) => false
|
||||
</pre>
|
||||
@@ -14,30 +14,31 @@ as well as minecraft related concepts like `block`, `entity`, `nbt`, `text`.
|
||||
|
||||
### `bool(expr)`
|
||||
|
||||
Returns a boolean context of the expression. Note that there are no true/false values in scarpet. `true` is
|
||||
alias of 1, and `false` is 0\. Bool is also interpreting string values as boolean, which is different from other
|
||||
Returns a boolean context of the expression.
|
||||
Bool is also interpreting string values as boolean, which is different from other
|
||||
places where boolean context can be used. This can be used in places where API functions return string values to
|
||||
represent binary values
|
||||
represent binary values.
|
||||
|
||||
<pre>
|
||||
bool(pi) => 1
|
||||
bool(false) => 0
|
||||
bool('') => 0
|
||||
bool(l()) => 0
|
||||
bool(l('')) => 1
|
||||
bool('foo') => 1
|
||||
bool('false') => 0
|
||||
bool('nulL') => 0
|
||||
if('false',1,0) => 1
|
||||
bool(pi) => true
|
||||
bool(false) => false
|
||||
bool('') => false
|
||||
bool(l()) => false
|
||||
bool(l('')) => true
|
||||
bool('foo') => true
|
||||
bool('false') => false
|
||||
bool('nulL') => false
|
||||
if('false',1,0) => true
|
||||
</pre>
|
||||
|
||||
### `number(expr)`
|
||||
|
||||
Returns a numeric context of the expression. Can be used to read numbers from strings
|
||||
Returns a numeric context of the expression. Can be used to read numbers from strings, or other types
|
||||
|
||||
<pre>
|
||||
number(null) => null
|
||||
number(null) => 0
|
||||
number(false) => 0
|
||||
number(true) => 1
|
||||
number('') => null
|
||||
number('3.14') => 3.14
|
||||
number(l()) => 0
|
||||
@@ -65,15 +66,15 @@ Supported types (with `"%<?>"` syntax):
|
||||
* `%%`: '%' character
|
||||
|
||||
<pre>
|
||||
str(null) => null
|
||||
str(false) => 0
|
||||
str('') => null
|
||||
str('3.14') => 3.14
|
||||
str(l()) => 0
|
||||
str(l('')) => 1
|
||||
str('foo') => null
|
||||
str('3bar') => null
|
||||
str(2)+str(2) => 22
|
||||
str(null) => 'null'
|
||||
str(false) => 'false'
|
||||
str('') => ''
|
||||
str('3.14') => '3.14'
|
||||
str([]) => '[]'
|
||||
str(['']) => '[]'
|
||||
str('foo') => 'foo'
|
||||
str('3bar') => '3bar'
|
||||
str(2)+str(2) => '22'
|
||||
str('pi: %.2f',pi) => 'pi: 3.14'
|
||||
str('player at: %d %d %d',pos(player())) => 'player at: 567, -2423, 124'
|
||||
</pre>
|
||||
@@ -226,18 +227,24 @@ length('foo') => 3
|
||||
### `rand(expr), rand(expr, seed)`
|
||||
|
||||
returns a random number from `0.0` (inclusive) to `expr` (exclusive). In boolean context (in conditions,
|
||||
boolean functions, or `bool`), returns false if the randomly selected value is less than 1\. This means
|
||||
that `rand(2)` returns true half of the time and `rand(5)` returns true for 80% (4/5) of the time. If seed is not
|
||||
provided, uses a random seed. If seed is provided, each consecutive call to rand() will act like 'next' call to the
|
||||
same random object. Scarpet keeps track of up to 1024 custom random number generators, so if you exceed this number
|
||||
(per app), then your random sequence will revert to the beginning.
|
||||
boolean functions, or `bool`), returns false if the randomly selected value is less than 1. This means
|
||||
that `bool(rand(2))` returns true half of the time and `!rand(5)` returns true for 20% (1/5) of the time. If seed is not
|
||||
provided, uses a random seed that's shared across all scarpet apps.
|
||||
If seed is provided, each consecutive call to rand() will act like 'next' call to the
|
||||
same random object. Scarpet keeps track of up to 65536 custom random number generators (custom seeds, per app),
|
||||
so if you exceed this number, your random sequences will revert to the beginning and start over.
|
||||
|
||||
<pre>
|
||||
map(range(10), floor(rand(10))) => [5, 8, 0, 6, 9, 3, 9, 9, 1, 8]
|
||||
map(range(10), bool(rand(2))) => [1, 1, 1, 0, 0, 1, 1, 0, 0, 0]
|
||||
map(range(10), bool(rand(2))) => [false, false, true, false, false, false, true, false, true, false]
|
||||
map(range(10), str('%.1f',rand(_))) => [0.0, 0.4, 0.6, 1.9, 2.8, 3.8, 5.3, 2.2, 1.6, 5.6]
|
||||
</pre>
|
||||
|
||||
## `reset_seed(seed)`
|
||||
|
||||
Resets the sequence of the randomizer used by `rand` for this seed to its initial state. Returns a boolean value
|
||||
indicating if the given seed has been used or not.
|
||||
|
||||
### `perlin(x), perlin(x, y), perlin(x, y, z), perlin(x, y, z, seed)`
|
||||
|
||||
returns a noise value from `0.0` to `1.0` (roughly) for 1, 2 or 3 dimensional coordinate. The default seed it samples
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
`scarpet` provides a number of constants that can be used literally in scripts
|
||||
|
||||
* `null`: nothing, zilch, not even false
|
||||
* `true`: pure true, or just 1 (one)
|
||||
* `false`: false truth, or true falsth, 0 (zero) actually
|
||||
* `true`: pure true, can act as `1`
|
||||
* `false`: false truth, or true falsth, equals to `0`
|
||||
* `pi`: for the fans of perimeters, its a perimeter of an apple pi of diameter 1\. About 3.14
|
||||
* `euler`: clever guy. Derivative of its exponent is goto 1\. About 2.72
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ reduce
|
||||
relu
|
||||
replace
|
||||
replace_first
|
||||
reset_seed
|
||||
return
|
||||
round
|
||||
sec
|
||||
|
||||
@@ -17,9 +17,10 @@ brightness
|
||||
chunk_tickets
|
||||
convert_date
|
||||
crafting_remaining_item
|
||||
create_datapack
|
||||
create_explosion
|
||||
create_marker
|
||||
current_dimension
|
||||
custom_dimension
|
||||
day_time
|
||||
delete_file
|
||||
destroy
|
||||
@@ -28,6 +29,7 @@ display_title
|
||||
draw_shape
|
||||
drop_item
|
||||
emitted_light
|
||||
enable_hidden_dimensions
|
||||
encode_nbt
|
||||
entity_area
|
||||
entity_event
|
||||
@@ -96,6 +98,7 @@ scoreboard
|
||||
scoreboard_add
|
||||
scoreboard_remove
|
||||
scoreboard_display
|
||||
scoreboard_property
|
||||
tag_matches
|
||||
team_add
|
||||
team_leave
|
||||
|
||||
@@ -4,6 +4,7 @@ _i
|
||||
_x
|
||||
_y
|
||||
_z
|
||||
_trace
|
||||
euler
|
||||
false
|
||||
null
|
||||
|
||||
@@ -42,4 +42,6 @@ __on_player_deals_damage(player, amount, entity) ->
|
||||
__on_player_dies(player) ->
|
||||
__on_player_respawns(player) ->
|
||||
__on_player_disconnects(player, reason) ->
|
||||
__on_player_connects(player) ->
|
||||
__on_player_connects(player) ->
|
||||
__on_explosion(pos, power, source, causer, mode, fire) ->
|
||||
__on_explosion_outcome(pos, power, source, causer, mode, fire, blocks, entities) ->
|
||||
@@ -25,7 +25,7 @@
|
||||
<Keywords name="Folders in comment, middle"></Keywords>
|
||||
<Keywords name="Folders in comment, close"></Keywords>
|
||||
<Keywords name="Keywords1">
|
||||
not fact rand
|
||||
not fact rand reset_seed
|
||||
sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh
|
||||
rad deg
|
||||
log log10 log1p
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
var undef vars if loop map filter first all c_for for while reduce continue break
|
||||
|
||||
import call outer type hash_code bool number str length rand sleep time profile_expr lower upper title replace replace_first
|
||||
import call outer type hash_code bool number str length sleep time profile_expr lower upper title replace replace_first
|
||||
</Keywords>
|
||||
<Keywords name="Keywords2">
|
||||
block pos pos_offset solid air liquid flammable
|
||||
@@ -55,14 +55,16 @@
|
||||
set without_updates
|
||||
blocks_movement block_sound material map_colour block_state block_list block_tags block_data poi set_poi
|
||||
place_item set_biome biome loaded_status generation_status inhabited_time spawn_potential chunk_tickets
|
||||
structure_eligibility structures structure_references set_structure reset_chunk reload_chunk custom_dimension
|
||||
plop harvest destroy create_explosion
|
||||
structure_eligibility structures structure_references set_structure
|
||||
reset_chunk reload_chunk create_datapack enable_hidden_dimensions
|
||||
add_chunk_ticket
|
||||
|
||||
convert_date unix_time
|
||||
|
||||
display_title
|
||||
|
||||
scoreboard scoreboard_add scoreboard_remove scoreboard_display
|
||||
scoreboard scoreboard_add scoreboard_remove scoreboard_display scoreboard_property
|
||||
|
||||
team_add team_list team_remove team_leave team_property
|
||||
|
||||
@@ -82,7 +84,7 @@
|
||||
|
||||
run save tick_time world_time day_time last_tick_times game_tick current_dimension in_dimension view_distance
|
||||
|
||||
plop harvest destroy schedule nbt draw_shape create_marker remove_all_markers
|
||||
schedule nbt draw_shape create_marker remove_all_markers
|
||||
|
||||
load_app_data store_app_data read_file write_file delete_file list_files
|
||||
escape_nbt parse_nbt encode_nbt tag_matches statistic
|
||||
@@ -91,7 +93,7 @@
|
||||
</Keywords>
|
||||
<Keywords name="Keywords3">euler pi null true false</Keywords>
|
||||
<Keywords name="Keywords4">x y z p</Keywords>
|
||||
<Keywords name="Keywords5">_ _i _a _x _y _z</Keywords>
|
||||
<Keywords name="Keywords5">_ _i _a _x _y _z _trace</Keywords>
|
||||
<Keywords name="Keywords6">global_</Keywords>
|
||||
<Keywords name="Keywords7">
|
||||
__command
|
||||
@@ -139,6 +141,8 @@
|
||||
__on_player_respawns
|
||||
__on_player_disconnects
|
||||
__on_player_connects
|
||||
__on_explosion
|
||||
__on_explosion_outcome
|
||||
</Keywords>
|
||||
<Keywords name="Keywords8">$</Keywords>
|
||||
<Keywords name="Delimiters">00' 01\ 02' 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
|
||||
|
||||
Reference in new issue
Block a user