Move some functions into system_info (#1084)
* Move some functions into `system_info` * Add docs for new `system_info()` properties
This commit is contained in:
1 parent
14be166935
commit
d034b8945a
3 files changed
+39
-14
No files matched your search
@@ -540,6 +540,8 @@ Returns server tick counter. Can be used to run certain operations every n-th ti
|
||||
|
||||
### `world_time()`
|
||||
|
||||
_**Deprecated**. Use `system_info('world_time')` instead._
|
||||
|
||||
Returns dimension-specific tick counter.
|
||||
|
||||
### `day_time(new_time?)`
|
||||
@@ -549,6 +551,8 @@ to that value. Daytime clocks are shared between all dimensions.
|
||||
|
||||
### `last_tick_times()`
|
||||
|
||||
_**Deprecated**. Use `system_info('server_last_tick_times')` instead._
|
||||
|
||||
Returns a 100-long array of recent tick times, in milliseconds. First item on the list is the most recent tick
|
||||
If called outside of the main tick (either throgh scheduled tasks, or async execution), then the first item on the
|
||||
list may refer to the previous tick performance. In this case the last entry (tick 100) would refer to the most current
|
||||
@@ -600,6 +604,9 @@ world-localized block, so not `block('stone')`, or a string representing a dimen
|
||||
Throws `unknown_dimension` if provided dimension can't be found.
|
||||
|
||||
### `view_distance()`
|
||||
|
||||
_**Deprecated**. Use `system_info('server_view_distance')` instead._
|
||||
|
||||
Returns the view distance of the server.
|
||||
|
||||
### `get_mob_counts()`, `get_mob_counts(category)` 1.16+
|
||||
@@ -659,6 +666,7 @@ Available options in the scarpet app space:
|
||||
* `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
|
||||
* `world_time` - Returns dimension-specific tick counter.
|
||||
|
||||
Relevant gameplay related properties
|
||||
* `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'`
|
||||
@@ -686,6 +694,11 @@ Available options in the scarpet app space:
|
||||
* `server_banned_ips` - list of banned IP addresses
|
||||
* `server_dev_environment` - boolean indicating whether this server is in a development environment.
|
||||
* `server_mods` - map with all loaded mods mapped to their versions as strings
|
||||
* `server_last_tick_times` - Returns a 100-long array of recent tick times, in milliseconds. First item on the list is the most recent tick
|
||||
If called outside of the main tick (either throgh scheduled tasks, or async execution), then the first item on the
|
||||
list may refer to the previous tick performance. In this case the last entry (tick 100) would refer to the most current
|
||||
tick. For all intent and purpose, `system_info('last_tick_times'):0` should be used as last tick execution time, but
|
||||
individual tick times may vary greatly, and these need to be taken with the little grain of averaging.
|
||||
|
||||
System related properties
|
||||
* `java_max_memory` - maximum allowed memory accessible by JVM
|
||||
|
||||
@@ -21,6 +21,7 @@ import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.SnoopyCommandSource;
|
||||
import carpet.script.utils.SystemInfo;
|
||||
import carpet.script.utils.InputValidator;
|
||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||
import carpet.script.utils.ShapeDispatcher;
|
||||
@@ -655,8 +656,10 @@ public class Auxiliary {
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTicks()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getWorld().getTime()));
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("world_time()");
|
||||
return new NumericValue(((CarpetContext) c).s.getWorld().getTime());
|
||||
});
|
||||
|
||||
expression.addContextFunction("day_time", -1, (c, t, lv) ->
|
||||
{
|
||||
@@ -672,16 +675,8 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("last_tick_times", -1, (c, t, lv) ->
|
||||
{
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
int currentReportedTick = ((CarpetContext) c).s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = ((CarpetContext) c).s.getServer().lastTickLengths;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
}
|
||||
return ListValue.wrap(ticks);
|
||||
c.host.issueDeprecation("last_tick_times()");
|
||||
return SystemInfo.get("last_tick_times", (CarpetContext)c);
|
||||
});
|
||||
|
||||
|
||||
@@ -742,8 +737,10 @@ public class Auxiliary {
|
||||
expression.addContextFunction("current_dimension", 0, (c, t, lv) ->
|
||||
ValueConversions.of( ((CarpetContext)c).s.getWorld()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance()));
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("view_distance()");
|
||||
return new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance());
|
||||
});
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
|
||||
@@ -23,9 +23,11 @@ import net.minecraft.world.WorldProperties;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
@@ -58,6 +60,7 @@ public class SystemInfo {
|
||||
WorldProperties prop = c.s.getServer().getOverworld().getLevelProperties();
|
||||
return ListValue.of(NumericValue.of(prop.getSpawnX()), NumericValue.of(prop.getSpawnY()), NumericValue.of(prop.getSpawnZ()));
|
||||
});
|
||||
put("world_time", c -> new NumericValue(c.s.getWorld().getTime()));
|
||||
|
||||
put("game_difficulty", c -> StringValue.of(c.s.getServer().getSaveProperties().getDifficulty().getName()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.s.getServer().getSaveProperties().isHardcore()));
|
||||
@@ -114,6 +117,18 @@ public class SystemInfo {
|
||||
ret.put(new StringValue(mod.getMetadata().getName()), new StringValue(mod.getMetadata().getVersion().getFriendlyString()));
|
||||
return MapValue.wrap(ret);
|
||||
});
|
||||
put("server_last_tick_times", c -> {
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
int currentReportedTick = c.s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = c.s.getServer().lastTickLengths;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
}
|
||||
return ListValue.wrap(ticks);
|
||||
});
|
||||
|
||||
put("java_max_memory", c -> new NumericValue(Runtime.getRuntime().maxMemory()));
|
||||
put("java_allocated_memory", c -> new NumericValue(Runtime.getRuntime().totalMemory()));
|
||||
|
||||
Reference in new issue
Block a user