entity.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ---@meta
  2. ---Entity definition
  3. --------------------
  4. -- Used by `minetest.register_entity`.
  5. --
  6. -- You can define arbitrary member variables here by using a '_' prefix:
  7. --
  8. -- `_custom_field = whatever:mt.ItemDef`.
  9. ---@class mt.EntityDef
  10. -- * A table of object properties.
  11. -- * Object properties being read directly from the entity definition
  12. -- table is deprecated.
  13. -- * Define object properties in this `initial_properties` table instead.
  14. ---@field initial_properties mt.ObjectProp
  15. ---@field name string Registered name `("mod:thing")`.
  16. ---@field object mt.ObjectRef
  17. local entity = {}
  18. ---@param staticdata string
  19. ---@param dtime number Elapsed time.
  20. function entity:on_activate(staticdata, dtime) end
  21. -- Called when the object is about to get removed or unloaded.
  22. --
  23. -- - Note that this won't be called if the object hasn't been activated in the
  24. -- first place. In particular, `minetest.clear_objects({mode = "full"})` won't
  25. -- call this, whereas `minetest.clear_objects({mode = "quick"})` might call
  26. -- this.
  27. ---@param removal boolean Indicating whether the object is about to get removed.
  28. function entity:on_deactivate(removal) end
  29. -- Called every server step.
  30. ---@param dtime number Elapsed time.
  31. ---@param moveresult mt.CollisionInfo|nil Only available if `physical` == `true`.
  32. function entity:on_step(dtime, moveresult) end
  33. --[[
  34. Damage calculation:
  35. ```
  36. damage = 0
  37. foreach group in cap.damage_groups:
  38. damage += cap.damage_groups[group]
  39. * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0)
  40. * (object.armor_groups[group] / 100.0)
  41. -- Where object.armor_groups[group] is 0 for inexistent values
  42. return damage
  43. ```
  44. Client predicts damage based on damage groups. Because of this, it is able to
  45. give an immediate response when an entity is damaged or dies; the response is
  46. pre-defined somehow (e.g. by defining a sprite animation) (not implemented;
  47. TODO). Currently a smoke puff will appear when an entity dies.
  48. The group `immortal` completely disables normal damage.
  49. Entities can define a special armor group, which is `punch_operable`. This group
  50. disables the regular damage mechanism for players punching it by hand or a
  51. non-tool item, so that it can do something else than take damage.
  52. ]]
  53. ---@param puncher mt.ObjectRef|nil
  54. ---@param time_from_last_punch number|nil
  55. ---@param tool_capabilities mt.ToolCaps|nil
  56. ---@param dir mt.Vector Pointing from the source of the punch to the punched object.
  57. ---@param damage number
  58. ---@return boolean is_damaged
  59. function entity:on_punch(puncher, time_from_last_punch, tool_capabilities, dir, damage) end
  60. -- Called when the object dies.
  61. ---@param killer mt.ObjectRef|nil
  62. function entity:on_death(killer) end
  63. -- Called when `clicker` pressed the 'place/use' key while pointing to the
  64. -- object (not necessarily an actual rightclick).
  65. ---@param clicker mt.ObjectRef
  66. function entity:on_rightclick(clicker) end
  67. ---@param child mt.ObjectRef
  68. function entity:on_attach_child(child) end
  69. ---@param child mt.ObjectRef|nil
  70. function entity:on_detach_child(child) end
  71. -- Called sometimes; the string returned is passed to `on_activate` when
  72. -- the entity is re-activated from static state.
  73. ---@return string
  74. function entity:get_staticdata() end
  75. ---Collision info passed to `on_step` (`moveresult` argument).
  76. ---@class mt.CollisionInfo
  77. ---@field touching_ground boolean
  78. ---@field collides boolean
  79. ---@field standing_on_object boolean
  80. ---@field collisions mt.Collisions
  81. -- `mt.Collisions` does not contain data of unloaded mapblock collisions
  82. -- or when the velocity changes are negligibly small.
  83. ---@class mt.Collisions
  84. ---@field type "node"|"object"
  85. ---@field axis "x"|"y"|"z"
  86. ---@field node_pos mt.Vector If type is "node".
  87. ---@field object mt.ObjectRef If type is "object".
  88. ---@field old_velocity mt.Vector
  89. ---@field new_velocity mt.Vector