Download (9 KB)
For Luanti 5.14 and above

How do I install this?

Node entity library (nodeentity) 🔗

Library for functional node entities, with minimal setup

Node entities should act exactly like normal nodes
any discrepancy should be reported

Namespace reference 🔗

nodeentity = {
  function add(pos, node), -- creates a functional node entity at specified position in accordance to specified MapNode table (actually returns an ObjectRef)  
  function read_world(pos, anchor, minp, maxp), -- creates a nodeset at <pos> with nodes from <minp> to <maxp> relative to <anchor>
  function relative_pos(entity), -- given a node luaentity, a position is constructed from which to access the node entity like one'd access normal nodes

  -- exposed internal tables
  fs_context = {
    [formname] = {
      [playername] = {formspec, entity} 
    }
  }, -- table of active forms in nodeentities
}

Position format 🔗

local position = {
  x, y, z -- position components
  relative = entityID -- optional relativity specifier; when present, the position is relative to the specified node entity or its corresponding node entity set
}

core/vector namespace functions and ObjectRef/Voxelmanip methods are wrapped to work with these positions
if any of them don't work, make an issue

Node entity sets ("nodeentity:nodeset") 🔗

2 node entities attached to the same nodeset share the same pos.relative, and exist at xyz offsets of each-other's positions

To add a node entity to a node set, attach it as specified: nodeobject:set_attach(nodeset, "", pos * 10), the engine requires the pos multiplication, but the automatic inclusion of the entity works as normal

Node definition interface 🔗

local nodedef = {
  ...
  function _nodeentity_step(self, dtime, moveresult), -- runs exclusively on node entities, identical to <step> in entity defintions
  <other callbacks> -- current entity is appended to the end of function arguments (abms and lbms included)
  ...
}

Entity fields 🔗

local entity = {
  ...
  function _showfs(playername, formname, formspec), -- used like core.show_formspec, includes the nuances in node forms
  _metadata, -- imitation of NodeMetaRef
  _invname, -- inventory name used in showing current node entity inventory
  _timer, -- lua implementation of NodeTimerRef
  ...
}

Reviews

Review

Do you recommend this mod?

  • English

    Sample AI generated Docs

    this has been generated by pasting the source code into chatgtp please whoever made this mod add actual docs later luanti_node_entities

    Turn nodes into entities while preserving metadata, inventories, timers, ABMs, LBMs, and formspecs.

    Entities

    nodeentity:node Node rendered as visual="node". Stores:

    name, param1, param2

    metadata (detached inventory)

    timer state Forwards node callbacks (on_construct, on_timer, inventory callbacks, etc.).

    nodeentity:nodeset Container entity used to attach multiple nodeentities (moving structures).

    API nodeentity.add(pos, node) ObjectRef nodeentity.add(vector pos, table node)

    Create a nodeentity.

    local obj = nodeentity.add({x=0,y=5,z=0}, { name="default:chest", param1=0, param2=0 }) nodeentity.relative_pos(entity) vector nodeentity.relative_pos(luaentity entity)

    Returns relative position used in forwarded callbacks.

    nodeentity.read_world(pos, anchor, minp, maxp) ObjectRef nodeentity.read_world(vector pos, vector anchor, vector minp, vector maxp)

    Copies a region into nodeentities attached to a nodeset.

    local ship = nodeentity.read_world( {x=0,y=20,z=0}, {x=0,y=0,z=0}, {x=-5,y=0,z=-5}, {x=5,y=5,z=5} ) ship:set_velocity({x=2,y=0,z=0}) Node Definition Compatibility

    Normal node defs work:

    core.register_node("mymod:machine", { on_construct = function(pos, entity) core.get_node_timer(pos):start(5) end,

    on_timer = function(pos, elapsed, entity) return true end,

    allow_metadata_inventory_put = function(pos, list, idx, stack, player, entity) return stack:get_count() end, }) Timers local t = core.get_node_timer(pos) t:start(5)

    on_timer(pos, elapsed, entity) supported. Metadata & Forms local meta = core.get_meta(pos) meta:set_string("infotext","Running") Forms using [nodemeta] and [context] work automatically. Notes

    Most core., vector., and VoxelManip node access is wrapped.

    ABMs & LBMs (run_at_every_load=true) supported.

    5 comments
  • English

    API documentation is insufficient

    I got very excited when I saw this mod. Entities that recreate nodes? Awesome!

    But sadly it is unusable in its current state because the API documentation is very insufficient. Only a few data formats are described but not the functions.

    1 comments