Adding min_y, max_y and world_border_info to system_info (#1168)

* Adding min_y and max_y

* Making it return all dimensions

* Adding world_border_info as well, cos y not

* Update docs/scarpet/api/Auxiliary.md

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
Ghoulboyandgnembon authored and GitHub committed 2021-11-30 03:03:15 +01:00
1 parent 16e1b7952e
commit 6c776b6131
2 files changed
+40 -1

No files matched your search

+4 -1
View File
@@ -695,8 +695,11 @@ Available options in the scarpet app space:
* `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
* `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.
Relevant gameplay related properties
* `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'`
@@ -17,9 +17,13 @@ import com.sun.management.OperatingSystemMXBean;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.SharedConstants;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.WorldSavePath;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.WorldProperties;
import net.minecraft.world.border.WorldBorder;
import java.lang.management.ManagementFactory;
import java.nio.file.Path;
@@ -60,6 +64,38 @@ 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_min_height", c-> {
Map<Value, Value> 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_max_height", c-> {
Map<Value, Value> 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<Value, Value> 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_time", c -> new NumericValue(c.s.getWorld().getTime()));
put("game_difficulty", c -> StringValue.of(c.s.getServer().getSaveProperties().getDifficulty().getName()));