Skip to main content

Bolt Compute

A beet plugin that lets you write expressions instead of inline number providers in the compute command.

Installation

In a beet project, use uv add bolt_compute and add the module in the require phase in your beet config:

require:
  - bolt
  - bolt_compute # <-- Add this line
pipeline:
  - mecha

Usage

Anywhere the compute command or subcommand is used, you can write an expression in parentheses instead of a number provider. For example, instead of:

compute default float {type: "minecraft:add", inputs: [{type: "minecraft:storage", storage: "demo:main", path: "a"}, 1.0f]}
data modify storage demo:main result set compute default float {type: "minecraft:add", inputs: [{type: "minecraft:storage", storage: "demo:main", path: "a"}, 1.0f]}

You can write:

compute default float (storage demo:main a + 1)
data modify storage demo:main result set compute default float (storage demo:main a + 1)

compute entity <target> and compute block <pos> work the same way:

compute entity @s float (storage demo:main a + 1)
compute block ~ ~ ~ integer (score this my_objective * 2)

Expressions are compiled into vanilla number providers during mecha's transform step. The generated NBT is then validated against the game's schema in the check step, like any hand-written number provider, so mistakes are reported on the expression itself.

The bolt subcommand

compute bolt, compute bolt_entity <target> and compute bolt_block <pos> always parse their argument as a bolt_compute expression:

compute bolt float (storage demo:main a + 1)
compute bolt_entity @s float (storage demo:main a + 1)
compute bolt_block ~ ~ ~ integer (score this my_objective * 2)

They compile to compute default, compute entity @s and compute block ~ ~ ~ respectively.

With the default default_command: true option, the vanilla argument is tried first. A parenthesized expression that is also valid Python, such as (1 + 1) or (x * 2), is evaluated by bolt at compile time and inlined as a constant. Use the bolt subcommand when you need a bolt_compute expression in that case:

x = 1
compute default float (x + 1)  # compute default float 2
compute bolt float (x + 1)     # compute default float {type: "minecraft:add", inputs: [1.0f, 1.0f]}

Set default_command: false to only enable expressions through the bolt subcommand:

meta:
  bolt_compute:
    default_command: false

Literal values

Expression Number provider
1.5, 3 constant
"demo:my_provider" reference to a number provider file
storage demo:main path.to.value minecraft:storage
score this my_objective minecraft:score on a context entity (this, attacker, direct_attacker, attacking_player, target_entity, interacting_entity)
score fixed jeb_ my_objective minecraft:score on a fixed name or UUID
x value of the bolt variable x: a number becomes a constant, a string becomes a reference
compute default float (storage demo:main path)
# compute default float {type: "minecraft:storage", storage: "demo:main", path: "path"}

compute default integer (score fixed jeb_ my_objective)
# compute default integer {type: "minecraft:score", target: {type: "fixed", name: "jeb_"}, score: "my_objective"}

y = "demo:my_provider"
compute bolt float (y * y)
# compute default float {type: "minecraft:mul", inputs: ["demo:my_provider", "demo:my_provider"]}

A score used in a float expression is wrapped in minecraft:from_int.

Operators

Operator float integer
+ add add
- sub sub
* mul mul
/ div
// div
% mod mod
** pow pow
unary - negate negate

Operator precedence follows Python, and parentheses can be used for grouping.

Functions

Every vanilla number provider type can be called as a function. Arguments can be passed by position or by name, and can themselves be expressions:

compute default float (uniform(0, 10))
compute default float (uniform(min=0, max=storage demo:main a))
compute default integer (binomial(10, 0.5))
compute default float (sin(storage demo:main angle))

Functions taking a list of inputs accept either a list or the inputs as separate arguments: max([1, 2, storage demo:main a]) or max(1, 2, storage demo:main a).

Type Functions
float abs, add, avg, ceil, conditional, constant, cos, div, enchantment_level, environment_attribute, floor, from_int, length, max, min, mod, mul, negate, number_dispatcher, pow, round, sin, sqrt, storage, sub, truncate, uniform, weighted_list
integer abs, add, avg, binomial, conditional, constant, div, environment_attribute, floor_div, floor_mod, from_float, max, min, mod, mul, negate, number_dispatcher, pow, storage, sub, uniform, weighted_list

Conditions

on_true if condition else on_false is equivalent to the conditional function. The condition is a predicate: either a predicate id, an inline predicate (26.3 format, with a type key), or a list of inline predicates that must all pass.

compute default float (1 if demo:my_predicate else 0)
compute default float (conditional(demo:my_predicate, 1, 0))

compute default float (
    220210 if {type: "minecraft:random_chance", chance: 0.5} else 23
#    ^        ^                                                ^
#    |        |                                                |
#  on_true    |                                             on_false
#         condition
)

Inline predicates are validated in mecha's check step. A predicate id is only checked to be a string.

Multiline expressions

Expressions can span several lines:

compute default float (
    storage demo:main a
    + storage demo:main b
)

Full example

x = "demo:my_provider"
y = 256*256

data modify storage demo:main result set compute bolt float (
    (storage demo:main prod1)*(storage demo:main prod2)*(storage demo:main prod3)*2
    *
    2485*52+
    max([0,1,(storage demo:main prod2),1])+(143)-
    (y*x) + x
)

More examples can be found in the examples folder.

Metadata

Release files for bolt_compute 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bolt_compute 0.2.0
File Size Uploaded Provenance Actions
bolt_compute-0.2.0.tar.gz 75.1 kB Without provenance Details for bolt_compute-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bolt_compute 0.2.0
File Interpreter ABI Platform Actions
bolt_compute-0.2.0-py3-none-any.whl Python 3 none any Details for bolt_compute-0.2.0-py3-none-any.whl

Total release size: 91.1 kB

Release files / bolt_compute-0.2.0.tar.gz

Download URL bolt_compute-0.2.0.tar.gz
Size 75.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c9707b60a0f5f6016fed74f09ac734acf8cd45202452555bebad8422a9d41da1
BLAKE2b-256 checksum
How to use checksums
6d9e9184becc2afe5cb08da7d7d03f70f0d1d1dadf3904b1715c9cf794653b28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / bolt_compute-0.2.0-py3-none-any.whl

Download URL bolt_compute-0.2.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
396f9d0f6ab874fa9c2f7875658cb8b030c0dc9d33d026cce92bd951d9c0b470
BLAKE2b-256 checksum
How to use checksums
6c89cc29c8f50336a8d7383e98cbe66dd039f7d72347627eb796a6e8b7a283a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for bolt_compute 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page