« Back to search

Mod

Entity node library

by The4spaceconstants · score 1.8 · license: MIT

Entity node library

Download latest release

A unified way to create nodes with entity features.

library

Entity node library (entitynode)

Namespace reference

entitynode = {
    register = function(nodename, node_def), -- registers an entity node, almost equivalent to core.register_node (see Additional definition fields)
    find = function(pos), -- returns the entity part of a node at pos, or nil if none
    entityname = "entitynode:base", -- entity part common registry name
    metakey = "entitynode:entity", -- metadata key for entity part guid
    group = "entitynode:has_entity", -- group for nodes with an entity part
}

Additional definition fields

node_def = {
    ...
    on_construct = function(pos), -- same as engine on_construct, but gets substituted during registration, so it won't be the same function in core.registered_nodes
    on_destruct = function(pos), -- same as engine on_destruct, same as above
    _init_entitynode = function(self, staticdata, dtime_s), -- same as on_activate for the entity part
    _fin_entitynode = function(self, removal), -- same as on_deactivate for the entity part
    _step_entitynode = function(self, dtime, moveresult),  -- same as on_step for the entity part
    ...
}

Entity behavior

The entity part of an entity node:

  • doesn't have persistent storage: use the node part's metadata for that
  • is only one type

Fields

local entity = {
    ...
    _nodename, -- name of associated node
    _def = core.registered_nodes[_nodename], -- definition of associated node
    ...
}