Skip to main content

Lua Scripting: Prop & Item API

This page covers every API available to FreeMinecraftModels prop and item scripts: context.prop, context.item, context.event, context.player, context.world, context.zones, context.scheduler, context.state, and context.log. If you are new to scripting, start with Getting Started first.


context.prop

The prop table provides information about the prop entity and methods to control its animations. This is rebuilt fresh for each hook call.

Fields

FieldTypeNotes
prop.model_idstringThe blueprint model name (e.g. "torch_01")
prop.current_locationlocation tableThe prop's position at the time the context was built

The location table has the standard fields: x, y, z, world, yaw, pitch.

Example: reading prop info
return {
api_version = 1,

on_spawn = function(context)
context.log:info("Prop spawned: " .. (context.prop.model_id or "unknown"))
local loc = context.prop.current_location
if loc then
context.log:info("Location: " .. loc.x .. ", " .. loc.y .. ", " .. loc.z)
end
end
}

prop:play_animation(name, blend, loop)

Plays a named animation on the prop model.

ParameterTypeDefaultNotes
namestringrequiredThe animation name as defined in the model file
blendbooleantrueWhether to blend with the current animation
loopbooleantrueWhether the animation loops

Returns true if the animation was found and started, false otherwise.

Example
return {
api_version = 1,

on_right_click = function(context)
local success = context.prop:play_animation("open", true, false)
if not success then
context.log:warn("Animation 'open' not found on this model!")
end
end
}

prop:stop_animation()

Stops all currently playing animations on the prop.

Takes no parameters.

Example
return {
api_version = 1,

on_right_click = function(context)
context.prop:stop_animation()
end
}

prop:hurt_visual()

Plays the visual hurt animation (red tint flash) on the prop without dealing any actual damage to it.

Takes no parameters.

Example
return {
api_version = 1,

on_left_click = function(context)
-- Flash red when punched, but don't actually take damage
if context.event then
context.event.cancel()
end
context.prop:hurt_visual()
end
}

prop:pickup()

Removes the prop from the world and drops a placement paper item at its location. The dropped item can be right-clicked on a block to place the prop again.

Takes no parameters.

Example
return {
api_version = 1,

on_right_click = function(context)
-- Let players pick up the prop by right-clicking it
context.prop:pickup()
end
}

prop:mount(player)

Mounts a player onto the first available mount point seat on the prop. The model must have mount-point bones defined.

ParameterTypeNotes
playerentity tableA player entity table (e.g. from context.event.player)
Example
return {
api_version = 1,

on_right_click = function(context)
local player = context.event and context.event.player
if player then
context.prop:mount(player)
end
end
}

prop:dismount(player)

Dismounts a player from their mount point seat on the prop.

ParameterTypeNotes
playerentity tableA player entity table
Example
return {
api_version = 1,

on_right_click = function(context)
local player = context.event and context.event.player
if player then
-- Toggle mount/dismount
local passengers = context.prop:get_passengers()
for i = 1, #passengers do
if passengers[i].uuid == player.uuid then
context.prop:dismount(player)
return
end
end
context.prop:mount(player)
end
end
}

prop:get_passengers()

Returns a Lua array of entity tables for all current passengers on the prop.

Takes no parameters.

