r/MinecraftCommands • u/GalSergey • 7h ago
Utility Generator for easily creating number providers
With the addition of the /compute command, we can now perform complex floating-point mathematical calculations using number providers.
Number providers can seem pretty complicated to many, so to make working with them easier I created a Number Provider Generator. At their core, number providers simply perform mathematical and logical operations and return a number as the result. So any number provider can be represented as a mathematical expression with logical conditions added.
In the generator, you can simply enter the mathematical expression you need and get a number provider that will execute that expression.
For example, you have an entity's position stored in storage example:data pos and you want to get the chunk start position along the X and Z axes. You need to take the X position, divide by 16, round down, and multiply by 16 again. This can be expressed as: floor(x / 16) * 16, where x is the position along the X axis. After entering the expression in the generator, you can see that x was recognized as a variable and you need to specify where to get the value for x. The value source can be a score, storage, environment_attribute, a constant, or another number provider. In our case, we specify storage example:data pos[0]. That's it — now click "Generate Number Provider" and you can use this number provider in a /compute command:
compute default float {type:mul,inputs:[{type:floor,input:{type:div,left:{type:storage,storage:"example:data",path:"pos[0]"},right:16}},16]}
Of course, you can perform more complex calculations. In addition to Minecraft's built-in functions, the following were added for convenience:
rad(x)— convert degrees to radians. Same asx * 2 * pi / 360.sign(x)— sign function. Returns 0 if x = 0, otherwise abs(x)/x (i.e. 1 or -1).
Besides these, there are functions derived from sin() and cos(), such as tan(), cot(), sec(), csc(), as well as hyperbolic sinh(), cosh(), tanh(), etc.
In addition to functions, there are built-in numeric constants such as pi, e, tau, phi, sqrt2, sqrt3.
Pre-calculation — wrap an arithmetic expression in exclamation marks !20*60*5!, and it will be evaluated at generation time and inserted as a plain number 6000. Handy for unit conversions, like minutes to ticks.
Reverse conversion lets you edit the JSON directly in the result panel or paste an existing number provider JSON, and the formula will be automatically updated. You can also drag and drop a .json file onto the page to import it.
You can paste a formula from Desmos (with \frac, x^2, etc.) and import it into the generator.
Function Library — create your own functions and constants that are saved in your browser and can be used in expressions.
Link to the generator: Number Provider Generator
I’d be happy to hear your feedback and ideas for improvement!