Skip to main content

Blocks and items

A machine in the world is a CraftEngine block whose behavior points to a machine type. Batteries, tanks and wrenches are CraftEngine items with MachineEngine's item behaviors. Both are written in a CraftEngine pack (plugins/CraftEngine/resources/<pack>/configuration/); run /ce reload all after a change.

The machine block​

blocks:
mypack:crusher:
behavior:
type: machineengine:machine
machine: mypack:crusher # the machine type
keep_contents: true
loot: {template: machineengine:loot_table/keep_contents}
KeyDefaultMeaning
machine—Required. The machine type (from an addon or a definition).
keep_contentsfalseA player breaking it gets one item holding the contents (below).
hopperstrueHoppers, droppers and hopper minecarts use the machine's item ports.
comparatortrueComparators read how full the machine is.
facing_propertyfacingThe block property that holds the facing, when the block has it.
active_propertyactiveA boolean property set while the machine works (to show another model).
storages, ports, options—Per-block numbers.
display_itemnoneDraw the block with a display entity of this item (and <item>/active while working).
display_rotation0Degrees the display item is turned (clockwise from above) when facing north.
display_rotationsnoneEach facing's rotation x/y, e.g. north=0/0,up=270/0; wins over display_rotation.
level_displaynoneA gauge inside the block: items <prefix>/1 to <prefix>/<steps> by how full level_storage is.
level_storageenergyThe storage the gauge shows.
level_steps4Number of gauge items.
side_displaynoneItems <prefix>/<side> shown on each side that has a port (its side configuration).

Per-block numbers​

The same machine type can back several blocks with different numbers — tiers, for example. Numbers written on the block replace the machine type's:

behavior:
type: machineengine:machine
machine: mypack:energy_cube
storages:
energy: {capacity: 4000000} # capacity of a storage
ports:
out: {rate: 4000} # per-tick rate of a port
options:
energy-per-tick: 200 # numbers the machine type reads (each addon lists its own)

/ce reload applies new numbers to machines already in the world.

Keep contents​

With keep_contents: true and the loot template machineengine:loot_table/keep_contents, a player breaking the machine gets one item holding its contents, process and upgrades; placing it back resumes the machine. Explosions and other breaks that are not a player's drop the contents as usual. An empty machine drops a plain item.

Hoppers and comparators​

  • The side a hopper touches selects the port; that port's direction and filter apply. hoppers: false turns this off for the block.
  • A comparator next to a machine gives 0 when it is empty and up to 15 when full, like a chest. comparator: false turns it off.

Templates​

MachineEngine ships CraftEngine templates for blocks that use its types, in plugins/CraftEngine/resources/machineengine/configuration/templates.yml (rewritten at every start: copy one under another name to change it). Put a template at the top of the block; keys written next to it are merged in:

blocks:
mypack:crusher:
template: machineengine:block/machine # machine of the same id, keeps its contents
behavior:
options: {energy-per-tick: 40}
settings: {template: default:settings/solid_1x1x1}
states:
template: machineengine:block_state/facing_active # block/<id>, block/<id>_active
TemplateWhat it gives
machineengine:block/machineThe machineengine:machine behavior for the machine of the same id, keep_contents, and its loot.
machineengine:block/transportThe machineengine:transport behavior for the transport of the same id; drops itself.
machineengine:loot_table/keep_contentsThe loot of a keep-contents block.
machineengine:block_state/solidOne solid model (model, default <namespace>:block/<id>).
machineengine:block_state/facingTurned by facing (4 directions).
machineengine:block_state/activeAnother model while active (active_model, default <namespace>:block/<id>_active).
machineengine:block_state/facing_activeBoth.
machineengine:block_state/display_renderedA block drawn by display entities: one invisible model (display_state, display_model, state_type).
machineengine:block_state/display_rendered_facingThe same, turned by facing (4 directions).
machineengine:block_state/display_rendered_facing_6The same, in all 6 directions.

Display-rendered blocks with the same display_state share one vanilla visual state, so many machines can use few block states. With CraftEngine's config factories (config_factory), a family of blocks (tiers) can be declared once — Mekanized does this for all its tiers.

Items​

Add MachineEngine's item behaviors to an item's behaviors: list:

items:
mypack:battery:
behaviors:
- type: machineengine:energy_item
max-energy: 1000000
max-output: 10000
client-bound-data:
machineengine:resource_lore: {} # show what it holds, in each player's language
BehaviorKeysDoes
machineengine:energy_itemmax-energy (required), max-input, max-output (per transfer, default no limit)The item holds energy.
machineengine:resource_itemresource, capacity (required), max-input, max-output, fill-from-machines (default false)The item holds one resource (a fluid, a chemical). With fill-from-machines, right-clicking a machine that holds it fills the item.
machineengine:wrenchclick, sneak-click: rotate, dismantle or none (default)rotate turns the machine a quarter; dismantle breaks it as the player would (keep-contents applies).
machineengine:upgradeupgrade (default: the item's own id)The item is a machine upgrade: install it from the menu, or right-click the machine (sneak: as many as fit).
machineengine:storage_reader—Right-click a machine to print its storages.

Machines charge or fill any item with these behaviors placed in their slots. machineengine:resource_lore under client-bound-data: adds lore lines with the current amounts; nothing is stored on the item for it.

At startup, MachineEngine logs any block or item that names a machine, transport, resource or upgrade type nobody registered.