From 1cefef82f74b0c6c08b23e9f00f3c6610a6b857f Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 30 Nov 2021 03:28:44 +0100 Subject: [PATCH] no-bs world height info --- docs/scarpet/api/Auxiliary.md | 9 ++--- .../java/carpet/script/utils/SystemInfo.java | 36 +++++-------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index a8d5f499..072f401e 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -697,10 +697,11 @@ Available options in the scarpet app space: * `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 in the overworld dimension * `world_time` - Returns dimension-specific tick counter. - * `world_max_y` - Returns all dimension's maximum y-values in a map form (`dimension` -> `max_y`). Values are numeric - * `world_min_y` - Same as above, returning minimum y-values instead. - * `world_border_info` - Returns all dimension's world border info in a map form (`dimension` -> `[[centre_pos], radius]`). Note that the y-value of `centre_pos` is always 0. - + * `world_top` - Returns current dimensions' topmost Y value where one can place blocks. + * `world_bottom` - Returns current dimensions' bottommost Y value where one can place blocks. + * `world_center` - Returns coordinates of the center of the world with respect of the world border + * `world_size` - Returns size of the world where at this distance from `world_center` world border appears. + * Relevant gameplay related properties * `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'` * `game_hardcore` - boolean whether the game is in hardcore mode diff --git a/src/main/java/carpet/script/utils/SystemInfo.java b/src/main/java/carpet/script/utils/SystemInfo.java index 8ffb41de..6aa56030 100644 --- a/src/main/java/carpet/script/utils/SystemInfo.java +++ b/src/main/java/carpet/script/utils/SystemInfo.java @@ -65,36 +65,16 @@ public class SystemInfo { return ListValue.of(NumericValue.of(prop.getSpawnX()), NumericValue.of(prop.getSpawnY()), NumericValue.of(prop.getSpawnZ())); }); - put("world_min_height", c-> { - Map dimMap = new HashMap<>(); - for (ServerWorld world : c.s.getServer().getWorlds()) { - dimMap.put(ValueConversions.of(world.getRegistryKey().getValue()), new NumericValue(world.getBottomY())); - } - return MapValue.wrap(dimMap); + put("world_bottom", c-> new NumericValue(c.s.getWorld().getBottomY())); + + put("world_top", c-> new NumericValue(c.s.getWorld().getTopY())); + + put("world_center", c-> { + WorldBorder worldBorder = c.s.getWorld().getWorldBorder(); + return ListValue.fromTriple(worldBorder.getCenterX(), 0, worldBorder.getCenterZ()); }); - put("world_max_height", c-> { - Map dimMap = new HashMap<>(); - for (ServerWorld world : c.s.getServer().getWorlds()) { - dimMap.put(ValueConversions.of(world.getRegistryKey().getValue()), new NumericValue(world.getLogicalHeight())); - } - return MapValue.wrap(dimMap); - }); - - put("world_border_info", c-> { - Map dimMap = new HashMap<>(); - for (ServerWorld world : c.s.getServer().getWorlds()) { - WorldBorder worldBorder = world.getWorldBorder(); - dimMap.put( - ValueConversions.of(world.getRegistryKey().getValue()), - ListValue.of( - ListValue.fromTriple(worldBorder.getCenterX(), 0, worldBorder.getCenterZ()), - new NumericValue(worldBorder.getMaxRadius()) - ) - ); - } - return MapValue.wrap(dimMap); - }); + put("world_size", c-> new NumericValue( c.s.getWorld().getWorldBorder().getMaxRadius())); put("world_time", c -> new NumericValue(c.s.getWorld().getTime()));