Skip to main content

Minpiler

Allows easier control over Mindustry microprocessors. You can write subset of Python instead assembler-like Mindustry instructions. Consider this as effort to reuse Python syntax, rather than Python implementation.

Warning: Everything that requires dynamic memory doesn't work: any data structure (list, dict, etc), classes, closures, recursion. Additionally you can't use any Python builtins (input, eval, Exception, etc). Imports do nothing, use it make flake8 happy. Explanation below.

Rationale

Mindustry microprocessors are quite nice and easy to understand. They have explicit limit of instructions per unit of time. They can operate on floats, refer to objects (null, constant strings, @-objects, in-game units) and fire several commands that affect the game.

Here is an example program that switches unloader output between lead and titanium depending on time:

read time cell1 0
op add time time 1
jump 4 lessThan time 300
set time 0
write time cell1 0
jump 8 greaterThan time 200
control configure unloader1 @titanium
end
control configure unloader1 @lead

This program is fairly simple, but if you insert any instruction in the middle of program, you have to rewrite many jump addresses.

What if you want to calculate some formula, let's say

2 + a * 2 + b + c * d * 3

You'll have to write:

op mul _r1 a 2
op add _r2 2 _r1
op add _r3 _r2 b
op mul _r4 c d
op mul _r5 _r4 3
op add result _r3 _r5

It becomes boring, error-prone and quite hard to modify.

What if you could write the following instead:

time = cell1[0]
time += 1
if time >= 300:
    time = 0
cell1[0] = time
unloader1.configure(M.at.lead if time > 200 else M.at.titanium)
result = 2 + a * 2 + b + c * d * 3

It's possible with minpiler!

  1. Write your code in subset of Python
  2. Compile it into Mindustry instructions
  3. Copy the result into clipboard
  4. Import code right into running game

So far so good, looks like you can just write Python code and then import it into the game. As a good Pythonista you're eager to use your knowledge of closures, classes and decorators to program Mindustry controllers, but unfortunately I have to stop you there. You won't be able to use most of the Python. All the restrictions arise from Mindustry processor architecture:

  1. There's no data structures, only scalar values are allowed (floats or opaque objects). The only exception are Memory cells that behave as fixed-size arrays of floats.
  2. You can't access variables indirectly, there're no pointers, no getattr.
  3. Subsequence of former, it's impossible to implement dynamic memory/stack (at least without Memory cells). This makes lists, iterators, classes, closures and other things impossible.
  4. Set of builtins is very restricted, you can only call what you have available in game (M.print, M.draw.clear, etc)

Anyway, I hope Minpiler will be handy enough for you to have lots of fun playing Mindustry.

How to use

# Install packages
pip install minpiler pyperclip

# Compile your code into clipboard
python -m minpiler --clip yourfile.py
# now open processor building, press Edit button, Import from Clipboard

Pyperclip is optional, it's only used with --clip option.

Refer to set of code samples in this repository.

Compatibility

Python >= 3.6 or compatible pypy3.

Mindustry: currently only 121 have been tested.

Metadata

Release files for minpiler 0.3.2

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

Source distribution (sdist)

Source distribution for minpiler 0.3.2
File Size Uploaded Provenance Actions
minpiler-0.3.2.tar.gz 19.7 kB Without provenance Details for minpiler-0.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 37.5 kB

Release files / minpiler-0.3.2.tar.gz

Download URL minpiler-0.3.2.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
23d5a2aafecb022395cee494d295ffddff44c56f326c105b60151fdaa296e7e1
BLAKE2b-256 checksum
How to use checksums
f6f0e423ffa7da65278f1d1cc392783c91c522cd023fcea082aac5eafd328f63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / minpiler-0.3.2-py3-none-any.whl

Download URL minpiler-0.3.2-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e74ded87d6d7b115b900c33b665f40e9005855d24bd329c1a46ff7b14ed49a42
BLAKE2b-256 checksum
How to use checksums
435ae5a18e8b00ee849658b7b6d7465efcc1183a01d04ead1f4f3c4a71fa871b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Security for minpiler 0.3.2

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