Skip to main content

MxtActions: Script Actions

Registering a Script Action​

MethodCallback parametersPurpose
entity(id, callback)(entity: Entity, params: object, context: FormulaContext)Registers an entity action.
biEntity(id, callback)(actor: Entity, target: Entity, params: object, context: FormulaContext)Registers a bi-entity action.
block(id, callback)(level: Level, pos: BlockPos, params: object, context: FormulaContext)Registers a block position action.
item(id, callback)(holder: Entity, stack: ItemStack, params: object, context: FormulaContext)Registers an item action.

All four callbacks correspond to type: "saturn:js" in a data pack. An exception thrown by a callback is caught and written to the error log; the current action is aborted, but the server does not crash.

The last argument is the live formula context of the dispatch, so a script reads the same event payload a data pack action could. This is how a script action sees a value such as damage that only the event knows about:

MxtActions.entity('example:knockback_on_hit', (entity, params, context) => {
const damage = context.explicit('damage')
if (Number.isNaN(damage)) return
entity.push(0, params.strength * damage, 0)
})

Register the callback with fewer parameters when the context is not needed — JavaScript ignores extra arguments. See FormulaContext for the variable methods; a script can read every built-in variable but cannot register a new one.

Running Any Built-in Action Directly​

MethodParametersReturn valueDescription
executeEntity(entity, definition)Entity, entity action JSONvoidDecodes and runs it through EntityAction.CODEC.
executeBiEntity(actor, target, definition)Two Entity, bi-entity action JSONvoidUses actor as the formula context subject.
executeBlock(level, pos, definition)Level, BlockPos, block action JSONvoidUses the level as the formula context.
executeItem(holder, stack, definition)Entity, ItemStack, item action JSONvoidUses the holder as the formula context subject.

definition is an action object whose format is exactly the same as a single action inside a data pack, and its type goes through the existing built-in registry dispatch:

MxtActions.executeEntity(player, {
type: 'mxt:heal',
amount: 4
})