Sharing Code with Libraries
When several PLCs share the same item lists, target stock numbers, or helper functions, copy-pasting the same code into every PLC gets tedious. Instead, save a module in your
PLC Programmer library and import it with load().
Step 1: Save a module in your Programmer library
Section titled “Step 1: Save a module in your Programmer library”- Open your
PLC Programmer (or the Browser Editor) and create a library entry named, for example, factory_defs. - Library names use lowercase letters, digits, and underscores (
a–z,0–9,_, up to 32 characters). - Put constants or helper functions in the file—no
scan()function needed:
FUEL_TARGET = 8ORE_LIST = ["minecraft:raw_iron", "minecraft:raw_copper", "minecraft:raw_gold"]
def _clamp(n, low, high): # starts with _ → private to this module if n < low: return low if n > high: return high return n
def top_up(src, dst, key, target): need = _clamp(target - dst.count(key), 0, target) if need > 0: move(src, dst, need, key=key)Step 2: Import it with load()
Section titled “Step 2: Import it with load()”Put load(...) statements at the very top of your PLC’s main script:
load("factory_defs", "FUEL_TARGET", "top_up")
SUPPLY = point("supply/item")FURNACE = point("furnace/item")
def scan(): top_up(SUPPLY, FURNACE.north, "minecraft:coal", FUEL_TARGET)You can also alias imported names with keyword syntax: load("factory_defs", target="FUEL_TARGET").
Built-in modules (mplc:)
Section titled “Built-in modules (mplc:)”Module names starting with mplc: load modules shipped directly with the mod—no Programmer library entry needed:
load("mplc:timers", "on_delay", "off_delay", "pulse")How library updates work
Section titled “How library updates work”- Modules are copied on upload: When you upload a program through your Programmer, MPLC bundles copies of every module it imports into the PLC block itself.
- Editing a library does not auto-update running PLCs: After changing
factory_defs, re-upload the scripts on the PLCs you want to pick up the change. (In the editor’s Files tabs, changed modules show a Library changed badge so you can spot them easily.) - Modules cannot declare registers: Only the main program can call
register(...). If a helper function needs persistent state—likeon_delay(HELD, ...)—declare the register in the main script and pass it into the helper as an argument. - Private names and re-exports: Names beginning with
_cannot be imported, and names that a module imported from somewhere else are not automatically re-exported. Import cycles (aloadsbloadsa) are rejected at upload.
Not an official Minecraft website. Not approved by or associated with Mojang or Microsoft.