Scoreboard Math Engine
The math module provides trigonometric and algebraic functions using scoreboard operations. All values use fixed-point arithmetic scaled by 1000 to preserve decimal precision inside integer-only scoreboards.
Registering the math module
This generates a load function that creates the kore_math objective and sets useful constants (#2, #360, #scale).
Reading the results
Because scoreboards only store integers, every result is scaled by 1000:
1000means1.0500means0.5-707means approximately-0.707
That convention stays consistent across trigonometric helpers and formulas, which makes it easier to combine several math operations in the same datapack.
Trigonometric functions
Sine and cosine use a pre-computed 360-entry lookup table (one entry per degree). The input score holds an angle in degrees; the output receives value × 1000.
This is particularly handy for scoreboard-driven movement systems, orbiting particles, or knockback calculations where the input angle is already tracked as an integer.
Square root
An iterative Babylonian / Newton approximation (8 iterations by default):
Use sqrt when you need a real distance magnitude from squared values, or when another formula requires a root instead of a squared distance.
Euclidean distance (squared)
Computes (x2−x1)² + (y2−y1)² + (z2−z1)²:
Computing the squared distance is often enough for range checks and is cheaper to chain with threshold comparisons than an actual square root.
Parabolic trajectory
Computes Y = v0 × t − (g × t²) / 2 for projectile simulation:
Example: projectile preview
The helpers are intentionally small and composable: you can build a more complex simulation by combining multiple scoreboard operations rather than relying on one giant black-box function.
Function reference
| Function | Description |
|---|---|
cos |
Cosine lookup (degrees → scaled result) |
sin |
Sine lookup (degrees → scaled result) |
sqrt |
Integer square root (Newton's method) |
distanceSquared |
Squared 3D Euclidean distance |
parabola |
Parabolic Y from time, velocity, and gravity |
See also
- State Delegates – Write scoreboard-backed values with less boilerplate before feeding them into math helpers.
- Cooldowns – Pair time-based gameplay gates with scoreboard-driven calculations.
- Scoreboards – Higher-level scoreboard utilities that fit naturally around these formulas.
