diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index a8ab3b82..9a537627 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -3350,6 +3350,9 @@ Returns current dimension that the script runs in. Evaluates the expression `expr` with different dimension execution context. `smth` can be an entity, world-localized block, so not `block('stone')`, or a string representing a dimension like: `'nether'`, `'the_nether'`, `'end'` or `'overworld'`, etc. + +### `view_distance()` +Returns the view distance of the server. ### `schedule(delay, function, args...)` diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 993620f7..a668dfa3 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -258,6 +258,9 @@ Returns current dimension that the script runs in. Evaluates the expression `expr` with different dimension execution context. `smth` can be an entity, world-localized block, so not `block('stone')`, or a string representing a dimension like: `'nether'`, `'the_nether'`, `'end'` or `'overworld'`, etc. + +### `view_distance()` +Returns the view distance of the server. ### `schedule(delay, function, args...)` diff --git a/docs/scarpet/resources/editors/idea/2.txt b/docs/scarpet/resources/editors/idea/2.txt index 279adc94..7e2a8d8a 100644 --- a/docs/scarpet/resources/editors/idea/2.txt +++ b/docs/scarpet/resources/editors/idea/2.txt @@ -102,6 +102,7 @@ ticks_randomly top transparent update +view_distance volume without_updates world_time \ No newline at end of file diff --git a/docs/scarpet/resources/editors/npp/scarpet.xml b/docs/scarpet/resources/editors/npp/scarpet.xml index 64158b61..67ceb72a 100644 --- a/docs/scarpet/resources/editors/npp/scarpet.xml +++ b/docs/scarpet/resources/editors/npp/scarpet.xml @@ -68,7 +68,7 @@ format logger sound particle particle_line particle_rect - run save tick_time world_time day_time last_tick_times game_tick seed current_dimension in_dimension + run save tick_time world_time day_time last_tick_times game_tick seed current_dimension in_dimension view_distance plop harvest destroy schedule nbt draw_shape create_marker remove_all_markers diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index cc3d4acc..e08efc78 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -2987,6 +2987,12 @@ public class CarpetExpression return (cc, tt) -> retval; }); + this.expr.addLazyFunction("view_distance", 0, (c, t, lv) -> { + ServerCommandSource s = ((CarpetContext)c).s; + Value retval = new NumericValue(s.getMinecraftServer().getPlayerManager().getViewDistance()); + return (cc, tt) -> retval; + }); + this.expr.addLazyFunction("in_dimension", 2, (c, t, lv) -> { ServerCommandSource outerSource = ((CarpetContext)c).s; Value dimensionValue = lv.get(0).evalValue(c);