Minecraft math helper by Mingshi Yang - Squid Workshop.
Minecraft Java Edition 1.13+ is supported, you may consult here and set the pack.mcmeta file according to your game version.
This datapack provide fast, high precision math operation functions using Scoreboard.
- Constants are stored under objective swMath_C. Feel free to define more in this file.
- Variables, including inputs and outputs, are stored under objective swMath_V.
- "sw" means Squid Workshop.
- For high precision computation, the input and output may have units of 0.0001. i.e., the score 10000 is used to represent 1, utilizing 4 digits. Actual error in computation is usually on magnitude of 0.01%. One visualization of different magnitudes of error is here. See example for implementation detail.
- No entities involved in calculations, avoiding entity selection ensures high throughout performance, compatibility and easy maintenance.
- Step 01 Download this repository as a zip and unpack.
- Step 02 Go to Minecraft directory, usually "C:/Users/youUserName/AppData/Roaming/.minecraft".
- Step 03 Choose the world folder in which you want to install the pack. Go to .../saves/world/datapacks folder.
- Step 04 Open Minecraft and open the world.
- Step 05 Type "/reload" command then press enter.
- Step 06 Enjoy
For Windows users, swMath_sync.bat is provided to facilitate redistribution and pack update. To install a new copy or update the pack with the most recent version, simply copy it to your desired .../saves/world/datapacks folder, and double click it there. It will download and extract the math datapack for you from GitHub.
The main function directory is math:functions/classes/core/. All functions provided are listed below.
To execute a function, consult the table and run the command
/function math:classes/core/Function
Function |
Description |
Unit |
---|---|---|
random/randint_base | return an integer following uniform distribution: Min = -2^31, Max = 2^31-1 |
N/A |
util/swap | a shortcut to assign value of input #vIn using value of output #vOut | N/A |
Function |
Description |
Unit |
---|---|---|
operations/square | compute square (1) (2) | N/A |
operations/sqrt | compute square root (2) | N/A |
random/randint_t | return an integer following t distribution given degrees of freedom. DoF >= 30 ~ Z distribution. Mean = 0, SD = 10000 |
N/A |
trig/arccos_rad | compute inverse cosine (3) | 0.0001 |
trig/arcsin_rad | compute inverse sine | 0.0001 |
trig/arctan_rad | compute inverse tangent | 0.0001 |
trig/cos_rad | compute cosine | 0.0001 |
trig/sin_rad | compute sine | 0.0001 |
trig/tan_rad | compute tangent | 0.0001 |
util/deg2rad | convert from degrees to radians | 0.0001 |
util/rad2deg | convert from radians to degrees | 0.0001 |
Function |
Description |
Unit |
---|---|---|
operations/division_4d | compute #vIn2 / #vIn with high precision | 0.0001 |
operations/division_round | compute #vIn2 / #vIn with rounding of output integer | N/A |
operations/multiply | compute #vIn * #vIn2 (1) | N/A |
trig/arctan2_rad | compute inverse tangent of #vIn2 / #vIn choosing the quadrant correctly |
0.0001 |
Function |
Description |
Unit |
---|---|---|
vector/magnitude | compute magnitude of vector | 0.0001 |
vector/unit | compute unit vector | 0.0001 |
Function |
Description |
Unit |
---|---|---|
vector/cross (4) | compute cross product | N/A |
vector/dot (4) | compute dot product | N/A |
Scalar |
Vector |
---|---|
#vOut, #vOut_Mag if needed | #vOi, #vOj, #vOk |
(1) Since the result may overflow the scoreboard, the magnitude is stored separately as #vOut_Mag and the #vOut may be scaled down to fit in the scoreboard. i.e. result = #vOut * #vOut_Mag
(2) In these operations, the input is considered without units.
(3) All trigonometry operations use radians as unit of measurement.
(4) Overflow is not yet monitored and result is not yet scaled.
-
Set inputs
/scoreboard players set #vIn2 swMath_V 123456 /scoreboard players set #vIn swMath_V 31416
-
Run function
/function math:classes/core/operations/division_4d
-
Get output
/scoreboard players get #vOut swMath_V
The above outputs 39297 units which matches the exact value 3.929717341.
-
Set input, 0.5 radians is 5000 units
/scoreboard players set #vIn swMath_V 5000
-
Run function
/function math:classes/core/trig/cos_rad
-
Get output
/scoreboard players get #vOut swMath_V
The above outputs 8776 units which matches the exact value 0.8775825619.
NO COMMERCIAL USE.
More datapacks developed by us here
Watch our videos on youtube here
Watch our videos on bilibili here
Join our QQ group: 74681732
Subscribe on wechat: 鱿鱼MC工作室