Example
return {
api_version = 1,

on_game_tick = function(context)
local passengers = context.prop:get_passengers()
if #passengers > 0 then
context.log:info("Prop has " .. #passengers .. " passenger(s)")
end
end
}

prop:has_mount_points()

Returns whether this prop has mount-point bones defined in its model.

Takes no parameters. Returns true or false.

Example
return {
api_version = 1,

on_right_click = function(context)
local player = context.event and context.event.player
if player and context.prop:has_mount_points() then
context.prop:mount(player)
end
end
}

prop:spawn_elitemobs_boss(filename, x, y, z)

Spawns an EliteMobs custom boss at the given location. Requires EliteMobs to be installed on the server.

ParameterTypeNotes
filenamestringThe custom boss filename (e.g. "my_boss.yml")
xnumberX coordinate
ynumberY coordinate
znumberZ coordinate

Returns a living entity table for the spawned boss, or nil if EliteMobs is not installed or the boss file does not exist.

Example
return {
api_version = 1,

on_right_click = function(context)
local loc = context.prop.current_location
if loc then
local boss = context.prop:spawn_elitemobs_boss("dungeon_guardian.yml", loc.x, loc.y + 1, loc.z)
if boss then
context.log:info("Spawned boss: " .. (boss.name or "unknown"))
else
context.log:warn("Could not spawn boss -- is EliteMobs installed?")
end
end
end
}

prop:open_inventory(player, title, rows)

Opens a persistent chest inventory GUI for the player. Contents are saved to the prop's PersistentDataContainer when the inventory is closed, and restored when opened again.

ParameterTypeDefaultNotes
playerentity tablerequiredThe player to show the inventory to
titlestringrequiredThe inventory title (supports & color codes)
rowsint3Number of rows (1-6, where 6 = 54 slots = double chest)

Returns true if the inventory was opened, false otherwise.


prop:is_viewing_inventory(player)

Returns whether the given player currently has this prop's inventory open.

ParameterTypeNotes
playerentity tableThe player to check

Returns true or false.

Example: Close animation when inventory is closed
context.state["task_" .. player.uuid] = context.scheduler:run_repeating(5, 5, function(tick_context)
if not tick_context.prop:is_viewing_inventory(player) then
tick_context.prop:play_animation("close", true, false)
tick_context.scheduler:cancel(tick_context.state["task_" .. player.uuid])
end
end)

prop:place_book(player)

Takes the written or writable book from the player's main hand and stores it on the prop.

ParameterTypeNotes
playerentity tableThe player holding the book

Returns true if successful.


prop:read_book(player)

Opens the stored book for reading by the player.

ParameterTypeNotes
playerentity tableThe player to show the book to

Returns true if a book was opened.


prop:take_book(player)

Returns the stored book to the player's inventory and removes it from the prop.

ParameterTypeNotes
playerentity tableThe player to give the book to

Returns true if successful.


prop:has_book()

Returns whether a book is stored on this prop. Takes no parameters.


prop:drop_inventory()

Drops all stored inventory contents at the prop's location as item entities, then clears the stored data. Automatically closes the inventory for any players currently viewing it.

Takes no parameters. Returns true if successful.


prop:drop_book()

Drops the stored book at the prop's location as an item entity and clears the stored book data.

Takes no parameters. Returns true if successful.


prop:set_persistent_data(key, value)

Stores a string value on the prop's armor stand PersistentDataContainer. This data survives server restarts and chunk unloads.

ParameterTypeNotes
keystringA unique key name (stored under fmm_lua_<key> internally)
valuestringThe value to store. Use tostring() for numbers and booleans.

Returns true if successful, false if the prop has no backing armor stand.


prop:get_persistent_data(key)

Retrieves a string value previously stored with set_persistent_data. Returns nil if the key has not been set.

ParameterTypeNotes
keystringThe key name used in set_persistent_data
Example: Persistent toggle state
return {
api_version = 1,

on_spawn = function(context)
local saved = context.prop:get_persistent_data("active")
context.state.active = saved == "true"
end,

on_right_click = function(context)
context.state.active = not context.state.active
context.prop:set_persistent_data("active", tostring(context.state.active))
end
}

context.item

The item table is available in item scripts only (not prop scripts). It provides information about the custom item and methods to manipulate it. This table is rebuilt fresh for each hook call.

Fields

FieldTypeNotes
item.idstringThe item type ID (the fmm_item_id from the YML config)

item:material()

Returns the material name of the item as a string (e.g. "DIAMOND_SWORD", "STICK").


item:get_amount() / item:set_amount(n)

Gets or sets the stack size of the item.

ParameterTypeNotes
nintThe new stack amount

item:consume(n)

Decrements the item's stack amount by n (default 1). If the resulting amount is 0 or less, the item is removed from the player's inventory.

ParameterTypeDefaultNotes
nint1Amount to consume

item:get_uses() / item:set_uses(n)

Gets or sets a custom use counter stored in the item's PersistentDataContainer. This is independent of vanilla durability and can be used to implement custom durability or charge systems.

ParameterTypeNotes
nintThe new use count

item:get_name() / item:set_name(s)

Gets or sets the display name of the item. Supports color codes with &.

ParameterTypeNotes
sstringThe new display name (e.g. "&b&lFrost Sword")

item:get_lore() / item:set_lore(table)

Gets or sets the item's lore. get_lore() returns a table of strings (one per line). set_lore() takes a table of strings.

ParameterTypeNotes
tabletableArray of strings, one per lore line
Example: Item script that tracks uses
return {
api_version = 1,

on_right_click = function(context)
local uses = context.item:get_uses()
if uses <= 0 then
context.player:send_message("&cThis item is out of charges!")
return
end
context.item:set_uses(uses - 1)
context.player:send_message("&aUsed! Charges remaining: " .. (uses - 1))
end
}

item:get_durability()

Returns a table with current and max fields representing the item's vanilla durability, or nil if the item has no durability bar.

Example
local dur = context.item:get_durability()
if dur then
context.player:send_message("Durability: " .. dur.current .. "/" .. dur.max)
end

item:get_durability_percentage()

Returns the remaining durability as a 0.0 to 1.0 fraction, or nil if the item has no durability bar.


item:use_durability(amount, can_break)

Reduces the item's vanilla durability by a flat amount.

ParameterTypeDefaultNotes
amountintrequiredHow many durability points to consume
can_breakbooleanfalseIf true, the item is destroyed when durability runs out. If false, durability stops at 1.

item:use_durability_percentage(fraction, can_break)

Reduces the item's vanilla durability by a percentage of its maximum.

ParameterTypeDefaultNotes
fractionnumberrequiredFraction of max durability to consume (e.g. 0.1 = 10%)
can_breakbooleanfalseIf true, the item is destroyed when durability runs out. If false, durability stops at 1.

context.event

Event data for the current hook. Available in click, combat, and interaction hooks for both prop and item scripts. Returns nil in hooks that have no associated event (on_spawn, on_game_tick, on_destroy, on_zone_enter, on_zone_leave, on_equip).

Fields and Methods

Field or MethodTypeNotes
event.playerplayer entity tableThe player who triggered the event. Available in on_left_click, on_right_click, and on_projectile_hit (the shooter, if it was a player). See Player Entity Methods for all fields and methods.
event.is_cancelledbooleanWhether the event is currently cancelled
event.cancel()functionCancels the event (e.g. prevents damage or interaction)
event.uncancel()functionUn-cancels a previously cancelled event
info

Not all events are cancellable. If the underlying Bukkit event does not implement Cancellable, event.cancel() and event.uncancel() will not be present and event.is_cancelled will always be false.

Example: Making a prop invulnerable

Example
return {
api_version = 1,

on_left_click = function(context)
if context.event then
context.event.cancel()
end
end
}

Example: Checking cancellation state

Example
return {
api_version = 1,

on_left_click = function(context)
if context.event and not context.event.is_cancelled then
context.event.cancel()
context.log:info("Damage cancelled!")
end
end
}
caution

Inside scheduled callbacks (scheduler:run_later, scheduler:run_repeating), context.event is always nil. Event modification can only happen during the event hook itself.


context.world

The world API is shared across all Nightbreak plugins. See context.world for the full reference.

info

FMM props use the same MagmaCore world table as EliteMobs bosses. All methods documented on the global page (get_block_at, set_block_at, spawn_particle, play_sound, strike_lightning, get_time, set_time, get_nearby_entities, get_nearby_players, spawn_entity, get_highest_block_y, raycast, spawn_firework) are available in FMM. See the MagmaCore world API for full details on world:raycast() (cast a ray and detect hit entities/blocks) and world:spawn_firework() (spawn firework rockets with custom colors and shapes). EliteMobs extends the world table with additional methods for spawning bosses, reinforcements, and more -- see EliteMobs World & Environment.


Player Entity Methods

Player entity tables are returned from context.event.player, context.world:get_nearby_players(), and zone callbacks.

Shared API

The entity tables, living entity methods, player-specific methods, and Player UI methods are shared across all Nightbreak plugins. See the MagmaCore Lua Scripting Engine for the full reference covering entity base fields, living entity fields and methods, player-specific fields and methods, and Player UI Methods. New player methods include player:get_target_entity() (raycast targeting), player:get_eye_location(), player:get_look_direction(), player:send_block_change() (per-player fake blocks), and player:reset_block() -- see Player-Specific Methods for details.


context.zones

The zones API is shared across all Nightbreak plugins. See context.zones for the full reference.


context.scheduler

The scheduler API is shared across all Nightbreak plugins. See context.scheduler for the full reference.


context.state

The state API is shared across all Nightbreak plugins. See context.state for the full reference.


context.log

The logging API is shared across all Nightbreak plugins. See context.log for the full reference.


Runtime Model

One Runtime Per Script Instance

Every prop entity that has scripts attached gets its own independent Lua runtime instance. When the prop spawns, FMM loads the Lua source, evaluates it in a fresh sandboxed environment, and stores the returned table. When the prop is removed, the runtime is shut down.

For item scripts, one runtime is created per (player, itemId) pair. When a player equips a custom item, FMM creates a script instance for that player and item type. When the item is unequipped, the runtime is shut down.

This means:

  • Local variables declared at file scope are private to that script instance.
  • context.state is completely isolated between instances, even if they share the same script file.

Scheduled Task Ownership

All tasks created through context.scheduler are owned by the runtime that created them. When a prop is removed:

  1. The runtime shuts down.
  2. Every owned task -- both one-shot and repeating -- is automatically cancelled.
  3. All zone watches are cleared.

Execution Budget

Every hook invocation and every callback invocation is timed. If a single call takes longer than 50 milliseconds, the script is disabled with a console warning:

[Lua] my_script.lua took 73ms in 'on_game_tick' (limit: 50ms) -- script disabled to prevent lag.

To stay within budget:

  • Avoid unbounded loops inside hooks.
  • Keep on_game_tick handlers lightweight -- they run every single tick.
  • Use context.scheduler:run_repeating(...) to spread work across ticks.

Complete Hook Reference

This table lists all hooks available across both prop and item scripts.

Prop Hooks (8)

HookFires whencontext.event
on_spawnProp spawns into the worldnil
on_game_tickEvery server tick (50ms)nil
on_destroyProp is removednil
on_left_clickPlayer left-clicks the propdamage event
on_right_clickPlayer right-clicks the propinteraction event
on_projectile_hitProjectile hits the propprojectile hit event
on_zone_enterPlayer enters a watched zonenil
on_zone_leavePlayer leaves a watched zonenil

Item Hooks (22)

HookCategoryFires whencontext.event
on_attack_entityCombatPlayer attacks an entitydamage event
on_kill_entityCombatPlayer kills an entitydeath event
on_take_damageCombatPlayer takes damagedamage event
on_shield_blockCombatPlayer blocks with shielddamage event
on_shoot_bowCombatPlayer shoots a bowbow shoot event
on_projectile_hitCombatPlayer's projectile hitsprojectile hit event
on_projectile_launchCombatPlayer launches projectilelaunch event
on_right_clickInteractionPlayer right-clicksinteract event
on_left_clickInteractionPlayer left-clicksinteract event
on_shift_right_clickInteractionPlayer shift+right-clicksinteract event
on_shift_left_clickInteractionPlayer shift+left-clicksinteract event
on_interact_entityInteractionPlayer right-clicks entityentity interact event
on_equipEquipmentItem enters active slotnil
on_unequipEquipmentItem leaves active slotnil
on_swap_handsEquipmentSwaps main/off handswap event
on_dropEquipmentPlayer drops itemdrop event
on_break_blockUtilityPlayer breaks blockblock break event
on_consumeUtilityPlayer consumes itemconsume event
on_item_damageUtilityItem takes durability damageitem damage event
on_fishUtilityPlayer uses fishing rodfish event
on_deathUtilityPlayer dies while equippeddeath event
on_game_tickLifecycleEvery tick while equippednil

Next Steps