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 anObjectRefpointing 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_sis the time passed since the object was unloaded, which can be used for updating the entity state.
- `on_deactivate(self)
- Called when the object is about to get removed or unloaded.
on_step(self, dtime)- Called on every server tick, after movement and collision processing.
dtimeis usually 0.1 seconds, as per thededicated_server_stepsetting inmulticraft.conf.
- Called on every server tick, after movement and collision processing.
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: anObjectRef(can benil)time_from_last_punch: Meant for disallowing spamming of clicks (can benil).tool_capabilities: capability table of used tool (can benil)dir: unit vector of direction of punch. Always defined. Points from the puncher to the punched.damage: damage that will be done to entity.- Can return
trueto prevent the default damage mechanism.
on_death(self, killer)- Called when the object dies.
killer: anObjectRef(can benil)
on_rightclick(self, clicker)on_attach_child(self, child)child: anObjectRefof the child that attaches
on_detach_child(self, child)child: anObjectRefof the child that detaches
on_detach(self, parent)parent: anObjectRef(can benil) 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_activatewhen the object is instantiated the next time.
- Should return a string that will be passed to