Skip to content

The Modular Definition

Aristeas edited this page Apr 26, 2024 · 2 revisions

The Modular Definition is the "blueprint" that tells Modular Assemblies Framework how to construct your assemblies. They are created in client mods and registered over the DefinitionApi.

The definition template can be found in DefinitionDefs.ModularPhysicalDefinition, and registered via DefinitionApi.RegisterDefinition();

Definition Reference

Object Description

string Name

The unique name representing this definition. This is used in several DefinitionApi calls.

Action OnInit

Parameterless action triggered whenever the definition is first loaded.

Action<int, IMyCubeBlock, bool> OnPartAdd

Registers an action to be triggered when a part is added.
The action is triggered with the following arguments:
- int PhysicalAssemblyId: The unique ID of the assembly containing this block.
- IMyCubeBlock newBlock: The freshly placed block.
- bool IsBaseBlock: If a base block is defined, this value will be true for that subtype.

Action<int, IMyCubeBlock, bool> OnPartRemove

Registers an action to be triggered when a part is removed.
The action is triggered with the following arguments:
- int PhysicalAssemblyId: The unique ID of the assembly containing this block.
- IMyCubeBlock newBlock: The freshly removed block.
- bool IsBaseBlock: If a base block is defined, this value will be true for that subtype.

Action<int, IMyCubeBlock, bool> OnPartDestroy

Registers an action to be triggered when a part is destroyed. Triggered immediately after OnPartRemove if a block was destroyed.
The action is triggered with the following arguments:
- int PhysicalAssemblyId: The unique ID of the assembly containing this block.
- IMyCubeBlock newBlock: The freshly destroyed block.
- bool IsBaseBlock: If a base block is defined, this value will be true for that subtype.

string BaseBlockSubtype

The primary block of an Assembly. Make sure this is a subtype referenced in AllowedBlockSubtypes OR null.
If this is set, assemblies will NOT be created until the baseblock exists. If the baseblock of an assembly is destroyed, disconnected assembly parts will be removed from the assembly.

string[] AllowedBlockSubtypes

The list of all block subtypes this assembly can contain.

Dictionary<string, Dictionary<Vector3I, string[]>> AllowedConnections

Allowed connection directions, measured in blocks. If an allowed SubtypeId is not included here, connections are allowed on all sides. If the connection type whitelist is empty, all allowed subtypes may connect on that side.
The first key set are subtypes, and the second dictionary set maps grid position offsets to allowed SubtypeIds; if you wanted to connect to a part 3 blocks from the center, you would use [new Vector3I(0, 0, -3)