Registered entities

Functions receive a "luaentity" as self:

  • It has the member .name, which is the registered name ("mod:thing")
  • It has the member .object, which is an ObjectRef pointing to the object
  • The original prototype stuff is visible directly via a metatable

Callbacks:

  • on_activate(self, staticdata, dtime_s)
    • Called when the object is instantiated.
    • dtime_s is the time passed since the object was unloaded, which can be used for updating the entity state.
  • on_step(self, dtime)
    • Called on every server tick, after movement and collision processing. dtime is usually 0.1 seconds, as per the dedicated_server_step setting in minetest.conf.
  • on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
    • Called when somebody punches the object.
    • Note that you probably want to handle most punches using the automatic armor group system.
    • puncher: an ObjectRef (can be nil)
    • time_from_last_punch: Meant for disallowing spamming of clicks (can be nil).
    • tool_capabilities: capability table of used tool (can be nil)
    • dir: unit vector of direction of punch. Always defined. Points from the puncher to the punched.
    • damage: damage that will be done to entity.
  • on_death(self, killer)
    • Called when the object dies.
    • killer: an ObjectRef (can be nil)
  • on_rightclick(self, clicker)
  • on_attach_child(self, child)
    • child: an ObjectRef of the child that attaches
  • on_detach_child(self, child)
    • child: an ObjectRef of the child that detaches
  • on_detach(self, parent)
    • parent: an ObjectRef (can be nil) from where it got detached
    • This happens before the parent object is removed from the world
  • get_staticdata(self)
    • Should return a string that will be passed to on_activate when the object is instantiated the next time.