Skip to content

Inheritance

DarkBladeDev edited this page Dec 27, 2025 · 1 revision

Inheritance & Templates

The MultiBlockEngine supports a powerful inheritance system that allows you to create "template" structures and extend them to create variations. This reduces duplication and makes managing complex sets of machines much easier.

The extends Keyword

Any multiblock YAML file can include the extends key pointing to another multiblock's id.

id: my_advanced_machine
extends: my_base_machine

How It Works

When the plugin loads, it:

  1. Loads all files.
  2. Builds a dependency graph (who extends who).
  3. Resolves them in order (Base -> Child -> Grandchild).
  4. Merges the configurations.

Merge Rules

  • Scalars (Strings, Numbers, Booleans): The child's value overrides the parent's value.
  • Lists (Actions, Patterns): The child's list completely replaces the parent's list. There is currently no "append" logic.
  • Maps/Sections (Variables, Behavior): These are deep merged. You can add new keys to a section without losing the parent's keys.

Example Scenario

1. The Template (base_machine.yml)

id: base_machine
tick_interval: 20
controller: IRON_BLOCK
pattern:
  - offset: [0, -1, 0]
    match: COAL_BLOCK
actions:
  on_break:
    - type: message
      value: "&cMachine broken!"

2. The Child (fast_machine.yml)

id: fast_machine
extends: base_machine
tick_interval: 5 # OVERRIDES parent (20 -> 5)

# INHERITS controller (IRON_BLOCK)
# INHERITS pattern (Coal block below)
# INHERITS on_break action

actions:
  on_create: # ADDS new event listener (didn't exist in parent)
    - type: message
      value: "&aFast machine created!"

Limitations

  • Circular Inheritance: You cannot have A extends B and B extends A. The plugin will detect this and disable both with an error.
  • Missing Parent: If the parent id cannot be found, the child will fail to load.

Clone this wiki locally