Skip to content
theblackswitch edited this page Jan 13, 2026 · 3 revisions

Available since version 2.0

Calculate things! For more information I'll refer to your local school :P

Usage

Sqrt

To calculate the sqrt, you can run the code below. This library uses a newtionian approximation to calculate the value of the square root.

scoreboard players set #precision tbs.math <precision>
scoreboard players set #a tbs.math <input_value>
function #theblackswitch:<version>/math/sqrt
scoreboard players get #result tbs.math

Arguments:

The arguments are passed as scoreboards

  • #precision tbs.math: The precision required for the calculation. Higher value means higher precision but at a higher performance cost (usually something like 3-6 is sufficient)
  • #a tbs.math: The input value of the sqrt

Returns:

The function returns the result of the calculation. It also stores said value in #result tbs.math

Example

Calculate the distance between 2 positions

# X = (X1 - X2)^2
scoreboard players operation #x temp = #pos.1.x temp
scoreboard players operation #x temp -= #pos.2.x temp
scoreboard players operation #x temp *= #x temp

# Y = (Y1 - Y2)^2
scoreboard players operation #y temp = #pos.1.y temp
scoreboard players operation #y temp -= #pos.2.y temp
scoreboard players operation #y temp *= #y temp

# X + Y
scoreboard players operation #a tbs.math = #x temp
scoreboard players operation #a tbs.math += #y temp

# Calculate the final result
return run function #theblackswitch:v2.0/math/sqrt

Enabling

This feature is enabled by default

Clone this wiki locally