Add commands.getDimension()

Debated "commands.getBlockDimension()" instead, to match
getBlockPosition, but I think this is fine.

Fixes #1866.
This commit is contained in:
Jonathan Coates
2026-05-07 13:36:05 +01:00
parent 663ffed433
commit defb713483
@@ -157,6 +157,18 @@ public class CommandAPI implements ILuaAPI {
return Collections.unmodifiableList(result);
}
/**
* Get the name of the dimension the current command computer is in, such as {@code minecraft:overworld}.
*
* @return The dimension the computer is in.
* @see #getBlockPosition()
* @since 1.119.0
*/
@LuaFunction
public final String getDimension() {
return computer.getLevel().dimension().location().toString();
}
/**
* Get the position of the current command computer.
*
@@ -165,10 +177,10 @@ public class CommandAPI implements ILuaAPI {
* @cc.treturn number This computer's y position.
* @cc.treturn number This computer's z position.
* @cc.see gps.locate To get the position of a non-command computer.
* @see #getDimension()
*/
@LuaFunction
public final Object[] getBlockPosition() {
// This is probably safe to do on the Lua thread. Probably.
var pos = computer.getPosition();
return new Object[]{ pos.getX(), pos.getY(), pos.getZ() };
}